Re: Several translations for the same string

2010-07-05 Thread Nuno Maltez
Have you tried giving the message different IDs and, in the English po
file, translating them to the same string while in the italian
language file translating to the same string? Silly example:

###it/myapp.po
#: .\myapp\models.py:39
msgid "is active (m)"
msgstr "è attivo"

#: .\myapp\models.py:87
msgid "is active (f)"
msgstr "è attiva"


###en/myapp.po
#: .\myapp\models.py:39
msgid "is active (m)"
msgstr "is active"

#: .\myapp\models.py:87
msgid "is active (f)"
msgstr "is active"


HTH,
Nuno

On Mon, Jul 5, 2010 at 10:53 AM, donato.gr  wrote:
> Hello,
> I'm writing an application which has to be translated in English and
> Italian.
> The problem is that italian adjectives change form according to the
> gender of the word they are referred to.
> E. g. "is active" can be translated as 'è attivo' or 'è attiva'.
>
> My question is: is it possible to specify more translations in
> django.po file, each to be used in specific classes or modules?
>
> Something like (of course, this won't work):
> #: .\myapp\models.py:39
> msgid "is active"
> msgstr "è attivo"
>
> #: .\myapp\models.py:87
> msgid "is active"
> msgstr "è attiva"
>
>
> Thank you,
> Donato
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Apache config trouble

2010-07-07 Thread Nuno Maltez
Hi,

Are you sure the syntax error isn't in the wsgi file itself?
/Library/WebServer/testing123/apache/django.wsgi

Nuno

On Wed, Jul 7, 2010 at 3:02 PM, Bradley Hintze
 wrote:
> Hi all,
>
> I'm getting the following error n the apache error log:
>
> [Wed Jul 07 09:53:12 2010] [error] [client 152.16.223.251] mod_wsgi
> (pid=425): Exception occurred processing WSGI script
> '/Library/WebServer/testing123/apache/django.wsgi'.
> [Wed Jul 07 09:53:12 2010] [error] [client 152.16.223.251]   File
> "/Library/WebServer/testing123/apache/django.wsgi", line 9
> [Wed Jul 07 09:53:12 2010] [error] [client 152.16.223.251]
> [Wed Jul 07 09:53:12 2010] [error] [client 152.16.223.251]     ^
> [Wed Jul 07 09:53:12 2010] [error] [client 152.16.223.251]
> SyntaxError: invalid syntax
>
>
>
> Here is what I have in httpd.conf:
>
> #WSGI stuff
> WSGIScriptAlias / /Library/WebServer/testing123/apache/django.wsgi
>
> 
> Order deny,allow
> Allow from all
> 
> #
>
> I am not seeing the 'invalid syntax.'
>
> Ane help would be appreciated
>
> --
> Bradley J. Hintze
> Graduate Student
> Duke University
> School of Medicine
> 801-712-8799
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Query raises a DoesNotExist error

2010-07-07 Thread Nuno Maltez
At a glance:

>        try:
>            FullProfile.objects.get(email=email)
>        except FullProfile.DoesNotExist:
>
>         test =
> FullProfile.objects.get(email=self.cleaned_data['email'])
>         raise forms.ValidationError("%s" % (test))


Shouldn't the second FullProfile.objects.get just raise a
FullProfile.DoesNotExist eception again? It seems you're just catching
an exception in order to throw it again in the except block...

hth,
Nuno

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



Re: models.py import from other models.py

2010-07-08 Thread Nuno Maltez
What error do you get when you execute  'manage.py syncDB'? Could you
paste it here?

Nuno

On Thu, Jul 8, 2010 at 2:28 AM, yugori  wrote:
> Hi, I'm beginner.
>
> I tried to execute 'manage.py syncDB' command,
> but it's not work.

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



Re: return number instead of string in admin

2010-07-14 Thread Nuno Maltez
Hi,

Why not

def __unicode__(self):
return u"%d" % self.mynumber

?

Nuno

On Wed, Jul 14, 2010 at 11:15 AM, alan-l
 wrote:
> Hi,
>
> in the tutorial i see that to return a string or a combination of
> strings, i can do:
>    def __unicode__(self):
>        return u'%s %s' % (self.firstname, self.surname)
>
>
> what do i need to do to return a number? or more importantly, what is
> the def called to ensure it is read and returned when looking at the
> class in admin?
>
>
> Thanks,
>
> Alan
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Admin Model Validation on ManyToMany Field

2010-07-14 Thread Nuno Maltez
Hi,

Just a guess: have you actually selected a user and a folder when
submitting the form? I think only valid field are present on the
cleaned_data dict, and your users and folder fields are not optional
(blank=True, null=True).

hth,
nuno

On Tue, Jul 13, 2010 at 1:45 PM, Heleen  wrote:
> Hello,
>
> I have the following classes:
> class Application(models.Model):
>  users = models.ManyToManyField(User, through='Permission')
>  folder = models.ForeignKey(Folder)
>
> class Folder(models.Model):
>  company = models.ManyToManyField(Compnay)
>
> class UserProfile(models.Model):
>  user = models.OneToOneField(User, related_name='profile')
>  company = models.ManyToManyField(Company)
>
> Now when I save application, I would like to check if the users do not
> belong to the application's folder's companies.
> I have posed this question before and someone came up with the
> following sollution:
> forms.py:
> class ApplicationForm(ModelForm):
>    class Meta:
>        model = Application
>
>    def clean(self):
>        cleaned_data = self.cleaned_data
>        users = cleaned_data['users']
>        folder = cleaned_data['folder']
>        if
> users.filter(profile__company__in=folder.company.all()).count() > 0:
>            raise forms.ValidationError('One of the users of this
> Application works in one of the Folder companies!')
>        return cleaned_data
>
> admin.py
> class ApplicationAdmin(ModelAdmin):
>    form = ApplicationForm
>
> This seems like right the way to go about this. The problem is that
> neither the users nor folder fields are in the cleaned_data and I get
> a keyerror when it hits the users = cleaned_data['users'] line.
>
> I was hoping that someone here could explain to me why these
> manytomany fields don't show up in cleaned_data and that someone could
> possibly give me a sollution to my problem.
>
> Thanks!
> Heleen
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Admin Model Validation on ManyToMany Field

2010-07-14 Thread Nuno Maltez
Sorry, I can't reproduce your error with django 1.2.

I copied your models (just removed the intermediaty "Permission"
because I don't know your User model) into a new app and I have 2
scenarios Adding an Application in the admin:

a) if I select a User and Folder, the validation runs just fine
b) if I do not select an User, then the "clean" method is still
accessed, but since 'users' is not present in the cleaned_data dict it
throws an exception - which is the scenario you give, hence my
original guess :)

Nuno

On Wed, Jul 14, 2010 at 2:32 PM, Heleen  wrote:
> Thank you for your reply.
>
> Yes I have selected a user and folder.
> I believe ManyToMany fields are always optional (hence many to many).
> So my users and company fields are optional, but my folder field
> isn't.
> When I add a new Application in the Admin I do specify a folder and
> users (if I don't I would at least get a 'Required field' error for
> the folder field).

> I've tested the method above (clean function) with another model that
> has a manytomany field, and it does exactly the same thing, even when
> I really do fill in the data. In fact, if I delibirately throw an
> error and look in the debug info I can see the ManyToMany field data
> being present in the POST data, just like I can when I do the same
> thing with the above models.
>
> Btw, I just noticed a typo in my Folder model description above,
> that's not the issue as it's correct in my original model.
>
> On Jul 14, 2:02 pm, Nuno Maltez  wrote:
>> Hi,
>>
>> Just a guess: have you actually selected a user and a folder when
>> submitting the form? I think only valid field are present on the
>> cleaned_data dict, and your users and folder fields are not optional
>> (blank=True, null=True).
>>
>> hth,
>> nuno
>>
>> On Tue, Jul 13, 2010 at 1:45 PM, Heleen  wrote:
>> > Hello,
>>
>> > I have the following classes:
>> > class Application(models.Model):
>> >  users = models.ManyToManyField(User, through='Permission')
>> >  folder = models.ForeignKey(Folder)
>>
>> > class Folder(models.Model):
>> >  company = models.ManyToManyField(Compnay)
>>
>> > class UserProfile(models.Model):
>> >  user = models.OneToOneField(User, related_name='profile')
>> >  company = models.ManyToManyField(Company)
>>
>> > Now when I save application, I would like to check if the users do not
>> > belong to the application's folder's companies.
>> > I have posed this question before and someone came up with the
>> > following sollution:
>> > forms.py:
>> > class ApplicationForm(ModelForm):
>> >    class Meta:
>> >        model = Application
>>
>> >    def clean(self):
>> >        cleaned_data = self.cleaned_data
>> >        users = cleaned_data['users']
>> >        folder = cleaned_data['folder']
>> >        if
>> > users.filter(profile__company__in=folder.company.all()).count() > 0:
>> >            raise forms.ValidationError('One of the users of this
>> > Application works in one of the Folder companies!')
>> >        return cleaned_data
>>
>> > admin.py
>> > class ApplicationAdmin(ModelAdmin):
>> >    form = ApplicationForm
>>
>> > This seems like right the way to go about this. The problem is that
>> > neither the users nor folder fields are in the cleaned_data and I get
>> > a keyerror when it hits the users = cleaned_data['users'] line.
>>
>> > I was hoping that someone here could explain to me why these
>> > manytomany fields don't show up in cleaned_data and that someone could
>> > possibly give me a sollution to my problem.
>>
>> > Thanks!
>> > Heleen
>>
>> > --
>> > You received this message because you are subscribed to the Google Groups 
>> > "Django users" group.
>> > To post to this group, send email to django-us...@googlegroups.com.
>> > To unsubscribe from this group, send email to 
>> > django-users+unsubscr...@googlegroups.com.
>> > For more options, visit this group 
>> > athttp://groups.google.com/group/django-users?hl=en.
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Admin Model Validation on ManyToMany Field

2010-07-14 Thread Nuno Maltez
On Wed, Jul 14, 2010 at 3:50 PM, Nuno Maltez  wrote:
> Sorry, I can't reproduce your error with django 1.2.
>
> I copied your models (just removed the intermediaty "Permission"
> because I don't know your User model) into a new app and I have 2

Oops, forgot to add i made the ManyToMany  a relation to django's User model.

Nuno

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



Re: problem models.py code

2010-07-14 Thread Nuno Maltez
Just set primary_key=True on your field:

jono = models.PositiveIntegerField(primary_key=True)

See the django documentation for details:
http://docs.djangoproject.com/en/dev/topics/db/models/#id1

Nuno

On Wed, Jul 14, 2010 at 6:38 PM, Jagdeep Singh Malhi
 wrote:
> I try  this code to create database in using django.
>
> file :models.py
> class amount(models.Model):
>     jono = models.PositiveIntegerField(unique=True)
>     name = models.CharField(max_length=750)
>     receipt = models.CharField(max_length=200)
>     phno = models.CharField(max_length=25)
>     type = models.CharField(max_length=50)
>     rdate = models.DateField('date published')
>     site = models.CharField(max_length=200)
>
> after run
> #python manage.py sql tcc
> command i get
> BEGIN;
> CREATE TABLE `tcc_amount` (
>    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
>    `jono` integer UNSIGNED NOT NULL UNIQUE,
>    `name` varchar(750) NOT NULL,
>    `receipt` varchar(200) NOT NULL,
>    `phno` varchar(25) NOT NULL,
>    `type` varchar(50) NOT NULL,
>    `rdate` date NOT NULL,
>    `site` varchar(200) NOT NULL
> )
> ;
> COMMIT;
>
> But i want 'jono'  is also AUTO_INCREMENT with 'id'  or  only jono
> not include the 'id '.
> Which code is used to make 'jono ' to auto increment.??
> Pleases help ,if possible.
>
> thanks
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Problem with simple search func in template

2010-07-16 Thread Nuno Maltez
On Fri, Jul 16, 2010 at 1:56 PM, maciekjbl  wrote:
> urlpatterns = patterns('django.views.generic.list_detail',
>    url(r'^(?P[-\w]+)/$', 'object_detail', info, name="link-
> prod"),
>    url(r'^$','object_list', info, name="link-home"),
>
> )
>
> urlpatterns += patterns('web_aplikacje.produkty.views',
>   url(r'^search/$', 'search', name="link-search"),
> )
>

I think your '/search/' url is being caught by your
"r'^(?P[-\w]+)/$" pattern and object_detail cannot find an
object with a 'search' slug.

Try to place the search pattern before the generic slug one.

hth,
Nuno

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



Re: Custom form field validation and required=False

2010-07-16 Thread Nuno Maltez
Hi,

Looking at Django's forms/fiedls.py may give you some ideas.

The test for an empty value is

if value in validators.EMPTY_VALUES

You can also use self.required to see if the required attribute is set
(e.g., see Field's validate() method).

Of course, a username with a single space will still raise your "User
not found" exception using this method  - but I think it's standard
behaviour for all Fields (try inserting a space in an integer field).

You're also ignoring validators on your custom clean method, but I
guess that's because you know you won't need them :)

"""
The clean() method on a Field subclass. This is responsible for
running to_python, validate and run_validators in the correct order
and propagating their errors. If, at any time, any of the methods
raise ValidationError, the validation stops and that error is raised.
This method returns the clean data, which is then inserted into the
cleaned_data dictionary of the form.
"""
http://docs.djangoproject.com/en/dev/ref/forms/validation/

hth,
Nuno




On Fri, Jul 16, 2010 at 2:01 PM, Paddy Joy  wrote:
> I'm trying to create a custom form field that will validate against
> auth.user. The field should throw a validation error if the user does
> not exist, otherwise the field should validate.
>
> So far I have:
>
> class ExistingUserField(forms.CharField):
>    def clean(self, value):
>        # Check if the user exists
>        try:
>            user = User.objects.get(username=value)
>        except:
>            # User does not exist
>            raise forms.ValidationError('User %s not found' % value)
>       return value
>
> I then use this in a form as:
>
> class MyForm(forms.Form):
>    user = ExistingUserField(required=False)
>
> This code works as expected when the user field is populated but does
> not honour the "required=False" argument, when the user field is left
> blank the error "User not found" is raised.
>
> Do i need to check for all forms of None and blank strings? Is there a
> better way?
>
> Paddy
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: GAE + Django Authentication

2010-07-20 Thread Nuno Maltez
Hi,

Have you tried django-nonrel? -
http://www.allbuttonspressed.com/projects/django-nonrel


On Tue, Jul 20, 2010 at 6:59 AM, Venkatraman S  wrote:
> Hi,
>
> Has anyone made inroads into django auth in GAE? I have been Googling around
> for sometime and havent found a credible link on this.
> Help would be great.
>
> Regards,
> -V
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Accessing the current user's first name

2010-07-20 Thread Nuno Maltez
Hi,

If user is a FK to the User model, then simply self.user.first_name
should work.

http://www.djangoproject.com/documentation/models/many_to_one/

Have you set the user property on the object you're trying to save?
What error do you get?

Btw what exactly are you trying to achieve with this line (I simply
didn't understand)?
User.get_profile = lambda self: Profile.objects.get_or_create(user=self)[0]

Nuno

On Tue, Jul 20, 2010 at 4:38 PM, reduxdj  wrote:
> OK, from my example, the model is called Roommate, so I am not
> duplicating any User model data there... So all of the information
> in that model has nothing to do the main user's email or other
> properties.
>
> Thanks for helping, I still don't have an answer from the above. How
> do
> I access the current user's email and name?
>
> On Jul 20, 10:33 am, Bill Freeman  wrote:
>> You don't say what model this is.  Since it doesn't exactly match
>> django.contrib.auth.models, I'm going to guess that you may not
>> be aware that the User model includes first_name, last_name,
>> and email fields of its own.  Having duplicated those fields, are
>> you perhaps becoming confused about where to find things?
>> The typical registration apps usually place this data in the User
>> instance, so if you're looking for it in your instance, you would
>> have had to arrange to copy it everytime something changes it
>> in either model.
>>
>> Duplicating data in one-to-one models (if what I'm looking at is
>> your profile model) isn't likely to win "best practice" accolades.
>>
>> Bill
>>
>> On Tue, Jul 20, 2010 at 10:08 AM, reduxdj  wrote:
>> > HI,
>>
>> > So I tried for an hour or so to access  the current user's first name,
>> > so I can send out a personalized invitation email. That reads, "Hi
>> > Sam, Your friend Charlie wants you to sign up here..." I understand
>> > how to access the user info from context, but how do I do it from
>> > inside one of my models with a user foreign key?
>>
>> > Now, what's funny is I don't know how to access the current user's
>> > first name.  I tried the following.
>>
>> > Thanks for the help!
>>
>> > Here's some code below.
>>
>> >    user =  models.ForeignKey(User)
>> >    first_name = models.CharField(max_length=200)
>> >    last_name = models.CharField(max_length=200)
>> >    email = models.CharField(max_length=200)
>> >    inv_date  = models.DateTimeField(auto_now_add=True)
>> >    is_registered = models.BooleanField()
>>
>> >    #def __unicode__(self):
>> >    #    return self.user.username
>>
>> >    def save(self, *args, **kwargs):
>>
>> >        if send_mail:
>> >            User.get_profile = lambda self:
>> > Profile.objects.get_or_create(user=self)[0]
>> >            current_site = Site.objects.get_current()
>> >            #subject =
>> > render_to_string('roommate_invitation_subject.txt')
>> >            # Email subject *must not* contain newlines
>> >            subject = "Hello..."
>> >            subject = ''.join(subject.splitlines())
>> >            message = render_to_string('roommate_invitation_email.txt',
>> > {'invitee':self.first_name,'inviter': self.user.first_name,'site':
>> > current_site })
>> >            send_mail('Invitation to xxx', message, 'invite_...@xxx',
>> > [str(self.email)])
>>
>> > --
>> > You received this message because you are subscribed to the Google Groups 
>> > "Django users" group.
>> > To post to this group, send email to django-us...@googlegroups.com.
>> > To unsubscribe from this group, send email to 
>> > django-users+unsubscr...@googlegroups.com.
>> > For more options, visit this group 
>> > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: permalink problem

2010-07-20 Thread Nuno Maltez
Maybe you can get a better description / traceback of the error from
the shell. Something like

python manage.py shell
>> from myapp.models import Post
>> p = Post.objects.all()[0]
>> p.get_absolute_url()

hth,
Nuno

On Tue, Jul 20, 2010 at 4:46 AM, vcarney  wrote:
> I'm having a problem getting a permalink to render an absolute url.
> Here is my template code:
>
>  href="{{ post.get_absolute_url }}">{{ post.title }}
>
> In models.py I have a Post class with:
>
> @models.permalink
>    def get_absolute_url(self):
>        return ('vblog_detail_month_numeric', (), {
>            'year': self.publish.year,
>            'month': self.publish.strftime('%m').lower(),
>            'day': self.publish.day,
>            'slug': self.slug
>        })
>
> Here is where I have a named url:
>
> url(r'^(?P\d{4})/(?P\d{1,2})/(?P\d{1,2})/(?P[-
> \w]+)/$',
>        view=vblog_views.post_detail,
>        name='vblog_detail_month_numeric'),
>
> My post_detail function starts with:
>
> def post_detail(request, slug, year, month, day, **kwargs):
>
> The post title always gets a blank href url returned in  href="{{ post.get_absolute_url }}">
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Unicode challenged

2010-08-09 Thread Nuno Maltez
> I have also tried replacing the write() statement with
> write( string_content.encode( '' )) where I have tried the
> encodings 'latin-1' and 'utf-8'; then it does not fail hard, but
> instead of the wanted 'øåæ' characters I get '?' marks.

Are you sure that you get '?' on the file if you write it this way, or
it's just
the console/editor that you're using to see the file's contents that
cannot handle
the text's encoding?

I really think write( string_content.encode( '' )) should work fine.

Nuno

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



Re: Need help with my Form.save() method. Trouble with ForeignKey and ManyToMany Fields.

2010-08-09 Thread Nuno Maltez
>        def clean_username(self):
>                data = self.cleaned_data['username']
>                try:
>                        User.objects.get(username=data)
>                except User.DoesNotExist:
>                        return
>                raise forms.ValidationError('The username "%s" is already 
> taken.' %
> data)


The django docs [1] say that for the clean_ method, "Just
like the general field clean() method, above, this method should
return the cleaned data, regardless of whether it changed anything or
not."

Since you're returning nothing, self.cleaned_data['username'] will be
None when saving your user hence the "auth_user.username may not be
NULL" exception.


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

hth,
Nuno

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



Re: problem with a formset from model

2010-08-11 Thread Nuno Maltez
This happens to me as well (also with 1.2.1). Seems like a bug with
_queryset vs queryset on BaseModelFormSet.

Maybe you could submit a ticket to http://code.djangoproject.com/query

Nuno

On Tue, Aug 10, 2010 at 9:21 PM, refreegrata  wrote:
> Hello list. I have a problem. I'm a newbie in Django using his first
> formset.
>
> I have this:
> 
> class BaseFormFormato_habilitar(BaseModelFormSet):
>    def __init__(self, *args, **kwargs):
>        super(BaseFormFormato_habilitar, self).__init__(*args,
> **kwargs)
>        self.queryset = Formato.objects.filter(actividad=True)
>
> FormFormato_habilitar = modelformset_factory(Formato, max_num=0,
> formset=BaseFormFormato_habilitar)
> 
>
> I want a formset with forms filtered for
> "Formato.objects.filter(actividad=True)", however, the formset always
> returns all the rows in the table. My alternatively subclass
> "BaseFormFormato_habilitar" don't works. What am I doing wrong?
> the problem is solved if i do "FormFormato_habilitar(queryset =
> Formato.objects.filter(actividad=True))" in a view, but i prefer solve
> the problem with a subclass in the "forms.py".
>
> thanks for read, and sorry for my poor english
>
> P.D.: I use Django 1.2.1
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: I need a middleware to add language to urls in my templates

2010-08-11 Thread Nuno Maltez
I'm not sure if this provides exactly what you need, and I've never
tested it with satchmo, but I've been using
http://code.google.com/p/django-localeurl/ with success to proved
different urls according to the language transparently.

Maybe this helps,
Nuno

On Wed, Aug 11, 2010 at 3:46 PM, Alessandro Ronchi
 wrote:
> I have a website that uses a get variable to set the django language. After
> that, a user can navigate the site in the choosen language.
> Web spiders, instead, reads all the web pages In standard language, because
> links doesn't have ?lang=en
> So, as a result, all my translated pages aren't on google.
> I know I should have different urls, but I cannot in this project because
> I'm using satchmo, a django e-commerce system, and I can't edit urls to work
> this way.
> So I thought I can create a middleware that incercepts all my  href="http://mydomain";> urls in templates and adds to href a lang=en,
> lang=fr,
> if the request.language is respectively en, fr.
> So all my links should be ok.
> Is it possible?
>
> --
> Alessandro Ronchi
> http://www.soasi.com
>
> Hobby & Giochi
> http://hobbygiochi.com
> http://www.facebook.com/hobbygiochi
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: problem with block tag and autoescaping

2010-09-16 Thread Nuno Maltez
On Wed, Sep 15, 2010 at 4:50 PM, Julian  wrote:
> before returning, all paramaters in the urls are separated by & as
> they should be. in the template the & occur as &. for example, the
> url is print'ed in the tag:
>
> /go/to/url?
> utts=-1&utsrc=trackuser&utsig=f6730dc992ee9a23c24ed0adae0eb5f6
>
> and in the template it looks like
>
> test a>

Sorry I can't help you much (never happened to me) but:

a) are you sure it's not beautifulsoup that's replacing your &?

b) shouldn't they be really separated by "&"? Using & will cause
validation errors:
http://htmlhelp.com/tools/validator/problems.html#amp

Nuno

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



Re: Deply with mod_wsgi

2010-09-16 Thread Nuno Maltez
At a glance: is your graphic dynamically generated and served by
Django? If so, shouldn't the the src of the img tag point
to /simuladores/grafico/ - or something under /simuladores where the
wsgi script can catch it - instead of /grafico ?

If your code is writing the image to the filesystem, is it writing it
to /var/www/django/grafico ?

hth,
Nuno


On Thu, Sep 16, 2010 at 12:30 PM, Waléria Antunes David
 wrote:
> Hi all,
>
> I need to put my project on the web server. I installed the Python, Django,
> mod_wsgi and configured the VirtualHost file: http://pastebin.com/Xe7SqhM1
> and created the script for the WSGI: http://pastebin.com/jgLHipnB
> Attached below two images of my project in the browser. My problem is, in
> the first image i  pass values end click on make curve to generate a graph
> but an error is written in log_error: http://pastebin.com/ZPzdC5c8  and a
> graphic is not displayed. See second image.
>
> What would be?
>
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Deply with mod_wsgi

2010-09-16 Thread Nuno Maltez
Well, my guess is that you should change the template responsible for
the page in your second picture and fix the  tag that displays
the graphic so that the source points to /simuladores/grafico/ instead
of /grafico/

Nuno

On Thu, Sep 16, 2010 at 6:05 PM, Waléria Antunes David
 wrote:
> Yes, my graph is generated dynamically. Where do I change my code for this
> error doesn't occur and my image appears?
>
> On Thu, Sep 16, 2010 at 1:56 PM, Nuno Maltez  wrote:
>>
>> At a glance: is your graphic dynamically generated and served by
>> Django? If so, shouldn't the the src of the img tag point
>> to /simuladores/grafico/ - or something under /simuladores where the
>> wsgi script can catch it - instead of /grafico ?
>>
>> If your code is writing the image to the filesystem, is it writing it
>> to /var/www/django/grafico ?
>>
>> hth,
>> Nuno
>>
>>
>> On Thu, Sep 16, 2010 at 12:30 PM, Waléria Antunes David
>>  wrote:
>> > Hi all,
>> >
>> > I need to put my project on the web server. I installed the Python,
>> > Django,
>> > mod_wsgi and configured the VirtualHost file:
>> > http://pastebin.com/Xe7SqhM1
>> > and created the script for the WSGI: http://pastebin.com/jgLHipnB
>> > Attached below two images of my project in the browser. My problem is,
>> > in
>> > the first image i  pass values end click on make curve to generate a
>> > graph
>> > but an error is written in log_error: http://pastebin.com/ZPzdC5c8  and
>> > a
>> > graphic is not displayed. See second image.
>> >
>> > What would be?
>> >
>> > Thanks.
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Django users" group.
>> > To post to this group, send email to django-us...@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > django-users+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/django-users?hl=en.
>> >
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Mudar Senha de um usuário

2010-09-17 Thread Nuno Maltez
Hi,

If the user is logged in, instead of

user = User.objects.get(username=nome)

you can use

user = request.user

See:
http://docs.djangoproject.com/en/dev/topics/auth/#authentication-in-web-requests

Nuno



2010/9/17 Giovanna Ronzé :
> Dado que um usuário está logado e quer mudar sua senha, como eu faço
> para o django mudar a senha daquele user sem que seja preciso que ele
> preencha esse campo (do nick)?
>
> Bem, para resolver esse problema, primeiro eu fiz de uma forma que
> necessitava do user dizer o nick.
> Pesquisando, eu vi que tinha uma classe PasswordChangeForm e tentei
> usar. Olha, se alguém me ensinar como se usa de fato (tanto no
> urls.py, no html e no views.py se possível ^.^) tudo bem. Mas eu
> realmente não consegui aplicar essa classe.
>
> Diante disso, voltei para ideia inicial de construir minha própria
> função. O problema voltou a ser o tal do campo user. Já que o usuário
> está logado, como eu 'pego' seu campo de username pelo views.py?
>
> Aí está a tentativa dessa função e os trechos de código relativos:
>
> [views.py]
>
> @login_required
> def mudar_senha (request):
>        return render_to_response('matematica/mudar_senha.html')
>
> @login_required
> def mudar_senha_dados (request):
>        erro = False
>        nome = request.POST['username']
>        user = User.objects.get(username=nome)
>
>        if request.POST['password'] == '':
>                erro = True
>                return render_to_response('matematica/mudar_senha.html', 
> {'erro':
> erro})
>        else:
>                user.set_password(request.POST['new_password'])
>                user.save()
>                return HttpResponseRedirect('/')
>
> [mudar_senha.html]
>
>                 method="post">
>
>                        Nova senha 
>                                 type="password">
>                                        {{ form.new_password }}
>                        
>
>
>                        
>                        
>
> [urls.py]
>
>        (r'^mudar_senha/', 'projeto.matematica.views.mudar_senha'),
>        (r'^mudar_senha_dados/',
> 'projeto.matematica.views.mudar_senha_dados'),
>
> Bem. Desde já agradeço a atenção.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: RSS Questions

2010-09-20 Thread Nuno Maltez
Hi,

I didn't have any problems subscribing to your blog with google reader
from http://www.tapnik.com/

>
> Secondly, I'd like to include the entire post in the RSS feed, not
> just the description. Looking at other feeds, it looks like these are
> stuffed into a "content:encoded" tag? Is that right? How to I get the
> RSS feed to generate that?

What's wrong with including the post's html in the description field?

http://djangogigs.com/feeds/gigs/

hth,
Nuno

On Fri, Sep 17, 2010 at 6:52 PM, Joel Davis  wrote:
> Hello,
>
> I am trying to set up a blog on my django-based website. I followed
> the examples here:
>
> http://docs.djangoproject.com/en/1.1/ref/contrib/syndication/
>
> The docs are great, and it was pretty easy to set up. And it sort-of
> works. But there are a couple of problems I can't figure out.
>
> First: Autodiscovery in google reader (and others). When I put most
> websites with a link rel="alternate" type="application/rss+xml" tag
> into Google Reader, the reader can find the RSS feed and subscribe.
> However, when I try this with my site, i get "This site doesn't have a
> feed, google can auto-generate one for you.." As far as I can tell
> I've followed everything that google suggests for autodiscovery, I
> can't tell what's different about my setup vs. others.  I'm sure I'm
> doing something basic and stupid but I can't spot it.

> The website is at http://www.tapnik.com/ and the feed is
> http://www.tapnik.com/feeds/blog
>
> I did notice that this was all refactored in django 1.2, I'd rather
> stick with 1.1 if I can, but if this might be a lot easier in 1.2 then
> I'll consider that.
>
> Thanks for any advice!
> Joel
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: filepath (system file system path) field

2010-09-22 Thread Nuno Maltez
On Tue, Sep 21, 2010 at 6:17 PM, pixelcowboy  wrote:
> Hi, I have seen this asked before here (without answers), but I wanted
> to know how to go on about creating a field that stores filepath names
> from the client filesystem, so I wanted to check if someone could
> recommend the best apporach: Creating a custom field perhaps? Or
> perhaps extending the filefield? Or maybe just use a charfiled and do
> it all in validation? What do you guys think?

Hmmm something like this?
http://docs.djangoproject.com/en/dev/ref/models/fields/#filepathfield


Nuno

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



Re: Using urlencode with the url tag

2010-03-18 Thread Nuno Maltez
On Mon, Mar 15, 2010 at 11:28 PM, saxon75  wrote:
> I'm trying to generate a link where the URL of the current page gets
> passed in the querystring of the link.  Like so: .
>
> I would have thought that I could do this relatively easily with
> template tags, so I've tried this:
>
> <% url arg1, arg2 as the_url %>
> http://www.example.com?variable={{ the_url|urlencode }}">
>
> However, for whatever reason, the urlencode filter isn't applied when
> the_url renders.  Is there a way to do this directly in the template,
> or do I have to generate the encoded URL in the view and pass it to
> the template?

Are you sure it's no applied? urlencode uses python's urllib.quote
(http://docs.python.org/library/urllib.html#urllib.quote)
and I think it doesn't encode the '/' character by default - maybe
that's why you don't see any changes by applying the filter.

Nuno

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



Re: An odd issue with loading /media/ files

2010-03-19 Thread Nuno Maltez
Have you checked the logs (or what gets printed to the console in your
dev server) to see if what files flash is actually requesting from the
server? Any 404s?

Nuno

On Fri, Mar 19, 2010 at 2:48 PM, Jeffrey Taggarty  wrote:
> Any ideas? I know the flash loader is working just fine, it's a
> trivial routine that's been done countless times on non-django web
> apps we've written but for some reason I cannot get the files to load
> in a django app.
>
> Thanks
>
>
> -Jeff
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: query a foreignkey

2010-03-19 Thread Nuno Maltez
On Fri, Mar 19, 2010 at 2:11 PM, het.oosten  wrote:
> To clarify. If I have three houses, and  house 120 has two
> reservations, I get a list like this:
>
> 120 121 122 120 (if all are available)
>
> If the query matches one reservation of house 120 i get a list like
> this:
>
> 121 122 120
>
> House 120 should been excluded from the list though.

This still happens with the model suggested by bruno and a filter like:

House.objects.exclude(reservations__arrival__range=(Check_arrival,
Check_departure)).exclude(reservations__departure__range=(Check_arrival,
Check_departure))

?

Nuno

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



Re: Dynamic multi-site - running many sites from one Django instance

2010-03-23 Thread Nuno Maltez
On Mon, Mar 22, 2010 at 5:53 PM, Tim Shaffer  wrote:
> It gives you multiple sites from one codebase with multiple settings
> files. They are using the same project module. So your project would
> look like this:
>
> project
> - app1
> - app2
> - settings.py
> - settings_site1.py
> - settings_site2.py
> - urls.py
>
> settings.py would contain all the settings like a normal django
> project, then settings_site1 and settings_site2 could import all those
> default settings and overwrite just the settings they need to (like
> SITE_ID and MEDIA_ROOT).


This is the method we use in production.

Nuno

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



Re: Remove session on browser close

2010-03-23 Thread Nuno Maltez
Do you really need to show the message for the remainder of the
session? Or just when the page loads
right after the user has successfully subscribed? in this case you
could just delete the value after being "used":

if request.session.get('signed_up', True):
form.thanks = True
# delete 'signed_up' from session

I'm not sure this meets your needs, but it's a suggestion :)

Nuno

On Mon, Mar 22, 2010 at 9:40 PM, grimmus  wrote:
> Basically all i want to do is the following :
>
> Have a newsletter signup form. When the user signs up successfully the
> area where the form was has a thanks message instead of the form.
>
> The form or thanks message is displayed on every page of the site, so
> I thought using a session would be the best way handle whether to show
> the form or the thanks message.
>
> Here is my form
>
> 
>                
>                    {% if form.errors %}
>                    Please enter a valid email address.
>                    {% endif %}
>                    {% if form.thanks %}
>                    Thanks for signing up
>                    {% endif %}
>                    {% if form.alreadyexists %}
>                    The email address already exists
>                    {% endif %}
>                    {% if not form.thanks %}
>                       value="Email
> address" onfocus="this.select()" />
>                       value="Go"/>
>                    {% endif %}
>                
>              
>
> And my view
>
> if request.POST:
>        form = SignUp(request.POST)
>
>        if form.is_valid():
>
>            email = request.POST.get('email', '')
>
>            try:
>                entry = MailingList.objects.get(email=email)
>
>                form.alreadyexists = True
>
>            except (KeyError, MailingList.DoesNotExist):
>
>                entry = MailingList()
>                entry.email = email
>                entry.date_added = datetime.now()
>                entry.save()
>
>                request.session['signed_up'] = True
>                form.thanks = True
>
>            return HttpResponseRedirect(request.get_full_path())
>
>        else:
>            print form.errors
>
>    else:
>
>            form = SignUp()
>
>            t = loader.get_template('home/page.html')
>            c = RequestContext(request,{
>                'form':form,
>            })
>
>            if request.session.get('signed_up', True):
>                form.thanks = True
>
>            return HttpResponse(t.render(c))
>
>
> Any help is greatly appreciated.
>
> On Mar 22, 3:13 pm, Bill Freeman  wrote:
>> And if the user disables javascript, or kills the browser without
>> normal exit, or loses
>> his connection, or pulls the ethernet cable, or has a power failure?
>>
>> On Mon, Mar 22, 2010 at 10:06 AM, Wiiboy  wrote:
>> > Couldn't you use Javascript for this? For example, on the
>> > onbeforeunload event, delete the sessionid cookie?
>>
>> > --
>> > You received this message because you are subscribed to the Google Groups 
>> > "Django users" group.
>> > To post to this group, send email to django-us...@googlegroups.com.
>> > To unsubscribe from this group, send email to 
>> > django-users+unsubscr...@googlegroups.com.
>> > For more options, visit this group 
>> > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: How verbose model name in admin panel

2010-03-24 Thread Nuno Maltez
I think you need toput verbose_name(_plural) in the class Meta
http://docs.djangoproject.com/en/dev/topics/db/models/#id3

class Category(models.Model):
   class Meta:
  verbose_name = "Kategoria"
  verbose_name_plural = "Kategorie"

Nuno

On Wed, Mar 24, 2010 at 5:49 PM, serek  wrote:
> Hi
>
> I use Django 1.1 and I would like to display in admin panel different
> model name.
>
> For example from code:
> class Category(models.Model):
> in admin panel I receive
> 'Categorys' instead of Categories
>
> I googled for this and try:
> class Category(models.Model):
>    verbose_name = "Kategoria"
>    verbose_name_plural = "Kategorie"
>
> but it is not working. Is there any other possibility to achive that?
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Initial data in a many to many field

2010-03-25 Thread Nuno Maltez
>On Thu, Mar 25, 2010 at 2:00 AM, mjlissner  wrote:
> I'll make things more concrete. I have the following in my model
> (which is made into a ModelForm):
> class UserProfile(models.Model):
>    barmembership = models.ManyToManyField(BarMembership,
>        verbose_name="the bar memberships held by the user",
>        blank=True,
>        null=True)
>
> In my view, I have some code that looks like this:
>        userProfile = request.user.get_profile()
>        bar_memberships = userProfile.barmembership.all()
>
>        profileForm = ProfileForm(
>        initial = {'barmembership' : [bar_memberships]})


I don't know why you're not using the "instance" argument to populate the form

profileForm = ProfileForm(instance=userProfile)


but you need to give the ModelForm a list of PKs for the many-to-many-field:

bar_memberships = [obj.pk for obj in ob.barmembership.all()]
profileForm = ProfileForm( initial = {'barmembership' : bar_memberships})

(see the model_to_dict code in django/forms/models.py )

And force the refresh on the browser if it looks like it's not working
:) (at least FF has a strange
habit of keeping selections when reloading a form, ignoring the
initial selected items on the HTML).

hth,
Nuno

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



Re: probleme with delete on cascade with foreign key self-referencing

2010-03-29 Thread Nuno Maltez
Hello,

Are you sure you don't have a cyclic reference in there:

cat1 -> cat2 -> cat1 ?

You can always insert a

import pdb; pdb.set_trace()

line in the method and use the debugger to figure out what's keeping
the loop from exiting normally.

Nuno

On Mon, Mar 29, 2010 at 2:55 PM, mouadino  wrote:
> hello everybody
>
> I have a model class where i m  using a foreign key self-referencing
> here is my code :
>
> class Categories(custom.Model):
>    url = models.ForeignKey(Urls, null=True, blank=True)
>    category = models.CharField(max_length=128)
>    parent_category = models.ForeignKey('self', null=True, blank=True)
>
>    def delete_all(self):
>        """delete the parent category => deleting all sub categories
> with the cascade delete"""
>        category = self
>        while category.parent_category:  #the root category have the
> parent_category NULL
>            category = category.parent_category
>
>
>        category.delete()
>
>
> and when i m  using the delete_all() with a sub category usually it
> goes until the root category with the loop and should delete it with
> all the sub categories because of the cascade delete  .
>
> But when i m calling the delete_all() it's goes in an infinity loop .
>
> If someone can help me , and sorry for my 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-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: raw sql

2010-03-29 Thread Nuno Maltez
>        self.fields['man'].queryset=Pupil.objects.filter(gender='M')
>        self.fields['woman'].queryset=Pupil.objects.filter(gender='F')
>
> It returns only the man and woman for each combo box. Now, also, I only want
> the User wich aren't Teacher. How can I do this? I've tried with Manager.raw()
> but it doesn't work or I don't know how to use it

I'm not sure I understood what you need, but how about

self.fields['man'].queryset=Pupil.objects.filter(gender='M', user__teacher=None)


Nuno

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



Re: Passing hidden foreign key to form as initial value

2010-04-01 Thread Nuno Maltez
What about:

class CourseBook(ModelForm):
   course = ModelChoiceField(queryset=Course.objects.all(),
widget=HiddenInput())

   class Meta:
   model = CourseBooking

and in your view:

form = CourseBook(initial = {'course': course.pk})


Nuno

On Wed, Mar 31, 2010 at 8:06 PM, phoebebright  wrote:
> Final approach:
> in the forms.py excluded the courses foreign key field
> in models.py made courses blank and nullable
> didn't pass any initial values to the form
> in the view, saved the form like this:
>            item = Courses.objects.get(pk=whatever)
>            obj = form.save(commit=False)
>            obj.course = item
>            obj.save()
>
> This doesn't feel very tidy to me, I think the form should have the
> hidden values, but it works!
>
>
> On Mar 31, 4:15 pm, phoebebright  wrote:
>> Brandon, Thanks for your suggestion.
>> I tried passing it an ID, but as you say, I also have to override the
>> save.  What I don't understand is why it does it fine if the form
>> includes the foreign key in a popup?  They are both passing back
>> integers after all.
>>
>> Also failed to get the save method working, tried to pass in the
>> course instance, but it still ends up trying to save with the id of
>> the course.  Is it not using cleaned_data?
>>
>>     def save(self, course=False, force_insert=False,
>> force_update=False, commit=True):
>>         if course:
>>             self.cleaned_data['course'] = course
>>             return super(CourseBook, self).save(commit=commit)
>>
>> Any suggestions welcome as I've spent the whole afternoon on this - I
>> won't go through the many other workarounds that havn't worked!
>>
>> Phoebe.
>>
>> On Mar 31, 4:02 pm, Brandon Taylor  wrote:
>>
>> > Hi there,
>>
>> > Instead of using the course object in your initial data, which will
>> > pass in the __unicode__ representation of the object, pass in the id:
>>
>> > form = CouseBook(initial = {'course': course.id})
>>
>> > That should get you the numeric id, but you'll also need to override
>> > your save method to get the course object to assign when you save your
>> > CourseBook form, as you can't assign an integer (coming from your
>> > hidden form field) to the value of a ForeignKey field on a model.
>>
>> > HTH,
>> > Brandon
>>
>> > On Mar 31, 8:20 am, phoebebright  wrote:
>>
>> > > Displayed fields resolve as expected, hidden fields cause errors.
>>
>> > > This works:
>>
>> > > in the model
>> > > CourseBook has a foreign key to Course
>>
>> > > In the view:
>>
>> > > course = Course.objects.get(pk=whatever)
>> > > form = CouseBook(initial = {'course': course})
>>
>> > > in the Form:
>>
>> > > class CourseBook(ModelForm):
>> > >     class Meta:
>> > >         model = CourseBooking
>>
>> > > The web page now displays a picklist of courses with the initial value
>> > > highlighted.  I can now do a form.save() no problem.
>>
>> > > However, if I make the course a hidden field, which is what I want.
>>
>> > > class CourseBook(ModelForm):
>> > >     course = forms.CharField(widget=forms.HiddenInput())
>>
>> > >     class Meta:
>> > >         model = CourseBooking
>>
>> > > then when I come to save() I get a ValueError, unable to assign "My
>> > > course"  etc. as it tries to put the name of the course into the
>> > > foreign key instead of a course instance.
>>
>> > > I can work around this putting a save method on the form, but it seems
>> > > to me django should resolve this for me
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Complex Django query - filtering, joining a many-to-many table

2010-04-01 Thread Nuno Maltez
How about just accessing the "through" models attributes using user__ :

filters['user__question_published_date']

see 
http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships


Hht,
Nuno

On Thu, Apr 1, 2010 at 3:09 PM, Jim N  wrote:
> Hello Djanglers,
>
> I am using a named many-to-many table ("Asking") to join "Questions"
> to "Users".  Asking has some fields I'd like to filter against.
>
> I now use a dictionary called filters:
>
>     filters = {}
>
>     if 'question' in request.GET:
>         filters['text__icontains'] = request.GET['question']
>     if 'is_visible' in request.GET:
>         filters['is_visible'] = request.GET['is_visible']
>
> [...]
>
>     questions = Question.objects.filter(**filters)
>
>
> I need to add filtering by the publish dates of the question, which
> are stored in the many-to-many join table "Asking", which joins users
> to questions.
>
> I can't figure out how I would do such a thing.
>
>
> model Question:
>
> class Question(models.Model):
>     text = models.TextField()
>     question_type = models.ForeignKey('QuestionType')
>     user = models.ManyToManyField(User, through='Asking', null=True)
>     submit_date = models.DateTimeField('Date Submitted',
> default=datetime.datetime.now)
>     responses = models.IntegerField(default=0)
>
>
> model Asking:
>
> class Asking(models.Model):
>     user = models.ForeignKey(User)
>     question = models.ForeignKey(Question)
>     is_primary_asker = models.BooleanField()
>     is_targeted_answerer = models.BooleanField()
>     question_targeted_date = models.DateTimeField(null=True,
> blank=True)
>     question_scheduled_post_date = models.DateTimeField(null=True,
> blank=True)
>     question_published_date = models.DateTimeField(null=True,
> blank=True)
>
>
>
> The current filter code:
>
>     filters = {}
>
>     if 'question' in request.GET:
>         filters['text__icontains'] = request.GET['question']
>     if 'is_visible' in request.GET:
>         filters['is_visible'] = request.GET['is_visible']
>     if 'featured_status' in request.GET:
>         filters['featured_status'] = request.GET['featured_status']
>     if 'has_responses' in request.GET:
>         filters['responses'] = request.GET['has_responses']
>     if 'user_id' in request.GET:
>         filters['user'] = request.GET['user_id']
>
>     if 'vertical' in request.GET:
>         if not request.GET['vertical'].isdigit():
>             # if vertical is passed in by name, get id
>             vertical =
> Vertical.objects.filter(vertical=request.GET['vertical'])[0]
>             filters['verticals'] = vertical.id
>         else:
>             filters['verticals'] = request.GET['vertical']
>
>     if filters == {}:
>         logging.debug("no filters, selecting all.")
>         questions = Question.objects.all().order_by(order_by)
> [offset:limit]
>     else:
>         logging.debug("using filters.")
>         questions =
> Question.objects.filter(**filters).order_by(order_by)[offset:limit]
>
>
>
> Thanks for any suggestions!
>
> -Jim
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Passing hidden foreign key to form as initial value

2010-04-01 Thread Nuno Maltez
I think the form I sent, with ModelChoiceField, will validate with the
returned values without any further code. Or am I missing something
obvious?


On Thu, Apr 1, 2010 at 6:49 PM, phoebebright  wrote:
> That's one option, the problem is changing the course value returned
> from the form into a course object so that the form will validate.
> This turned out to be a surprising amount of trouble (because you have
> to do it before validation), hence reason for doing simpler work
> around.

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



Re: Noticed some strange behaviour of request.GET.get()

2010-04-07 Thread Nuno Maltez
The only difference I can see is that

request.GET.get ('subdir')

will return an unicode string, u"public_html", instead of a normal
string, 'public_html'.


If it works with the byte string, try changing the line to

subdir_path = str(request.GET.get('subdir'))

Nuno

2010/4/7 Alexey Vlasov :
> Hi.
>
> There's a simple code in urls.py:
> ==
> def ls (request):
>    import os
>
>    out_html = ''
>    home_path = '/home/www/test-django'
>    # subdir_path = request.GET.get ('subdir')
>    subdir_path = 'public_html'
>
>    for root, dirs, files in os.walk (os.path.join (home_path, subdir_path)):
>        out_html += "%s\n" % root
>
>    return HttpResponse (out_html)
> ==
>
> There's a catalogue in "home_path/subdir_path" which name
> includes cyrillic symbols (фыва):
> $ pwd
> /home/www/test-django/public_html
> $ ls -la
> drwx---r-x  4 test-django test-django  111 Apr  6 20:26 .
> drwx--x--- 13 test-django test-django 4096 Apr  6 20:26 ..
> -rw-r--r--  1 test-django test-django  201 Apr  6 17:43 .htaccess
> -rwxr-xr-x  1 test-django test-django  911 Apr  6 16:38 index.fcgi
> lrwxrwxrwx  1 test-django test-django   66 Mar 28 17:34 media -> ../
> python/lib64/python2.5/site-packages/django/contrib/admin/media
> drwxr-xr-x  2 test-django test-django    6 Apr  6 15:48 фыва
>
> My code works correct, here's the result:
> $ curl -s http://test-django.example.com/ls/
> /home/www/test-django/public_html 
> /home/www/test-django/public_html/фыва
>
> But if I change "subdir_path = 'public_html'" to
> "subdir_path = request.GET.get ('subdir')" then the request:
> $ curl -s http://test-django.example.com/ls/\?subdir=public_html
> leads to an error:
>
> Request Method: GET
> Request URL: http:// test-django.example.com/ls/
> Django Version: 1.0.2 final
> Python Version: 2.5.2
> Installed Applications:
> ['django.contrib.auth',
>  'django.contrib.contenttypes',
>  'django.contrib.sessions',
>  'django.contrib.sites']
> Installed Middleware:
> ('django.middleware.common.CommonMiddleware',
>  'django.contrib.sessions.middleware.SessionMiddleware',
>  'django.contrib.auth.middleware.AuthenticationMiddleware')
>
> Traceback:
> File "/home/www/test-django/python/lib64/python2.5/
> site-packages/django/core/handlers/base.py" in get_response
>  86.                 response = callback(request, *callback_args, 
> **callback_kwargs)
> File "/home/www/test-django/django/demo/urls.py" in ls
>  40.     for root, dirs, files in os.walk (os.path.join (home_path, 
> subdir_path)):
> File "/usr/lib64/python2.5/os.py" in walk
>  293.         if isdir(join(top, name)):
> File "/usr/lib64/python2.5/posixpath.py" in isdir
>  195.         st = os.stat(path)
>
> Exception Type: UnicodeEncodeError at /ls/
> Exception Value: 'ascii' codec can't encode characters in position
>  45-48: ordinal not in range(128)
>
> I don't understand it why "subdir_path" getting the same very value in one 
> case works perfectly and in the
> +other fails.
>
> Django runs following the instuctions
> +http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#running-django-on-a-shared-hosting-provider-wit
> +h-apache
>
> --
> BRGDS. Alexey Vlasov.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Inline for model causes problem during save

2010-04-08 Thread Nuno Maltez
If I understand correctly, you can't create a User without defining a
SoldService at the same time?
Can't reproduce this behaviour. Which version of Django are you using?

Nuno

2010/4/7 onorua :
> Hello colleagues,
>
> I have the models.py:
> class User(models.Model):
>    LastName = models.CharField(max_length=50, verbose_name =
> "Фамилия")
>    FirstName = models.CharField(max_length=50, verbose_name = "Имя")
>    MidleName = models.CharField(max_length=50, verbose_name =
> "Отчество")
>
> class SoldServices(models.Model):
>    state_choices = (
>        ('ACT', u'Активно'),
>        ('PAS', u'Пасивно'),
>        ('TRM', u'Отключено'),
>        )
>    Service = models.ForeignKey('Service', verbose_name = 'Услуга')
>    User = models.ForeignKey('User', blank=True, null=True,
> verbose_name = 'Пользователь', related_name='SoldService')
>    ValidFrom = models.DateTimeField(default=datetime.today(),
> verbose_name = u"Активный с")
>    ValidTo = models.DateTimeField(verbose_name = u"Активный до")
>    State = models.CharField(default='ACT', max_length=3, choices =
> state_choices , verbose_name="Состояние")
>
> admin.py:
> class SoldServicesInline(admin.TabularInline):
>    model = SoldServices
>
> class UserAdmin(admin.ModelAdmin):
>    inlines = [SoldServicesInline]
>
> When I'm trying to save the User model with Admin interface, it
> through an error like Service and ValidTo should be set for all non
> filled feelds in inline form.
> How can I prevent this behavior? I need possibility to add new inlines
> (I can't set extra=0), but I don't want to add this every time, and
> this behavior looks strange to me.
> When I change to blank=True, null=True, it create blank Sold services
> as soon as I save the User which is not acceptable also.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Inline for model causes problem during save

2010-04-09 Thread Nuno Maltez
On Thu, Apr 8, 2010 at 7:42 PM, onorua  wrote:
> I'm using 1.1.1
> On the development server on my laptop - it doesn't happen, on
> production - happen every time.
> How can I debug why this happen?

I have no idea :-P Any other differences between the 2 environments?
Database server?

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



Re: Problem with RSS feed. (Long Post)

2010-04-09 Thread Nuno Maltez
> Exception Type: ImproperlyConfigured at /feeds/latest/
> Exception Value: Give your Entry class a get_absolute_url() method, or
> define an item_link() method in your Feed class.

Have you tried the obvious - do what the Exception tells you and add a
"get_absolute_url" method to the model of the objects published on the
feed, or an item_link in your Feed class?

from http://docs.djangoproject.com/en/dev/ref/contrib/syndication/
"""
To specify the contents of , you have two options. For each item
in items(), Django first tries calling the item_link() method on the
Feed class. In a similar way to the title and description, it is
passed it a single parameter, item. If that method doesn't exist,
Django tries executing a get_absolute_url() method on that object.
Both get_absolute_url() and item_link() should return the item's URL
as a normal Python string. As with get_absolute_url(), the result of
item_link() will be included directly in the URL, so you are
responsible for doing all necessary URL quoting and conversion to
ASCII inside the method itself.
"""

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



Re: another many-to-many filtering question

2010-04-09 Thread Nuno Maltez
Hi,

On Wed, Apr 7, 2010 at 9:35 PM, Jim N  wrote:
> I want to get Questions that a given User has not asked yet.  That
> is,  Questions where there is no Asking record for a given User.  I
> have the User's id.

Well, you can use the exclude() method. In a ManyToMany, the "user"
field is like a User with the additional properties defined in the
"through" model, so I think you can just do:

Question.objects.exclude(user__id=my_user__id)

Just see the examples the documentation provides:
http://www.djangoproject.com/documentation/models/many_to_many/


> Models look like:
>
> class Question(models.Model):
>     text = models.TextField()
>     question_type = models.ForeignKey('QuestionType')
>     user = models.ManyToManyField(User, through='Asking', null=True)
>
> class Asking(models.Model):
>     user = models.ForeignKey(User)
>     question = models.ForeignKey(Question)
>     is_primary_asker = models.BooleanField()
>
> User is the built-in django.contrib.auth.models User.
>
> Thanks!  Maybe this is simple and I just am not seeing it.
>
> -Jim
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Send file over HTTP

2010-04-15 Thread Nuno Maltez
http://stackoverflow.com/questions/68477/send-file-using-post-from-a-python-script

although this is not really a django issue...

On Tue, Apr 13, 2010 at 8:59 PM, Rafael Nunes  wrote:
> How can I send a file over HTTP?

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



Re: ChoiceField invalid literal for int() with base 10: ''

2010-04-15 Thread Nuno Maltez
Hi,

I think the problem is tyhat you're using the wrong type of field in your form.

A ChoiceField, like the documentations says [1], returns '' for an
empty value, i.e. when
you do not select an option. Trying to save an empty string into ans
INT field in the database
will throw the error you see.

If you want to save the integer 0 when the user doesn't make a choice,
use a TypedChoiceField [2]
and pass the argument 'empty_value' as 0:

content = forms.TypedChoiceField(required=False,
choices=CONTENT_CHOICES, widget=RadioSelect(), empty_value=0)

[1]- http://docs.djangoproject.com/en/dev/ref/forms/fields/#choicefield
[2]- http://docs.djangoproject.com/en/dev/ref/forms/fields/#typedchoicefield


hth,
Nuno

On Tue, Apr 13, 2010 at 6:47 PM, geraldcor  wrote:
> Hello all,
>
> I know the error "invalid literal for int() with base 10: '' " has
> been discussed a lot in the past, but this seems to be unique to my
> situation.
>
> I have 2 choice fields as defined below for both the model and form:
>
> models.py
> class Checkin(models.Model):
> ...
> content = models.IntegerField(db_column='Content', blank=True,
> default=0)
> specie = models.IntegerField(db_column='Specie', blank=True,
> default=0)
> (I have tried a few variations on default and null=True etc)
> (This is accessing a legacy database)
>
> forms.py
> CONTENT_CHOICES=(
>        (2, 'IDFB USA Method'),
>        (5, 'IDFB ADFC Official'),
>        (7, 'IDFB Canada Method'),
>        (8, 'IDFB Australian Method'),
>        (9, 'General Report Format'),
>        (3, 'European Method'),
>        (4, 'Japanese Method'),
>        (6, 'California Method'),
>        (10, 'GB/T (Chinese)'),
> )
> SPECIES_CHOICES=(
>        (4, 'Down'),
>        (5, 'Feather'),
>        (6, 'Down and Feather'),
>        (7, 'Pre-Down'),
>        (8, 'Pre-Feather'),
>        (9, 'Pre-Down and Feather'),
> )
> class CheckinForm(ModelForm):
> ...
> content = forms.ChoiceField(required=False, choices=CONTENT_CHOICES,
> widget=forms.RadioSelect())
> specie = forms.ChoiceField(required=False, choices=SPECIES_CHOICES,
> widget=forms.RadioSelect())
>
> When I try to save the form and I do not select anything for these two
> fields I get the above error and the two fields are not listed in the
> POST area of the Request Information section of the error page.
> However, if I select something for each of those tests, the form saves
> just fine and all is well. I am using MySQL and the fields are INT(10)
> Default Value 0 or Null (I've tried both) and Not Null has been
> selected and not selected just for testing.
>
> I assume the problem has something to do with trying to save an empty
> string in an INT field, but my checkboxes that are unselected do not
> raise errors and the only thing different is that they are TINYINT(1).
> Any ideas on why this is happening. I'm trying to give as much info
> without being too verbose. I will post more if needs be.
>
> Thanks for all help both past and future.
>
> Greg
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Problem with RSS feed. (Long Post)

2010-04-21 Thread Nuno Maltez
As you probably have found out by now, since you're using 1.1, just
creat the templates

feed/_description.html

as mentioned in the docs for version 1.1:
http://docs.djangoproject.com/en/1.1/ref/contrib/syndication/


On Wed, Apr 14, 2010 at 5:44 PM, Ronnie Betzen  wrote:
>> Have you tried the obvious - do what the Exception tells you and add a
>> "get_absolute_url" method to the model of the objects published on the
>> feed, or an item_link in your Feed class?
>
> Well, duh.
> This teaches me not to be reading documentation at 2 am while I'm sleepy.
> I somehow looked straight at that and and thought get_absolute_url() was an
> internal function to Djano.  Thanks for the reality check!  ;-)
>
> At any rate, the feed is working now.  I'm getting the feed to show up in my
> reader. However, I am now puzzling over another problem with the feed.
> When the feed shows up in the reader, the title of the article shows up in
> both the title _and_ description fields.  This was traced down to the fact 
> that
> the __unicode__() method in my Entry class returns the headline attribute and
> not the body_text attribute.  The headline attribute is desirable for the the
> item's title, but I'm at a loss as to how to get the description field in the
> item to display the body_text contents.  I'm still going over the
> documentation as time permits and after the previous incident, I've got this
> sneaking suspicion I'm again not seeing the forest through the trees. ;)
>
> Thanks for all the help. I especially appreciate the pointers to appropriate
> documentation.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: feed decorator

2010-04-26 Thread Nuno Maltez
Have you tried invoking the pyhton debugger inside _wrapped to find
out the actual values of req_format and fmt and what's happening in
there?

Nuno

On Mon, Apr 19, 2010 at 4:15 AM, Streamweaver  wrote:
> I'm having trouble developing a feed decorator. I feel like the
> decorator I've come up with should work but isn't and I wanted to ask
> if someone can spot my error.
>
> I have two view methods one that returns a normal HTML view and
> another that returns an rss feed of the same data.  They both take the
> same arguments.  I am trying to create a decorator that checks the
> request objects for a format variable in the querystring and returns
> the feed view instead of the html view.  Like so:
>
> my_view_feed
>
> @format_req('rss', my_view_feed)
> my_view
>
> So a request for '/site/foo/bar' would return 'my_view' but '/site/foo/
> bar?format=rss' would return 'my_view_feed'
>
> This is the decorator method I created and I would think would work
> but I'm still struggling a bit with decorators with arguments, even
> after reading Bruce's excellent post (http://www.artima.com/weblogs/
> viewpost.jsp?thread=240845)
>
> def format_req(fmt, new_fn):
>
>    def _decorator(view_fn):
>
>        def _wraped(request, *args, **kwargs):
>            req_format = request.GET.get('format', None)
>            if req_format == fmt:
>                return new_fn(request, *args, **kwargs)
>            # Default to returning the original method
>            return view_fn(request, *args, **kwargs)
>
>        return _wraped
>
>    return _decorator
>
> I would have though a request with 'format=rss' would return new_view
> but no matter what I do I always get view_fn returned.
>
> Can anyone point me toward where I'm going wrong.  As usual I'll post
> the final code once I get it working for reference.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Many-To-Many issue; trying to find a way around conditional id

2010-04-26 Thread Nuno Maltez
Are you saying that:

collegelist = 
college.current_objects.filter(collegechoices__school=highschoolid).exclude(name='Undeclared').distinct().annotate(ccount=Count('collegechoices'))

gives you the same results as

collegelist = 
college.current_objects.exclude(name='Undeclared').distinct().annotate(ccount=Count('collegechoices'))

?

I don't think it should behave that way...

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



Re: modelForm ordering

2010-04-26 Thread Nuno Maltez
I'm not sure I understood correctly what you wanted to achieve, but if
you want to order the
Persons in the dropdown for the players field by name, you need to
change the order of the queryset
associated with that field.

For a ForeignKey field, a ModelForm generates a ModelChoiceField
http://docs.djangoproject.com/en/dev/ref/forms/fields/#modelchoicefield
that has a queryset attribute holding the QuerySet used to populate the dropdow.

You can change the order in the __init__ method of your form:

class RotationForm(forms.ModelForm):
   def __init__(self, *args, **kwargs):
super(RotationForm, self).__init__(*args, **kwargs)
self.fields["player"].queryset =
self.fields["player"].queryset.order_by("name")

Or by overriding the field on the form:

class RotationForm(forms.ModelForm):
 player = 
forms.ModelChoiceField(queryset=Person.objects.all().order_by("name"))


Hope this gives you some pointers in the right direction.
Nuno

On Tue, Apr 20, 2010 at 3:09 PM, darren  wrote:
> I am not able to figure out how to order the records that fill the
> drop down list in a model form.  On line 112 below, I have attempted
> to order the Rotation model by player.  But, the drop down list that
> is created for me is not ordered that way.  I also tried relocating
> line 112 to within the Meta class definition.  But, that didn't work
> either.  I see field ordering in the docs.  But, I don't see this
> mentioned.
>
> Any suggestions would be more than appreciated.
>
> 101 class Rotation(models.Model):
> 102     player = models.ForeignKey(Person, to_field='f_name',
> verbose_name='Player', limit_choices_to={'relationship' : 'Player'})
> 103     date = models.DateField('Date', default=datetime.date.today)
> 104     game_type = models.CharField("Game Type",
> choices=(('Scrimmage', 'Scrimmage'), ('Tournament', 'Tournament')),
> max_length=10)
> 105     inning_count = models.IntegerField("Innings Out", default=1)
> 106     def __unicode__(self):
> 107         return '%s || %s %s || %s || %s' % (self.date,
> self.player.f_name, self.player.l_name, self.game_type,
> str(self.inning_count))
> 108     class Meta:
> 109         ordering = ['date']
> 110
> 111 class RotationForm(forms.ModelForm):
> 112     Rotation.objects.order_by('player')
> 113     class Meta:
> 114         model = Rotation
> 115         exclude = ['date', 'inning_count']
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: NoReverseMatch for authentication app views

2010-05-03 Thread Nuno Maltez
Can you access the django login view by typing the URL directly on the
browser (http:///login/)?

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



Re: How to filter a query set based on a calculated date value?

2010-05-03 Thread Nuno Maltez
You can try the extra() method and write some SQL:

http://docs.djangoproject.com/en/dev/ref/models/querysets/#extra-select-none-where-none-params-none-tables-none-order-by-none-select-params-none

Something like (you'd need the correct functions for adding time and
finding the current date for you database system):

MyModel.objects.extra(where='my_date_field + my_month_field > CURDATE()' )

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



Re: filebrowser issue

2010-05-04 Thread Nuno Maltez
On Mon, May 3, 2010 at 8:10 PM, Bobby Roberts  wrote:
> hey I have a strange issue.  I was having trouble getting django-
> tinymce and filebrowser working.  I've worked through all of the
> errors etc.  In filebrowser, I can create a new directory, but when i
> try to upload a file or image, nothing happens... it acts like it's
> uploading but it's not on the server anywhere.  I've checked the perms
> on my upload directory and it seems to be ok.  Any ideas?

Do you see filebrowser calling the upload url in your logs or dev
console? Any errors, or is it logged as 200 OK?

I think fb uses Uploadify to upload the files, so you might want to
try checking the HTTP response from the server using Firebug or a
similar tool - that will probably explain what's going on and even
show you the debug page generated by django in case of any exceptions.

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



Re: values() and GenericRelation

2010-05-07 Thread Nuno Maltez
>  MyModel.objects.values('id', 'field1__name', 'field2',
> 'field3__value', 'my_custom_set')

...

> I could use all() result, but I must use the ForeingKey values of the
> field1 and field3, so I don't know how to get its values if it not the
> way I said before.
>
> How can I resolve this?

I can't help you on how to use the values method, but can't you just access
obj.field1.name  to get the name of the related object in field 1 (or
obj.field1.id to get its id).


HTH,
Nuno

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



Re: Localeurl and django-multilingual

2010-05-10 Thread Nuno Maltez
How are you creating the url for the links? Are you using the {% url
%} tag and reverse() functions? It should work, we have sites with
localeurl and django-multilingual running fine in production.

Nuno

On Sat, May 8, 2010 at 12:34 PM, Alessandro Ronchi
 wrote:
> I need to have links with language code prefix, and different contents.
>
> I've achieved that with both localeurl and django-multilingual, and I can
> get the tranlated version if i choice the correct url:
> for example http://mydomain.com/it/c/auto-intere/1/ and
> http://mydomain.com/pl/c/auto-intere/1/
>
> but if I open http://mydomain.com/pl/c/auto-intere/1/
> all the next link will redirect back to /it/
>
> So, I need to fix the user choice and set it to the user request language.
>
> Is it possible?
> How?
>
> --
> Alessandro Ronchi
>
> http://www.soasi.com
> SOASI - Sviluppo Software e Sistemi Open Source
>
> Hobby & Giochi, l'e-commerce del divertimento
> http://hobbygiochi.com
> http://www.facebook.com/hobbygiochi
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Paginating search results

2010-05-11 Thread Nuno Maltez
You need to pass the current search paramters in your query string
(?party=D&q=&page= ) when you create the links to all the
pages, and you need to be able to retrieve them from request.GET in
order to recreate the object list (reps) when rendering a specific
page (any particular reason why are you using POST in the search
form?).

hth,
Nuno

On Tue, May 11, 2010 at 1:58 AM, Nick  wrote:
> I'm trying to paginate results from a search with multiple options.
> The only problem is, once I hit the next button it clears the query
> and I'm left paginating all the objects in the DB.
>
> Here is my view:
>
> def filter_search(request):
>    if request.POST:
>        reps = Rep.objects.all()
>    else:
>        reps = []
>    query = request.POST
>    if 'q' in request.POST:
>        q = request.POST.get('q', '')
>        qset = (
>        Q(Last_Name__icontains=q) | Q(First_Name__icontains=1)
>               )
>        reps = reps.filter(qset)
>    else:
>        q = []
>    if len(q):
>        qlist = q
>    else:
>        qlist = []
>    if 'party' in request.POST:
>        party = request.POST.getlist('party')
>        reps = reps.filter(Party__in=party)
>    else:
>        party = []
>    if len(party):
>        plist = party
>    else:
>        plist = []
>    paginator = Paginator(reps, 15)
>    results = paginator.count
>    try:
>        page = int(request.POST.get('page', '1'))
>    except:
>        page = 1
>    try:
>        repList = paginator.page(page)
>    except (EmptyPage, InvalidPage):
>        repList = paginator.page(paginator.num_pages)
>    finalq = request.POST
>    return render_to_response("Government/search.html", {
>            'reps': repList,
>            'query': query,
>            'plist': plist,
>            'qlist': qlist,
>            'results': results,
>            'finalq': finalq
> })
>
> Here is my tpl:
>
>
>        
>        
>        Democrat  
>        Republican 
>        
>        
>
> {% if query %}
> Your search for {% if qlist %} {{ qlist}} {% endif %}
> {% if plist %} {% for p in plist %} {% if forloop.first %} Party
> ({{ p }}) {% else %} &  Party ({{p}}) {% endif %}
> {% endfor %}{% endif %} returned {{ reps.paginator.count }} span> result(s)
> 
> {% for object in reps.object_list %}
> {{ object.Position }} {{ object.First_Name }}
> {{ object.Last_Name }} http://django.newsok.com/government/
> reps/{{ object.Last_Name }}_{{ object.First_Name}}">view more
> {% endfor %}
> 
>
>
> 
> {% if reps.has_previous %}
>  href="&page={{ reps.previous_page_number }}">Previous
> {% else %}
> Previous
> {% endif %}
>
>
> {% if reps.has_next %}
> Next a>
> {% else %}
> Next
> {% endif %}
> 
>
>
> That href is the cause of the problem, how do I pass a page to the url
> without resetting the query?
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Paginating search results

2010-05-11 Thread Nuno Maltez
Great, Just make sure you don't end up with multiple "page" arguments
on your query string when navigating through the results (click next;
click next again...).

Nuno

On Tue, May 11, 2010 at 2:41 PM, Nick  wrote:
> The POST thing was the result of late night meltdowns and desperation.
> I tend to just try stupid things when i'm working through an issue
> like this, just seeing what the application is capable of doing. I've
> switched it all back to GET.
>
> I found the answer around 1 this morning.  You are exactly right, I
> needed to capture the query string and place it in the "next" and
> "previous" page links. Here's how I went about doing that, just in
> case someone else runs into this issue:
>
>  query_string = request.GET.copy()
>
> and then in the dict:
>
> 'query_string': query_string.urlencode()
>
>
>
>
>
> On May 11, 4:46 am, Nuno Maltez  wrote:
>> You need to pass the current search paramters in your query string
>> (?party=D&q=&page= ) when you create the links to all the
>> pages, and you need to be able to retrieve them from request.GET in
>> order to recreate the object list (reps) when rendering a specific
>> page (any particular reason why are you using POST in the search
>> form?).
>>
>> hth,
>> Nuno
>>
>>
>>
>> On Tue, May 11, 2010 at 1:58 AM, Nick  wrote:
>> > I'm trying to paginate results from a search with multiple options.
>> > The only problem is, once I hit the next button it clears the query
>> > and I'm left paginating all the objects in the DB.
>>
>> > Here is my view:
>>
>> > def filter_search(request):
>> >    if request.POST:
>> >        reps = Rep.objects.all()
>> >    else:
>> >        reps = []
>> >    query = request.POST
>> >    if 'q' in request.POST:
>> >        q = request.POST.get('q', '')
>> >        qset = (
>> >        Q(Last_Name__icontains=q) | Q(First_Name__icontains=1)
>> >               )
>> >        reps = reps.filter(qset)
>> >    else:
>> >        q = []
>> >    if len(q):
>> >        qlist = q
>> >    else:
>> >        qlist = []
>> >    if 'party' in request.POST:
>> >        party = request.POST.getlist('party')
>> >        reps = reps.filter(Party__in=party)
>> >    else:
>> >        party = []
>> >    if len(party):
>> >        plist = party
>> >    else:
>> >        plist = []
>> >    paginator = Paginator(reps, 15)
>> >    results = paginator.count
>> >    try:
>> >        page = int(request.POST.get('page', '1'))
>> >    except:
>> >        page = 1
>> >    try:
>> >        repList = paginator.page(page)
>> >    except (EmptyPage, InvalidPage):
>> >        repList = paginator.page(paginator.num_pages)
>> >    finalq = request.POST
>> >    return render_to_response("Government/search.html", {
>> >            'reps': repList,
>> >            'query': query,
>> >            'plist': plist,
>> >            'qlist': qlist,
>> >            'results': results,
>> >            'finalq': finalq
>> > })
>>
>> > Here is my tpl:
>>
>> >        
>> >        
>> >        Democrat  
>> >        Republican 
>> >        
>> >        
>>
>> > {% if query %}
>> > Your search for {% if qlist %} {{ qlist}} {% endif %}
>> > {% if plist %} {% for p in plist %} {% if forloop.first %} Party
>> > ({{ p }}) {% else %} &  Party ({{p}}) {% endif %}
>> > {% endfor %}{% endif %} returned {{ reps.paginator.count }}> > span> result(s)
>> > 
>> > {% for object in reps.object_list %}
>> > {{ object.Position }} {{ object.First_Name }}
>> > {{ object.Last_Name }} http://django.newsok.com/government/
>> > reps/{{ object.Last_Name }}_{{ object.First_Name}}">view more
>> > {% endfor %}
>> > 
>>
>> > 
>> > {% if reps.has_previous %}
>> > > > href="&page={{ reps.previous_page_number }}">Previous
>> > {% else %}
>> > Previous
>> > {% endif %}
>>
>> > {% if reps.has_next %}
>> > Next> > a>
>> > {% else %}
>> > Next
>> > {% endif %}

Re: Taking on a NoneType error

2010-05-12 Thread Nuno Maltez
Hi,

I think the simple

{% if entry.DOB %} {{ entry.DOB|age }}{% else  %} N/A {% endif %}

should work. Or, the other way around:

{% if not entry.DOB %} ...


You could also try testing in your filter:

def age(bday, d=None):
   if bday is None:
 return None
   

and use the default_if_none filter

{{ entry.DOB|age|default_if_none:"N/A" }}

This, however, doesn't seem to make sense:
>
> def detail(request, last_name, first_name):
>r = get_object_or_404(Rep, Last_Name=last_name,
> First_Name=first_name)
>if r.DOB == None:
>r.DOB = NULLage
>return render_to_response('Government/repsSingle.html', {'entry':
> r, 'NULLage': NULLage})
>
> The in the template:
>
> {% if NULLage %}

NULLage is never set by your test in the view, seems like it's a
constant value, and the if in the template would always evaluate the
same way (be it True or False).

HTH,
Nuno

On Wed, May 12, 2010 at 6:06 PM, Nick  wrote:
> I am using a custom template tag called calculate age to produce an
> age in numbers based on a filter for a template tag.
>
> Here is the tag:
>
> def age(bday, d=None):
>    if d is None:
>        d = datetime.datetime.now()
>    return (d.year - bday.year) - int((d.month, d.day) < (bday.month,
> bday.day))
>
> register.filter('age', age)
>
> here is how it is used in a template:
>
> {{ entry.DOB|age }} # that produces an age
>
>
> Here is the problem, not all of the entries in my DB have a date of
> birth (henceforth known as DOB).
>
> This raises and error.
>
> I have tried to get around this many different ways. Here are few:
>
> {% ifequal entry.DOB None %} N/A {% else %}  {{ entry.DOB|age }} {%
> endif %}
>
> {% ifequal entry.DOB "None" %} N/A {% else %}  {{ entry.DOB|age }} {%
> endif %}
>
> {% if entry.DOB == None #I have custom operators set up and this logic
> works in the shell but not in the template %} N/A {% else %}
> {{ entry.DOB|age }} {% endif %}
>
> {% if entry.DOB == 'None' %} N/A {% else %}  {{ entry.DOB|age }} {%
> endif %}
>
> I've even tried it in my view:
>

>
> This is a good grief sort of error and is making my brain blood boil.
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Using a variable for a field name in a filter?

2010-05-14 Thread Nuno Maltez
Sure: http://docs.python.org/tutorial/controlflow.html#unpacking-argument-lists

myfilter = { var_field: "found" }
Foo.objects.filter(**myfilter}

hth,
Nuno

On Fri, May 14, 2010 at 2:19 PM, derek  wrote:
> Given a model Foo, with a field bar:
> Foo.objects.filter(bar = "found")
> works just fine.
>
> But, in my case, different fields are needed at different times, so I
> would like to use:
> Foo.objects.filter(var_field = "found")
> where "var_field" is a variable which will be set to the name of a
> field (such as "bar").
>
> The above is incorrect - how do I accomplish this?
>
> Thanks
> Derek
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: M2M with Intermediary - Django Admin Support - Doesn't appear?

2010-05-14 Thread Nuno Maltez
Hmmm ... you should have an inline formset at the bottom to add firms
to your Article, with an associated input box forthe rating.

If I understand correctly, each relation Article-Firm now needs a
rating (mandatory), sou you can't just select Firms from a
filter_horizontal widget - you need a way to input the rating as well.

Nuno

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



Re: override base translations in your project

2010-05-17 Thread Nuno Maltez
I believe it should work the way you describe (you can even remove the
line with the reference to the source).

Are all the other translations in your project, excepto for those
copied from the third party app, working fine?

Nuno

On Sun, May 16, 2010 at 11:46 PM, lenz  wrote:
> The Django docs tell that it is possible to "override base
> translations in your project path" but i have no idea how this works.
>
> I tried to copy the some contents of an third party apps django.po to
> the django.po file of the project but i see no change after compiling.
>
> To me it seems obvious that it could not work because the path of the
> entry is wrong if copied to the projects django.po
>
> This is one of the statements i copied from APP/locale/LANG/django.po
> th PROJECT/locale/LANG/django.po
> #: content/application/models.py:127
> msgid "application content"
> msgstr "Applikation"
>
> How to override translations of third party apps the right way?
>
> Thanks
> Lenz
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Custom Model Fields

2010-05-18 Thread Nuno Maltez
Hi,

I think what you're trying to accomplish is more or less what
django-tagging [http://code.google.com/p/django-tagging/] does, so I
suggest looking at its source code.

HTH,
Nuno

On Sun, May 9, 2010 at 11:24 PM, Nick Taylor
 wrote:
> Hi all,
>
> I want to create my own "field" type for a model, this essentially
> will be a relationship to another model via a generic link model
> (using GenericForeignKey etc).
>
> As en example I basically want to do the following in models.py:
>
> class Pizza(models.Model):
>   toppings = IngredientsField()
>
> Which can then be reused in another app sandwiches/models.py as:
>
> class Sandwich(models.Model)
>   filling = IngredientsField()
>
> Where I use a IngredientsField() field type which then controls the
> links as a separate set of models Ingredients and IngredientItems.
>
> Now I have created in fields.py:
>
> class IngredientsField(CharField):
>    def __init__(self, *args, **kwargs):
>    ..
>
> However I get an "Unknown column 'pizza_pizza.toppings' in 'field
> list'" error - BUT I don't want to add it as a column in toppings as I
> want it to be linked via the link table/model IngredientItems.
> Eventually what I want to achieve is while using the admin system for
> certain models that you manage there will be a text box where you can
> enter ingredients into a TextField in the admin comma delimited
> "Cheese, Ham" and then the model take care of the rest.
>
> Hopefully I'm pretty close, any ideas anyone?
>
> Thanks in advance,
>
> Nick
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: send_mail not firing

2010-05-19 Thread Nuno Maltez
Anything it the mail server's logs? Any trace of your app trying to
send the message? Any errors?

Nuno

On Tue, May 18, 2010 at 11:42 PM, Nick  wrote:
> Actually, I've fixed the problem with send_activation. If i go via the
> form it still doesn't trigger the email.
>
> On May 18, 5:19 pm, Nick  wrote:
>> I get the same results.
>>
>> I dropped into the shell and tried it out
>>
>> >>> user = User(username="nick", email="t...@test.com")
>> >>> send_activation(user)
>>
>> 1
>>
>> I think the 1 means that it passed but I don't get any emails sent
>>
>> On May 18, 5:08 pm, "ge...@aquarianhouse.com"
>>
>>
>>
>>  wrote:
>> > what happens if you set fail_silently to True?
>>
>> > On May 19, 12:05 am, Nick  wrote:
>>
>> > > I am having an issue with an authentication app I am writing. The app
>> > > saves the form appropriately but doesn't send the confirmation email.
>> > > I am using the same email_host settings as with other application that
>> > > send email messages but with no results. Here is the process.
>>
>> > > First a form processes the information:
>>
>> > > from django.contrib.auth.forms import UserCreationForm
>> > > from django import forms
>> > > from django.contrib.auth.models import User
>> > > from activate import send_activation
>>
>> > > class RegisterForm(UserCreationForm):
>> > >     email = forms.EmailField(label="E-Email")
>>
>> > >     class Meta:
>> > >         model = User
>> > >         fields = ("username", "email")
>>
>> > >     def clean_email(self):
>> > >         email = self.cleaned_data["email"]
>>
>> > >         try:
>> > >             User.objects.get(email=email)
>> > >         except User.DoesNotExist:
>> > >             return email
>>
>> > >         raise forms.ValidationError("A user with that email address
>> > > already exists.")
>>
>> > >         def save(self):
>> > >             user = super(RegisterForm, self).save(commit=False)
>> > >             send_activation(user)
>> > >             user.is_active = False
>> > >             user.save()
>>
>> > > the activate.py file:
>>
>> > > from django.core.mail import send_mail
>> > > from hashlib import md5
>> > > from django.template import loader, Context
>> > > from Obits.settings import BASE_URL as base_url
>>
>> > > def send_activation(user):
>> > >     code = md5(user.username).hexdigest()
>> > >     url = "%sactivate/?user=%s&code=%s" % (base_url, user.username,
>> > > code)
>> > >     template = loader.get_template('obits/eactivate.html')
>> > >     context = ({
>> > >          'username': user.username,
>> > >          'url': url,
>> > >      })
>> > >     send_mail('Activate account at super site', 'this is a test',
>> > > 'myem...@mydomain.com, [user.email], fail_silently=False)
>>
>> > > The form saves to the DB, it hits all of the conditions but fails to
>> > > send an email. I can't get any error messages so I'm really at a loss.
>>
>> > > --
>> > > You received this message because you are subscribed to the Google 
>> > > Groups "Django users" group.
>> > > To post to this group, send email to django-us...@googlegroups.com.
>> > > To unsubscribe from this group, send email to 
>> > > django-users+unsubscr...@googlegroups.com.
>> > > For more options, visit this group 
>> > > athttp://groups.google.com/group/django-users?hl=en.
>>
>> > --
>> > You received this message because you are subscribed to the Google Groups 
>> > "Django users" group.
>> > To post to this group, send email to django-us...@googlegroups.com.
>> > To unsubscribe from this group, send email to 
>> > django-users+unsubscr...@googlegroups.com.
>> > For more options, visit this group 
>> > athttp://groups.google.com/group/django-users?hl=en.
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group 
>> athttp://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Extremely simple question that I can't get a simple answer for in Docs

2010-05-19 Thread Nuno Maltez
I think you need the google search help list :-)

Just type "django forms" in the search box at docs.djangoproject.com

And in the first result you have a lot of examples on how to print
everything from a form in your template:
http://docs.djangoproject.com/en/dev/topics/forms/

On Wed, May 19, 2010 at 5:23 PM, pyfreak  wrote:
> Frustratingly enough, docs.djangoproject.com tells you how to print
> out the HMTL for a single field in your form, but it uses a shell to
> demonstrate it:
>
>  f = ContactForm()
 print f['subject']
>   >
 print f['message']
>
>
> However, I need to know how to do this in a template
>
> I tried placing my form in the template like {{ f['subject'] }} and I
> get TemplateSyntaxError.  Of course using my own form and existing
> fields
>
>
> What is the syntax for this.
>
> I tried all types of search terms to hopefully catch a thread with
> someone doing this, but ended up at zero.
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: ModelForm gives invalid option.

2010-05-26 Thread Nuno Maltez
You simply need to provide a default value for your field, i.e. :
turtle_type = models.IntegerField(null=False, blank=False,
choices=TURTLE_TYPES, default=1)

See the notes on:
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#field-types


hth,
Nuno

On Tue, May 25, 2010 at 10:05 PM, Joshua Frankenstein Lutes
 wrote:
> I have a Model that looks something like this:
>
> ==
> class Turtle(models.Model):
> turtle_type = models.IntegerField(null=False, blank=False,
> choices=TURTLE_TYPES)
> ==
>
> I use it to create a ModelForm:
>
> ==
> class TurtleForm(forms.ModelForm):
> class Meta:
> model = Turtle
>
> widgets = {
> 'turtle_type': forms.RadioSelect,
> }
> ==
>
> The problem is that when I display the TurtleForm, it shows a radio
> select for "-", which correlates to a null option. This
> doesn't validate when the form is submitted and I don't want it to be
> a selectable option. How can I prevent this from being displayed?
> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Session not working as i had hoped

2010-05-26 Thread Nuno Maltez
http://docs.djangoproject.com/en/dev/topics/http/sessions/#using-sessions-in-views


>    if request.session.get('has_visited',True):

You're passing True as the default value to the get method  - get(key,
default=None); this means that when 'has_visited' isn't set in your
session (1st visit) it still returns True.

Just replace :

   if request.session.get('has_visited',True):
   visited = True
   else:
   visited = False

with

visited = request.session.get('has_visited', False)

hth,
Nuno

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



Re: Image deduplication and upload_to

2010-05-27 Thread Nuno Maltez
Hi,

I think it's designed to do that. See the behaviour of the
save/get_available_name methods on core/files/storage.py (in the
django source). Maybe you can write your own storage that overrides
this (never tried it, but should work).

Nuno

2010/5/26 Ricardo Bánffy :
> Hi folks.
>
> I want to prevent the duplication of uploaded images. For that, I am
> using the upload_to property of ImageField set to a callable that
> computes the md5 hash of the uploaded file data and returns a file
> name. This should work _but_ when I save the model, the filename I
> gave back in the function is getting a "_1", "_2" and so on suffix to
> prevent my efforts at deduplication.
>
> http://dpaste.com/199576/
>
> Anyone has had a similar problem?
>
> I understand I'll have to take care of other problems too, like
> preventing the deletion of files that are referenced by more than one
> ImageFile and could do something to prevent the actual overwriting of
> the same data on the same file as before, but that's a start.
>
>
> --
> Ricardo Bánffy
> http://www.dieblinkenlights.com
> http://twitter.com/rbanffy
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: mod_wsgi can't find app to import..but I added path to wsgi file?!

2010-05-27 Thread Nuno Maltez
> ImportError: No module named mvc

What's the "mvc" module? Python can't seem to find it. Is it in your
python path?

Nuno


On Thu, May 27, 2010 at 4:20 PM, Chris Seberino  wrote:
>
> I fixed the path issue that was causing the spinning but now I'm back
> to getting import errors even with __init__.py in my apache
> directory.  Here is the exact error from Apache's error.log.
>
> ...
> [Thu May 27 10:18:18 2010] [error] [client 99.159.221.130]
> _default = translation(settings.LANGUAGE_CODE)
> [Thu May 27 10:18:18 2010] [error] [client 99.159.221.130]   File "/
> usr/lib/pymodules/python2.6/django/utils/translation/trans_real.py",
> line 194, in translation
> [Thu May 27 10:18:18 2010] [error] [client 99.159.221.130]
> default_translation = _fetch(settings.LANGUAGE_CODE)
> [Thu May 27 10:18:18 2010] [error] [client 99.159.221.130]   File "/
> usr/lib/pymodules/python2.6/django/utils/translation/trans_real.py",
> line 180, in _fetch
> [Thu May 27 10:18:18 2010] [error] [client 99.159.221.130]     app =
> import_module(appname)
> [Thu May 27 10:18:18 2010] [error] [client 99.159.221.130]   File "/
> usr/lib/pymodules/python2.6/django/utils/importlib.py", line 35, in
> import_module
> [Thu May 27 10:18:18 2010] [error] [client 99.159.221.130]
> __import__(name)
> [Thu May 27 10:18:18 2010] [error] [client 99.159.221.130]
> ImportError: No module named mvc
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: password reset getting error - 'function' object is not iterable

2010-05-28 Thread Nuno Maltez
At a first glance it looks like a problem with your urls. Could you show us
your custom template and url definitions from urls.py?

Nuno

On Thu, May 27, 2010 at 7:10 PM, Pankaj Singh <
singh.pankaj.iitkg...@gmail.com> wrote:

>
>
>
>
> Exception Value:
>
> 'function' object is not iterable
>
>
>
>
>
>
>
>

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



Re: tinymce hyperlinks

2010-05-31 Thread Nuno Maltez
Which version of grappelli are you using? Currently the trunk requires
django 1.2 but I think there's a branch that still works with 1.1.

Having said that, we're using grappelli (a slightly older revision)
with Django 1.1 in a live project and it works just fine. Do you
notice any javascript errors when using the wizard?

Nuno

On Sun, May 30, 2010 at 9:45 PM, Bobby Roberts  wrote:
> i'm using django 1.1 with tinymce and the grappelli skins.  we just
> realized that the tinymce editor does not let you put hyperlinks in.
> if you go into HTML and hand code them they are fine.  if you try to
> click the link button and use the wizard, no link is inserted and the
> insert button doesn't do anything.  Has anyone else run into this.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: ImportError: No module named django.core

2010-05-31 Thread Nuno Maltez
Well, it seems that your python lib is at /usr/lib/python2.6/dist-packages:

> mx:~/webapps$ python -c "from distutils.sysconfig import
> get_python_lib; print get_python_lib()"
>
> /usr/lib/python2.6/dist-packages

but django is in "local" - /usr/local/lib/python2.6/dist-packages

> /usr/local/lib/python2.6/dist-packages/django/bin/django-admin.py

So have you tried adding /usr/local/lib/python2.6/dist-packages/
(directory that holds the django module) to your pythonpath?

Nuno

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



Re: tinymce hyperlinks

2010-05-31 Thread Nuno Maltez
Maybe related to this issue?

http://code.google.com/p/django-grappelli/issues/detail?id=184

It's supposed to be fixed on the latest grappelli release though.

Nuno


On Mon, May 31, 2010 at 5:13 PM, Bobby Roberts  wrote:
> the only javascript error i'm getting is this:
>
> document.getElementsBySelector is not a function
>
> it's in my admin/js folder in the action.js file?
>
>
>
>
> On May 31, 5:15 am, Nuno Maltez  wrote:
>> Which version of grappelli are you using? Currently the trunk requires
>> django 1.2 but I think there's a branch that still works with 1.1.
>>
>> Having said that, we're using grappelli (a slightly older revision)
>> with Django 1.1 in a live project and it works just fine. Do you
>> notice any javascript errors when using the wizard?
>>
>> Nuno
>>
>> On Sun, May 30, 2010 at 9:45 PM, Bobby Roberts  wrote:
>> > i'm using django 1.1 with tinymce and the grappelli skins.  we just
>> > realized that the tinymce editor does not let you put hyperlinks in.
>> > if you go into HTML and hand code them they are fine.  if you try to
>> > click the link button and use the wizard, no link is inserted and the
>> > insert button doesn't do anything.  Has anyone else run into this.
>>
>> > --
>> > You received this message because you are subscribed to the Google Groups 
>> > "Django users" group.
>> > To post to this group, send email to django-us...@googlegroups.com.
>> > To unsubscribe from this group, send email to 
>> > django-users+unsubscr...@googlegroups.com.
>> > For more options, visit this group 
>> > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Problems with Django File Fields

2010-05-31 Thread Nuno Maltez
Well, I know this doesn't address most of the issues you raise, but
I've used a combination of django-filebrowser,
http://code.google.com/p/django-filebrowser/ , FileBrowseField and
apache's x-sendfile, http://tn123.ath.cx/mod_xsendfile/, for serving
restricted access files, successfully.

I found that django-filebrowser and FileBrowseField really make the
admin's task of managing file uploads easier. You can make your own
directory structure, even though you have to do it manually.

This, of course, doesn't solve your all your issues:
- the filepath (relative to a media folder) is still stored in the
database, but to be honest it hasn't been an actual problem so far.
- to make a file private is the administrators responsibility - the
admin must upload the files to a "private" folder, secured by apache,
and
to serve the file you must code a view that validates the user's
permissions and returns the filepath to mod xsendfile.

It's not a perfect solution but it's the best I found so far, at least
for my purposes :)

Nuno

On Mon, May 31, 2010 at 2:06 PM, klaasvanschel...@gmail.com
 wrote:
> Hi All,
>
> The standard  Django File Fields (both on models and the form
> equivalent) have a number of shortcomings from my point of view / in
> my field. The most important of these are:
>
> * The result of uploaded file fields are assumed to be "public", i.e.
> served through the MEDIA url. I would rather store the files somewhere
> safe and determine in my view who gets to download what.
> * The filename is stored in the database, including the (potentially
> long) path to the file. This in itself creates all kinds of trouble:
>  * What if I want to move a file?
>  * What if the full path is longer than 255 characters?
>  * What if I create (using objects) a separate directory structure?
> Why is there now a global uniqueness constraint on variable names?
>
> As far as I see the custom storage system does not fix any of the
> above problems, since it is "name" based.
>
> For a number of my applications I've worked around the above problems
> by simply coding around it: I'm storing the filename in the DB in a
> CharField, and manually read/write the file from/to disk in view
> operations. I'm using the [appname]/[modelname]/[fieldname]/id as a
> path.
>
> Obviously I'd like to factor out the above. So I tried
> http://docs.djangoproject.com/en/1.2/howto/custom-model-fields/
>
> I'm running into a bunch of problems:
> * The 'real' django FileField does not follow the pattern from the
> article above (i.e. search for to_python in the source). What's going
> on here?
> * As described above, I'd like to use the pk of an object to write the
> file. However, the pk is not available before the save is done (at the
> model level). Are there known solutions for this problem?
>
> What paths could you recommend for me? Are my observations on the
> limitations of FileFields correct? Have some of you tried and found
> (different?) solutions?
>
> thanks a bunch.
>
> regards,
> Klaas van Schelven
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Path issue (TemplateDoesNotExist)

2010-06-02 Thread Nuno Maltez
Well, if you're trying to render a template : "posts/post_list.html",
the post_list.html file should live inside "posts" directory inside of
your "templates" directory :

templates/posts/post_list.html

Don't mix html and python files in the same dir.

Nuno


On Wed, Jun 2, 2010 at 4:44 AM, M. Bashir Al-Noimi  wrote:
>
> Hi folks,
>
> I'm trying to build my first blog by python/django but during writing it I 
> faced a path problem so django couldn't recognize template path.
> For that the debugger gave me the following log (you can see full log and the 
> whole project in the attachment), although I added the absolute template path 
> to TEMPLATE_DIRS tuple. Could you please tell me what's wrong?
>
> PS
> I still newbie guys ;-)
>
> --log--
>
> TemplateDoesNotExist at /
>
> posts/post_list.html
>
> Request Method: GET
> Request URL: http://127.0.0.1:8000/
> Exception Type: TemplateDoesNotExist
> Exception Value:
>
> posts/post_list.html
>
> Exception Location: C:\Python26\lib\site-packages\django\template\loader.py 
> in find_template_source, line 74
> Python Executable: C:\Python26\python.exe
> Python Version: 2.6.3
> Python Path: ['Q:\\Apps\\Common\\eclipse-py\\workspace\\MyBlog\\src\\MyBlog', 
> 'Q:\\Apps\\Common\\eclipse-py\\workspace\\MyBlog\\src', 
> 'Q:\\Apps\\Common\\eclipse-py\\workspace\\MyBlog\\templates', 'C:\\Python26', 
> 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\lib\\lib-tk', 
> 'C:\\Python26\\lib\\plat-win', 'C:\\Python26\\lib\\site-packages', 
> 'C:\\WINDOWS\\system32\\python26.zip']
> Server time: Mon, 31 May 2010 15:45:49 +0200
>
> --
> Best Regards
> Muhammad Bashir Al-Noimi
> My Blog: http://mbnoimi.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-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

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



Mysql + Unicode + username curiosity

2011-11-14 Thread Nuno Maltez
So, I just ran into a funny issue. I'm using Django + Mysql and when
retrieving users (Auth.user) form the database, the username field
comes as a bytestring while everything else seems to
come as unicode strings:

>>> from django.contrib.auth.models import User
>>> a=User.objects.get(id=1)
>>> a.username
'admin'
>>> a.email
u'admin@localhost'

I know you should only use letters and a few more characters in
usernames, but that seems to be verified in the forms only.  I look at
the User model and username, email first and last names
are all CharFields, yet username displays this peculiar behaviour. Any
reason for this?

I'm using:
mysqld  Ver 5.1.41
Django  (1, 3, 1, 'final', 0)
MySQLdb (1,2,3,'final',0)


In my.conf used in the connection I have
[client]
default-character-set = utf8

and the tables were created with utf8_general_ci

Thanks in advance,
Nuno

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



ANN: Two-Step Authentication with Django

2012-01-23 Thread Nuno Maltez
django-twostepauth is a Django application that allows user authentication
with two steps for  additional security. The first step with username
and password and the
second step with a one-time code such as the codes generated by soft
token devices like
Google Authenticator.

Features:

* Authentication with TOTP (Time-Based One-Time Password)
* Authentication HOTP (HMAC-Based One-Time Password)
* Support for the login in the admin site
* Selective activation of two-step for the admin site, the main site or both
* Support for authentication backup codes
* Automatic adjustment for clock synchronization issues

It comes with an example project that shows how to use in a site and
also how to integrate with django-registration and
django-profiles.

We've released the code at
https://bitbucket.org/cogni/django-twostepauth

an it's also at pypi:
http://pypi.python.org/pypi/django-twostepauth


Quick demo video:
http://youtu.be/-vXcZKzGXl0

Hope this is useful to someone. Feedback deeply appreciated.

Cheers

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