kopia lustrzana https://github.com/wagtail/wagtail
Add object type column to site history report
rodzic
917b4ebd07
commit
ce3a3daffa
|
@ -5,6 +5,7 @@ from django.utils.translation import gettext_lazy as _
|
||||||
from django_filters.widgets import SuffixedMultiWidget
|
from django_filters.widgets import SuffixedMultiWidget
|
||||||
|
|
||||||
from wagtail.admin.widgets import AdminDateInput, BooleanButtonSelect, ButtonSelect, FilteredSelect
|
from wagtail.admin.widgets import AdminDateInput, BooleanButtonSelect, ButtonSelect, FilteredSelect
|
||||||
|
from wagtail.core.utils import get_content_type_label
|
||||||
|
|
||||||
|
|
||||||
class DateRangePickerWidget(SuffixedMultiWidget):
|
class DateRangePickerWidget(SuffixedMultiWidget):
|
||||||
|
@ -107,12 +108,7 @@ class ContentTypeModelChoiceField(django_filters.fields.ModelChoiceField):
|
||||||
than the default 'wagtailcore | page' representation of a ContentType
|
than the default 'wagtailcore | page' representation of a ContentType
|
||||||
"""
|
"""
|
||||||
def label_from_instance(self, obj):
|
def label_from_instance(self, obj):
|
||||||
model = obj.model_class()
|
return get_content_type_label(obj)
|
||||||
if model:
|
|
||||||
return model._meta.verbose_name.capitalize()
|
|
||||||
else:
|
|
||||||
# no corresponding model class found; fall back on the name field of the ContentType
|
|
||||||
return obj.model
|
|
||||||
|
|
||||||
|
|
||||||
class ContentTypeFilter(django_filters.ModelChoiceFilter):
|
class ContentTypeFilter(django_filters.ModelChoiceFilter):
|
||||||
|
|
|
@ -7,7 +7,10 @@
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="title">
|
<th class="title">
|
||||||
{% trans 'Page' %}
|
{% trans 'Item' %}
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
{% trans 'Object type' %}
|
||||||
</th>
|
</th>
|
||||||
<th>
|
<th>
|
||||||
{% trans 'Action' %}
|
{% trans 'Action' %}
|
||||||
|
@ -35,6 +38,9 @@
|
||||||
{{ entry.label }}
|
{{ entry.label }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
|
<td>
|
||||||
|
{{ entry.content_type|format_content_type }}
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ entry.message }}
|
{{ entry.message }}
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -37,7 +37,7 @@ from wagtail.core.models import (
|
||||||
from wagtail.core.telepath import JSContext
|
from wagtail.core.telepath import JSContext
|
||||||
from wagtail.core.utils import camelcase_to_underscore
|
from wagtail.core.utils import camelcase_to_underscore
|
||||||
from wagtail.core.utils import cautious_slugify as _cautious_slugify
|
from wagtail.core.utils import cautious_slugify as _cautious_slugify
|
||||||
from wagtail.core.utils import escape_script
|
from wagtail.core.utils import escape_script, get_content_type_label
|
||||||
from wagtail.users.utils import get_gravatar_url
|
from wagtail.users.utils import get_gravatar_url
|
||||||
|
|
||||||
|
|
||||||
|
@ -659,6 +659,11 @@ def user_display_name(user):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def format_content_type(content_type):
|
||||||
|
return get_content_type_label(content_type)
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def i18n_enabled():
|
def i18n_enabled():
|
||||||
return getattr(settings, 'WAGTAIL_I18N_ENABLED', False)
|
return getattr(settings, 'WAGTAIL_I18N_ENABLED', False)
|
||||||
|
|
|
@ -155,7 +155,11 @@ class LogEntriesView(ReportView):
|
||||||
# and build a lookup table
|
# and build a lookup table
|
||||||
object_lookup = {}
|
object_lookup = {}
|
||||||
for log_model_index, pks in pks_by_log_model_index.items():
|
for log_model_index, pks in pks_by_log_model_index.items():
|
||||||
log_entries = self.log_models[log_model_index].objects.prefetch_related('user__wagtail_userprofile').in_bulk(pks)
|
log_entries = (
|
||||||
|
self.log_models[log_model_index].objects
|
||||||
|
.prefetch_related('user__wagtail_userprofile', 'content_type')
|
||||||
|
.in_bulk(pks)
|
||||||
|
)
|
||||||
for pk, log_entry in log_entries.items():
|
for pk, log_entry in log_entries.items():
|
||||||
object_lookup[(log_model_index, pk)] = log_entry
|
object_lookup[(log_model_index, pk)] = log_entry
|
||||||
|
|
||||||
|
|
|
@ -136,6 +136,19 @@ def safe_snake_case(value):
|
||||||
return snake_case_string
|
return snake_case_string
|
||||||
|
|
||||||
|
|
||||||
|
def get_content_type_label(content_type):
|
||||||
|
"""
|
||||||
|
Return a human-readable label for a content type object, suitable for display in the admin
|
||||||
|
in place of the default 'wagtailcore | page' representation
|
||||||
|
"""
|
||||||
|
model = content_type.model_class()
|
||||||
|
if model:
|
||||||
|
return model._meta.verbose_name.capitalize()
|
||||||
|
else:
|
||||||
|
# no corresponding model class found; fall back on the name field of the ContentType
|
||||||
|
return content_type.model.capitalize()
|
||||||
|
|
||||||
|
|
||||||
def accepts_kwarg(func, kwarg):
|
def accepts_kwarg(func, kwarg):
|
||||||
"""
|
"""
|
||||||
Determine whether the callable `func` has a signature that accepts the keyword argument `kwarg`
|
Determine whether the callable `func` has a signature that accepts the keyword argument `kwarg`
|
||||||
|
|
Ładowanie…
Reference in New Issue