Skip to content

Commit

Permalink
Clean session nav_menu cache when switch the language.
Browse files Browse the repository at this point in the history
  • Loading branch information
sshwsfc committed Sep 21, 2016
1 parent 74f673f commit 614439d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions xadmin/plugins/language.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@

from django.conf import settings
from django.template import loader
from django.views.i18n import set_language
from xadmin.plugins.utils import get_context_dict
from xadmin.sites import site
from xadmin.views import BaseAdminPlugin, CommAdminView
from xadmin.views import BaseAdminPlugin, CommAdminView, BaseAdminView


class SetLangNavPlugin(BaseAdminPlugin):
Expand All @@ -13,6 +14,13 @@ def block_top_navmenu(self, context, nodes):
context['redirect_to'] = self.request.get_full_path()
nodes.append(loader.render_to_string('xadmin/blocks/comm.top.setlang.html', context=context))

class SetLangView(BaseAdminView):

def post(self, request, *args, **kwargs):
if 'nav_menu' in request.session:
del request.session['nav_menu']
return set_language(request)

if settings.LANGUAGES and 'django.middleware.locale.LocaleMiddleware' in settings.MIDDLEWARE_CLASSES:
site.register_plugin(SetLangNavPlugin, CommAdminView)
site.register_view(r'^i18n/', lambda site: 'django.conf.urls.i18n', 'i18n')
site.register_view(r'^i18n/setlang/$', SetLangView, 'set_language')

0 comments on commit 614439d

Please sign in to comment.