Model Validation

2011-09-24 Thread jenia ivlev
I have a model M that has a field num=models.IntegerField()
I have a modelform called 'F' for model 'M'.
I want to ensure that num is never negative.

If I do validation in my form class, 'F', then i can do clean_num():
if negative than throw ValidationError('Num can never be negative').
This validationerror will be automatically redisplayed to the user by
redirecting him to back to the form that he submitted and displaying
the 'Num can never be negative' message on top of the num field.
Thats all done automatically by django as soon as I throw the
validationerror from the clean_fieldname method.

I would like to be able to do all that, but in the model class.

So F, that has a FormField for the ModelField 'num' , will fail and
display the error message defined in the model class that its
representing.
Also F2 and Fxxx will do the same if they all represent 'M' and have a
FormField for ModelField num.

How can I achieve this?

Thank you for your time and kind concern.
jenia

-- 
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: Parellel request from the same user in very short time

2011-09-24 Thread Russell Keith-Magee
On Sat, Sep 24, 2011 at 10:08 PM, Martin Tiršel  wrote:
> Hello,
>
> I am using Apache with mod_wsgi and following setting:
>
> WSGIDaemonProcess dev.xyz.com processes=1 threads=5 user=xyz group=xyz
> display-name=dev.xyz.com
>
> I am observing some situations where a user sends the same request multiple
> times (double click?) where the time between these requests is very low -
> 80-100ms. Then I got these situations (bot request from the same user):
>
> 1. request A - SELECT ...
> 2. request B - SELECT ...
> 3. request A - INSERT ... (insert is based on select result from step 1)
> 4. request B - INSERT ... (insert is based on select result from step 2)
>
> Because 1. and 2. gets the same data, I end with doubled (or sometimes
> trippled) inserts what breaks my application. How do you prevent such
> behaviour? I am using Django 1.2.x

I might be missing something obvious here, but isn't this *exactly*
what database transactions are designed to fix? Admittedly, you've got
an unusual presentation born out of weird browser behavior, but making
sure that two overlapping operations don't violate data integrity
sounds like the textbook case for using transactions.

Yours,
Russ Magee %-)

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



Django auth context processor: not to query for user for each request

2011-09-24 Thread Alexey Moskvin
Hi,  I enabled django auth middleware, so now I have a user variable
in my request context. In this case for each page request user object
is queried from the database. Is it possible to set up this middleware
to use a cached user object (for example, put by me in session)? User
objects are not updated frequently, so I don't need to have an extra
DB query for each page. Thanks.

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



Re: Parellel request from the same user in very short time

2011-09-24 Thread Thomas Orozco
Well, depends on what you're going to do with this data and what it
represents, but maybe the simpler solution is to use a small javascript in
your page that prevents the user from posting the same data twice.
I actually had the same issue running a site of mine, and a double POST is
mostly detrimental to the user, so there's no risk of having anyone changing
the JS just to be able to post twice.

You however have to consider users with noscript then.

Or you could try and speed up the process of answering the request so the
user does go like "Oh maybe I didn't click!" using, for example,
asynchronous work.

It's up to you!

Thomas

2011/9/24 Martin Tiršel 

> Hello,
>
> I am using Apache with mod_wsgi and following setting:
>
> WSGIDaemonProcess dev.xyz.com processes=1 threads=5 user=xyz group=xyz
> display-name=dev.xyz.com
>
> I am observing some situations where a user sends the same request multiple
> times (double click?) where the time between these requests is very low -
> 80-100ms. Then I got these situations (bot request from the same user):
>
> 1. request A - SELECT ...
> 2. request B - SELECT ...
> 3. request A - INSERT ... (insert is based on select result from step 1)
> 4. request B - INSERT ... (insert is based on select result from step 2)
>
> Because 1. and 2. gets the same data, I end with doubled (or sometimes
> trippled) inserts what breaks my application. How do you prevent such
> behaviour? I am using Django 1.2.x
>
> I am just applying memcached to prevent these situations:
>
> lock_id = "construction_view-%s" % context['active_base'].id
> acquire_lock = lambda: cache.add(lock_id, "true", LOCK_EXPIRE)
> release_lock = lambda: cache.delete(lock_id)
>
> while not acquire_lock() and lock_attempt < 3:
>time.sleep(1)
>lock_attempt += 1
> else:
>raise ...
> ...
> release_lock()
>
>
> But I am not sure if this is the right way. If there is no better solution,
> the second question is, should I time.sleep(1) until previous request
> releases lock or return some 5xx or 4xx error on such request?
>
> Thanks,
> Martin
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe@**
> googlegroups.com .
> For more options, visit this group at http://groups.google.com/**
> group/django-users?hl=en
> .
>
>

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



Parellel request from the same user in very short time

2011-09-24 Thread Martin Tiršel

Hello,

I am using Apache with mod_wsgi and following setting:

WSGIDaemonProcess dev.xyz.com processes=1 threads=5 user=xyz group=xyz  
display-name=dev.xyz.com


I am observing some situations where a user sends the same request  
multiple times (double click?) where the time between these requests is  
very low - 80-100ms. Then I got these situations (bot request from the  
same user):


1. request A - SELECT ...
2. request B - SELECT ...
3. request A - INSERT ... (insert is based on select result from step 1)
4. request B - INSERT ... (insert is based on select result from step 2)

Because 1. and 2. gets the same data, I end with doubled (or sometimes  
trippled) inserts what breaks my application. How do you prevent such  
behaviour? I am using Django 1.2.x


I am just applying memcached to prevent these situations:

lock_id = "construction_view-%s" % context['active_base'].id
acquire_lock = lambda: cache.add(lock_id, "true", LOCK_EXPIRE)
release_lock = lambda: cache.delete(lock_id)

while not acquire_lock() and lock_attempt < 3:
time.sleep(1)
lock_attempt += 1
else:
raise ...
...
release_lock()


But I am not sure if this is the right way. If there is no better  
solution, the second question is, should I time.sleep(1) until previous  
request releases lock or return some 5xx or 4xx error on such request?


Thanks,
Martin

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



small problem with django-filebrowser and tinymce integration

2011-09-24 Thread xpanta
Hi,

I am trying to integrate django-tinymce with django-filebrowser for my
django admin.
Everything (almost) works fine.

- manage.py test filebrowser, works ok
- http://localhost:8000/admin/filebrowser/browse/ works, too

however when I press the  button on the windows popup of
 of tinymce button panel in its HTML field nothing
happens.
in my firefox debug window I get an error like this:

f is undefined
code: http://localhost:8000/static/js/tiny_mce/tiny_mce_src.js
line: 11981

and on my dev-server output window I get a 500 error like this:

"GET /tinymce/filebrowser/ HTTP/1.1" 500

Any ideas what am I doing wrong?

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



Re: DJango doesn't work with Oracle 11g on Windows 8

2011-09-24 Thread Benjamin Welton

Hey Alec,
django.core.exceptions.ImproperlyConfigured: Error loading cx_Oracle 
module: DLL load failed: %1 is not a valid Win32 application.
Do you have the visual c redistributable installed for 64bit and the 
Python for windows extensions for 64bit installed?


Ben

On 9/24/2011 3:17 AM, Alec Taylor wrote:

Good afternoon,

Unfortunately DJango doesn't work with Oracle 11g Express on Windows 8 x64.

DJango error: http://pastebin.com/8tAzsjYh (summary: "No module named
cx_Oracle")

pip install cx_Oracle output: http://pastebin.com/6Y61PqSM

easy_install cx_Oracle output: http://pastebin.com/rCsY63RS

Summary: "Unable to find vcvarsall.bat"

When I try tried the x64 installer from
http://cx-oracle.sourceforge.net/ (using Python 2.7 x64), I got the
following manage.py syncdb error: http://pastebin.com/syqxF4m6

How can I make DJango work with my Oracle 11g Express database?

Thanks for all suggestions,

Alec Taylor



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



DJango doesn't work with Oracle 11g on Windows 8

2011-09-24 Thread Alec Taylor
Good afternoon,

Unfortunately DJango doesn't work with Oracle 11g Express on Windows 8 x64.

DJango error: http://pastebin.com/8tAzsjYh (summary: "No module named
cx_Oracle")

pip install cx_Oracle output: http://pastebin.com/6Y61PqSM

easy_install cx_Oracle output: http://pastebin.com/rCsY63RS

Summary: "Unable to find vcvarsall.bat"

When I try tried the x64 installer from
http://cx-oracle.sourceforge.net/ (using Python 2.7 x64), I got the
following manage.py syncdb error: http://pastebin.com/syqxF4m6

How can I make DJango work with my Oracle 11g Express database?

Thanks for all suggestions,

Alec Taylor

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