Re: align a ModelForm

2008-11-04 Thread limas


dear Law,

The admin css worked nicely. But my work is not fullfilled yet.
Actually i have a Model Candidate.
class Candidate(models.Model):
site=models.ForeignKey(Site)
first_name=models.CharField('First Name',max_length=30)
last_name=models.CharField('Last Name',max_length=30)
phone_home=models.CharField(max_length=16)
phone_work=models.CharField(max_length=16)
address=models.CharField(max_length=100)
city=models.CharField(max_length=30)
state=models.CharField(max_length=30)
source=models.CharField(max_length=40)
date_available=models.DateTimeField()
can_relocate=models.BooleanField()
notes=models.CharField(max_length=300)
key_skills=models.CharField(max_length=200)
current_employers=models.CharField(max_length=100)
enter_by=models.CharField(max_length=50)
owner=models.CharField(max_length=50)
date_created=models.DateField(auto_now_add=True)

I create a ModelForm for it, CandidateForm.
There is a Attachment model, it contains a FileField.
What i want is that rearrange the fields in the CandidateForm and
insert a  in between it.
In admin it done through ModelAdmin.
What i want to do here...
please help me..

lima

On 5 Nov, 11:26, "Low Kian Seong" <[EMAIL PROTECTED]> wrote:
> No. Look at the css of the admin that says fieldsets and put your
> fields in the  tags to let the css definitions
> take effect.

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Authenticating static files against Django Auth with FastCGI

2008-11-04 Thread MrJogo

Awesome! This is INCREDIBLY helpful.

In terms of using it (I'm not too familiar with server stuff), I have
a few questions (which have to do with Apache, not lighttpd, so you
might not know). Basically, once I create that handler file and view,
how do I use them? Do I modify the .fcgi file (from
http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#running-django-on-a-shared-hosting-provider-with-apache)
to use the new wsgiserver? Do I create a .htaccess file in my media
directory with FastCgiAuthorizer set to the script (in which case, the
docs, 
http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html#FastCgiAuthorizer,
also say I need FastCgiAuthenticator)? If these questions are somewhat
nonsensical, it's because I don't completely understand what's going
on when a request is made. Thanks!

On Oct 23, 1:37 am, Chris Emerson <[EMAIL PROTECTED]> wrote:
> On Thu, Oct 23, 2008 at 12:05:45AM -0700,MrJogowrote:
>
> > I found a useful thread (http://groups.google.com/group/django-users/
> > browse_thread/thread/affb11a7692a29ef/
> > e1e2d569c1e9104d#016b2fe82fd80f36), so I think I can narrow my
> > question down a little: How do I use FastCgiAuthenticator to
> > authenticate against Django's auth module?
>
> I've done this (I'm using lighttpd).  I've put my code in some snippets:
>
> http://www.djangosnippets.org/snippets/1149/http://www.djangosnippets.org/snippets/1150/
>
> Hope this helps,
>
> Chris
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: align a ModelForm

2008-11-04 Thread Low Kian Seong

No. Look at the css of the admin that says fieldsets and put your
fields in the  tags to let the css definitions
take effect.

On Wed, Nov 5, 2008 at 1:37 PM, limas <[EMAIL PROTECTED]> wrote:
>
>
>
>
>> I have done something similar and I generated my form automatically
>> using 'forms.as_p' then I put in some sections of the css from admin
>> interface's css and it works. The section you want to look at is the
>> fieldset section.
>
> hello Low,
>
> I can't understand what you mentioned clearly. Is i want to make use
> of /django/contrib/admin/templates/admin/includes/fieldset.html file.
> I tried it but failed. How can i specify the fieldset tags by not
> create any fieldsets using ModelAdmin.
> I can't use ModelAdmin for creating my own form to display it in my
> own page.
> Is there any mistake from me?
>
> sorry for my terrible English.
>
> >
>



-- 
Low Kian Seong
blog: http://lowkster.blogspot.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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: align a ModelForm

2008-11-04 Thread limas




> I have done something similar and I generated my form automatically
> using 'forms.as_p' then I put in some sections of the css from admin
> interface's css and it works. The section you want to look at is the
> fieldset section.

hello Low,

I can't understand what you mentioned clearly. Is i want to make use
of /django/contrib/admin/templates/admin/includes/fieldset.html file.
I tried it but failed. How can i specify the fieldset tags by not
create any fieldsets using ModelAdmin.
I can't use ModelAdmin for creating my own form to display it in my
own page.
Is there any mistake from me?

sorry for my terrible English.

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: align a ModelForm

2008-11-04 Thread Low Kian Seong

I have done something similar and I generated my form automatically
using 'forms.as_p' then I put in some sections of the css from admin
interface's css and it works. The section you want to look at is the
fieldset section.

Thanks.

On Tue, Nov 4, 2008 at 8:21 PM, limas <[EMAIL PROTECTED]> wrote:
>
> hello Thomas,
> i tried with ModelAdmin, but it is not working properly in my own
> views.
> i got this error "__init__() got an unexpected keyword argument
> 'instance'"
> hop u understand what my problem is.
> Actually i want to customize my page with a look and feel of django
> admin page. Some modification in the alignment of a single ModelForm.
>
> thank you for ur suggestions.
> i expect u will respond to this reply..
> Lima
>
>
> On 3 Nov, 18:33, Thomas Guettler <[EMAIL PROTECTED]> wrote:
>> limas schrieb:
>>
>> > Can i align a single long ModelForm into two raws?
>> > can i use django admin modules for my own purpose by customizing it?
>> > please give me some suggestions .
>>
>> Yes, you can do both. Suggestion: Read the documentation.
>>
>> Suggestion:http://docs.djangoproject.com/en/dev/ref/contrib/admin/http://groups.google.com/group/django-users/browse_thread/thread/536e...
>>
>>  HTH,
>>   Thomas
>>
>> --
>> Thomas Guettler,http://www.thomas-guettler.de/
>> E-Mail: guettli (*) thomas-guettler + de
> >
>



-- 
Low Kian Seong
blog: http://lowkster.blogspot.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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



How to use post_save signal

2008-11-04 Thread Low Kian Seong

Dear all,

I am using django to write an a web based sales inventory system for
my client. To this end, I have created two objects in my models which
is :

Sales and Stock. Everytime a sales is associated with a particular
stock is created, I want to update the Stock object's status field as
'Sold'. Asking on the #django channel, they suggested I override the
save method for the model which lead me to finally try out the
post_save signal.

I tried out most of the examples and tried to associate my method
which actually will try to get the particular stock object based on
the foreign key entry from Sales and update that object's 'status'
field. This however does not work. I tried to put the
signals.post_save.connect method in my __init__.py file and models.py
file but the code is not executed. Can someone please point me to a
project or url which has a more complete example for using the signals
and post_save? It seems like a very powerful component of the django
architecture.

Thank you in advance.


-- 
Low Kian Seong
blog: http://lowkster.blogspot.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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Caught an exception while rendering: no such table: django_admin_log

2008-11-04 Thread joshuajenkins

Sure thought I had. Dumb mistake, 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Caught an exception while rendering: no such table: django_admin_log

2008-11-04 Thread Colin Bean

On Tue, Nov 4, 2008 at 3:00 PM, joshuajenkins <[EMAIL PROTECTED]> wrote:
>
> I'm running into an issue when just starting with Django 1.0 where the
> following exception is caught:
> Caught an exception while rendering: no such table: django_admin_log
>
> I've done some searching and it appears that this is common if you're
> not running Django 1.0, but 0.96 or lower.
>
> I've verified that I'm running 1.0 by checking at the command line
> (manage.py --version) which outputs 1.0-final-SVN-unkown
>
> Is this a common problem? All I have is a very simple model and a
> modified urls.py file.
>
> Any help would be appreciated.
> >
>


Did you run manage.py syncdb after adding django.contrib.admin to your
installed apps?

Colin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Caught an exception while rendering: no such table: django_admin_log

2008-11-04 Thread joshuajenkins

I'm running into an issue when just starting with Django 1.0 where the
following exception is caught:
Caught an exception while rendering: no such table: django_admin_log

I've done some searching and it appears that this is common if you're
not running Django 1.0, but 0.96 or lower.

I've verified that I'm running 1.0 by checking at the command line
(manage.py --version) which outputs 1.0-final-SVN-unkown

Is this a common problem? All I have is a very simple model and a
modified urls.py file.

Any help would be appreciated.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Design question : best way to show 1 .. N different categoried items

2008-11-04 Thread John M

i have a model for status reports:http://dpaste.com/88760/

The report has 1-N bullet Points, each bullet Point has a category.

What I want to figure out, whats my best way to display this in a
template, given that the category list is flexible.  I mean, a report
might have 1 or more categories.

I'd like to then group the bullet points for each category on the
site.

Your help is appreciated.

John


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: multiple models in object_list

2008-11-04 Thread John M

Thanks for the info.

Turns out that I was looking at the wrong bit of code (gr), and
wasted 2hrs of my day.

John

On Nov 4, 2:36 pm, "Matías Costa" <[EMAIL PROTECTED]> wrote:
> On Tue, Nov 4, 2008 at 8:37 PM, John M <[EMAIL PROTECTED]> wrote:
>
> > I'm trying to figure out how I can use more than one model with a call
> > to object_list generic view.
>
> http://www.djangosnippets.org/snippets/1103/
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: multiple models in object_list

2008-11-04 Thread Matías Costa
On Tue, Nov 4, 2008 at 8:37 PM, John M <[EMAIL PROTECTED]> wrote:

>
> I'm trying to figure out how I can use more than one model with a call
> to object_list generic view.
>

http://www.djangosnippets.org/snippets/1103/

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Overriding update in models

2008-11-04 Thread Matías Costa
On Tue, Nov 4, 2008 at 9:58 PM, Antonio Volpon <[EMAIL PROTECTED]>wrote:

>
> Hello.
>
> I am very new to Django and I'm having some problems in overriding the
> save method for a simple class. In particular, the following code
> (models.py) used against a Mysql database doesn't change the value of
> the two date fields when i save the page in admin, while it correctly
> changes the value of description. I think I'm doing something
> completely wrong, right?
>
> Thanks a lot,
> Antonio
>
> import datetime
> from django.db import models
>
> class Object(models.Model):
>description = models.CharField(max_length=255)
>insert_date = models.DateTimeField(editable=False)
>update_date = models.DateTimeField(editable=False)
>
>def save(self):
>if not self.id:
>self.insert_date = datetime.date.today()
>self.update_time = datetime.date.today()
>super(Object, self).save()
>

Hakan Waara is right, you can use auto_now. But for arbitrary operations on
datetime filelds try datetime.datetime.now() and datetime.timedelta(), not
datetime.date.

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: [Spam] problem building project with python 2.6 startproject won't work

2008-11-04 Thread Gwynne Reddick

On Tue, 4 Nov 2008 13:12:46 -0800 (PST), bizcuit wrote:
>
> I have been using Django with Python 2.5 the past few months.
>
> Today I removed Python 2.5 installed Python 2.6 and downloaded
> Django.
>
> when I try to create a project from the command line in Windows
> Vista:
>
> django-admin.py startproject myProject
>
> I get "Type 'django-admin.py help' for usage." returned.
>
> Does anyone know why this is not working?
>
> thanks
>
> -- jk
>

I had this problem recently in Vista and it turned out to be a issue with the 
.py file association, only the first argument was getting passed to the 
django-admin.py script. Specifically the file association open command was:

python.exe" "%1"

when it needs to be:

python.exe" "%1" %*

unfortunately, unlike XP, you can't directly edit the association in Vista, you 
need to use something like File Type Doctor, see 
http://www.annoyances.org/exec/show/article02-500

G

-- 
Gwynne Reddick, [EMAIL PROTECTED] on 04/11/2008

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Overriding update in models

2008-11-04 Thread Antonio Volpon

Thanks both.

Horrible typo. I noticed, however, that the time update isn't the
current one. Have to look at some locale?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Overriding update in models

2008-11-04 Thread Håkan Waara

Instead of manually setting the update time and created date, as it  
seems like you mean to do here, I highly recommend auto_now and now  
auto_now_add attributes that you can add to your date fields, to get  
this functionality for free.  See 
http://docs.djangoproject.com/en/dev/ref/models/fields/#datetimefield

/Håkan

4 nov 2008 kl. 22.41 skrev Antonio Cavedoni:

>
> Ciao Antonio,
>
> On Nov 4, 2008, at 8:58 PM, Antonio Volpon wrote:
>> import datetime
>> from django.db import models
>>
>> class Object(models.Model):
>>   description = models.CharField(max_length=255)
>>   insert_date = models.DateTimeField(editable=False)
>>   update_date = models.DateTimeField(editable=False)
>>
>>   def save(self):
>>   if not self.id:
>>   self.insert_date = datetime.date.today()
>>   self.update_time = datetime.date.today()
>>   super(Object, self).save()
>
> you have a field called update_date but then you reference it as
> self.update_time in the save() method, maybe that’s why it isn’t
> working?
>
> Cheers!
> -- 
> Antonio
>
>
> >


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: problem building project with python 2.6 startproject won't work

2008-11-04 Thread Karen Tracey
On Tue, Nov 4, 2008 at 4:12 PM, bizcuit <[EMAIL PROTECTED]> wrote:

>
> I have been using Django with Python 2.5 the past few months.
>
> Today I removed Python 2.5 installed Python 2.6 and downloaded Django.
>
> when I try to create a project from the command line in Windows Vista:
>
> django-admin.py startproject myProject
>
> I get "Type 'django-admin.py help' for usage." returned.
>
> Does anyone know why this is not working?
>

Do you have DJANGO_SETTINGS_MODULE defined in the environment?  startproject
is not a valid command if settings have been specified, see:

http://code.djangoproject.com/ticket/8639

which links to another ticket that asks for an improved error message in
this case.

Karen

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Overriding update in models

2008-11-04 Thread Antonio Cavedoni

Ciao Antonio,

On Nov 4, 2008, at 8:58 PM, Antonio Volpon wrote:
> import datetime
> from django.db import models
>
> class Object(models.Model):
>description = models.CharField(max_length=255)
>insert_date = models.DateTimeField(editable=False)
>update_date = models.DateTimeField(editable=False)
>
>def save(self):
>if not self.id:
>self.insert_date = datetime.date.today()
>self.update_time = datetime.date.today()
>super(Object, self).save()

you have a field called update_date but then you reference it as  
self.update_time in the save() method, maybe that’s why it isn’t  
working?

Cheers!
-- 
Antonio


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Overriding update in models

2008-11-04 Thread Antonio Volpon

Alex, thanks a lot for the suggestion, but it doesn't work.

Antonio

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



problem building project with python 2.6 startproject won't work

2008-11-04 Thread bizcuit

I have been using Django with Python 2.5 the past few months.

Today I removed Python 2.5 installed Python 2.6 and downloaded Django.

when I try to create a project from the command line in Windows Vista:

django-admin.py startproject myProject

I get "Type 'django-admin.py help' for usage." returned.

Does anyone know why this is not working?

thanks

-- jk

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Newb testing question

2008-11-04 Thread Rick Kitts

On Nov 4, 2008, at 1:00 PM, Karen Tracey wrote:

> [...snip...]
> The order of things during validation is specified clearly in the  
> docs:
>
> http://docs.djangoproject.com/en/dev/ref/forms/validation/

This was useful, thanks.
>
>
> This page has a subsection on cleaning fields that depend on each  
> other, where it is recommended that such validation be done in the  
> form clean() method as opposed to an individual field's clean  
> method.  An individual field's clean method should really focus on  
> validating that field's data, not that field's data plus some other  
> field's data.  It isn't clear to me if you are unaware of the  
> existence of the form's overall clean() method or if you just don't  
> agree with the recommendation that that is where cross-field  
> validation should be performed.  (Also cross-field validation didn't  
> seem to be an issue in your first message so I don't know if we've  
> gotten off on a tangent or if that was really an issue in your first  
> example.)

I may have been aware of it. I think I've seen e.g. password2  
validation in a couple of places though and just assumed...

Well, sort of a tangent. What I was getting at is that the "raw" data  
of the form (i.e. the data from all field.clean() calls) should, in my  
mind, be set up before creator validation is called. That's probably a  
little specious in the face of form.clean() though.

>
>
>
> Second this tends to make righting unit tests rather more error  
> prone. Or at least the sort of tests I'm used to writing. I realize  
> there are various idiomatic ways of dealing with the problems I'm  
> having (spelunk the error list, etc) but certainly I can imagine  
> better ways. Keep in mind I'm not at all a python person (yet) so  
> this may in fact be entirely infeasible. But presumably one can do  
> something like declare clean_xxx as follows:
>
> def clean_something(self, password1, password2):
>   # Stuff
>
> Provided one can get to the names of the arguments it seems then  
> that it would be useful to do something in full_clean() like
>
> for each argument in the args list of each clean_xxx method:
>   name = arg name
>   if there_is_a_field_named(name):
>   set the value of that argument to field.clean()
>   else:
>   raise somethingorother
>
> I like this in several dimensions, much as I'd like faster-than- 
> light travel, which is to say it would be really cool but I don't  
> see how to get there from here.
>
> Regardless of whether this is implementable in Python I feel it  
> would be rather more complicated to explain and use than the current  
> approach.  clean for a field not only validates that the data is OK  
> but normalizes it to a consistent form -- if you start trying to do  
> cross-field validation before all of the individual data bits have  
> been normalized then your cross-field validation has to worry about  
> handling non-normalized data.  As it is if you put your cross-field  
> validation in the form's clean() method then it only has to deal  
> with validating normalized data.

This is a win, I agree.

>
>
>
> Anyway, I can see several ways around this and I'll pick one or the  
> other. OTOH, if testing at this level of granularity is inconsistent  
> with the python/djano world view, I would love to hear what's  
> better. Understanding code is easy(ish), philosophy is hard.
>
> Testing that an individual field's validation works as expected is  
> not inconsistent with Django or Python philosophy.  However testing  
> that by calling the field's clean method directly is not the right  
> approach -- this method is intended to be called by Django as part  
> of the overall form cleaning.  Therefore to ensure that the  
> environment/args/etc is set up for it as it will be when your code  
> actually runs in production, it is best to test it by calling the  
> form's is_valid() function, and examining the results in the effect  
> it has on the form.

That's what I got too as well.

Thanks for the time and patience,
---Rick

> >


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Overriding update in models

2008-11-04 Thread Alex Koshelev
Hi, Antonio.

Try to replace `datetime.date.today()` with `datetime.datetime.now()` calls.


On Tue, Nov 4, 2008 at 23:58, Antonio Volpon <[EMAIL PROTECTED]>wrote:

>
> Hello.
>
> I am very new to Django and I'm having some problems in overriding the
> save method for a simple class. In particular, the following code
> (models.py) used against a Mysql database doesn't change the value of
> the two date fields when i save the page in admin, while it correctly
> changes the value of description. I think I'm doing something
> completely wrong, right?
>
> Thanks a lot,
> Antonio
>
> import datetime
> from django.db import models
>
> class Object(models.Model):
>description = models.CharField(max_length=255)
>insert_date = models.DateTimeField(editable=False)
>update_date = models.DateTimeField(editable=False)
>
>def save(self):
>if not self.id:
>self.insert_date = datetime.date.today()
>self.update_time = datetime.date.today()
>super(Object, self).save()
>
>
>
>
> >
>

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: 'NoneType' object is not iterable

2008-11-04 Thread Javi

Thanks but I'd already tried it. I don't understand why in the
production server is not added the preceeding slash to the url. My
urls.py is as follows:
urlpatterns = patterns('candidateTool.assessmentSystem.views',
(r'^$', 'index'),
(r'^enter/$', 'enter'),
(r'^main/$', 'main'),
(r'^exam/(?P\d+)/$', 'exam'),
(r'^myexam/(?P\d+)/$', 'my_exam'),
(r'^solved/(?P\d+)/$', 'solved_exam'),
(r'^report/$', 'report'),
(r'^exams/$', 'exams'),
(r'^admin/(.*)', admin.site.root),
)

In the index page is called /enter and I've also tried /enter/ but
neither work :(


On Nov 4, 7:07 pm, Xiong Chiamiov <[EMAIL PROTECTED]> wrote:
> If it works in one environment, but not another, then it might have
> something to do with your settings files.  When you create your links,
> are you having the href be "/enter" or "/enter/"?  I think the
> middleware class you're reading about is for trailing slashes, not
> preceeding ones.
>
> On Nov 4, 9:35 am, Javi <[EMAIL PROTECTED]> wrote:
>
> > Hello everybody!
> > I'm using django 1.0-1 version and Apache as a server web. In the dev
> > server everything works fine but in the production server I get the
> > following error when I ask for a url:
>
> > NoneType' object is not iterable
>
> > Request Method:         POST
> > Request URL:    http://localhostenter/
> > Exception Type:         TypeError
> > Exception Value:
>
> > 'NoneType' object is not iterable
>
> > Exception Location:     /var/lib/python-support/python2.5/django/core/
> > handlers/base.py in get_response, line 77
> > Python Executable:      /usr/bin/python
> > Python Version:         2.5.2
>
> > I think it's because the "/" after "localhost" is not added, actually
> > the url in the browser ishttp://localhost/enter/
>
> > I've been reading about the problem and someone speaks about creating
> > a middleware class... I don't know...
>
> > Is there another simpler way to sort the problem out?
>
> > Thanks in advance.
>
> > Greetings.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Overriding update in models

2008-11-04 Thread Antonio Volpon

Hello.

I am very new to Django and I'm having some problems in overriding the
save method for a simple class. In particular, the following code
(models.py) used against a Mysql database doesn't change the value of
the two date fields when i save the page in admin, while it correctly
changes the value of description. I think I'm doing something
completely wrong, right?

Thanks a lot,
Antonio

import datetime
from django.db import models

class Object(models.Model):
description = models.CharField(max_length=255)
insert_date = models.DateTimeField(editable=False)
update_date = models.DateTimeField(editable=False)

def save(self):
if not self.id:
self.insert_date = datetime.date.today()
self.update_time = datetime.date.today()
super(Object, self).save()




--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Newb testing question

2008-11-04 Thread Karen Tracey
On Tue, Nov 4, 2008 at 2:06 PM, Rick Kitts <[EMAIL PROTECTED]> wrote:

> Well, I think it's clear what I see. I sort of disagree about the impl,
> design, call it what you will.
>

It wasn't clear to me what you had seen nor what you wanted to argue about
though you have clarified that some in this post.


>
> Specifically, the current impl makes testing harder than it needs to be, or
> at least the testing that I'd like to do. That is, I have a field, that
> field has validation rules and I'd like to test that the work. Strictly a
> field has 2 sets of validation rules, those on the field itself (or is it
> more correct to say on the widget), and a (possibly empty) set of rules
> defined by the form creator (call them creator validations).
>
> So a couple of issues about this.
>
> First, the cleaned_data attribute (member?) is not guaranteed to be
> populated fully at the time any creator validation is called. That is, if I
> have 2 dependent fields, say password1, password2, I cannot get
> cleaned_data['password2'] inside of the creator validator clean_password1()
> unless/until the full_clean() impl get's to the field password2. Thus the
> ordering of fields and the impls of clean_xxx() are coupled in what I'd call
> a non-obvious fashion. This seems unnecessary but that's just me.
>

The order of things during validation is specified clearly in the docs:

http://docs.djangoproject.com/en/dev/ref/forms/validation/

This page has a subsection on cleaning fields that depend on each other,
where it is recommended that such validation be done in the form clean()
method as opposed to an individual field's clean method.  An individual
field's clean method should really focus on validating that field's data,
not that field's data plus some other field's data.  It isn't clear to me if
you are unaware of the existence of the form's overall clean() method or if
you just don't agree with the recommendation that that is where cross-field
validation should be performed.  (Also cross-field validation didn't seem to
be an issue in your first message so I don't know if we've gotten off on a
tangent or if that was really an issue in your first example.)


>
> Second this tends to make righting unit tests rather more error prone. Or
> at least the sort of tests I'm used to writing. I realize there are various
> idiomatic ways of dealing with the problems I'm having (spelunk the error
> list, etc) but certainly I can imagine better ways. Keep in mind I'm not at
> all a python person (yet) so this may in fact be entirely infeasible. But
> presumably one can do something like declare clean_xxx as follows:
>
> def clean_something(self, password1, password2):
> # Stuff
>
> Provided one can get to the names of the arguments it seems then that it
> would be useful to do something in full_clean() like
>
> for each argument in the args list of each clean_xxx method:
> name = arg name
> if there_is_a_field_named(name):
> set the value of that argument to field.clean()
> else:
> raise somethingorother
>
> I like this in several dimensions, much as I'd like faster-than-light
> travel, which is to say it would be really cool but I don't see how to get
> there from here.
>

Regardless of whether this is implementable in Python I feel it would be
rather more complicated to explain and use than the current approach.  clean
for a field not only validates that the data is OK but normalizes it to a
consistent form -- if you start trying to do cross-field validation before
all of the individual data bits have been normalized then your cross-field
validation has to worry about handling non-normalized data.  As it is if you
put your cross-field validation in the form's clean() method then it only
has to deal with validating normalized data.


> Anyway, I can see several ways around this and I'll pick one or the other.
> OTOH, if testing at this level of granularity is inconsistent with the
> python/djano world view, I would love to hear what's better. Understanding
> code is easy(ish), philosophy is hard.
>

Testing that an individual field's validation works as expected is not
inconsistent with Django or Python philosophy.  However testing that by
calling the field's clean method directly is not the right approach -- this
method is intended to be called by Django as part of the overall form
cleaning.  Therefore to ensure that the environment/args/etc is set up for
it as it will be when your code actually runs in production, it is best to
test it by calling the form's is_valid() function, and examining the results
in the effect it has on the form.

Karen

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en

multiple models in object_list

2008-11-04 Thread John M

I'm trying to figure out how I can use more than one model with a call
to object_list generic view.

currently I have this..
objectlist_dict =   {'queryset' : Report.reports.all(),
 'extra_context' : {'category_list' : 
Category.objects.all() },
}

urlpatterns = patterns('',
(r'^$', object_list,
objectlist_dict )  ,

my template tries this..

 All Categories 

{% for cat in category_list %}

{{ cat.name }}


{% endfor %}

but the category's never get shown.

Thoughts?

Thanks,

John
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: num_in_admin equivalent in newforms

2008-11-04 Thread Xiong Chiamiov

Actually, extra by itself does exactly what I want.  For some reason I
couldn't see it - I guess I just got caught up in the specific name.
Thanks.

On Nov 4, 10:32 am, Daniel Roseman <[EMAIL PROTECTED]>
wrote:
> On Nov 4, 5:57 pm, Xiong Chiamiov <[EMAIL PROTECTED]> wrote:
>
> > I'm in the process of converting a bunch of sites from pre-nfa to
> > 1.0.  One of the things I've run across is the change in inlines in
> > the admin interface.  Previously, there was 
> > (http://www.djangoproject.com/documentation/0.96/model-api/#many-to-on..)
> > a parameter called num_in_admin that, when set to =1, would show all
> > filled models and one blank, allowing you to have the ability to add
> > as many of an object as you want without having a page filled with
> > blank models.
>
> > The current implementation, however doesn't seem to support this
> > (http://docs.djangoproject.com/en/dev/ref/contrib/admin/
> > #inlinemodeladmin-objects).  Am I overlooking something obvious, or is
> > there another way to do this?
>
> Some combination of extra and max_num will do what you want.
> --
> DR.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Newb testing question

2008-11-04 Thread Rick Kitts
Well, I think it's clear what I see. I sort of disagree about the  
impl, design, call it what you will.

Specifically, the current impl makes testing harder than it needs to  
be, or at least the testing that I'd like to do. That is, I have a  
field, that field has validation rules and I'd like to test that the  
work. Strictly a field has 2 sets of validation rules, those on the  
field itself (or is it more correct to say on the widget), and a  
(possibly empty) set of rules defined by the form creator (call them  
creator validations).

So a couple of issues about this.

First, the cleaned_data attribute (member?) is not guaranteed to be  
populated fully at the time any creator validation is called. That is,  
if I have 2 dependent fields, say password1, password2, I cannot get  
cleaned_data['password2'] inside of the creator validator  
clean_password1() unless/until the full_clean() impl get's to the  
field password2. Thus the ordering of fields and the impls of  
clean_xxx() are coupled in what I'd call a non-obvious fashion. This  
seems unnecessary but that's just me.

Second this tends to make righting unit tests rather more error prone.  
Or at least the sort of tests I'm used to writing. I realize there are  
various idiomatic ways of dealing with the problems I'm having  
(spelunk the error list, etc) but certainly I can imagine better ways.  
Keep in mind I'm not at all a python person (yet) so this may in fact  
be entirely infeasible. But presumably one can do something like  
declare clean_xxx as follows:

def clean_something(self, password1, password2):
# Stuff

Provided one can get to the names of the arguments it seems then that  
it would be useful to do something in full_clean() like

for each argument in the args list of each clean_xxx method:
name = arg name
if there_is_a_field_named(name):
set the value of that argument to field.clean()
else:
raise somethingorother

I like this in several dimensions, much as I'd like faster-than-light  
travel, which is to say it would be really cool but I don't see how to  
get there from here.

Anyway, I can see several ways around this and I'll pick one or the  
other. OTOH, if testing at this level of granularity is inconsistent  
with the python/djano world view, I would love to hear what's better.  
Understanding code is easy(ish), philosophy is hard.

Thanks for the pointer to the errorlist.

Apologies if this makes no sense at all. I am not, again, a python/ 
django person.

---Rick

On Nov 4, 2008, at 10:32 AM, Karen Tracey wrote:

> On Tue, Nov 4, 2008 at 12:07 PM, Rick <[EMAIL PROTECTED]> wrote:
>
> Give a man a fish...
>
> Right, so I see now what's going on. Is this the right place to argue
> about how this works?
>
> It isn't clear what you see or what you want to argue about?
>
> cleaned_data is established when the form is validated and is  
> deleted if the entire form does not pass validation (though I think  
> there is a ticket open that asks for cleaned_data to stick around  
> with the valid values that did pass validation, so that might change).
>
> There is no way to validate part of a form -- it is all-or-nothing.   
> If you want to check for an error on a specific field, then check  
> for the existence of that field's name in the errors dictionary  
> after calling is_valid().  (You can also verify that you get the  
> exact error message you are looking for, if you like.)
>
> Karen
>
>
> ---Rick
>
>
> On Nov 4, 8:46 am, Rick Kitts <[EMAIL PROTECTED]> wrote:
> > Thanks, it does but this is a bad test methodology. is_valid()
> > verifies the entire form and there is no way of knowing in the  
> test if
> > the validation is failing because of other reasons or the specific  
> one
> > I (think) I'm testing.
> >
> > I guess the broader question then is when is cleaned_data  
> established?
> > It appears transient since if I call the clean_xxx() method after
> > calling is_valid() then I still get the attriberr.
> >
> > ---Rick
> >
> > On Nov 4, 2008, at 5:10 AM, Dan Fairs wrote:
> >
> >
> >
> > >> Running the test causes a splash of barf that says:
> >
> > >> AttributeError: 'TheFormClass' object has no attribute  
> 'cleaned_data'
> >
> > > Try calling form.is_valid() (which should in addition return  
> whether
> > > the validation framework as a whole thought the form was valid).  
> This
> > > should invoke your clean_ method.
> >
> > > Cheers,
> > > Dan
> >
> > > --
> > > Dan Fairs <[EMAIL PROTECTED]> |http://www.fezconsulting.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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en

Re: Using Django

2008-11-04 Thread [EMAIL PROTECTED]

So, I added this to the urlpatterns var:

(r'^$', 'mysite.polls.views.current_datetime'),

...and this to views.py located in the polls directory

from django.http import HttpResponse
import datetime

def current_datetime(request):
now = datetime.datetime.now()
html = "It is now %s." % now
return HttpResponse(html)

When I open a browser and go to http://www.mysite.com I wind up in the
mysite.com directory on my Dreamhost server, rather than the url being
mapped to the django site located at /home/username/projects/mysite.

Thanks,

Jason


On Nov 3, 4:10 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > I understand the mapping of urls.py but I guess I'm not clear on a few
> > things to begin with, like what is the equivalent to an index.html
> > page in django? I know that the system works off of a template system
> > like using "base.html" as the design skeleton for a site and extending
> > that system with calls to different views, but what happens when I
> > want to just request the index page for a django site? Let's say I
> > register and add a subdomain to my Dreamhost account say...
> > mysite.com, when I issue the startproject command as django-admin.py
> > startproject mysite is there some sort of connection between the two?
> > Do I scrap the Dreamhost generated directory "mysite.com" and the
> > actual command I should be issuing is django-admin.py startproject
> > mysite.COM? What is returned for an index page if there is no
> > ndex.html or index.php?
>
> Your site's root page is whatever is mapped to r"^$", the empty URL.
>
> It's the same for directories. If you *want* to map something on to
> .../something.html you can, but there is no need to. When a
> "directory-like URL" is passed by a browser the returned result is
> whatever is generated by the view the the URL is mapped to. Or a 404 if
> no such mapping can be found.
>
> regards
>  Steve
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Newb help request about fields and and subfields

2008-11-04 Thread mondonauta

hello, sorry i'm newb so that's y i need your help.
i made a model... and thanks django, it's very simple... but my
problem
is that i want 1 specific field from this model to be split in 3
choiceFields.
ah, in the database's table the same field is stored as varchar (i''m
working with mysql).

i tried to create a custom field that use MultiValueField as
form_class
and MultiWidget as widget, but then in the admin page i obtain
something like:


|
|   Add __name_of_model__
|
| _label__field_
|
| _lavel__field_
|
| _myfield_label_   _1subfield_2subfield_3subfield
|
|

while i would like to obtain something like:

_
|
| Add __name_of_model__
|
| _label__field_
|
| _label__field_
|
| _myfield_label__1sublabel_   _1subfield_ _2sublabel_
_2subfield_ _3sublabel_ _3subfield_
|
|

i hope you all can understand what i mean from these scratches.

i'm sure (and i hope) there is a way to obtain what i want, but i
really don't know how

thanks in advance for your 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-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django's decoupling apps but template should couple them together, right?

2008-11-04 Thread Dj Gilcrease

The point of decoupling the apps is so that you can share them with
others without having to give them all of your site, and it make it
ALOT easier to maintain since if you want to make changes to the way
the menu works you dont have to read though hundred of lines of code
dealing with the rest of your site, you just go right to the menu
application.

As for third party applications, they are (as long as they are
designed properly) easy to integrate with your own site since they
already have all the required code, you just need to write the
template and CSS info to make it fit with your sites design.

On Tue, Nov 4, 2008 at 2:14 AM, ilmarik <[EMAIL PROTECTED]> wrote:
>
> Thank you for all your elaborated answers
>
> However I still don't see the point to have decouped apps in my
> project. Web page mainly is a program for serving some text or media
> or for saving some user data under the hood. Having an app for
> particular business logic AND another pool of views, tags and
> processors to use it, feels like I have to create everything twice or
> makes an app to be a directory with just models.py in it.
>
> I was realy happy when I read about apps, but now I feel a bit
> disappointed.
> what about using third party elements in my project?

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Where can I find the "What's new" in detail in django's doc 1.0?

2008-11-04 Thread Dave Dash

Here's the changelist:

http://docs.djangoproject.com/en/dev/releases/1.0/

On Nov 4, 7:04 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Where can I find the "What's new" in detail in django's doc 1.0?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: num_in_admin equivalent in newforms

2008-11-04 Thread Daniel Roseman

On Nov 4, 5:57 pm, Xiong Chiamiov <[EMAIL PROTECTED]> wrote:
> I'm in the process of converting a bunch of sites from pre-nfa to
> 1.0.  One of the things I've run across is the change in inlines in
> the admin interface.  Previously, there was 
> (http://www.djangoproject.com/documentation/0.96/model-api/#many-to-one-relat...)
> a parameter called num_in_admin that, when set to =1, would show all
> filled models and one blank, allowing you to have the ability to add
> as many of an object as you want without having a page filled with
> blank models.
>
> The current implementation, however doesn't seem to support this
> (http://docs.djangoproject.com/en/dev/ref/contrib/admin/
> #inlinemodeladmin-objects).  Am I overlooking something obvious, or is
> there another way to do this?

Some combination of extra and max_num will do what you want.
--
DR.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Newb testing question

2008-11-04 Thread Karen Tracey
On Tue, Nov 4, 2008 at 12:07 PM, Rick <[EMAIL PROTECTED]> wrote:

>
> Give a man a fish...
>
> Right, so I see now what's going on. Is this the right place to argue
> about how this works?
>

It isn't clear what you see or what you want to argue about?

cleaned_data is established when the form is validated and is deleted if the
entire form does not pass validation (though I think there is a ticket open
that asks for cleaned_data to stick around with the valid values that did
pass validation, so that might change).

There is no way to validate part of a form -- it is all-or-nothing.  If you
want to check for an error on a specific field, then check for the existence
of that field's name in the errors dictionary after calling is_valid().
(You can also verify that you get the exact error message you are looking
for, if you like.)

Karen


>
> ---Rick
>
>
> On Nov 4, 8:46 am, Rick Kitts <[EMAIL PROTECTED]> wrote:
> > Thanks, it does but this is a bad test methodology. is_valid()
> > verifies the entire form and there is no way of knowing in the test if
> > the validation is failing because of other reasons or the specific one
> > I (think) I'm testing.
> >
> > I guess the broader question then is when is cleaned_data established?
> > It appears transient since if I call the clean_xxx() method after
> > calling is_valid() then I still get the attriberr.
> >
> > ---Rick
> >
> > On Nov 4, 2008, at 5:10 AM, Dan Fairs wrote:
> >
> >
> >
> > >> Running the test causes a splash of barf that says:
> >
> > >> AttributeError: 'TheFormClass' object has no attribute 'cleaned_data'
> >
> > > Try calling form.is_valid() (which should in addition return whether
> > > the validation framework as a whole thought the form was valid). This
> > > should invoke your clean_ method.
> >
> > > Cheers,
> > > Dan
> >
> > > --
> > > Dan Fairs <[EMAIL PROTECTED]> |http://www.fezconsulting.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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: custom auth

2008-11-04 Thread Karen Tracey
On Tue, Nov 4, 2008 at 11:39 AM, Gabriel Rossetti <
[EMAIL PROTECTED]> wrote:

>
> Gabriel Rossetti wrote:
> > Hello everyone,
> >
> > I'm trying to get a custom auth handler to work but I keep on getting
> > this error when accessing request.user.get_profile() :
> >
> > DoesNotExist: User matching query does not exist.
> >
> > I followed the following tutorials :
> >
> > http://garage.pimentech.net/mdm_src_dj_auth_documentation/
> >
> http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-model/
> >
> > Here is my auth handler :
> >
> > from proj.app.models import User as MyUser
> > from django.contrib.auth.models import User, check_password
> >
> > def authenticate(self, username=None, password=None):
> > try:
> > myUser = MyUser.objects.get(email=username)
> > except MyUser.DoesNotExist:
> > return None
> > pwdValid = check_password(password, myUser.password)
> > if(pwdValid):
> > try:
> > user = User.objects.get(username=username)
> > except User.DoesNotExist:
> > user = User(username=username,
> > email=username,
> > first_name=myUser.firstName,
> > last_name=myUser.lastName,
> > password="none")
> > user.is_staff = False
> > user.is_superuser = False
> > user.save()
> > myUser.user = user # Not sure if this is really needed,
> > I tried it since it didn't work and it still doesn't
> > myUser.save() # Not sure if this is really needed, I
> > tried it since it didn't work and it still doesn't
> > return user
> > return None
> >
> > def get_user(self, userId):
> > try:
> > return User.objects.get(pk=userId)
> > except User.DoesNotExist:
> > return None
> >
> > here is my model :
> >
> > from django.db import models
> > from django.contrib.auth.models import User as DjangoUser
> >
> > class User(models.Model):
> > id = models.AutoField(primary_key=True)
> > firstname = models.CharField(maxlength=20)
> > lastname = models.CharField(maxlength=20)
> > email = models.CharField(maxlength=50)
> > password = models.CharField(maxlength=20)
> > user = models.ForeignKey(DjangoUser, unique=True)
> > #user = models.OneToOneField(DjangoUser, core=True) # This doesn't
> > work either
> >
> > I really don't see why it doesn't work...does anyone have a clue?
> >
> > Thank you,
> > Gabriel
> >
> > PS I've already looked at past posts on the subject but the common
> > answer is to create the profile, but in my case it's already created,
> > maybe I'm linking it wrong?
> >
> >
> Am I getting no responses because :
>
>   1) I missing something obvious
>   2) I said something wrong
>   3) The answer is so simple that no one wants to take the time to write it
>   4) No one has a clue
>   5) No on has the time
>   6) Another reason not listed here
>
>
It's a pretty safe bet that mostly people don't have the time for a question
that is sufficiently complicated/confusing to require more than a simple
answer.  From a high level it isn't immediately obvious how a custom
authenticate method can cause get_profile() to fail -- get_profile knows
nothing of custom authentication.  The error you are getting means that for
whatever user ID you are attempting get_profile() on, there is no record in
your custom User table (btw I find it confusing to name more than one model
the same thing and I think you are asking for trouble when you forget the
"as User" on your import of User somewhere) with that ID.

Looking at your custom authenticate, however, does provide some clues as to
what might have gone wrong -- you are doing more in authenticate than just
authenticating.  It appears you are auto-creating
django.contrib.auth.models.User objects to match your existing custom User
objects.  The lines you have that set the 'user' field in a  custom User
object and save it are necessary to link your custom User to the associated
Django user model, but from the comments it appears you did not have them
there initially.  Thus you may have created some number of Django user
objects without having set the appropriate value in the associated custom
user model.  Adding those lines after-the-fact won't fix the existing custom
User models that don't have the proper values set in the user field, since
on a 2nd run through of the same code you won't fall into the except
UserDoesNotExist case since you created the User on the first go-round.

So, check the values for the user column in your custom user table.  Based
on the error you are getting they don't appear to be correct and the code as
you have it won't fix that.

Karen

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the 

Re: 'NoneType' object is not iterable

2008-11-04 Thread Xiong Chiamiov

If it works in one environment, but not another, then it might have
something to do with your settings files.  When you create your links,
are you having the href be "/enter" or "/enter/"?  I think the
middleware class you're reading about is for trailing slashes, not
preceeding ones.

On Nov 4, 9:35 am, Javi <[EMAIL PROTECTED]> wrote:
> Hello everybody!
> I'm using django 1.0-1 version and Apache as a server web. In the dev
> server everything works fine but in the production server I get the
> following error when I ask for a url:
>
> NoneType' object is not iterable
>
> Request Method:         POST
> Request URL:    http://localhostenter/
> Exception Type:         TypeError
> Exception Value:
>
> 'NoneType' object is not iterable
>
> Exception Location:     /var/lib/python-support/python2.5/django/core/
> handlers/base.py in get_response, line 77
> Python Executable:      /usr/bin/python
> Python Version:         2.5.2
>
> I think it's because the "/" after "localhost" is not added, actually
> the url in the browser ishttp://localhost/enter/
>
> I've been reading about the problem and someone speaks about creating
> a middleware class... I don't know...
>
> Is there another simpler way to sort the problem out?
>
> Thanks in advance.
>
> Greetings.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



problem with inlineformset_factory

2008-11-04 Thread Petry

Hi all,

I'm having a weird problem when using inlineformset_factory, he can
only register up to 2 records, after that causes a validation error

"(Hidden field id) User phone with this None already exists."

Here is my forms [1], models [2] and views [3]

[1] http://dpaste.com/88598/
[2] http://dpaste.com/88599/
[3] http://dpaste.com/88600/

--

Marcos Daniel Petry
http://mdpetry.net


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



num_in_admin equivalent in newforms

2008-11-04 Thread Xiong Chiamiov

I'm in the process of converting a bunch of sites from pre-nfa to
1.0.  One of the things I've run across is the change in inlines in
the admin interface.  Previously, there was (http://
www.djangoproject.com/documentation/0.96/model-api/#many-to-one-relationships)
a parameter called num_in_admin that, when set to =1, would show all
filled models and one blank, allowing you to have the ability to add
as many of an object as you want without having a page filled with
blank models.

The current implementation, however doesn't seem to support this
(http://docs.djangoproject.com/en/dev/ref/contrib/admin/
#inlinemodeladmin-objects).  Am I overlooking something obvious, or is
there another way to do 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-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: An interesting URL dispatcher problem

2008-11-04 Thread redmonkey

Hi Brian,

Thanks for your comment. I completely understand what you are saying,
and anyone trying to match the "?" character should take note, but in
this situation I am using it to try to tell Django that that named
group in the regular expression may, or may not, be included.

RM

On Nov 4, 5:33 pm, Brian Neal <[EMAIL PROTECTED]> wrote:
> On Nov 4, 10:50 am, redmonkey <[EMAIL PROTECTED]> wrote:
>
>
>
> > My problem is with the URL writing. I first wrote some unit tests to
> > find the regular expressions that worked but Django doesn't seem to
> > like the '?' in URL configurations.
>
> ? is a special character in regular expressions, just like $, ^, etc.
> You must escape it if you want to use it literally, e.g. \?. However,
> I don't think the ? as part of any GET arguments in a URL are going to
> be available to you, from what I remember about django works.
>
> I'm not really following what you are trying to do however.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: An interesting URL dispatcher problem

2008-11-04 Thread redmonkey

I have to admit, the missing ) is a typo. I made up the ice cream
example to try to simplify my problem, and accidentally missed it off.

Perhaps my example is too simple.
> I have a small form on a page that is mostly optional fields with the
> exception of some drop down boxes.

My actual form has 3 optional fields, and this complicated matters
with matching URLs. Fortunately, two of the fields are limits for a
price search, so I've used "-" to identify the re, and the third is a
text description so I'm expecting URLs that look like "/100-200/persian
%20rug/" (Where 100-200 is the price range, and "persian%20rug" is a
quoted text search).

My issue is that any of those 3 fields may not be submitted, but
somehow I need to redirect to the process view.

The http://jobs.guardian.co.uk/jobs/; title="Guardian
Jobs">Guardian Jobs site is a nice example of the effect I want to
create as you add filtering paramters on the left, although I'm using
a form to collect user input as opposed to giving them a list of
ranges which is more difficult.

I hope that clears a few things up.

On Nov 4, 5:23 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> redmonkey wrote:
> > Hi,
>
> > I have a small form on a page that is mostly optional fields with the
> > exception of some drop down boxes. I want to take the data submitted
> > through this form and use them to form a URL.
>
> > My problem is with the URL writing. I first wrote some unit tests to
> > find the regular expressions that worked but Django doesn't seem to
> > like the '?' in URL configurations.
>
> > How can I write a workflow that converts optional, POSTed data to a
> > RESTful URL for processing?
>
> > Here's an example:
>
> > class IceCreamForm(forms.form):
> >     description = forms.CharField(required=False)
> >     flavour = forms.ChoiceField(choices=FLAVOUR_CHOICES, initial=0)
> >     FLAVOUR_CHOICES = (
> >            ...
> >     )
>
> > This is my form class. It contains one optional field, and one
> > required field. When rendered on a page, the form POSTs it's data to
> > the the 'process' view:
>
> > def process(request):
> >     # Standard form stuff (is_valid) ...
> >     params = {}
> >     if form.cleaned_data['description']:
> >         params.update(description=form.cleaned_data['description'])
> >    if form.cleaned_data['flavour']:
> >        params.update(flavour=form.cleaned_data['flavour'])
>
> >    return HttpResponseRedirect('proj.app.views.filter', kwags=params)
>
> > def filter(request, description=None, flavour=0):
> >     ... do stuff ...
>
> > Here, I collect the parameters from the form and try to turn them into
> > a pretty URL that redirects to the filter view to do something with
> > the data. It's the URL writing I'm having problems with. I want to
> > write things like:
>
> > urlpatterns += patterns('proj.app.views',
> >     (r'^(?P\w+)/((?P\w+)/)?$', 'filter'),
> > )
>
> It might be better to try something that makes the last slash optional
> in a different way. How about
>
>     (r'^(?P\w+)(/(?P\w+))/?$', 'filter'),
>
> > The question mark is wrapped around an extra '/' to complete the URL,
> > but it doesn't work. Nor does
>
> > urlpatterns += patterns('proj.app.views',
> >     (r'^(?P\w+)/$', 'filter'),
> >     (r'^(?P\w+)/(?P\w+/$', 'filter'),
> > )
>
> > I'm surprised with the result of the last one, and so I'm sure I'm
> > missing something. Does anyone have any ideas or simplifications for
> > me?
>
> The last one doesn't even appear to be a syntactically correct re due to
> mismatching parentheses ... did you copy and paste, or mis-transcribe?
>
> regards
>  Steve
> --
> Steve Holden        +1 571 484 6266   +1 800 494 3119
> Holden Web LLC              http://www.holdenweb.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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



'NoneType' object is not iterable

2008-11-04 Thread Javi

Hello everybody!
I'm using django 1.0-1 version and Apache as a server web. In the dev
server everything works fine but in the production server I get the
following error when I ask for a url:

NoneType' object is not iterable

Request Method: POST
Request URL:http://localhostenter/
Exception Type: TypeError
Exception Value:

'NoneType' object is not iterable

Exception Location: /var/lib/python-support/python2.5/django/core/
handlers/base.py in get_response, line 77
Python Executable:  /usr/bin/python
Python Version: 2.5.2

I think it's because the "/" after "localhost" is not added, actually
the url in the browser is http://localhost/enter/

I've been reading about the problem and someone speaks about creating
a middleware class... I don't know...

Is there another simpler way to sort the problem out?

Thanks in advance.

Greetings.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: An interesting URL dispatcher problem

2008-11-04 Thread Brian Neal

On Nov 4, 10:50 am, redmonkey <[EMAIL PROTECTED]> wrote:
>
> My problem is with the URL writing. I first wrote some unit tests to
> find the regular expressions that worked but Django doesn't seem to
> like the '?' in URL configurations.

? is a special character in regular expressions, just like $, ^, etc.
You must escape it if you want to use it literally, e.g. \?. However,
I don't think the ? as part of any GET arguments in a URL are going to
be available to you, from what I remember about django works.

I'm not really following what you are trying to do however.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: An interesting URL dispatcher problem

2008-11-04 Thread Steve Holden

redmonkey wrote:
> Hi,
> 
> I have a small form on a page that is mostly optional fields with the
> exception of some drop down boxes. I want to take the data submitted
> through this form and use them to form a URL.
> 
> My problem is with the URL writing. I first wrote some unit tests to
> find the regular expressions that worked but Django doesn't seem to
> like the '?' in URL configurations.
> 
> How can I write a workflow that converts optional, POSTed data to a
> RESTful URL for processing?
> 
> Here's an example:
> 
> class IceCreamForm(forms.form):
> description = forms.CharField(required=False)
> flavour = forms.ChoiceField(choices=FLAVOUR_CHOICES, initial=0)
> FLAVOUR_CHOICES = (
>   ...
> )
> 
> This is my form class. It contains one optional field, and one
> required field. When rendered on a page, the form POSTs it's data to
> the the 'process' view:
> 
> def process(request):
> # Standard form stuff (is_valid) ...
> params = {}
> if form.cleaned_data['description']:
> params.update(description=form.cleaned_data['description'])
>   if form.cleaned_data['flavour']:
>   params.update(flavour=form.cleaned_data['flavour'])
> 
>   return HttpResponseRedirect('proj.app.views.filter', kwags=params)
> 
> def filter(request, description=None, flavour=0):
> ... do stuff ...
> 
> Here, I collect the parameters from the form and try to turn them into
> a pretty URL that redirects to the filter view to do something with
> the data. It's the URL writing I'm having problems with. I want to
> write things like:
> 
> urlpatterns += patterns('proj.app.views',
> (r'^(?P\w+)/((?P\w+)/)?$', 'filter'),
> )
> 
It might be better to try something that makes the last slash optional
in a different way. How about

(r'^(?P\w+)(/(?P\w+))/?$', 'filter'),

> The question mark is wrapped around an extra '/' to complete the URL,
> but it doesn't work. Nor does
> 
> urlpatterns += patterns('proj.app.views',
> (r'^(?P\w+)/$', 'filter'),
> (r'^(?P\w+)/(?P\w+/$', 'filter'),
> ) 
> 
> I'm surprised with the result of the last one, and so I'm sure I'm
> missing something. Does anyone have any ideas or simplifications for
> me?
> 
The last one doesn't even appear to be a syntactically correct re due to
mismatching parentheses ... did you copy and paste, or mis-transcribe?

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: An interesting URL dispatcher problem

2008-11-04 Thread TiNo
>
> Here, I collect the parameters from the form and try to turn them into
> a pretty URL that redirects to the filter view to do something with
> the data. It's the URL writing I'm having problems with. I want to
> write things like:


Why not do it in the process view immediatly?


> urlpatterns += patterns('proj.app.views',
>(r'^(?P\w+)/((?P\w+)/)?$', 'filter'),
> )
>
> The question mark is wrapped around an extra '/' to complete the URL,
> but it doesn't work. Nor does
>
> urlpatterns += patterns('proj.app.views',
>(r'^(?P\w+)/$', 'filter'),
>(r'^(?P\w+)/(?P\w+/$', 'filter'),
> )
>

you are missing a closing ) on the last line:
 (r'^(?P\w+)/(?P\w+*)*/$', 'filter'),

Tino

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Newb testing question

2008-11-04 Thread Rick

Give a man a fish...

Right, so I see now what's going on. Is this the right place to argue
about how this works?

---Rick


On Nov 4, 8:46 am, Rick Kitts <[EMAIL PROTECTED]> wrote:
> Thanks, it does but this is a bad test methodology. is_valid()  
> verifies the entire form and there is no way of knowing in the test if  
> the validation is failing because of other reasons or the specific one  
> I (think) I'm testing.
>
> I guess the broader question then is when is cleaned_data established?  
> It appears transient since if I call the clean_xxx() method after  
> calling is_valid() then I still get the attriberr.
>
> ---Rick
>
> On Nov 4, 2008, at 5:10 AM, Dan Fairs wrote:
>
>
>
> >> Running the test causes a splash of barf that says:
>
> >> AttributeError: 'TheFormClass' object has no attribute 'cleaned_data'
>
> > Try calling form.is_valid() (which should in addition return whether
> > the validation framework as a whole thought the form was valid). This
> > should invoke your clean_ method.
>
> > Cheers,
> > Dan
>
> > --
> > Dan Fairs <[EMAIL PROTECTED]> |http://www.fezconsulting.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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



An interesting URL dispatcher problem

2008-11-04 Thread redmonkey

Hi,

I have a small form on a page that is mostly optional fields with the
exception of some drop down boxes. I want to take the data submitted
through this form and use them to form a URL.

My problem is with the URL writing. I first wrote some unit tests to
find the regular expressions that worked but Django doesn't seem to
like the '?' in URL configurations.

How can I write a workflow that converts optional, POSTed data to a
RESTful URL for processing?

Here's an example:

class IceCreamForm(forms.form):
description = forms.CharField(required=False)
flavour = forms.ChoiceField(choices=FLAVOUR_CHOICES, initial=0)
FLAVOUR_CHOICES = (
...
)

This is my form class. It contains one optional field, and one
required field. When rendered on a page, the form POSTs it's data to
the the 'process' view:

def process(request):
# Standard form stuff (is_valid) ...
params = {}
if form.cleaned_data['description']:
params.update(description=form.cleaned_data['description'])
if form.cleaned_data['flavour']:
params.update(flavour=form.cleaned_data['flavour'])

return HttpResponseRedirect('proj.app.views.filter', kwags=params)

def filter(request, description=None, flavour=0):
... do stuff ...

Here, I collect the parameters from the form and try to turn them into
a pretty URL that redirects to the filter view to do something with
the data. It's the URL writing I'm having problems with. I want to
write things like:

urlpatterns += patterns('proj.app.views',
(r'^(?P\w+)/((?P\w+)/)?$', 'filter'),
)

The question mark is wrapped around an extra '/' to complete the URL,
but it doesn't work. Nor does

urlpatterns += patterns('proj.app.views',
(r'^(?P\w+)/$', 'filter'),
(r'^(?P\w+)/(?P\w+/$', 'filter'),
)

I'm surprised with the result of the last one, and so I'm sure I'm
missing something. Does anyone have any ideas or simplifications for
me?

Thanks,

Red Monkey



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Newb testing question

2008-11-04 Thread Rick Kitts

Thanks, it does but this is a bad test methodology. is_valid()  
verifies the entire form and there is no way of knowing in the test if  
the validation is failing because of other reasons or the specific one  
I (think) I'm testing.

I guess the broader question then is when is cleaned_data established?  
It appears transient since if I call the clean_xxx() method after  
calling is_valid() then I still get the attriberr.

---Rick

On Nov 4, 2008, at 5:10 AM, Dan Fairs wrote:

>
>> Running the test causes a splash of barf that says:
>>
>> AttributeError: 'TheFormClass' object has no attribute 'cleaned_data'
>>
>
> Try calling form.is_valid() (which should in addition return whether
> the validation framework as a whole thought the form was valid). This
> should invoke your clean_ method.
>
> Cheers,
> Dan
>
> --
> Dan Fairs <[EMAIL PROTECTED]> | http://www.fezconsulting.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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: custom auth

2008-11-04 Thread Gabriel Rossetti

Gabriel Rossetti wrote:
> Hello everyone,
>
> I'm trying to get a custom auth handler to work but I keep on getting 
> this error when accessing request.user.get_profile() :
>
> DoesNotExist: User matching query does not exist.
>
> I followed the following tutorials :
>
> http://garage.pimentech.net/mdm_src_dj_auth_documentation/
> http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-model/
>
> Here is my auth handler :
>
> from proj.app.models import User as MyUser
> from django.contrib.auth.models import User, check_password
>
> def authenticate(self, username=None, password=None):
> try:
> myUser = MyUser.objects.get(email=username)
> except MyUser.DoesNotExist:
> return None
> pwdValid = check_password(password, myUser.password)
> if(pwdValid):
> try:
> user = User.objects.get(username=username)
> except User.DoesNotExist:
> user = User(username=username,
> email=username,
> first_name=myUser.firstName,
> last_name=myUser.lastName,
> password="none")
> user.is_staff = False
> user.is_superuser = False
> user.save()
> myUser.user = user # Not sure if this is really needed, 
> I tried it since it didn't work and it still doesn't
> myUser.save() # Not sure if this is really needed, I 
> tried it since it didn't work and it still doesn't
> return user
> return None
>
> def get_user(self, userId):
> try:
> return User.objects.get(pk=userId)
> except User.DoesNotExist:
> return None
>
> here is my model :
>
> from django.db import models
> from django.contrib.auth.models import User as DjangoUser
>
> class User(models.Model):
> id = models.AutoField(primary_key=True)
> firstname = models.CharField(maxlength=20)
> lastname = models.CharField(maxlength=20)
> email = models.CharField(maxlength=50)
> password = models.CharField(maxlength=20)
> user = models.ForeignKey(DjangoUser, unique=True)
> #user = models.OneToOneField(DjangoUser, core=True) # This doesn't 
> work either
>
> I really don't see why it doesn't work...does anyone have a clue?
>
> Thank you,
> Gabriel
>
> PS I've already looked at past posts on the subject but the common 
> answer is to create the profile, but in my case it's already created, 
> maybe I'm linking it wrong?
>
>   
Am I getting no responses because :

   1) I missing something obvious
   2) I said something wrong
   3) The answer is so simple that no one wants to take the time to write it
   4) No one has a clue
   5) No on has the time
   6) Another reason not listed here

:-)
Gabriel

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to get the id in an admin template

2008-11-04 Thread Adi Jörg Sieker

On 04.11.2008 17:19 Uhr, webcomm wrote:
> How do I get the instance id from within an admin template?  I want to
> add a link to view the instance, and I need the id to create that
> link.  Like so...
>
> View this item
>
>
if your Model supplies a get_absolute_url method, then the Admin will 
automatically create a "view on site" link
on the change detail page.
See also 
http://docs.djangoproject.com/en/dev/ref/models/instances/#get-absolute-url

adi

-- 
Adi J. Sieker mobile: +49 - 178 - 88 5 88 13
Freelance developer   web:http://www.sieker.info/profile
SAP-Developer

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



how to get the id in an admin template

2008-11-04 Thread webcomm

How do I get the instance id from within an admin template?  I want to
add a link to view the instance, and I need the id to create that
link.  Like so...

View this item

Thanks,
Ryan
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: saving multiple versions of an uploaded image

2008-11-04 Thread varikin



On Nov 4, 2:33 am, Chris Amico <[EMAIL PROTECTED]> wrote:
> Hi folks,
>
> I'm trying to turn one uploaded image into several: a full-size and
> thumbnail (and more, eventually). Here's the model I'm playing with,
> just for testing:
>
> class TestPhoto(models.Model):
>     "This is only for testing. Delete it later and make a real photo
> model"
>     title = models.CharField(max_length=100)
>     pub_date = models.DateTimeField(auto_now_add=True)
>     full_size = models.ImageField(upload_to="images/photos/%Y/%b/%d")
>     thumbnail = models.ImageField(upload_to="images/photos/%Y/%b/%d",
> blank=True)
>
> Resizing is simple enough using a script off Django Snippets:
>
> def thumbnail(filename, size=(50, 50), output_filename=None):
>     image = Image.open(filename)
>     if image.mode not in ('L', 'RGB'):
>         image = image.convert('RGB')
>     image = image.resize(size, Image.ANTIALIAS)
>
>     # get the thumbnail data in memory.
>     if not output_filename:
>         output_filename = get_default_thumbnail_filename(filename)
>     image.save(output_filename, image.format)
>     return output_filename
>
> That part works like a charm when I run it on save(), and the returned
> files end up exactly where they should be. But how do I get Django to
> recognize that output file as a File object?
>
> I've tried adding another ImageField to the model and using a save()
> method to populated it with the output_filename from thumbnail(). It
> gets the path right, but the url ends up being something like
> MEDIA_URL + self.full_size.path + "thumb.jpg" or media.mydomain.com/
> home/chrisamico/webapps/media/images/photos/2008/Oct/23/
> IMG_0460.thumb.jpg. That's a big 404.
>
> I could write a simple method to create the right url (since it's just
> full_size.url with .thumb.jpg on the end) but that would be repetitive
> for each size.
>
> Thanks as always for the help.

I have been overriding the save method on the model.  I have found
that by the time the save method is called, the file is saved to the
disk already, So I open the original, resize and save to the
thumbnail:

from __future__ import division
import os
import tempfile
import Image
from django.core.files import File

class Picture(models.Model)
name = models.CharField(max_length=200)
original = models.ImageField(upload_to='original')
thumbnail = models.ImageField(upload_to='thumbnail')

def save(self, force_update=False, force_insert=False):
#Open image as PIL Image and get name
orig = Image.open(self.original.path)
name = os.path.basename(self.original.name)

#using future division, calculating height for width of
100 to keep aspect
height = int(100 * orig.size[1] / orig.size[0])

#Resize, open tempfile, and save to temp
thumb = orig.resize((width, height), Image.ANTIALIAS)
thumb_file = tempfile.NamedTemporaryFile('w+b')
thumb.save(thumb_file, 'JPEG')

#Save tempfile to thumbnail
self.thumbnail.save(name, File(thumb_file), False)
thumb_file.close() #tempfile is deleted upon close:)

   super(Picture, self).save(force_update, force_insert)

I hope this is clear enough. I actually have more in this for
specifying the size of the thumbnail and some other processing, but
this is the core of how I do 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: django: object has no attribute 'clean_data', Help me!!!

2008-11-04 Thread Daniel Hepper

>   26. username=self.clean_data['username']
clean_data was renamed to cleaned_data. See
http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges#Newforms:clean_datachangedtocleaned_data

Regards,
Daniel Hepper


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



django: object has no attribute 'clean_data', Help me!!!

2008-11-04 Thread 为爱而生
Environment:

Request Method: POSTRequest URL: http://127.0.0.1:8080/register/Django
Version: 1.0-final-SVN-unknownPython Version: 2.5.2Installed
Applications:['django.contrib.auth', 'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.sites',
'django_bookmarks.bookmarks']Installed
Middleware:('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware')Traceback:File
"C:\Python25\Lib\site-packages\django\core\handlers\base.py" in
get_response  86. response = callback(request,
*callback_args, **callback_kwargs)File
"D:\django\django_bookmarks\..\django_bookmarks\bookmarks\views.py" in
register_page  46. if form.is_valid():File
"C:\Python25\Lib\site-packages\django\forms\forms.py" in is_valid
120. return self.is_bound and not bool(self.errors)File
"C:\Python25\Lib\site-packages\django\forms\forms.py" in _get_errors
111. self.full_clean()File
"C:\Python25\Lib\site-packages\django\forms\forms.py" in full_clean
227. value = getattr(self, 'clean_%s' %
name)()File "D:\django\django_bookmarks\bookmarks\forms.py" in
clean_username  26.
username=self.clean_data['username']Exception Type: AttributeError at
/register/Exception Value: 'RegistrationForm' object has no attribute
'clean_data'

-- 
"OpenBookProject"-开放图书计划邮件列表
详情: http://groups.google.com/group/OpenBookProject
维基: http://wiki.woodpecker.org.cn/

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django on Apache (mod_python) administration cookie problem

2008-11-04 Thread Dave Dash

I had cleared the cookies, I also tried in another browser as well -
same result.

On Nov 3, 10:50 pm, Graham Dumpleton <[EMAIL PROTECTED]>
wrote:
> On Nov 4, 5:08 pm, Dave  Dash <[EMAIL PROTECTED]> wrote:
>
> > I am witnessing this issue using manage.py runserver.
>
> > The only useful information I can give is this was working when I was
> > running .97 (or whatever was the trunk a few months back), I recently
> > upgraded to the latest trunk (~1.1) and now continually get this
> > message.
>
> > I suspect something has changed in the last few months and I missed
> > whatever it was.  I'm going to attempt to setup a dummy project and
> > try this again.
>
> > If anybody has some clue, please let me know,
>
> Clear the cookie for the application from your browser cache.
>
> Graham
>
> > Cheers,
>
> > Dave Dash
>
> > On Sep 30, 5:05 pm, Álvaro Justen <[EMAIL PROTECTED]> wrote:
>
> > > Ah, some details:
> > > -> Admin interface runs OK with python manage.py runserver - as of it
> > > is an Apache error, Django's web server isn't affected by this bug.
> > > -> I'm using Debian etch as server: I've installed Apache, PHP and
> > > mod_php with Debian packages, but Django installed manually.
> > > -> Versions:
> > >   * Apache: Server version: Apache/2.2.3
> > >     Server built:   Mar 22 2008 09:29:10
> > >   * PHP: PHP 5.2.0-8+etch11 (cli) (built: May 10 2008 10:46:24)
> > >     Copyright (c) 1997-2006 The PHP Group
> > >     Zend Engine v2.2.0, Copyright (c) 1998-2006 Zend Technologies
> > >   * Django: 1.0-final-SVN-unknown
>
> > > --
> > >  Cheers,
> > >   Álvaro Justen
> > >   Debian GNU/Linux user
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: django: object has no attribute 'clean_data', Help me!!!

2008-11-04 Thread Karen Tracey
On Tue, Nov 4, 2008 at 10:19 AM, 为爱而生 <[EMAIL PROTECTED]> wrote:
> Environment:
> [snipped]
>
> File "C:\Python25\Lib\site-packages\django\forms\forms.py" in full_clean
> 227. value = getattr(self, 'clean_%s' % name)()
> File "D:\django\django_bookmarks\bookmarks\forms.py" in clean_username
> 26. username=self.clean_data['username']
>
> Exception Type: AttributeError at /register/
> Exception Value: 'RegistrationForm' object has no attribute 'clean_data'

You are apparently trying to use code written for an older version of Django
on a newer version of Django.  clean_data was renamed to cleaned_data quite
a while ago:

http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges#Newforms:clean_datachangedtocleaned_data

Assuming you want to use a 1.0 level of Django, you either need to get a
version of the code you are running that has been updated to work with
Django 1.0, or you will need to migrate it yourself (in which case you may
need to do more beyond adjusting to this change, see the porting guide and
list of Backward Incopmatible changes pointed to above).

Karen

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Where can I find the "What's new" in detail in django's doc 1.0?

2008-11-04 Thread [EMAIL PROTECTED]

Where can I find the "What's new" in detail in django's doc 1.0?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to get comment_count in view?

2008-11-04 Thread Info Cascade

I was just asking myself a similar question. I want to know the total
result count of a query but only return  a subset of the query.
Articles.objects.filter(somefield__contains='some
query')[start:start+num_rows]

I understand the slice creates a LIMIT in the database query.  But I
also need the total non-limited result count, which could potentially be
quite large.  It seems wasteful to get the entire query result and then
use .count() or len() to get the number of rows returned, and *then*
slice it anyway.

What is the best approach?

In MySQL it's possible to do
select SQL_CALC_FOUND_ROWS  * from table limit 5,10
Then, you can do "select FOUND_ROWS()"

Has anyone tried something similar?  I'm now using Postgres, which I
assume has some similar functionality. Anyone know what it is?

Any comments welcome.

Best,
Liam



Chatchai Neanudorn wrote:
> from django.contrib.comments.models import Comment
> from post.models import Post
>
> #get comments for model
> Comment.objects.for_model(Post).count()
>
> #get comment for instance
> Comment.objects.for_model(Post.objects.get(id=1)).count()
>
> 2008/11/2 David.D <[EMAIL PROTECTED]
> >
>
>
> I can get comment_count in templates:
>
> {% get_comment_count for object as comment_count %}
>
>
> But how to get it in my view?
>
>
>
> >


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Beginner on Django and web developing

2008-11-04 Thread bruno desthuilliers



On 4 nov, 03:02, "DULMANDAKH Sukhbaatar" <[EMAIL PROTECTED]> wrote:
> > Hello folks, I have aready used python only in desktop. About 1 a week
> > ago I installed the Django 1.0 on Fedora 9. I wonder about the
> > djangobook, its version is 0.96 or 1.0?
>
> book's version is 1.0, but written for 0.96.

oops, my bad :(


Sorry, I should have doubled-checked this before answering


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Using settings.py mechanism for application settings

2008-11-04 Thread James Bennett

On Mon, Nov 3, 2008 at 7:01 PM, pk <[EMAIL PROTECTED]> wrote:
> James is right that for any of my own app, I can just tell the user
> to put in some settings in the project level settings.py file. In fact
> that is exactly what I do now.

And that is what quite a number of popular third-party Django
applications -- every one of them intended to be used and reused --
are doing. I don't really see a need for some system of forcing
default values, since in many cases *not* supplying an explicit value
for such a setting is an error (because not supplying it *or* falling
back to a default can break the application or cause undesired
behavior). Much better to simply document what's needed, and rely on
the fact that trying to run without setting it will raise an error.



-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: AW: __str__, __unicode__ representation of model fields

2008-11-04 Thread Donn

On Monday, 03 November 2008 10:50:34 Bülent Aldemir wrote:
> I want to have a nice representation for the other MyModel() fields. Must I
> define for each field a method to accomplish my task?
Seems the best way. There's only one 'repr' for any object and if you want 
specific ones then either make a single def that takes an arg (an instance of 
the field you want to format or a string to match in the def) and then have 
it spit out a formatted value in response, or have a def per field.

\d

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Newb testing question

2008-11-04 Thread Dan Fairs

> Running the test causes a splash of barf that says:
>
> AttributeError: 'TheFormClass' object has no attribute 'cleaned_data'
>

Try calling form.is_valid() (which should in addition return whether  
the validation framework as a whole thought the form was valid). This  
should invoke your clean_ method.

Cheers,
Dan

--
Dan Fairs <[EMAIL PROTECTED]> | http://www.fezconsulting.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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: strptime() working in python, but not within django?

2008-11-04 Thread Thomas Guettler

Hi,

Maybe some LANG entries in os.environ are different.

Or the datetime module is loaded from a different location.
is datetime.__file__ equal?

  HTH,
Thomas

mpobrien schrieb:
> I'm working on something that involves parsing out a date from a
> string, so i'm using the datetime.strptime() function. I've noticed
> that this works correctly in python, but when i run it within a django
> environment it doesn't seem to work. Example, in python:
>
> ...


-- 
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Admin behavior: what is errors.items in change_form.html?

2008-11-04 Thread Karen Tracey
On Tue, Nov 4, 2008 at 7:36 AM, nazar <[EMAIL PROTECTED]> wrote:

>
> Now I got it!!!
>
> I had TEMPLATE_STRING_IF_INVALID = 'TEMPLATE_STRING_IF_INVALID'
>
> So that 'items' was rendered as 'TEMPLATE_STRING_IF_INVALID' (and I
> saw it clearly). And I met the bug, bacause gettext was unable to use
> it as int parameter.
>
> Now I cleared this: TEMPLATE_STRING_IF_INVALID = '' and bug
> disappeared.
>

Yes, the admin rather relies on TEMPLATE_STRING_IF_INVALID being empty.
See:

http://docs.djangoproject.com/en/dev/ref/templates/api/#invalid-template-variables
http://code.djangoproject.com/ticket/3579

However, this particular case is a genuine bug in the admin templates.  Even
with an empty TEMPLATE_STRING_IF_INVALID, the wrong message is displayed
when there is only one error to be corrected on the page.   I've opened a
ticket to get that (and anywhere else in the admin that this construct is
used) fixed:

http://code.djangoproject.com/ticket/9514

Karen

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Admin behavior: what is errors.items in change_form.html?

2008-11-04 Thread nazar

Now I got it!!!

I had TEMPLATE_STRING_IF_INVALID = 'TEMPLATE_STRING_IF_INVALID'

So that 'items' was rendered as 'TEMPLATE_STRING_IF_INVALID' (and I
saw it clearly). And I met the bug, bacause gettext was unable to use
it as int parameter.

Now I cleared this: TEMPLATE_STRING_IF_INVALID = '' and bug
disappeared.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: link to other record in admin change list

2008-11-04 Thread Karen Tracey
On Tue, Nov 4, 2008 at 3:24 AM, chris <[EMAIL PROTECTED]> wrote:

>
> Dear Fabio,
>
> That did the trick!  I have searched all over the manuals, but must
> have overlooked this.  It is a bit confusing that this seems to be
> different from is_safe and mark_safe, but for the moment I am happy
> that its working now.  Thanks a lot for pointing it out!
>

allow_tags predates the general autoescaping support that added is_safe &
friends, that is why its name is a bit inconsistent.

Karen

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Basic SQL

2008-11-04 Thread Tonne

I must have read that section ten times, but not seen the wood for the
trees in my haste to find the right approach. It's making more sense
to me now.

Thanks 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-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: align a ModelForm

2008-11-04 Thread limas

hello Thomas,
i tried with ModelAdmin, but it is not working properly in my own
views.
i got this error "__init__() got an unexpected keyword argument
'instance'"
hop u understand what my problem is.
Actually i want to customize my page with a look and feel of django
admin page. Some modification in the alignment of a single ModelForm.

thank you for ur suggestions.
i expect u will respond to this reply..
Lima


On 3 Nov, 18:33, Thomas Guettler <[EMAIL PROTECTED]> wrote:
> limas schrieb:
>
> > Can i align a single long ModelForm into two raws?
> > can i use django admin modules for my own purpose by customizing it?
> > please give me some suggestions .
>
> Yes, you can do both. Suggestion: Read the documentation.
>
> Suggestion:http://docs.djangoproject.com/en/dev/ref/contrib/admin/http://groups.google.com/group/django-users/browse_thread/thread/536e...
>
>  HTH,
>   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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Basic SQL

2008-11-04 Thread Daniel Roseman

On Nov 4, 9:50 am, Tonne <[EMAIL PROTECTED]> wrote:
> Daniel, thank you (x100)! That was exactly what I was looking for.
>
> > {% for entry in entries %}
> > {{ entry.title }}
> >     {% for image in entry.image_set.all %}
> >     
> >     {% endfor %}
> > {% endfor %}
>
> Now, could I ask what the name of the concept is that allows
> "image_set" to spontaneously exist, so that I can read up more about
> it in the docs? I seemed to have missed it so far.

Backwards or reverse relationships. See here:
http://docs.djangoproject.com/en/dev/topics/db/queries/#following-relationships-backward

--
DR.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Graphing error using Surftrackr

2008-11-04 Thread El'd

Hi Guys

Got Surftrackr up and running on Apache using Django and all the
necessary packages needed as describe in the How-To-Install manual.
I'm getting this error when wanting to graph the user statistics:


AssertionError at /graphs/group/1/bytes/pie3d/ Request Method: GET
Request URL: http://192.168.100.110/graphs/group/1/bytes/pie3d/
Exception Type: AssertionError
Exception Value:
Exception Location: /usr/lib/python2.4/site-packages/
pygooglechart-0.2.1-py2.4.egg/pygooglechart.py in float_scale_value,
line 102 Python Executable: /usr/bin/python Python Version: 2.4.3
Python Path: ['/data', '/usr/lib/python2.4/site-packages/
pygooglechart-0.2.1-py2.4.egg', '/usr/lib/python2.4/site-packages/
MySQL_python-1.2.2-py2.4-linux-i686.egg', '/usr/lib/python2.4/site-
packages/dateutil-1.2-py2.4.egg', '/usr/lib/python24.zip', '/usr/lib/
python2.4/site-packages', '/usr/lib/python2.4', '/usr/lib/python2.4/
plat-linux2', '/usr/lib/python2.4/lib-tk', '/usr/lib/python2.4/lib-
dynload', '/usr/lib/python2.4/site-packages/Numeric', '/usr/lib/
python2.4/site-packages/gtk-2.0']


Environment:

Request Method: GET
Request URL: http://192.168.100.110/graphs/group/1/bytes/pie3d/
Django Version: 0.97-pre-SVN-unknown
Python Version: 2.4.3
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'django.contrib.humanize',
 'surftrackr.log',
 'surftrackr.wordsearch',
 'surftrackr.preferences',
 'surftrackr.search',
 'surftrackr.httpauth',
 'surftrackr.trackr']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.doc.XViewMiddleware')


Traceback:
File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py"
in get_response
  82. response = callback(request, *callback_args,
**callback_kwargs)
File "/data/surftrackr/graphs/views.py" in show_group_graph_bytes
  106. google_chart = chart.get_url()
File "/usr/lib/python2.4/site-packages/pygooglechart-0.2.1-py2.4.egg/
pygooglechart.py" in get_url
  336. url_bits = self.get_url_bits(data_class=data_class)
File "/usr/lib/python2.4/site-packages/pygooglechart-0.2.1-py2.4.egg/
pygooglechart.py" in get_url_bits
  886. url_bits = Chart.get_url_bits(self,
data_class=data_class)
File "/usr/lib/python2.4/site-packages/pygooglechart-0.2.1-py2.4.egg/
pygooglechart.py" in get_url_bits
  344.
url_bits.append(self.data_to_url(data_class=data_class))
File "/usr/lib/python2.4/site-packages/pygooglechart-0.2.1-py2.4.egg/
pygooglechart.py" in data_to_url
  592. data = self.scaled_data(data_class, self.x_range,
self.y_range)
File "/usr/lib/python2.4/site-packages/pygooglechart-0.2.1-py2.4.egg/
pygooglechart.py" in scaled_data
  900. return Chart.scaled_data(self, data_class, x_range,
self.y_range)
File "/usr/lib/python2.4/site-packages/pygooglechart-0.2.1-py2.4.egg/
pygooglechart.py" in scaled_data
  577. scaled_dataset.append(
File "/usr/lib/python2.4/site-packages/pygooglechart-0.2.1-py2.4.egg/
pygooglechart.py" in scale_value
  116. scaled = cls.int_scale_value(value, range)
File "/usr/lib/python2.4/site-packages/pygooglechart-0.2.1-py2.4.egg/
pygooglechart.py" in int_scale_value
  112. return int(round(cls.float_scale_value(value, range)))
File "/usr/lib/python2.4/site-packages/pygooglechart-0.2.1-py2.4.egg/
pygooglechart.py" in float_scale_value
  102. assert(upper > lower)

Exception Type: AssertionError at /graphs/group/1/bytes/pie3d/
Exception Value:

Any assistance would be appreciated.


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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: "Mix and match" model form?

2008-11-04 Thread Jonathan Buchanan

On Tue, Nov 4, 2008 at 9:59 AM, Håkan Waara <[EMAIL PROTECTED]> wrote:
>
> I would love any ideas or feedback around this area, and to hear of
> how others in the community do it.
>
> /Håkan

I would just use two Forms.

Forms:

class EditUserForm(forms.ModelForm):
class Meta:
model = User
fields = (email, first_name, last_name)

class EditProfileForm(forms.ModelForm):
class Meta:
model = Profile
fields = (avatar, location)

View:

def edit_user(request, user_id):
user = get_object_or_404(User, id=user_id)
profile = user.get_profile()

if request.method == 'POST':
user_form = EditUserForm(request.POST, instance=user)
profile_form = EditProfileForm(request.POST,
   instance=profile)
if all([user_form.is_valid(), profile_form.is_valid()]):
user_form.save()
profile_form.save()
return HttpResponseRedirect(
reverse('user_profile', args=[user_id]))
else:
user_form = EditUserForm(instance=user)
profile_form = EditProfileForm(instance=profile)

return render_to_response('edit_user.html', {
'user_': user,
'user_form': user_form,
'profile_form': profile_form,
}, context_instance=RequestContext(request))

Template:


  {{ user_form.as_p }}
  {{ profile_form.as_p }}
  

Cancel
  


Regards,
Jonathan.

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



"Mix and match" model form?

2008-11-04 Thread Håkan Waara

Hello all,

A situation that I'm encountering all the more often is something like  
this: You create a form that has some fields that belong to one model,  
and some fields from another model. Because it's a mix, you can't make  
it as easy as a ModelForm. I love ModelForms. :-)

One common example of this is if you want to change user information,  
and you have a UserProfile -- you may want to change both the User and  
its associated UserProfile.

Ideally, the MixModelForm class would work something like this:

1) It would allow you to specify fields from different models that you  
want to "import" into this form
2) It would validate based on those fields, of course
3) Finally, if everything validates fine, it would take care of saving  
the data in all the right places

So what are your ways of dealing with this situation?

I actually started working on this kind of form class, but got lost in  
metaclass hell. And I'm worried that I'd run into problems if I'm  
starting to override django Form classes, since metaclasses and this  
style of programming is relatively new for me.

If anyone is interested, I have created an AdaptiveField(model, field,  
**kwargs) that accomplishes #1 and #2, but you still have to care of  
saving yourself (#3).

I would love any ideas or feedback around this area, and to hear of  
how others in the community do it.

/Håkan
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Basic SQL

2008-11-04 Thread Tonne

Daniel, thank you (x100)! That was exactly what I was looking for.

> {% for entry in entries %}
> {{ entry.title }}
>     {% for image in entry.image_set.all %}
>     
>     {% endfor %}
> {% endfor %}

Now, could I ask what the name of the concept is that allows
"image_set" to spontaneously exist, so that I can read up more about
it in the docs? I seemed to have missed it so far.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django's decoupling apps but template should couple them together, right?

2008-11-04 Thread ilmarik

Thank you for all your elaborated answers

However I still don't see the point to have decouped apps in my
project. Web page mainly is a program for serving some text or media
or for saving some user data under the hood. Having an app for
particular business logic AND another pool of views, tags and
processors to use it, feels like I have to create everything twice or
makes an app to be a directory with just models.py in it.

I was realy happy when I read about apps, but now I feel a bit
disappointed.
what about using third party elements in my project?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Basic SQL

2008-11-04 Thread Daniel Roseman

On Nov 4, 7:45 am, Tonne <[EMAIL PROTECTED]> wrote:
> I think I may be barking up the wrong tree, and if so please excuse
> the above. I now suspect that I should be associating the images with
> their relevant entries with template tags.

You don't even need to do that. Assuming you have a queryset of Entry
objects as a variable called 'entries':

{% for entry in entries %}
{{ entry.title }}
{% for image in entry.image_set.all %}

{% endfor %}
{% endfor %}

Obviously change the mark-up to suit.
You would need a template tag if you wanted to filter the list of
related images based on some extra criteria, since you can't pass in
parameters to filter via the plain template language.

--
DR.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



saving multiple versions of an uploaded image

2008-11-04 Thread Chris Amico

Hi folks,

I'm trying to turn one uploaded image into several: a full-size and
thumbnail (and more, eventually). Here's the model I'm playing with,
just for testing:

class TestPhoto(models.Model):
"This is only for testing. Delete it later and make a real photo
model"
title = models.CharField(max_length=100)
pub_date = models.DateTimeField(auto_now_add=True)
full_size = models.ImageField(upload_to="images/photos/%Y/%b/%d")
thumbnail = models.ImageField(upload_to="images/photos/%Y/%b/%d",
blank=True)

Resizing is simple enough using a script off Django Snippets:

def thumbnail(filename, size=(50, 50), output_filename=None):
image = Image.open(filename)
if image.mode not in ('L', 'RGB'):
image = image.convert('RGB')
image = image.resize(size, Image.ANTIALIAS)

# get the thumbnail data in memory.
if not output_filename:
output_filename = get_default_thumbnail_filename(filename)
image.save(output_filename, image.format)
return output_filename

That part works like a charm when I run it on save(), and the returned
files end up exactly where they should be. But how do I get Django to
recognize that output file as a File object?

I've tried adding another ImageField to the model and using a save()
method to populated it with the output_filename from thumbnail(). It
gets the path right, but the url ends up being something like
MEDIA_URL + self.full_size.path + "thumb.jpg" or media.mydomain.com/
home/chrisamico/webapps/media/images/photos/2008/Oct/23/
IMG_0460.thumb.jpg. That's a big 404.

I could write a simple method to create the right url (since it's just
full_size.url with .thumb.jpg on the end) but that would be repetitive
for each size.

Thanks as always for the 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-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: link to other record in admin change list

2008-11-04 Thread chris

Dear Fabio,

That did the trick!  I have searched all over the manuals, but must
have overlooked this.  It is a bit confusing that this seems to be
different from is_safe and mark_safe, but for the moment I am happy
that its working now.  Thanks a lot for pointing it out!

Chris

On Nov 4, 4:06 pm, Fabio Natali <[EMAIL PROTECTED]> wrote:
> Chris wrote:
>
> [...]
>
> > I have set up a callable in the admin.py, but the HTML I eject there
> > gets escaped, so that I end up seeing etc in the
> > list, instead of the link.  Here is the relevant piece of admin.py:
>
> Hi Chris! Did you try with varchars.allow_tags?
>
> http://docs.djangoproject.com/en/dev/ref/contrib/admin/#list-display
>
> Hth,
>
> --
> Fabio Natali
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---