Login

anonymous_required decorator

Author:
yetty
Posted:
July 4, 2013
Language:
Python
Version:
1.5
Tags:
decorator auth anonymous
Score:
1 (after 1 ratings)

Decorator to preserve view from logged users.

 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 6 years, 4 months ago
  2. render_to_response decorator by coleifer 4 years, 7 months ago
  3. Stales Cache Class Method Decorator by amitu 6 years, 6 months ago
  4. Conditional cache decorator by alexisbellido 2 years, 7 months ago
  5. Commit on success unless managed decorator by Kronuz 5 years, 7 months ago

Comments

Please login first before commenting.