RE: How to Auto fill fields on Save in Django Admin?

2011-02-16 Thread Chris Matthews
Hi Matteius,

You must set blank=True in the model so that the form can be returned to you 
with those fields empty and then you fill it in the save().

pub_date = models.DateTimeField(blank=True)
author = models.ForeignKey(User, blank=True, verbose_name='Author')

Also read up on editable=False

Regards
Chris
-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Matteius
Sent: 17 February 2011 08:47
To: Django users
Subject: How to Auto fill fields on Save in Django Admin?

I have an Announcement model that has two fields I want to auto-fill
in when they are left blank (they are required fields with normal
defaults).  I have the following Code (simplified data listing for
this post)  THe Problem is that when I go to save an Announement
in the admin with either of those fields blank it returns to the Add/
Edit Form with "This field is required." despite my code to try and
fill that in.  Clearly I'm missing how to do this, any advice?

class Announcement(models.Model):
""" Represents an Announcement in the classcomm system. """

# Data Model Fields
pub_date = models.DateTimeField()
author = models.ForeignKey(User, verbose_name='Author')

def clean(self):
""" Implement auto fill pub_date. """
if not self.pub_date:
self.pub_date = datetime.today()
super(Announcement, self).clean()
# EndDef

def save(self):
""" Implement auto fill pub_date. """
if not self.pub_date:
self.pub_date = datetime.today()
super(Announcement, self).save()
# EndDef
# EndClass

Then in admin.py I have:

class AnnouncementAdmin(admin.ModelAdmin):
""" Admin customizations for Announcement Models. """
fieldsets = (
(None, {
'fields': ('headline', 'department', 'course', 'content')
}),
('Advanced options', {
'classes': ('collapse',),
'fields': ('author', 'pub_date', 'make_global')
}),
)

def save_model(self, request, obj, form, change):
""" Autofill in author when blank on save models. """
obj.author = request.user
obj.save()
# EndDef

def save_formset(self, request, form, formset, change):
""" Autofill in author when blank on save formsets. """
instances = formset.save(commit=False)
for instance in instances:
instance.author = request.user
instance.save()
formset.save_m2m()
# EndDef
# EndClass


Regards,
Matt

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

-- 
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 Auto fill fields on Save in Django Admin?

2011-02-16 Thread Matteius
I have an Announcement model that has two fields I want to auto-fill
in when they are left blank (they are required fields with normal
defaults).  I have the following Code (simplified data listing for
this post)  THe Problem is that when I go to save an Announement
in the admin with either of those fields blank it returns to the Add/
Edit Form with "This field is required." despite my code to try and
fill that in.  Clearly I'm missing how to do this, any advice?

class Announcement(models.Model):
""" Represents an Announcement in the classcomm system. """

# Data Model Fields
pub_date = models.DateTimeField()
author = models.ForeignKey(User, verbose_name='Author')

def clean(self):
""" Implement auto fill pub_date. """
if not self.pub_date:
self.pub_date = datetime.today()
super(Announcement, self).clean()
# EndDef

def save(self):
""" Implement auto fill pub_date. """
if not self.pub_date:
self.pub_date = datetime.today()
super(Announcement, self).save()
# EndDef
# EndClass

Then in admin.py I have:

class AnnouncementAdmin(admin.ModelAdmin):
""" Admin customizations for Announcement Models. """
fieldsets = (
(None, {
'fields': ('headline', 'department', 'course', 'content')
}),
('Advanced options', {
'classes': ('collapse',),
'fields': ('author', 'pub_date', 'make_global')
}),
)

def save_model(self, request, obj, form, change):
""" Autofill in author when blank on save models. """
obj.author = request.user
obj.save()
# EndDef

def save_formset(self, request, form, formset, change):
""" Autofill in author when blank on save formsets. """
instances = formset.save(commit=False)
for instance in instances:
instance.author = request.user
instance.save()
formset.save_m2m()
# EndDef
# EndClass


Regards,
Matt

-- 
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: Importing modules in code

2011-02-16 Thread Kenneth Gonsalves
On Wed, 2011-02-16 at 02:12 -0800, Daniel Roseman wrote:
> Your question betrays a misconception that I often see. Django - at
> least 
> when served other than via CGI - does not reload everything for each 
> request. The Django process is long-running, and is managed by the
> server, 
> but usually runs for a number of requests before being respawned. 

could you elaborate on this? I am suffering from this misconception.
-- 
regards
KG
http://lawgon.livejournal.com
Coimbatore LUG rox
http://ilugcbe.techstud.org/

-- 
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: App engine serving static files?

2011-02-16 Thread Eric Chamberlain

On Feb 15, 2011, at 11:44 PM, Praveen Krishna R wrote:

> Hey Guys,
> 
> Does Anyone has experience, serving static content with google app engine?
> Does it make a big difference, than serving it with nginx on the same server 
> as django?
> I currently use a shared hosting, and was just thinking to move the static 
> content to GAE
> I would like to know your thoughts on this

We serve our static content from Amazon S3, it's much easier to setup and use.

--
Eric Chamberlain, Founder
RF.com - http://RF.com/







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



RE: how can I filter related (foreign key) objects?

2011-02-16 Thread Chris Matthews
Hi Serek,



Try this

def doMagic(self):

date = '2010-05-04'

#//here I need to take 10 conencted Bbb objects whcich data is less 
then date

previous10days = Bbb.objects.filter(date__lt=date).order_by('data')



Also read up about managers 
http://docs.djangoproject.com/en/1.2/topics/db/managers/ in case you should 
consider using it (depending upon how much magic is required from your 
function).



Regards

Chris



-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of serek
Sent: 17 February 2011 00:51
To: Django users
Subject: how can I filter related (foreign key) objects?



Hi



I have not idea how to describe my problem, so I show pice of code:





class Aaa(models.Model):

name = models.CharField(max_length=200, unique=True)

is_active = models.BooleanField()



class Meta:

ordering = ('name',)



def doMagic(self):

  date = '2010-05-04'

  //here I need to take 10 conencted Bbb objects whcich data is less

then date

previous10days = self.bbb_set.filter(Bbb.date <

date).order_by('data')





class Bbb(models.Model):

date = models.DateField()

value = models.DecimalField(max_digits=7, decimal_places=2)

aaa = models.ForeignKey(Aaa)



a = Aaa()

a.doMagic throw error that Bbb.date is undefined - what can be 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.


-- 
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: Having trouble synchronizing the database, can someone help?

2011-02-16 Thread Chen Xu
Sorry, I dont really understand how python manage.py sqlcustom  command
works, can anyone give an example, I am trying to flush a database for one
of my two apps.


Thanks

On Tue, Feb 15, 2011 at 12:33 AM, Szabo, Patrick (LNG-VIE) <
patrick.sz...@lexisnexis.at> wrote:

>  I think i rember reading in the doc that you can somehow run custom
> sql...is that an option ?!
>
>
>
> If this is something you don’t have to do regularly you could also just
> connect to the db with some gui-client and delete the tables there
>
>
>
> . . . . . . . . . . . . . . . . . . . . . . . . . .
>
>  **
>
> Patrick Szabo
> XSLT-Entwickler
>
> LexisNexis
> Marxergasse 25, 1030 Wien
>
> patrick.sz...@lexisnexis.at
>
> Tel.: +43 (1) 534 52 - 1573
>
> Fax: +43 (1) 534 52 - 146
>
>
> *Von:* django-users@googlegroups.com [mailto:django-users@googlegroups.com]
> *Im Auftrag von *Chen Xu
> *Gesendet:* Dienstag, 15. Februar 2011 09:01
>
> *An:* django-users@googlegroups.com
> *Betreff:* Re: Having trouble synchronizing the database, can someone
> help?
>
>
>
> thanks, flush does help, but it delete everything, however I have 2 apps in
> my db, so is there any commands (ex: sqlclear ) that allows me to
> only remove the tables in particular app??
>
> Thanks
>
> On Mon, Feb 14, 2011 at 11:51 PM, Szabo, Patrick (LNG-VIE) <
> patrick.sz...@lexisnexis.at> wrote:
>
> I think sqlflush just prints the SQL-Statement.
>
> Flush will actually du the job
>
>
>
> Hope that helps !
>
>
>
> . . . . . . . . . . . . . . . . . . . . . . . . . .
>
> Patrick Szabo
> XSLT-Entwickler
>
> LexisNexis
> Marxergasse 25, 1030 Wien
>
> patrick.sz...@lexisnexis.at
>
> Tel.: +43 (1) 534 52 - 1573
>
> Fax: +43 (1) 534 52 - 146
>
>
>
> *Von:* django-users@googlegroups.com [mailto:django-users@googlegroups.com]
> *Im Auftrag von *Chen Xu
> *Gesendet:* Dienstag, 15. Februar 2011 08:45
> *An:* django-users@googlegroups.com
> *Betreff:* Re: Having trouble synchronizing the database, can someone
> help?
>
>
>
> thanks very much everyone, but I just have one more small question.
>
> I tried to use some python manage.py command to delete tables (ex:
> sqlflush, sqlreset),
> but they all just print out the sql statement without doing the real job,
> so what is the command to do the actual removal of the tables?
>
>
> 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.
>
>
>
>
> --
> ⚡ Chen Xu ⚡
>
> --
> 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.
>
>
>  --
> 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.
>



-- 
⚡ Chen Xu ⚡

-- 
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: form select box how to (help needed)

2011-02-16 Thread Chris Matthews
Hi Bobby,

See 
http://adil.2scomplement.com/2008/05/django-add-choices-to-form-fields-on-runtime/

Try something like the following:

# Define your choices
LOCATION_CHOICES = ((1,'location1'),
(2,'location2'),
(3,'location3'),
(4,'location4'),
   )

LOCATION_CHOICES_PUBLIC = ((1,'location1'),
(2,'location2'),
(3,'location3'),
   )

Example 1
-
class ProfileForm(forms.Form):
class Meta:
model = Profile

locations = forms.ChoiceField(required=True)

def __init__(self, *args, **kwargs):
# This is a bit of a hack
if 'user_type' in kwargs and kwargs['user_type'] == 'public':
public = True
# We do not want to pass our kwarg to super
del kwargs['user_type']
else:
public = False

super(ProfileForm, self).__init__(*args, **kwargs)

if 'user_type' in kwargs and kwargs['user_type'] == 'public':
self.fields['locations'].choices = LOCATION_CHOICES_PUBLIC
else:
self.fields['locations'].choices = LOCATION_CHOICES

In your module use
form = ProfileForm(user_type='public')
or
form = ProfileForm()

Example 2
-
class ProfileForm(forms.Form):
class Meta:
model = Profile

# the limited choices are our default
locations = forms.ChoiceField(choices = LOCATION_CHOICES_PUBLIC, 
required=True)

In your module
form = ProfileForm()
if not public:
form.fields['locations'].choices = LOCATION_CHOICES


Example 2 is a bit 'cleaner'/neater I think.

Regards
Chris

-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Bobby Roberts
Sent: 16 February 2011 15:14
To: Django users
Subject: Re: form select box how to (help needed)

i have no idea what this means is there an example anywhere?

On Feb 16, 12:43 am, Kenneth Gonsalves  wrote:
> On Tue, 2011-02-15 at 19:05 -0800, Bobby Roberts wrote:
> > I can't load it through the "CHOICES" parameter in my forms field...
> > how can I do this?
>
> override __init__ in your form and populate there
> --
> regards
> KGhttp://lawgon.livejournal.com
> Coimbatore LUG roxhttp://ilugcbe.techstud.org/

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

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



Slammed Hard on Django Admin Queries with Tabular Inlines

2011-02-16 Thread Matteius
So I've been implementing the new Django 1.2 and 1.3 methods such as
queryset in my admin.py for my Classcomm student models.  All is going
well, in the case of an Add/Edit DDO page I went from having 82/87 to
6/10 queries which makes things now much more tolerable.  However I
still have a concern that has developed into a hypothesis and that is:
On Admin TabularInlines  ForeignKey User fields will generate 2
queries per User selection widget where each query looks like:

0.57SELECT
EXPLAIN

Toggle Stacktrace

SELECT `auth_user`.`id`, `auth_user`.`username`,
`auth_user`.`first_name`, `auth_user`.`last_name`,
`auth_user`.`email`, `auth_user`.`password`, `auth_user`.`is_staff`,
`auth_user`.`is_active`, `auth_user`.`is_superuser`,
`auth_user`.`last_login`, `auth_user`.`date_joined` FROM `auth_user`

Well so for example, I have 2 of these queries at least on any
Department Add/Edit page because I have a TabularInline Couse widget.
I get 2 queries for the first widget, and if the Department has n
courses then I get n additional query lines all with the identical
query.  This is one case where I really wish I had johny-cacheing in
place!

It is also bad for a Course Edit Page with 3 Tabular Inline:
Instructors, Mentors and Assignments.  In this case I get 5 identical
auth_user queries: I'm guessing 1 for the Course.course_director
field. And 2 each for the Instructor and Mentor auth_user ForeignKey
fields.  My guess is there is a bug in the widget code or template
that is generating this query twice initially? and the subsequent
queries are the summation of queries considering queries won't be
reused, but rather regenerated across the original admin fieldsets and
each admin Inline.  More work will go into simplifying these queries
in the admin, and please offer any suggestions or if my hypothesis
sounds correct to you.

Thanks, Best Regards,
matt

-- 
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: thummer and django

2011-02-16 Thread Graham Dumpleton
Add the 500.html template like it tells you to, then you can see what the 
real error is. Otherwise enable DEBUG, as is also suggests.

http://docs.djangoproject.com/en/dev/topics/http/views/#the-500-server-error-view

On Thursday, February 17, 2011 7:31:04 AM UTC+8, mickarea wrote:
>
> Hi, 
>
>
> I'm trying to test thummer on my ubuntu 10.04 server machine, but i 
> got this error : 
>
>
> ProcessId:  3635 
> Interpreter:'test.test.com' 
>
> ServerName: 'test.test.com' 
> DocumentRoot:   '/var/www/thummer/thummer' 
>
> URI:'/300/300/1/http://news.bbc.co.uk/' 
> Location:   None 
> Directory:  '/var/www/thummer/thummer/' 
> Filename:   '/var/www/thummer/thummer/300' 
> PathInfo:   '/300/1/http:/news.bbc.co.uk/' 
>
> Phase:  'PythonHandler' 
> Handler:'django.core.handlers.modpython' 
>
> Traceback (most recent call last): 
>
>   File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 
> 1537, in HandlerDispatch 
> default=default_handler, arg=req, silent=hlist.silent) 
>
>   File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 
> 1229, in _process_target 
> result = _execute_target(config, req, object, arg) 
>
>   File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 
> 1128, in _execute_target 
> result = object(arg) 
>
>   File "/usr/lib/pymodules/python2.6/django/core/handlers/ 
> modpython.py", line 228, in handler 
> return ModPythonHandler()(req) 
>
>   File "/usr/lib/pymodules/python2.6/django/core/handlers/ 
> modpython.py", line 201, in __call__ 
> response = self.get_response(request) 
>
>   File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py", 
> line 134, in get_response 
> return self.handle_uncaught_exception(request, resolver, exc_info) 
>
>   File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py", 
> line 166, in handle_uncaught_exception 
> return callback(request, **param_dict) 
>
>   File "/usr/lib/pymodules/python2.6/django/views/defaults.py", line 
> 23, in server_error 
> t = loader.get_template(template_name) # You need to create a 
> 500.html template. 
>
>   File "/usr/lib/pymodules/python2.6/django/template/loader.py", line 
> 81, in get_template 
> source, origin = find_template_source(template_name) 
>
>   File "/usr/lib/pymodules/python2.6/django/template/loader.py", line 
> 74, in find_template_source 
> raise TemplateDoesNotExist, name 
>
> TemplateDoesNotExist: 500.html 
>
>
> I don't understand what is wrong, i google it, it seems that 
> mod_python can't access to the thummer application ? 
>
> " 
> You're seeing this particular traceback because an internal error 
> occurred and you don't have a template for displaying the "internal 
> server error" message -- when DEBUG is True, Django does this on the 
> fly for you to display the traceback, but when DEBUG is False you must 
> create a template named '500.html' to display on an internal error 
> (called '500.html', because 500 is the HTTP status code for an 
> internal server error). If you look at the traceback you'll see a line 
> which says "You need to create a 500.html template", and the final 
> line is telling you Django could not find that template. 
> " 
>
> But my python path is : 
> PythonPath "['/var/www/thummer'] + sys.path" 
>
>
> and  on the folder /var/www/thummer : 
> COPYING 
> database/ 
> media/ 
> templates/ 
>   404.html 
>   admin/ 
>   base.html 
>   thumbs/ 
> thummer/ 
>
>
> And finally my example config : 
>
>
>  
>
> ErrorLog /var/log/apache2/error.log 
>
> # Possible values include: debug, info, notice, warn, error, 
> crit, 
> # alert, emerg. 
> LogLevel warn 
>
> CustomLog /var/log/apache2/access.log combined 
>
>
>   DocumentRoot /var/www/thummer/thummer 
>
> AllowOverride All 
> Order Allow,Deny 
> Allow from All 
> SetHandler python-program 
> PythonHandler django.core.handlers.modpython 
> SetEnv DJANGO_SETTINGS_MODULE thummer.settings 
> PythonDebug On 
> PythonPath "['/var/www/thummer'] + sys.path" 
>
>   # Static Media Content 
>   Alias /media /var/www/thummer/media 
>
> SetHandler None 
> Order Allow,Deny 
> Allow from All 
>
>   Alias /admin-media /usr/share/python-support/python-django/django/ 
> contrib/admin/media 
>
> SetHandler None 
> Order Allow,Deny 
> Allow from All 
>
>  
>
>
>
> So what is wrong ? 
>
>
> thanks for the help, 
>
>
>
>

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



thummer and django

2011-02-16 Thread mickarea
Hi,


I'm trying to test thummer on my ubuntu 10.04 server machine, but i
got this error :


ProcessId:  3635
Interpreter:'test.test.com'

ServerName: 'test.test.com'
DocumentRoot:   '/var/www/thummer/thummer'

URI:'/300/300/1/http://news.bbc.co.uk/'
Location:   None
Directory:  '/var/www/thummer/thummer/'
Filename:   '/var/www/thummer/thummer/300'
PathInfo:   '/300/1/http:/news.bbc.co.uk/'

Phase:  'PythonHandler'
Handler:'django.core.handlers.modpython'

Traceback (most recent call last):

  File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line
1537, in HandlerDispatch
default=default_handler, arg=req, silent=hlist.silent)

  File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line
1229, in _process_target
result = _execute_target(config, req, object, arg)

  File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line
1128, in _execute_target
result = object(arg)

  File "/usr/lib/pymodules/python2.6/django/core/handlers/
modpython.py", line 228, in handler
return ModPythonHandler()(req)

  File "/usr/lib/pymodules/python2.6/django/core/handlers/
modpython.py", line 201, in __call__
response = self.get_response(request)

  File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py",
line 134, in get_response
return self.handle_uncaught_exception(request, resolver, exc_info)

  File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py",
line 166, in handle_uncaught_exception
return callback(request, **param_dict)

  File "/usr/lib/pymodules/python2.6/django/views/defaults.py", line
23, in server_error
t = loader.get_template(template_name) # You need to create a
500.html template.

  File "/usr/lib/pymodules/python2.6/django/template/loader.py", line
81, in get_template
source, origin = find_template_source(template_name)

  File "/usr/lib/pymodules/python2.6/django/template/loader.py", line
74, in find_template_source
raise TemplateDoesNotExist, name

TemplateDoesNotExist: 500.html


I don't understand what is wrong, i google it, it seems that
mod_python can't access to the thummer application ?

"
You're seeing this particular traceback because an internal error
occurred and you don't have a template for displaying the "internal
server error" message -- when DEBUG is True, Django does this on the
fly for you to display the traceback, but when DEBUG is False you must
create a template named '500.html' to display on an internal error
(called '500.html', because 500 is the HTTP status code for an
internal server error). If you look at the traceback you'll see a line
which says "You need to create a 500.html template", and the final
line is telling you Django could not find that template.
"

But my python path is :
PythonPath "['/var/www/thummer'] + sys.path"


and  on the folder /var/www/thummer :
COPYING
database/
media/
templates/
  404.html
  admin/
  base.html
  thumbs/
thummer/


And finally my example config :




ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error,
crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined


  DocumentRoot /var/www/thummer/thummer
  
AllowOverride All
Order Allow,Deny
Allow from All
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE thummer.settings
PythonDebug On
PythonPath "['/var/www/thummer'] + sys.path"
  
  # Static Media Content
  Alias /media /var/www/thummer/media
  
SetHandler None
Order Allow,Deny
Allow from All
  
  Alias /admin-media /usr/share/python-support/python-django/django/
contrib/admin/media
  
SetHandler None
Order Allow,Deny
Allow from All
  




So what is wrong ?


thanks for the help,



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



ManyToMany problem

2011-02-16 Thread Amar
Hi,

I have a problem with accessing items using ManyToMany relationship.
Here is a sample from shell:

>>> parts = Event.objects.all()[0].participants.all()
>>> parts
[, ]
>>> parts[0]

>>> parts[1]

>>> for p in parts:
...   print p
...
P1
P2


I cant figure out why accessing parts[0] and parts[1] gives the same
result, but loop works.

Code:
class Event(models.Model):
...
participants = models.ManyToManyField(Participant,
through='EventParticipant')

class EventParticipant(models.Model):
...
participant = models.ForeignKey(Participant)
event = models.ForeignKey(Event,
related_name="event_participants")

There is also a Participant class with nothing special inside. All
class have __unicode__ method to return name of the event/participant.

I'm still learning django, so any help will be apreciated :D

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



Re: how can I filter related (foreign key) objects?

2011-02-16 Thread Matias Aguirre
Just refer to the field name, you don't need the class:

prev = self.bbb_set.filter(date__lt=date)

Take a look to field lookup rules:
http://docs.djangoproject.com/en/dev/topics/db/queries/#field-lookups-intro

Excerpts from serek's message of Wed Feb 16 20:51:05 -0200 2011:
> Hi
> 
> I have not idea how to describe my problem, so I show pice of code:
> 
> 
> class Aaa(models.Model):
> name = models.CharField(max_length=200, unique=True)
> is_active = models.BooleanField()
> 
> class Meta:
> ordering = ('name',)
> 
> def doMagic(self):
> date = '2010-05-04'
> //here I need to take 10 conencted Bbb objects whcich data is less
> then date
> previous10days = self.bbb_set.filter(Bbb.date <
> date).order_by('data')
> 
> 
> class Bbb(models.Model):
> date = models.DateField()
> value = models.DecimalField(max_digits=7, decimal_places=2)
> aaa = models.ForeignKey(Aaa)
> 
> a = Aaa()
> a.doMagic throw error that Bbb.date is undefined - what can be wrong?
> 
-- 
Matías Aguirre 

-- 
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 can I filter related (foreign key) objects?

2011-02-16 Thread serek
Hi

I have not idea how to describe my problem, so I show pice of code:


class Aaa(models.Model):
name = models.CharField(max_length=200, unique=True)
is_active = models.BooleanField()

class Meta:
ordering = ('name',)

def doMagic(self):
date = '2010-05-04'
//here I need to take 10 conencted Bbb objects whcich data is less
then date
previous10days = self.bbb_set.filter(Bbb.date <
date).order_by('data')


class Bbb(models.Model):
date = models.DateField()
value = models.DecimalField(max_digits=7, decimal_places=2)
aaa = models.ForeignKey(Aaa)

a = Aaa()
a.doMagic throw error that Bbb.date is undefined - what can be 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: App engine serving static files?

2011-02-16 Thread rafael.nu...@gmail.com
The 'cold start' could be a problem. But if you pay $9/month to 'AlwaysOn'
feature, it's ok.
I am using without 'AlwaysOn', with a little 'workaround' and with an
agressive cache, it's very good.

On Wed, Feb 16, 2011 at 9:32 AM, Brian Bouterse  wrote:

> I've never used it, but I always wanted to use 
> DryDropto push all my static media over to GAE.
>
> Brian
>
>
> On Wed, Feb 16, 2011 at 2:44 AM, Praveen Krishna R <
> rpraveenkris...@gmail.com> wrote:
>
>> *Hey Guys,*
>> *
>> *
>> *Does Anyone has experience, serving static content with google app
>> engine?*
>> *Does it make a big difference, than serving it with nginx on the same
>> server as django?*
>> *I currently use a shared hosting, and was just thinking to move the
>> static content to GAE*
>> *I would like to know your thoughts on this*
>> *
>> *
>> --
>> Thanks and Regards,
>> *Praveen Krishna R*
>>
>>  --
>> 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.
>>
>
>
>
> --
> Brian Bouterse
> ITng Services
>
> --
> 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.
>

-- 
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: Class-based views & authentication

2011-02-16 Thread Łukasz Rekucki
On 16 February 2011 19:46, Andre Terra  wrote:
> I should also add that the functionality described in the docs simply did
> not work for me:
> http://docs.djangoproject.com/en/dev//topics/class-based-views/#decorating-the-class
>
> My attempt to follow that approach is registered here:
> http://dpaste.com/hold/423359/

It's an error in the docs. It should be:

class ProtectedView(TemplateView):
template_name = 'secret.html'

@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(ProtectedView, self).dispatch(*args, **kwargs)

You can report it to the bug tracker here:
http://code.djangoproject.com/newticket

Thanks.

-- 
Łukasz Rekucki

-- 
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 CMS 2.1.2 released

2011-02-16 Thread Jonas Obrist
We just released django CMS 2.1.2 to fix a CSRF issue occuring in some 
browser with django CMS 2.1.1.


This release fixes the CSRF issues happening on Ajax requests in older 
Internet Explorers (and according to some reports also other browsers) 
as well as a CSRF issue when adding embbeded plugins to text plugins.


Changes in this version:

- Fixed CMS Ajax requests CSRF protection.

Many thanks to Krzysztof Bandurski, Angelo Dini, Manuel Schmidt and 
kar1m for helping solving us this issue.


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



PDF response using wkhtmltopdf.

2011-02-16 Thread juanefren
I am using wkhtmltopdf to create PDF files, how ever I don't know how
to return them properly, docs says using a single dash instead of
output file name will write that to stdout. But I don't realize how to
return that content.

I have been trying using subprocess.Popen this way:

r = HttpResponse(Popen(command_args), mimetype='application/pdf')
r['Content-Disposition'] = 'filename=my_file_name.pdf'
return r

But I am not getting the result.

The only way I have managed to work is writting to file system in
media folder, and then redirect to the url based file, but this way
doesn't look good.

Thanks in advance.

-- 
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: Class-based views & authentication

2011-02-16 Thread Andre Terra
I should also add that the functionality described in the docs simply did
not work for me:
http://docs.djangoproject.com/en/dev//topics/class-based-views/#decorating-the-class

My attempt to follow that approach is registered here:
http://dpaste.com/hold/423359/


Sincerely,
Andre Terra


On Wed, Feb 16, 2011 at 4:41 PM, Andre Terra  wrote:

> Thank you for sharing that, Pascal. I'm already using it on my project!
>
> I've modified get_login_url to fallback to settings.LOGIN_URL, though.
>
> I'll keep an eye open on the development of this, as CBVs really are great
> to work with.
>
>
> Sincerely,
> Andre Terra
>
>
>
> On Wed, Feb 9, 2011 at 4:06 PM, Pascal Germroth wrote:
>
>> Hi,
>>
>> >> To make things a bit easier, I'm about to write my own mixin for that
>> so
>> >> I only have to provide a method that checks if credentials are OK.
>> >
>> > As you've noticed, you can override the dispatch to decorate the view
>> > as required, and if you have a common authentication pattern, you can
>> > put that logic into a mixin.
>>
>>
>> For future reference, this is what I use now:
>>
>>
>> class LoginMixin(object):
>>  def get_test_func(self):
>>return getattr(self, 'test_func', lambda u: u.is_authenticated())
>>  def get_login_url(self):
>>return getattr(self, 'login_url', None)
>>  def get_redirect_field_name(self):
>>return getattr(self, 'redirect_field_name', None)
>>  def dispatch(self, request, *args, **kwargs):
>>from django.contrib.auth.decorators import user_passes_test
>>return user_passes_test(
>>  self.get_test_func(),
>>  login_url = self.get_login_url(),
>>  redirect_field_name = self.get_redirect_field_name()
>>)(super(LoginMixin, self).dispatch
>>)(request, *args, **kwargs)
>>
>>
>> class DashboardView(LoginMixin, TemplateView):
>>  login_url = '/base/login'
>>  template_name = 'dashboard.html'
>>
>>
>>
>> LoginMixin *must* be the first base class, otherwise it could not
>> override View.dispatch in the other base classes.
>>
>>
>> --
>> Pascal Germroth
>>
>> --
>> 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.
>>
>>
>

-- 
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: Class-based views & authentication

2011-02-16 Thread Andre Terra
Thank you for sharing that, Pascal. I'm already using it on my project!

I've modified get_login_url to fallback to settings.LOGIN_URL, though.

I'll keep an eye open on the development of this, as CBVs really are great
to work with.


Sincerely,
Andre Terra


On Wed, Feb 9, 2011 at 4:06 PM, Pascal Germroth wrote:

> Hi,
>
> >> To make things a bit easier, I'm about to write my own mixin for that so
> >> I only have to provide a method that checks if credentials are OK.
> >
> > As you've noticed, you can override the dispatch to decorate the view
> > as required, and if you have a common authentication pattern, you can
> > put that logic into a mixin.
>
>
> For future reference, this is what I use now:
>
>
> class LoginMixin(object):
>  def get_test_func(self):
>return getattr(self, 'test_func', lambda u: u.is_authenticated())
>  def get_login_url(self):
>return getattr(self, 'login_url', None)
>  def get_redirect_field_name(self):
>return getattr(self, 'redirect_field_name', None)
>  def dispatch(self, request, *args, **kwargs):
>from django.contrib.auth.decorators import user_passes_test
>return user_passes_test(
>  self.get_test_func(),
>  login_url = self.get_login_url(),
>  redirect_field_name = self.get_redirect_field_name()
>)(super(LoginMixin, self).dispatch
>)(request, *args, **kwargs)
>
>
> class DashboardView(LoginMixin, TemplateView):
>  login_url = '/base/login'
>  template_name = 'dashboard.html'
>
>
>
> LoginMixin *must* be the first base class, otherwise it could not
> override View.dispatch in the other base classes.
>
>
> --
> Pascal Germroth
>
> --
> 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.
>
>

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



unique_together validation passes on model forms that exclude unique fields

2011-02-16 Thread Lior Sion
Hi,

I have a model with a unique_together field set. I also have a form
for that model that excludes one field - but I still need the
uniqueness to stay.

Example:

class A(models.Model):
name  = models.CharField(max_length=30)
friend = models.ForeignKey(Friend)

and the form:

class AForm(ModelForm):
class Meta:
model = Event
fields = ('name')

that is, someone editing A can change the name, but they can't get to
a case that one friend have the same A's name.

>From what I gather, the is_valid passes since I excluded friend from
the form, but that's exactly the case I want.. it also makes sense.

Do you agree with opening a ticket? What do you think?

-- 
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.contrib.auth.views.login customization

2011-02-16 Thread Dean Chester
I would write my own login controller using the Authentication and Login 
methods. Check out this part of the django docs: 
http://docs.djangoproject.com/en/1.2/topics/auth/#how-to-log-a-user-in

Dean 
On 16 Feb 2011, at 13:51, galago wrote:

> Is it possible, to add some extra validation checks into 
> django.contrib.auth.views.login?
> I need to check some fields from UserProfile to 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-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.

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



Admin - click through to parent / child

2011-02-16 Thread Alec
Hi,

I'm wondering if there are any add-ons that show a list of children
and give the ability to click through to parent or children records.
I'm aware of the InlineAdmin feature, but I'm thinking of a non-
editable list of children for all relations that automatically (i.e.
no need to edit admin.py for each model) appears below the record you
are currently editing.  For lookup/parent fields, where there is
currently the drop down to select the parent, you would also be able
to click the name to go directly to that parent record.

Any ideas?  Google didn't find me anything yet.

Thanks,
Alec

-- 
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 + WebDAV

2011-02-16 Thread Michael Ryan
I have looked at wsgiDAV as well as a nice looking WebDAV emulator for
Google App Engines, and they will be considered when I go to start
this project.

A big issue with WebDAV from an HTTP framework perspective is that
ideally it should be storage agnostic.

When you start to throw in stuff like "what happens if they want to
store files on S3", then a lot of existing resources out there which
use the Python OS library start to become less useful.

I'm still writing a spec sheet for this project, will probably start
development some time in March.

On Feb 16, 7:16 am, MrMuffin  wrote:
> Have you looked athttp://code.google.com/p/wsgidav/?
>
> Thomas
>
> On 15 Feb, 14:25, Thomas Weholt  wrote:
>
>
>
>
>
>
>
> > Please post any findings on this subject or information about any
> > projects you might start to solve/provide this to this group. This is
> > very interesting. :-)
> > I`ve made a ftpserver which authenticates logins using django user
> > management, but a webdavserver would be even nicer.
>
> > Thomas
>
> > On Tue, Feb 15, 2011 at 5:50 AM, Michael A. Ryan  
> > wrote:
>
> > > Hello Django Users
>
> > > I'm looking for people who have experience interfacing Django with WebDAV 
> > > protocol, or using Django as a basis for authentication to a WebDAV 
> > > server.
>
> > > I'm interested in at least comparing notes but potentially interested in 
> > > maybe co-authoring an open source module for WebDAV.
>
> > > Thanks,
>
> > > Michael
>
> > > --
> > > 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 
> > > athttp://groups.google.com/group/django-users?hl=en.
>
> > --
> > Mvh/Best regards,
> > Thomas Weholthttp://www.weholt.org

-- 
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: Datefield

2011-02-16 Thread william ratcliff
There is a nice stack overflow question on this:
http://stackoverflow.com/questions/38601/using-django-time-date-widgets-in-custom-form


On Wed, Feb 16, 2011 at 10:26 AM, Szabo, Patrick (LNG-VIE) <
patrick.sz...@lexisnexis.at> wrote:

>  Hi,
>
>
>
> I built my own view where users can add new DB-entries.
>
> I have a DateField and generated the Form for it directly from the model
> but i don’t see this calender-icon like i do in the admin panel.
>
> How can I add it ?!
>
>
>
> Is it enough to just reference to the .js in the template !? (doesn’t seem
> to work)
>
>
>
> Kind regards
>
>  . . . . . . . . . . . . . . . . . . . . . . . . . .
>
>  **
>
> Patrick Szabo
> XSLT-Entwickler
>
> LexisNexis
> Marxergasse 25, 1030 Wien
>
> patrick.sz...@lexisnexis.at
>
> Tel.: +43 (1) 534 52 - 1573
>
> Fax: +43 (1) 534 52 - 146
>
>
>
>  --
> 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.
>

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



Datefield

2011-02-16 Thread Szabo, Patrick (LNG-VIE)
Hi, 

 

I built my own view where users can add new DB-entries. 

I have a DateField and generated the Form for it directly from the model
but i don't see this calender-icon like i do in the admin panel. 

How can I add it ?!

 

Is it enough to just reference to the .js in the template !? (doesn't
seem to work)

 

Kind regards


. . . . . . . . . . . . . . . . . . . . . . . . . .
Patrick Szabo
 XSLT-Entwickler 
LexisNexis
Marxergasse 25, 1030 Wien

mailto:patrick.sz...@lexisnexis.at
Tel.: +43 (1) 534 52 - 1573 
Fax: +43 (1) 534 52 - 146 





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



Ajax form in django

2011-02-16 Thread mf
Hi, the problem I'm having is that, when I submit the form, the
response is placed in a new url(/feedback) instead of placing it in
the actual(/results) url. The alert never gets executed.

I guess I'm doing something wrong in the template but I can't find
views.py:
def ajax_feedback(request):
success = False
if request.method == "POST":
post = request.POST.copy()
if post.has_key('rel') and post.has_key('relp'):
rel = post['rel']
relp = post['relp']
q = post['query']
fq = post['full_query']
fq = fq[:350]
ip = request.META['REMOTE_ADDR']
feedback = FeedBack(q=q, ip_address=ip,
user=request.user,
relevance=rel, rel_pages=relp,
full_query=fq)
feedback.save()
success = True
if success == True:
return HttpResponse("Success")
else:
return HttpResponse("Error")
results.html:

   Yes
   No

   1-5 
   6-10
  
  
  


var create_note = function() {
  var rel = $("#rel").val()
  var relp = $("#relp").val()
  var query = {{ query }}
  var full_query = {{ bq }}
   var data = { rel:rel, relp:relp, query:query,
full_query:full_query };
   var args = {
type: "POST",
url: "/feedback/",
data: data,
success: function(msg){
 alert(msg);
}
  $.ajax(args);
  return false;
};
$("#create").click(create_note);

urls.py:
...
(r'^feedback/$', views.ajax_feedback),
(r'^results/(?P.+)/$', views.results),
...

Thank you in advance for your answers,

Mariano.

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



reimport module every n seconds in main process

2011-02-16 Thread Santiago Caracol
Hello,

in a Django application I compile certain data into a Python module
for efficiency reasons. Each time an admin changes or adds objects,
this module also changes. Therefore, I want my main process (the one
that is started with "manage.py runserver" or the like) to reimport
the data module every n (e.g. 10) seconds.

How could this be done?

Santiago

-- 
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: chrome extension

2011-02-16 Thread Piotr Zalewa
On 02/16/11 05:34, Tony Lambropoulos wrote:
> Should I assume that this was a silly question?
> 
> On Mon, Feb 14, 2011 at 10:10 PM, Tony  > wrote:
> 
> Hi,
> Is there any way to have a chrome extension with a backend in Django,
> like for storing data server side and using its views?  Or is this not
> possible?
> thanks

I know nothing about Chrome extensions, but someone has written one for
my jsFiddle. You definitely can send a GET request (which this extension
is doing), I assume you will be able to send POST and receive response,
which would answer your question as a yes.

If the question was about installing Django instance inside Chrome
browser, than the answer is a NO. :)

zalun
-- 
blog  http://piotr.zalewa.info
jobs  http://webdev.zalewa.info
twit  http://twitter.com/zalun
face  http://facebook.com/zaloon

-- 
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: chrome extension

2011-02-16 Thread Derek
> On Mon, Feb 14, 2011 at 10:10 PM, Tony  wrote:
> > Hi,
> > Is there any way to have a chrome extension with a backend in Django,
> > like for storing data server side and using its views?  Or is this not
> > possible?
> > thanks
>
A similar question:
http://stackoverflow.com/questions/3411690/server-side-with-chrome-extensions

-- 
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 select a random tuples from a database table and render them?

2011-02-16 Thread balu
Thank you Shawn...

On Feb 16, 6:46 pm, Shawn Milochik  wrote:
> QuestionBank.objects.filter(id__in = id_list)

-- 
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 custom field or widget?

2011-02-16 Thread Shawn Milochik
Sure. In your ModelForm instance's __init__, set that field's ".choices" 
value.


--
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.contrib.auth.views.login customization

2011-02-16 Thread galago
Is it possible, to add some extra validation checks 
into django.contrib.auth.views.login?
I need to check some fields from UserProfile to 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-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.



Mockup, like Fudge, in unittesting of django when the orm is involved

2011-02-16 Thread MrMuffin
I`m looking into new ways to unittest my django code. The reason for
this is that I find it cumbersome to always have to set up a real
database, allthough using sqlite and :memory: makes it relatively
easy, I was wondering if anybody has done it using mock/fake objects
like Fudge? Writing unittests that involves using the django orm is a
hassle. I`ve included my way of doing this at the bottom and would
like comments on how to improve. Running it like this means it cannot
be automated because the script asks for confirmation about creating a
super-user.

http://farmdev.com/projects/fudge/using-fudge.html#fake-objects-without-patches-dependency-injection

My hackish way of testing when the django orm is used:

import unittest

def configure(appName):
from django.conf import settings, global_settings
_INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.humanize',
appName,
)

the_module = __import__(appName)
settings.configure(default_settings=global_settings,
   INSTALLED_APPS = _INSTALLED_APPS,
   DATABASE_NAME=':memory:',
   DATABASE_ENGINE='sqlite3',
   SETTINGS_MODULE = appName,
   )

from django import db
from django.core.management import call_command
reload(db)
call_command('syncdb')

configure('someapp') # someapp is a package in the python path

from django.conf import settings
from django.test.utils import setup_test_environment,
teardown_test_environment

class testSomeApp(unittest.TestCase):

def setUp(self):
setup_test_environment()

def tearDown(self):
teardown_test_environment()



if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(testSomeApp)
unittest.TextTestRunner(verbosity=2).run(suite)

-- 
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 select a random tuples from a database table and render them?

2011-02-16 Thread Shawn Milochik


QuestionBank.objects.filter(id__in = id_list)

--
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 select a random tuples from a database table and render them?

2011-02-16 Thread balu
Respected all

I'm currently working on building an Online Examination system. In
that there will be a Question Bank which contains hundreds of
questions about different questions. I represented them using Django
model class. From them I have to select 20 questions and render them
as question paper for the user.

For that I wrote a random function to pick up rows uniquely from the
database. Suppose that random function returned the primary key values
293, 333, 444, 642, 534

In "Views" I could able to get reference for first question by using
"questions = QuestionBank.objects.get(id =293)".
How to add other rows having primary key values 333, 444, 642 and 534
to "questions".

-- 
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: Importing modules in code

2011-02-16 Thread Aryeh Leib Taurog
On Feb 16, 12:21 pm, galago  wrote:
> My django runs on FastCGI as I can see.
> I have that small part of the code:
>
> # Generate user register_hash
>                 import hashlib
>                 reg_hash = hashlib.md5()
>                 reg_hash.update(request.POST.get('email') +
> str(random.random()) + request.POST.get('username'))
>                 reg_hash = reg_hash.hexdigest()
>
> Is there any sesne to load hashlib on the top? It's used once, when user is
> created.

In this case I don't think it really matters much.  If you want to be
consistent with Python convention, you should put it at the top.  In a
case where the import is a single function or class, particularly if
it's not a common one and/or used only once in the code, I personally
might see more reason to import it where it's used.  This would allow
the reader to determine more easily where the object is defined
without having to jump around in the code and also provides a pretty
clear indication that the object isn't use elsewhere (assuming, of
course that most imports are made at the top).

-- 
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: form select box how to (help needed)

2011-02-16 Thread Bobby Roberts
i have no idea what this means is there an example anywhere?

On Feb 16, 12:43 am, Kenneth Gonsalves  wrote:
> On Tue, 2011-02-15 at 19:05 -0800, Bobby Roberts wrote:
> > I can't load it through the "CHOICES" parameter in my forms field...
> > how can I do this?
>
> override __init__ in your form and populate there
> --
> regards
> KGhttp://lawgon.livejournal.com
> Coimbatore LUG roxhttp://ilugcbe.techstud.org/

-- 
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: unicode options in models...

2011-02-16 Thread galago
At the top of the file pase:

# -*- coding: utf-8 -*-

In declaration of text that contains utf8 make it in that way:

  help_text = u"dádá español"

 of course set file encoding to utf8 :)

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



unicode options in models...

2011-02-16 Thread Mario

Hi, total noob here.
This is probably me being extremelly stupid at some point, and I
haven't found an answer to this question however i phrased it even tho
it's probably in the documentation somewhere but I just don't
understand it

So I'm writing a django site in spanish and the spanish non-ascii
characters such as accents and Ñ work fine everywhere except in model
options such as verbose_name or help_text. They don't work in field
names either but i can live with that.

so if write
class Test(models.Model):
test = models.CharField(max_length=100, help_text="dádá español")

When i try to syncdb i get this error

SyntaxError: Non-ASCII character '\xc3' in file /Users/Sala4/Documents/
BLUR_WEB/DJANGO/blurweb/../blurweb/website/models.py on line 49, but
no encoding declared; see http://www.python.org/peps/pep-0263.html for
details

I read the site above but didnt understand a thing sorry...I thought
django used utf-8 all over the place and everything should be easy and
rosy as long as the database is in utf-8 too (it is), where am I
wrong?
thanks a lot

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



Full Archive of Tutorial Code?

2011-02-16 Thread cousin isaac
Aloha,

I'd like to see what the final code of the tutorial ought to look like
so am wondering if there is an archive somewhere of the completed
project?

Thanks,

Cousin Isaac

-- 
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: 'str' object is not callable

2011-02-16 Thread Chris Matthews
Hi Patrick,



You can typically get it by:

1)missing the % for a string format:

  x = "Hello number %d" (5)

  TypeError: 'str' object is not callable



2) And if you overwrite a function name with a string, e.g."

>>> min(5,2,3)

2



>>> hour,min,sec = "14:59:03".split(":")

>>> min(5,2,3)

TypeError: 'str' object is not callable



Just check your recent code.



Regards

Chris



-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Szabo, Patrick (LNG-VIE)
Sent: 16 February 2011 14:03
To: django-users@googlegroups.com
Subject: 'str' object is not callable



Hi,



Im getting 'str' object is not callable and i have no idea why.

What I'm doing is the following:



delete



buchung is a list and the 6th element oft hat list is an object with an

attribute id.



In my urls.py i did this:



(r'deletion_time/(?P\d+)/$', 'deletion_time'),



And the view looks like this:



def deletion_time(request, obj_id):

buchung = Buchung.object.filter(id = obj_id)

buchung.delete()

return HttpResponseRedirect('/main/')



Can anyone tell me what's causing this error ?!



Kind regards



. . . . . . . . . . . . . . . . . . . . . . . . . .

Patrick Szabo

 XSLT-Entwickler

LexisNexis

Marxergasse 25, 1030 Wien



mailto:patrick.sz...@lexisnexis.at

Tel.: +43 (1) 534 52 - 1573

Fax: +43 (1) 534 52 - 146











--

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.


-- 
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 + WebDAV

2011-02-16 Thread MrMuffin
Have you looked at http://code.google.com/p/wsgidav/ ?

Thomas

On 15 Feb, 14:25, Thomas Weholt  wrote:
> Please post any findings on this subject or information about any
> projects you might start to solve/provide this to this group. This is
> very interesting. :-)
> I`ve made a ftpserver which authenticates logins using django user
> management, but a webdavserver would be even nicer.
>
> Thomas
>
> On Tue, Feb 15, 2011 at 5:50 AM, Michael A. Ryan  wrote:
>
>
>
>
>
>
>
>
>
> > Hello Django Users
>
> > I'm looking for people who have experience interfacing Django with WebDAV 
> > protocol, or using Django as a basis for authentication to a WebDAV server.
>
> > I'm interested in at least comparing notes but potentially interested in 
> > maybe co-authoring an open source module for WebDAV.
>
> > Thanks,
>
> > Michael
>
> > --
> > 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 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> Mvh/Best regards,
> Thomas Weholthttp://www.weholt.org

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



'str' object is not callable

2011-02-16 Thread Szabo, Patrick (LNG-VIE)
Hi, 

Im getting 'str' object is not callable and i have no idea why. 
What I'm doing is the following:

delete

buchung is a list and the 6th element oft hat list is an object with an
attribute id.

In my urls.py i did this:

(r'deletion_time/(?P\d+)/$', 'deletion_time'),

And the view looks like this:

def deletion_time(request, obj_id):
buchung = Buchung.object.filter(id = obj_id)
buchung.delete()
return HttpResponseRedirect('/main/')

Can anyone tell me what's causing this error ?!

Kind regards

. . . . . . . . . . . . . . . . . . . . . . . . . .
Patrick Szabo
 XSLT-Entwickler 
LexisNexis
Marxergasse 25, 1030 Wien

mailto:patrick.sz...@lexisnexis.at
Tel.: +43 (1) 534 52 - 1573 
Fax: +43 (1) 534 52 - 146 





-- 
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: App engine serving static files?

2011-02-16 Thread Brian Bouterse
I've never used it, but I always wanted to use
DryDropto push all my static media over
to GAE.

Brian

On Wed, Feb 16, 2011 at 2:44 AM, Praveen Krishna R <
rpraveenkris...@gmail.com> wrote:

> *Hey Guys,*
> *
> *
> *Does Anyone has experience, serving static content with google app
> engine?*
> *Does it make a big difference, than serving it with nginx on the same
> server as django?*
> *I currently use a shared hosting, and was just thinking to move the
> static content to GAE*
> *I would like to know your thoughts on this*
> *
> *
> --
> Thanks and Regards,
> *Praveen Krishna R*
>
>  --
> 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.
>



-- 
Brian Bouterse
ITng Services

-- 
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: pymssql: Problem with Unicode string

2011-02-16 Thread Ramiro Morales
On Wed, Feb 16, 2011 at 8:46 AM, Orgil  wrote:
> Hello.
> I can not get unicode string from MSSQL.
> I have pymssql-1.0.2, freetds-0.82, ubuntu-10.10.

It seems you have sent this message to the wrong mailing list.

-- 
Ramiro Morales

-- 
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: Importing modules in code

2011-02-16 Thread galago
My django runs on FastCGI as I can see.
I have that small part of the code:

# Generate user register_hash
import hashlib
reg_hash = hashlib.md5()
reg_hash.update(request.POST.get('email') + 
str(random.random()) + request.POST.get('username'))
reg_hash = reg_hash.hexdigest()


Is there any sesne to load hashlib on the top? It's used once, when user is 
created. 

-- 
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: Importing modules in code

2011-02-16 Thread Daniel Roseman
On Wednesday, February 16, 2011 8:38:40 AM UTC, galago wrote:
>
> Is it a good idea to import modules in the middle of the code, and not on 
> the beginning?
> I want to make a hash generation. It's few lines - it's used once in all 
> application. Should I import hashlib just on the beginning of the file? Now 
> I put it with the rest of the code.
> Is it bad?
>
> I don't want to import it with all requests in my app view.
>

Your question betrays a misconception that I often see. Django - at least 
when served other than via CGI - does not reload everything for each 
request. The Django process is long-running, and is managed by the server, 
but usually runs for a number of requests before being respawned. So given 
that once you've imported something it stays available for the lifetime of 
the process, it makes very little difference where you do it.

IMO the only reason not to import modules at the top of the file is to avoid 
circular dependencies.
--
DR.

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



Re: chrome extension

2011-02-16 Thread Daniel Roseman
On Wednesday, February 16, 2011 5:34:42 AM UTC, Tony wrote:
>
> Should I assume that this was a silly question?
>
>
No, just that no-one who knows the answer has been around since you posted 
it.

I've never written a Chrome extension but I suspect they have no network 
access and can only store data locally, via the LocalStorage api.
--
DR.

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



Re: how to get attribute of intermediary model?

2011-02-16 Thread Daniel Roseman
On Wednesday, February 16, 2011 12:36:49 AM UTC, Margie Roginski wrote:
>
> Say I am using an intermediary model like that in the doc: 
>
> class Person(models.Model): 
> name = models.CharField(max_length=128) 
>
> class Group(models.Model): 
> name = models.CharField(max_length=128) 
> members = models.ManyToManyField(Person, through='Membership') 
>
> class Membership(models.Model): 
> person = models.ForeignKey(Person) 
> group = models.ForeignKey(Group) 
> date_joined = models.DateField() 
>
> For a given group, say I want to go through the persons in the group 
> and print the date each joined the group. 
>
> beatles = Group.objects.get(name="beatles") 
> for person in group.members.all(): 
># get join date for person 
>
> What's the best way to do this?  It seems to me that I have to add a 
> related_name to the person field of Membership like this: 
>
> person = models.ForeignKey(Person, related_name="memberships") 
>
> and then traverse backward from the person back to the membership, 
> filtering to find the correct membership based on the group name.  Can 
> someone tell me if there is a better way?  So I'm thinking I have to 
> do this: 
>
> beatles = Group.objects.get(name="beatles") 
> for person in group.members.all(): 
>   joinDate = person.memberships.filter(group_name="beatles") 
> [0].date_joined 
>
> Thanks for any pointers, 
>
> Margie


It's easier than that. You can get all memberships for a group in one go:

memberships = 
Membership.objects.filter(group__name="beatles").select_related()
for m in memberships:
print m.person.name, m.date_joined

--
DR.

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



RE: Importing modules in code

2011-02-16 Thread Chris Matthews
Hi Galago,

For some conventions see 
http://docs.djangoproject.com/en/dev/internals/contributing/?from=olddocs#django-conventions
and http://www.python.org/dev/peps/pep-0008/

Generally I do imports at the top of the module in this order (with a blank 
line inbetween):

1.   python modules

2.   django modules

3.   3rd party modules

4.   Your project/application modules

Regards
Chris

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of galago
Sent: 16 February 2011 10:39
To: django-users@googlegroups.com
Subject: Importing modules in code

Is it a good idea to import modules in the middle of the code, and not on the 
beginning?
I want to make a hash generation. It's few lines - it's used once in all 
application. Should I import hashlib just on the beginning of the file? Now I 
put it with the rest of the code.
Is it bad?

I don't want to import it with all requests in my app view.
--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
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-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: pymssql: Problem with Unicode string

2011-02-16 Thread Adnan Sadzak
You did not install static libs and headers

Try this:
aptitude install freetds-bin freetds-common freetds-dev

or just freetds-dev.

Cheers



On Wed, Feb 16, 2011 at 9:46 AM, Orgil  wrote:
> Hello.
> I can not get unicode string from MSSQL.
> I have pymssql-1.0.2, freetds-0.82, ubuntu-10.10.
> I have two computers.
> First is well configured and good working (i did not configured). From
> that computer, I can read the unicode.
> Now i am trying to set up connection to mssql and reading unicode
> string on second computer. I am trying to install and configure
> freetds like first computer. But I can not do this.
>
> When I run "$ locate freetds" from terminal on first computer (which
> is good working one), the result is:
> 
> /etc/freetds
> /etc/freetds/freetds.conf
> /usr/local/freetds
> /usr/local/etc/freetds.conf
> /usr/local/freetds/bin
> /usr/local/freetds/etc
> /usr/local/freetds/include
> /usr/local/freetds/lib
> /usr/local/freetds/man
> /usr/local/freetds/share
> /usr/local/freetds/bin/bsqldb
> /usr/local/freetds/bin/bsqlodbc
> /usr/local/freetds/bin/datacopy
> /usr/local/freetds/bin/defncopy
> /usr/local/freetds/bin/fisql
> /usr/local/freetds/bin/freebcp
> /usr/local/freetds/bin/osql
> /usr/local/freetds/bin/tdspool
> /usr/local/freetds/bin/tsql
> /usr/local/freetds/etc/freetds.conf
> /usr/local/freetds/etc/locales.conf
> /usr/local/freetds/etc/pool.conf
> /usr/local/freetds/include/bkpublic.h
> /usr/local/freetds/include/cspublic.h
> /usr/local/freetds/include/cstypes.h
> /usr/local/freetds/include/ctpublic.h
> /usr/local/freetds/include/sqldb.h
> /usr/local/freetds/include/sqlfront.h
> /usr/local/freetds/include/sybdb.h
> /usr/local/freetds/include/syberror.h
> /usr/local/freetds/include/sybfront.h
> /usr/local/freetds/include/tds_sysdep_public.h
> /usr/local/freetds/lib/libct.a
> /usr/local/freetds/lib/libct.la
> /usr/local/freetds/lib/libct.so
> /usr/local/freetds/lib/libct.so.4
> /usr/local/freetds/lib/libct.so.4.0.0
> /usr/local/freetds/lib/libsybdb.a
> /usr/local/freetds/lib/libsybdb.la
> /usr/local/freetds/lib/libsybdb.so
> /usr/local/freetds/lib/libsybdb.so.5
> /usr/local/freetds/lib/libsybdb.so.5.0.0
> /usr/local/freetds/lib/libtdsodbc.a
> /usr/local/freetds/lib/libtdsodbc.la
> /usr/local/freetds/lib/libtdsodbc.so
> /usr/local/freetds/lib/libtdsodbc.so.0
> /usr/local/freetds/lib/libtdsodbc.so.0.0.0
> /usr/local/freetds/man/man1
> /usr/local/freetds/man/man5
> /usr/local/freetds/man/man1/bsqldb.1
> /usr/local/freetds/man/man1/bsqlodbc.1
> /usr/local/freetds/man/man1/datacopy.1
> /usr/local/freetds/man/man1/defncopy.1
> /usr/local/freetds/man/man1/fisql.1
> /usr/local/freetds/man/man1/freebcp.1
> /usr/local/freetds/man/man1/osql.1
> /usr/local/freetds/man/man1/tsql.1
> /usr/local/freetds/man/man5/freetds.conf.5
> /usr/local/share/man/man5/freetds.conf.5
> /var/cache/apt/archives/freetds-common_0.82-6build1_all.deb
> /var/cache/apt/archives/freetds-dev_0.82-6build1_i386.deb
> /var/lib/dpkg/info/freetds-common.list
> /var/lib/dpkg/info/freetds-common.postrm
> /var/tmp/freetds.conf.swp
> --
>
> And when I do the same run second computer, result is:
> --
> /etc/freetds
> /etc/freetds.conf
> /etc/freetds/freetds.conf
> /home/usi/Downloads/freetds-stable.tgz
> /usr/local/etc/freetds.conf
> /usr/local/etc/freetds.conf.save
> /usr/local/share/man/man5/freetds.conf.5
> /usr/man/man5/freetds.conf.5
> /usr/share/freetds
> /usr/share/doc/freetds-common
> /usr/share/doc/freetds-dev
> /usr/share/doc/freetds-common/NEWS.gz
> /usr/share/doc/freetds-common/README
> /usr/share/doc/freetds-common/README.Debian
> /usr/share/doc/freetds-common/TODO.Debian
> /usr/share/doc/freetds-common/TODO.gz
> /usr/share/doc/freetds-common/changelog.Debian.gz
> /usr/share/doc/freetds-common/changelog.gz
> /usr/share/doc/freetds-common/copyright
> /usr/share/doc/freetds-common/examples
> /usr/share/doc/freetds-common/examples/freetds.conf
> /usr/share/doc/freetds-common/examples/freetds.conf.pl
> /usr/share/doc/freetds-common/examples/locales.conf
> /usr/share/doc/freetds-common/examples/odbcinst.ini
> /usr/share/doc/freetds-dev/changelog.Debian.gz
> /usr/share/doc/freetds-dev/changelog.gz
> /usr/share/doc/freetds-dev/copyright
> /usr/share/freetds/freetds.conf
> /usr/share/man/man5/freetds.conf.5.gz
> /var/cache/apt/archives/freetds-bin_0.82-7_i386.deb
> /var/cache/apt/archives/freetds-common_0.82-7_all.deb
> /var/cache/apt/archives/freetds-dev_0.82-7_i386.deb
> /var/lib/dpkg/info/freetds-common.list
> /var/lib/dpkg/info/freetds-common.md5sums
> /var/lib/dpkg/info/freetds-common.postinst
> /var/lib/dpkg/info/freetds-common.postrm
> /var/lib/dpkg/info/freetds-dev.list
> /var/lib/dpkg/info/freetds-dev.md5sums
> /var/lib/dpkg/info/freetds-dev.preinst
> -
>
> As the results, there is so huge difference between two computers.
> I can not install freetds as installed as on first 

Few words about serialization roboustness and django app served via fcgi and nginx connected over unix or tcp socket

2011-02-16 Thread gro...@sq9mev.info
Hi there ;).
Yesterday i noticed some strange behaviour of one of my sites - view [1]
serving json serialized data (one model, no references, 130 objects) was
executed about 20 secs[3] in production environment [2], and less than
1s via development server. Strange thing. What I've found - the view
served in production makes lots of writes(), and due to that - lots of
context switching. Every single json syntax character was put in
subsequent write. Serialized response was returned to client in portions
of n*1024B during this 20 sesc. Not too roboust.
Next thing to mention is that my production env uses tcp socket to
communication between frontend and django app - as [3] shows - that's
the worst scenario with view [1]. I've changed my view to write
serialized data to buffer before returning the response [4] - execution
time decreases dramatically, about 40 times. It's not due tu QoS - test
were made locally.

Further investigation i've made shows, that using tcp socket to
communication between nginx and django app improoves execution time as
well, but not so dramatically as using buffer - nevermind if with tcp or
unix socket.
I've experienced this behaviour as well with flup or with native django
runffcgi.
Writing directly to response [1] while using tcp socket is less
expensive (but not optimal) probably because of OS network buffers, am I
right?

What's the cause? Maybe ducktyping used somewhere in django code? Had no
time to find this issue, or maybe feature ;>. Anyway - mayby it's worth
to mention about that in django docs - these ar awsome for me in general
;). Is the [4] method optimal? Any ideas/hints?

My virtual environment is described in [5].
Any feedback will be appreciated ;)


[1]
def incidents_json(request):
i=Incident.objects.filter(public=True)
json_serializer = serializers.get_serializer("json")()
response=HttpResponse(mimetype='application/json')
json_serializer.serialize(i, ensure_ascii=False, stream=response,
fields=('date', 'slug', 'created', 'location','title'))
return response


[2] Production environment: django 1.2.5, python 2.7, virtualenv, flup,
nginx, supervosord

[3] execution times:
[bociek@webserver ~]$ time lynx --dump
http://www.mysite.tld/incydenty/json/ > /dev/null # serializing to
buffer, fcgi over unix socket

real0m0.485s

user0m0.017s
sys 0m0.120s

[bociek@webserver ~]$ time lynx --dump
http://www.mysite.tld/incydenty/json-dt/ > /dev/null # serializing to
response, fcgi over unix socket

real0m22.292s
^
user0m0.037s
sys 0m0.100s

[bociek@webserver ~]$ time lynx --dump
http://www.fcgi.mysite.tld/incydenty/json/ > /dev/null # serializing to
buffer, fcgi over tcp socket

real0m0.513s

user0m0.023s
sys 0m0.110s

[bociek@webserver ~]$ time lynx --dump
http://www.fcgi.mysite.tld/incydenty/json-dt/ > /dev/null # serializing
to response, fcgi over tcp socket

real0m1.224s

user0m0.033s
sys 0m0.113s

[4]
def incidents_json2(request):
i=Incident.objects.filter(public=True)
from django.core import serializers
data = serializers.serialize("json",i, ensure_ascii=False,
fields=('date', 'slug', 'created', 'location','title'))
return HttpResponse(content=data, mimetype='application/json')

[5]
BeautifulSoup==3.2.0
Django==1.2.5
Markdown==2.0.3
PIL==1.1.7
Whoosh==1.7.1
django-authopenid==1.0.1
django-extensions==0.6
django-haystack==1.1.0
django-photologue==2.3
django-registration==0.7
django-tinymce==1.5.1a1
facebook-python-sdk==0.1
## FIXME: could not find svn URL in dependency_links for this package:
flup==1.0.3.dev-20110111
httplib2==0.6.0
oauth2==1.5.165
psycopg2==2.4-beta2
pyenchant==1.6.5
pyproj==1.8.8
python-openid==2.2.5
simplejson==2.1.3
wsgiref==0.1.2
xmpppy==0.5.0rc1

[5.1] communicating over tcp socket:
location / {
fastcgi_pass 127.0.0.1:9002;
include /etc/nginx/fcgi_django.params;
}

[5.2] and over unix socket:
location / {
fastcgi_pass unix:/tmp/sq.sock;
include /etc/nginx/fcgi_django.params;
}

fcgi_django.params:
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param REQUEST_METHOD$request_method;
fastcgi_param QUERY_STRING  $query_string;
fastcgi_param CONTENT_TYPE  $content_type;
fastcgi_param CONTENT_LENGTH$content_length;
fastcgi_param REMOTE_ADDR   $remote_addr;
fastcgi_param REMOTE_PORT   $remote_port;
fastcgi_param SERVER_ADDR   $server_addr;
fastcgi_param SERVER_PORT   $server_port;
fastcgi_param SERVER_NAME   $http_host;
fastcgi_param SERVER_PROTOCOL   $server_protocol;
fastcgi_pass_header Authorization;
fastcgi_intercept_errors off;



-- 
Cheers
Bartek

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

Django custom field or widget?

2011-02-16 Thread ju
I have an integer fields, but their default widget is TextInput. I
want to use Select widget, but I have to explicitly provide possible
values.

Is it possible they to be automatically generated from 'initial',
'min_value' and 'max_value' validation rules of integer! field?

Do I have to make my own field, widget, or both? And how?

P.S. Also here 
http://stackoverflow.com/questions/5014687/django-custom-field-or-widget

-- 
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 Templates: Form field name as variable?

2011-02-16 Thread ju
> I like it too, but aren't you still stuck with validating it or are you
> applying a validator to each field you generate this way?

I'm not sure that I understand the question but this is how I create
new fields

self.fields['ticket_%s' % ticket['id']] = forms.IntegerField(label =
'', initial = 0, min_value = 0, max_value = self._max_tickets_count)

and there are validation rules - integer value from 0 to
_max_tickets_count

On Feb 15, 9:24 pm, Mike Ramirez  wrote:
> On Tuesday, February 15, 2011 01:31:07 am ju wrote:
>
> > Thank you very much for you answer
>
> > I prefer to use validation that form class provides for me...
>
> I do too.
>
> > I tried to use  but
> > the other problem that I have is that I can't get errors for each
> > field of form :(
> > .  
> > There is another solution that I decide to use:
> >http://stackoverflow.com/questions/4993625/django-templates-form-fiel...
> > -as-variable
>
> I like it too, but aren't you still stuck with validating it or are you
> applying a validator to each field you generate this way?
>
> Mike
> --
> A physicist is an atom's way of knowing about atoms.
>                 -- George Wald

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



UserCreationForm extended fields

2011-02-16 Thread galago
Hi,
I'm building register form using UserCreationForm.
I have simple form:

class RegisterCustomerForm(UserCreationForm):
def __init__(self, *args, **kwargs):
super(RegisterCustomerForm, self).__init__(*args, **kwargs)
self.fields['email'].required = True
self.fields['email'].label = _(u'Email')
self.fields['username'].label = _(u'Login')
self.fields['first_name'].required = True
self.fields['last_name'].required = True
required_css_class = 'required'
error_css_class = 'error'
address = forms.CharField(max_length=255, min_length=10, required=True)
telephone = forms.CharField(max_length=30, required=True)
class Meta():
model = User
fields = ('email','first_name','last_name',)



Now I want to make a custom validation of email field.
I want to make it by function def clean_field

How can I get access to email field?
 

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



pymssql: Problem with Unicode string

2011-02-16 Thread Orgil
Hello.
I can not get unicode string from MSSQL.
I have pymssql-1.0.2, freetds-0.82, ubuntu-10.10.
I have two computers.
First is well configured and good working (i did not configured). From
that computer, I can read the unicode.
Now i am trying to set up connection to mssql and reading unicode
string on second computer. I am trying to install and configure
freetds like first computer. But I can not do this.

When I run "$ locate freetds" from terminal on first computer (which
is good working one), the result is:

/etc/freetds
/etc/freetds/freetds.conf
/usr/local/freetds
/usr/local/etc/freetds.conf
/usr/local/freetds/bin
/usr/local/freetds/etc
/usr/local/freetds/include
/usr/local/freetds/lib
/usr/local/freetds/man
/usr/local/freetds/share
/usr/local/freetds/bin/bsqldb
/usr/local/freetds/bin/bsqlodbc
/usr/local/freetds/bin/datacopy
/usr/local/freetds/bin/defncopy
/usr/local/freetds/bin/fisql
/usr/local/freetds/bin/freebcp
/usr/local/freetds/bin/osql
/usr/local/freetds/bin/tdspool
/usr/local/freetds/bin/tsql
/usr/local/freetds/etc/freetds.conf
/usr/local/freetds/etc/locales.conf
/usr/local/freetds/etc/pool.conf
/usr/local/freetds/include/bkpublic.h
/usr/local/freetds/include/cspublic.h
/usr/local/freetds/include/cstypes.h
/usr/local/freetds/include/ctpublic.h
/usr/local/freetds/include/sqldb.h
/usr/local/freetds/include/sqlfront.h
/usr/local/freetds/include/sybdb.h
/usr/local/freetds/include/syberror.h
/usr/local/freetds/include/sybfront.h
/usr/local/freetds/include/tds_sysdep_public.h
/usr/local/freetds/lib/libct.a
/usr/local/freetds/lib/libct.la
/usr/local/freetds/lib/libct.so
/usr/local/freetds/lib/libct.so.4
/usr/local/freetds/lib/libct.so.4.0.0
/usr/local/freetds/lib/libsybdb.a
/usr/local/freetds/lib/libsybdb.la
/usr/local/freetds/lib/libsybdb.so
/usr/local/freetds/lib/libsybdb.so.5
/usr/local/freetds/lib/libsybdb.so.5.0.0
/usr/local/freetds/lib/libtdsodbc.a
/usr/local/freetds/lib/libtdsodbc.la
/usr/local/freetds/lib/libtdsodbc.so
/usr/local/freetds/lib/libtdsodbc.so.0
/usr/local/freetds/lib/libtdsodbc.so.0.0.0
/usr/local/freetds/man/man1
/usr/local/freetds/man/man5
/usr/local/freetds/man/man1/bsqldb.1
/usr/local/freetds/man/man1/bsqlodbc.1
/usr/local/freetds/man/man1/datacopy.1
/usr/local/freetds/man/man1/defncopy.1
/usr/local/freetds/man/man1/fisql.1
/usr/local/freetds/man/man1/freebcp.1
/usr/local/freetds/man/man1/osql.1
/usr/local/freetds/man/man1/tsql.1
/usr/local/freetds/man/man5/freetds.conf.5
/usr/local/share/man/man5/freetds.conf.5
/var/cache/apt/archives/freetds-common_0.82-6build1_all.deb
/var/cache/apt/archives/freetds-dev_0.82-6build1_i386.deb
/var/lib/dpkg/info/freetds-common.list
/var/lib/dpkg/info/freetds-common.postrm
/var/tmp/freetds.conf.swp
--

And when I do the same run second computer, result is:
--
/etc/freetds
/etc/freetds.conf
/etc/freetds/freetds.conf
/home/usi/Downloads/freetds-stable.tgz
/usr/local/etc/freetds.conf
/usr/local/etc/freetds.conf.save
/usr/local/share/man/man5/freetds.conf.5
/usr/man/man5/freetds.conf.5
/usr/share/freetds
/usr/share/doc/freetds-common
/usr/share/doc/freetds-dev
/usr/share/doc/freetds-common/NEWS.gz
/usr/share/doc/freetds-common/README
/usr/share/doc/freetds-common/README.Debian
/usr/share/doc/freetds-common/TODO.Debian
/usr/share/doc/freetds-common/TODO.gz
/usr/share/doc/freetds-common/changelog.Debian.gz
/usr/share/doc/freetds-common/changelog.gz
/usr/share/doc/freetds-common/copyright
/usr/share/doc/freetds-common/examples
/usr/share/doc/freetds-common/examples/freetds.conf
/usr/share/doc/freetds-common/examples/freetds.conf.pl
/usr/share/doc/freetds-common/examples/locales.conf
/usr/share/doc/freetds-common/examples/odbcinst.ini
/usr/share/doc/freetds-dev/changelog.Debian.gz
/usr/share/doc/freetds-dev/changelog.gz
/usr/share/doc/freetds-dev/copyright
/usr/share/freetds/freetds.conf
/usr/share/man/man5/freetds.conf.5.gz
/var/cache/apt/archives/freetds-bin_0.82-7_i386.deb
/var/cache/apt/archives/freetds-common_0.82-7_all.deb
/var/cache/apt/archives/freetds-dev_0.82-7_i386.deb
/var/lib/dpkg/info/freetds-common.list
/var/lib/dpkg/info/freetds-common.md5sums
/var/lib/dpkg/info/freetds-common.postinst
/var/lib/dpkg/info/freetds-common.postrm
/var/lib/dpkg/info/freetds-dev.list
/var/lib/dpkg/info/freetds-dev.md5sums
/var/lib/dpkg/info/freetds-dev.preinst
-

As the results, there is so huge difference between two computers.
I can not install freetds as installed as on first computer!

How to install freetds as installed as on first computer?

Regards,
Orgil

-- 
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: ID of each request

2011-02-16 Thread Masklinn
On 15 févr. 2011, at 17:58, Bzyczek  wrote:
>> I am not aware of anything, but you can easily make a piece of middleware
>> which generated a UUID then exposed this in the request object :)
> 
> Yes I could, but then I must provide to all parts of my code request
> object. I don't know how to build something like "global variable",
> which will be safe regardless on server configuration (many
> procesesses/threads of my app).
Thread local set to an uuid4 by a middleware?

That should work as long as you know django will not multiplex requests within 
a given thread (a guarantee I can't give you, but as far as I know django does 
not use coroutines or tasklets)

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



Importing modules in code

2011-02-16 Thread galago
Is it a good idea to import modules in the middle of the code, and not on 
the beginning?
I want to make a hash generation. It's few lines - it's used once in all 
application. Should I import hashlib just on the beginning of the file? Now 
I put it with the rest of the code.
Is it bad?

I don't want to import it with all requests in my app view.

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



Re: Dajaxice Unresolved Import

2011-02-16 Thread Jorge Bastida
>
> Does anyone know if it matters what version I install of these
> packages?
> (I'm using version 2.6.6 of python and 1.2.3-1ubuntu0.2.10.10.1 of
> python-django.)


Hi,
Probably the problem is that you are using an old django-dajaxice version.
0.1.5 had some bugs related to the function registration that were fixed in
0.1.6
Try to upgrade it to a newer version (0.1.8)
https://github.com/jorgebastida/django-dajaxice/downloads

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.