Tuesday, November 16, 2010

Re: Set Language in the Admin

On Tue, Nov 16, 2010 at 9:58 AM, Federico Capoano
<nemesis.design@libero.it> wrote:
> This will affect the frontend too?
>

Yes, I'd replace it with a customized version of the LocaleMiddleware,
something like this ought to do the trick:

from django.middleware.locale import LocaleMiddleware
from django.utils import translation

class LocaleButNotInAdminMiddleware(LocaleMiddleware):
KWARG = 'DisableLocalisation'
def process_view(self, request, view_func, view_args, view_kwargs):
disable_localisation = self.KWARG in view_kwargs and
view_kwargs.pop(self.KWARG)
if disable_localisation:
translation.deactivate()
if hasattr(request, 'LANGUAGE_CODE')
del request.LANGUAGE_CODE
def process_response(self, request, response):
if hasattr(request, 'LANGUAGE_CODE'):
super(LocaleButNotInAdminMiddleware,
self).process_response(request, response)
return response

and then change how you include the admin into your urlconf from
something like this:

urlpatterns = patterns('',
(r'^admin/(.*)', include(admin.site.urls)),
)

to something like this:

urlpatterns = patterns('',
(r'^admin/(.*)', include(admin.site.urls), {'DisableLocalisation': True}),
)

So that it disables the effects of the LocaleMiddleware when the view
to be served will be passed the appropriate kwarg, and the kwarg is
passed to the view by configuring it so in the urlconf. The kwarg
should never make it to the admin views.

Cheers

Tom

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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate