Re: Anyone using django tabs ?

2013-06-20 Thread tony gair
The answer I think is no , ah well. 

On Thursday, 20 June 2013 09:28:39 UTC, tony gair wrote:
>
> I am trying django tabs for my site navigation and was wondering is I have 
> to list multiple tabs in the html file thats inherits from base.html
>
> {% if request.user.is_superuser %}
>  {% activetab "topnav" "home" %}
>  {% activetab "topnav" "admin" %}
> {% endif %}
>
> or can I say
> {% if request.user.is_superuser %}
>  {% activetab "topnav" "home" "topnav" "admin"%}
> {% endif %}
>
> or even 
>
> {% if request.user.is_superuser %}
>  {% activetab "home"  "admin"%}
> {% endif %}
>
> with only one navigation bar?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Anyone using django tabs ?

2013-06-20 Thread tony gair
I am trying django tabs for my site navigation and was wondering is I have 
to list multiple tabs in the html file thats inherits from base.html

{% if request.user.is_superuser %}
 {% activetab "topnav" "home" %}
 {% activetab "topnav" "admin" %}
{% endif %}

or can I say
{% if request.user.is_superuser %}
 {% activetab "topnav" "home" "topnav" "admin"%}
{% endif %}

or even 

{% if request.user.is_superuser %}
 {% activetab "home"  "admin"%}
{% endif %}

with only one navigation bar?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: readonly_fields

2013-06-19 Thread tony gair
Ah thanks that explains that I'll look into changing the readonly
attribute on the widget, is there a list of widgets do you know as some of
these are choice fields i.e. non text and non integer fields


On Wed, Jun 19, 2013 at 1:26 PM, Timster  wrote:

> Where are you setting that? readonly_fields is for ModelAdmin when you are
> working with the admin app.
>
> If you want to do it in a normal form, you will need to set readonly
> attribute on the widget.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/SEWttelj3h0/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




readonly_fields

2013-06-19 Thread tony gair

I have tried to use readonly_fields in a form to designate fields that the 
user is not allowed to change.

class Meta 
readonly_fields = [user]
e.g.


However when I show the form the user can edit them.doh, btw I do want 
to display, but not to edit!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: database -> model -> charting

2013-06-10 Thread tony gair
I have subsequently located the problem. I think where the chartit.py 
supplies a parameter saying use_decimal=true is wrong. I have removed that 
parameter and found that it works with that change. 
Do you know if this is because of updates to jquery? 

On Monday, June 10, 2013 12:38:02 PM UTC, tony gair wrote:
>
> I tried that on 1.5 and tried my code out in a 1.4 install. I get the same 
> error.  Interestingly in stack overflow they mention this problem at 
> http://stackoverflow.com/questions/8644060/caught-typeerror-while-rendering-init-got-an-unexpected-keyword-argument
>
> and chartit in its own code seems to expect a decimal value regardless, so 
> maybe decimal values are hardwired into the code
>
> On Monday, June 10, 2013 10:55:00 AM UTC, Christian Schulz wrote:
>>
>> It could be a problem with the simpleson.dumps options in django 1.5 vs. 
>> the included simplejson. I remember there was something... 
>> Change: 
>> chartit/templatetags/chartit.py 
>> - from django.utils import simplejson 
>> +import simplejson 
>>
>>
>> > TypeError at /heating/chart/ 
>> > __init__() got an unexpected keyword argument 'use_decimal' 
>> > Request Method:GET 
>> > Request URL:http://127.0.0.1:8000/heating/chart/ 
>> > Django Version:1.5.1 
>> > Exception Type:TypeError 
>> > Exception Value: 
>> > __init__() got an unexpected keyword argument 'use_decimal' 
>> > Exception Location:/usr/lib/python2.7/json/__init__.py in dumps, line 
>> 250 
>> > Python Executable:/usr/bin/python 
>> > Python Version:2.7.4 
>> > Python Path: 
>> > ['/home/tony/django/sh', 
>> >  '/usr/local/lib/python2.7/dist-packages/Django-1.5.1-py2.7.egg', 
>> >  '/usr/lib/python2.7', 
>> >  '/usr/lib/python2.7/plat-i386-linux-gnu', 
>> >  '/usr/lib/python2.7/lib-tk', 
>> >  '/usr/lib/python2.7/lib-old', 
>> >  '/usr/lib/python2.7/lib-dynload', 
>> >  '/usr/local/lib/python2.7/dist-packages', 
>> >  '/usr/lib/python2.7/dist-packages', 
>> >  '/usr/lib/python2.7/dist-packages/PILcompat', 
>> >  '/usr/lib/python2.7/dist-packages/gtk-2.0', 
>> >  '/usr/lib/python2.7/dist-packages/ubuntu-sso-client', 
>> >  '/usr/lib/python2.7/dist-packages/ubuntuone-client', 
>> >  '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel', 
>> >  '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol'] 
>> > 
>> > This was my error. What I did was replace the two american city 
>> > temperature example with my own model data. However my data was 
>> > different in that the two temperatures were integer and the time axis 
>> > variable was actually utctime time (unconverted :) ) , the odd thing 
>> > though is that there seems to be no way to specify the variables going 
>> > in to the wrapper. e.g. Why is it insisting on a decimal, I cannot see 
>> > where this is specified in the example! 
>> > 
>> > On Monday, 10 June 2013 08:28:57 UTC, Christian Schulz wrote: 
>> > 
>> > I installed with python2.7/1.4.5 some weeks ago , but I didn't use 
>> a 
>> > BigIntegerField. What is your error message? 
>> > 
>> > 
>> > > After trying this I find a problem with the types it can use. For 
>> > > example it does not seem to like BigIntegerField unless there is 
>> > > something else I am doing wrong. Thinking about it, maybe I am 
>> > letting 
>> > > chartit do too much for me but I do like the idea of something 
>> > doing 
>> > > the hard thinking for me :). I am using python 2.7 and django 
>> > 1.5, are 
>> > > you using the same ? 
>> > > 
>> > > On Friday, 7 June 2013 11:33:07 UTC+1, Christian Schulz wrote: 
>> > > 
>> > > When you have some experience with JS/Highcharts 
>> django-chartit 
>> > > might be 
>> > > interesting. 
>> > > Easy is relativ but I got it and I'm really not a django/JS 
>> > pro. It's 
>> > > nice work, but dev progress seems fallen asleep. 
>> > > 
>> > > http://chartit.shutupandship.com/ 
>> > <http://chartit.shutupandship.com/> 
>> > <http://chartit.shutupandship.com/ 
>> > <http://chartit.shut

Re: database -> model -> charting

2013-06-10 Thread tony gair
I tried that on 1.5 and tried my code out in a 1.4 install. I get the same 
error.  Interestingly in stack overflow they mention this problem at 
http://stackoverflow.com/questions/8644060/caught-typeerror-while-rendering-init-got-an-unexpected-keyword-argument

and chartit in its own code seems to expect a decimal value regardless, so 
maybe decimal values are hardwired into the code

On Monday, June 10, 2013 10:55:00 AM UTC, Christian Schulz wrote:
>
> It could be a problem with the simpleson.dumps options in django 1.5 vs. 
> the included simplejson. I remember there was something... 
> Change: 
> chartit/templatetags/chartit.py 
> - from django.utils import simplejson 
> +import simplejson 
>
>
> > TypeError at /heating/chart/ 
> > __init__() got an unexpected keyword argument 'use_decimal' 
> > Request Method:GET 
> > Request URL:http://127.0.0.1:8000/heating/chart/ 
> > Django Version:1.5.1 
> > Exception Type:TypeError 
> > Exception Value: 
> > __init__() got an unexpected keyword argument 'use_decimal' 
> > Exception Location:/usr/lib/python2.7/json/__init__.py in dumps, line 
> 250 
> > Python Executable:/usr/bin/python 
> > Python Version:2.7.4 
> > Python Path: 
> > ['/home/tony/django/sh', 
> >  '/usr/local/lib/python2.7/dist-packages/Django-1.5.1-py2.7.egg', 
> >  '/usr/lib/python2.7', 
> >  '/usr/lib/python2.7/plat-i386-linux-gnu', 
> >  '/usr/lib/python2.7/lib-tk', 
> >  '/usr/lib/python2.7/lib-old', 
> >  '/usr/lib/python2.7/lib-dynload', 
> >  '/usr/local/lib/python2.7/dist-packages', 
> >  '/usr/lib/python2.7/dist-packages', 
> >  '/usr/lib/python2.7/dist-packages/PILcompat', 
> >  '/usr/lib/python2.7/dist-packages/gtk-2.0', 
> >  '/usr/lib/python2.7/dist-packages/ubuntu-sso-client', 
> >  '/usr/lib/python2.7/dist-packages/ubuntuone-client', 
> >  '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel', 
> >  '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol'] 
> > 
> > This was my error. What I did was replace the two american city 
> > temperature example with my own model data. However my data was 
> > different in that the two temperatures were integer and the time axis 
> > variable was actually utctime time (unconverted :) ) , the odd thing 
> > though is that there seems to be no way to specify the variables going 
> > in to the wrapper. e.g. Why is it insisting on a decimal, I cannot see 
> > where this is specified in the example! 
> > 
> > On Monday, 10 June 2013 08:28:57 UTC, Christian Schulz wrote: 
> > 
> > I installed with python2.7/1.4.5 some weeks ago , but I didn't use a 
> > BigIntegerField. What is your error message? 
> > 
> > 
> > > After trying this I find a problem with the types it can use. For 
> > > example it does not seem to like BigIntegerField unless there is 
> > > something else I am doing wrong. Thinking about it, maybe I am 
> > letting 
> > > chartit do too much for me but I do like the idea of something 
> > doing 
> > > the hard thinking for me :). I am using python 2.7 and django 
> > 1.5, are 
> > > you using the same ? 
> > > 
> > > On Friday, 7 June 2013 11:33:07 UTC+1, Christian Schulz wrote: 
> > > 
> > > When you have some experience with JS/Highcharts 
> django-chartit 
> > > might be 
> > > interesting. 
> > > Easy is relativ but I got it and I'm really not a django/JS 
> > pro. It's 
> > > nice work, but dev progress seems fallen asleep. 
> > > 
> > > http://chartit.shutupandship.com/ 
> >  
> >  > > 
> > > 
> > > 
> > > > 
> > > > 
> > > > I would like to hear peoples opinions on third party django 
> > > charting 
> > > > apps, with various considerations. My primary consideration 
> > > would ease 
> > > > of use by a django noob. Thanks 
> > > > -- 
> > > > You received this message because you are subscribed to 
> > the Google 
> > > > Groups "Django users" group. 
> > > > To unsubscribe from this group and stop receiving emails 
> from 
> > > it, send 
> > > > an email to django-users...@googlegroups.com . 
> > > > To post to this group, send email to 
> > django...@googlegroups.com 
> > > . 
> > > > Visit this group at 
> > > http://groups.google.com/group/django-users?hl=en 
> >  
> > >  > >. 
> > > > For more options, visit 
> > https://groups.google.com/groups/opt_out 
> >  
> > >  > >. 
> > > > 
> > > > 
> > 

Re: database -> model -> charting

2013-06-10 Thread tony gair
TypeError at /heating/chart/
__init__() got an unexpected keyword argument 'use_decimal'
Request Method: GET
Request URL: http://127.0.0.1:8000/heating/chart/
Django Version: 1.5.1
Exception Type: TypeError
Exception Value: 
__init__() got an unexpected keyword argument 'use_decimal'
Exception Location: /usr/lib/python2.7/json/__init__.py in dumps, line 250
Python Executable: /usr/bin/python
Python Version: 2.7.4
Python Path: 
['/home/tony/django/sh',
 '/usr/local/lib/python2.7/dist-packages/Django-1.5.1-py2.7.egg',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-i386-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/PILcompat',
 '/usr/lib/python2.7/dist-packages/gtk-2.0',
 '/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
 '/usr/lib/python2.7/dist-packages/ubuntuone-client',
 '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel',
 '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol']

This was my error. What I did was replace the two american city temperature 
example with my own model data. However my data was different in that the 
two temperatures were integer and the time axis variable was actually 
utctime time (unconverted :) ) , the odd thing though is that there seems 
to be no way to specify the variables going in to the wrapper. e.g. Why is 
it insisting on a decimal, I cannot see where this is specified in the 
example!

On Monday, 10 June 2013 08:28:57 UTC, Christian Schulz wrote:
>
> I installed with python2.7/1.4.5 some weeks ago , but I didn't use a 
> BigIntegerField. What is your error message? 
>
>
> > After trying this I find a problem with the types it can use. For 
> > example it does not seem to like BigIntegerField unless there is 
> > something else I am doing wrong. Thinking about it, maybe I am letting 
> > chartit do too much for me but I do like the idea of something doing 
> > the hard thinking for me :). I am using python 2.7 and django 1.5, are 
> > you using the same ? 
> > 
> > On Friday, 7 June 2013 11:33:07 UTC+1, Christian Schulz wrote: 
> > 
> > When you have some experience with JS/Highcharts django-chartit 
> > might be 
> > interesting. 
> > Easy is relativ but I got it and I'm really not a django/JS pro. 
> It's 
> > nice work, but dev progress seems fallen asleep. 
> > 
> > http://chartit.shutupandship.com/  
>
> > 
> > 
> > > 
> > > 
> > > I would like to hear peoples opinions on third party django 
> > charting 
> > > apps, with various considerations. My primary consideration 
> > would ease 
> > > of use by a django noob. Thanks 
> > > -- 
> > > You received this message because you are subscribed to the Google 
> > > Groups "Django users" group. 
> > > To unsubscribe from this group and stop receiving emails from 
> > it, send 
> > > an email to django-users...@googlegroups.com . 
> > > To post to this group, send email to django...@googlegroups.com 
> > . 
> > > Visit this group at 
> > http://groups.google.com/group/django-users?hl=en 
> > . 
> > > For more options, visit https://groups.google.com/groups/opt_out 
> > . 
> > > 
> > > 
> > 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: database -> model -> charting

2013-06-08 Thread tony gair
After trying this I find a problem with the types it can use. For example 
it does not seem to like BigIntegerField unless there is something else I 
am doing wrong. Thinking about it, maybe I am letting chartit do too much 
for me but I do like the idea of something doing the hard thinking for me 
:). I am using python 2.7 and django 1.5, are you using the same ?

On Friday, 7 June 2013 11:33:07 UTC+1, Christian Schulz wrote:
>
> When you have some experience with JS/Highcharts django-chartit might be 
> interesting. 
> Easy is relativ but I got it and I'm really not a django/JS pro. It's 
> nice work, but dev progress seems fallen asleep. 
>
> http://chartit.shutupandship.com/ 
>
>
> > 
> > 
> > I would like to hear peoples opinions on third party django charting 
> > apps, with various considerations. My primary consideration would ease 
> > of use by a django noob. Thanks 
> > -- 
> > You received this message because you are subscribed to the Google 
> > Groups "Django users" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> > an email to django-users...@googlegroups.com . 
> > To post to this group, send email to 
> > django...@googlegroups.com. 
>
> > Visit this group at http://groups.google.com/group/django-users?hl=en. 
> > For more options, visit https://groups.google.com/groups/opt_out. 
> > 
> > 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: database -> model -> charting

2013-06-07 Thread tony gair
Been trying out a couple over the last few hours. I have to say, the one 
you mention seems streets ahead of anything else, and its documented really 
well, which is the clincher for me.
Many thanks for that super helpful info!

On Friday, 7 June 2013 11:33:07 UTC+1, Christian Schulz wrote:
>
> When you have some experience with JS/Highcharts django-chartit might be 
> interesting. 
> Easy is relativ but I got it and I'm really not a django/JS pro. It's 
> nice work, but dev progress seems fallen asleep. 
>
> http://chartit.shutupandship.com/ 
>
>
> > 
> > 
> > I would like to hear peoples opinions on third party django charting 
> > apps, with various considerations. My primary consideration would ease 
> > of use by a django noob. Thanks 
> > -- 
> > You received this message because you are subscribed to the Google 
> > Groups "Django users" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> > an email to django-users...@googlegroups.com . 
> > To post to this group, send email to 
> > django...@googlegroups.com. 
>
> > Visit this group at http://groups.google.com/group/django-users?hl=en. 
> > For more options, visit https://groups.google.com/groups/opt_out. 
> > 
> > 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




database -> model -> charting

2013-06-07 Thread tony gair


I would like to hear peoples opinions on third party django charting apps, 
with various considerations. My primary consideration would ease of use by 
a django noob. Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: getting information from a many to many model from user

2013-06-07 Thread tony gair
That would work nicely if I had done my own user management app but I 
lazily used Userena. I think I need to override a function of their profile 
form so it only displays fields if the superuser or a designated boolean in 
same said profile is set to true:)
Do you know how I would over ride a class function ?

On Thursday, 6 June 2013 13:02:02 UTC, Daniel Roseman wrote:
>
> On Thursday, 6 June 2013 11:00:40 UTC+1, tony gair wrote:
>
>>
>>
>>
>> I use the Userena app to manage my users but I want the superuser to 
>> choose the organisation for them so they cannot wonder around other 
>> organisations information.
>>
>> I can either create a foreign key in their profile to point to the 
>> organisation but then I expect they can change it, which would not be 
>> acceptable. 
>>
>> I could create a many to many set of models (as per the documentation) 
>> but then I need to discover the organisation they are part of, every time a 
>> form is entered into, in which case I would need a function to discover the 
>> organisation id from the querying the user object in my group model.
>>
>> My favourite would probably be to have unmodifiable fields (by them) but 
>> which the superuser can alter. Anyone know how I would do this?
>>
>>
>>
> Users can only alter fields if you write code that allows them to do so. 
> If you don't want them to alter a particular field in their profile, just 
> don't include that field on the form (or specifically exclude it).
> --
> DR.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




getting information from a many to many model from user

2013-06-06 Thread tony gair



I use the Userena app to manage my users but I want the superuser to choose 
the organisation for them so they cannot wonder around other organisations 
information.

I can either create a foreign key in their profile to point to the 
organisation but then I expect they can change it, which would not be 
acceptable. 

I could create a many to many set of models (as per the documentation) but 
then I need to discover the organisation they are part of, every time a 
form is entered into, in which case I would need a function to discover the 
organisation id from the querying the user object in my group model.

My favourite would probably be to have unmodifiable fields (by them) but 
which the superuser can alter. Anyone know how I would do this?


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: CBVs and logging a user

2013-06-04 Thread tony gair
excellent thanks Bill!



On Tue, Jun 4, 2013 at 9:35 PM, Bill Freeman  wrote:

> Looking closer, do you have an app named 'main'?  If so does it have a
> urls.py in it?  Can you import that without error (say in the manage.py
> shell)?  If so, try:
>
> repr(main.urlpatterns)
>
> (Since the error message complains that main.urls has no url patterns in
> it.)
>
> If you don't expect to use such a module, check your existing urls.py
> files for a url pattern that does include('main.urls'), or something close.
>
>
> On Tue, Jun 4, 2013 at 2:58 AM, tony gair  wrote:
>
>> my URLS_CONF points to my urls.py in my main project directory. The error
>> only once I press the login button, the form is validated, the user
>> then(correctly ) is authenticated then it fails with the error when I try
>> to redirect it to a view.
>>
>>
>> On Monday, June 3, 2013 2:45:09 PM UTC, tony gair wrote:
>>>
>>>
>>> I'm getting an error
>>>
>>> Request URL: 
>>> http://127.0.0.1:8000/heating/**login/?next=/heating/orglv/<http://127.0.0.1:8000/heating/login/?next=/heating/orglv/>
>>> Django Version: 1.5.1
>>> Exception Type: ImproperlyConfigured
>>> Exception Value:
>>> The included urlconf main.urls doesn't have any patterns in it
>>>
>>> my login form and view has been modified to work off email and password
>>> rather than username and password
>>>
>>>
>>> my forms.py looks like
>>>
>>> class MyCustomLoginForm(forms.Form):
>>>   """A login form for the customer model"""
>>>   email = forms.EmailField(
>>> label=('Your email address'),
>>> required=True)
>>>   password = forms.CharField(
>>> label=('Your password'),
>>> widget=forms.PasswordInput,
>>> required=True)
>>>
>>>   def clean(self):
>>> """If the user is valid and active then auth them & return the
>>> clean_data"""
>>> clean_data = self.cleaned_data
>>> try:
>>>   # authenticate the details
>>>   user = authenticate(
>>>   username=clean_data['email'],
>>>   password=clean_data['password'**])
>>>   if user and user.is_active:
>>>   self.user = user
>>>   return clean_data
>>> except (KeyError, AttributeError):
>>>   pass
>>> raise forms.ValidationError(('**Incorrect Password'))
>>>
>>> views.py looks like
>>> class LoginView(FormView):
>>> """Give a view to login"""
>>> form_class = MyCustomLoginForm
>>>   template_name = 'login.html'
>>>   success_url = reverse ('orglv')
>>>
>>> def get_success_url(self):
>>>   return reverse ('orglv')
>>>
>>> def form_valid(self, form):
>>>   """ if the form is valid, then log the user in"""
>>>   login(self.request, form.user)
>>>   return HttpResponseRedirect(self.get_**success_url())
>>>
>>> backends.py looks like
>>>
>>>
>>> class EmailOrUsernameModelBackend(**object):
>>> def authenticate(self, username=None, password=None):
>>> print(username)
>>> print(password)
>>> try:
>>>  user = Heating_User.objects.get(**email=username)
>>>  print(user.username)
>>>  print(user.password)
>>>  if user.check_password(password):
>>> print("password ok")
>>>  return user
>>> except Heating_User.DoesNotExist:
>>>  print("crap")
>>> return None
>>>
>>> def get_user(self, user_id):
>>> try:
>>> return Heating_User.objects.get(pk=**user_id)
>>> except User.DoesNotExist:
>>> return None
>>>
>>> and my login.html looks like
>>>
>>>{% extends "base.html" %}
>>>
>>> {% block title %}Login{% endblock title %}
>>>
>>> {% block content %}
>>> 
>>> {% csrf_token %}
>>> {{ form.as_p }}
>>> login
>>> 
>>> 
>>> {% endblock content %}
>>>
>>>
>>>
>>> and my urls.py lo

Re: CBVs and logging a user

2013-06-03 Thread tony gair
my URLS_CONF points to my urls.py in my main project directory. The error 
only once I press the login button, the form is validated, the user 
then(correctly ) is authenticated then it fails with the error when I try 
to redirect it to a view.

On Monday, June 3, 2013 2:45:09 PM UTC, tony gair wrote:
>
>
> I'm getting an error
>
> Request URL: http://127.0.0.1:8000/heating/login/?next=/heating/orglv/
> Django Version: 1.5.1
> Exception Type: ImproperlyConfigured
> Exception Value: 
> The included urlconf main.urls doesn't have any patterns in it
>
> my login form and view has been modified to work off email and password 
> rather than username and password
>
>
> my forms.py looks like
>
> class MyCustomLoginForm(forms.Form):
>   """A login form for the customer model"""
>   email = forms.EmailField(
> label=('Your email address'),
> required=True)
>   password = forms.CharField(
> label=('Your password'),
> widget=forms.PasswordInput,
> required=True)
>  
>   def clean(self):
> """If the user is valid and active then auth them & return the 
> clean_data"""
> clean_data = self.cleaned_data
> try:
>   # authenticate the details
>   user = authenticate(
>   username=clean_data['email'],
>   password=clean_data['password'])
>   if user and user.is_active:
>   self.user = user
>   return clean_data
> except (KeyError, AttributeError):
>   pass
> raise forms.ValidationError(('Incorrect Password'))
>
> views.py looks like
> class LoginView(FormView):
> """Give a view to login"""
> form_class = MyCustomLoginForm
>   template_name = 'login.html'
>   success_url = reverse ('orglv')
>
> def get_success_url(self):
>   return reverse ('orglv')
>  
> def form_valid(self, form):
>   """ if the form is valid, then log the user in"""
>   login(self.request, form.user)
>   return HttpResponseRedirect(self.get_success_url())
>
> backends.py looks like
>
>
> class EmailOrUsernameModelBackend(object):
> def authenticate(self, username=None, password=None):
> print(username)
> print(password)
> try:
>  user = Heating_User.objects.get(email=username)
>  print(user.username)
> print(user.password)
>  if user.check_password(password):
> print("password ok")
> return user
> except Heating_User.DoesNotExist:
>  print("crap")
> return None
>
> def get_user(self, user_id):
> try:
> return Heating_User.objects.get(pk=user_id)
> except User.DoesNotExist:
> return None
>
> and my login.html looks like
>
>{% extends "base.html" %}
>
> {% block title %}Login{% endblock title %}
>
> {% block content %}
> 
> {% csrf_token %}
> {{ form.as_p }}
> login
> 
> 
> {% endblock content %}
>
>
>
> and my urls.py looks like
>
> urlpatterns = patterns('',
> url(regex=r'login/$',
> view=LoginView.as_view(),
> name="login"
> ), 
>  
>
>
> has anyone any ideas?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




CBVs and logging a user

2013-06-03 Thread tony gair

I'm getting an error

Request URL: http://127.0.0.1:8000/heating/login/?next=/heating/orglv/
Django Version: 1.5.1
Exception Type: ImproperlyConfigured
Exception Value: 
The included urlconf main.urls doesn't have any patterns in it

my login form and view has been modified to work off email and password 
rather than username and password


my forms.py looks like

class MyCustomLoginForm(forms.Form):
  """A login form for the customer model"""
  email = forms.EmailField(
label=('Your email address'),
required=True)
  password = forms.CharField(
label=('Your password'),
widget=forms.PasswordInput,
required=True)
 
  def clean(self):
"""If the user is valid and active then auth them & return the 
clean_data"""
clean_data = self.cleaned_data
try:
  # authenticate the details
  user = authenticate(
  username=clean_data['email'],
  password=clean_data['password'])
  if user and user.is_active:
  self.user = user
  return clean_data
except (KeyError, AttributeError):
  pass
raise forms.ValidationError(('Incorrect Password'))

views.py looks like
class LoginView(FormView):
"""Give a view to login"""
form_class = MyCustomLoginForm
  template_name = 'login.html'
  success_url = reverse ('orglv')

def get_success_url(self):
  return reverse ('orglv')
 
def form_valid(self, form):
  """ if the form is valid, then log the user in"""
  login(self.request, form.user)
  return HttpResponseRedirect(self.get_success_url())

backends.py looks like


class EmailOrUsernameModelBackend(object):
def authenticate(self, username=None, password=None):
print(username)
print(password)
try:
 user = Heating_User.objects.get(email=username)
 print(user.username)
print(user.password)
 if user.check_password(password):
print("password ok")
return user
except Heating_User.DoesNotExist:
 print("crap")
return None

def get_user(self, user_id):
try:
return Heating_User.objects.get(pk=user_id)
except User.DoesNotExist:
return None

and my login.html looks like

   {% extends "base.html" %}

{% block title %}Login{% endblock title %}

{% block content %}

{% csrf_token %}
{{ form.as_p }}
login


{% endblock content %}



and my urls.py looks like

urlpatterns = patterns('',
url(regex=r'login/$',
view=LoginView.as_view(),
name="login"
), 
 


has anyone any ideas?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: django , python and ides

2013-06-03 Thread tony gair
Got to say that this looks very promising. Theres also a Django plugin too. 
dddjjjannnggooo!


On Saturday, June 1, 2013 9:01:00 PM UTC, Doug S wrote:
>
> Hey I just ran into a new opensource Python IDE that looks interesting 
> that wasn't around when I commited to Aptana
> Ninja-ide 
> http://www.ninja-ide.org/
> review at:
> http://yatharthrock.blogspot.com/2013/01/ninja.html
>
> Has anyone used this yet?
>
>
>
> On Sat, Jun 1, 2013 at 4:56 PM, Doug Snyder 
> > wrote:
>
>> one free one on LInux I'd avoid is SPE IDE - Stani's Python Editor
>> It's just too old and in the dark ages
>> I had a lot of problems with encodings and white space/indentation 
>> nightmares when taking my code from it to other editors
>>
>> If you go with a simple text editor on Linux try Kate,
>> its got some minimal Python functionality built in like code coloring and 
>> intelligent indentation
>>  
>>
>> On Sat, Jun 1, 2013 at 4:46 PM, Doug Snyder 
>> > wrote:
>>
>>> I use an IDE called Aptana Studio 3 and like it.
>>> I can't say that I've tried a lot of IDEs and I tend to get more 
>>> opinionated about programming languages and technologies than editors
>>> but when I got into Django I looked at some options and found Aptana to 
>>> be the most full featured free and platform independent option that I could 
>>> dig up. Its meant to be a web development IDE so it has some nice 
>>> HTML/CSS/JavaScript/JQuery niceities like code coloring, code completion 
>>> and things ( which helps me get through the design and onto the important 
>>> stuff: Django ). Aptana is built on top of PyDev, the python plugin for 
>>> Eclipse ( which has been an opensource standard IDE for a good long time ), 
>>> so its got everything python from PyDev and then has a few Django 
>>> conveniences built in too, like some common command line django commands 
>>> available from the IDE's GUI, and a (i)python shell that loads up your 
>>> django environment and lets you do stuff like play with your models to get 
>>> them working before you add in extended admin functionality for them or 
>>> cook up a proper web interface. 
>>> One complaint I have with it is that its a little hard to work with 
>>> Aptana Django projects if you are developing them on multiple computers 
>>> because the project profile has hard coded paths. The work around is to 
>>> ignore them in your version control. One the first computer you start the 
>>> project with, Aptana and PyDev will create well formed project meta data 
>>> file ( one for each ). You manually copy the new computer and manually edit 
>>> the hidden files and change the file paths in the XML to fit the different 
>>> file system. It could be worse and I'll probably stop complaining once I 
>>> write a script to do it for me.
>>> All around Aptana offers a lot.
>>> I'm believe in simplicity when it comes to programming
>>> When it comes to IDEs I believe in convenience.
>>>
>>>
>>> On Sat, Jun 1, 2013 at 12:57 PM, Jacky Tedy 
>>> > wrote:
>>>
 I just use Vim

 -- 
 You received this message because you are subscribed to the Google 
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send 
 an email to django-users...@googlegroups.com .
 To post to this group, send email to 
 django...@googlegroups.com
 .
 Visit this group at http://groups.google.com/group/django-users?hl=en.
 For more options, visit https://groups.google.com/groups/opt_out.
  
  

>>>
>>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




django , python and ides

2013-05-31 Thread tony gair
Python and Django are not my first languages and currently I am using it 
like I would a compiled language inside gedit on debian wheezy. I was 
actually quite surprised to find a lot of people using it on windows and 
macs when I went to my local python user group but enough digression!.
 I was wondering if anyone using debian wheezy can recommend a nice ide 
(hopefully opensource but if not then relatively inexpenisive) for django 
and python?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




CBVs and using existing forms for user authentication etc

2013-05-31 Thread tony gair

I'm trying to write my first django app using cbv's and good practice ala 2 
scoops!

(thanks for all the help so far in this forum btw!)

I have constructed the app using django braces and CBV's and have noticed 
that I can only authenticate into my app through the admin panel.

I suspect that django already has the logging mechanism for my abstractuser 
and its just a matter of declaring it in my urls, 

is this so?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: django 1.5 abstractuser / accessing information of logged on user

2013-05-30 Thread tony gair
Thanks for the post Tom, I notice that the FormMixin class is from 
django.views.generic.edit and I am confused to how to use it so I gave it a 
try with
#views.py
class PremisesUpdateView(LoginRequiredMixin, FormMixin):
form_class = PremisesForm 
model = Premises
success_url = reverse_lazy('premlv')
def get_form_kwargs(self):
kwargs = super(PremisesUpdateView, self).get_form_kwargs()
kwargs['heating_user'] = self.request.user
return kwargs
#forms.py
class HeatingUserForm ( forms.ModelForm):

def __init__(self, *args, **kwargs):
self.user=kwargs.pop('heating_user')
super(HeatingUserForm, self).__init__(*args, **kwargs)
if self.user.is_superuser:
self.fields['premises'].queryset = Premises.objects.all() 
elif self.user.is_staff:
self.fields['premises'].queryset = 
Premises.objects.filter(organisation=self.user.organisation)
else:
self.fields['premises'].queryset = 
Premises.objects.filter(id=self.user.premises)
 
#premises = CustomModelChoiceField(queryset=Premises.objects.all())
#organisation = CustomModelChoiceField(queryset=Organisation.objects.all())
class Meta:
model=Heating_User
fields = [ 'username', 'password', 'first_name', 'last_name', 
'email', 'is_staff', 'is_active', 'date_joined', 'jobtitle', 
'organisation', 'premises' ]

however a problem now occurs with my urls.py  , because not i get an error 
'type object 'PremisesCreateView' has no attribute 'as_view'
#urls.py
 ),
url(
regex=r'premuv/(?P\d+)/$',
view=PremisesUpdateView.as_view(),
name="premuv"
),
do you know what I would substitute as_view() for ,

thanks for the grounding in these CBV, I am using them ala 2 scoops of 
django!

On Thursday, 30 May 2013 11:14:27 UTC, Tom Evans wrote:
>
> On Thu, May 30, 2013 at 9:57 AM, tony gair > 
> wrote: 
> > 
> > I am using CBV / django braces for authentication. My user authorisation 
> > model inherits abstractuser and adds a few fields which are foreign keys 
> to 
> > two other models organisation and premises. 
> > 
> > When a form initialises I want to be able to examine the details of the 
> user 
> > logged in , look to see if they are a is_superuser  or is_staff and 
> occupy 
> > my organisation and premises form fields accordingly using the values 
> stored 
> > as foreign keys in the logged on and authenticated user. 
> > 
> > My main problem at the moment is that I get a KeyError for the line 
> > 'self.user=kwargs.pop('user')' centered on 'user' 
> > 
> > 
> > #heating/forms.py 
> > from django import forms 
> > from .models import Organisation, Premises,  Heating_User, Room, Heater 
> > 
> > class HeatingUserForm ( forms.ModelForm): 
> > 
> >   def __init__(self, *args, **kwargs): 
> > self.user=kwargs.pop('User') 
> > super(HeatingUserForm, self).__init__(*args, **kwargs) 
> > if self.user.is_superuser: 
> > self.fields['premises'].queryset = Premises.objects.all() 
> > elif self.user.is_staff: 
> > self.fields['premises'].queryset = 
> > Premises.objects.filter(organisation=self.user.organisation) 
> > else: 
> > self.fields['premises'].queryset = 
> > Premises.objects.filter(id=self.user.premises) 
> > 
> > 
> > #models.py 
> > from django.conf import settings 
> > from django.core.urlresolvers import reverse 
> > from django.db import models 
> > from django.contrib.auth.models import AbstractUser 
> > 
> > class Heating_User (AbstractUser): 
> >   jobtitle = models.CharField(max_length=255) 
> >   organisation = models.ForeignKey(Organisation, null=True) 
> >   premises = models.ForeignKey(Premises, null= True) 
> > def __unicode__(self): 
> > return self.username 
> > def get_absolute_url(self): 
> > return reverse('users-detail', kwargs={'pk':self.pk}) 
> > #end of files 
> > 
> > 
> > can anyone see where I am going wrong here? 
> > 
>
> 'user' is not an argument that is supplied to every form that is 
> initialised, I was trying to explain this to you yesterday. 
>
> Yesterday you said are using a CBV. A CBV that deals with forms 
> probably uses the FormMixin to provide it's form handling: 
>
>
> https://docs.djangoproject.com/en/1.5/ref/class-based-views/mixins-editing/#django.views.generic.edit.FormMixin
>  
>
> FormMixin defines various functions and attributes on the class, which 
> you can customise in your derived version of the class to give 
> specialis

Re: django 1.5 abstractuser / accessing information of logged on user

2013-05-30 Thread tony gair
Thanks for the post Tom, I notice that the FormMixin class is from 
django.views.generic.edit and I am confused to how to use it so I gave it a 
try with
#views.py
class PremisesUpdateView(LoginRequiredMixin, FormMixin):
form_class = PremisesForm 
model = Premises
success_url = reverse_lazy('premlv')
def get_form_kwargs(self):
kwargs = super(PremisesUpdateView, self).get_form_kwargs()
kwargs['heating_user'] = self.request.user
return kwargs
#forms.py
class PremisesUpdateView(LoginRequiredMixin, FormMixin):
form_class = PremisesForm 
model = Premises
success_url = reverse_lazy('premlv')
def get_form_kwargs(self):
kwargs = super(PremisesUpdateView, self).get_form_kwargs()
kwargs['heating_user'] = self.request.user
return kwargs

however a problem now occurs with my urls.py  , because not i get an error 
'type object 'PremisesCreateView' has no attribute 'as_view'
#urls.py
 ),
url(
regex=r'premuv/(?P\d+)/$',
view=PremisesUpdateView.as_view(),
name="premuv"
),
do you know what I would substitute as_view() for ,

thanks for the grounding in these CBV, I am using them ala 2 scoops of 
django!

On Thursday, 30 May 2013 11:14:27 UTC, Tom Evans wrote:
>
> On Thu, May 30, 2013 at 9:57 AM, tony gair > 
> wrote: 
> > 
> > I am using CBV / django braces for authentication. My user authorisation 
> > model inherits abstractuser and adds a few fields which are foreign keys 
> to 
> > two other models organisation and premises. 
> > 
> > When a form initialises I want to be able to examine the details of the 
> user 
> > logged in , look to see if they are a is_superuser  or is_staff and 
> occupy 
> > my organisation and premises form fields accordingly using the values 
> stored 
> > as foreign keys in the logged on and authenticated user. 
> > 
> > My main problem at the moment is that I get a KeyError for the line 
> > 'self.user=kwargs.pop('user')' centered on 'user' 
> > 
> > 
> > #heating/forms.py 
> > from django import forms 
> > from .models import Organisation, Premises,  Heating_User, Room, Heater 
> > 
> > class HeatingUserForm ( forms.ModelForm): 
> > 
> >   def __init__(self, *args, **kwargs): 
> > self.user=kwargs.pop('User') 
> > super(HeatingUserForm, self).__init__(*args, **kwargs) 
> > if self.user.is_superuser: 
> > self.fields['premises'].queryset = Premises.objects.all() 
> > elif self.user.is_staff: 
> > self.fields['premises'].queryset = 
> > Premises.objects.filter(organisation=self.user.organisation) 
> > else: 
> > self.fields['premises'].queryset = 
> > Premises.objects.filter(id=self.user.premises) 
> > 
> > 
> > #models.py 
> > from django.conf import settings 
> > from django.core.urlresolvers import reverse 
> > from django.db import models 
> > from django.contrib.auth.models import AbstractUser 
> > 
> > class Heating_User (AbstractUser): 
> >   jobtitle = models.CharField(max_length=255) 
> >   organisation = models.ForeignKey(Organisation, null=True) 
> >   premises = models.ForeignKey(Premises, null= True) 
> > def __unicode__(self): 
> > return self.username 
> > def get_absolute_url(self): 
> > return reverse('users-detail', kwargs={'pk':self.pk}) 
> > #end of files 
> > 
> > 
> > can anyone see where I am going wrong here? 
> > 
>
> 'user' is not an argument that is supplied to every form that is 
> initialised, I was trying to explain this to you yesterday. 
>
> Yesterday you said are using a CBV. A CBV that deals with forms 
> probably uses the FormMixin to provide it's form handling: 
>
>
> https://docs.djangoproject.com/en/1.5/ref/class-based-views/mixins-editing/#django.views.generic.edit.FormMixin
>  
>
> FormMixin defines various functions and attributes on the class, which 
> you can customise in your derived version of the class to give 
> specialised effects. The one you'll need to change in order to pass 
> user to the form constructor is get_form_kwargs(). You will want to do 
> something like this: 
>
> class MyClassBasedView(UpdateView): 
> form_class = HeatingUserForm 
> def get_form_kwargs(self): 
> kwargs = super(MyClassBasedView, self).get_form_kwargs() 
> kwargs['user'] = self.request.user 
> return kwargs 
>
> Then, when your class based view instantiates your form, it will 
> provide the correct arguments. 
>
> Cheers 
>
> Tom 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: linking the logged in user to other models to filter query sets -( noobie )

2013-05-30 Thread tony gair
with the line
self.user = kwargs.pop('user')

do I need to import anything to access that the value 'user' ?
 
On Wednesday, 29 May 2013 15:16:32 UTC, Tom Evans wrote:
>
> On Wed, May 29, 2013 at 3:29 PM, tony gair > 
> wrote: 
> > 
> > 
> > I've done a basic django app with a user which contains an organisation 
> and 
> > premises foreign key inside the user model which has been inherited 
> using 
> > the features of django 1.5. 
> > 
> > I use the organisation id and premises id inside other models which I 
> would 
> > like to present themselves providing they are the same. 
> > 
> > I have tried to closely follow the 'two scoops of django approach' in 
> that I 
> > use a CBV with django braces approach to show my models. 
> > 
> > It is very important for me only to show the models in the views which 
> use 
> > either the organisation id or premises id. 
> > 
> > At the moment in my  forms.py for my  user it looks like 
> > 
> >  
> > #forms.py 
> > class HeatingUserForm ( forms.ModelForm): 
> > 
> > premises = CustomModelChoiceField(queryset=Premises.objects.all()) 
> > organisation = 
> CustomModelChoiceField(queryset=Organisation.objects.all()) 
> > class Meta: 
> > model=Heating_User 
> > fields = [ 'username', 'password', 'first_name', 'last_name', 
> > 'email', 'is_staff', 'is_active', 'date_joined', 'jobtitle', 
> 'organisation', 
> > 'premises' ] 
> > 
> > *** 
> > 
> > Unless the user is a super user, I want the organisation to be 
> restricted to 
> > the organisation that the logged in user is of the same . The premises 
> > should be restricted to those premises that have the same id as the 
> logged 
> > in user. 
> > 
> > Can anyone tell me how this is done? 
> > 
> > :) 
> > 
>
> You want to do different things in the form based upon the current 
> user, so the first step is to require that a user object is passed to 
> the form's __init__ method. Then, you simply manipulate the queryset 
> attributes on the desired fields after calling the super class' 
> __init__ method. 
>
> Also, if premises and organisation are foreign key fields, as it 
> seems, you don't need to declare the fields at all: 
>
> class HeatingUserForm (forms.ModelForm): 
> def __init__(self, *args, **kwargs): 
> self.user = kwargs.pop('user') 
> super(HeatingUserForm, self).__init__(*args, **kwargs) 
> if self.user.is_superuser: 
> self.fields['premises'].queryset = Premises.objects.all() 
> self.fields['organisation'].queryset = 
> Organisation.objects.all() 
> else: 
> self.fields['premises'].queryset = 
> Premises.objects.filter(users=self.user) 
> self.fields['organisation'].queryset = 
> Organisation.objects.filter(users=self.user) 
> class Meta: 
> model=Heating_User 
> fields = [ … ] 
>
> You could also do some additional cleanup work, if the number of 
> choices for either of those two fields is exactly one, you could 
> replace the widget on the form field with a hidden input, so that you 
> do not display a pointless control (OTOH, it may not be pointless). 
>
> Cheers 
>
> Tom 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




django 1.5 abstractuser / accessing information of logged on user

2013-05-30 Thread tony gair

I am using CBV / django braces for authentication. My user authorisation 
model inherits abstractuser and adds a few fields which are foreign keys to 
two other models organisation and premises.

When a form initialises I want to be able to examine the details of the 
user logged in , look to see if they are a is_superuser  or is_staff and 
occupy my organisation and premises form fields accordingly using the 
values stored as foreign keys in the logged on and authenticated user. 

My main problem at the moment is that I get a KeyError for the line 
'self.user=kwargs.pop('user')' centered on 'user'


#heating/forms.py
from django import forms
from .models import Organisation, Premises,  Heating_User, Room, Heater

class HeatingUserForm ( forms.ModelForm):

  def __init__(self, *args, **kwargs):
self.user=kwargs.pop('User')
super(HeatingUserForm, self).__init__(*args, **kwargs)
if self.user.is_superuser:
self.fields['premises'].queryset = Premises.objects.all() 
elif self.user.is_staff:
self.fields['premises'].queryset = 
Premises.objects.filter(organisation=self.user.organisation)
else:
self.fields['premises'].queryset = 
Premises.objects.filter(id=self.user.premises)
 

#models.py
from django.conf import settings
from django.core.urlresolvers import reverse
from django.db import models
from django.contrib.auth.models import AbstractUser

class Heating_User (AbstractUser):
  jobtitle = models.CharField(max_length=255)
  organisation = models.ForeignKey(Organisation, null=True)
  premises = models.ForeignKey(Premises, null= True)
def __unicode__(self):
return self.username
def get_absolute_url(self):
return reverse('users-detail', kwargs={'pk':self.pk})
#end of files

 
can anyone see where I am going wrong here?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: linking the logged in user to other models to filter query sets -( noobie )

2013-05-29 Thread tony gair
I think my first post was a bit messy and I left some information out
I have an organisation as a foreign key contained in my abstact user object 
which is Heating_User. The premises also contains the organisation as a 
foreign key. What I am looking to do on my premises view is to filter the 
premises so that the organisation is the same as that for the logged in 
user. Although my model does include the premises id I want it so there is 
a organisation wide flag that would list all the premises if that flag was 
set. The superuser flag I (oh my that looks really useful). I think you 
have probably told me what I need to know but I'm not sure. I guess what I 
am asking in addition is how do I access the logged in user organisation 
foreign key so that I can filter the query? 

I hope that makes sense, I am quite new to this, but very enthused!!

On Wednesday, 29 May 2013 15:16:32 UTC, Tom Evans wrote:
>
> On Wed, May 29, 2013 at 3:29 PM, tony gair > 
> wrote: 
> > 
> > 
> > I've done a basic django app with a user which contains an organisation 
> and 
> > premises foreign key inside the user model which has been inherited 
> using 
> > the features of django 1.5. 
> > 
> > I use the organisation id and premises id inside other models which I 
> would 
> > like to present themselves providing they are the same. 
> > 
> > I have tried to closely follow the 'two scoops of django approach' in 
> that I 
> > use a CBV with django braces approach to show my models. 
> > 
> > It is very important for me only to show the models in the views which 
> use 
> > either the organisation id or premises id. 
> > 
> > At the moment in my  forms.py for my  user it looks like 
> > 
> >  
> > #forms.py 
> > class HeatingUserForm ( forms.ModelForm): 
> > 
> > premises = CustomModelChoiceField(queryset=Premises.objects.all()) 
> > organisation = 
> CustomModelChoiceField(queryset=Organisation.objects.all()) 
> > class Meta: 
> > model=Heating_User 
> > fields = [ 'username', 'password', 'first_name', 'last_name', 
> > 'email', 'is_staff', 'is_active', 'date_joined', 'jobtitle', 
> 'organisation', 
> > 'premises' ] 
> > 
> > *** 
> > 
> > Unless the user is a super user, I want the organisation to be 
> restricted to 
> > the organisation that the logged in user is of the same . The premises 
> > should be restricted to those premises that have the same id as the 
> logged 
> > in user. 
> > 
> > Can anyone tell me how this is done? 
> > 
> > :) 
> > 
>
> You want to do different things in the form based upon the current 
> user, so the first step is to require that a user object is passed to 
> the form's __init__ method. Then, you simply manipulate the queryset 
> attributes on the desired fields after calling the super class' 
> __init__ method. 
>
> Also, if premises and organisation are foreign key fields, as it 
> seems, you don't need to declare the fields at all: 
>
> class HeatingUserForm (forms.ModelForm): 
> def __init__(self, *args, **kwargs): 
> self.user = kwargs.pop('user') 
> super(HeatingUserForm, self).__init__(*args, **kwargs) 
> if self.user.is_superuser: 
> self.fields['premises'].queryset = Premises.objects.all() 
> self.fields['organisation'].queryset = 
> Organisation.objects.all() 
> else: 
> self.fields['premises'].queryset = 
> Premises.objects.filter(users=self.user) 
> self.fields['organisation'].queryset = 
> Organisation.objects.filter(users=self.user) 
> class Meta: 
> model=Heating_User 
> fields = [ … ] 
>
> You could also do some additional cleanup work, if the number of 
> choices for either of those two fields is exactly one, you could 
> replace the widget on the form field with a hidden input, so that you 
> do not display a pointless control (OTOH, it may not be pointless). 
>
> Cheers 
>
> Tom 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




linking the logged in user to other models to filter query sets -( noobie )

2013-05-29 Thread tony gair


I've done a basic django app with a user which contains an organisation and 
premises foreign key inside the user model which has been inherited using 
the features of django 1.5.

I use the organisation id and premises id inside other models which I would 
like to present themselves providing they are the same.

I have tried to closely follow the 'two scoops of django approach' in that 
I use a CBV with django braces approach to show my models.

It is very important for me only to show the models in the views which use 
either the organisation id or premises id.

At the moment in my  forms.py for my  user it looks like


#forms.py
class HeatingUserForm ( forms.ModelForm):

premises = CustomModelChoiceField(queryset=Premises.objects.all())
organisation = CustomModelChoiceField(queryset=Organisation.objects.all())
class Meta:
model=Heating_User
fields = [ 'username', 'password', 'first_name', 'last_name', 
'email', 'is_staff', 'is_active', 'date_joined', 'jobtitle', 
'organisation', 'premises' ]

***

Unless the user is a super user, I want the organisation to be restricted 
to the organisation that the logged in user is of the same . The premises 
should be restricted to those premises that have the same id as the logged 
in user. 

Can anyone tell me how this is done?

:)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




listing objects in a html file

2013-05-28 Thread tony gair


This file is used to print out the name of the premises with an update link 
, however I wanted to add a list of premises with the in_use flag set to 
false. 
Can anyone tell me what I am doing wrong?


{% extends "base.html" %}

{% block content %}
Premises

{% unusedpremises = [] %}
{% for premises in object_list %}
{% if premises.in_use %}
{{ premises.name }}  Update   
 
{% else unusedpremises.add(premises) %}
{% endif %}
{% endfor %}

Unused Premises

{% for premises in unusedpremises %}
{{ premises.name }}  Update  
%nbsp 
{% endif %}
{% endfor %}

{% endblock %}

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




newbie- delete confirmation

2013-05-16 Thread tony gair

I'm making a cbv with django braces

I'm wanting to delete a record with a confirm form , does anyone know of an 
exampple to show me how to do this

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.