Re: I18N and caching: page don't change language until I press F5 in browser

2011-11-04 Thread Torsten Bronger
Hallöchen!

Salvatore Iovene writes:

> On Friday, November 4, 2011 5:31:46 PM UTC+2, Salvatore Iovene wrote:
>>
>> if hasattr(request, 'session'):
>> request.session['django_language'] = lang
>> else:
>> response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang)
>>
>
> I have solved my problem by setting the cookie unconditionally (i.e. 
> outside of that else-statement). I copied that code from 
> django.views.i18n.set_language. I wonder if that's a bug. 

Strange.  I had the very same problem, but I identified the
browser's internal caching heuristics as the problem.  If there are
no explicit caching headers in the response, the browser guesses.
Sending e.g. "Expires: ..." so that the page expires immediately
solved the problem.

(By the way, I didn't send those headers eventually.  The browser's
heuristics make the site faster in other cases, and users switch
language only seldomly.)

Tschö,
Torsten.

-- 
Torsten BrongerJabber ID: torsten.bron...@jabber.rwth-aachen.de
  or http://bronger-jmp.appspot.com

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



Re: Trouble starting new project

2011-11-04 Thread dotcomboy
Did you try "python django-admin.py startproject mysite"?

Is Python on the path?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/AkW0jKgnabsJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



admindocs app - almost, but not, working

2011-11-04 Thread lorin
I followed the instructions to activate the admindocs (https://
docs.djangoproject.com/en/dev/ref/contrib/admin/admindocs/#overview)
and now I see a link Documentation, next to Welcome, myname in the
admin, and that goes to a nice page at admin/doc. But none of the
hyperlinks go to working pages (Tags, Filters, Models, Views,
Bookmarklets). E.g. Models goes to admin/models/ and results in a Page
not found (404) with a very short message "The requested admin page
does not exist."

Using the development server.

Any ideas?

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



Re: Site Administration Page

2011-11-04 Thread Jesramz
Is your url pointing to (http://127.0.0.1:8080/admin/)  ?

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



Re: Django class based views - not keen - anyone else??

2011-11-04 Thread Kurtis Mullins
Hey Cal,

Yeah the documentation is a bit lacking. It's kinda difficult to put the
pieces together. But once you learn how to use them -- they're pretty
awesome and powerful. It does seem a little difficult to deviate away from
the box at first, but once you understand how they work -- it's pretty
straightforward. Sometimes, you just have to think outside of the box :)

On Fri, Nov 4, 2011 at 6:36 PM, Cal Leeming [Simplicity Media Ltd] <
cal.leem...@simplicitymedialtd.co.uk> wrote:

> Hey all,
>
> I took a look through some of the documentation for class based views - and
> my first reaction was "Eww.".
>
> Imho, it looks much like the "admin section" customization stuff, and
> would quickly become a pain to work with if you deviate away from 'the box'.
>
> This comes from me having absolutely no experience of using class based
> views - just from what I've seen in the documentation and examples etc. (my
> background - 2 years of django exp, 6 years-ish python).
>
> It'd be good to hear other peoples thought on this - from both sides of
> the fence!
>
> Cal
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Furbee
No worries. Wow, I've got some interesting results. I am pretty sure the
ModelForm class has a bug in it that it is not looking at the secondary
database with the using() method. It is a bug in the foreign reference
fields only, though.

I set up tables in my default database, and in an extra database named
staff, which is set up in settings.py.

In default DB:
n_test_staff
username;nics_group
"tsamuel";1

n_nics_groups
n_group_number;n_group_name
1;"Group1"
2;"Group2"

In staff DB:
n_test_staff
username;nics_group
"tsamuel";2 (Notice tsamuel in group 2 in this DB)

n_nics_groups
n_group_number;n_group_name
1;"Staff1"
2;"Staff2"

In the models, wrote __unicode__(self): method to show the groups.


Here's something strange:
>>> from models import Staff, NICSGroupType
>>> from django.forms import ModelForm
>>> class StaffForm(ModelForm):
... class Meta:
... model = Staff
...
>>> staff = Staff.objects.using('staff').get(username='tsamuel')
>>> print staff
tsamuel 
>>> form = StaffForm(instance=staff)
>>> print form
Username:
Nics group:
-
2: Group2
1: Group1


Notice this ModelForm is getting the Staff data from the 'staff' database,
but is getting the reference n_nics_groups data from the default database's
n_nics_groups table. Remember in staff tsamuel was part of group 2, which
is the selected option, but the label is Group2 instead of Staff2, which is
the value in n_nics_groups table in the 'staff' database.


Then I tried deleting the default database n_test_staff table to verify:
>>> from models import Staff, NICSGroupType
>>> from django.forms import *
>>> class StaffForm(ModelForm):
... class Meta:
... model = Staff
...
>>> staff = Staff.objects.using('staff').get(username='tsamuel')
>>> form = StaffForm(instance=staff)
>>> print form
Username:
Nics group:
-
2: Group2
1: Group1




Now, if I delete the default database's n_nics_groups table also, so it
should all be using the 'staff' database, the only place n_test_staff and
n_nics_groups exist now.
>>> from models import Staff, NICSGroupType
>>> from django.forms import *
>>> class StaffForm(ModelForm):
... class Meta:
... model = Staff
...
>>> staff = Staff.objects.using('staff').get(username='tsamuel')
>>> print staff
tsamuel 
>>> form = StaffForm(instance=staff)
>>> print form
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.5/site-packages/django/utils/encoding.py", line
27, in __str__
return self.__unicode__().encode('utf-8')
  File "/usr/lib/python2.5/site-packages/django/forms/forms.py", line 95,
in __unicode__
return self.as_table()
  File "/usr/lib/python2.5/site-packages/django/forms/forms.py", line 217,
in as_table
errors_on_separate_row = False)
  File "/usr/lib/python2.5/site-packages/django/forms/forms.py", line 180,
in _html_output
'field': unicode(bf),
  File "/usr/lib/python2.5/site-packages/django/forms/forms.py", line 408,
in __unicode__
return self.as_widget()
  File "/usr/lib/python2.5/site-packages/django/forms/forms.py", line 439,
in as_widget
return widget.render(name, self.value(), attrs=attrs)
  File "/usr/lib/python2.5/site-packages/django/forms/widgets.py", line
516, in render
options = self.render_options(choices, [value])
  File "/usr/lib/python2.5/site-packages/django/forms/widgets.py", line
533, in render_options
for option_value, option_label in chain(self.choices, choices):
  File "/usr/lib/python2.5/site-packages/django/forms/models.py", line 882,
in __iter__
for obj in self.queryset.all():
  File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line
107, in _result_iter
self._fill_cache()
  File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line
772, in _fill_cache
self._result_cache.append(self._iter.next())
  File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line
273, in iterator
for row in compiler.results_iter():
  File "/usr/lib/python2.5/site-packages/django/db/models/sql/compiler.py",
line 680, in results_iter
for rows in self.execute_sql(MULTI):
  File "/usr/lib/python2.5/site-packages/django/db/models/sql/compiler.py",
line 735, in execute_sql
cursor.execute(sql, params)
  File
"/usr/lib/python2.5/site-packages/django/db/backends/postgresql_psycopg2/base.py",
line 44, in execute
return self.cursor.execute(query, args)
DatabaseError: relation "n_nics_groups" does not exist


This seems to be a bug in the ModelForm class that is not honoring the
referenced fields that exist outside the default database. I tried
appending the using('staff') to a few different places in the StaffForm
class and also to the instance of StaffForm, but to no avail. Anybody else
see this as not a bug?

Furbee

On Fri, Nov 4, 2011 at 1:45 PM, Tabitha Samuel wrote:

> I don't mean to be spamming you like this, just thought you might be
> interested in this result:
>
> So I created the same tables (n_test_staff and 

Django class based views - not keen - anyone else??

2011-11-04 Thread Cal Leeming [Simplicity Media Ltd]
Hey all,

I took a look through some of the documentation for class based views - and
my first reaction was "Eww.".

Imho, it looks much like the "admin section" customization stuff, and would
quickly become a pain to work with if you deviate away from 'the box'.

This comes from me having absolutely no experience of using class based
views - just from what I've seen in the documentation and examples etc. (my
background - 2 years of django exp, 6 years-ish python).

It'd be good to hear other peoples thought on this - from both sides of the
fence!

Cal

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



[Problem]Site Administration Page

2011-11-04 Thread Nora Youssef
Hi

I tried to follow the steps included here
http://www.jetbrains.com/pycharm/quickstart/django_guide.html
but i stopped at running the "Site Administration page" when i run the
application it produces
Congratulations It Worked ! Page actually it's the start page it
appears when i tested the server at first time
how can i get the Site administration page do i miss any
configuration ?
any help

Thanks in advance.

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



Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Tabitha Samuel
I don't mean to be spamming you like this, just thought you might be
interested in this result:

So I created the same tables (n_test_staff and n_nics_groups) in the
default gibbs database. I removed the using part in the form statement
(form = StaffForm(instance = Staff.objects.using('gold').get(username
=current_staff), so now it looks like form = StaffForm(instance =
Staff.objects.get(username =current_staff) and it works fine,
everything is getting displayed in the view perfectly!!

Problem is that those two tables have to live in the other database -
gold. Not sure how to proceed from here. I may just have to remove the
foreign key reference for the time being and update it manually in the
code, until a fix can be found for this.

Tabitha

On Nov 4, 3:19 pm, Tabitha Samuel  wrote:
> I found this patch for the raw function (https://
> code.djangoproject.com/attachment/ticket/13805/manager.patch), because
> according to this ticket (https://code.djangoproject.com/ticket/
> 13805), .raw does not work in a multi db env. So this is what I have:
>
> in django/db/models/manager.py, I have created a new function:
> def raw(self, raw_query, params=None, using=None, *args, **kwargs):
>         if using is None:
>             using = self._db
>         print using
>         return RawQuerySet(raw_query=raw_query, model=self.model,
> params=params, using=using, *args, **kwargs)
>
> The print using returns "gold" so I know it is using this method.
>
> Now, I have
>   form = StaffForm(instance = Staff.objects.raw("SELECT s.*,
> g.n_group_name FROM n_test_staff s LEFT JOIN n_nics_groups g
> ON(g.n_group_number = s.nics_group) WHERE s.username =
> 'tsamuel'",None,"gold"))
> in my view and I am still getting the error:
> AttributeError at /staff/staffinfo
> 'RawQuerySet' object has no attribute '_meta'
>
> This is the traceback:
> Traceback:
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> core/handlers/base.py" in get_response
>   111.                         response = callback(request,
> *callback_args, **callback_kwargs)
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> contrib/auth/decorators.py" in _wrapped_view
>   23.                 return view_func(request, *args, **kwargs)
> File "/nics/a/home/tsamuel/tssandbox/gibbs/utils/decorators.py" in
> decorate
>   11.         return view_func(request, *args, **kws)
> File "/nics/a/home/tsamuel/tssandbox/gibbs/../gibbs/staff/views.py" in
> staff_info
>   156.     form = StaffForm(instance = Staff.objects.raw("SELECT s.*,
> g.n_group_name FROM n_test_staff s LEFT JOIN n_nics_groups g
> ON(g.n_group_number = s.nics_group) WHERE s.username =
> 'tsamuel'",None,"gold"))
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> forms/models.py" in __init__
>   237.             object_data = model_to_dict(instance, opts.fields,
> opts.exclude)
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> forms/models.py" in model_to_dict
>   110.     opts = instance._meta
>
> Exception Type: AttributeError at /staff/staffinfo
> Exception Value: 'RawQuerySet' object has no attribute '_meta'
>
> On Nov 4, 2:49 pm, Tabitha Samuel  wrote:
>
>
>
>
>
>
>
> > One thought I have is that the using() is messing things up. Would it
> > be possible for you to create a second non-default db, throw these two
> > tables in there and then try the same thing? If that works for you,
> > then I must have a ghost sitting in my system! :-|
>
> > On Nov 4, 2:28 pm, Furbee  wrote:
>
> > > That is very strange... I recreated this on my development system and it
> > > worked fine. I looked for Django bugs, but haven't found any related to
> > > this issue. To be clear, the table n_nics_groups definitely exists in the
> > > same database as n_test_staff, right? It does in mine because I used 
> > > python
> > > manage.py syncdb to create them from the models. If so, maybe we should 
> > > try
> > > to create a raw() query to see if the system has a bug creating the query.
> > > This should be similar:
>
> > > form = StaffForm(instance = Staff.objects.raw("SELECT s.*, g.n_group_name
> > > FROM n_test_staff s LEFT JOIN n_nics_groups g ON(g.n_group_number =
> > > s.nics_group) WHERE s.username = 'tsamuel'))
>
> > > If that throws an error, we may have a problem in the DB layer.
>
> > > Thanks,
>
> > > Furbee
>
> > > On Fri, Nov 4, 2011 at 10:29 AM, Tabitha Samuel 
> > > wrote:
>
> > > > The error that I'm getting is on the second form instantiation, that
> > > > is on the line:
>
> > > > form = StaffForm(instance = Staff.objects.using('gold').get(username =
> > > > current_staff)
> > > > where current_staff='tsamuel' for instance
>
> > > > This is the traceback of the error that I get when I do a print form
> > > > right after getting the form:
> > > > Environment:
>
> > > > Request Method: GET
> > > > Request 

Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Furbee
I guess the ModelForm must require the Meta class, sorry about that. This
is really strange behavior, but it looks like everything you've got is
correct.

Running syncdb will only create new databases/tables, it does not ALTER any
existing tables or modify any of the data. However, if you have other
models that don't have corresponding tables created, syncdb would create
those.

Furbee

On Fri, Nov 4, 2011 at 11:46 AM, Tabitha Samuel wrote:

> Yep, n_nics_groups and n_test_staff exist in the same 'gold'
> database.
>
> So when I tried:
> form = StaffForm(instance = Staff.objects.using('gold').raw("SELECT
> s.*, g.n_group_name FROM n_test_staff s LEFT JOIN n_nics_groups g
> ON(g.n_group_number = s.nics_group) WHERE s.username = 'tsamuel')"))
>I got the error:
> 'QuerySet' object has no attribute 'raw'
>
> and when I tried:
> form = StaffForm(instance = Staff.objects.raw("SELECT s.*,
> g.n_group_name FROM n_test_staff s LEFT JOIN n_nics_groups g
> ON(g.n_group_number = s.nics_group) WHERE s.username =
> 'tsamuel')")).using('gold')
> 'RawQuerySet' object has no attribute '_meta'
>
> So here is one thing, both tables (n_test_staff and n_nics_groups)
> were pre-existing, meaning I have not created them using syncdb from
> the models. They're been used by other applications within my group.
> I've just created the models that would correspond to these tables, I
> have not run syncdb on the database. I am a little hesitant to do so,
> since I don't want to change the db values and mess up other
> applications.
>
> Tabitha
>
> On Nov 4, 2:28 pm, Furbee  wrote:
> > That is very strange... I recreated this on my development system and it
> > worked fine. I looked for Django bugs, but haven't found any related to
> > this issue. To be clear, the table n_nics_groups definitely exists in the
> > same database as n_test_staff, right? It does in mine because I used
> python
> > manage.py syncdb to create them from the models. If so, maybe we should
> try
> > to create a raw() query to see if the system has a bug creating the
> query.
> > This should be similar:
> >
> > form = StaffForm(instance = Staff.objects.raw("SELECT s.*, g.n_group_name
> > FROM n_test_staff s LEFT JOIN n_nics_groups g ON(g.n_group_number =
> > s.nics_group) WHERE s.username = 'tsamuel'))
> >
> > If that throws an error, we may have a problem in the DB layer.
> >
> > Thanks,
> >
> > Furbee
> >
> > On Fri, Nov 4, 2011 at 10:29 AM, Tabitha Samuel <
> tabitha.sam...@gmail.com>wrote:
> >
> >
> >
> >
> >
> >
> >
> > > The error that I'm getting is on the second form instantiation, that
> > > is on the line:
> >
> > > form = StaffForm(instance = Staff.objects.using('gold').get(username =
> > > current_staff)
> > > where current_staff='tsamuel' for instance
> >
> > > This is the traceback of the error that I get when I do a print form
> > > right after getting the form:
> > > Environment:
> >
> > > Request Method: GET
> > > Request URL:http://watermelon.nics.utk.edu:8004/staff/staffinfo
> >
> > > Django Version: 1.3.1
> > > Python Version: 2.6.2
> > > Installed Applications:
> > > ['django.contrib.auth',
> > >  'django.contrib.contenttypes',
> > >  'django.contrib.sessions',
> > >  'django.contrib.sites',
> > >  'gibbs.quartermaster',
> > >  'gibbs.userportal',
> > >  'gibbs.reports',
> > >  'gibbs.events',
> > >  'gibbs.job_stats',
> > >  'gibbs.simulator',
> > >  'gibbs.staff']
> > > Installed Middleware:
> > > ('django.contrib.csrf.middleware.CsrfViewMiddleware',
> > >  'django.middleware.common.CommonMiddleware',
> > >  'django.contrib.csrf.middleware.CsrfResponseMiddleware',
> > >  'django.contrib.sessions.middleware.SessionMiddleware',
> > >  'django.contrib.auth.middleware.AuthenticationMiddleware')
> >
> > > Traceback:
> > > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > > core/handlers/base.py" in get_response
> > >  111. response = callback(request,
> > > *callback_args, **callback_kwargs)
> > > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > > contrib/auth/decorators.py" in _wrapped_view
> > >  23. return view_func(request, *args, **kwargs)
> > > File "/nics/a/home/tsamuel/tssandbox/gibbs/utils/decorators.py" in
> > > decorate
> > >  11. return view_func(request, *args, **kws)
> > > File "/nics/a/home/tsamuel/tssandbox/gibbs/../gibbs/staff/views.py" in
> > > staff_info
> > >  159. print form
> > > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > > utils/encoding.py" in __str__
> > >  27. return self.__unicode__().encode('utf-8')
> > > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > > forms/forms.py" in __unicode__
> > >  95. return self.as_table()
> > > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > > forms/forms.py" in as_table
> > >  217. errors_on_separate_row = False)
> > > File 

Multiple sessions per user?

2011-11-04 Thread Nan
OK, the subject doesn't *quite* describe what I need to do, but
almost.  Basically, I'd like to have

1) one "session" that expires after logout or browser close, and
applies to logged-in sessions (like the default Django session
framework using the "SESSION_EXPIRE_AT_BROWSER_CLOSE" setting)

2) one "session" that's persistent indefinitely and applies to both
anonymous and logged-in users.

The data in (2) could probably be stored directly in a cookie, but
it's pretty handy how the session framework protects one from users
editing cookies, abstracts away database storage, etc. -- and I'd
rather not have to duplicate this functionality.

Any suggestions?

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



Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Tabitha Samuel
I found this patch for the raw function (https://
code.djangoproject.com/attachment/ticket/13805/manager.patch), because
according to this ticket (https://code.djangoproject.com/ticket/
13805), .raw does not work in a multi db env. So this is what I have:

in django/db/models/manager.py, I have created a new function:
def raw(self, raw_query, params=None, using=None, *args, **kwargs):
if using is None:
using = self._db
print using
return RawQuerySet(raw_query=raw_query, model=self.model,
params=params, using=using, *args, **kwargs)

The print using returns "gold" so I know it is using this method.

Now, I have
  form = StaffForm(instance = Staff.objects.raw("SELECT s.*,
g.n_group_name FROM n_test_staff s LEFT JOIN n_nics_groups g
ON(g.n_group_number = s.nics_group) WHERE s.username =
'tsamuel'",None,"gold"))
in my view and I am still getting the error:
AttributeError at /staff/staffinfo
'RawQuerySet' object has no attribute '_meta'

This is the traceback:
Traceback:
File "/nics/a/applications/gibbs/python/site-packages_django/django/
core/handlers/base.py" in get_response
  111. response = callback(request,
*callback_args, **callback_kwargs)
File "/nics/a/applications/gibbs/python/site-packages_django/django/
contrib/auth/decorators.py" in _wrapped_view
  23. return view_func(request, *args, **kwargs)
File "/nics/a/home/tsamuel/tssandbox/gibbs/utils/decorators.py" in
decorate
  11. return view_func(request, *args, **kws)
File "/nics/a/home/tsamuel/tssandbox/gibbs/../gibbs/staff/views.py" in
staff_info
  156. form = StaffForm(instance = Staff.objects.raw("SELECT s.*,
g.n_group_name FROM n_test_staff s LEFT JOIN n_nics_groups g
ON(g.n_group_number = s.nics_group) WHERE s.username =
'tsamuel'",None,"gold"))
File "/nics/a/applications/gibbs/python/site-packages_django/django/
forms/models.py" in __init__
  237. object_data = model_to_dict(instance, opts.fields,
opts.exclude)
File "/nics/a/applications/gibbs/python/site-packages_django/django/
forms/models.py" in model_to_dict
  110. opts = instance._meta

Exception Type: AttributeError at /staff/staffinfo
Exception Value: 'RawQuerySet' object has no attribute '_meta'


On Nov 4, 2:49 pm, Tabitha Samuel  wrote:
> One thought I have is that the using() is messing things up. Would it
> be possible for you to create a second non-default db, throw these two
> tables in there and then try the same thing? If that works for you,
> then I must have a ghost sitting in my system! :-|
>
> On Nov 4, 2:28 pm, Furbee  wrote:
>
>
>
>
>
>
>
> > That is very strange... I recreated this on my development system and it
> > worked fine. I looked for Django bugs, but haven't found any related to
> > this issue. To be clear, the table n_nics_groups definitely exists in the
> > same database as n_test_staff, right? It does in mine because I used python
> > manage.py syncdb to create them from the models. If so, maybe we should try
> > to create a raw() query to see if the system has a bug creating the query.
> > This should be similar:
>
> > form = StaffForm(instance = Staff.objects.raw("SELECT s.*, g.n_group_name
> > FROM n_test_staff s LEFT JOIN n_nics_groups g ON(g.n_group_number =
> > s.nics_group) WHERE s.username = 'tsamuel'))
>
> > If that throws an error, we may have a problem in the DB layer.
>
> > Thanks,
>
> > Furbee
>
> > On Fri, Nov 4, 2011 at 10:29 AM, Tabitha Samuel 
> > wrote:
>
> > > The error that I'm getting is on the second form instantiation, that
> > > is on the line:
>
> > > form = StaffForm(instance = Staff.objects.using('gold').get(username =
> > > current_staff)
> > > where current_staff='tsamuel' for instance
>
> > > This is the traceback of the error that I get when I do a print form
> > > right after getting the form:
> > > Environment:
>
> > > Request Method: GET
> > > Request URL:http://watermelon.nics.utk.edu:8004/staff/staffinfo
>
> > > Django Version: 1.3.1
> > > Python Version: 2.6.2
> > > Installed Applications:
> > > ['django.contrib.auth',
> > >  'django.contrib.contenttypes',
> > >  'django.contrib.sessions',
> > >  'django.contrib.sites',
> > >  'gibbs.quartermaster',
> > >  'gibbs.userportal',
> > >  'gibbs.reports',
> > >  'gibbs.events',
> > >  'gibbs.job_stats',
> > >  'gibbs.simulator',
> > >  'gibbs.staff']
> > > Installed Middleware:
> > > ('django.contrib.csrf.middleware.CsrfViewMiddleware',
> > >  'django.middleware.common.CommonMiddleware',
> > >  'django.contrib.csrf.middleware.CsrfResponseMiddleware',
> > >  'django.contrib.sessions.middleware.SessionMiddleware',
> > >  'django.contrib.auth.middleware.AuthenticationMiddleware')
>
> > > Traceback:
> > > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > > core/handlers/base.py" in get_response
> > >  111.                         response = callback(request,
> > > *callback_args, 

Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Tabitha Samuel
One thought I have is that the using() is messing things up. Would it
be possible for you to create a second non-default db, throw these two
tables in there and then try the same thing? If that works for you,
then I must have a ghost sitting in my system! :-|

On Nov 4, 2:28 pm, Furbee  wrote:
> That is very strange... I recreated this on my development system and it
> worked fine. I looked for Django bugs, but haven't found any related to
> this issue. To be clear, the table n_nics_groups definitely exists in the
> same database as n_test_staff, right? It does in mine because I used python
> manage.py syncdb to create them from the models. If so, maybe we should try
> to create a raw() query to see if the system has a bug creating the query.
> This should be similar:
>
> form = StaffForm(instance = Staff.objects.raw("SELECT s.*, g.n_group_name
> FROM n_test_staff s LEFT JOIN n_nics_groups g ON(g.n_group_number =
> s.nics_group) WHERE s.username = 'tsamuel'))
>
> If that throws an error, we may have a problem in the DB layer.
>
> Thanks,
>
> Furbee
>
> On Fri, Nov 4, 2011 at 10:29 AM, Tabitha Samuel 
> wrote:
>
>
>
>
>
>
>
> > The error that I'm getting is on the second form instantiation, that
> > is on the line:
>
> > form = StaffForm(instance = Staff.objects.using('gold').get(username =
> > current_staff)
> > where current_staff='tsamuel' for instance
>
> > This is the traceback of the error that I get when I do a print form
> > right after getting the form:
> > Environment:
>
> > Request Method: GET
> > Request URL:http://watermelon.nics.utk.edu:8004/staff/staffinfo
>
> > Django Version: 1.3.1
> > Python Version: 2.6.2
> > Installed Applications:
> > ['django.contrib.auth',
> >  'django.contrib.contenttypes',
> >  'django.contrib.sessions',
> >  'django.contrib.sites',
> >  'gibbs.quartermaster',
> >  'gibbs.userportal',
> >  'gibbs.reports',
> >  'gibbs.events',
> >  'gibbs.job_stats',
> >  'gibbs.simulator',
> >  'gibbs.staff']
> > Installed Middleware:
> > ('django.contrib.csrf.middleware.CsrfViewMiddleware',
> >  'django.middleware.common.CommonMiddleware',
> >  'django.contrib.csrf.middleware.CsrfResponseMiddleware',
> >  'django.contrib.sessions.middleware.SessionMiddleware',
> >  'django.contrib.auth.middleware.AuthenticationMiddleware')
>
> > Traceback:
> > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > core/handlers/base.py" in get_response
> >  111.                         response = callback(request,
> > *callback_args, **callback_kwargs)
> > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > contrib/auth/decorators.py" in _wrapped_view
> >  23.                 return view_func(request, *args, **kwargs)
> > File "/nics/a/home/tsamuel/tssandbox/gibbs/utils/decorators.py" in
> > decorate
> >  11.         return view_func(request, *args, **kws)
> > File "/nics/a/home/tsamuel/tssandbox/gibbs/../gibbs/staff/views.py" in
> > staff_info
> >  159.     print form
> > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > utils/encoding.py" in __str__
> >  27.         return self.__unicode__().encode('utf-8')
> > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > forms/forms.py" in __unicode__
> >  95.         return self.as_table()
> > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > forms/forms.py" in as_table
> >  217.             errors_on_separate_row = False)
> > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > forms/forms.py" in _html_output
> >  180.                     'field': unicode(bf),
> > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > forms/forms.py" in __unicode__
> >  408.         return self.as_widget()
> > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > forms/forms.py" in as_widget
> >  439.         return widget.render(name, self.value(), attrs=attrs)
> > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > forms/widgets.py" in render
> >  516.         options = self.render_options(choices, [value])
> > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > forms/widgets.py" in render_options
> >  533.         for option_value, option_label in chain(self.choices,
> > choices):
> > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > forms/models.py" in __iter__
> >  882.             for obj in self.queryset.all():
> > File "/nics/a/applications/gibbs/python/site-packages_django/django/db/
> > models/query.py" in _result_iter
> >  107.                 self._fill_cache()
> > File "/nics/a/applications/gibbs/python/site-packages_django/django/db/
> > models/query.py" in _fill_cache
> >  772.
> > self._result_cache.append(self._iter.next())
> > File "/nics/a/applications/gibbs/python/site-packages_django/django/db/
> > models/query.py" in iterator
> >  273.         for row in 

Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Tabitha Samuel
Yep, n_nics_groups and n_test_staff exist in the same 'gold'
database.

So when I tried:
form = StaffForm(instance = Staff.objects.using('gold').raw("SELECT
s.*, g.n_group_name FROM n_test_staff s LEFT JOIN n_nics_groups g
ON(g.n_group_number = s.nics_group) WHERE s.username = 'tsamuel')"))
I got the error:
'QuerySet' object has no attribute 'raw'

and when I tried:
form = StaffForm(instance = Staff.objects.raw("SELECT s.*,
g.n_group_name FROM n_test_staff s LEFT JOIN n_nics_groups g
ON(g.n_group_number = s.nics_group) WHERE s.username =
'tsamuel')")).using('gold')
'RawQuerySet' object has no attribute '_meta'

So here is one thing, both tables (n_test_staff and n_nics_groups)
were pre-existing, meaning I have not created them using syncdb from
the models. They're been used by other applications within my group.
I've just created the models that would correspond to these tables, I
have not run syncdb on the database. I am a little hesitant to do so,
since I don't want to change the db values and mess up other
applications.

Tabitha

On Nov 4, 2:28 pm, Furbee  wrote:
> That is very strange... I recreated this on my development system and it
> worked fine. I looked for Django bugs, but haven't found any related to
> this issue. To be clear, the table n_nics_groups definitely exists in the
> same database as n_test_staff, right? It does in mine because I used python
> manage.py syncdb to create them from the models. If so, maybe we should try
> to create a raw() query to see if the system has a bug creating the query.
> This should be similar:
>
> form = StaffForm(instance = Staff.objects.raw("SELECT s.*, g.n_group_name
> FROM n_test_staff s LEFT JOIN n_nics_groups g ON(g.n_group_number =
> s.nics_group) WHERE s.username = 'tsamuel'))
>
> If that throws an error, we may have a problem in the DB layer.
>
> Thanks,
>
> Furbee
>
> On Fri, Nov 4, 2011 at 10:29 AM, Tabitha Samuel 
> wrote:
>
>
>
>
>
>
>
> > The error that I'm getting is on the second form instantiation, that
> > is on the line:
>
> > form = StaffForm(instance = Staff.objects.using('gold').get(username =
> > current_staff)
> > where current_staff='tsamuel' for instance
>
> > This is the traceback of the error that I get when I do a print form
> > right after getting the form:
> > Environment:
>
> > Request Method: GET
> > Request URL:http://watermelon.nics.utk.edu:8004/staff/staffinfo
>
> > Django Version: 1.3.1
> > Python Version: 2.6.2
> > Installed Applications:
> > ['django.contrib.auth',
> >  'django.contrib.contenttypes',
> >  'django.contrib.sessions',
> >  'django.contrib.sites',
> >  'gibbs.quartermaster',
> >  'gibbs.userportal',
> >  'gibbs.reports',
> >  'gibbs.events',
> >  'gibbs.job_stats',
> >  'gibbs.simulator',
> >  'gibbs.staff']
> > Installed Middleware:
> > ('django.contrib.csrf.middleware.CsrfViewMiddleware',
> >  'django.middleware.common.CommonMiddleware',
> >  'django.contrib.csrf.middleware.CsrfResponseMiddleware',
> >  'django.contrib.sessions.middleware.SessionMiddleware',
> >  'django.contrib.auth.middleware.AuthenticationMiddleware')
>
> > Traceback:
> > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > core/handlers/base.py" in get_response
> >  111.                         response = callback(request,
> > *callback_args, **callback_kwargs)
> > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > contrib/auth/decorators.py" in _wrapped_view
> >  23.                 return view_func(request, *args, **kwargs)
> > File "/nics/a/home/tsamuel/tssandbox/gibbs/utils/decorators.py" in
> > decorate
> >  11.         return view_func(request, *args, **kws)
> > File "/nics/a/home/tsamuel/tssandbox/gibbs/../gibbs/staff/views.py" in
> > staff_info
> >  159.     print form
> > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > utils/encoding.py" in __str__
> >  27.         return self.__unicode__().encode('utf-8')
> > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > forms/forms.py" in __unicode__
> >  95.         return self.as_table()
> > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > forms/forms.py" in as_table
> >  217.             errors_on_separate_row = False)
> > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > forms/forms.py" in _html_output
> >  180.                     'field': unicode(bf),
> > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > forms/forms.py" in __unicode__
> >  408.         return self.as_widget()
> > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > forms/forms.py" in as_widget
> >  439.         return widget.render(name, self.value(), attrs=attrs)
> > File "/nics/a/applications/gibbs/python/site-packages_django/django/
> > forms/widgets.py" in render
> >  516.         options = self.render_options(choices, [value])
> > File 

Re: Caching at model class level

2011-11-04 Thread Malcolm Box
On 4 November 2011 07:02, Thomas Guettler  wrote:

> Am 03.11.2011 18:42, schrieb Tom Evans:
> > On Thu, Nov 3, 2011 at 2:22 PM, Thomas Guettler  wrote:
> >> Hi,
> >>
> >> I try to reduce the number of db-queries in my app.
> >>
> >> There is a model which changes almost never. It is like a "type of
> ticket"
> >> in a trouble ticket system.
> >>
> >> On one page there are seven SQL-Queries (SELECT  FROM ticket_type
> where id=123) which of course always return
> >> the same result.
>

How are you getting 7 queries the same? Would select_related solve the
problem by doing it all in one query?

Malcolm

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



Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Furbee
That is very strange... I recreated this on my development system and it
worked fine. I looked for Django bugs, but haven't found any related to
this issue. To be clear, the table n_nics_groups definitely exists in the
same database as n_test_staff, right? It does in mine because I used python
manage.py syncdb to create them from the models. If so, maybe we should try
to create a raw() query to see if the system has a bug creating the query.
This should be similar:

form = StaffForm(instance = Staff.objects.raw("SELECT s.*, g.n_group_name
FROM n_test_staff s LEFT JOIN n_nics_groups g ON(g.n_group_number =
s.nics_group) WHERE s.username = 'tsamuel'))

If that throws an error, we may have a problem in the DB layer.

Thanks,

Furbee

On Fri, Nov 4, 2011 at 10:29 AM, Tabitha Samuel wrote:

> The error that I'm getting is on the second form instantiation, that
> is on the line:
>
> form = StaffForm(instance = Staff.objects.using('gold').get(username =
> current_staff)
> where current_staff='tsamuel' for instance
>
> This is the traceback of the error that I get when I do a print form
> right after getting the form:
> Environment:
>
>
> Request Method: GET
> Request URL: http://watermelon.nics.utk.edu:8004/staff/staffinfo
>
> Django Version: 1.3.1
> Python Version: 2.6.2
> Installed Applications:
> ['django.contrib.auth',
>  'django.contrib.contenttypes',
>  'django.contrib.sessions',
>  'django.contrib.sites',
>  'gibbs.quartermaster',
>  'gibbs.userportal',
>  'gibbs.reports',
>  'gibbs.events',
>  'gibbs.job_stats',
>  'gibbs.simulator',
>  'gibbs.staff']
> Installed Middleware:
> ('django.contrib.csrf.middleware.CsrfViewMiddleware',
>  'django.middleware.common.CommonMiddleware',
>  'django.contrib.csrf.middleware.CsrfResponseMiddleware',
>  'django.contrib.sessions.middleware.SessionMiddleware',
>  'django.contrib.auth.middleware.AuthenticationMiddleware')
>
>
> Traceback:
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> core/handlers/base.py" in get_response
>  111. response = callback(request,
> *callback_args, **callback_kwargs)
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> contrib/auth/decorators.py" in _wrapped_view
>  23. return view_func(request, *args, **kwargs)
> File "/nics/a/home/tsamuel/tssandbox/gibbs/utils/decorators.py" in
> decorate
>  11. return view_func(request, *args, **kws)
> File "/nics/a/home/tsamuel/tssandbox/gibbs/../gibbs/staff/views.py" in
> staff_info
>  159. print form
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> utils/encoding.py" in __str__
>  27. return self.__unicode__().encode('utf-8')
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> forms/forms.py" in __unicode__
>  95. return self.as_table()
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> forms/forms.py" in as_table
>  217. errors_on_separate_row = False)
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> forms/forms.py" in _html_output
>  180. 'field': unicode(bf),
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> forms/forms.py" in __unicode__
>  408. return self.as_widget()
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> forms/forms.py" in as_widget
>  439. return widget.render(name, self.value(), attrs=attrs)
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> forms/widgets.py" in render
>  516. options = self.render_options(choices, [value])
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> forms/widgets.py" in render_options
>  533. for option_value, option_label in chain(self.choices,
> choices):
> File "/nics/a/applications/gibbs/python/site-packages_django/django/
> forms/models.py" in __iter__
>  882. for obj in self.queryset.all():
> File "/nics/a/applications/gibbs/python/site-packages_django/django/db/
> models/query.py" in _result_iter
>  107. self._fill_cache()
> File "/nics/a/applications/gibbs/python/site-packages_django/django/db/
> models/query.py" in _fill_cache
>  772.
> self._result_cache.append(self._iter.next())
> File "/nics/a/applications/gibbs/python/site-packages_django/django/db/
> models/query.py" in iterator
>  273. for row in compiler.results_iter():
> File "/nics/a/applications/gibbs/python/site-packages_django/django/db/
> models/sql/compiler.py" in results_iter
>  680. for rows in self.execute_sql(MULTI):
> File "/nics/a/applications/gibbs/python/site-packages_django/django/db/
> models/sql/compiler.py" in execute_sql
>  735. cursor.execute(sql, params)
> File "/nics/a/applications/gibbs/python/site-packages_django/django/db/
> backends/util.py" in execute
>  34. return self.cursor.execute(sql, params)
> File 

Re: I18N and caching: page don't change language until I press F5 in browser

2011-11-04 Thread Salvatore Iovene
On Friday, November 4, 2011 5:31:46 PM UTC+2, Salvatore Iovene wrote:
>
> if hasattr(request, 'session'):
> request.session['django_language'] = lang
> else:
> response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang)
>

I have solved my problem by setting the cookie unconditionally (i.e. 
outside of that else-statement). I copied that code from 
django.views.i18n.set_language. I wonder if that's a bug. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/dmAVToeRYvEJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Trouble starting new project

2011-11-04 Thread Sydney Lo
I go into the folder that I would like to store my project and
successfully start up python 2.7 then I checked to see if django was
installed and it shows that I have 1.3.1 installed. So i run the
command "django-admin.py startproject mysite" it says invalid syntax.
I am using admin command prompt on windows 7.

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



Filtering generic relation with additional field

2011-11-04 Thread guardbadger
Hi all,

Appreciate some help trying to build a queryset. Im hoping I can make
this in django, without having to crack open raw sql... Here is my
setup:

class Container(models.Model):
  permissions = generic.GenericRelation(Permission)

class Item(models.Model):
  container = models.ForeignKey(Container)
  extraSetting = models.ForeignKey(ExtraSetting)

class Permission(models.Model):
  content_type = models.ForeignKey(ContentType)
  content_object = generic.GenericForeignKey()
  extraSetting =   models.ForeignKey(ExtraSetting)

class ExtraSetting(models.Model):
  

Convoluted made up example, but hopefully you can see what the data
might be.

So the problem im trying to solve. I need to get a list of items and
their permissions, but restrict the permission set so that I only get
permissions where extraSetting is the same on the Item and on the
permission.

So I want to run something like

Item.objects.filter(container__permissions__extraSetting=Item.extraSetting)

Hope this makes some form of sense...

thanks

guardbadger

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



Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Tabitha Samuel
The error that I'm getting is on the second form instantiation, that
is on the line:

form = StaffForm(instance = Staff.objects.using('gold').get(username =
current_staff)
where current_staff='tsamuel' for instance

This is the traceback of the error that I get when I do a print form
right after getting the form:
Environment:


Request Method: GET
Request URL: http://watermelon.nics.utk.edu:8004/staff/staffinfo

Django Version: 1.3.1
Python Version: 2.6.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'gibbs.quartermaster',
 'gibbs.userportal',
 'gibbs.reports',
 'gibbs.events',
 'gibbs.job_stats',
 'gibbs.simulator',
 'gibbs.staff']
Installed Middleware:
('django.contrib.csrf.middleware.CsrfViewMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.contrib.csrf.middleware.CsrfResponseMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "/nics/a/applications/gibbs/python/site-packages_django/django/
core/handlers/base.py" in get_response
  111. response = callback(request,
*callback_args, **callback_kwargs)
File "/nics/a/applications/gibbs/python/site-packages_django/django/
contrib/auth/decorators.py" in _wrapped_view
  23. return view_func(request, *args, **kwargs)
File "/nics/a/home/tsamuel/tssandbox/gibbs/utils/decorators.py" in
decorate
  11. return view_func(request, *args, **kws)
File "/nics/a/home/tsamuel/tssandbox/gibbs/../gibbs/staff/views.py" in
staff_info
  159. print form
File "/nics/a/applications/gibbs/python/site-packages_django/django/
utils/encoding.py" in __str__
  27. return self.__unicode__().encode('utf-8')
File "/nics/a/applications/gibbs/python/site-packages_django/django/
forms/forms.py" in __unicode__
  95. return self.as_table()
File "/nics/a/applications/gibbs/python/site-packages_django/django/
forms/forms.py" in as_table
  217. errors_on_separate_row = False)
File "/nics/a/applications/gibbs/python/site-packages_django/django/
forms/forms.py" in _html_output
  180. 'field': unicode(bf),
File "/nics/a/applications/gibbs/python/site-packages_django/django/
forms/forms.py" in __unicode__
  408. return self.as_widget()
File "/nics/a/applications/gibbs/python/site-packages_django/django/
forms/forms.py" in as_widget
  439. return widget.render(name, self.value(), attrs=attrs)
File "/nics/a/applications/gibbs/python/site-packages_django/django/
forms/widgets.py" in render
  516. options = self.render_options(choices, [value])
File "/nics/a/applications/gibbs/python/site-packages_django/django/
forms/widgets.py" in render_options
  533. for option_value, option_label in chain(self.choices,
choices):
File "/nics/a/applications/gibbs/python/site-packages_django/django/
forms/models.py" in __iter__
  882. for obj in self.queryset.all():
File "/nics/a/applications/gibbs/python/site-packages_django/django/db/
models/query.py" in _result_iter
  107. self._fill_cache()
File "/nics/a/applications/gibbs/python/site-packages_django/django/db/
models/query.py" in _fill_cache
  772.
self._result_cache.append(self._iter.next())
File "/nics/a/applications/gibbs/python/site-packages_django/django/db/
models/query.py" in iterator
  273. for row in compiler.results_iter():
File "/nics/a/applications/gibbs/python/site-packages_django/django/db/
models/sql/compiler.py" in results_iter
  680. for rows in self.execute_sql(MULTI):
File "/nics/a/applications/gibbs/python/site-packages_django/django/db/
models/sql/compiler.py" in execute_sql
  735. cursor.execute(sql, params)
File "/nics/a/applications/gibbs/python/site-packages_django/django/db/
backends/util.py" in execute
  34. return self.cursor.execute(sql, params)
File "/nics/a/applications/gibbs/python/site-packages_django/django/db/
backends/postgresql_psycopg2/base.py" in execute
  44. return self.cursor.execute(query, args)

Exception Type: DatabaseError at /staff/staffinfo
Exception Value: relation "n_nics_groups" does not exist


Tabitha


On Nov 4, 11:31 am, Furbee  wrote:
> Oh no, that would not be a good thing to share! :-) That's a bummer that
> the upgrade broke things.
>
> So, the error is being raised on this line?
> staff_form = StaffForm(request.POST, instance=staffinstance).using('gold')
>
> Furbee
>
> On Fri, Nov 4, 2011 at 8:02 AM, Tabitha Samuel 
> wrote:
>
>
>
>
>
>
>
> > So this is how I'm creating the staff form:
>
> > def staff_info(request, *args, **kws):
> >    class StaffForm(forms.ModelForm):
> >        class Meta:
> >          model= Staff
> >          
> >          
> >          
> >  if request.method == 'POST' and request.POST['event'] ==
> > 'choosestaff':
> > 

Re: django-registration-template

2011-11-04 Thread Andre Lopes
Great! I will test your templates. I'm new to Django and I have
searched a lot for this. The templates look awesome.

Best Regards,


On Fri, Nov 4, 2011 at 4:11 AM, Ezequiel Bertti  wrote:
> Hi,
> I just release a project on github with bootstrap from twitter v1.4 form
> django-registration.
> Is a simple use of bootstrap just using template for render with css. No
> python code need.
> Its is perfect sample for designers to know how to use bootstrap without
> asking to programmer to do some fix in their code.
> https://github.com/ebertti/django-registration-bootstrap
> It is my first of many github public projects.
> --
> Ezequiel Bertti
> E-Mail: eber...@gmail.com
> From Brazil
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Help with relationships

2011-11-04 Thread goof2092
hello all.
due to either lack of knowledge or confusion, I am unable to achieve a 
relationship using 3 models.
I have the models as below:



class Provider(models.Model):
name = models.CharField(max_length=50)
address = models.TextField()
phone = models.CharField(max_length=14)
email = models.EmailField(max_length=30)
post_box = models.CharField('Post Box No',max_length=10)
reg_date = models.DateField('Membership Start Date')
exp_date = models.DateField('Membership Expiry Date')
reg_status = models.CharField(max_length=2, choices=REG_STATUS_CHOICES)
 def __unicode__(self):
   return self.name


class Plan(models.Model):
plan_name = models.CharField(max_length=30)
provider = models.ForeignKey(Provider)

def __unicode__(self):
   return self.plan_name



class Member(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
address = models.TextField()
phone = models.CharField(max_length=14)
email = models.EmailField(max_length=30)
post_box = models.CharField(max_length=10)
provider = models.ForeignKey(Provider)
scheme = models.ForeignKey(*No idea what to do here*)
member_type = models.CharField(max_length=2, choices=MEMBER_TYPE_CHOICES)
dob = models.DateField()
gender = models.CharField(max_length=2, choices=GENDER_CHOICES)
id_no = models.CharField(max_length=20)
membership_no = models.CharField(max_length=20)
nationality = models.CharField(max_length=40)
reg_date = models.DateField()
exp_date = models.DateField()
reg_status = models.CharField(max_length=2, choices=REG_STATUS_CHOICES)

def __unicode__(self):
   return u'%s %s' % (self.first_name, self.last_name)
-

The idea is that when using the admin interface to add a Member, I will 
choose the *Provider* from a drop down list ( no problem, this is ok) BUT, 
the only *schemes* that should show for selection in the drop down list for 
this *Member*, must be those that relate to the select Provider. How do I 
ties this into the Member model in relation to the Plan model? The plan 
must have one Provider to which it belongs (as defined there by the Foreign 
key).

Thanks for any help.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/0Fav_bRR4zoJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Reg. Basic django.db.models

2011-11-04 Thread Brett Epps
Hi Ganesh,

Here are some examples:

Filter: SELECT * FROM device WHERE locked = true - returns a QuerySet
which can be evaluated as a list of Device objects
Get: SELECT * FROM device WHERE id = (value of id variable) LIMIT 1 -
returns a single Device object
All: SELECT * FROM schedule - returns a QuerySet which can be evaluated as
a list of Schedule objects

These are only approximations.  For example, get() does not imply a
"LIMIT", since Django looks for cases where multiple objects were returned
and throws an exception.  But hopefully this helps you understand how the
ORM maps to SQL queries.

Here's the relevant part of the documentation [1], in case you haven't
found it yet.

Brett


1. https://docs.djangoproject.com/en/dev/topics/db/queries/

On 11/3/11 11:40 PM, "Ganesh Kumar"  wrote:

>Hi,
>
>I'm a new to Django. I know mysql queries.
>I cant understand django queries, Basically My understanding
>complicated to the django queries. please guide me.
>
>Device.objects.filter(device_id = device_id)[0]
>Device->table
>device-->column
>
>Device.objects.filter(locked = True)
>
>Device.objects.get(device_id = id)
>
>Schedule.objects.all()
>
>filter method what type 0f content return.--> equivalent sql quires
>get method what exactly doing---> equivalent quires
>all method what exactly doing -> equivalent sql quires
>
>
>please guide me..
>
>-Ganesh
>Did I learn something today? If not, I wasted it.
>
>-- 
>You received this message because you are subscribed to the Google Groups
>"Django users" group.
>To post to this group, send email to django-users@googlegroups.com.
>To unsubscribe from this group, send email to
>django-users+unsubscr...@googlegroups.com.
>For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.
>

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



Re: I18N and caching: page don't change language until I press F5 in browser

2011-11-04 Thread Salvatore Iovene
PS: I have also tried the @vary_on_header('Accept-Language') decorator, but 
unfortunately that didn't help either.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/A7S2lsJ11x0J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



I18N and caching: page don't change language until I press F5 in browser

2011-11-04 Thread Salvatore Iovene
Hi,
I've got a Django website that's multi-lingual, and I'd like to use 
memcaching on it. While everything works fine with caching disabled, I have 
observed the following when caching is enabled:

1) Open any page on the website
2) Click on link (the image of a little flat) to change language
3) This runs a view that sets the language in the session and the cookie, 
and then redirects to the referrer
4) Observe that the page is still in the original language!
5) Press F5 in the browser
6) Observe that the page is now in the language I wanted

Obviously I'm expecting the page to change language at point 4 (and that's 
the way it works without caching.

Now let me how you some relevant code:

My middlewares:

MIDDLEWARE_CLASSES = 
(   
   

'django.middleware.cache.UpdateCacheMiddleware', # KEEP AT THE 
BEGINNING

'django.middleware.http.ConditionalGetMiddleware',  



'django.middleware.common.CommonMiddleware',



'django.contrib.sessions.middleware.SessionMiddleware', 



'django.contrib.auth.middleware.AuthenticationMiddleware',  



'django.middleware.cache.CacheMiddleware',  



'django.middleware.locale.LocaleMiddleware',

  

'django.contrib.messages.middleware.MessageMiddleware', 

 

'privatebeta.middleware.PrivateBetaMiddleware', 


'django.middleware.cache.FetchFromCacheMiddleware', # KEEP AT THE 
END   
)  

The view that changes language:

@require_GET
def set_language(request, lang):
from django.utils.translation import check_for_language, activate

next = request.REQUEST.get('next', None)
if not next:
next = request.META.get('HTTP_REFERER', None)
if not next:
next = '/'
response = HttpResponseRedirect(next)
if lang and check_for_language(lang):
if hasattr(request, 'session'):
request.session['django_language'] = lang
else:
response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang)
activate(lang)

if request.user.is_authenticated():
profile = UserProfile.objects.get(user = request.user)
profile.language = lang
profile.save()

return response


I have tried changing the order of the middleware, but to no avail.

Can somebody please help?

Thanks!
  Salvatore.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/ha0fhmNQZZgJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Furbee
Oh no, that would not be a good thing to share! :-) That's a bummer that
the upgrade broke things.

So, the error is being raised on this line?
staff_form = StaffForm(request.POST, instance=staffinstance).using('gold')

Furbee

On Fri, Nov 4, 2011 at 8:02 AM, Tabitha Samuel wrote:

> So this is how I'm creating the staff form:
>
> def staff_info(request, *args, **kws):
>class StaffForm(forms.ModelForm):
>class Meta:
>  model= Staff
>  
>  
>  
>  if request.method == 'POST' and request.POST['event'] ==
> 'choosestaff':
> current_staff =
> request.POST.get('selectstaff')
> elif request.method == 'POST' and request.POST['event'] ==
> 'editstaff':
> #print
> request
> current_staff =
> request.POST.get('username')
> errors =
> validate_staff(request)
> if errors is not None and len(errors) ==
> 0:
> print
> request.POST
> staffinstance = Staff.objects.using('gold').get(username =
> current_staff)
> #new_form =
> StaffForm(instance=staffinstance)
> #print
> new_form
> staff_form = StaffForm(request.POST,
> instance=staffinstance).using('gold')
> staff_form.last_modification_time =
> datetime.now()
> staff_form.supervisor =
> staffinstance.supervisor
> staff_form.start_date =
> staffinstance.start_date
>staff_form.creation_time =
> staffinstance.creation_time
>staff_form.termination_date =
> staffinstance.termination_date
>   staff_form.using('gold').save()
>
> else:
>current_staff =
> request.user.username
>tg_info,staff, nics_info =
> get_tg_info(current_staff)
>
>groups =
> NICSGroupType.objects.using('gold').all()
> form = StaffForm(instance =
> Staff.objects.using('gold').select_related().get(username =
> current_staff))
>print
> form
>return render_to_response('staff/staffinfo.html',{'form':form,
> 'tginfo':tg_info, 'nicsinfo': nics_info, 'staff':staff,
> 'is_admin':is_admin, 'errors':errors},context_instance =
> RequestContext(request))
>
>
> Funny thing is that this worked perfectly in version 1.1a of django.
> All trouble started when I switched to 1.3. I was using extDbManager
> to create the gold connection in the 1.1 version since 'gold' is a non-
> default db (used only for this model) and 1.1 only had in built
> support for a single db.
>
> And yes, I do have a page for the view. Problem is that it is passcode
> protected and I don't think I'm at liberty to give you access to it. :
> (
>
> Tabitha
> On Nov 4, 10:44 am, Mark Furbee  wrote:
> > Good Morning Tabitha.
> >
> > Actually, do you have a model for StaffForm? That is the object being
> > instantiated and then causing the error. If there is no nics group
> > reference field in the StaffForm object, it may raise this error. Also,
> do
> > you have this running in a view/template? Do you have a real page that
> > you've tried this on, or have you just tried it in the shell?
> >
> > Thanks,
> >
> > Furbee
> >
> > On Fri, Nov 4, 2011 at 7:02 AM, Tabitha Samuel  >wrote:
> >
> >
> >
> >
> >
> >
> >
> > > Here is staff/models.py
> >
> > > from django.db import models
> >
> > > class NICSGroupType(models.Model):
> > >n_group_number = models.IntegerField(primary_key = True)
> > >n_group_name = models.CharField(max_length = 512)
> > > def __str__(self):
> > >return self.n_group_name
> > > class Meta:
> > >db_table = "n_nics_groups"
> >
> > > class StaffpageAdmin(models.Model):
> > >n_id= models.IntegerField(primary_key =
> > > True)
> > >n_username  = models.CharField(max_length = 50)
> > >class Meta:
> > >db_table = 'n_staffpage_admin'
> >
> > > class Staff(models.Model):
> > >username= models.CharField(primary_key = True,
> > > max_length = 50)
> > >home_phone  = models.CharField(max_length = 12,
> > > null=True)
> > >cell_phone  = models.CharField(max_length = 12,
> > > null = True)
> > >home_address= models.CharField(max_length = 1024,
> > > null = True)
> > >home_city   = models.CharField(max_length = 64,
> > > null = True)
> > >home_state  = models.CharField(max_length = 32,
> > > null = True)
> > >home_zip= models.CharField(max_length = 10,
> > > null = True)
> > >emergency_name  = models.CharField(max_length =64,
> > > null = True)
> > >emergency_phone = models.CharField(max_length = 12,
> > > null = True)
> > >nics_group  = models.ForeignKey(NICSGroupType,
> > > to_field="n_group_number",db_column="nics_group",
> > > null=True,blank=True)
> > >room_number = models.CharField(max_length = 32,
> > > null = True)
> > >title   = models.CharField(max_length = 64)
> > >supervisor  = models.CharField(max_length = 

Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Tabitha Samuel
So this is how I'm creating the staff form:

def staff_info(request, *args, **kws):
class StaffForm(forms.ModelForm):
class Meta:
  model= Staff
  
  
  
 if request.method == 'POST' and request.POST['event'] ==
'choosestaff':
current_staff =
request.POST.get('selectstaff')
elif request.method == 'POST' and request.POST['event'] ==
'editstaff':
#print
request
current_staff =
request.POST.get('username')
errors =
validate_staff(request)
if errors is not None and len(errors) ==
0:
print
request.POST
staffinstance = Staff.objects.using('gold').get(username =
current_staff)
#new_form =
StaffForm(instance=staffinstance)
#print
new_form
staff_form = StaffForm(request.POST,
instance=staffinstance).using('gold')
staff_form.last_modification_time =
datetime.now()
staff_form.supervisor =
staffinstance.supervisor
staff_form.start_date =
staffinstance.start_date
staff_form.creation_time =
staffinstance.creation_time
staff_form.termination_date =
staffinstance.termination_date
   staff_form.using('gold').save()
 
else:
current_staff =
request.user.username
tg_info,staff, nics_info =
get_tg_info(current_staff)

groups =
NICSGroupType.objects.using('gold').all()
form = StaffForm(instance =
Staff.objects.using('gold').select_related().get(username =
current_staff))
print
form
return render_to_response('staff/staffinfo.html',{'form':form,
'tginfo':tg_info, 'nicsinfo': nics_info, 'staff':staff,
'is_admin':is_admin, 'errors':errors},context_instance =
RequestContext(request))


Funny thing is that this worked perfectly in version 1.1a of django.
All trouble started when I switched to 1.3. I was using extDbManager
to create the gold connection in the 1.1 version since 'gold' is a non-
default db (used only for this model) and 1.1 only had in built
support for a single db.

And yes, I do have a page for the view. Problem is that it is passcode
protected and I don't think I'm at liberty to give you access to it. :
(

Tabitha
On Nov 4, 10:44 am, Mark Furbee  wrote:
> Good Morning Tabitha.
>
> Actually, do you have a model for StaffForm? That is the object being
> instantiated and then causing the error. If there is no nics group
> reference field in the StaffForm object, it may raise this error. Also, do
> you have this running in a view/template? Do you have a real page that
> you've tried this on, or have you just tried it in the shell?
>
> Thanks,
>
> Furbee
>
> On Fri, Nov 4, 2011 at 7:02 AM, Tabitha Samuel 
> wrote:
>
>
>
>
>
>
>
> > Here is staff/models.py
>
> > from django.db import models
>
> > class NICSGroupType(models.Model):
> >    n_group_number = models.IntegerField(primary_key = True)
> >    n_group_name = models.CharField(max_length = 512)
> >     def __str__(self):
> >        return self.n_group_name
> >     class Meta:
> >        db_table = "n_nics_groups"
>
> > class StaffpageAdmin(models.Model):
> >    n_id                        = models.IntegerField(primary_key =
> > True)
> >    n_username                  = models.CharField(max_length = 50)
> >    class Meta:
> >        db_table = 'n_staffpage_admin'
>
> > class Staff(models.Model):
> >    username                    = models.CharField(primary_key = True,
> > max_length = 50)
> >    home_phone                  = models.CharField(max_length = 12,
> > null=True)
> >    cell_phone                  = models.CharField(max_length = 12,
> > null = True)
> >    home_address                = models.CharField(max_length = 1024,
> > null = True)
> >    home_city                   = models.CharField(max_length = 64,
> > null = True)
> >    home_state                  = models.CharField(max_length = 32,
> > null = True)
> >    home_zip                    = models.CharField(max_length = 10,
> > null = True)
> >    emergency_name              = models.CharField(max_length =64,
> > null = True)
> >    emergency_phone             = models.CharField(max_length = 12,
> > null = True)
> >    nics_group                  = models.ForeignKey(NICSGroupType,
> > to_field="n_group_number",db_column="nics_group",
> > null=True,blank=True)
> >    room_number                 = models.CharField(max_length = 32,
> > null = True)
> >    title                       = models.CharField(max_length = 64)
> >    supervisor                  = models.CharField(max_length = 25,
> > null = True, blank = True)
> >    url                         = models.CharField(max_length =
> > 256,null = True, blank = True)
> >    im                          = models.CharField(max_length = 32,
> > null = True, blank=True)
> >    last_modification_time      = models.IntegerField()
> >    start_date                  = models.IntegerField()
> >    creation_time               = models.IntegerField()
> >    termination_date            = models.IntegerField(null = True,
> > blank = True)
> >    bio                         = models.TextField()
> >    

Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Mark Furbee
Good Morning Tabitha.

Actually, do you have a model for StaffForm? That is the object being
instantiated and then causing the error. If there is no nics group
reference field in the StaffForm object, it may raise this error. Also, do
you have this running in a view/template? Do you have a real page that
you've tried this on, or have you just tried it in the shell?

Thanks,

Furbee

On Fri, Nov 4, 2011 at 7:02 AM, Tabitha Samuel wrote:

> Here is staff/models.py
>
> from django.db import models
>
> class NICSGroupType(models.Model):
>n_group_number = models.IntegerField(primary_key = True)
>n_group_name = models.CharField(max_length = 512)
> def __str__(self):
>return self.n_group_name
> class Meta:
>db_table = "n_nics_groups"
>
> class StaffpageAdmin(models.Model):
>n_id= models.IntegerField(primary_key =
> True)
>n_username  = models.CharField(max_length = 50)
>class Meta:
>db_table = 'n_staffpage_admin'
>
> class Staff(models.Model):
>username= models.CharField(primary_key = True,
> max_length = 50)
>home_phone  = models.CharField(max_length = 12,
> null=True)
>cell_phone  = models.CharField(max_length = 12,
> null = True)
>home_address= models.CharField(max_length = 1024,
> null = True)
>home_city   = models.CharField(max_length = 64,
> null = True)
>home_state  = models.CharField(max_length = 32,
> null = True)
>home_zip= models.CharField(max_length = 10,
> null = True)
>emergency_name  = models.CharField(max_length =64,
> null = True)
>emergency_phone = models.CharField(max_length = 12,
> null = True)
>nics_group  = models.ForeignKey(NICSGroupType,
> to_field="n_group_number",db_column="nics_group",
> null=True,blank=True)
>room_number = models.CharField(max_length = 32,
> null = True)
>title   = models.CharField(max_length = 64)
>supervisor  = models.CharField(max_length = 25,
> null = True, blank = True)
>url = models.CharField(max_length =
> 256,null = True, blank = True)
>im  = models.CharField(max_length = 32,
> null = True, blank=True)
>last_modification_time  = models.IntegerField()
>start_date  = models.IntegerField()
>creation_time   = models.IntegerField()
>termination_date= models.IntegerField(null = True,
> blank = True)
>bio = models.TextField()
>photopath   = models.CharField(max_length = 5048)
>office_phone= models.CharField(max_length=12)
>email   = models.CharField(max_length = 256)
>preferred_name  = models.CharField(max_length = 50,
> null = True, blank = True)
>deleted = models.BooleanField(default = False)
>viewable= models.BooleanField(default = True)
>
>class Meta:
>db_table = "n_test_staff"
>
> class TG_Staff(models.Model):
>g_name  = models.CharField(primary_key = True,
> max_length = 1024)
>g_modification_time = models.IntegerField()
>g_active= models.CharField(max_length = 5)
>g_common_name   = models.CharField(max_length = 1024)
>g_phone_number  = models.CharField(max_length = 1024)
>g_default_project   = models.CharField(max_length = 1024)
>g_office_address= models.CharField(max_length = 1024)
>g_bz_phone  = models.CharField(max_length = 1024)
>g_bz_phone_ext  = models.CharField(max_length = 1024)
>g_citizenship   = models.CharField(max_length = 1024)
>g_street_address= models.CharField(max_length = 1024)
>g_street_address2   = models.CharField(max_length = 1024)
>g_city  = models.CharField(max_length = 1024)
>g_state = models.CharField(max_length = 1024)
>g_zip   = models.CharField(max_length = 1024)
>g_country   = models.CharField(max_length = 1024)
>g_dept  = models.CharField(max_length = 1024)
>g_tg_person_id  = models.CharField(max_length = 1024)
>g_org   = models.CharField(max_length = 1024)
>g_position  = models.CharField(max_length = 1024)
>g_home_phone= models.CharField(max_length = 1024)
>g_fax   = models.CharField(max_length = 1024)
>g_ldap_id   = models.IntegerField()
>g_email_address = models.CharField(max_length = 1024)
>
>class Meta:
>db_table 

Re: Translation problem with percent sign

2011-11-04 Thread Martin J. Laubach
  Just remove the line with "python-format" from your translation since it 
isn't a format string after all.

mjl

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/T_0dGHybS8YJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Tabitha Samuel
Here is staff/models.py

from django.db import models

class NICSGroupType(models.Model):
n_group_number = models.IntegerField(primary_key = True)
n_group_name = models.CharField(max_length = 512)
def __str__(self):
return self.n_group_name
class Meta:
db_table = "n_nics_groups"

class StaffpageAdmin(models.Model):
n_id= models.IntegerField(primary_key =
True)
n_username  = models.CharField(max_length = 50)
class Meta:
db_table = 'n_staffpage_admin'

class Staff(models.Model):
username= models.CharField(primary_key = True,
max_length = 50)
home_phone  = models.CharField(max_length = 12,
null=True)
cell_phone  = models.CharField(max_length = 12,
null = True)
home_address= models.CharField(max_length = 1024,
null = True)
home_city   = models.CharField(max_length = 64,
null = True)
home_state  = models.CharField(max_length = 32,
null = True)
home_zip= models.CharField(max_length = 10,
null = True)
emergency_name  = models.CharField(max_length =64,
null = True)
emergency_phone = models.CharField(max_length = 12,
null = True)
nics_group  = models.ForeignKey(NICSGroupType,
to_field="n_group_number",db_column="nics_group",
null=True,blank=True)
room_number = models.CharField(max_length = 32,
null = True)
title   = models.CharField(max_length = 64)
supervisor  = models.CharField(max_length = 25,
null = True, blank = True)
url = models.CharField(max_length =
256,null = True, blank = True)
im  = models.CharField(max_length = 32,
null = True, blank=True)
last_modification_time  = models.IntegerField()
start_date  = models.IntegerField()
creation_time   = models.IntegerField()
termination_date= models.IntegerField(null = True,
blank = True)
bio = models.TextField()
photopath   = models.CharField(max_length = 5048)
office_phone= models.CharField(max_length=12)
email   = models.CharField(max_length = 256)
preferred_name  = models.CharField(max_length = 50,
null = True, blank = True)
deleted = models.BooleanField(default = False)
viewable= models.BooleanField(default = True)

class Meta:
db_table = "n_test_staff"

class TG_Staff(models.Model):
g_name  = models.CharField(primary_key = True,
max_length = 1024)
g_modification_time = models.IntegerField()
g_active= models.CharField(max_length = 5)
g_common_name   = models.CharField(max_length = 1024)
g_phone_number  = models.CharField(max_length = 1024)
g_default_project   = models.CharField(max_length = 1024)
g_office_address= models.CharField(max_length = 1024)
g_bz_phone  = models.CharField(max_length = 1024)
g_bz_phone_ext  = models.CharField(max_length = 1024)
g_citizenship   = models.CharField(max_length = 1024)
g_street_address= models.CharField(max_length = 1024)
g_street_address2   = models.CharField(max_length = 1024)
g_city  = models.CharField(max_length = 1024)
g_state = models.CharField(max_length = 1024)
g_zip   = models.CharField(max_length = 1024)
g_country   = models.CharField(max_length = 1024)
g_dept  = models.CharField(max_length = 1024)
g_tg_person_id  = models.CharField(max_length = 1024)
g_org   = models.CharField(max_length = 1024)
g_position  = models.CharField(max_length = 1024)
g_home_phone= models.CharField(max_length = 1024)
g_fax   = models.CharField(max_length = 1024)
g_ldap_id   = models.IntegerField()
g_email_address = models.CharField(max_length = 1024)

class Meta:
db_table = "g_user"

Is this what you needed?

Tabitha

On Nov 4, 2:00 am, Furbee  wrote:
> Hi Tabitha,
>
> I wish I could supply a quick and simple answer to fix what's going on in
> your database, but nothing obvious is standing out. Can you supply your
> model for StaffForm? That seems to be where the problem lies, since we can
> get details from the model and view elsewhere.
>
> Thanks,
>
> Furbee
>
> On Thu, Nov 3, 2011 at 7:22 PM, Tabitha Samuel 
> wrote:
>
>
>
>
>
>
>
> > K, so that worked...
>
> > This is what I got:
> > In [5]: i = 

Translation problem with percent sign

2011-11-04 Thread Martin Tiršel

Hello,

I am using Django 1.2.5.


* template:

{% trans 'If you cancel queued construction, you will get 75% of resources  
back' %}



* django-admin.py makemessages -l sk produces:

#: templates/core/buildings/construction.html:65
#, python-format
msgid "If you cancel queued construction, you will get 75% of resources  
back"

msgstr ""

I open the .po file in poedit program and add translation "Zrušením budovy  
v stavebnom rade sa ti vráti 75% surovín" what produces:


1375 #: templates/core/buildings/construction.html:65
1376 #, python-format
1377 msgid "If you cancel queued construction, you will get 75% of  
resources back"

1378 msgstr "Zrušením budovy v stavebnom rade sa ti vráti 75% surovín"

And poedit (or django compilemessages) shows me an error  
"...po:1378:format specification in 'msgid' nad 'msgstr' for argument a  
are not the same". When I add 75%% in my translated string doesn't work  
either, I need to manually edit the msgid string and change % for %%, so  
it looks so:


1375 #: templates/core/buildings/construction.html:65
1376 #, python-format
1377 msgid "If you cancel queued construction, you will get 75%% of  
resources back"

1378 msgstr "Zrušením budovy v stavebnom rade sa ti vráti 75%% surovín"

This will compile. But no translation occurs because it seems that {%  
trans %} can not handle percent sign. Is it so or I am doing something  
wrong?



I could split the string into two translation string like this:

{% trans 'If you cancel queued construction, you will get' %} 75% {% trans  
'of resources back' %}


but this seems a little bit ugly. Or I could use HTML entity  or  
perhaps use {% blocktrans %} and instead of % use some variable like {{  
PERCENT_SIGN }}. But all of this is a little bit complicated so I first  
need to know if I am not doing something bad or perhaps there is a bug in  
Django.


Thanks,
Martin

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



Re: How can I limit a 'list_filter' to a certain subset of objects?

2011-11-04 Thread Andre Terra
Hello, Rodrigo

>From looking at the ModelAdmin source code[1], I think all you need to do
is reimplement the queryset() method in your subclass on admin.py.

Make sure you return a filtered queryset based on request.user. I never use
the admin, so I'm not so sure about how the user will be accessible from
the admin, so maybe someone else will have to explain the final steps.


Cheers,
AT

[1]
https://code.djangoproject.com/browser/django/trunk/django/contrib/admin/options.py#L214

On Thu, Nov 3, 2011 at 8:35 PM, Rodrigo Cea  wrote:

> Explanation:
>
> I have 3 models: Client, Project and Task. Each Client has 1 or more
> Projects. Each Project has 1 or more Tasks.
>
> A Client can only see the Projects assigned to him and the Tasks assigned
> to one of his Projects. This is already working, overriding "queryset" in
> the ModelAdmin instance.
>
> However, in the changelist for Tasks, there is a list_filter on Projects,
> so a Client can view the Tasks that are assigned to a certain Project.
>
> THE PROBLEM: this 'Project' filter shows all Projects, whether they're
> assigned to the Client or not. I need it to only show the Projects assigned
> to the Client.
>
> Thanks,
>
> Rodrigo
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/xO-ARZBOXp4J.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Abstract FormView

2011-11-04 Thread Kurtis Mullins
Great answer. Thanks a lot!

On Thu, Nov 3, 2011 at 8:08 AM, Andre Terra  wrote:

> All you have to do is create a MyFormMixin class and add all those methods
> you want to override. Usually you will want to call super() on the class so
> that the normal behavior is also present in your final class.
>
> The difference between a Mixin and a full-fledged Class can be nearly
> non-existent in some cases, so don't worry about the terminology. If you
> want, you can even subclass 'object' to make it as generic as it gets.
>
>
> # example.py
>
> class MyFormMixin(object):
> def get_form_kwargs(self, *args, **kwargs):
> kw = super(MyFormMixin, self).get_form_kwargs(*args, **kwargs)
> kw.update({'some': 'extra', 'permantent': 'kwargs'})
> return kw
>
> class MyViewWithMixin(MyFormMixin, FormView):
> pass
>
> # end example.py
>
> Hope that helps! Let us know if you have any other questions.
>
>
> Cheers,
> AT
>
>
>
> On Wed, Nov 2, 2011 at 6:47 PM, Kurtis  wrote:
>
>> Hey,
>>
>> I have a couple of FormViews that override quite a few methods. I want
>> to write an "Abstract View" that I can subclass for these. I'm
>> guessing what I actually need is a custom Mixin but I'm really not
>> sure.
>>
>> Any suggestions on how to go about doing this?
>>
>> Some methods I'm overriding:
>>
>> get_form_kwargs
>> form_valid
>> form_invalid
>> get_context_data
>>
>> Other than the form_class, the code in each is the same line for line
>> (except of course when referencing the Class name)
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Django login() fails when using custom Facebook backend

2011-11-04 Thread Tom Evans
On Fri, Nov 4, 2011 at 4:11 AM, kz26  wrote:
> I'm currently working on a site (Django 1.3) where all users will be
> authenticated through Facebook. To do this, I've written a simple
> custom authentication backend:
>
>
> # custom Facebook authentication backend
> from django.contrib.auth.models import User
> from site_main.models import *
> from fb import facebook
>
> class FBAuthBackend:
>    def authenticate(self, token):
>        try:
>            graph = facebook.GraphAPI(token)
>            profile = graph.get_object("me") # will throw an exception
> if token is invalid
>            uid = profile['id']
>
>            # check for existing user
>            user = self.get_user(uid)
>
>            # otherwise create a new user
>            if user == None:
>                user = User(username=uid)
>                #user.set_unusable_password()
>                user.set_password(User.objects.make_random_password())
>                user.save()
>                uprofile = UserProfile(user=user)
>                uprofile.save()
>
>            user.first_name = profile['first_name']
>            user.last_name = profile['last_name']
>            user.save()
>            return user
>        except:
>            return None
>
>    def get_user(self, user_id):
>        try:
>            return User.objects.get(username=user_id)
>        except:
>            return None
>
>
> This backend works fine - it checks the access token it receives and
> creates a new user or returns an existing one, as expected.
>
> I have a couple of login-related views:
>
> from models import *
> from django.contrib.auth import *
> from django.shortcuts import *
> from django.http import *
>
> def site_login(request):
>    if 'token' in request.GET:
>        u = authenticate(token=request.GET['token'])
>        if u:
>            login(request, u)
>    return redirect('/')
>
> def logintest(request):
>    return HttpResponse(str(request.user.is_authenticated()))
>
>
> The authenticate() call works fine - u is assigned a valid user object
> where u.is_authenticated() is True. However, once I navigate to any
> other page - for example, the URL that calls logintest, the user is no
> longer authenticated, i.e. u._is_authenticated() = False. It's almost
> as if the login() call never saved the user into the session.
>
> Please help - I am about ready to tear out my hair over this, and this
> is stalling the rest of my development!
>
> Thanks!
>

Are you certain your session cookie is being set with the correct
domain, and that the same session cookie is returned on subsequent
pages? Test by examining request headers.

Cheers

Tom

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



Reg. Basic django.db.models

2011-11-04 Thread Ganesh Kumar
Hi,

I'm a new to Django. I know mysql queries.
I cant understand django queries, Basically My understanding
complicated to the django queries. please guide me.

Device.objects.filter(device_id = device_id)[0]
Device->table
device-->column

Device.objects.filter(locked = True)

Device.objects.get(device_id = id)

Schedule.objects.all()

filter method what type 0f content return.--> equivalent sql quires
get method what exactly doing---> equivalent quires
all method what exactly doing -> equivalent sql quires


please guide me..

-Ganesh
Did I learn something today? If not, I wasted it.

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



django-registration-template

2011-11-04 Thread Ezequiel Bertti
Hi,

I just release a project on github with bootstrap from twitter v1.4 form
django-registration.

Is a simple use of bootstrap just using template for render with css. No
python code need.

Its is perfect sample for designers to know how to use bootstrap without
asking to programmer to do some fix in their code.

https://github.com/ebertti/django-registration-bootstrap

It is my first of many github public projects.

-- 
Ezequiel Bertti
E-Mail: eber...@gmail.com
>From Brazil

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



Django login() fails when using custom Facebook backend

2011-11-04 Thread kz26
I'm currently working on a site (Django 1.3) where all users will be
authenticated through Facebook. To do this, I've written a simple
custom authentication backend:


# custom Facebook authentication backend
from django.contrib.auth.models import User
from site_main.models import *
from fb import facebook

class FBAuthBackend:
def authenticate(self, token):
try:
graph = facebook.GraphAPI(token)
profile = graph.get_object("me") # will throw an exception
if token is invalid
uid = profile['id']

# check for existing user
user = self.get_user(uid)

# otherwise create a new user
if user == None:
user = User(username=uid)
#user.set_unusable_password()
user.set_password(User.objects.make_random_password())
user.save()
uprofile = UserProfile(user=user)
uprofile.save()

user.first_name = profile['first_name']
user.last_name = profile['last_name']
user.save()
return user
except:
return None

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


This backend works fine - it checks the access token it receives and
creates a new user or returns an existing one, as expected.

I have a couple of login-related views:

from models import *
from django.contrib.auth import *
from django.shortcuts import *
from django.http import *

def site_login(request):
if 'token' in request.GET:
u = authenticate(token=request.GET['token'])
if u:
login(request, u)
return redirect('/')

def logintest(request):
return HttpResponse(str(request.user.is_authenticated()))


The authenticate() call works fine - u is assigned a valid user object
where u.is_authenticated() is True. However, once I navigate to any
other page - for example, the URL that calls logintest, the user is no
longer authenticated, i.e. u._is_authenticated() = False. It's almost
as if the login() call never saved the user into the session.

Please help - I am about ready to tear out my hair over this, and this
is stalling the rest of my development!

Thanks!

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



Re: Caching at model class level

2011-11-04 Thread Thomas Guettler
Am 03.11.2011 18:42, schrieb Tom Evans:
> On Thu, Nov 3, 2011 at 2:22 PM, Thomas Guettler  wrote:
>> Hi,
>>
>> I try to reduce the number of db-queries in my app.
>>
>> There is a model which changes almost never. It is like a "type of ticket"
>> in a trouble ticket system.
>>
>> On one page there are seven SQL-Queries (SELECT  FROM ticket_type where 
>> id=123) which of course always return
>> the same result.
>>
>> I want to cache the objects:
>>
>> t1=TicketType.objects.get(id=123)
>> t2=TicketType.objects.get(id=123)

> Hey
> 
> I wouldn't use this approach - caching in threadlocals is the wrong
> place to cache. Primarily, this is because the cache is in the wrong
> location - it is per thread, which means you must have n caches for n
> threads. This is an inefficient use of memory, it would be better to
> cache at a different level, eg memcached, redis, etc.

Hey,

The database queries (without cache) are fast enough. There are just too many. 
Sometimes
up to ten equal SELECT by primary key statements during one request. If you 
substitute
fast sql queries with fast cache access, I don't have a benefit.

> Secondly, this caching is very naïve. Queries are never evicted from
> the cache, ...

Yes, I know. The lines I wrote were just a prototype.

I want to use this for things that doesn't change for several days. The cache
could get purged by touching the wsgi-file, which reloads the wsgi worker 
processes.

  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: Relation not found error while dealing with foreign keys and forms

2011-11-04 Thread Furbee
Hi Tabitha,

I wish I could supply a quick and simple answer to fix what's going on in
your database, but nothing obvious is standing out. Can you supply your
model for StaffForm? That seems to be where the problem lies, since we can
get details from the model and view elsewhere.

Thanks,

Furbee

On Thu, Nov 3, 2011 at 7:22 PM, Tabitha Samuel wrote:

> K, so that worked...
>
> This is what I got:
> In [5]: i = Staff.objects.using('gold').get(username='tsamuel')
>
> In [6]: i.nics_group.n_group_name
> Out[6]: u'Systems and Operations'
>
> Looks like the foreign key is working fine from the db's perspective.
> This is how I'm getting the form:
> form = StaffForm(instance = Staff.objects.using('gold').get(username
> =current_staff))
> where current_staff = 'tsamuel'
> and then if I do a print form, I get a relation n_nics_groups does not
> exist error.
>
> Once again, thank you so much for your help, I really appreciate it!
>
> Tabitha
>
> On Nov 3, 1:26 pm, Furbee  wrote:
> > I may have lead you astray. I set up the same models on my end and get
> the
> > same query; it didn't show the join of the foreign key in the QuerySet of
> > Staff, but when I did a get() on username='tsamuel' I got a Staff object.
> > Then I was able to get the group they belonged to. This was successful
> for
> > me:
> >
> > Here's my data:
> >
> > table: n_nics_groups
> > n_group_number; n_group_name
> > 1; "TestGroup1"
> > 2; "TestGroup2"
> > 3; "TestGroup3"
> >
> > table: n_test_staff
> >
> "tfigura";"";"";"";"";"";"";"";"";2;"";"''";"";"";"";1;1;1;;"''";"''";"''";"''";"";FALSE;TRUE
> >
> "tsamuel";"";"";"";"";"";"";"";"";1;"";"''";"";"";"";1;1;1;;"''";"''";"''";"''";"''";FALSE;TRUE
> >
> > 'tfigura' is in group with n_group_number 2, tsamuel is in group with
> > n_group_number 1.
> >
> > python manage.py shell:
> >
> > >>> from project.models import NICSGroupType, Staff
> > >>> i = Staff.objects.get(username='tsamuel')
> > >>> i.nics_group.n_group_name
> > >>> u'TestGroup1'
> >
> > Is this operational for your instance? If not, I would double check that
> > the n_nics_groups table definitely exists in the datasource you defined
> as
> > 'gold.' This should be defined in the DATABASES section of settings.py.
> It
> > looks like it is the database 'public' from your example, but double
> check
> > that the 'gold' DATABASE points there.
> >
> > Otherwise, I wonder if it is somewhere where you are defining the form
> > object. First, let's verify that the foreign key reference is being
> honored
> > on your system, by running the above test, to verify that the group is
> > printed, when you get() a specific record and print the
> > nics_group.n_group_name.
> >
> > Thanks,
> >
> > Furbee
> >
> > On Wed, Nov 2, 2011 at 5:09 PM, Tabitha Samuel 
> > wrote:>
> Thank you so much for your reply! So I got a "Staff object has no
> > > attribute 'query'" error when I did it with the get. I got the sql
> > > when I tried it with the filter instead (instance =
> > > Staff.objects.using('gold').filter(username='tsamuel') >>
> > > str(instance.query))this is what I'm getting:
> >
> > > 'SELECT "n_test_staff"."username", "n_test_staff"."home_phone",
> > > "n_test_staff"."cell_phone", "n_test_staff"."home_address",
> > > "n_test_staff"."home_city", "n_test_staff"."home_state",
> > > "n_test_staff"."home_zip", "n_test_staff"."emergency_name",
> > > "n_test_staff"."emergency_phone", "n_test_staff"."nics_group",
> > > "n_test_staff"."room_number", "n_test_staff"."title",
> > > "n_test_staff"."supervisor", "n_test_staff"."url",
> > > "n_test_staff"."im", "n_test_staff"."last_modification_time",
> > > "n_test_staff"."start_date", "n_test_staff"."creation_time",
> > > "n_test_staff"."termination_date", "n_test_staff"."bio",
> > > "n_test_staff"."photopath", "n_test_staff"."office_phone",
> > > "n_test_staff"."email", "n_test_staff"."preferred_name",
> > > "n_test_staff"."deleted", "n_test_staff"."viewable" FROM
> > > "n_test_staff" WHERE "n_test_staff"."username" = tsamuel '
> >
> > > Looks like from the query, is not looking into the n_nics_groups
> > > table. Question is why?
> >
> > > Tabitha
> >
> > > On Nov 2, 6:00 pm, Furbee  wrote:
> > > > Can you try this and tell us what you see:
> >
> > > > Run a shell using python manage.py shell
> >
> > > > >>> instance = Staff.objects.using('gold').get(username='tsamuel')
> > > > >>> str(instance.query)
> >
> > > > This will tell us whether or not the database, reference, and such
> are
> > > > correctly translating into a query. The error means Django is
> sending an
> > > > erroneous query to your database layer.
> >
> > > > Furbeenator
> >
> > > > On Wed, Nov 2, 2011 at 1:54 PM, Tabitha Samuel <
> tabitha.sam...@gmail.com
> > > >wrote:
> >
> > > > > Hi,
> >
> > > > > In brief here is my problem. I have two simple tables, one has a
> one
> > > > > to many relation with the other. The problem I run into is