Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def decorated_view(request, *args, **kwargs):
user = request.user
if user.is_anonymous:
return reject_request(request)
if user.has_perms(['wagtailadmin.access_admin']):
preferred_language = None
if hasattr(user, 'wagtail_userprofile'):
preferred_language = user.wagtail_userprofile.get_preferred_language()
l18n.set_language(preferred_language)
time_zone = user.wagtail_userprofile.get_current_time_zone()
activate_tz(time_zone)
if preferred_language:
with override(preferred_language):
return view_func(request, *args, **kwargs)
else:
return view_func(request, *args, **kwargs)
if not request.is_ajax():
messages.error(request, _('You do not have permission to access the admin'))
return reject_request(request)
def _get_time_zone_choices():
time_zones = [(tz, str(l18n.tz_fullnames.get(tz, tz)))
for tz in get_available_admin_time_zones()]
time_zones.sort(key=itemgetter(1))
return BLANK_CHOICE_DASH + time_zones