decorators.py 425 B

123456789101112131415
  1. from django.core.urlresolvers import reverse
  2. from django.shortcuts import redirect
  3. from functools import wraps
  4. def require_party_login(fn):
  5. @wraps(fn)
  6. def enforce(request, party_name, *args, **kwargs):
  7. if request.user.username == party_name:
  8. return fn(request, party_name, *args, **kwargs)
  9. else:
  10. return redirect(reverse('party_login', args=[party_name]))
  11. return enforce