anonymous_required decorator

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
from django.contrib.auth.decorators import user_passes_test
from django.conf import settings


def anonymous_required(function=None, redirect_url=None):
    if not redirect_url:
        redirect_url = settings.LOGIN_REDIRECT_URL

    actual_decorator = user_passes_test(
        lambda u: u.is_anonymous(),
        login_url=redirect_url
    )

    if function:
        return actual_decorator(function)
    return actual_decorator

More like this

  1. Cache Decorator by ericmoritz 5 years, 4 months ago
  2. render_to_response decorator by coleifer 3 years, 7 months ago
  3. Stales Cache Class Method Decorator by amitu 5 years, 6 months ago
  4. Conditional cache decorator by alexisbellido 1 year, 8 months ago
  5. Commit on success unless managed decorator by Kronuz 4 years, 7 months ago

Comments

(Forgotten your password?)