Customized decorators that enhance the default behavior of django.contrib.auth.decorators.permission_required().
The default behavior of django.contrib.auth.decorators.permission_required() for any user does not meet the required permission level is to redirect them to the login page– even if that user is already logged in. For more discussion of this behavior and current status in Django, see: http://code.djangoproject.com/ticket/4617
These decorators work the same way as the Django equivalents, with the added feature that if the user is already logged in and does not have the required permission, they will see 403 page instead of the login page.
The decorators should be used exactly the same as their django equivalents.
The code is based on the django snippet code at http://djangosnippets.org/snippets/254/
View decorator that checks to see if the user passes the specified test. See django.contrib.auth.decorators.user_passes_test().
Anonymous users will be redirected to login_url, while logged in users that fail the test will be given a 403 error. In the case of a 403, the function will render the 403.html template.
Decorator for views that checks whether a user has a particular permission enabled, redirecting to the login page or rendering a 403 as necessary.
See django.contrib.auth.decorators.permission_required().
Decorator for views that checks that the user passes the given test, redirecting to the log-in page if necessary. The test should be a callable that takes the user object and returns True if the user passes.
Returns special response to ajax calls instead of blindly redirecting.
To use with class methods instead of functions, use django.utils.decorators.method_decorator(). See http://docs.djangoproject.com/en/dev/releases/1.2/#user-passes-test-login-required-and-permission-required
Decorator for views that checks that the user is logged in, redirecting to the log-in page if necessary, but returns a special response for ajax requests. See eulcore.django.auth.decorators.user_passes_test_with_ajax().
Decorator for views that checks whether a user has a particular permission enabled, redirecting to the log-in page if necessary, but returns a special response for ajax requests. See eulcore.django.auth.decorators.user_passes_test_with_ajax().
Custom generic form fields for use with Django forms.
W3C date field that uses a W3CDateWidget for presentation and uses a simple regular expression to do basic validation on the input (but does not actually test that it is a valid date).
alias of W3CDateWidget
Multi-part date widget that generates three text input boxes for year, month, and day. Expects and generates dates in any of these W3C formats, depending on which fields are filled in: YYYY-MM-DD, YYYY-MM, or YYYY.
Generate and render a django.forms.widgets.TextInput for a single year, month, or day input.
If size is specified in the extra attributes, it will also be used to set the maximum length of the field.
Parameters: |
|
---|---|
Returns: | rendered HTML output for the text input |
Render the widget as HTML inputs for display on a form.
Parameters: |
|
---|---|
Returns: | HTML text with three inputs for year/month/day |
Generate a single value from multi-part form data. Constructs a W3C date based on values that are set, leaving out day and month if they are not present.
Parameters: |
|
---|---|
Returns: | string value |
A django.forms.ChoiceField whose choices are not static, but instead generated dynamically when referenced.
Parameters: | choices – callable; this will be called to generate choices each time they are referenced |
---|
alias of DynamicSelect
A Select widget whose choices are not static, but instead generated dynamically when referenced.
Parameters: | choices – callable; this will be called to generate choices each time they are referenced. |
---|