defining models for unit testing only

2010-08-21 Thread mack the finger
I wrote a django 'app', thats basically just a class that takes a
Queryset, some other information, and then outputs an HttpResponse
object (it does some other things too). How do I write unit tests for
this class? The app itself does not contain any models, yet the
functionality of the class depends on a model. The testing docs do not
mention anything about this.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: check email duplication at registration

2010-08-21 Thread Steve Holden
On 8/21/2010 10:32 PM, John Yeukhon Wong wrote:
> Hi, sorry for the problem.
> 
> Well, this is used in registration. As stated in the title, this is
> used to prevent "duplication".
> Let say an existing user in db, whose username is abc, and email is
> 1...@acb.com
> After testing, I can still register an account with the existing email
> address, which means that the code does not work properly
> 
I repeat: the clean_*() functions should be methods of the
RegistrationForm class - indent them so they are at the same level as
the body of the class.

At the moment they are functions, and Django has no way of knowing they
"belong"to the form.

regards
 Steve


> Full source code
> 
> 
> 
> /code begins
> 
> 
> 
> 
> import re
> from django import forms
> from django.contrib.auth.models import User
> 
> class RegistrationForm(forms.Form):
> username = forms.CharField(label=u'Username', max_length=30)
> email = forms.EmailField(label=u'Email')
> password1 = forms.CharField(
> label=u'Password',
> widget=forms.PasswordInput()
> )
> password2 = forms.CharField(
> label=u'Password (Again)',
> widget=forms.PasswordInput()
> )
> 
> def clean_password2(self):
> if 'password1' in self.cleaned_data:
> password1 = self.cleaned_data['password1']
> password2 = self.cleaned_data['password2']
> if password1 == password2:
> return password2
> raise forms.ValidationError('Passwords do not match.')
> 
> def clean_username(self):
> username = self.cleaned_data['username']
> if not re.search(r'^\w+$', username):
> raise forms.ValidationError('Username can only contain
> ''alphanumeric characters and the underscore.')
> try:
> User.objects.get(username=username)
> except User.DoesNotExist:
> return username
> raise forms.ValidationError('Username is already taken.')
> 
> def clean_email(self):
> email = self.cleaned_data['email']
> try:
> User.objects.get(email=email)
> except User.DoesNotExist:
> return email
> raise forms.ValidationError('This email address has been
> registered with an existing user.')
> 
> 
> 
> 
> 
> 
> 
> /// code ends
> 
> On Aug 21, 10:05 pm, Steve Holden  wrote:
>> On 8/21/2010 7:23 PM, John Yeukhon Wong wrote:> I don't think this code is 
>> working properly
>>
>> That isn't a very helpful description. For better answers, please
>> describe what it is doing that it should not (or what it is not doing
>> that it should).
>>
>>
>>
>>> from django import forms
>>> from django.contrib.auth.models import User
>>
>>> def clean_email(self):
>>> email = self.cleaned_data['email']
>>> try:
>>> User.objects.get(email=email)
>>> except User.DoesNotExist:
>>> return email
>>> raise forms.ValidationError('This email address has been
>>> registered with an existing user.')
>>
>>> How should I rewrite it properly? Thanks!!
>>
>> Shouldn't clean_email() be a method of the form it's a part of? You
>> appear to have written it as a stand-alone function, so it probably
>> isn't being called at all.
>>
>> regards
>>  Steve
>> --
>> DjangoCon US 2010 September 7-9http://djangocon.us/
> 


-- 
DjangoCon US 2010 September 7-9 http://djangocon.us/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: check email duplication at registration

2010-08-21 Thread John Yeukhon Wong
Hi, sorry for the problem.

Well, this is used in registration. As stated in the title, this is
used to prevent "duplication".
Let say an existing user in db, whose username is abc, and email is
1...@acb.com
After testing, I can still register an account with the existing email
address, which means that the code does not work properly

Full source code



/code begins




import re
from django import forms
from django.contrib.auth.models import User

class RegistrationForm(forms.Form):
username = forms.CharField(label=u'Username', max_length=30)
email = forms.EmailField(label=u'Email')
password1 = forms.CharField(
label=u'Password',
widget=forms.PasswordInput()
)
password2 = forms.CharField(
label=u'Password (Again)',
widget=forms.PasswordInput()
)

def clean_password2(self):
if 'password1' in self.cleaned_data:
password1 = self.cleaned_data['password1']
password2 = self.cleaned_data['password2']
if password1 == password2:
return password2
raise forms.ValidationError('Passwords do not match.')

def clean_username(self):
username = self.cleaned_data['username']
if not re.search(r'^\w+$', username):
raise forms.ValidationError('Username can only contain
''alphanumeric characters and the underscore.')
try:
User.objects.get(username=username)
except User.DoesNotExist:
return username
raise forms.ValidationError('Username is already taken.')

def clean_email(self):
email = self.cleaned_data['email']
try:
User.objects.get(email=email)
except User.DoesNotExist:
return email
raise forms.ValidationError('This email address has been
registered with an existing user.')







/// code ends

On Aug 21, 10:05 pm, Steve Holden  wrote:
> On 8/21/2010 7:23 PM, John Yeukhon Wong wrote:> I don't think this code is 
> working properly
>
> That isn't a very helpful description. For better answers, please
> describe what it is doing that it should not (or what it is not doing
> that it should).
>
>
>
> > from django import forms
> > from django.contrib.auth.models import User
>
> > def clean_email(self):
> >     email = self.cleaned_data['email']
> >     try:
> >         User.objects.get(email=email)
> >     except User.DoesNotExist:
> >         return email
> >     raise forms.ValidationError('This email address has been
> > registered with an existing user.')
>
> > How should I rewrite it properly? Thanks!!
>
> Shouldn't clean_email() be a method of the form it's a part of? You
> appear to have written it as a stand-alone function, so it probably
> isn't being called at all.
>
> regards
>  Steve
> --
> DjangoCon US 2010 September 7-9http://djangocon.us/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 comparing variables in a view

2010-08-21 Thread Steve Holden
On 8/21/2010 8:35 PM, Kevin wrote:
> I have attempted to troubleshoot this myself with no luck and am very
> confused why a simple IF statement is not working.  I have used if
> statements in python before and never had such a problem.  I am rather
> glad to see that PRINT outputs to the console, this helps a bit for
> troubleshooting.  Variable information:
> 
> client_id = Comes in from a views request... def
> view_client(request,client_id):
> c.id = Comes in from a database model.
> 
> -- code --
> print "%s - %s" % (str(client_id),str(c.id))
> if str(client_id) == str(c.id):
> -- end --
> 
> The console output, displays 3 - 3 as plain as a day, this is why I am
> very confused on why it is not resolving.  The logic always resolves
> as False, which should resolve as True.  I came to the conclusion that
> both objects were different by using dir() and printing it out to the
> console, hence the reason I now placed both objects inside a str() in
> hopes it may work, but alas, it does not.  If I put it as 3 == 3, it
> resolves as True.  Any ideas?  Placed in str() along with dir(), both
> objects are now equal, but the IF statement sees otherwise.
> 
First of all, the "%s" string formatting code automatically performs an
str() on whatever value is presented, so you could have used

print "%s - %s" % (client_id, c.id)

I would normally use something like

print "/%s/ - /%s/" % (client_id, c.id)

to remove any possibility that white space was causing the problem.

Unfortunately dir() does not give you the information you really need,
which is the type of the information. So you might want to try

print type(client_id), type(c.id)

to give you some more insight into why the equality comparison is
failing.  And be prepared to learn that the comparison *isn't* failing,
but that the logic guarded by the if is not operating the way you think
it does.

regards
 Steve
-- 
DjangoCon US 2010 September 7-9 http://djangocon.us/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: check email duplication at registration

2010-08-21 Thread Steve Holden
On 8/21/2010 7:23 PM, John Yeukhon Wong wrote:
> I don't think this code is working properly
> 
That isn't a very helpful description. For better answers, please
describe what it is doing that it should not (or what it is not doing
that it should).

> from django import forms
> from django.contrib.auth.models import User
> 
> def clean_email(self):
> email = self.cleaned_data['email']
> try:
> User.objects.get(email=email)
> except User.DoesNotExist:
> return email
> raise forms.ValidationError('This email address has been
> registered with an existing user.')
> 
> 
> 
> How should I rewrite it properly? Thanks!!
> 
Shouldn't clean_email() be a method of the form it's a part of? You
appear to have written it as a stand-alone function, so it probably
isn't being called at all.

regards
 Steve
-- 
DjangoCon US 2010 September 7-9 http://djangocon.us/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 on Mac OS X

2010-08-21 Thread AndrewK
I've had the same problem on my Mac just now.
It seems like this is an issue with django-timezones

Try to install dev version from here:
pip install -e 
git://github.com/brosner/django-timezones.git#egg=django-timezones

Andrew

On Aug 9, 1:40 pm, Daniel França  wrote:
> Thanx for all the help,
> I tried to run on Sqlite3, and I don't if it's bad or good news, but there's
> error even in Sqlite3
>
> just when I tried to create the db (syncdb) I get just after I input my
> users data or when I try to create a user in shell:
> Traceback (most recent call last):
>   File "manage.py", line 31, in 
>     execute_from_command_line()
>   File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa 
> ges/django/core/management/__init__.py",
> line 429, in execute_from_command_line
>     utility.execute()
>   File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa 
> ges/django/core/management/__init__.py",
> line 379, in execute
>     self.fetch_command(subcommand).run_from_argv(self.argv)
>   File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa 
> ges/django/core/management/base.py",
> line 191, in run_from_argv
>     self.execute(*args, **options.__dict__)
>   File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa 
> ges/django/core/management/base.py",
> line 218, in execute
>     output = self.handle(*args, **options)
>   File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa 
> ges/django/core/management/base.py",
> line 347, in handle
>     return self.handle_noargs(**options)
>   File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa 
> ges/django/core/management/commands/syncdb.py",
> line 103, in handle_noargs
>     emit_post_sync_signal(created_models, verbosity, interactive, db)
>   File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa 
> ges/django/core/management/sql.py",
> line 185, in emit_post_sync_signal
>     interactive=interactive, db=db)
>   File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa 
> ges/django/dispatch/dispatcher.py",
> line 162, in send
>     response = receiver(signal=self, sender=sender, **named)
>   File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa 
> ges/django/contrib/auth/management/__init__.py",
> line 44, in create_superuser
>     call_command("createsuperuser", interactive=True)
>   File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa 
> ges/django/core/management/__init__.py",
> line 166, in call_command
>     return klass.execute(*args, **defaults)
>   File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa 
> ges/django/core/management/base.py",
> line 218, in execute
>     output = self.handle(*args, **options)
>   File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa 
> ges/django/contrib/auth/management/commands/createsuperuser.py",
> line 134, in handle
>     User.objects.create_superuser(username, email, password)
>   File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa 
> ges/django/contrib/auth/models.py",
> line 133, in create_superuser
>     u = self.create_user(username, email, password)
>   File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa 
> ges/django/contrib/auth/models.py",
> line 129, in create_user
>     user.save(using=self._db)
>   File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa 
> ges/django/db/models/base.py",
> line 435, in save
>     self.save_base(using=using, force_insert=force_insert,
> force_update=force_update)
>   File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa 
> ges/django/db/models/base.py",
> line 543, in save_base
>     created=(not record_exists), raw=raw)
>   File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa 
> ges/django/dispatch/dispatcher.py",
> line 162, in send
>     response = receiver(signal=self, sender=sender, **named)
>   File
> "/Users/danielfranca/workspace/django/view/tint/apps/account/models.py",
> line 61, in create_account
>     account, created =
> Account.objects.get_or_create(user=instance,timezone='America/Sao_Paulo')
>   File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa 
> ges/django/db/models/manager.py",
> line 135, in get_or_create
>     return self.get_query_set().get_or_create(**kwargs)
>   File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa 
> ges/django/db/models/query.py",
> line 366, in get_or_create
>     return self.get(**kwargs), False
>   File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packa 
> ges/django/db/models/query.py",
> line 336, in get
>     num = len(clone)
>   File
> "/Library/Frameworks/Python.fr

Re: Trouble comparing variables in a view

2010-08-21 Thread Felippe Bueno
did you tried int() ?
just an idea ...

On Sat, Aug 21, 2010 at 9:35 PM, Kevin  wrote:
> I have attempted to troubleshoot this myself with no luck and am very
> confused why a simple IF statement is not working.  I have used if
> statements in python before and never had such a problem.  I am rather
> glad to see that PRINT outputs to the console, this helps a bit for
> troubleshooting.  Variable information:
>
> client_id = Comes in from a views request... def
> view_client(request,client_id):
> c.id = Comes in from a database model.
>
> -- code --
> print "%s - %s" % (str(client_id),str(c.id))
> if str(client_id) == str(c.id):
> -- end --
>
> The console output, displays 3 - 3 as plain as a day, this is why I am
> very confused on why it is not resolving.  The logic always resolves
> as False, which should resolve as True.  I came to the conclusion that
> both objects were different by using dir() and printing it out to the
> console, hence the reason I now placed both objects inside a str() in
> hopes it may work, but alas, it does not.  If I put it as 3 == 3, it
> resolves as True.  Any ideas?  Placed in str() along with dir(), both
> objects are now equal, but the IF statement sees otherwise.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@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 comparing variables in a view

2010-08-21 Thread Kevin
I have attempted to troubleshoot this myself with no luck and am very
confused why a simple IF statement is not working.  I have used if
statements in python before and never had such a problem.  I am rather
glad to see that PRINT outputs to the console, this helps a bit for
troubleshooting.  Variable information:

client_id = Comes in from a views request... def
view_client(request,client_id):
c.id = Comes in from a database model.

-- code --
print "%s - %s" % (str(client_id),str(c.id))
if str(client_id) == str(c.id):
-- end --

The console output, displays 3 - 3 as plain as a day, this is why I am
very confused on why it is not resolving.  The logic always resolves
as False, which should resolve as True.  I came to the conclusion that
both objects were different by using dir() and printing it out to the
console, hence the reason I now placed both objects inside a str() in
hopes it may work, but alas, it does not.  If I put it as 3 == 3, it
resolves as True.  Any ideas?  Placed in str() along with dir(), both
objects are now equal, but the IF statement sees otherwise.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 to prepopulate admin form with default data?

2010-08-21 Thread widoyo
Hello Gondor,

If you mean 'admin model' is http://localhost:8000/admin/ (Django
Admin page)

your problem solution is mentioned in this docs:
http://docs.djangoproject.com/en/1.2/ref/contrib/admin/#modeladmin-methods

Widoyo

On Aug 21, 2:57 pm, gondor  wrote:
> class Notes(models.Model):
>   name = models.ForeignKey('name', blank=True, null=True)
>   text = models.TextField('Text',blank=True)
>   date = models.DateField(blank=True, default=datetime.date.today());
>
> I have a simple admin model for inputting a note with a date into the
> database.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



check email duplication at registration

2010-08-21 Thread John Yeukhon Wong
I don't think this code is working properly

from django import forms
from django.contrib.auth.models import User

def clean_email(self):
email = self.cleaned_data['email']
try:
User.objects.get(email=email)
except User.DoesNotExist:
return email
raise forms.ValidationError('This email address has been
registered with an existing user.')



How should I rewrite it properly? 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-us...@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: mutually referential models

2010-08-21 Thread widoyo

Just add quote into your model that you do not defined yet.

On Aug 22, 12:26 am, Andy Howell  wrote:
>
> class Computer(models.Model):
>     name = models.CharField(max_length=80)
>     description = models.CharField(max_length=80, null=True)
>     interfaces = models.ManyToManyField(ComputerInterface)
>
 interfaces = models.ManyToManyField('ComputerInterface')

Widoyo

> class ComputerInterface(Node):
>     ipAddr = models.IPAddressField(null=True)
>     mbitsPerSec = models.IntegerField(null=True)
...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Touch-ing django.wsgi doesn't reliably reload source code

2010-08-21 Thread Graham Dumpleton


On Aug 22, 12:07 am, Jim  wrote:
> Hello,
>
> I have Django running under apache2 (the worker version, I believe,
> with MaxRequestsPerChild set to the default, which is 0).  I am using
> mod_wsgi in daemon mode.  I have checked that it is daemon mode using
> the method described on mod_wsgi's ReloadingSourceCode page.
>
> I need to do a nightly refresh because I get data for the db from a
> coworker somewhere else.  So I have a cron job that does as follows.
>
>   (1) Sets a flag "SITE_UP=False" in the code base file "site_up.py"
> that shows up in each RequestContext, causing each dynamic page to say
> "site is not up" since base.html looks for that flag {{SITE_UP}}.
>   (2) Touches django.wsgi so pages will tell visitors the site is not
> up.
>   (3) Updates the dB
>   (4) Sets the flag from (1) back to its starting value
> "SITE_UP=True".
>   (5) Touches django.wsgi.
>
> (Step (3) takes perhaps a half hour.  If there is a better way to do
> what I am trying to do, I'd be very glad to hear it.)
>
> The problem is: I come in the next morning and sometimes the pages
> work, while sometimes they say "Site is no up".
>
> If I keep refreshing a page in my browser then sometimes it works
> correctly and gives me the new data, and sometimes it says "not up."
>
> If I restart apache, the problem of showing "not up" disappears.
>
> I had thought that Apache's children talk to the wsgi processes (I
> have 4 of them), which mod_wsgi's ReloadingSourceCode page tells me
> will be restarted.    But obviously I'm not understanding something.
>
> I wonder if anyone has a suggestion about how I am going wrong?  I was
> hopeful of finding a way to accomplish this without having to restart
> apache from a cron job.

Set Apache directive LogLevel to 'info' instead or 'warn'. This will
cause mod_wsgi to log information about when it is restarting
processes. Analyse that and see if anything stands out.

BTW, what version of mod_wsgi are you using? Update to mod_wsgi 3.3 if
you are using an old version.

Graham

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: searching stackedinline fields via search_fields in admin

2010-08-21 Thread gondor
Here is what i'm trying to do:  I've looked at my code and I don't
have a foreign key out reference from my model thus cannot find the
inline fields.   reverse reference doens't seem to work either

class CarRadio(modesl.Model):
  name = models.ForeignKey('Car');
  id = models.CharField(max_length='10', blank=True)


class Car(models.Model):
  owner = CharField(max_length='10')
  name = CharField(max_length='10')
  model = CharField(max_length='10')
  typeofwheels = CharField(max_length='10')
  ...


class CarAdmin(admin.Model):
  list_filter = {'model', 'name', 'typeofwheels'}< --  I want to
add list_filter from CarRadioInline here
  search_fileds = {'model', 'name',}< --  I wanted to add search
fields from CarRadioInline here
  inlines = [ CarRadioInline, ]


class CarRadioInline(admin.StackedInline):
  model = CarRadio
  extra = 1
  fieldset = ((None, {'fields': (('name', 'id'))})

thanx

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Need some help with URL layout

2010-08-21 Thread Uwe Schuerkamp
thanks for your comments guys, I guess I'm more or less on the right
track!

All the best,

Uwe

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Ability to use PSP templates with Django?

2010-08-21 Thread hcarvalhoalves
There are 2 approaches:

- Think data structures instead, and put all this logic on your view,
such that the template just needs to iterate thru one variable to
build the menu. Something like passing in the template context:

menu = [{'name': 'django', 'text': 'Official Django Site', 'url':
'http://djangoproject.com/'}, ...]

- Write template tags for building the menu. This is the cleanest
approach, as you comprise all menu logic in a reusable tag.

On 20 ago, 18:00, Kevin  wrote:
> I come from the world of mod_python and really enjoyed the PSP
> template system, where I can embed Python code directly in my template
> for dynamically generating menus and such.
>
> What is the recommended method of calling a PSP template from inside
> Django and rendering it?
>
> Here is a sniplet of code I am trying to convert over to the Django
> template engine, but cannot figure out the best method:
>
> for name, text, url in menu_items:
>     attr = ""
>     if name == hlight:
>         attr = "class='highlight'"
>     # begin
> %>
>             ><%=text%> tr>
> <%
> # end
> %>
>
> And yes, this menu code is from the mod_python example site.  Also
> does Django include an example fully working site to display most, if
> not all of it's abilities?  The example site which mod_python includes
> is very simple, but is a great starting point for a website.
>
> mod_python's example site is here:  http://modpython.org/examples/
>
> I really think having such an example for django would be good as
> well.  I am actually in the process of basically re-creating this
> example site in django to learn how django works and how it differs
> from mod_python coding.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Need some help with URL layout

2010-08-21 Thread Steve Holden
On 8/21/2010 1:39 PM, widoyo wrote:
> It could be better if you omit '_ALL' at URL
> 
> So:
> /ranking/de/ # for Germany ranking Nation wide
> /ranking/ # for all country
> 
> can put summary of ranking for such URL, instead of list of all
> ranking nation or all country.
> 
The  point being, you can start out with a queryset that specifies all
items, then optionally apply filters for the restrictions specified in
the URL. Querysets are"lazy" (they don't actually touch the database
until they *have* to) so this isn't going to involve huge database
queries except when you try to rank across all countries.

regards
 Steve


> Widoyo
> 
> On Aug 21, 7:35 am, Uwe Schuerkamp  wrote:
>> ranking/de/hf   Country: Germany, District: Herford (I'll be using
>> german number plates here to discriminate among districts
>> /ranking/de/_ALL Nation-Wide Ranking for Germany
>> /ranking/gr/agnAgios Nikolaos, Greece: Ranking of observers in
>> Agios Nik. on Crete, Greece
>> /ranking/_ALL/_ALL  world-wide ranking
>>
> 


-- 
DjangoCon US 2010 September 7-9 http://djangocon.us/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Ability to use PSP templates with Django?

2010-08-21 Thread Albert Hopkins
On Fri, 2010-08-20 at 14:00 -0700, Kevin wrote:
> I come from the world of mod_python and really enjoyed the PSP
> template system, where I can embed Python code directly in my template
> for dynamically generating menus and such.
> 
> What is the recommended method of calling a PSP template from inside
> Django and rendering it?
> 
> Here is a sniplet of code I am trying to convert over to the Django
> template engine, but cannot figure out the best method:
> 
> for name, text, url in menu_items:
> attr = ""
> if name == hlight:
> attr = "class='highlight'"
> # begin
> %>
> ><%=text%> tr>
> <%
> # end
> %>
> 
> And yes, this menu code is from the mod_python example site.  Also
> does Django include an example fully working site to display most, if
> not all of it's abilities?  The example site which mod_python includes
> is very simple, but is a great starting point for a website.
> 
> mod_python's example site is here:  http://modpython.org/examples/
> 
> I really think having such an example for django would be good as
> well.  I am actually in the process of basically re-creating this
> example site in django to learn how django works and how it differs
> from mod_python coding.
> 

Django has it's own templating system.  You can use others, but if
you're just starting off it's probably best to stick with what's
built-in.  Like most toolkits, there is no 1-to-1 translation between
PSP and Django.  They are indeed very different beasts. You are best off
just learning how things work in Django and adapting to its methods and
idiosyncrasies.  

Have you actually visited the Django web site[1]?  There are tutorials
and API docs and other examples.  A once-through at the tutorial should
give you a good idea how Django's templates and PSP differ. That should
help you get started such that at least you can ask more concrete
questions.

[1] http://www.djangoproject.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-us...@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: Enter a field in the database after encryption

2010-08-21 Thread widoyo
refer to this docs:

http://docs.djangoproject.com/en/1.2/ref/contrib/admin/#modeladmin-methods

Use

def save_model(self, ...):
mymodel.password = # put your md5 encrypted here ...
mymodel.save()

Widoyo

On Aug 21, 11:05 pm, Amitanshu  wrote:
> Actually I missed something in my post, writing it again :
>
>  got entered in encrypted format (like md5) "in database".>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: mutually referential models

2010-08-21 Thread Karen Tracey
On Sat, Aug 21, 2010 at 1:26 PM, Andy Howell wrote:

> Is there a way I can refer to a class not yet defined?


Yes, see:
http://docs.djangoproject.com/en/1.2/ref/models/fields/#module-django.db.models.fields.related

The paragraph that starts "If you need to create a relationship on a model
that has not yet been defined..."

However, I'm not sure that is what you want. You have shown both a
many-to-many relationship (defined in Computer) between Computer and
ComputerInterface, and a one-to-one relationship (defined in
ComputerInteface) between these same two models. That sounds a bit odd.
Perhaps if you described in prose English the relationship you are looking
to define between these things, someone would be able to help with the
Django field definitions to match.

Karen
-- 
http://tracey.org/kmt/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Need some help with URL layout

2010-08-21 Thread widoyo
It could be better if you omit '_ALL' at URL

So:
/ranking/de/ # for Germany ranking Nation wide
/ranking/ # for all country

can put summary of ranking for such URL, instead of list of all
ranking nation or all country.

Widoyo

On Aug 21, 7:35 am, Uwe Schuerkamp  wrote:
> ranking/de/hf   Country: Germany, District: Herford (I'll be using
> german number plates here to discriminate among districts
> /ranking/de/_ALL     Nation-Wide Ranking for Germany
> /ranking/gr/agn    Agios Nikolaos, Greece: Ranking of observers in
> Agios Nik. on Crete, Greece
> /ranking/_ALL/_ALL  world-wide ranking
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



mutually referential models

2010-08-21 Thread Andy Howell
As a test application to learn Django, I'm trying to model a network of 
computers,
switches, patch panels and the connections between them. As a start, I have:


class Node(models.Model):
name = models.CharField(max_length=80)
description = models.CharField(max_length=80, null=True)
nodeLeft = models.ForeignKey('self')
nodeRight = models.ForeignKey('self')
# name of wire connecting to left and right nodes
labelLeft = models.CharField(max_length=20, null=True)
labelRight = models.CharField(max_length=20, null=True)

class Computer(models.Model):
name = models.CharField(max_length=80)
description = models.CharField(max_length=80, null=True)
interfaces = models.ManyToManyField(ComputerInterface)

class ComputerInterface(Node):
ipAddr = models.IPAddressField(null=True)
mbitsPerSec = models.IntegerField(null=True)
computer = models.OneToOneField(Computer)

I run into a problem because ComputerInterface is not defined at the time its 
needed for
the "Computer" class:

  File "/home/andy/src/django-test/netlist/nodes/models.py", line 17, in 
Computer
interfaces = models.ManyToManyField(ComputerInterface)
NameError: name 'ComputerInterface' is not defined

Is there a way I can refer to a class not yet defined?

Thanks,

Andy

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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-Cms Installation Error

2010-08-21 Thread Marek Dudek

You have django 1.2.1, now I noticed
I wasn't able to install any version of django-cms with django 1.2.1 and 
I tried 2.0.0, 2.0.1, 2.0.2 and 2.1.0-beta3
Most up-to-date combination that I successfully installed is django 
1.1.1 with django-cms 2.0.2.

Hope this helps


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@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-Cms Installation Error

2010-08-21 Thread Marek Dudek

Hello

Your django version doesn't match django-cms version.
You didn't specify which you are using so it's hard to say what you 
should change.

I encountered this problem and written a message some time ago.
It contains the table with matching versions that should help you.

Marek Dudek

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@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: searching stackedinline fields via search_fields in admin

2010-08-21 Thread !!CONDORIOUS!!
Hello Karen,

You are right.  I'll try that when I get home.  I knew that solution
and even applied it in another model but because I was blinded by the
stackedline.

thank you both

Condor

On Sat, Aug 21, 2010 at 5:34 AM, Karen Tracey  wrote:
> On Sat, Aug 21, 2010 at 2:01 AM, Condorious  wrote:
>>
>> My goal is to add search to stackedinline in addition to the common
>> standard search fields.  If admin model knows enough to stackinline the
>> right stackedinline model, we should be able to
>> Search it as well.  I just need someone to point me in the right direction
>> or some me some sample code that does it
>
> I am not sure what you are looking for beyond ringmeup's example. That
> example shows the syntax (double underscore) for listing related fields to
> be searched in search_fields. This syntax works for both forward and
> backwards relationships. In the example, Books are presumably listed inline
> on an Author's admin change page, and the very last ModelAdmin definition
> includes the title of the author's books among the search fields. So
> searching on the authors change list page will include searching on a model
> field that may be listed among its inline information.
>
> There is nothing automatic that will populate search_fields with such
> fields, if that is what you are looking for. There is also no requirement
> that the related models for such fields be included as inlines in the model
> admin, so you could include book titles among the author's search fields
> even if books were not listed inline on the Author's change page.
>
> Karen
> --
> http://tracey.org/kmt/
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>



-- 
Condor
310.951.1177
condor.c...@gmail.com

:%s/war/peace/g

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Enter a field in the database after encryption

2010-08-21 Thread Amitanshu
Actually I missed something in my post, writing it again :



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Enter a field in the database after encryption

2010-08-21 Thread Amitanshu
Hi All,
I am new to Django and while making an app in Django I got
stuck at one point. What I was trying to do is to have 3 fields in my
app, username, password and age. I want that if I enter my password
(through admin page of my app) it got entered in encrypted format
(like md5). If anyone of you have any idea how can I do this, that
will be a great help.

Thanks in advance,
Ami

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Touch-ing django.wsgi doesn't reliably reload source code

2010-08-21 Thread Jim
Hello,

I have Django running under apache2 (the worker version, I believe,
with MaxRequestsPerChild set to the default, which is 0).  I am using
mod_wsgi in daemon mode.  I have checked that it is daemon mode using
the method described on mod_wsgi's ReloadingSourceCode page.

I need to do a nightly refresh because I get data for the db from a
coworker somewhere else.  So I have a cron job that does as follows.

  (1) Sets a flag "SITE_UP=False" in the code base file "site_up.py"
that shows up in each RequestContext, causing each dynamic page to say
"site is not up" since base.html looks for that flag {{SITE_UP}}.
  (2) Touches django.wsgi so pages will tell visitors the site is not
up.
  (3) Updates the dB
  (4) Sets the flag from (1) back to its starting value
"SITE_UP=True".
  (5) Touches django.wsgi.

(Step (3) takes perhaps a half hour.  If there is a better way to do
what I am trying to do, I'd be very glad to hear it.)

The problem is: I come in the next morning and sometimes the pages
work, while sometimes they say "Site is no up".

If I keep refreshing a page in my browser then sometimes it works
correctly and gives me the new data, and sometimes it says "not up."

If I restart apache, the problem of showing "not up" disappears.

I had thought that Apache's children talk to the wsgi processes (I
have 4 of them), which mod_wsgi's ReloadingSourceCode page tells me
will be restarted.But obviously I'm not understanding something.

I wonder if anyone has a suggestion about how I am going wrong?  I was
hopeful of finding a way to accomplish this without having to restart
apache from a cron job.

Thank you,
Jim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Path mess

2010-08-21 Thread clochemer
Thanks a lot! I was lost with paths and all that. You really helped me
to solve my problems!

On Aug 21, 1:44 pm, Steve Holden  wrote:
> On 8/21/2010 4:52 AM, clochemer wrote:
>
>
>
> > Thanks for your quick replies. You helped me to understand what is
> > happening.
>
> > However, I can not make all work together. Let me explain the problems
> > that I am having right now...
>
> > I wrote a piece of code in a folder within my django project path just
> > like this:
>
> > /home/myproject/utils/commserver.py
>
> > So using my new knowledge I wrote a program just like this:
>
> > import os, sys
>
> > sys.path.append("/home/myproject")
>
> The effect of this statement is to allow the import of any module (or
> package) in the /home/myproject directory.
>
> > os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
>
> This would imply that your settings.py lives in
>
> /home/myproject/myproject/
>
> if you want to use the path entry you just added. Is this in fact the
> case? Usually, for testing, you can rely on the fact that the directory
> containing the program you run (manage.py) is added to sys.path
> automatically by the interpreter, and there is no need to muck about
> with sys.path. And there would be no need to set the
> DJANGO_SETTINGS_MODULE manually either.
>
> > #I need the models form an application
> > #the aplication is included in INSTALLED_APPS
> > #importing models like this "from myproject.models import * raises the
> > same error
> > #i imported * just for testing purposes
> > from myproject.app.models import *
>
> > and the following error is raised:
> > ImportError: No module named myproject.app.models
> > #/home/myproject/app/models.py do exist
>
> In which case you should be adding /home to sys.path if you add
> anything. But that's not a terribly good idea.
>
> Try removing the sys.path.append and the os.environ setting, and then use
>
> from models import *
>
> (though in fact importing specific names is much better, and it's
> actually quite unusual to have a models.py in the top-level project
> directory - but I see you already know that. Sorry!), and
>
> from app.models import *
>
> > i also tried to import something from django, so I removed the
> > previous import and i wrote:
> > from django.db.models import *
> > and the following error is raised
> > raise ImportError("Could not import settings '%s' (Is it on sys.path?
> > Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e))
> > ImportError: Could not import settings 'myproject.settings' (Is it on
> > sys.path? Does it have syntax errors?): No module named
> > myproject.settings
>
> > Is it on sys.path? Yes Sir, i appended to sys.path
> > Does it have syntax errors? I believe not Sir.
>
> > And now is when i understand nothing.
>
> I think you are simply slightly confused about the Python sys.path.
>
> I hope this has helped. You'll get there soon - keep trying!
>
> regards
>  Steve
>
>
>
> > On Aug 20, 11:02 pm, Shawn Milochik  wrote:
> >> If you set your environment variable DJANGO_SETTINGS_MODULE in the
> >> environment your script is running in, you need only add this line to
> >> your script (in addition to your model imports, of course).
>
> >> from django.conf import settings
>
> >> Otherwise you'll need to import the OS module in your script and add a
> >> line like this:
>
> >> os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
>
> >> Note that, in either case, you need to ensure that the proper path has
> >> been added to your PYTHONPATH.
>
> >> More detail, since you said you weren't quite a Python pro yet.
>
> >> Prerequisite
>
> >>     Ensure that your project folder is on your PYTHONPATH.
> >>     Example:
>
> >>         #at the command line, not in your script
> >>         export PYTHONPATH=/home/name/projects:$PYTHONPATH
>
> >>     Solution #1:
> >>         #at the command line, not in your script
> >>         export DJANGO_SETTINGS_MODULE='myproject.settings'
>
> >>         Now you can just do this in your script:
> >>         from django.conf import settings
>
> >>     Solution #2:
>
> >>         #in your script, not on the command line
> >>         import os
> >>         os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
>
> >> To me, solution 1 is easier, and cleaner, because if you change your
> >> settings file you don't have to change all your scripts. However, you
> >> may not have the ability to change the environment if you have
> >> multiple Django projects and don't want to break all the other ones.
>
> >> Shawn
>
> --
> DjangoCon US 2010 September 7-9http://djangocon.us/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Create files and directories from Django 1.2.1

2010-08-21 Thread Doug Blank
On Mon, Aug 16, 2010 at 8:51 PM, Mike Dewhirst  wrote:
> On 16/08/2010 10:22pm, Doug Blank wrote:
>>
>> On Mon, Aug 16, 2010 at 7:23 AM, Mark Mooij  wrote:
>>>
>>> Allright I tried a couple of things with your suggested appraoch:
>>>
>
> 
>
>>
>> I doubt it. You shouldn't really do this:
>>
>> kmlpath = "%s/%s" % (basepath, game_id)
>
> I suggested this to avoid having to cast game_id as a string. I'm not all
> that knowledgeable about the upcoming Python 3 tsunami but I figure there
> will be less hassle if I use the inbuilt string formatting in %s. At least I
> hope so!
>
>>
>> but do this:
>>
>> kmlpath = os.path.join(basepath, game_id)
>
> Now I have a question - more Python than Django. os.path.join is very clever
> but in Windows we have multiple approaches. One is to simply use forward
> slashes and rely on the infrastructure to know what to do and the other is
> to be agnostically cross-platform with os.path.sep and os.path.join. We can
> also use r'raw\backslashes' and u'C:\\escaped\\backslashes'
>
> I have come unstuck using all of them at one time or another. I can't quite
> put my finger on it at the moment but I have also seen things like
> 'C:\path\to/some/file.txt' arising from combinations of the approaches and
> surprisingly being successful.
>
> So my question is, has anyone written a dissertation on the best approaches
> for particular circumstances?

Always use os.path.join and you will (almost) never go wrong, and will
work cross-platform. If you need to make something into a string, use:

kmlpath = os.path.join(basepath, str(item1), str(game_id), str(subthing))

One caveat is that the encoding of a string versus the file system
encoding can differ, so you might need something different than str or
unicode. But that doesn't sound like it is your original problem.

-Doug

> Mike
>
>>
>> as different OS's have different path formats. Or perhaps it is the
>> kml string that you are creating that has other issues (unicode?) I
>> would print out the mkdirs string to see what you are creating.
>>
>> HTH,
>>
>> -Doug
>>
>>> Mark
>>>
>>> On 16 aug, 08:32, Mike Dewhirst  wrote:

 On 16/08/2010 12:57pm, Mike Dewhirst wrote:





> On 16/08/2010 1:06am, Mark Mooij wrote:
>>
>> Hi Mike,

>> Thanks for your reply. I haven't changed anything else, I am
>> processing the MS updates, but I don't think this is the problem, as
>> this all worked fine before the migration to 1.2.1, also if I call the
>> script directly (outside Django) it works fine.
>> My view looks like this:
>> ..
>> import createKML
>> ..
>> def my_view(request, arg):
>> ...
>> createKML.createKML(arg)

> I don't really know what is happening here that might have changed in
> 1.2.1 maybe someone else can suggest something.

> In the meantime here is suggested approach to discovering the exact
> problem ...

> import os
> ...
> def createKML(id, basepath="D:/path/to/mysite/templates/maps"):
> ...
> try:
> if id:
> kmlpath = "%s/%s" % (basepath, str(id))

 actually .. kmlpath = "%s/%s" % (basepath, id)

> if not os.path.isdir(kmlpath):
> os.makedirs(kmlpath)
> writefile = "%s/%s" % (kmlpath, str(id))

 actually .. writefile = "%s/%s" % (kmlpath, id)



> f = open(writefile, 'wb')
> else:
> raise
> except Exception as e:
> print("id = %s\nbasepath = %s\n%s" % (id, basepath, e)
> ...

> mike

>> ...

>> In the createKML.py the problem arises in:
>> ...
>> import os
>> ...
>> def createKML(id):
>> ...
>> os.mkdir("D:/path/to/mysite/templates/maps/"+str(id))
>> writefile = "D:/path/to/mysite/templates/maps/"+str(id)+"/"+str(id)
>> + ".kml"
>> f = open(writefile, 'wb')
>> ...

>> I hope this helps?

>> On 14 aug, 21:55, Mike Dewhirst  wrote:
>>>
>>> On 15/08/2010 12:10am, Mark Mooij wrote:

 Hi all,

 I recently migrated from Django 1.1.1 to 1.2.1. In 1.1.1 I had an
 application which imports an external python script in which a
 directory and some files are created. Since the migrate this doesn't
 work anymore, I get a number of IOErrors because the files (and
 directory) that should be created can't be found. I've tried
 changing
 my directories and slashes (I'm using Windows), but no success.

>>> Have you changed anything else?

>>> For example, are you processing the Microsoft Windows update patches
>>> which (for WinXP) insert extra permission steps? Have you changed
>>> your
>>> OS from XP to Win7?

>>> Can you post the source of the script?

 Can't I use the os python functions anymore in Django 1.2.1? In the
 documentation I've read about Managing files in models but I prefer
 to
 handle this thr

Re: Django-Cms Installation Error

2010-08-21 Thread Karen Tracey
On Sat, Aug 21, 2010 at 7:11 AM, Jagdeep Singh Malhi <
singh.malh...@gmail.com> wrote:

> I try to Install the Django-Cms using this link
> http://www.django-cms.org/en/documentation/2.0/installation/
>
> I face this error. I am able understand this error
>
> ERROR is : -
> {
> ImproperlyConfigured at /
>
> 'PageAdmin.exclude' refers to field 'created_by' that is missing from
> the form.
>
> Request Method: GET
> Request URL:http://localhost/django/
> Django Version: 1.2.1
> Exception Type: ImproperlyConfigured
> Exception Value:
>
> 'PageAdmin.exclude' refers to field 'created_by' that is missing from
> the form.
>

This is likely due to the fix for this ticket:
http://code.djangoproject.com/ticket/12689, which added validation of
ModelAdmin exclude specifications. Apparently django-cms 2.0 included such
an invalid specification which used to pass unnoticed before this fix went
into Django. It seems to have been fixed in django-cms: this thread in the
django-cms group:
http://groups.google.com/group/django-cms/browse_thread/thread/184a957224cd1a96/notes
that you need to be using django-cms 2.1.x if you are using Django
1.2.x.

Karen
-- 
http://tracey.org/kmt/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: searching stackedinline fields via search_fields in admin

2010-08-21 Thread Karen Tracey
On Sat, Aug 21, 2010 at 2:01 AM, Condorious  wrote:

> My goal is to add search to stackedinline in addition to the common
> standard search fields.  If admin model knows enough to stackinline the
> right stackedinline model, we should be able to
> Search it as well.  I just need someone to point me in the right direction
> or some me some sample code that does it
>
>
I am not sure what you are looking for beyond ringmeup's example. That
example shows the syntax (double underscore) for listing related fields to
be searched in search_fields. This syntax works for both forward and
backwards relationships. In the example, Books are presumably listed inline
on an Author's admin change page, and the very last ModelAdmin definition
includes the title of the author's books among the search fields. So
searching on the authors change list page will include searching on a model
field that may be listed among its inline information.

There is nothing automatic that will populate search_fields with such
fields, if that is what you are looking for. There is also no requirement
that the related models for such fields be included as inlines in the model
admin, so you could include book titles among the author's search fields
even if books were not listed inline on the Author's change page.

Karen
-- 
http://tracey.org/kmt/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Need some help with URL layout

2010-08-21 Thread Uwe Schuerkamp
Hi folks,

please excuse this long-winded post, but I'm a bit stuck with the
layout of my urls.py. Let me try to explain what the site I'm using
Django for does at the moment: Basically it's a website where local
birdwatchers (the ones with feathers, not boobies ;-) can log their
observations. By "local", I mean the local district of Herford.

Noiw after several months of the site being live, I keep getting
requests from users to widen the site's scope to all of Germany or
even world-wide, which I think is a rather nice idea. So right now the
entire site lives under a common URL called "ranking", so I thought I
could restrict and calculate local and nationwide rankings using the
following URL structure:

ranking/de/hf   Country: Germany, District: Herford (I'll be using
german number plates here to discriminate among districts
/ranking/de/_ALL Nation-Wide Ranking for Germany
/ranking/gr/agnAgios Nikolaos, Greece: Ranking of observers in
Agios Nik. on Crete, Greece
/ranking/_ALL/_ALL  world-wide ranking

I hope you get the idea.

Ideally, I'd use the url structure to restrict the list of birds,
observations, observers and region by whatever the user provides in
the request.

I've read about mappings that you can use to pass parameters into
functions in urls.py (for instance, {"region": "_ALL"} if only a
country code is provided in the URL), but of course that means I have
to check those parameters in each and every view I write, filter()ing
and excluding within the view as I retrieve the applicable objects
from the database, which seems rather cumbersome and probably breaks
the DRY principle in a big way.

So here's my question as a relative Django noob: Is this the best way
to go about such a layout, or am I missing some critical feature
Django provides already and that I just don't know about yet? I've
read the Definite Guide to Django Book front to back FWIW.

All the best & thanks in advance for your comments & ideas,

Uwe

PS: The site in question is available at http://www.birders-hf.de/ranking/
just in case you want to check it out.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Ability to use PSP templates with Django?

2010-08-21 Thread Kevin
I come from the world of mod_python and really enjoyed the PSP
template system, where I can embed Python code directly in my template
for dynamically generating menus and such.

What is the recommended method of calling a PSP template from inside
Django and rendering it?

Here is a sniplet of code I am trying to convert over to the Django
template engine, but cannot figure out the best method:

for name, text, url in menu_items:
attr = ""
if name == hlight:
attr = "class='highlight'"
# begin
%>
><%=text%>
<%
# end
%>

And yes, this menu code is from the mod_python example site.  Also
does Django include an example fully working site to display most, if
not all of it's abilities?  The example site which mod_python includes
is very simple, but is a great starting point for a website.

mod_python's example site is here:  http://modpython.org/examples/

I really think having such an example for django would be good as
well.  I am actually in the process of basically re-creating this
example site in django to learn how django works and how it differs
from mod_python coding.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Path mess

2010-08-21 Thread Steve Holden
On 8/21/2010 4:52 AM, clochemer wrote:
> Thanks for your quick replies. You helped me to understand what is
> happening.
> 
> However, I can not make all work together. Let me explain the problems
> that I am having right now...
> 
> I wrote a piece of code in a folder within my django project path just
> like this:
> 
> /home/myproject/utils/commserver.py
> 
> So using my new knowledge I wrote a program just like this:
> 
> import os, sys
> 
> sys.path.append("/home/myproject")

The effect of this statement is to allow the import of any module (or
package) in the /home/myproject directory.

> os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
> 
This would imply that your settings.py lives in

/home/myproject/myproject/

if you want to use the path entry you just added. Is this in fact the
case? Usually, for testing, you can rely on the fact that the directory
containing the program you run (manage.py) is added to sys.path
automatically by the interpreter, and there is no need to muck about
with sys.path. And there would be no need to set the
DJANGO_SETTINGS_MODULE manually either.

> #I need the models form an application
> #the aplication is included in INSTALLED_APPS
> #importing models like this "from myproject.models import * raises the
> same error
> #i imported * just for testing purposes
> from myproject.app.models import *
> 
> and the following error is raised:
> ImportError: No module named myproject.app.models
> #/home/myproject/app/models.py do exist
> 
In which case you should be adding /home to sys.path if you add
anything. But that's not a terribly good idea.

Try removing the sys.path.append and the os.environ setting, and then use

from models import *

(though in fact importing specific names is much better, and it's
actually quite unusual to have a models.py in the top-level project
directory - but I see you already know that. Sorry!), and

from app.models import *

> i also tried to import something from django, so I removed the
> previous import and i wrote:
> from django.db.models import *
> and the following error is raised
> raise ImportError("Could not import settings '%s' (Is it on sys.path?
> Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e))
> ImportError: Could not import settings 'myproject.settings' (Is it on
> sys.path? Does it have syntax errors?): No module named
> myproject.settings
> 
> Is it on sys.path? Yes Sir, i appended to sys.path
> Does it have syntax errors? I believe not Sir.
> 
> And now is when i understand nothing.
> 
I think you are simply slightly confused about the Python sys.path.

I hope this has helped. You'll get there soon - keep trying!

regards
 Steve

> On Aug 20, 11:02 pm, Shawn Milochik  wrote:
>> If you set your environment variable DJANGO_SETTINGS_MODULE in the
>> environment your script is running in, you need only add this line to
>> your script (in addition to your model imports, of course).
>>
>> from django.conf import settings
>>
>> Otherwise you'll need to import the OS module in your script and add a
>> line like this:
>>
>> os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
>>
>> Note that, in either case, you need to ensure that the proper path has
>> been added to your PYTHONPATH.
>>
>> More detail, since you said you weren't quite a Python pro yet.
>>
>> Prerequisite
>>
>> Ensure that your project folder is on your PYTHONPATH.
>> Example:
>>
>> #at the command line, not in your script
>> export PYTHONPATH=/home/name/projects:$PYTHONPATH
>>
>> Solution #1:
>> #at the command line, not in your script
>> export DJANGO_SETTINGS_MODULE='myproject.settings'
>>
>> Now you can just do this in your script:
>> from django.conf import settings
>>
>> Solution #2:
>>
>> #in your script, not on the command line
>> import os
>> os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
>>
>> To me, solution 1 is easier, and cleaner, because if you change your
>> settings file you don't have to change all your scripts. However, you
>> may not have the ability to change the environment if you have
>> multiple Django projects and don't want to break all the other ones.
>>
>> Shawn
> 


-- 
DjangoCon US 2010 September 7-9 http://djangocon.us/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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-Cms Installation Error

2010-08-21 Thread Jagdeep Singh Malhi
sorry, I am  not able understand this error.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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-Cms Installation Error

2010-08-21 Thread Jagdeep Singh Malhi
I try to Install the Django-Cms using this link
http://www.django-cms.org/en/documentation/2.0/installation/

I face this error. I am able understand this error

ERROR is : -
{
ImproperlyConfigured at /

'PageAdmin.exclude' refers to field 'created_by' that is missing from
the form.

Request Method: GET
Request URL:http://localhost/django/
Django Version: 1.2.1
Exception Type: ImproperlyConfigured
Exception Value:

'PageAdmin.exclude' refers to field 'created_by' that is missing from
the form.

Exception Location: /usr/local/lib/python2.6/dist-packages/django/
contrib/admin/validation.py in check_formfield, line 361
Python Executable:  /usr/bin/python
Python Version: 2.6.5
Python Path:['/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2',
'/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/
python2.6/lib-dynload', '/usr/lib/python2.6/dist-packages', '/usr/lib/
python2.6/dist-packages/PIL', '/usr/lib/python2.6/dist-packages/
gst-0.10', '/usr/lib/pymodules/python2.6', '/usr/lib/python2.6/dist-
packages/gtk-2.0', '/usr/lib/pymodules/python2.6/gtk-2.0', '/usr/lib/
python2.6/dist-packages/wx-2.6-gtk2-unicode', '/usr/local/lib/
python2.6/dist-packages', '/home/jagdeep/']
Server time:Sat, 21 Aug 2010 06:01:24 -0500
}

Please Help

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Path mess

2010-08-21 Thread clochemer
Thanks for your quick replies. You helped me to understand what is
happening.

However, I can not make all work together. Let me explain the problems
that I am having right now...

I wrote a piece of code in a folder within my django project path just
like this:

/home/myproject/utils/commserver.py

So using my new knowledge I wrote a program just like this:

import os, sys

sys.path.append("/home/myproject")
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'

#I need the models form an application
#the aplication is included in INSTALLED_APPS
#importing models like this "from myproject.models import * raises the
same error
#i imported * just for testing purposes
from myproject.app.models import *

and the following error is raised:
ImportError: No module named myproject.app.models
#/home/myproject/app/models.py do exist

i also tried to import something from django, so I removed the
previous import and i wrote:
from django.db.models import *
and the following error is raised
raise ImportError("Could not import settings '%s' (Is it on sys.path?
Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'myproject.settings' (Is it on
sys.path? Does it have syntax errors?): No module named
myproject.settings

Is it on sys.path? Yes Sir, i appended to sys.path
Does it have syntax errors? I believe not Sir.

And now is when i understand nothing.

On Aug 20, 11:02 pm, Shawn Milochik  wrote:
> If you set your environment variable DJANGO_SETTINGS_MODULE in the
> environment your script is running in, you need only add this line to
> your script (in addition to your model imports, of course).
>
> from django.conf import settings
>
> Otherwise you'll need to import the OS module in your script and add a
> line like this:
>
> os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
>
> Note that, in either case, you need to ensure that the proper path has
> been added to your PYTHONPATH.
>
> More detail, since you said you weren't quite a Python pro yet.
>
> Prerequisite
>
>     Ensure that your project folder is on your PYTHONPATH.
>     Example:
>
>         #at the command line, not in your script
>         export PYTHONPATH=/home/name/projects:$PYTHONPATH
>
>     Solution #1:
>         #at the command line, not in your script
>         export DJANGO_SETTINGS_MODULE='myproject.settings'
>
>         Now you can just do this in your script:
>         from django.conf import settings
>
>     Solution #2:
>
>         #in your script, not on the command line
>         import os
>         os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
>
> To me, solution 1 is easier, and cleaner, because if you change your
> settings file you don't have to change all your scripts. However, you
> may not have the ability to change the environment if you have
> multiple Django projects and don't want to break all the other ones.
>
> Shawn

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



how to prepopulate admin form with default data?

2010-08-21 Thread gondor
class Notes(models.Model):
  name = models.ForeignKey('name', blank=True, null=True)
  text = models.TextField('Text',blank=True)
  date = models.DateField(blank=True, default=datetime.date.today());



I have a simple admin model for inputting a note with a date into the
database.
date is prepopulated automatically with the current timestamp.  I want
to
automatically prepopulate the name with the current logged in user
name.


Does anyone know how to do that?

Any help is appreciated.

Thank you

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.