Re: customization using form_class with generic views

2009-07-26 Thread Frédéric Hébert

Hi,

AFAICS, it's nearly impossible to do this in the way you want to.

 set_pub_date is an another view which does a CRUD operation like
generic view create_object and you pass it to extra_context which is
relevant to a template operation.

extra_context declares new objects in the template and is not intended
to add new control logic on the form.

Maybe you wanted to pass to extra_context a new PressReleaseCRUD form
and uses it in place of  generic views' form ? In that case why do you
use a generic view ?

I wonder why you don't want to do this logic on your model instance ?


Frédéric

-- 
http://www.openidfrance.fr/fhebert

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



Re: problem with milliseconds and mysql database

2009-07-25 Thread Frédéric Hébert

Hi,

could you be more explanatory in your question ?

How do you set your field value ? via a models.DateTimeField ?

About the example that you 've given : is it the solution or what's
giving the error ?

I've tried your example and it works fine.

Try to look for answers in django.db.fields.__init__ in DateTimeField class

Frédéric

2009/7/25 Asinox :
>
> Hi, guy, i have a problem trying to save "datetime" in mysql.
>
> the problem is that mysql dont need milliseconds in the datatime
> field...
>
> how ill send datatime in format "2009-12-12  1:25:30" without that
> python and Django say: Enter a valid date/time in -MM-DD HH:MM[:ss
> [.uu]] format  ??
>
> Thanks
> >
>



-- 
http://www.openidfrance.fr/fhebert

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



Re: How to create this filter

2009-07-24 Thread Frédéric Hébert

It seems to me that you have to transform your fields lookup like that :

 col1_value >= col2_value * 2

something like col1__gte=F('col2') * 2

Frédéric

2009/7/24 David :
>
> Hello,
>
> Here is a table "myTable" with columns of "col1", "col2", "col3", ...,
> "col5". The types of these columns are all float. Now for two values
> from any two columns of these columns, I may need to add, or subtract,
> or multiply or divide these two values. With this result, I do a
> condition check.
>
> For example, I want to retrieve all objects that meet "col1_value /
> col2_value >= 2.0". How to create such a filter? It seems to me that F
> () might be the right choice, however the document on this part in
> QuerySet API is quite rough.
>
> Anybody knows how to create such a filter? or anybody knows any url
> links that introduce F() in details?
>
> Thanks so much.
> >
>



-- 
http://www.openidfrance.fr/fhebert

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



Re: Bug when creating Q object from string representation of another Q object?

2009-07-22 Thread Frédéric Hébert

You don't give us enough explanation about your error.

 What type of error have you got ?

 What is your orig variable ?

 How do you serialize your Q object ?

 Are you sure that a Q object can be instantiated like that ?

 Frédéric

2009/7/21 Margie :
>
> I have a situation where I want to do the following:
>       take a bunch of POST params and from them create a Q object
>       urlencode that Q object and turn it into a GET param, redirect
> using that param
>       process the GET that contains the urlencoded Q object, create a
> Q object from it, and use it in a filter
>
>
> I think this should all be possible, however, I am having trouble
> recreating the new Q object from the string representation of the
> original Q object. Here's an example of the problem:
>
 filter_orig = Q(owner__username='mlevine')
 print filter_orig
> (AND: ('owner__username', 'mlevine'))
 filter_new = Q("%s" % orig)
 print filter_new
> (AND: (AND: ('owner__username', 'mlevine')))
 Task.objects.filter(filter_orig)
> [, ]
 Task.objects.filter(filter_new)
> Traceback (most recent call last):
> ...
>  File "/home/mlevine/django/django_libs/django-admin-ui-july8/lib/
> python2.6/site-packages/django/db/models/sql/query.py", line 1520, in
> add_filter
>    arg, value = filter_expr
>
>
> Note that in the above log, when I print filter_new, there is an extra
> AND at the front.  Logically this shouldn't be be a problem, but I
> suspect that it is indicative of the problem.
>
> Is what I'm doing above supposed to work?  Is this a bug?
>
> This is using 1.1 beta.
>
> Margie
>
>
>
> >
>



-- 
http://www.openidfrance.fr/fhebert

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



Re: Making Django ldapauth more sophisticated

2009-07-21 Thread Frédéric Hébert



On 21 juil, 00:35, "Daniele Procida" 
wrote:
> I finally have ldapauth working now, and a user who is in our LDAP
> database can connect as a Django User.
>
> But it's not entirely satisfactory. Before the LDAP user becomes a
> Django User they have to try logging (which fails of course).

Are you talking about admin login or a custom login ?

 We use too a bind to ldap for authentication in admin and we've
directly setted is_staff to True in this bind; it works.

 The user is directly connected.

 The problem is now to get permissions from ldap :-)

Frédéric


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



AnonymousUser and groups attribute

2009-07-21 Thread Frédéric Hébert

Hi there,

 I've a context_processor to automatically add to each template a
object which says to me if a given user is memeber of an admin group.
It works fine when user is authenticated (whichever groups he belongs
to) but raise an AttributeError when user is not.

"Nonetype has no attribute _meta" in models.query (get_meta method)

Here is my context_processor code :

--- CODE --

def is_gestion(request):

try:
return {'gestion': request.user.groups.get
(name=settings.BAOBAB_ADMIN_GROUP)}
except Group.DoesNotExist:
if request.user.is_superuser:
return {'gestion': True}
else:
return {'gestion': False}


- CODE ---

and here the my pasted trace :
http://dpaste.com/69576/

It appears that an AnonymousUser has an EmptyManager connected to its
groups attribute.

 AFAICS, this manager permits to keep the code applied to an
authenticated user valid even if an anonymous user is here.

 (eg we have more or less the same attributes on both User and
AnonymousUser objects).

 How can I handle the groups relation in this way ?

Thanks a lot

 Frédéric



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



Re: urls.py error: unbalanced parenthesis

2009-07-19 Thread Frédéric Hébert

2009/7/19 Rob B (uk) :
>
> Getting a unblanced parenthesis error with this urls setup. Not sure
> why.

The message is pretty self-explanatory. It seems to me that you have
forgotten a parenthesis after your first symbolic group named year.

Frédéric

> urls.py:
> from django.conf.urls.defaults import *
> from coltrane.models import Entry
>
> entry_info_dict = {
>        'queryset': Entry.objects.all(),
>        'date_field': 'pub_date',
>        }
>
> urlpatterns = patterns('django.views.generic.date_based',
>         (r'^$', 'archive_index', entry_info_dict,
> 'coltrane_entry_archive_index'),
>         (r'^(?P\d{4}/$', 'archive_year', entry_info_dict,
> 'coltrane_entry_archive_year'),
>         (r'^(?P\d{4}/(?P\w{3})/$', 'archive_month',
> entry_info_dict, 'coltrane_entry_archive_month'),
>         (r'^(?P\d{4}/(?P\w{3})/(?P\d{2}/)$',
> 'archive_day', entry_info_dict, 'coltrane_entry_archive_day'),
>         (r'^(?P\d{4}/(?P\w{3})/(?P\d{2})/(?P[-
> \w]+)/$', 'object_detail', entry_info_dict,  'coltrane_entry_detail'),
>    )
> >
>



-- 
http://www.openidfrance.fr/fhebert

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[Resolved] Re: Nested views and urls patterns declaration order

2009-07-13 Thread Frédéric Hébert

Hi,

> Try adding a '^' character to the front of your regular expressions,
> and see if the requests are passed to the proper views.

thanks a lot, it works.

> In your 'bad' situation, a url like "ue/reservations/xyz" gets matched
> by the first regex, and passed to view_list_reservation (your inner
> view), rather than being passed to your outer view, as you would like.

yes. When a url pattern like 'reservations/(\w*)/?$'

comes before this 'ue/(\d+)/reservations/?(\w*)/?$' it matches first.


Thanks a lot again,

Frédéric







-- 
http://www.openidfrance.fr/fhebert

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Nested views and urls patterns declaration order

2009-07-13 Thread Frédéric Hébert

Hi there,

first, here is my config:
 python 2.5.2
 django 1.0.2
 plateforme linux debian lenny

 I've two nested views, the inner of two using the list_detail.list
generic view.
The outter define a QuerySet and passes it to the inner view.

When I declare the outter view after the inner in urls.py she's never
been called. It's the inner that's got it.
(She's called when I reverse the order of declaration, eg the outter
first)

 I've pasted the code at dpaste : http://dpaste.com/hold/66588/

It's maybe a very stupid problem but I can't see why this happens.

Regards,

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



Re: Problem with AD (LDAP) authentication

2009-07-08 Thread Frédéric Hébert

Hi,

 Maybe,  should you put is_staff=True :

http://docs.djangoproject.com/en/dev/topics/auth/#users


Regards,

Frédéric


2009/7/8 Technicalbard :
>
> I'm trying to write an Active Directory / LDAP authenication, and I'm
> having problems.  The code is at: http://dpaste.com/hold/64752/
>
> When I set this authentication and then try to go to 
> http://localhost:8000/admin
> and login to the development server, it authenticates against the LDAP
> server (the print statements indicate as such in the django console),
> and it does create a new django user in the database.  But it doesn't
> redirect me to the admin interface.  It brings back the login screen
> with the error message:
>
> Please enter a correct username and password. Note that both fields
> are case-sensitive.
>
> Except I know that I did because the database was updated.  What am I
> doing wrong?
> >
>



-- 
http://www.openidfrance.fr/fhebert

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Catch an IntegrityError in views to get back pk value of prexisting model

2009-07-01 Thread Frédéric Hébert
Form(new_data1)

if form1.is_valid():
try:
enseignant = form1.save()
except IntegrityError:
enseignant = Enseignant.objects.get
(prenom__exact=new_data1['prenom'], nom__exact=new_data1['nom'])

-- CODE -

But it seems that the uniqueness is validate before the call of
model.save() and therefore before reaching DB.
The form seems never validate even when the teacher did not exist in
the DB.

 My question is : is there a way to catch the duplicate entry
exception and to retrieve the previous primary key (is there something
like IntegrityError.previous_pk )


Many thanks in advance and apologize for this very long post.

 Frédéric Hébert

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



Re: rollback transaction without an exception when transaction is tied to http requests

2009-06-26 Thread Frédéric Hébert

2009/6/26 sico :
>
> Hi
>

Hi

> Is it possible to rollback the transaction without raising an
> exception when the transactions are tied to http requests??

What do you mean ?
You use raw sql in  a view ?


> I'm writing several records in one post call, if any fail I'd like to
> rollback the transaction but return a nice error message to the user.
> Surely I'm missing something as this seems quite a simple
> requirement...

AFAIK, django automatically rollbacks your transaction when you use
its orm (and surely raises an exception).
If you use raw sql you can surely use try ... except around the Python
DB API call

>
> thanks in advance
> Simon


Frédéric

> >
>



-- 
http://www.openidfrance.fr/fhebert

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



Re: MemoryError on bigs list of items

2009-06-25 Thread Frédéric Hébert

2009/6/25 Andrew Fong <fongand...@gmail.com>:
>
> To clarify, you're displaying a list of 1000+ models on a single page,
> yes?
>

Yes, i will change that as soon as I could.

> My understanding is that the debug_toolbar analyzes each SQL query and
> keeps each result in memory before rendering everything in the
> template. I don't know how your query works, but let's take an extreme
> case and say your request executes 1000+ queries. In addition to
> keeping 1000 models in memory, the debug_toolbar now has to also
> contain the query data for 1000 queries. If you have a small amount of
> memory, this could eat it up pretty quick.
>

I understand that. But, what's bother me is that this very same list
have worked well before (with an average of two seconds of loading) on
the same server.
Indeed when I has activated debug_toolbar on my PC, lists were very
slow to display (about ten seconds and more) but there was not a
Memory error.

My validation server is virtualized. I will see with my admin the
amount of memory on it.

> I don't think setting MaxRequestsPerChild = 1 would do anything to
> cause a MemoryError. It should actually help, since if you're
> restarting the process after just 1 request, any memory leaks won't
> have time to build up.
No, indeed. A MaxRequestPerChild set to 1 don't change anything


Many thanks for your reply,

>
> -- Andrew
>

Frédéric

> On Jun 25, 1:15 pm, Frédéric Hébert <fg.heb...@gmail.com> wrote:
>> Hi there,
>>
>>  I'm facing with a curious problem.
>>
>>  I've an project which is hosted on three differents servers :
>>
>>  one (my local PC) :
>> debian lenny /
>> python 2.5.2 / django 1.0.2 final
>> apache 2.2.9 / mod_python 3.3.1-7
>>
>>  the two others (production and validation server) :
>> OpenSUSE 11.1 /
>> python 2.6.2 / django 1.0.2 final
>> apache 2.2.10 / mod_python 3.3.x-x
>>
>>  Two months ago, I've launched this project both on production server
>> and validation server.
>>  Neither validation server nor production server caused me any
>> trouble.
>>
>> Today, to test something, I've installed debug_toolbar extension and
>> set MaxRequestPerChild to 1 in Apache's conf file, both on my local
>> dev PC and on the validation server.
>>
>> When I want to display two long list (1000+ items each) i get a
>> MemoryError one time out of two. The remainder of project goes fine.
>>
>>  I've resetted MaxRequestPerChild to 1 (default value on OpenSUSE)
>> and commented out debug_toolbar's things in my settings, restart
>> Apache. But error happened again on the validation server.
>>
>>  On my local PC, it works well, with debug_toolbar and MaxReq.. set or
>> not.
>>
>> I've pasted the traceback  herehttp://dpaste.com/hold/59667/
>>
>>  AFAICS, an exception occurs when django tries to render a debug
>> template
>>
>> Here is an exerpt of my vhost conf file on OpenSUSE :
>>  DocumentRoot /srv/www/enseignements-dev.ehess.fr/ue
>>
>>     
>>       SetHandler python-program
>>       PythonHandler django.core.handlers.modpython
>>       SetEnv DJANGO_SETTINGS_MODULE ue.settings_dev
>>       PythonDebug On
>>       PythonPath "['/srv/www/enseignements-dev.ehess.fr/', '/srv/www/
>> enseignements-dev.ehess.fr/ue/'] + sys.path"
>>     
>>
>> Many thanks in advance,
>>
>>  Frédéric
> >
>



-- 
http://www.openidfrance.fr/fhebert

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



MemoryError on bigs list of items

2009-06-25 Thread Frédéric Hébert

Hi there,

 I'm facing with a curious problem.

 I've an project which is hosted on three differents servers :

 one (my local PC) :
debian lenny /
python 2.5.2 / django 1.0.2 final
apache 2.2.9 / mod_python 3.3.1-7

 the two others (production and validation server) :
OpenSUSE 11.1 /
python 2.6.2 / django 1.0.2 final
apache 2.2.10 / mod_python 3.3.x-x

 Two months ago, I've launched this project both on production server
and validation server.
 Neither validation server nor production server caused me any
trouble.

Today, to test something, I've installed debug_toolbar extension and
set MaxRequestPerChild to 1 in Apache's conf file, both on my local
dev PC and on the validation server.

When I want to display two long list (1000+ items each) i get a
MemoryError one time out of two. The remainder of project goes fine.

 I've resetted MaxRequestPerChild to 1 (default value on OpenSUSE)
and commented out debug_toolbar's things in my settings, restart
Apache. But error happened again on the validation server.

 On my local PC, it works well, with debug_toolbar and MaxReq.. set or
not.

I've pasted the traceback  here http://dpaste.com/hold/59667/

 AFAICS, an exception occurs when django tries to render a debug
template

Here is an exerpt of my vhost conf file on OpenSUSE :
 DocumentRoot /srv/www/enseignements-dev.ehess.fr/ue


  SetHandler python-program
  PythonHandler django.core.handlers.modpython
  SetEnv DJANGO_SETTINGS_MODULE ue.settings_dev
  PythonDebug On
  PythonPath "['/srv/www/enseignements-dev.ehess.fr/', '/srv/www/
enseignements-dev.ehess.fr/ue/'] + sys.path"



Many thanks in advance,

 Frédéric

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



Re: MySQLdb Exceptions

2009-06-11 Thread Frédéric Hébert

Hi,

have you an access to your mysql server config file ?

In that case, you could enable logging :
To see the current variables values type mysqld --verbose --version in
a shell prompt.
Search for log* variables.
If log is set to false see link below

"The general query log is a general record of what mysqld is doing.
The server writes information to this log when clients connect or
disconnect, and it logs each SQL statement received from clients. The
general query log can be very useful when you suspect an error in a
client and want to know exactly what the client sent to mysqld. "
(from MySQL 5.0 manual)

http://dev.mysql.com/doc/refman/5.0/en/query-log.html

Hope it will be helpfull

Frédéric

2009/6/11 jrivero :
>
> Hi!
>
> I have one mysqldb exception on insert or update in some model with
> message [1] and can not find it. Django does not catch and return
> generic error 500.
>
> [1]: Exception exceptions.TypeError: "'NoneType' object is not
> callable" in  object at 0x1dd56d50>> ignored
>
> I suspect that appears after a change in the properties of any table.
>
> Some idea for find? Is possible catch all exception commit-query's and
> logging the query?
>
> Thanks!
> Jordi.
>
> >
>

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



How to do custom validation of models ?

2009-06-09 Thread Frédéric Hébert

Hi all,

 I have two models related with a foreign key like these :

  CODE ---

 class Reservation(models.Model):
   some fields here ...

 class Periodicite(models.Model):
  some fields here 
# rep_opt is a fake suite of bits, where each bit represent
# a(some) day(s) of the week like so f.e. :
# 100 represents monday
# 1001000 represents monday + thursday
rep_opt = ?
reservation = models.ForeignKey(Reservation, verbose_name='')

  -- CODE 

 The 'Periodicite' model will never be bind to a form instance,
because none of it's field need an user input (it's automatically
filled with informations from 'Reservation' model).

 What I would like is to ensure that rep_opt is a valid 'encoding' of
a valid day, eg only filled with 0 or 1, at least a 1 character, and
is 7 'bits' width.

 I have not found a models.fields.RegexField and then want to do it in
the Periodicite model's save method. But how could we do some
validation here, and tell to django when a validation fails in order
to abort validation process ?

Thanks in advance for your replies,

 Frédéric

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



Re: Overriding save() method on models to automatically add ManyToMany relationship

2009-06-09 Thread Frédéric Hébert

Hi,
> defsave(self, *args):
>    models.Model(save, *args)
>    category = Category.objects.all()[0]
>    self.categories.add(category)
>
> This does not work, I'm sure it's saving ManyToMany relationships
> later on in thesaveprocess.  Is there a way to make this work?
>


IMHO, it's make sense : you call the parent save method before
defining new categories on it. How parent save method could know
anything about these new categories ?

Have you try :

def save(self, *args, **kwargs):
category = Category.objects.all()[0]
self.categories.add(category)
super(Product, self).save(*args, **kwargs)

Frédéric

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---