Source code for superdjango.db.completed.admin

# Imports

from django.contrib import admin
from django.utils.translation import ugettext_lazy as _
from ..audit.utils import is_audit_model
from .filters import CompletedByListFilter

# Exports

__all__ = (
    "BaseCompletedByAdmin",
)

# Models


[docs]class BaseCompletedByAdmin(admin.ModelAdmin): """Base admin class for models implementing the ``CompletedByModel``."""
[docs] def get_actions(self, request): return [ "mark_complete", "mark_incomplete", ]
[docs] def get_fields(self, request, obj=None): return [ "is_complete", ]
[docs] def get_list_display(self, request): return [ "completed_by", "completed_dt", "is_complete", ]
[docs] def get_list_filter(self, request): return [ "is_complete", CompletedByListFilter, ]
[docs] def mark_complete(self, request, queryset): """Mark a set of records as complete.""" count = 0 for row in queryset: row.mark_complete(request.user) count += 1 self.message_user(request, _("Marked %s records complete." % count))
mark_complete.short_description = _("Mark Selected Records as Complete")
[docs] def mark_incomplete(self, request, queryset): """Mark a set of records as complete.""" count = 0 for row in queryset: row.mark_incomplete() count += 1 self.message_user(request, _("Marked %s records incomplete." % count))
mark_incomplete.short_description = _("Mark Selected Records as Incomplete")
[docs] def save_model(self, request, obj, form, change): # It is safe to call mark_complete() even when the record has already been marked as archived. if obj.is_complete: obj.mark_complete(request.user, commit=False) super().save_model(request, obj, form, change)