decorators.py 805 B

12345678910111213141516171819
  1. from django.utils.translation import ugettext as _
  2. from misago.views import error403
  3. def block_authenticated(f):
  4. def decorator(*args, **kwargs):
  5. request = args[0]
  6. if not request.firewall.admin and request.user.is_authenticated():
  7. return error403(request, _("%{username}s, this page is not available to signed in users.") % {'username': request.user.username})
  8. return f(*args, **kwargs)
  9. return decorator
  10. def block_guest(f):
  11. def decorator(*args, **kwargs):
  12. request = args[0]
  13. if not request.user.is_authenticated():
  14. return error403(request, _("Dear Guest, only signed in members are allowed to access this page. Please sign in or register and try again."))
  15. return f(*args, **kwargs)
  16. return decorator