Django job opportunity in Bordeaux, France

2016-01-12 Thread bruno desthuilliers
We're looking for a Python / Django dev : 
http://emploi.alsacreations.com/offre-565470-Developpeur-django-python.html


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ed27fc12-ca66-4be7-bec2-c09ea764d0a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Insert variable into RequestContext?

2013-05-06 Thread bruno desthuilliers
Looks like you want a context_processor : 
https://docs.djangoproject.com/en/1.5/ref/templates/api/#subclassing-context-requestcontext

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




Re: configure url

2012-11-15 Thread bruno desthuilliers
On Thursday, November 15, 2012 7:25:28 AM UTC+1, rh wrote:
>
> All the tutorials I looked at didn't explain (?P\w+) and it seems 
> that the 
> tutorials say things like "it's a regular expression, go read python docs 
> for more". 
> Maybe regexs are consider ugly plumbing stuff unsuitable for tutorials. 
>


Django is a framework, and the django documentation documents the framework 
- not the underlying language, which already has it's own doc AND a 
tutorial :

http://docs.python.org/2.7/library/re.html#module-re
http://docs.python.org/2.7/howto/regex.html#regex-howto




-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/9E38bsyWW1wJ.
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 mod-wsgi multiple instances of One Class object

2012-11-06 Thread bruno desthuilliers
On Monday, November 5, 2012 7:07:23 PM UTC+1, drunksaint wrote:
 

> This model was running perfectly in the DEV deployement. When I moved to 
> PROD in apache, this broke (as in there are multiple instances of scObj 
> being created, so a score update from player-1's move on player-2 is not 
> reflected in a different move by player-3 on player-2) . I need to simulate 
> a singleton class behaviour / global scObj behaviour, which I am not able 
> to do.
>

In web applications, shared state is usually implemented using a database 
of some sort (relational or not). 

 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/IG-ttb666DMJ.
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: Design decision

2012-11-06 Thread bruno desthuilliers
On Tuesday, November 6, 2012 3:13:40 PM UTC+1, rdollinger wrote:
>
> Hi,
>
> I'm starting a new project, that is composed with various modules 
> (application). This project will sold to costumers (ca. 100) with different 
> configurations (modules, language, ...). My intention is to have models, 
> urls, views, templates globally for all costumers. Costumer specific are 
> obviously the settings, some static files and the content. But there is 
> also some master data, that should be globally for all costumers.
>
> So my question, how can I handle this requirements? Is better have 
> separated django projects (instance) for each costumer and sync the global 
> master data between the costumers? Or one django project (instance) for all 
> costumers with one big database?
>
>

There's no one-size-fits-all answer, depends on how the "project" is to be 
sold and what it does. Given your description (per-customer settings / 
installed apps / static files etc) it looks like the first solution (one 
instance per customer) might be a better solution, with possibly a 
per-customer database for contents and a shared database for "master data" 
(django can use more than one db at once).

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Ryi_NtgZ8bkJ.
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 Admin doesn't show all fields from model when registered.

2012-08-18 Thread bruno desthuilliers


Le jeudi 16 août 2012 21:00:56 UTC+2, Tundebabzy a écrit :
>
> Ok I fixed it and in case someone else falls into such a trap, here's 
> how I fixed it. 
>
> My Answer model had a field with name 'is_correct' and had a method 
> with name 'is_correct'.
>


Everything in Python is an object, including functions, classes, modules 
etc. In a class statement's body, if you first bind name "is_correct" to 
something (here a field but it could have been anything) then to something 
else (here a function but it could have been anything too), then the second 
binding will replace the first one. 

 

I think django should be able to detect such things and raise an error 
>

"Django" (that is, in this case, django models metaclass) doesn't even know 
about this - all it gets is the namespace (ie: a dict) obtained by 
evaluating the class statement's body. This is how Python work, and 
expecting something else just means that you assume it works like some 
other language you already know (bad luck: no two languages work the same).
 

> or there should be a note in the documentation warning people not to 
> name their model methods with model field names. 
>
>
Why should Django documents Python features ? Python is already (and quite 
extensively) documented on it's own : http://docs.python.org/



 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/fspuOAnnWwIJ.
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 TypeError

2012-07-23 Thread bruno desthuilliers
On Tuesday, July 17, 2012 8:00:39 AM UTC+2, sandy wrote:
>
> I want to have different views for my application for different types 
> of users. For this I have this code for my views.py file : 
>
> def index1(request): 
> u = User.objects.all() 
>

This has been solved.
 

> if u.is_staff ==1 and u.is_active == 1 and u.is_superuser == 1: 
>


User.is_staff, User.is_active and User.is_superuser already have a boolean 
value, so you don't need to test against 1 (or True etc).

if u.is_staff  and u.is_active and u.is_superuser : 


 

> return render_to_response('tcc11_12/index1.html', 
> context_instance=RequestContext(request)) 
> elif u.is_staff == 1 and u.is_active == 1 and u.is_superuser == 0: 
>


You only have one different predicate here, so you could factor your tests:


 if u.is_staff  and u.is_active:
 if u.is_superuser : 
 return render_to_response('tcc11_12/index1.html', 
context_instance=RequestContext(request))
 else:
 return render_to_response('tcc11_12/index2.html', 
context_instance=RequestContext(request)) 
 else: 
 return 
render_to_response('index3.html',context_instance=RequestContext(request)) 


Note that if only the template change, you could avoid multiple returns too:
 
 template = 'index3.html' # default
 if u.is_staff  and u.is_active:
 template = 'tcc11_12/index1.html' if u.is_superuser else  
'tcc11_12/index2.html'
 
 return 
render_to_response(template,context_instance=RequestContext(request)) 


Also, if you're using request.user as the user *and the default 
authentication backend and auth form*, only "active" users should be able 
to log in, so your test on 'is_active' _may_ (or not !) be just useless:

https://docs.djangoproject.com/en/1.3/topics/auth/#django.contrib.auth.models.User.is_active

HTH

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



Re: Problem to complète the xml template

2012-07-05 Thread bruno desthuilliers
On Wednesday, July 4, 2012 8:12:50 PM UTC+2, nef wrote:
>
> Hello,
>

Bonjour 
 

> I want to cry a function allowing me to complete a template *. Xml. May I 
> have a problem with the passage of the object render_to_response. In short 
> here is my code. In fact, I do not know how to return an object that can 
> permattre me to complete my template automatically.
> I am using django 1.1 and Python 2.6
> Function writes to the file views.py
>
> def main_formation(request, formation_id):
> formations = Formation.objects.get(id=formation_id)
>

You name your variable "formations" (plural) but your query returns a 
single Formation instance. 
 

> variables = RequestContext(request, {
> 'formations': formations
> })
> return render_to_response('saisie/formation.xml', variables)
>
> This is mu xml template
>
> (snip headers)
>
 

>   {% if formations %}
>
> 
>  
>
{{ formation.ville }}
>

You named the variable "formations" (plural) but you're trying to access an 
indexistant "formation" (singular) object. This will eval to the 
settings.TEMPLATE_STRING_IF_INVALID value, which by default is an empty 
string. For developpment, it might help to set TEMPLATE_STRING_IF_INVALID 
to a more obvious value (I personnaly use "XXX:INVALID").
 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/QOUNvX6jcz8J.
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: have an object available in every templates

2012-06-29 Thread bruno desthuilliers


On Thursday, June 28, 2012 5:53:46 PM UTC+2, Bastian wrote:
>
> Well, I was curious to see if it worked with a context processor so I 
> tried and indeed it works. After all it's only returning an object or list 
> of objects in a dictionary. Now I don't know which method is the most 
> efficient.
>


The context_processor will be called for each and every RequestContext (so 
for each and every view AND templatetag creating a RequestContext), so 
better to avoid anything "intensive" here. 

Also, it won't have access to the existing context - which may or not be a 
problem, but for something "my favorite books" (which really means : "the 
favorité books of request.user"), you can bet one day or another you will 
want to show "the favorite books of _another_ user", and this is something 
that won't work with a context processor.

To make a long story short : use a custom template tag that will take the 
user as an argument. 

My 2 cents...

 

>
> On Thursday, June 28, 2012 2:11:37 PM UTC+2, Bastian wrote:
>>
>> Hi,
>>
>> I don't know if this is possible or how to do it. I would like to write a 
>> sort of context processor where I pass an object to the template. I have 
>> always passed strings to these variables. Let's say I have a Book model and 
>> in a view I list the latest books I've added to the database. In the 
>> corresponding template I will then have an objects list with these objects. 
>> But I also want to be able to call a variable containing another list of 
>> objects, say my favorite books, without having to pass it explicitly from 
>> the view and being able to call it from any template.
>> Can I do it with context processors, or anything else actually?
>>
>> Thanks.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/6qFgwqrD--wJ.
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: interpretting urls

2012-06-28 Thread bruno desthuilliers
On Wednesday, June 27, 2012 11:53:56 PM UTC+2, Sam007 wrote:
>
>
> Going thru the doc link you gave, I did not understand the term middleware 
> request processing?
>
> but if the incoming HttpRequest object has an attribute called urlconf (set 
> by middleware *request 
> processing*),
>  
> its value will be used in place of the 
> ROOT_URLCONF
>  setting.
>
>
>
It's also in the FineManual. If you look at the doc's home page, you'll 
find a very explicit reference to middlewares : 

https://docs.djangoproject.com/en/dev/#the-view-layer

Should I mention that there's a "search" feature in the doc too ?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/KQ6qET4bU4UJ.
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: interpretting urls

2012-06-27 Thread bruno desthuilliers


On Tuesday, June 26, 2012 6:52:06 PM UTC+2, Sam007 wrote:
>
> Hi,
>
> I am bit confused about what exactly do these urls imply in the url.py
>
>
This is all documented here : 
https://docs.djangoproject.com/en/dev/topics/http/urls/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Zo3bjY0ZFvgJ.
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: ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.

2012-06-26 Thread bruno desthuilliers
Désolé, je ne parle pas espagnol...

On Monday, June 25, 2012 7:49:01 AM UTC+2, totechess wrote:
>
> Tengo el siguiente problema. Con la última actualización de django 1.5 
> supongamos estoy en un directorio x y al hacer django-admin 
> startproject miProyecto me genera la carpeta miProyecto con la 
> siguiente estructura 
>
> manage.py 
> miProyecto/ 
>__init__.py  settings.py  urls.py  wsgi.py 
>
> al posicionarme en el directorio raiz del proyecto me lanza el 
> siguiente error 
> ImportError: Settings cannot be imported, because environment variable 
> DJANGO_SETTINGS_MODULE is undefined. 
>
> Anterior a esta version no me generaba esta estructura de archivos. 
> ¿Como puedo corregir el problema?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/b5btuIeux7UJ.
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: am new to the django ,facing problem in searching the database with primary key(student id)

2012-06-26 Thread bruno desthuilliers


On Tuesday, June 26, 2012 8:47:27 AM UTC+2, rick wrote:
>
> Reverse for 'add_record.views.search' with arguments '( Student_login object>,)' and keyword arguments '{}' not found.
>
>
 Your problem is with reverse url resolving, not with "searching the 
database".  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Th6Zm4_xiRQJ.
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: Hey

2012-06-25 Thread bruno desthuilliers
On Monday, June 25, 2012 8:05:13 AM UTC+2, Pervez Mulla wrote:
>
> HI,
>
> How can I extract data from DB so that I can take that data n send it to 
> templates to display graphs according to DataBase values .
> How can I write view function for that?
>


Everything you need to know is here : https://docs.djangoproject.com


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/KZxMgro5DnkJ.
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: Render time

2012-06-25 Thread bruno desthuilliers
On Monday, June 25, 2012 1:34:08 PM UTC+2, larry@gmail.com wrote:
>
>  Now they want me to add to that how long 
> the browser takes to render the page
>

How would server code ever know this ? 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/fWnI-Ri1WGQJ.
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.



runserver cache my template files

2012-06-22 Thread bruno desthuilliers
I assume you did check your browser cache ? 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/vcMDF4DurtYJ.
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: Custom Tags and Includes, invalid block !

2012-06-19 Thread bruno desthuilliers


On Tuesday, June 19, 2012 12:37:29 AM UTC+2, upmauro wrote:
>
> Hello, sorry my english !
>
> I have one question, i create one custom tag and this works fine.
>
> But i have a situation :
>
> *site.html*
> *
> *
> {% include "header.html" %}
>
> Django looks the best framework for web !
>
> {% include "footer.html" %}
>
>
Just as a side note : Django template system has template inheritance which 
is a way better solution than PHP-ish includes wrt/ site-wide page layout. 

(snip - Guevara already answered the question). 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/y6BISY4Mn10J.
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: trailing slash defeats get_absolute_url

2012-06-15 Thread bruno desthuilliers
On Friday, June 15, 2012 9:42:33 AM UTC+2, Mike Dewhirst wrote:
>
> On 15/06/2012 5:11pm, bruno desthuilliers wrote: 
> > You have to end your url patterns with a slash, ie r'^search/'. 
>
> Ok. I added a trailing slash to the get_absolute_url method like so ...   
> return 'xitem/%s/' % self.id ... 



While we're at it: you should definitely use 
django.core.urlresolvers.reverse (same thing as the {% url %} templatetag) 
to reverse-build your urls, instead of hard-coding them (well, unless you 
really enjoy having to grep thru your whole codebase when your url scheme 
changes). As a matter of fact, you wouldn't have had to edit this part if 
you had used reverse() instead, just adding the final slash in the url 
pattern would have been enough.

 

> and added an extra url pattern ... 
>
> urlpatterns = patterns('item.views', 
>  url(r'^search/$', 'search'), 
>

Note that you may want to make the slash conditional, ie:

   r'^search/?$'

so it will match both "/search" and "/search/"


HTH

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/iN2ICAX2EjcJ.
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.



trailing slash defeats get_absolute_url

2012-06-15 Thread bruno desthuilliers
You have to end your url patterns with a slash, ie r'^search/'. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/JAbME4x4ZusJ.
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.



trailing slash defeats get_absolute_url

2012-06-15 Thread bruno desthuilliers
You have to end your url patterns with a slash, ie r'^search/'. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/iks8SsEo2v4J.
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: 'ascii' codec can't encode character u'\xe4'

2012-06-14 Thread bruno desthuilliers


On Thursday, June 14, 2012 1:58:28 PM UTC+2, lawgon wrote:
>
> On Thu, 2012-06-14 at 04:19 -0700, bruno desthuilliers wrote: 
> > > I have an application which runs on a webfaction hosting. 
> > 
> > 
> > 
> > How is it deployed exactly ? 
>
> apache + wsgi 
>


Ok, so that's the same setup we use... Are you/they using the 
WSGIDaemonProcess and WSGIProcessGroup directives ? (I bet they do if it's 
shared hosting and they know what's good for them). But anyway: I did not 
test the damn thing thoroughly but IIRC the problem appeared whether 
running daemon or embedded mode - the django process env is stil inherited 
from the Apache process. Using os.setenv in the .wsgi script is _supposed_ 
to cure the problem but our experience (here again I did not have time to 
really explore the problem :-/) is that it often doesn't work (can't even 
tell if it ever worked at all), so we alway end up editing apache conf - 
which _is_ a know working solution.

Your best bet here is to first try the os.setenv trick, and if it doesn't 
solve the problem contact webfaction and see what you / they can do.

HTH (and please report the solution)

 

> > (sorry never used webfaction hosting for django - nor for anything 
> > else 
> > FWIW) 
>
> not my choice, client choice 
> >   
> > 
> > > I also have 
> > > the same app running on my devel machine. The code in the two 
> > machines 
> > > are pulled from the same repo. Django versions are identical. 
> > Python 
> > > versions are identical. I try to upload a file called Lisäinfo 
> > > kummeille.pdf in the dev machine. No problem. When I try the same 
> > file 
> > > in webfaction, I get the above error. I have checked and find I can 
> > use 
> > > python to open and save a file of the same name from the python 
> > prompt 
> > > in the webfaction shell. In templates, admin and and generated 
> > pdfs, 
> > > these non ascii characters are handled perfectly. Has anyone got 
> > any 
> > > clues about this? 
> > 
> > 
> > 
> > 
> > Each time I had this problem, it happened that the server process was 
> > using 
> > Apache's default locale, and that Apache default's locale was "C", not 
> > the 
> > utf8 locale configured for users. Not much of a problem for me since I 
> > have 
> > admin access but that may not be the case with webfaction :-/ 
>
> I think that should be it - my dev server runs nginx (and on my own 
> server I have root and anyway do not use apache. 
>
> -- 
> regards 
> Kenneth Gonsalves 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Plu2MEPmJ40J.
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: 'ascii' codec can't encode character u'\xe4'

2012-06-14 Thread bruno desthuilliers


On Thursday, June 14, 2012 12:35:40 PM UTC+2, lawgon wrote:
>
> hi, 
>
> I have an application which runs on a webfaction hosting.



How is it deployed exactly ? 
(sorry never used webfaction hosting for django - nor for anything else 
FWIW)
 

> I also have 
> the same app running on my devel machine. The code in the two machines 
> are pulled from the same repo. Django versions are identical. Python 
> versions are identical. I try to upload a file called Lisäinfo 
> kummeille.pdf in the dev machine. No problem. When I try the same file 
> in webfaction, I get the above error. I have checked and find I can use 
> python to open and save a file of the same name from the python prompt 
> in the webfaction shell. In templates, admin and and generated pdfs, 
> these non ascii characters are handled perfectly. Has anyone got any 
> clues about this?




Each time I had this problem, it happened that the server process was using 
Apache's default locale, and that Apache default's locale was "C", not the 
utf8 locale configured for users. Not much of a problem for me since I have 
admin access but that may not be the case with webfaction :-/

HTH

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/q1DkO6bIJyUJ.
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: more than 1 level of belongsTo

2012-06-08 Thread bruno desthuilliers
What about posting your CakePHP questions to a CakePHP related
group ?

On Jun 8, 2:56 pm, rahajiyev  wrote:
> Hi, I have a model Foo belongsTo Bar, which in turn belongsTo Xyzzy.
> When I do $this->Foo->find('all');
>
> sql dump shows that the SQL join is performed only for Foo->Bar, but
> Xyzzy is never mentioned.
> I tried all sorts of 'recursive' => 1 it didn't matter.
> Please help me.
>
> CakePHP 1.3.15

-- 
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: RSS Feed

2012-06-08 Thread bruno desthuilliers
On Jun 8, 1:53 pm, armagan  wrote:
> Hi,
>
> I'm trying to implemente an rss to my project. I have done a simple
> example in django doc.

Which one ? url, please.

> But I have an error in urls.py.
>
> from 'blogum.feeds import LatestEntriesFeed' ==> I've imported this, I
> have an error  'No module named feeds'.

Is 'blogum' (which I assume it's a django app, iow a python package,
iow a directory with a __init__.py file in it) in your sys.path ? If
yes, is there a file named "feeds.py" in it ?

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



Re: url_dir

2012-06-06 Thread bruno desthuilliers
On Jun 6, 12:50 pm, Satvir Toor  wrote:
> I read the linkhttps://docs.djangoproject.com/en/1.3/topics/http/urls/
>
> above unable to understand what is regular expression in url pattern
> e.g r'^pyrheology/plot/tensile/(?P\d+).png$'

Do you mean "I don't understand where's the regular expression part in
the whole url pattern" or "I don't understand what this regular
expression means" or "I don't understand how it used by the
framework" ?

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

2012-06-06 Thread bruno desthuilliers
On Jun 6, 12:32 pm, Satvir Toor  wrote:

> Please explain me the following code that exists in urls.py file of
> the project.
> url(r'^pyrheology/plot/str/(?P\d+).png$',\
>         'pyrheology.views.str_tmc_plot_img',\
>         name='pyrheology-str-tmc-plot-img'),


https://docs.djangoproject.com/en/1.3/topics/http/urls/

Please come back if you still have questions after you've read the
above.

-- 
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: Accessing current URI from template tag

2012-06-06 Thread bruno desthuilliers
On Jun 6, 10:27 am, Swaroop Shankar V  wrote:
> Hello All,
>
> Well my question is on how to get the current URI in a template tag.

You'll have to use a RequestContext in the views rendering the
templates where you use this templatetag, and activate the
django.core.context_processors.request context processor. Then it's
just a matter of passing either the whole context or just the request
(or even just the request URI) to you template tag.



-- 
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: . delete() don't work

2012-06-06 Thread bruno desthuilliers
On Jun 5, 7:22 pm, Lucas Aride Moulin  wrote:
> The syncdb worked. Isso didn't know that the delete() need a table.
> Thanks,

It doesn't, of course. The problem you report is surprising to say the
least...

-- 
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 perform a simple search ignoring characters with accents (á, é, í, ó, ú)

2012-06-05 Thread bruno desthuilliers
Since no one seemed to mention it so far: what about using a real
fulltext search engine ?
(hint : django-haystack provides a django-ish, unified API over quite
a few known search engines).

-- 
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: Retrieve datas from database

2012-06-04 Thread bruno desthuilliers
On Jun 4, 2:23 pm, by-neron  wrote:

> however,
>
> in mysite/template/index.html
>
>  {% for post in latestPosts %}
>      {{ post.id }}
>     {% endfor %}
> prints nothing because it could not send data here. How can i send it ?

You pass them as a Context object to the render() method of the
template - which is what your code is doing.  IOW : the problem is
probably elsewhere.

I assume that
1/ you are running the builtin dev server with the DEBUG flag set to
True in your settings,
2/ you do have some posts in your database,
3/ you already made sure your code was using the right template (like
by editing something in your template and reloading the url to check
if you see the edit).


-- 
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: Using the django.contrib.auth User in my model - database error

2012-06-04 Thread bruno desthuilliers
On Jun 4, 11:01 am, xTalisman  wrote:
> Solved :
> I dropped all the database tables (including the contib.auth ones) and ran
> syncdb, suddenly everything was fine. odd , but is working now .

Well, nice to know it works now, but yes this _is_ odd.

-- 
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: Understanding Django for PHP developer

2012-06-04 Thread bruno desthuilliers
On Jun 3, 12:18 pm, mikegolf  wrote:
> Hi,
> I've started to learn Django recently, however for last 5+ years I've
> been developing using PHP (especially Yii) and thus asking if there's
> any tutorial / documentation on significant differences in
> *thinking*.
> What I mean is for example objects' lifecycle - for PHP the life cycle
> of object is strictly related to the single request..
> I know that for Python / Django developers these are obvious things,
> but not for me. Thus I'd love to see an article / document which
> points these base and significant differences.
> Any recommendations?

Well, the answer may not be as simple as it seems, as it first
requires a correct understanding of Python's execution model,
namespaces, scopes and bindings (aka "variables") - and this would
make for a rather long and technical document. Then you have to know
how your django application is deployed.

I think the most important points wrt/ "objects lifcycle" are (overly
simplified):

* a Python module's top-level code is executed once the first time the
module is imported
* "import", "class" and "function" statements are executable
statements
* the code at the toplevel of a "class" statement is executed once
before the metaclass is called and the class object created
* all this will occur for each of your django server processes
* you can have multiple processes serving the same django application,
and ay request can be mapped to any process (this depends on the front
server and gateway so you have no control over this)

To make a long story short: remember you are in a long running
process, so never modify (mutate or rebind) any module or class
attribute when serving a request.

As an exemple, I once spent quite a few hours debugging a seemingly
intermittent and very very strang problem on a form. The root problem
was a younger co-worker wrote code that was mutating some of the
form's *class* attributes in the class initializer, and depending on
which process would process the form's submission, things would - or
not - get totally mixed up.

A more common mistake is to initialize a class or module date
attribute with the result of a call to datetime.datetime.now() and
wonder why it's not updated on each and every request.

-- 
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: Using the django.contrib.auth User in my model - database error

2012-06-04 Thread bruno desthuilliers
On Jun 4, 9:49 am, xTalisman  wrote:
> I ran syncdb without a problem ,  then when I used the admin interface I
> get the following error :
>
> Exception Type: DatabaseError at /admin/coordination/project/
> Exception Value: no such column: coordination_project.manager_id
>

syncdb only creates the table if it doesn't yet exist in your db - it
will NOT modify an existing table. I guess you ran syncdb a first time
before adding the manager field ? if you either have to update your
schema manually or (better) use a schema-migration tool like South.

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



Re: Problem with Django Project

2012-06-01 Thread bruno desthuilliers
On Jun 1, 10:47 am, cmac0tt  wrote:
> Learning Django/Python by converting a warped >0.96 project to a 1.4
> project with python 2.7.3
>
> So this is my github to make it easier. Can anyone tell me what it is
> thats causing me to keep chasing errors around?

Just a suggestion : "failure to follow the official tutorial" ?

Now learning a framework takes some time, and porting code from one
framework to another can be error prone - you usually pay more
attention (and have less code needing attention at one given moment)
when writing new code than when modifying existing one.

> I fix one to find
> another, then another, then another. I'm curious if i'm on the right
> track here or just basically bouncing myself around, and if I am then
> is there any pointers anyone has.
>
> git://github.com/cmac0tt/wikicamp.git

Some web-browsable link would have been more helpful (sorry, I'm not
going to clone your repo).

> thank for the help. Note my current error is:
>
> ValueError at /wikicamp/create/
>
> The view wikicamp.wiki.views.view_page didn't return an HttpResponse
> object.

A view (wether function or class-based) is supposed to return an
HttpResponse (or subclass of), either directly or via a call to a
shortcut helper function (like render() or render_to_response()). Your
wikicamp.wiki.views.view_page function (following Python naming
conventions I assume it's a function) obviously returns something else
but since you didn't post the traceback we can say much more. If you
want more help about this particular view, please post the snippet.

-- 
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: Adding values to formdata of ModelForm before saving

2012-05-31 Thread bruno desthuilliers
On 31 mai, 20:09, Schmidtchen Schleicher 
wrote:
> Thank you for your quick answer, but it doesn't really work. It raises the
> exception "can't assign to operator"
> My view now looks like this:
>
> @login_required
> > def create_termin(request, calid, year=None, month=None, day=None):
> >     kalender = get_object_or_404(Kalender,pk=int(calid))

You don't need the int conversion here

> >     if request.method == "POST":
> >         print(request.POST)
> >         form = NewTerminForm(request.POST)
>
> >         if form.is_valid():
> >             formdata = form.cleaned_data
> >             if formdata['participants']:
> >                 form.participants = request.user.id
> >             form.save(commit=False)
> >             form.in_calendar-id = kalender

"in_calendar-id" is not a valid Python identifier. It's parsed as
"form.in_calendar - id = kalender"

-- 
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: sqlall fails silently

2012-05-31 Thread bruno desthuilliers
On May 31, 8:24 am, vijay shanker  wrote:
> hi
> i defined three models and put them in /appname/models/ a.py, b.py,
> c.py. and a __init__.py in which i import all classes defined inside
> a.py/b.py/c.py.
>
> when i try to do a ./manage.py sqll appname at prompt , it simply
> passes of without any output.
>  what could be possibly done to debug it .. i had put the appname in
> installed_apps, other app respond to sqlall printing related mysql
> queries .

You need to set your model's Meta app_label :
https://docs.djangoproject.com/en/1.3/ref/models/options/#app-label

-- 
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: image files do not get deleted on deleting an object

2012-05-31 Thread bruno desthuilliers
On May 31, 9:14 am, kenneth gonsalves  wrote:
> hi,
>
> I have just noticed that on deleting an object, the images and files
> stored on disk for this object do not get deleted. Is this a bug or a
> feature?

https://docs.djangoproject.com/en/1.3/releases/1.3/#deleting-a-model-doesn-t-delete-associated-files

HTH

-- 
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: derived fields and getattr

2012-05-25 Thread bruno desthuilliers
On May 25, 2:32 pm, Larry Martell  wrote:
> On Fri, May 25, 2012 at 2:24 AM, bruno desthuilliers
>
> >> I couldn't use the display name or the getattr failed.
>
> > ???
>
> When I first did:
>
> extra(select={"Delta" : self.field_name})
>
> Then getattr(self.field_name) failed with "object has no attribute
> 'col1-col2'".

Obviously - the attribute name is then "Delta", not self.field_name
(which is rather a misleading name since it's really an sql clause,
not a field name).

> Yes, I've been writing python for years too,

Sorry, that's not always the case for peoples posting here.

> and I realize I can put
> in a dict. But it still has to be in 2 places - the code that
> implements the first query that generates the chart, and the code that
> does the drill down query when they click on a point.

You can eventually define the dict in one place and use it from both,
but once again it's hard to say without seeing the real code :-|

-- 
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: track change

2012-05-25 Thread bruno desthuilliers
On May 24, 11:00 pm, Carsten Jantzen  wrote:
>
> Not sure what you mean by detecting skill change using properties, I
> havn't looked into that.
> Could you point to some documentation about it.

Python has a strong support for computed attributes[1], and offers a
builtin "property" type for the most common use cases[2]. This let you
turn a plain attribute into a computed one (using a getter/setter
pair) without breaking client code. What I had in ming was to turn
your "skill" fields into computed attributes (using either properties
or a custom descriptor) to track change.

Now having looked at django-audit implementation (http://
code.google.com/p/django-audit/), I think their approach using the
__setattr__ hook[3] would be better here. Here's a very Q&D and naïve
implementation example:


import datetime

class SkillChange(models.Model):
player = models.ForeignKey(Player)
skill = models.CharField()
value = models.IntegerField()
date = models.DatetimeField()

class Player(models.Model):
   # your fields definitions here
   skill_x = models.IntegerField()
   skill_y = models.IntegerField()

   # which fields we want to track
   _tracked_fields = ['skill_x', 'skill_y']

   def __init__(self, *args, **kw):
   super(Player, self).__init__(*args, **kw)
   self._changed = {}

  def __setattr__(self, attr, value)
  if attr in self._tracked_fields:
  old_val = getattr(self, attr, None)
  if old_val != value:
 self._changed[attr] = value
  super(Player, self).__setattr__(attr, value)

  def save(self, *args, **kw):
  super(Player, self).save(*args, **kw)
  now = datetime.datetime.now()
  for skill, value in self._changed.items():
  SkillChange.objects.create(
  player=self,
  skill=skill,
  value=value,
  date=now
  )
  self._changed = {}

Untested code, of course, it's just meant as a (possible) proof of
concept. You'll probably have to deal with a few special cases like
what happens when creating a new Player instance etc

HTH

[1] 
http://docs.python.org/release/2.6.7/reference/datamodel.html#implementing-descriptors
[2] http://docs.python.org/release/2.6.7/library/functions.html#property
[3] 
http://docs.python.org/release/2.6.7/reference/datamodel.html#object.__setattr__



-- 
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: derived fields and getattr

2012-05-25 Thread bruno desthuilliers

On May 24, 11:50 pm, Larry Martell  wrote:
> I got this to work by adding the derived field to the drill down query
> with queryset.extra, and then it was available with getattr. The only
> issue I had was they wanted the derived field displayed with a name
> (not col1-col2). In the first query I was able to easily do this. But
> in the drill down query I had to do:
>
> extra(select={self.field_name : self.field_name})

The QuerySet.extra() "select" params is a mapping of
"attribute_name":"SQL clause", so you could just write:

  extra(select={"Delta" : "col1 - col2"})

of for somethin more generic:

  extra(select={self.display_name: self.sql_clause})

or if more than one extra field involved:


  extra(select=self.extra_fields)


where extra_fields = {"displayname1":"sql clause 1", "displayname2",
"sql clause 2"}


> I couldn't use the display name or the getattr failed.

???

> But then it was
> displaying with 'col1-col2'. So then I had to explicitly test for it
> and set the display name:
>
>             if field_name == 'col1-col2': display_name = 'Delta'
>             else: display_name = field_name



If you need display names that you don't want to use as field names
(or if you want translatable display names etc), you can maintain a
mapping of fieldname:display_name and then just do a dict lookup, ie:

display_name = display_names.get(field_name, field_name)


Can't really help more here without seeing the actual code, but from
years of experience with Python, I really doubt you have to write
something as ugly as the above snippet ;)

HTH

-- 
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: loop over model ids ? possible ?

2012-05-25 Thread bruno desthuilliers
On May 25, 8:19 am, doniyor  wrote:
> hey guys,
> i need to loop over the number of ids of objects in my db table and create
> accordingly the same number of html fields. how can i do it.. my effort is
> this:
>  numberOfIds = Produkt.objects.count()
>         i = 1;
>         for i in range(0,numberOfIds):
>             p = Produkt.objects.get(id=i)
>             #lookup in db and create html input field depending on the #of
> ids.
>             i=i+1

Django stuff set aside, the right way to iterate over a range in
Python is:

for i in range(0, x):
print i


> but it says: Produkt matching query does not exist. i know, obviously it is
> not right,

You can be sure it _is_ right. Or do you think that no one would have
spot a bug in one of the most used features of a years tested
library ?

> but how is it possible?

create table foo(id int primary key auto_increment, num integer not
null);
insert into foo(num) values(1);
insert into foo(num) values(2);
insert into foo(num) values(3);
insert into foo(num) values(4);
select * from foo order by id;
delete from foo where id=2;
insert into foo(num) values(2);
select * from foo order by id;



If you want a list (well, a ValueQuerySet in this case) of
Produkts.id, the right call is:

ids = Produkt.objects.values_list("id", flat=True)

But iterating over this only to retrieve each produkt in a loop is a
waste of time and resources - you're doing N+1 queries instead of
_one_ single query. See Kenneth's post for the appropriate solution.

-- 
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: derived fields and getattr

2012-05-24 Thread bruno desthuilliers
On May 24, 3:44 pm, Larry Martell  wrote:
> On Thu, May 24, 2012 at 2:27 AM, bruno desthuilliers
>
>  wrote:
> > On May 23, 10:39 pm, Larry Martell  wrote:
> >> I was asked to make a mod to a large django app that I didn't write.
> >> They wanted me to add a derived field to a query, e.g. select
> >> col1-col2 from table ...
>
> > I assume you're talking about using queryset.extra ?
>
> No I build the query myself.

Are you using the ORM at all ?

> >> I did that and it works, but in some other part of the code it calls
> >> getattr(object, field) and when field == col1-col2 it blows up
> >> with"object has no attribute 'col1-col2'"
>
> > Are you sure the instance on which it failed was retrieved using the
> > appropriate query ?
>
> That could be the case. What happens is the data set returned creates
> a chart. The points on the chart are clickable links that drill down
> and generate a more detailed chart. It's in that secondary chart that
> the error occurs. But OTOH, getattr does retrieve the attributes of
> the actual columns from the initial query, so it much be the same
> instance.

Except that, very obviously, it isn't.

> > Can you post the relevant parts of your code ? (here or via dpaste ?)
>
> Unfortunately, no. It's a lot of code with a ton of inherited classes.

Uhu. Real life vs example code, as usual. So all you can do is trace
your code using the logging module (or print statements) and the
debugger.

-- 
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-crequest - New app announcement

2012-05-24 Thread bruno desthuilliers
On May 24, 2:57 pm, Alireza Savand  wrote:
> On Thursday, May 24, 2012 4:46:34 PM UTC+4, bruno desthuilliers wrote:
>
>
> > Uhu... What if I'm running my code from the shell or a command ?
>
> By the way, there is also *set_request*(*request*) for that situation.

Yes. In Zope/Plone too, and then you have to setup a fake request for
each and every "no-web" interaction, and then it still manage to fail
one way or another. Been here, done that, have the tee-shirt.

Logging... Well, you know you do have a whole traceback in your logs
using logger.exception in a try/except block ? You can as well let
exceptions propagate up until your view (or exception handling
middleware) and log relevant request data from there.

I don't mean you don't have a use case, but your solution leads to
other problems that from experience are possibly worse. FWIW, I wonder
if you couldn't just hack the root logger from a middleware to inject
relevant request data from the logging itself instead.

-- 
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: track change

2012-05-24 Thread bruno desthuilliers
On May 23, 10:45 pm, Carsten Jantzen  wrote:

> When I load the player I would like to see his latest stats.
> If I goto the players page I would like to be able to view when and
> what skill changed.
>
> I am looking for a good way to implement it.
> I was thinking to make the skill it's own object and make a one to
> many relation on the player.
> What I am afraid of is that the same skill will show up multiple times
> when loading the player.

There are many ways to tackle this problem, and the "best" one depends
on your game's rules. Your above solution would indeed return the
whole history, and you'd need to filter it out to only get the last
value for each skill. A PITA to work with and not exactly efficient...

If it's only for stats and you have no other reason to turn skills
into proper models, the simplest thing would be to add a
"SkillChanged" model, ie (Q&D):

class SkillChange(models.Model):
player = models.ForeignKey(Player)
skill = models.CharField()
value = models.IntegerField()
date = models.DatetimeField(auto_now_add=True)

then detect skill changes using properties (or explicit getters /
setters) to access your Player's class skills fields and create a new
SkillChange for each skill update.

Or use any of the solutions Andre suggested

-- 
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 call RegexValidator explicitly?

2012-05-24 Thread bruno desthuilliers
On May 24, 4:30 am, forthfan  wrote:
>
> from django import forms
> from django.core.validators import *
>
> class IdentForm(forms.Form):
>   ident = forms.CharField()
>   ident_type = forms.ChoiceField(choices=(
>       ('EIN','Employer ID'),
>       ('SSN','Social Security Number'),
>   ))
>
>   TYPE_CHOICES = (
>       ('EIN','\d{2}-\d{7}'),
>       ('SSN','\d{3}-\d{2}-\d{4}'),
>   )
>
>   def clean(self):
>     cleaned_data = super(IdentForm, self).clean()
>     ident = cleaned_data.get('ident')
>     ident_type = cleaned_data.get('ident_type')

Don't assume you'll have values for both fields in cleaned_data - they
may have failed validation already.


>     regexp = TYPE_CHOICES[ident_type]

I assume you meant:

  regexp = self.TYPE_CHOICES[ident_type]

but it wont work since TYPE_CHOICES is a list of tuples, not a dict,
so this should be:


  regexp = dict(self.TYPE_CHOICES)[ident_type]

>     RegexValidator([regexp]) # What's missing?

First, you have to get rid of the [] here - RegexpValidator expects
either a string or compiled regexp as first argument.

Then once you have a validator instance, you have to call it (like you
would call a function)

>     # How do I pass ident to the validator?

As argument to the call.

>     if ??: # Do I test for existence of error message?

Validators raise a django.core.exceptions.ValidationError

>       ident = ''
>     return cleaned_data

Rebinding the 'indent' symbol in the current namespace won't change
the value (if any) of cleaned_data['ident']. You want to modify
cleaned_data itself (and either set the erreor message manually in
either ident and/or ident_type fields errors or reraise the
ValidationError)

class IdentForm(forms.Form):
  ident = forms.CharField()
  ident_type = forms.ChoiceField(choices=(
  ('EIN','Employer ID'),
  ('SSN','Social Security Number'),
  ))

  TYPE_CHOICES = (
  ('EIN','\d{2}-\d{7}'),
  ('SSN','\d{3}-\d{2}-\d{4}'),
  )

 # no need to reinstanciate validators on each call, we can as well
 # do the job here once for all
 TYPE_VALIDATORS = dict((key, RegexpValidator(regexp)) for key, regexp
in TYPE_CHOICES)

 def clean(self):
cleaned_data = super(IdentForm, self).clean()
ident = cleaned_data.get('ident', '')
ident_type = cleaned_data.get('ident_type', '')
if ident and ident_type:
   # we assume that ident_type is ok here - if not there's
   # a serious problem with forms.ChoiceField ;)
   validate = self.TYPE_VALIDATORS[ident_type]
   try:
   validate(ident)
   except ValidationError, e:
   # doing the simplest thing here, so the error will appear
   # in non-field errors. If you want to set the error on
   # the ident and/or ident_type field(s), cf the FineManual:
   # 
https://docs.djangoproject.com/en/1.3/ref/forms/validation/#described-later
   del self.cleaned_data['ident']
   raise

return cleaned_data

HTH

-- 
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-crequest - New app announcement

2012-05-24 Thread bruno desthuilliers
On May 24, 12:35 pm, Alireza Savand  wrote:
> Hi
> Yesterday i released an app for django.
> *Basically it's just a middleware to access current request of your django
> application from anywhere in your code.*

Uhu... What if I'm running my code from the shell or a command ?

>From experience with some other frameworks / technos, (PHP, Zope /
Plone, etc), it's a pretty bad idea to depend too much on a "current
request" - it leads to way to much coupling in parts of the code that
should be able to work in any environment. Trying to do anything
commandline with Plone is just a major PITA, when not bordering on
impossible.

-- 
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: derived fields and getattr

2012-05-24 Thread bruno desthuilliers
On May 23, 10:39 pm, Larry Martell  wrote:
> I was asked to make a mod to a large django app that I didn't write.
> They wanted me to add a derived field to a query, e.g. select
> col1-col2 from table ...

I assume you're talking about using queryset.extra ?

> I did that and it works, but in some other part of the code it calls
> getattr(object, field) and when field == col1-col2 it blows up
> with"object has no attribute 'col1-col2'"

Are you sure the instance on which it failed was retrieved using the
appropriate query ? Can you post the relevant parts of your code ?
(here or via dpaste ?)




-- 
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: Registering and authenticating via iPhone/Android app

2012-05-24 Thread bruno desthuilliers
On May 23, 3:12 pm, Roarster  wrote:
> Thanks Bruno.  I've had a bit more of a look into this and everyone seems
> to be using OAuth, as you mention.  I did try to get this working with the
> Tastypie API but I couldn't really find any documentation and found it a
> bit of a struggle.  I guess I'll have to look into this further.

Yes, OAuth is not exactly the most straightforward protocol - but it's
becoming the de facto standard for such issues.

> I've also looked into the public APIs you mention and none of them seem to
> allow registration (at least not on the public API).  I guess since my API
> will be private (at least initially) I can do what I want, I was just
> hoping to find out what some other well used apps (e.g. Instagram) might
> use for communication.  Do you think it's possible they just have another
> REST API they don't disclose?

How would I know ?-)

-- 
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: Is there a custom forms component of python-web?

2012-05-24 Thread bruno desthuilliers
plonk.

On May 24, 9:58 am, kevon wang  wrote:
> I want to find a plugin of django what it can custom fields in the form.
> The functions include custom fields in web page and create the fields in
> database.
> plug's flow like these:
>      1.we can define fields in web page
> --> 2.create the table in database(table includes all custom fields)
> --> 3.generate CURD operations in web server
> --> 4.we can CURD records in web pages.
>
> I want to know whether there is a plugin or component of django, If there
> is please tell me. Maybe there is the other plugin like this as well.
>
> I'm urgent. Thanks very much.

-- 
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: Registering and authenticating via iPhone/Android app

2012-05-23 Thread bruno desthuilliers
On May 23, 1:12 pm, Roarster  wrote:
> I'm developing a site using Django using the built in user authentication
> module.  This is all working fine and users can register, login, etc. on
> the web site with no problems.  The plan is to also have companion
> iPhone/Android apps where users can register/login and then access their
> data on the main site.  This is where I'm a bit unsure of how to proceed.
>  I've been looking into using TastyPie to create a REST API which I think
> will work fine for accessing/updating data but I'm not sure if this is
> appropriate for creating new users and authenticating existing users.

I'm definitly not an expert when it comes to mobile apps, but there
are quite a few known REST (or XMLRPC or else) APIs around that
include at least user authentication - think google (including
youtube, blogger etc), dailymotion, most blogging platforms, etc.

As far as I'm concerned, I'd definitly use the API for authentication
too (possibly using OAuth). wrt/ registration, well, I have not
checked if any of the above APIs support this, but from your Django
app's POV, it's still all about HTTP requests / responses anyway so
well...

My 2 cents, really..

-- 
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: Is there a custom forms component of python-web?

2012-05-23 Thread bruno desthuilliers
On May 23, 12:27 pm, kevon wang  wrote:
> Is there a component as above

Yes.

> thanks!

You're welcome.

hint #1: google is your friend. Took me about 15 seconds to get the
answer, so way less than the time you spent posting your question.

hint #2: what you're looking for is usally named a form builder.

hint #3: Django and Python peoples are usually much more friendly than
the average programmers group, but not doing your homework is still
not an option. If you hope to get answers, at least explain what you
already tried to solve your problem by yourself.

-- 
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: ordering m2m query based on through table

2012-05-23 Thread bruno desthuilliers
On May 23, 11:43 am, akaariai  wrote:

> I would guess you would get duplicate objects returned.

We programmers are usually very bad at guessing. So when in doubt,
check, don't guess ;)

> I think the
> query works as follows:
>   - Fetch all Blook's categories
>   - For those categories you fetch all the classifications (not only
> those which are related to Blook) and order by the position in there.

Not quite - cf the generated SQL below.

> So, you could get the same category multiple times ordered by
> positions not related to the blook <-> category connection.

That's not the case. Demonstration:

First, check that we do have categories shared by multiples blooks
(else it wouldn't mean much):

>>> for blook in blooks:
... print blook, blook.categories.order_by("id").values_list("id",
flat=True)
...

#139 [533L, 534L, 535L, 536L, 537L, 538L, 539L, 540L, 541L, 542L,
543L, 544L, 545L, 546L, 547L]
#129 [534L, 535L, 537L, 539L, 540L, 542L, 543L, 544L, 545L, 546L,
547L]
#128 [534L]
#126 [533L, 534L, 535L, 536L, 537L, 538L, 539L, 540L, 541L, 542L,
543L, 544L, 545L, 546L, 547L]
#127 [533L, 534L, 535L, 536L, 537L, 538L, 539L, 540L, 541L, 542L,
543L, 544L, 545L, 546L, 547L]
#118 [534L]

Now check that for each blook, we have the same categories whether
sorted or unsorted:

>>> for blook in blooks:
... cats = blook.categories.all()
... scats = blook.sorted_categories
... assert set(cats) == set(scats), "OOPS ??? %s" % blook
...

Well... No AssertionError raised, so it's correct.

> Maybe the above code does work correctly.

It does.

Custom ordering is possibly one of the most common use case for
"through" m2ms, so you can bet it works - else there would have been
quite some criticism about it ;)

> The interaction between
> multiple references to same reverse foreign key relation in single
> queryset is somewhat hard to remember. Could you post the generated
> SQL?

here you go - reformated for readability:

SELECT
  `blookcore_category`.`id`,
  `blookcore_category`.`label`
FROM
  `blookcore_category`
   LEFT OUTER JOIN `blookcore_classification`
   ON (`blookcore_category`.`id` =
`blookcore_classification`.`category_id`)
WHERE
   `blookcore_classification`.`blook_id` = 118
ORDER BY
   `blookcore_classification`.`position` ASC


I don't quite get why it uses a left outer join instead of the inner
join used when not adding the order by clause, but writing a working,
usable ORM is not exactly a piece of cake so I won't complain about
this ;). Anyway: the where clause still makes sure we only get the
relevant categories.

HTH

-- 
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: DB joining 3 tables in django admin, while searching on the primary table

2012-05-23 Thread bruno desthuilliers


On May 20, 9:42 am, Aditya Sriram M  wrote:

> I tried this but it failed? Can you pls correct me?

yes : "it failed" is the worst possible way to describe a problem if
you expect to get some help. If you get an exception and traceback,
please read them carefully, and eventually post them. Else at least
describe the (unexpected) result.

> where definition of 'get_user_name' is
>
> def get_user_name(self, obj):
>         return u'%s %s %s' % (obj.customerid__first_name,
> obj.customerid__middle_name, obj.customerid__last_name)

What do you expect "obj.customerid__first_name" to eval to exactly ?

> where 'first_name', 'middle_name' etc are properties of the 'User' model.


http://en.wikipedia.org/wiki/Programming_by_permutation ?

I'm sorry to have to say, but it definitly looks like you just don't
have a clue about how Python and Django work. Please take time to
learn at least Python 101, then do Django tutorial. This should answer
your questions and save everyone time on such issues.

-- 
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: ordering m2m query based on through table

2012-05-23 Thread bruno desthuilliers
On May 22, 4:34 pm, akaariai  wrote:

> So, you would want to do collection.songs.all() and have that ordered
> by the sequence defined in the m2m table? I agree - this seems to be
> somewhat hard currently.


I currently have a similar scheme in one of our projects, works fine
as far as I can tell:


class Categorie(Model):
   # 


class Blook(Model):
  # 
  categories = models.ManyToManyField(
Category,
through='Classification',
related_name="blooks",
)

  @property
  def sorted_categories(self):
 return self.categories.order_by("classifications__position")


class Classification(Model):
category = models.ForeignKey(
Category,
related_name="classifications"
)

blook = models.ForeignKey(
Blook,
related_name="classifications"
)

position = models.PositiveIntegerField(
_(u"Position"),
)

class Meta:
unique_together = (
("blook", "category"),
("blook", "position"),
)




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

2012-05-23 Thread bruno desthuilliers
git (or whatever versioning system you're using) + South for schema
migrations + virtualenv / pip for depencies + a simple shell script on
the server to update the whole damn thing and restart services
(Apache, whatever). You can even have the script run by a cron job so
the server is updated every night.


-- 
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: ModelForms and CreateView Help

2012-05-22 Thread bruno desthuilliers
On May 22, 10:34 am, wchildsuk  wrote:
> Hi,
>
> I'm trying to use generic class based views to edit a specific
> queryset but I can't see to get my code working. I've defined queryset

Nope, cf Xavier's answer on this.

> and relevant form but when the form renders it doesn't contain the
> queryset and when it saves it creates a new entry instead of editing
> the existing one.

from the FineManual:

"""class CreateView

A view that displays a form for creating an object, redisplaying
the form with validation errors (if there are any) and saving the
object.
"""

""class UpdateView

A view that displays a form for editing an existing object,
redisplaying the form with validation errors (if there are any) and
saving changes to the object.
"""

Your code:

"""
class ManageReminderMessages(CreateView):
   ...
"""

As a last note: the pk of the model instance to be edited is usually
passed as part of the url (cf the relevant chapter in the
FineManual)... Unless you want to write a new view for each and any
instance of your model, of course ;)

-- 
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: user.set_password('new password')

2012-05-21 Thread bruno desthuilliers
On May 19, 5:49 pm, Timothy Makobu 
wrote:
> user.save returns the function object,


actually it evals to a method object


;)

-- 
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: My context variables don't show in templates

2012-05-21 Thread bruno desthuilliers
On May 20, 12:29 am, Mohamed Turki  wrote:
>
> def home(request):
>     var = ""
>     n = None

Better to use readable names.

>     if request.method == u'GET':
>         GET = request.GET
>         if GET.has_key(u'name'):
>             n = GET[u'name']
>             try:
>                 user = UserProfile.objects.get(facebookId = n)

In most django code, "user" will refer to a
django.contrib.auth.models.User instance. "profile" might be a better
name here (law of the least surprise).

>                 user.is_active = True
>                 user.last_login = datetime.now()
>                 var = user.facebookId

so "var" == "n" == "user.facebookId". Uhuh... Using three different
names for the same object in the same scope is possibly not a great
idea when it comes to readability.

>                 user.save()
>
>                 print var
>
>                 #on log out
>                 if GET.has_key(u'logout'):
>                     print 'im logging out!'
>                     user = UserProfile.objects.get(facebookId = n)
>                     user.is_active = False
>                     user.last_login = datetime.now()
>                     user.save()
>
>             except:

_never ever_ use a bare except clause, unless it's followed by a
"raise" statement. The actual exception might be very different than
what you assume it is (for the record, sys.exit() raise a SysExit
exception...)



>                 user = UserProfile(facebookId=n,playedHours=0,
> is_active=True)
>                 user.save()

Ok, so what if

1/ request.method != "GET"
2/ "name" not in request.GET
3/ any expected or unexpected exception sent you in the exception
handler ?

>     print var
>     context  = {'nom':var}

FWIW, Django's template system is smart enough to handle attribute
lookup. In practice you'd be better to populate your context with your
UserProfile instance...

>     return
> render_to_response('home.html',context,context_instance=RequestContext(request))
>
> and in my template I have something as simple as :
>
> {{ nom }}
>
> However, when I replace *var* with a "bla bla bla" for example, it shows on
> my template, but when I pass a variable name

What do you mean by "variable name" ???

> to the
> context, it doesn't show ! I also can see the *var* value on my console
> (notice i'm using print twice or thrice in the code)

Indeed - but possibly not in the most effective way. You'd have more
infos adding print statements in each and every branch giving clear
indications about what part of the code you're in ATM. A mere "print
var" will only output an empty line if var == "", so you can easily
miss it.


>
> am I doing anything wrong here?

Well, quite a few things yes ;)

... but if your last print statement shows the expected value, then
there's no reason (at the python / django level) it shouldn't show up
in your template.

To make sure your context is what you expect it to be, add a

   print "context : %s" % context

line just before the return statement.

-- 
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: Trying to Edit Existing Post; Can't Get Form to Display

2012-05-21 Thread bruno desthuilliers
On May 19, 5:41 pm, Jonathan Baker 
wrote:

Just a note about best practises:

>
> # views.py

(snip)

>             return HttpResponseRedirect("/report/all/")

Better to use named urls and django.core.urlresolvers.reverse, this
avoids quite a lot of pain and trouble when you have to change your
urls schemes.

My 2 cents...

-- 
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 forms - overriding constructor for changing field type depending by input

2012-05-21 Thread bruno desthuilliers


On May 20, 5:28 pm, luke lukes  wrote:
> thanks Paul and DR, your solution worked. anyway now i have a problem with
> the validation of that form (her's the view):


(snip)

Sorry, your code's indentation get messed up so it's hard to tell
where the problem ise exactly. Please post a link to dpaste or
something similar...

Oh and yes, just in case : wrt/ the form, Paul and Daniel are right
about the assignment to self.fields[fieldname], but you also need to
call the parent's __init__ before.

-- 
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 the Exception Type

2012-05-15 Thread bruno desthuilliers
On May 15, 1:29 am, LJ  wrote:
> I am trying to add exception handling to my application.
> I have been reading the documentation on Django 
> Exceptions:https://docs.djangoproject.com/en/dev/ref/exceptions/
> I also found the list of Exceptions (both Django and Python).
> But for testing purposes, I need a way to handle all exceptions and to
> log the exception types:
>
> try:
>    addresses = Address.objects.all()
> except Exception:
>   logger.debug(Exception.Type)

try:
   addresses = Address.objects.all()
except Exception, e:
  # cheap
  logger.debug("got %s" % type(e))
  # better since you'll have the whole traceback
  logger.exception("oops : %s" % e)
  raise # IMPORTANT

-- 
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 the Exception Type

2012-05-15 Thread bruno desthuilliers
On May 15, 2:31 am, Nikolas Stevenson-Molnar 
wrote:
> You could also log the whole stack trace using the traceback 
> module:http://docs.python.org/library/traceback.html

Or just use logging.exception, that takes care of all the gory details
in a single and simple call:

try:
   foo = bar.baaz()
except Exception, e: # 'exception as e' won't work with older python
versions
   logger.exception("oops")
   raise # if you don't handle the exception, let it propagate, thanks


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



Re: Error: 'module' object is not callable

2012-04-27 Thread bruno desthuilliers
On Apr 27, 2:30 pm, Tom Evans  wrote:
>
> The datetime class lives inside the datetime module.

So far so good but!

> You must have
> "import datetime" in that code, perhaps as well as "from datetime
> import datetime".

The first statement will import the datetime module and bind it to the
name "datetime" in the current namespace. The second will import the
datetime class from the datetime module and bind it to the name
"datetime" in thye current namespace, _in this cas overwriting the
first binding. IOW : you either use the first form and access the
datetime class as "datetime.datetime", or use the second form and
access the datetime class as "datetime", but using both forms is at
once useless and confusing.

As far as I'm concerned, I strongly favor the first form (importing
the module and using the fully qualified name), since there are other
useful stuff in the datetime module and chances are you'll need them
if you need the (badly named) datetime.datetime class.

-- 
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: Custom commands for manage.py

2012-04-27 Thread bruno desthuilliers
On Apr 26, 11:50 pm, "."  wrote:
> Hello,
>
> I have several questions connected with custom commands.
>
> 1. How to delete anything from this dict? Is there a specific method
> for this? [1]
>
> >>> Poll.objects.all()
>
> []


This is not a dict, it's a QuerySet containing one single Poll
instance. Deleting model instances can be done either on the instance
itself or at the Queryset level for a batch delete. It's _of course_
all documented in the FineManual here: 
https://docs.djangoproject.com/en/1.4/#the-model-layer


> 2. How to get rid of default options (which are available from --help
> (traceback, verbosity etc.))? Those are handled by
> BaseCommand.option_list. But I haven't found a way to write a class
> without them.

Just redefine your Command class option_list:

class MyBadCommand(BaseCommand):
option_list = () # no options at all...



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

2012-04-27 Thread bruno desthuilliers
On Mar 23, 12:46 am, hack  wrote:
> I think I shot myself in the foot using ModelForms to generate all of my
> html forms.  Is there any way to use a stylesheet when your forms are
> generated from ModelForms?

Yes of course, why ?

> I've tried everything and cannot get it to work.  I've tried directly
> importing the css files, I've tried loading them from STATIC, and I've
> tried setting css in Meta, but nothing seems to work.

Your problem is with serving the css files, not with Django's form.

-- 
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: Can't find module

2012-04-27 Thread bruno desthuilliers
On Apr 27, 3:56 am, Gerald Klein  wrote:
> Hi, I am having a strange problem, I have a search module named 'search'
> but Django states ;No module named search

full traceback please ?

> here is my url
>
> url(r'^search/$', 'cms.search.views.search'),

is the cms.search app in your settings.INSTALLED_APPS ? Is there any
other package or module named "cms" in you sys.path ?

-- 
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: keep models simple ? where to put the business logic ?

2012-04-27 Thread bruno desthuilliers
On Apr 23, 3:45 pm, Javier Guerra Giraldez  wrote:
> On Mon, Apr 23, 2012 at 6:47 AM, bruno desthuilliers
>
>  wrote:
> > Models - like any other module - should indeed be "as simple as
> > possible", _but not simpler_. If you concern is about your models.py
> > file size, it might be time to refactor it into a package.
>
> or maybe the app has to be more focused, and split in two or more apps.

Possibly, but sometimes the complexity is inherent to the domain and
trying to split the app just makes things more complicated for no good
reason.

> > Now if there are parts of your methods that are low-level enough and
> > don't really need to know about your models, yeps, they may belong to
> > some "model-agnostic" utility module.
>
> also when the usercase concepts are not exactly the same as the
> database records. then another model-like layer can be useful.
>
> for example, lets say you're working with a genealogy application, and
> you have a Person model, and several kinds of relationships between
> person instances.   But let's also say that you have a 'Family'
> concept that is easy to derive from the database (so it doesn't need
> another model class), but you want to add some extra behaviour at the
> Family level (above Person and Relationship).   then it might be
> useful to add a new Family.py

please make it lowercase ;)

> module that works on your models

"model" is kind of an overloaded term here - there's the Django
"Model" class, and there's the "domain model" layer. As far as I'm
concerned, it all belongs to the "models" module / package, even if
there's not a single "Model" class involved.

> but in the end, yes: the vast majority of business logic belongs in
> models.py files, definitely not in the views.

Indeed.

> --
> Javier

-- 
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: keep models simple ? where to put the business logic ?

2012-04-27 Thread bruno desthuilliers
On Apr 24, 1:32 pm, Michael Palumbo 
wrote:
> Hi guys,
>
> Thanks for your answers, it helps.
>
> - Anemic domain model : I didn’t know about this before, it is good to know.
> - Daniel : if I split my models and import all of them in my __ini__.py
> file, why do I still need to use the app_label meta ?

1/ tables prefix
2/ all management commands working on apps

> However, my feeling of having a complex models might also come from the
> fact that I put some numerous try..except blocks inside my function and log
> the errors.
> So my question is: when raising and catching errors and when logging ?
> We could say that catching errors and logging are not part of the business
> logic either

Why so ?

> and they should thus be on a higher level ?

Depends... As a general rule, only catch exceptions you can handle,
else let them propagate. There are a few cases where you want to catch
some exception you cannot directly handle:

1/ when you want to log some contextual info before re-resaising the
original exception

2/ when you want replace the original exception by your own to "hide"
some low-level implementation detail  and/or help the calling code
handling this particular error. In both cases, don't assume to much
about what really happened in the first place and keep as much
debugging info as possible.

Also, remember that django already comes with a top-level exception
handler around your views, so the worst thing that may happen is an
HTTP 500.

-- 
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: Ways to handle long-running server-side processing in Django

2012-04-23 Thread bruno desthuilliers
On Apr 21, 11:34 pm, David Markey  wrote:
> Sounds like the API should return a UUID that can then be used to poll,
> while celery or similar does the heavy lifting in the background?

+1

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: keep models simple ? where to put the business logic ?

2012-04-23 Thread bruno desthuilliers
On Apr 22, 7:51 pm, Michael Palumbo 
wrote:
> Hi,
>
> I know this has already been discussed several times, I found several posts
> about it through Google but I'm still interested in getting your opinion on
> an example.
>
> I'm wondering that because my models file is getting big. That makes me
> confused so I'm wondering if I'm doing the right thing from a design point
> of view.
> I have the feeling that my models should remain simple. What do you think ?

https://www.google.com/search?q=anemic+domain+model

> For example, let's say I want to create a model named Feed. (simplified
> version)
> class Feed(models.Model):
>     name = models.CharField(max_length=255, unique=True)
>     url = models.URLField(unique=True)
>     etag = models.CharField(max_length=255, null=True, blank=True)
>
> I want to be able to extract a feed (that is to say to download it and
> store it(as a file but I also keep a track in the DB through a File
> model)). Would you create:
> - an extract method in the model

That's probably what I would do.

>
> - a view:

Nope. The view should just deal with user interactions (in this case,
allow a user to launch the extraction).

FWIW, a part of the Django code I see suffer from this problem (anemic
domain, and anemic forms to), and it's a major PITA when you want to
extend such a code, because you have business logic and user
interaction logic deeply mixed in the views for no good reason.


> - a "util" function to whom I pass the Feed object.
> f = Feed.objects.get(pk=1)
> utils.extract_feed(f)

How is this better than having the very same function being a method
of the model ?

Models - like any other module - should indeed be "as simple as
possible", _but not simpler_. If you concern is about your models.py
file size, it might be time to refactor it into a package.

Now if there are parts of your methods that are low-level enough and
don't really need to know about your models, yeps, they may belong to
some "model-agnostic" utility module. Refactoring methods this way can
help keeping the method code hi-level and readable.

My 2 cents

-- 
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: apache2 privileges

2012-04-19 Thread bruno desthuilliers
On Apr 18, 5:12 pm, "Daniel Sokolowski"
 wrote:
> Hi Bruno,
>
> Can you expand on that, each of your sites has a user account created? Yes?

Depends on the concrete use-case but mostly, yes, each django site
will have a dedicated user account. If it's a dedicated hosting for
one customer having 2 or more sites, we either use the same user
account for all sites or (for either technical or customer-policy
reasons) one account per site.

-- 
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: cannot import name current_datetime

2012-04-19 Thread bruno desthuilliers
On Apr 18, 8:47 pm, asherakhet06 
wrote:
> H all!
>
> I am fairly new to programming (went over LPTHW) and now going through the
> Djangobook on the internet.  Quick beginners question:  In Chapter 3, where
> I am looking at a dynamic webpage in the 2nd example

Could you please post a link to this resource ?

> I am running into some
> problems with the current_datetime function I am trying to set up. When, in
> views.py I insert the "datetime.datetime.now()" statement and "import
> current_datetime" into my urls.py file

If your import statement is actually "import current_datetime", then
the book is wrong, Python imports dont work that way. You either
import a module then use a qualified name to access the module's
symbols, ie:

from myapp import views
now = views.current_datetime()

or import a symbol from a module and use it directly, ie:

from myapp.views import current_datetime
now = current_datetime()

of course the module (or the package containing the module) must be in
your pythonpath.

for more about the import statement, see

* http://docs.python.org/release/2.7/tutorial/modules.html

and

* 
http://docs.python.org/release/2.7/reference/simple_stmts.html#the-import-statement

> but it's been
> a real puzzle for me to be honest:/  Anybody have any tips on how to solve
> this error?  I know it is really important to be careful to copy EXACTLY as
> mentioned in the programming book(s),

Books are sometimes wrong, and sometimes a bit outdated.

-- 
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: question about celery

2012-04-19 Thread bruno desthuilliers
On Apr 19, 11:05 am, Mike  wrote:

(...)
> Now I want to
> move the processing off to a different machine so I'm looking into Celery.
>  What I'm not sure about is what are the requirements of the workers.  Do
> they need to have the code they are going to run already installed

Yes. But you can use NFS to avoid having to keep the code in sync on
different machines.

> or is it
> somehow pickled and sent to the worker?

No.

>  My current script checks the DB
> for a job, runs the job, and then inserts the data into the django DB.  I
> guess this won't work with Celery because the remote workers won't have
> access to the django DB.

Why not ? Neither the django and/or celery processes have to run on
the same host as the SQL server, that's what the "HOST" setting is for
(https://docs.djangoproject.com/en/1.3/ref/settings/#std:setting-HOST)

FWIW, if you start to have performance issues, moving the SQL server
process to a different machine might be the first thing to do
(depending on where the issues are of course).

>  I guess the celery tasks should accept data and
> only return data - all the interaction with the database should happen on
> the web server hosting the django app, right?

Nope. Just use the right HOST setting.

-- 
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: apache2 privileges

2012-04-18 Thread bruno desthuilliers
On Mar 9, 6:43 pm, "j...@jsdey.com"  wrote:
> My apache2 server on linux is running as www-data.  My project is in a
> standard user account.  apache2 can't access files on the user account

Using mod_wsgi in daemon mode let you run the django processes as
another user/group, and this is definitly the best solution IMHO.

-- 
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: row level permissions - why?

2012-04-17 Thread bruno desthuilliers
On Apr 17, 8:07 am, Mike  wrote:
> In my app I need a way to associate objects with a specific user.  Users
> should not have access to other users objects. I'm implementing this in my
> model by setting a ForeignKey to the user that owns the object:
>
> owner = models.ForeignKey(User)
>
> Is this a bad idea?

Seems quite sensible for the use case you describe.

> Can someone explain under what circumstances I would
> need to use a row level permissions app?

Row level permissions are useful when you have a more complex (and
possibly dynamic) scheme - a common example would be a CMS with public
and restricted areas, per-area admins and a validation/publication
worflow.

-- 
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: Where/how to load global static data?

2012-04-05 Thread bruno desthuilliers
On Apr 5, 3:11 pm, Tom Evans  wrote:
>
> OP: I have a couple of solutions. One of the first things the server
> does is import your settings, so if you load and parse your static
> data at that point, then you will have access to it from that point
> onwards.

Please dont. Settings are, well, settings, and should contain as few
executable code as possible.

A memoized function seems like the best solution here. Just for the
record, the usual way to have code executed at process startup is to
call this code from within one of your app's models.py - as theses
modules are garanteed to be imported by django at process startup (but
used to be executed twice when running anything from manage.py which
can be a PITA - this seems to have beed fixed the recent 1.4 release).

-- 
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: templates couple apps to a site; how do you separate them?

2012-03-14 Thread bruno desthuilliers
On Mar 14, 2:31 am, Ken  wrote:
> I'm struggling with how I should go about writing "pluggable" apps.  I
> haven't found a satisfactory way of decoupling apps from a site and
> the primary sticking point is templates.  I've combed through some
> discussions but have not found any that have helped.
>
> A site's templates determine the look and feel.  If an app is to play
> nice, then it needs to know a site's templates.  If an app uses its
> own templates, then it can override the site's look and feel.

The simplest solution is to provide barebones templates within the app
and let the project team override them.

-- 
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 deployment practices -- do people use setup.py?

2012-03-14 Thread bruno desthuilliers
On Mar 12, 11:55 pm, Tom Eastman  wrote:
> Hey guys,
>
> I'm looking for deployment best practices for Django projects. Google
> searches seem to show countless numbers of them, many of them somewhat
> contradictory :-)
>
> So as a simple discussion point: I'm curious to know if lots of people
> use setup.py to deploy a django project?

We dont - we use virtualenvs (no-site-packages), pip requirements, and
git.

-- 
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: Can i specify a different set of global context processors for admin?

2012-03-09 Thread bruno desthuilliers


On Mar 9, 9:58 am, Paul  wrote:
> Nearly all views of an application i'm working on have the same
> sidebars with dynamic contents. So i generate these in a custom global
> context processor so it is available to any view without having to
> specify the custom processor each time.

This is better solved with custom template tags and template
inheritance.

> It turns out that also in admin views the same processors are used
> (from TEMPLATE_CONTEXT_PROCESSORS) which is not desired. So i'm
> starting to doubt whether this was such a good idea or not
>
> How could i solve this?

cf above.

-- 
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: Exception handling in templates

2012-03-06 Thread bruno desthuilliers
On Mar 6, 7:07 am, Aryeh Leib Taurog  wrote:

> Let's say I have the following code:
>
> class MyClass:
>     def my_title(self):
>         if 'some string' not in self.get_another_object().x:
>             return 'Specific Title'
>
> Then I have a template:
>
> {% with instance_of_myclass as obj %}
> {% if obj.my_title %}
>   {{ obj.my_title }}
> {% else %}
>   Generic Title
> {% endif %}
>
> Sometimes self.get_another_object() returns an object which doesn't
> have attribute 'x' so my_title() raises an AttributeError exception.
> Under Django 1.2.4 the template renders as 'Generic Title,' but under
> 1.3.1 I get a server error.

Did you check the DEBUG and TEMPLATE_DEBUG flags in your settings ?

-- 
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: load settings on database

2012-02-16 Thread bruno desthuilliers


On Feb 16, 4:55 am, Anderson Borges  wrote:
> Hey guys
> I am learning django and I have a question
> I have a table in my database call SettingsUser so how can I load this table 
> to all views on my application?

I just don't understand what "loading a table" is supposed to mean. If
you want to make some object (model instance or whatever) available to
all your templates, a context processor will do the job. If you want
to make it available to all your views, you can use a middleware and
attach the relevant object(s) to the request object.

Now given the name ("settingsuser") I suspect it's a kind of "per-user
settings" stuff. If so, the SettingsUser model should have a
foreignkey on User, and then you can just follow the reversed
relationship, ie:


# youmodels.py
class UserSetting(models.Model):
user = models.ForeignKey(User, related_name="settings")
parrot_is_dead = models.BooleanField(u"Is user's parrot dead ?",
default=True)


# yourviews.py


def something(request, *args, **kw):
print request.user.settings.all()

HTH

-- 
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: connection.cursor()

2012-02-16 Thread bruno desthuilliers
On Feb 16, 10:29 am, MikeKJ  wrote:
> I got these imported tables from an external source so I need to
> access the data using connection.

Not necessarily - if there's no compound primary key, you can build
django models from the tables using manage.py inspectdb (be sure to
add the managed=False and set the correct tablename in the generated
model's Meta).


> The problem I have is getting at the data in more than 1 table with
> one dict the pure sql call would be something like
>
> select * from yw_basics ywb left join yw_next ywn on ywb.id = ywn.id
> where ywn.field = 0

"select * " is usually a bad idea.

> def dictfetchall(cursor):
>     desc = cursor.description
>     return [
>         dict(zip([col[0] for col in desc], row))
>         for row in cursor.fetchall()
>     ]

You'd be better using lazy evaluation:

def dictfetchall(cursor):
# avoid reexecuting constant code in a loop
desc = col[0] for col in cursor.description
for row in cursor:
yield dict(zip(desc, row))


> def secondhand(request):
>     from django.db import connection, transaction

Please avoid imports in functions.

>     cursor = connection.cursor()
>     cursor.execute("SELECT * from yw_basics")
>     stuff = dictfetchall(cursor)
>
> I tried adding the sql call above into the cusor.execute and failed
> miserably so any clues would be gratefully received.

First clue : "failed miserably" is about the most useless possible
description of the problem, specially if you hope to get any help. At
the very least explain what happens (and if you get an exception post
the full traceback).

-- 
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: Logging from multiple processes

2012-02-15 Thread bruno desthuilliers
On Feb 14, 6:23 pm, JC  wrote:
> Hey guys,
>
> Does Django 1.3.1 handle logging from multiple processes or I have to
> have some special consideration?

Not really a django-specific problem - the problem exists as soon as
you have concurrent write access on a same file. The solution is of
course to NOT log to a file.

> This document may be 
> related:https://code.djangoproject.com/wiki/LoggingProposalbut its two years
> old so I was wondering maybe Django now supports this?

https://docs.djangoproject.com/en/1.3/topics/logging/

IOW : learn to use the standard python logging module. If you're using
mod_wsgi the simplest thing is to use a streamhandler on sys.stderr
and let apache do the dirty work.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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 runserver 504 on static assets with IE only

2012-02-15 Thread bruno desthuilliers


On Feb 14, 8:56 pm, JC  wrote:
> On IE8 however,
> my fiddler trace shows that random static assets (css, js, img) aren't
> loading most (2/3) of the time.  The server trace doesn't seem to see
> or log the request at all.

Then it might be that for some reason IE8 just doesn't request the
assets.

-- 
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 make a small change for apps installed under /site-packages dir

2012-02-09 Thread bruno desthuilliers
On Feb 8, 7:01 pm, Tom Lesters  wrote:
> > Generally speaking, using virtualenv (no-site-packages) + pip (with a
> > requirement file you keep in your project) is a GoodPractice(tm) when
> > it comes to dependencies.
>
> I'm actually using virtuallenv + pip now, thanks for advice anyways!

GoodBoy(tm) !-)

>
> Daniel's solution works great in this case.

That's indeed what I would do here - simplest thing that can possibly
work.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Can anyone please explain the following settings?

2012-02-09 Thread bruno desthuilliers
On Feb 9, 3:39 am, John Yeukhon Wong  wrote:

(snip code)

> I just don't understand what each of the options above mean Can
> someone please explain them?  Thanks.

https://docs.djangoproject.com/en/1.3/ref/settings/

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

2012-02-09 Thread bruno desthuilliers
On Feb 9, 9:41 am, Rune Kaagaard  wrote:
> Dear django-users
>
> I keep doing patterns like:
>
>         has_changed = False
>         if resource.user.email != request.POST['email']:
>             resource.user.email = request.POST['email']
>             has_changed = True
>         if resource.user.is_active != request.POST['is_active']:
>             resource.user.is_active = request.POST['is_active']
>             has_changed = True
>         if has_changed:
>             resource.user.save()
>
> although it works, I feel like there is a cleaner solution. How would
> you solve such a problem?

https://docs.djangoproject.com/en/1.3/topics/forms/
https://docs.djangoproject.com/en/1.3/topics/forms/modelforms/


Note that if you really insist on doing things by hand and not doing
any validation/sanitization on user inputs, you could at least avoid
repetitions:

user = resource.user
fields = ("email", "is_active")
has_changed = False
for field in fields:
old = getattr(user, field)
new = request.POST.get(field)
if new != old:
setattr(user, field, new)
has_changed = True
if has_changed:
user.save()

But I really don't see the point in NOT using forms :-/

-- 
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 make a small change for apps installed under /site-packages dir

2012-02-06 Thread bruno desthuilliers
On Feb 5, 6:16 pm, Tom Lesters  wrote:
> hi all,
>
> I installed an app called idios into python2.6/site-packages/idios dir,

Which is possibly not a great idea... as you now know .

Generally speaking, using virtualenv (no-site-packages) + pip (with a
requirement file you keep in your project) is a GoodPractice(tm) when
it comes to dependencies.

> now I need to make a small change, adding the following line(just for
> purpose of explaining this question)
> @login_required
> to one of the functions defined in idios/views.py

Daniel already provided the simplest solution for this problem. For
more involved changes and assuming you prefer not to mess with the
third part app's code, you can also monkeypatch the relevant functions
in your own app.

> or it's just the nature of any django apps:
> if you need to modify anything in the urls.py ,views.py or models.py,
> you just grab the source and make is as a local project app?

Depends on how much you need to modify the third part app. Forking the
app is sometimes the best solution, but it means you'll have a hard
time keeping in sync with the original code when bugfixes and new
features will be released. Monkeypatching doesn't totally solve this
problem but from experience it makes for easier updates.

My 2 cents...

-- 
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: Rooting my application at the base (/) of the URL

2012-02-03 Thread bruno desthuilliers
On Feb 2, 9:14 pm, Johan  wrote:
> Hi
>
>   I have deployed my application on Apache using WSGI, using
> WSGIScriptAlias / /var/www/site/django.wsgi. Everything looks very
> good. My actual application lives at http:///application. So
> with the setup above when I browse to http:// django 404 page. I get this even if I add a .htaccess file ro
> redirect / to /application. I can understand why this happening, it
> because the wsgi script is rooted at / so the .htaccess file is never
> utilized. If I change the WSGIScript alias setting to be
> WSGIScriptAlias /application /var/www/site/django.wsgi. Then
> the .htaccess file gets invoked but django stops working.

If you want your django app to be the root of your django project, you
just have to fix your root urls.py. FWW, here's the relevant part of
my current project's root url.py:

urlpatterns = patterns(
'',
url(r'^$', main_views.home, name="home"),
url(r'^blookshop/', include('blookshop.urls')),
url(r'^admin/', include(admin.site.urls)),
   )


>  In the meantime what would also work is to add an entry in the main
> application's urls.py to redirect / to /application. But I don't know
> how to do this. So any help would be appreciated.

googling +django +redirect +view, I get the answer at the very top of
the 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: Newbie django/python with C++ background wants enums

2012-02-02 Thread bruno desthuilliers
On Feb 1, 10:45 pm, NENAD CIKIC  wrote:
> Hello, the subject expresses my discomfort with certain python
> characteristics, given my background, and my lack of python knowledge.
> Specifically lets say that I have a model with a Text field and char field.
> The char field is length 1 and says "use or do not use the text field".

A BooleanField might be better then.

> The
> char field can have Y or N values.
> So using the admin interface I wanted to override the clean method but I
> did not want to write
> if text.__len__==0 and char=='Y':
>   raise exception

"__magic_methods__" are here to support operators (or operator-like)
implementation, and except for a very few corner cases you should not
call them directly. So here you want "len(text)", not
"text.__len__()".

Also note that the parens are the "call operator", so "text.__len__"
will eval to the "__len__" method object itself (remember that in
Python everythin is an object, including classes, functions and
methods), not to the result of calling this method.

And finally, in Python, empty sequences (at least for the builtin
sequence types), empty dicts, empty strings, numeric zero (int, float
etc) and the None object all have a false value in a boolean context
(FWIW, True and False and the bool type are late additions to the
language). So the pythonic way to test for an empty string is just :

if not txt:
print "txt is empty"

> In C/C++ you would use enum for these sort of things. So I ended with
> defining in models.py something as:
> TO_USE= (
>     ('Y', 'Yes'),
>     ('N', 'No'),
>     )
>
> class X(models.Model):
>     txt= models.CharField(db_index=True,null=True, blank=True,max_length=30)
>     use_txt=
> models.CharField(blank=False,max_length=1,default='D',choices=TO_USE)

I'd still use a BooleanField here as far as I'm concerned, but when it
comes to multiple choices, here's how I do:


class X(models.Model):
USE_YES = 'Y'
USE_NO = 'N'
USE_CHOICES = (
(USE_YES, u"Yes"),
(USE_NO, u"No"),
)

   use_txt = models.CharField(
   u"Use text",
   max_length=1,
   choices=USE_CHOICES,
   default=""
   )


then I can test the value using the class pseudo-constants, ie:


x = X.objects.get(pk=1)
if x.use_txt == x.USE_YES:
   pass

> and in admin.py something as
> class XForm(forms.ModelForm):
>     def clean(self):
>         cleaned_data=super(XForm, self).clean()
>         txt= cleaned_data['txt'].strip()
>         use_txt=cleaned_data['use_txt'].strip()
>
>         if txt.__len__()==0 and use_txt==TO_USE.__getitem__(0)[0]:

would be a bit better (or at least a bit less worse ) this way:

if not txt and use_txt == TO_USE[0][0]:

But that's still not something I'd be happy with. My above solution
would make it a bit more readable:

if use_txt == X.USE_YES and not txt:


>             raise forms.ValidationError('This is needed!')
>
>         return cleaned_data
>
> The part .__getitem__(0)[0] is not very readable.

Indeed. And not even consistant - if you insist on using
__magic_methods__ instead of the operators, at least go all the way:

TO_USE.__getitem__(0).__getitem__(0)

?-)

Sorry, just kidding 


-- 
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: model for uploading a file - not working??

2012-01-25 Thread bruno desthuilliers
On Jan 25, 4:54 pm, Krondaj  wrote:
(snip)
> I get:
>
>   File "/home/chrissmith/Dcode/rrws/rrs/models.py", line 36
>     upload_doc = models.FileField(upload_to 'documents')
>
> ^
> SyntaxError: invalid syntax
>
> any idea's what's up?

Please re-read carefully the error message and the line it points to.
The error message says "SyntaxError: invalid syntax", which means your
code isn't valid python code. The cursor points to where the syntax
error happens, that is the whitespace between 'upload_to' and
"documents".

The valid syntax would be:

   upload_doc = models.FileField(upload_to='documents')

I strongly suggest you take some time to learn Python - at least do
the official tutorial - if you hope to get anything done in Django.


-- 
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: Deverifying a URLField

2012-01-25 Thread bruno desthuilliers
On Jan 25, 12:30 am, Rich Jones  wrote:
> Hello, all!

(snip - Mike already answered)

> Will I need to do a database migration
> to do this? Or can I just add a 'verified=False' and run syncdb?

URL Validation is done in django, not in the database, so there's no
need for a migration here. Also note that syncdb DOES NOT migrate
anything - if you have a need for schema and data migrations then
South is your friend.

-- 
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: Why can't erase this model object? "AssertionError: Question object can't be deleted because its id attribute is set to None."

2012-01-23 Thread bruno desthuilliers
On Jan 22, 12:39 am, Chris Seberino  wrote:
> On Jan 21, 2:43 pm, JohnA  wrote:
>
> > How are you finding these objects?  That might point to the answer.
>
> > Probably the likeliest explanation is that you are creating the
> > objects but not saving them.
>
> In the Django shell I do
>
> quests = Question.objects.all()
> quests[579].delete()
>
> Why does the objects.all() invocation add this id=None

No reason it should do this, and I really doubt this is the case -
unless you're using a (broken) custom Manager you didn't mention when
you posted your model definition.


> to quests list?

"quests" is not a list, it's a QuerySet (https://
docs.djangoproject.com/en/1.3/ref/models/querysets/).

-- 
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: Why can't erase this model object? "AssertionError: Question object can't be deleted because its id attribute is set to None."

2012-01-23 Thread bruno desthuilliers


On Jan 22, 1:34 pm, akaariai  wrote:
> There is still the possibility that you really have a row where the PK
> is somehow null.

Very unlikely given the model definition, but well, sh*t happens.

-- 
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: Why can't erase this model object? "AssertionError: Question object can't be deleted because its id attribute is set to None."

2012-01-23 Thread bruno desthuilliers
On Jan 21, 6:31 pm, Chris Seberino  wrote:
> On Jan 21, 6:44 am, Tom Evans  wrote:
>
> > Models are representations of rows in a database.
> > Deleting a model instance implies removing a row from a database.
> > Model instances have an id attribute which denotes their row in the 
> > database.
> > Models whose id is None don't exist in the database, and so it is
> > nonsense to delete them - they don't exist.

This should read "they don't exist _in the database_" - a model
instance is not a database row, it's a python object. The database row
only exists if and when the model instance has been saved, and until
the database row is deleted.

> That makes perfect sense but then why do these zombie id=None objects
> show up?

That's one question... And I don't have the answer.

> *WHERE* are they living if not in the database?  Does the Django shell
> somehow have a secondary storage area for this zombie id=None object
> stuff I can delete somehow?

And that's another question, which has a very simple answer: model
instances live in your python process (django's dev server, wsgi
process, custom management command, django shell or whatever). If you
fire a django shell, import your model class and instanciate it
directly and don't save it you will have a model instance with no id
(assuming you're using the auto id field which is the default).


-- 
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: Joining tables

2012-01-16 Thread bruno desthuilliers
On Jan 16, 8:04 am, Arun P  wrote:
> Does this work?
>
> info =
> ExtraInformation.objects.filter(user__is_active=1,user__is_staff=0,user__is_superuser=0).order_by("popularity").select_related("user")
>
> users = map(lambda i: i.user, info)


That was for the "uselessly complicated and memory-hungry" method. Now
for the "simple lazy" method:

=> users = User.objects.filter().order_by("extrainformation__popularity")

@OP : You can add a select_related if you plan on using data from
ExtraInformation so you save on useless queries.

-- 
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: change min_length in form __init__?

2012-01-13 Thread bruno desthuilliers
On Jan 11, 12:15 pm, galgal  wrote:
> Is there any way, to change the field's *min_length* argument inside form
> constructor? That doesn't work:
>
> def __init__(self, *args, **kwargs):
>     super(CreateTeamForm, self).__init__(*args, **kwargs)
>     self.fields['primary_color'].min_length = 4

Assuming primary_color is a CharField, this should theoretically
JustWork AFAICT. What is the result ? ("doesn't work" is not really
descriptive...)

-- 
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: change min_length in form __init__?

2012-01-13 Thread bruno desthuilliers
On Jan 13, 7:02 am, Wen 温业逵Yekui  wrote:
> why you use the "*" in your function argument?
>
Because it's the sensible thing to do here - cf
http://docs.python.org/release/2.6.7/tutorial/controlflow.html#more-on-defining-functions


-- 
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: Session value persistence between views

2011-09-07 Thread bruno desthuilliers
On Sep 6, 10:42 am, alaric  wrote:
> Hi:
> I am very new to Django but I am trying to authenticate using Django's
> session framework.
> Problem is: I need the raw password to ssh as that user to retrieve
> data on another machine. I haven't gotten it to work however.
>
> I have a login view that looks like:
>
> def login(request):
>     request.session['blah']=request.POST['username']
>     request.session['blah2']=request.POST['password']
>
> 
>
> def view_data(request):
>     username=request.session['blah']
>     password=request.session['blah2']
> 
>
> I get KeyError with view_data. Am I missing something here?

Is your session correctly configured ?
https://docs.djangoproject.com/en/1.3/topics/http/sessions/

-- 
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: Pagination of more than one field

2011-09-07 Thread bruno desthuilliers
On Sep 6, 4:41 pm, Yaşar Arabacı  wrote:
> I think your question can be solved with javascript and ajax, rather than
> with django. How is your knowledge in that area?


This can definitly be resolved with Django, and it's always better to
have something working without js / ajax when possible (you can then
add js / ajax afterward).

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



  1   2   3   4   5   6   7   8   9   10   >