# Imports
from django.utils.translation import gettext_lazy as _
from superdjango import ui
# Exports
__all__ = (
"BaseHistoryModelUI",
)
# Models
[docs]class BaseHistoryModelUI(ui.ModelUI):
"""Base class for UI based on ``HistoryModel``."""
controls = {
'object_label': ui.controls.CharControl(label=_("record name")),
'object_id': ui.controls.CharControl(label=_("record ID")),
'verbose_name': ui.controls.CharControl(label=_("record type")),
}
detail_options = ui.DetailOptions(
"added_dt",
"verbose_name",
"object_label",
"action",
"performed_by",
"absolute_url",
)
list_options = ui.ListOptions(
"object_label",
"object_id",
"verbose_name",
"action",
"performed_by",
"added_dt",
link_field="object_label"
)
[docs] def check_permission(self, request, verb, field=None, record=None):
"""Only super users have delete access. All others are checked only for detail and list permissions."""
if verb == ui.VERB.DELETE:
return request.user.is_superuser
if verb in (ui.VERB.DETAIL, ui.VERB.LIST):
return super().check_permission(request, verb, field=field, record=record)
return False