Utility functions for template tags¶
Like _add_link_to_context(), but allows for using a specific named permission, and any named url on the modeladmin, with optional url parameters.
Uses _add_link_to_context() internally once it has established the permissions are OK.
Always returns a dictionary with two keys, whose values may be empty strings.
Parameters: - admin_site – the string name of an admin site; eg: admin
- request – the current WSGIRequest
- opts – the _meta Options object to get the app_label and module_name for the desired URL.
- permname – The permission name to find; eg: add, change, delete
- viewname – The name of the view to find; eg: changelist, donkey
- url_params – a list of items to be passed as args to the underlying use of reverse.
- query – querystring to append.
Returns: a dictionary containing link and verbose_name keys, whose values are the reversed URL and the display name of the object. Both may be blank.
Return type: dictionary
Find out if a model is in our known list and at has least 1 permission. If it’s in there, try and reverse the URL to return a dictionary for the final Inclusion Tag’s context.
Always returns a dictionary with two keys, whose values may be empty strings.
Parameters: - admin_site – the string name of an admin site; eg: admin
- request – the current WSGIRequest
- opts – the _meta Options object to get the app_label and module_name for the desired URL.
- permname – The permission name to find; eg: add, change, delete
- url_params – a list of items to be passed as args to the underlying use of reverse.
- query – querystring to append.
Returns: a dictionary containing link and verbose_name keys, whose values are the reversed URL and the display name of the object. Both may be blank.
Return type: dictionary
Minor wrapper around reverse(), catching the NoReverseMatch that may be thrown, and instead returning an empty unicode string.
Parameters: - urlname – the view, or named URL to be reversed
- params – any parameters (as args, not kwargs) required to create the correct URL.
Returns: the URL discovered, or an empty string
Return type: unicode string
If we’re not at 1.6, the changelist uses “pop” in the querystring.
Changed in version 0.8.1: Returns a tuple of the querystring and a boolean of whether or not
A pulled-up-and-out version of the sorting the standard Django AdminSite does on the index view.
Parameters: modeladmins – dictionary of modeladmins Returns: the same modeladmins, with their ordering changed. Return type: list
Given a context, determine whether a User exists, and if they see anything.
Changed in version 0.8.1: if DEBUG is True, then better error messages are displayed to the user, as a reminder of what settings need to be in place. Previously it was dependent on having a LOGGING configuration that would show the messages.
Parameters: context – a RequestContext. Accepts any Context like object, but it explicitly tests for a request key and request.user Returns: whether or not the given context should allow further processing. Return type: True or False
Given the name of an AdminSite instance, try to resolve that into an actual object
Note
This function is exposed in the public API as get_admin_site(), which uses memoization to cache discovered AdminSite objects.
Parameters: admin_site – the string name of an AdminSite named and mounted on the project. Returns: an AdminSite instance matching that given in the admin_site parameter. Return type: AdminSite or None
Taken from AdminSite, find all ModelAdmin classes attached to the given admin and compile a dictionary of Model types visible to the current User, limiting the methods available (add/edit/history/delete) as appropriate.
Always returns a dictionary, though it may be empty, and thus evaluate as Falsy.
Parameters: - request – the current request, for permissions checking etc.
- admin_site – a concrete AdminSite named and mounted on the project.
Returns: visible ModelAdmin classes.
Return type: dictionary