approval.admin.sandbox API documentation

# approval.admin.sandbox

Django Admin configuration for approval.

Attributes: SandboxAdmin: The `ApprovalAdmin` class configures the Administration interface to help admins monitor all the changed still pending in every approval-enabled model.

View Source

     1"""
     2Django Admin configuration for approval.
     3
     4Attributes:
     5    SandboxAdmin:
     6        The `ApprovalAdmin` class configures the Administration interface
     7        to help admins monitor all the changed still pending in every
     8        approval-enabled model.
     9"""
    10from django.contrib.admin import display
    11from django.contrib.admin.options import ModelAdmin
    12from django.template.loader import render_to_string
    13from django.utils.safestring import mark_safe
    14from django.utils.translation import gettext_lazy as _
    15
    16
    17class SandboxAdmin(ModelAdmin):
    18    """Moderation of approval sandboxes."""
    19
    20    list_select_related = True
    21    list_display = ["id", "source", "moderator", "approved", "draft", "updated", "get_sandbox_data"]
    22    readonly_fields = ["source"]
    23    list_display_links = ["id"]
    24    list_filter = ["approved", "draft", "updated", "moderator__is_superuser"]
    25    actions = ["do_deny", "do_approve"]
    26
    27    # Actions
    28    @display(description=_("Deny selected approval requests"))
    29    def do_deny(self, request, queryset):
    30        """Refuse selected approval requests."""
    31        for approval in queryset:
    32            approval.deny(user=request.user, save=True)
    33        self.message_user(request, _("Selected edits have been denied."))
    34
    35    @display(description=_("Approve selected approval requests"))
    36    def do_approve(self, request, queryset):
    37        """Accept selected approval requests."""
    38        for approval in queryset:
    39            approval.approve(user=request.user, save=True)
    40        if approval.delete_on_approval:
    41            self.message_user(request, _("Upon approval, deletion has been performed."))
    42        self.message_user(request, _("Selected edits have been accepted."))
    43
    44    # Getter
    45    @display(description=_("Content"))
    46    def get_sandbox_data(self, obj) -> str:
    47        """Return a human-readable version of the sandbox contents."""
    48        fields = obj.sandbox.get("fields", {})
    49        store = obj.sandbox.get("store", {})
    50        return mark_safe(
    51            render_to_string(
    52                "approval/display/sandbox-data.html", {"fields": fields, "store": store}
    53            )
    54        )

class SandboxAdmin(django.contrib.admin.options.ModelAdmin): View Source

    18class SandboxAdmin(ModelAdmin):
    19    """Moderation of approval sandboxes."""
    20
    21    list_select_related = True
    22    list_display = ["id", "source", "moderator", "approved", "draft", "updated", "get_sandbox_data"]
    23    readonly_fields = ["source"]
    24    list_display_links = ["id"]
    25    list_filter = ["approved", "draft", "updated", "moderator__is_superuser"]
    26    actions = ["do_deny", "do_approve"]
    27
    28    # Actions
    29    @display(description=_("Deny selected approval requests"))
    30    def do_deny(self, request, queryset):
    31        """Refuse selected approval requests."""
    32        for approval in queryset:
    33            approval.deny(user=request.user, save=True)
    34        self.message_user(request, _("Selected edits have been denied."))
    35
    36    @display(description=_("Approve selected approval requests"))
    37    def do_approve(self, request, queryset):
    38        """Accept selected approval requests."""
    39        for approval in queryset:
    40            approval.approve(user=request.user, save=True)
    41        if approval.delete_on_approval:
    42            self.message_user(request, _("Upon approval, deletion has been performed."))
    43        self.message_user(request, _("Selected edits have been accepted."))
    44
    45    # Getter
    46    @display(description=_("Content"))
    47    def get_sandbox_data(self, obj) -> str:
    48        """Return a human-readable version of the sandbox contents."""
    49        fields = obj.sandbox.get("fields", {})
    50        store = obj.sandbox.get("store", {})
    51        return mark_safe(
    52            render_to_string(
    53                "approval/display/sandbox-data.html", {"fields": fields, "store": store}
    54            )
    55        )

Moderation of approval sandboxes.

list_select_related = True
list_display = ['id', 'source', 'moderator', 'approved', 'draft', 'updated', 'get_sandbox_data']
readonly_fields = ['source']
list_display_links = ['id']
list_filter = ['approved', 'draft', 'updated', 'moderator__is_superuser']
actions = ['do_deny', 'do_approve']
@display(description=_('Deny selected approval requests'))
def do_deny(self, request, queryset): View Source

    29    @display(description=_("Deny selected approval requests"))
    30    def do_deny(self, request, queryset):
    31        """Refuse selected approval requests."""
    32        for approval in queryset:
    33            approval.deny(user=request.user, save=True)
    34        self.message_user(request, _("Selected edits have been denied."))

Refuse selected approval requests.

@display(description=_('Approve selected approval requests'))
def do_approve(self, request, queryset): View Source

    36    @display(description=_("Approve selected approval requests"))
    37    def do_approve(self, request, queryset):
    38        """Accept selected approval requests."""
    39        for approval in queryset:
    40            approval.approve(user=request.user, save=True)
    41        if approval.delete_on_approval:
    42            self.message_user(request, _("Upon approval, deletion has been performed."))
    43        self.message_user(request, _("Selected edits have been accepted."))

Accept selected approval requests.

@display(description=_('Content'))
def get_sandbox_data(self, obj) -> str: View Source

    46    @display(description=_("Content"))
    47    def get_sandbox_data(self, obj) -> str:
    48        """Return a human-readable version of the sandbox contents."""
    49        fields = obj.sandbox.get("fields", {})
    50        store = obj.sandbox.get("store", {})
    51        return mark_safe(
    52            render_to_string(
    53                "approval/display/sandbox-data.html", {"fields": fields, "store": store}
    54            )
    55        )

Return a human-readable version of the sandbox contents.

media View Source

    193    def _media(self):
    194        # Get the media property of the superclass, if it exists
    195        sup_cls = super(cls, self)
    196        try:
    197            base = sup_cls.media
    198        except AttributeError:
    199            base = Media()
    200
    201        # Get the media definition for this class
    202        definition = getattr(cls, "Media", None)
    203        if definition:
    204            extend = getattr(definition, "extend", True)
    205            if extend:
    206                if extend is True:
    207                    m = base
    208                else:
    209                    m = Media()
    210                    for medium in extend:
    211                        m += base[medium]
    212                return m + Media(definition)
    213            return Media(definition)
    214        return base

##### Inherited Members

django.contrib.admin.options.ModelAdmin
  ModelAdmin
  list_per_page
  list_max_show_all
  list_editable
  search_fields
  search_help_text
  date_hierarchy
  save_as
  save_as_continue
  save_on_top
  paginator
  preserve_filters
  inlines
  add_form_template
  change_form_template
  change_list_template
  delete_confirmation_template
  delete_selected_confirmation_template
  object_history_template
  popup_response_template
  action_form
  actions_on_top
  actions_on_bottom
  actions_selection_counter
  checks_class
  model
  opts
  admin_site
  get_inline_instances
  get_urls
  urls
  get_model_perms
  get_form
  get_changelist
  get_changelist_instance
  get_object
  get_changelist_form
  get_changelist_formset
  get_formsets_with_inlines
  get_paginator
  log_addition
  log_change
  log_deletion
  action_checkbox
  get_actions
  get_action_choices
  get_action
  get_list_display
  get_list_display_links
  get_list_filter
  get_list_select_related
  get_search_fields
  get_search_results
  get_preserved_filters
  construct_change_message
  message_user
  save_form
  save_model
  delete_model
  delete_queryset
  save_formset
  save_related
  render_change_form
  response_add
  response_change
  response_post_save_add
  response_post_save_change
  response_action
  response_delete
  render_delete_form
  get_inline_formsets
  get_changeform_initial_data
  changeform_view
  add_view
  change_view
  changelist_view
  get_deleted_objects
  delete_view
  history_view
  get_formset_kwargs
django.contrib.admin.options.BaseModelAdmin
  autocomplete_fields
  raw_id_fields
  fields
  exclude
  fieldsets
  form
  filter_vertical
  filter_horizontal
  radio_fields
  prepopulated_fields
  formfield_overrides
  ordering
  sortable_by
  view_on_site
  show_full_result_count
  check
  formfield_for_dbfield
  formfield_for_choice_field
  get_field_queryset
  formfield_for_foreignkey
  formfield_for_manytomany
  get_autocomplete_fields
  get_view_on_site_url
  get_empty_value_display
  get_exclude
  get_fields
  get_fieldsets
  get_inlines
  get_ordering
  get_readonly_fields
  get_prepopulated_fields
  get_queryset
  get_sortable_by
  lookup_allowed
  to_field_allowed
  has_add_permission
  has_change_permission
  has_delete_permission
  has_view_permission
  has_view_or_change_permission
  has_module_permission