def POST(self): if self.request.user.is_authenticated(): self.request.user.lang_code = self.request.POST.get( 'language', None) self.request.user.save() return django_set_language(self.request)
def set_language(request): """ Call default django set_language but set language cookie to advise caching middleware """ lang_code = request.POST.get('language', None) response = django_set_language(request) if lang_code: response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code) return response
def set_language(request): auth_user = request.user.is_authenticated() lang_code = request.POST.get('language', None) request.session[LANGUAGE_SESSION_KEY] = lang_code if auth_user: set_user_preference(request.user, DARK_LANGUAGE_KEY, lang_code) return django_set_language(request) # we can return a simple redirect response, but I left this in place just in case !
def set_language(request): if request.method == 'POST': if request.POST.get('language'): language = request.POST['language'].lower() if language.startswith('<'): # Internet Explorer sends the contents of the <button> tag # instead of its value startPos = language.find(START) + len(START) - 1 endPos = language.find(END, startPos) language = language[startPos:endPos] request.POST = request.POST.copy() request.POST['language'] = language return django_set_language(request)
def POST(self): if self.request.user.is_authenticated(): self.request.user.lang_code = self.request.POST.get('language', None) self.request.user.save() return django_set_language(self.request)
def POST(self): return self.GET() class SetLanguage(ViewClass): """ Extends django's set_language view to save the user's language in his profile """ def POST(self): if self.request.user.is_authenticated(): self.request.user.lang_code = self.request.POST.get('language', None) self.request.user.save() return django_set_language(self.request) class Report(ViewClass): def __init__(self, report=1): from main.management.commands.report import reports self.report = reports[report - 1] @user_passes_test(lambda u: u.is_superuser) def GET(self): return HttpResponse(self.report(), mimetype="application/x-download") index = Index() contact = Contact() <<<<<<< HEAD