Re: How/where to call setlocale

2014-09-16 Thread rettevhcirlu
Hi, 
I ran into a similar problem yesterday while programming a web shop with 
Django (Version 1.6, Python version 3.3) where language switching should 
immediately have an effect on the way prices, etc. are displayed (doing so 
by a  in the template and 
redirecting back to the page where it was called). The locale is indeed not 
set this way and needs to be set explicitly. What I finally came up with as 
a first working solution as part of a function:

def convert_my_price(_price)  # _price is a decimal.Decimal
language = django.utils.translation.get_language()
if language == 'en':
locale.setlocale(locale.LC_ALL, 'en_US.utf-8') # 'en_GB.utf-8' 
 didn't work for me 
else:
locale.setlocale(locale.LC_ALL, 'de_DE.utf-8')# this is the 
fallback

_loc = locale.localeconv() 
.
.  # process the Decimal
.  
return my_price_as_a_string

After doing so I have access to the locale details stored in the 
dictionairy _loc, like e.g. _loc['thousands_sep'], _loc['currency_symbol'] 
in this function, but also everywhere else via locale.localeconv() 
This function however is currently called from within class based views, 
but also implemented as a template filter. Of course one should not set the 
locale every time when calling this function, as you mentioned 
locale.getlocale() will should whether it was correctly set or not.

Where you call locale.setlocale depends on your application. When you only 
have to set it once maybe the best would be to call it in even in e.g. 
wsgi.py 

Best regards,
Ulrich

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/65e039ab-b2ef-4f78-ab39-0ee53f2f5629%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best way to learn Django considering Python versions and etc.

2013-12-10 Thread rettevhcirlu
Dear Bruce,
being myself a Python programmer for more than 16 years I only recently 
started usind django when I was looking for a way to set up a web 
application. The reason for this choice is motivated by the positive 
experience I always had with Python and so I dived into Django. Now when it 
comes to Python programming there is always this 2.X vs 3.X thing and this 
is also something one immediately has to deal with when it comes to Django 
programming. Setting up Apache and using mod_wsgi, calling a local Django 
installation set up with virtualenv, I directly ran into the problem that 
mod_wsgi can only work with a Django version using the same Python version 
mod_wsgi was compiled against. Since I am running a gentoo linux and 
therefore used to keep things relatively up to date, I decided to use 
Django version 1.6 and Python version 3.3. Of course then I discovered that 
this renders almost 80-90% of the additional Django packages, which make 
Django so powerful, "useless" because they are still with the old Python 
2.7 version. Just as an example: using Python 3.3 kicks out all Django 
based web shop framworks (to my best knowledge) and reduces the useable 
internationalization packages to only two ot three. And so on.
Therefore I personally recommend using Pyhton 3.3 only if one is safe with 
Python programming and if one has the time to do some things from scratch. 
If we are talking about different Django versions (I know you where talking 
about different Django versions only, but I thought it is worth having a 
look at the Python version as well): I realized that there where quite 
heavy changes in the framework over the different versions, and assuming 
that such a tendency will remain it would be better to use the newest 
stable version of Django instead of an old version where you probably have 
to rewrite large parts of the code when porting to a newer version.
Regarding literature the most useful one is the 1000+ pages Django doc. 
This is a really excellent documentation, and since Django is progressing 
quite fast, it will the most useful reading on this topic. Of course there 
are also excellent code snippets on certain Django topics on the web.
In the very beginning, when playing around with Django, I also used tried 
the Bitnami Django stack, but personally I didn't find it very useful.
Best wishes,
Ulrich

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3261a455-aecb-4d9d-93f0-01cb2f5800cc%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.