Skip to content

Commit

Permalink
Add VinaigrettteAdminLanguageMiddleware to avoid using vinaigrette in…
Browse files Browse the repository at this point in the history
… the admin.
  • Loading branch information
rory-geoghegan-ecometrica committed Apr 18, 2014
1 parent 100579e commit a8d15e1
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion vinaigrette/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import re

from django.db.models.signals import pre_save, post_save
from django.utils.translation import ugettext, ugettext_lazy
from django.conf import settings
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext, ugettext_lazy, activate, get_language

class VinaigretteError(Exception):
pass
Expand Down Expand Up @@ -69,3 +71,26 @@ def __get__(self, obj, type=None):

def __set__(self, obj, value):
obj.__dict__[self.name] = value


class VinaigrettteAdminLanguageMiddleware(object):
"""
Use this middleware to ensure the admin is always running under the
default language, to prevent vinaigrette from clobbering the registered
fields with the user's picked language in the change views. Aslo make
sure that this is after any LocaleMiddleware like classes.
"""

def is_admin_request(self, request):
"""
Returns True if this request is for the admin views.
"""
return request.path.startswith(reverse('admin:index'))

def process_request(self, request):
print("***** RORY: path: %r admin: %r" % ( request.path, reverse('admin:index')))
if not self.is_admin_request(request):
return None

# We are in the admin site
activate(settings.LANGUAGE_CODE)

0 comments on commit a8d15e1

Please sign in to comment.