forked from ietf-tools/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecorators.py
More file actions
22 lines (16 loc) · 826 Bytes
/
decorators.py
File metadata and controls
22 lines (16 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Copyright The IETF Trust 2012-2020, All Rights Reserved
# -*- coding: utf-8 -*-
import functools
from urllib.parse import quote as urlquote
from django.urls import reverse
from django.http import HttpResponseRedirect
def nomcom_private_key_required(view_func):
def inner(request, *args, **kwargs):
year = kwargs.get('year', None)
if not year:
raise Exception('View decorated with nomcom_private_key_required must receive a year argument')
if not 'NOMCOM_PRIVATE_KEY_%s' % year in request.session:
return HttpResponseRedirect('%s?back_to=%s' % (reverse('ietf.nomcom.views.private_key', None, args=(year, )), urlquote(request.get_full_path())))
else:
return view_func(request, *args, **kwargs)
return functools.update_wrapper(inner, view_func)