Admin classes

These provide additional functionality which may be depended on by django-adminlinks or related packages.

class adminlinks.admin.AdminUrlWrap[source]

A minor helper for mixing into ModelAdmin instances, exposing the url wrapping function used in the standard get_urls().

_get_wrap()[source]

Returns some magical decorated view that applies admin_view() to a ModelAdmin view:

from django.contrib.admin import ModelAdmin

class MyObj(AdminUrlWrap, ModelAdmin):

    def do_something(self):
        wrapper = self._get_wrap()
        wrapped_view = wrapper(self.my_custom_view)
        return wrapped_view
Returns:a decorated view.
class adminlinks.admin.AdminlinksMixin[source]

Our mixin, which serves two purposes:

  • Allows for per-field editing through the use of the use of change_field_view().

    • Per-field editing requires the change permission for the object.
    • Per-field editing is not exposed in the AdminSite at all.
    • Per-field editing may be enabled in the frontend by using the EditField template tag
  • Allows for the following views to be automatically closed on success, using a customisable template (see get_success_templates() for how template discovery works.)

change_field_view(*args, **kwargs)[source]

Allows a user to view a form with only one field (named in the URL args) to edit. All others are ignored.

data_changed(querydict)[source]

Can be passed things like request.GET, or just dictionaries, whatever. This is our magic querystring variable.

New in version 0.8.1.

delete_view(request, object_id, extra_context=None)[source]

Overrides the Django default, to try and provide a better experience for frontend editing when deleting an object successfully.

Ridiculously, there’s no response_delete method to patch, so instead we’re just going to do a similar thing and hope for the best.

get_changelist(request, **kwargs)[source]

If the changelist hasn’t been customised, lets just replace it with our own, which should allow us to track data changes without erroring.

New in version 0.8.1.

get_response_add_context(request, obj)[source]

Provides a context for the template discovered by get_success_templates(). Only used when we could reliably determine that the request was in our JavaScript modal window, allowing us to close it automatically.

For clarity’s sake, it should always return the minimum values represented here.

Returns:Data which may be given to a template. Must be JSON serializable, so that a template may pass it back to the browser’s JavaScript engine.
Return type:a dictionary.
get_response_change_context(request, obj)[source]

Provides a context for the template discovered by get_success_templates(). Only used when we could reliably determine that the request was in our JavaScript modal window, allowing us to close it automatically.

For clarity’s sake, it should always return the minimum values represented here.

Returns:Data which may be given to a template. Must be JSON serializable, so that a template may pass it back to the browser’s JavaScript engine.
Return type:a dictionary.
get_response_delete_context(request, obj_id, extra_context)[source]

Provides a context for the template discovered by get_success_templates(). Only used when we could reliably determine that the request was in our JavaScript modal window, allowing us to close it automatically.

For clarity’s sake, it should always return the minimum values represented here.

Note

At the point this is called, the original object no longer exists, so we are stuck trusting the obj_id given as an argument.

Changed in version Introduced: extra_context parameter.

Returns:Data which may be given to a template. Must be JSON serializable, so that a template may pass it back to the browser’s JavaScript engine.
Return type:a dictionary.
get_success_templates(request)[source]
Forces the attempted loading of the following:
  • a template for this model.
  • a template for this app.
  • a template for any parent model.
  • a template for any parent app.
  • a guaranteed to exist template (the base success file)
Parameters:request – The WSGIRequest
Returns:list of strings representing templates to look for.
maybe_fix_redirection(request, response, obj=None)[source]

This is a middleware-ish thing for marking whether a redirect needs to say data changed ... it’s pretty complex, so has lots of comments.

New in version 0.8.1.

response_add(request, obj, *args, **kwargs)[source]

Overrides the Django default, to try and provide a better experience for frontend editing when adding a new object.

response_change(request, obj, *args, **kwargs)[source]

Overrides the Django default, to try and provide a better experience for frontend editing when editing an existing object.

should_autoclose(request)[source]

New in version 0.8.1.

Returns:Whether or not _autoclose was in the request and whether Save was pressed, or whether Save and add another/continue editing was.
wants_to_autoclose(request)[source]

New in version 0.8.1.

Returns:Whether or not _autoclose was in the request
wants_to_continue_editing(request)[source]

New in version 0.8.1.

Returns:Whether Save was pressed, or whether Save and add another/continue editing was.