Skip to content

Commit e0a59fb

Browse files
committed
feat: Add usage info to changelist
1 parent 6a2092d commit e0a59fb

File tree

10 files changed

+242
-145
lines changed

10 files changed

+242
-145
lines changed

djangocms_alias/admin.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from cms.utils.urlutils import admin_reverse
44
from django import forms
55
from django.contrib import admin, messages
6+
from django.db import models
67
from django.http import (
78
Http404,
89
HttpRequest,
@@ -20,7 +21,7 @@
2021
LIST_ALIAS_URL_NAME,
2122
USAGE_ALIAS_URL_NAME,
2223
)
23-
from .filters import CategoryFilter, SiteFilter
24+
from .filters import CategoryFilter, SiteFilter, UsedFilter
2425
from .models import Alias, AliasContent, Category
2526
from .utils import (
2627
emit_content_change,
@@ -34,7 +35,7 @@
3435
"AliasContentAdmin",
3536
]
3637

37-
alias_admin_list_display = ["content__name", "category", "admin_list_actions"]
38+
alias_admin_list_display = ["content__name", "category", "used", "admin_list_actions"]
3839
djangocms_versioning_enabled = AliasCMSConfig.djangocms_versioning_enabled
3940

4041
if djangocms_versioning_enabled:
@@ -67,6 +68,7 @@ class AliasAdmin(GrouperModelAdmin):
6768
list_filter = (
6869
SiteFilter,
6970
CategoryFilter,
71+
UsedFilter,
7072
)
7173
fields = ("content__name", "category", "site", "content__language")
7274
readonly_fields = ("static_code",)
@@ -79,6 +81,15 @@ def get_actions_list(self) -> list:
7981
"""Add alias usage list actions"""
8082
return super().get_actions_list() + [self._get_alias_usage_link, self._get_alias_delete_link]
8183

84+
def get_queryset(self, request):
85+
qs = super().get_queryset(request)
86+
# Annotate each Alias with a boolean indicating if related cmsplugins exist
87+
return qs.annotate(cmsplugins_count=models.Count("cms_plugins"))
88+
89+
@admin.display(description=_("Used"), boolean=True, ordering="cmsplugins_count")
90+
def used(self, obj: Alias) -> bool:
91+
return obj.cmsplugins_count > 0
92+
8293
def has_delete_permission(self, request: HttpRequest, obj: Alias = None) -> bool:
8394
# Alias can be deleted by users who can add aliases,
8495
# if that alias is not referenced anywhere.
@@ -124,9 +135,9 @@ def delete_model(self, request: HttpRequest, obj: Alias):
124135
sender=self.model,
125136
)
126137

127-
def _get_alias_usage_link(self, obj: Alias, request: HttpRequest, disabled: bool = False) -> str:
138+
def _get_alias_usage_link(self, obj: Alias, request: HttpRequest) -> str:
128139
url = admin_reverse(USAGE_ALIAS_URL_NAME, args=[obj.pk])
129-
return self.admin_action_button(url, "info", _("View usage"), disabled=disabled)
140+
return self.admin_action_button(url, "info", _("View usage"))
130141

131142
def _get_alias_delete_link(self, obj: Alias, request: HttpRequest) -> str:
132143
url = admin_reverse(DELETE_ALIAS_URL_NAME, args=[obj.pk])

djangocms_alias/filters.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,35 @@ def choices(self, changelist):
7878
"query_string": changelist.get_query_string({self.parameter_name: lookup}),
7979
"display": title,
8080
}
81+
82+
83+
class UsedFilter(admin.SimpleListFilter):
84+
title = _("Used in Alias Plugin")
85+
parameter_name = "used"
86+
87+
def lookups(self, request, model_admin):
88+
return [
89+
("yes", _("Used")),
90+
("no", _("Unused")),
91+
]
92+
93+
def queryset(self, request, queryset):
94+
value = self.value()
95+
if value == "yes":
96+
return queryset.filter(cmsplugins_count__gt=0)
97+
elif value == "no":
98+
return queryset.filter(cmsplugins_count=0)
99+
return queryset
100+
101+
def choices(self, changelist):
102+
yield {
103+
"selected": self.value() is None,
104+
"query_string": changelist.get_query_string(remove=[self.parameter_name]),
105+
"display": _("All"),
106+
}
107+
for lookup, title in self.lookup_choices:
108+
yield {
109+
"selected": self.value() == lookup,
110+
"query_string": changelist.get_query_string({self.parameter_name: lookup}),
111+
"display": title,
112+
}
159 Bytes
Binary file not shown.

djangocms_alias/locale/de/LC_MESSAGES/django.po

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,34 @@ msgid ""
1111
msgstr ""
1212
"Project-Id-Version: PACKAGE VERSION\n"
1313
"Report-Msgid-Bugs-To: \n"
14-
"POT-Creation-Date: 2025-08-22 23:06+0200\n"
14+
"POT-Creation-Date: 2025-08-26 08:10+0200\n"
1515
"PO-Revision-Date: 2023-01-10 21:21+0000\n"
1616
"Last-Translator: Fabian Braun <[email protected]>, 2025\n"
1717
"Language-Team: German (https://app.transifex.com/divio/teams/58664/de/)\n"
18+
"Language: de\n"
1819
"MIME-Version: 1.0\n"
1920
"Content-Type: text/plain; charset=UTF-8\n"
2021
"Content-Transfer-Encoding: 8bit\n"
21-
"Language: de\n"
2222
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
2323

2424
#: admin.py:78
2525
msgid "<i>Missing language</i>"
2626
msgstr "<i>Fehlende Sprache</i>"
2727

28-
#: admin.py:134 cms_toolbars.py:104
28+
#: admin.py:89 filters.py:88
29+
msgid "Used"
30+
msgstr "In Verwendung"
31+
32+
#: admin.py:140 cms_toolbars.py:103
2933
#: templates/djangocms_alias/alias_usage.html:50
3034
msgid "View usage"
3135
msgstr "Verwendung anzeigen"
3236

33-
#: admin.py:141
37+
#: admin.py:147
3438
msgid "Delete Alias"
3539
msgstr "Verlinkung löschen"
3640

37-
#: admin.py:183
41+
#: admin.py:189
3842
#, python-brace-format
3943
msgid ""
4044
"Alias content for language {} deleted. A new empty alias content will be "
@@ -47,60 +51,61 @@ msgstr ""
4751
msgid "django CMS Alias"
4852
msgstr "django CMS Alias"
4953

50-
#: cms_plugins.py:31 cms_toolbars.py:52 forms.py:270 views.py:58 views.py:326
54+
#: cms_plugins.py:37 cms_plugins.py:271 cms_plugins.py:309 cms_toolbars.py:51
55+
#: forms.py:270
5156
msgid "Alias"
5257
msgstr "Alias"
5358

54-
#: cms_plugins.py:53
59+
#: cms_plugins.py:59
5560
msgid "Edit Alias"
5661
msgstr "Alias bearbeiten"
5762

58-
#: cms_plugins.py:67
63+
#: cms_plugins.py:73
5964
msgid "Detach Alias"
6065
msgstr "Alias trennen"
6166

62-
#: cms_plugins.py:82 cms_plugins.py:99
67+
#: cms_plugins.py:88 cms_plugins.py:106
6368
msgid "Create Alias"
6469
msgstr "Alias erstellen"
6570

66-
#: cms_toolbars.py:53 cms_toolbars.py:80 templates/djangocms_alias/base.html:4
71+
#: cms_toolbars.py:52 cms_toolbars.py:79 templates/djangocms_alias/base.html:4
6772
msgid "Aliases"
6873
msgstr "Aliasse"
6974

70-
#: cms_toolbars.py:96
75+
#: cms_toolbars.py:95
7176
msgid "Change alias settings"
7277
msgstr "Alias-Einstellungen ändern"
7378

74-
#: cms_toolbars.py:114
79+
#: cms_toolbars.py:112
7580
msgid "Delete alias"
7681
msgstr "Alias löschen"
7782

78-
#: cms_toolbars.py:159 templates/djangocms_alias/create_alias.html:31
83+
#: cms_toolbars.py:157 templates/djangocms_alias/create_alias.html:31
7984
msgid "Create"
8085
msgstr "Erstellen"
8186

82-
#: cms_toolbars.py:172 internal_search.py:29
87+
#: cms_toolbars.py:170 internal_search.py:29
8388
msgid "Language"
8489
msgstr "Sprache"
8590

86-
#: cms_toolbars.py:224
91+
#: cms_toolbars.py:222
8792
msgid "Add Translation"
8893
msgstr "Übersetzung hinzufügen"
8994

90-
#: cms_toolbars.py:235
95+
#: cms_toolbars.py:233
9196
msgid "Delete Translation"
9297
msgstr "Übersetzung löschen"
9398

94-
#: cms_toolbars.py:252
99+
#: cms_toolbars.py:250
95100
msgid "Copy all plugins"
96101
msgstr "Alle Plugins kopieren"
97102

98-
#: cms_toolbars.py:254
103+
#: cms_toolbars.py:252
99104
#, python-format
100105
msgid "from %s"
101106
msgstr "von %s"
102107

103-
#: cms_toolbars.py:255
108+
#: cms_toolbars.py:253
104109
#, python-format
105110
msgid "Are you sure you want to copy all plugins from %s?"
106111
msgstr "Sind Sie sicher, dass Sie alle Plugins aus %s kopieren wollen?"
@@ -125,7 +130,7 @@ msgstr "Neue Alias-Kategorie erstellen"
125130
msgid "Site"
126131
msgstr "Site"
127132

128-
#: filters.py:37 filters.py:73
133+
#: filters.py:37 filters.py:73 filters.py:104
129134
msgid "All"
130135
msgstr "Alle"
131136

@@ -137,6 +142,14 @@ msgstr "Kein Site"
137142
msgid "Category"
138143
msgstr "Kategorie"
139144

145+
#: filters.py:83
146+
msgid "Used in Alias Plugin"
147+
msgstr "In Alias-Baustein verwendet"
148+
149+
#: filters.py:89
150+
msgid "Unused"
151+
msgstr "Nicht in Verwendung"
152+
140153
#: forms.py:78
141154
msgid "A plugin or placeholder is required to create an alias."
142155
msgstr ""
@@ -188,7 +201,7 @@ msgstr "Version-Status"
188201
msgid "Default"
189202
msgstr "Vorgabe"
190203

191-
#: models.py:51 models.py:269
204+
#: models.py:51 models.py:263
192205
msgid "name"
193206
msgstr "Name"
194207

@@ -224,31 +237,31 @@ msgstr "statischer Code"
224237
msgid "To render the alias in templates."
225238
msgstr "Um Aliasse in Vorlagen zu rendern"
226239

227-
#: models.py:104 models.py:387
240+
#: models.py:104 models.py:382
228241
msgid "alias"
229242
msgstr "Alias"
230243

231244
#: models.py:105
232245
msgid "aliases"
233246
msgstr "Aliasse"
234247

235-
#: models.py:283
248+
#: models.py:277
236249
msgid "alias content"
237250
msgstr "Alias-Inhalt"
238251

239-
#: models.py:284
252+
#: models.py:278
240253
msgid "alias contents"
241254
msgstr "Alias-Inhalte"
242255

243-
#: models.py:392
256+
#: models.py:387
244257
msgid "template"
245258
msgstr "Vorlage"
246259

247-
#: models.py:399
260+
#: models.py:394
248261
msgid "alias plugin model"
249262
msgstr "Alias-Plugin-Model"
250263

251-
#: models.py:400
264+
#: models.py:395
252265
msgid "alias plugin models"
253266
msgstr "Alias-Plugin-Modelle"
254267

@@ -259,9 +272,9 @@ msgstr "Speichern"
259272
#: templates/admin/djangocms_alias/alias/delete_confirmation.html:15
260273
#, python-format
261274
msgid ""
262-
"You don't have permissions to delete %(object_name)s \"%(escaped_object)s\"."
263-
" Please request your site admin to add permissions to delete alias, or "
264-
"delete alias from all places that it being used."
275+
"You don't have permissions to delete %(object_name)s \"%(escaped_object)s\". "
276+
"Please request your site admin to add permissions to delete alias, or delete "
277+
"alias from all places that it being used."
265278
msgstr ""
266279
"Sie haben keine Berechtigung, %(object_name)s \"%(escaped_object)s\" zu "
267280
"löschen. Bitte fragen Sie Ihren Administrator, Ihnen die Rechte zum Löschen "
@@ -276,20 +289,20 @@ msgstr ""
276289
"Sind Sie sicher, dass Sie %(object_name)s \"%(escaped_object)s\" löschen "
277290
"möchten?"
278291

279-
#: templates/admin/djangocms_alias/alias/delete_confirmation.html:24
292+
#: templates/admin/djangocms_alias/alias/delete_confirmation.html:23
280293
msgid "This alias is used by following objects:"
281294
msgstr "Dieser Alias wird von folgenden Objekten genutzt:"
282295

283-
#: templates/admin/djangocms_alias/alias/delete_confirmation.html:34
296+
#: templates/admin/djangocms_alias/alias/delete_confirmation.html:33
284297
msgid "This alias is not used by any object."
285298
msgstr "Dieser Alias wird nirgendwo genutzt."
286299

287-
#: templates/admin/djangocms_alias/alias/delete_confirmation.html:41
300+
#: templates/admin/djangocms_alias/alias/delete_confirmation.html:40
288301
#: templates/djangocms_alias/detach_alias.html:17
289302
msgid "Yes, I'm sure"
290303
msgstr "Ja, ich bin sicher!"
291304

292-
#: templates/admin/djangocms_alias/alias/delete_confirmation.html:43
305+
#: templates/admin/djangocms_alias/alias/delete_confirmation.html:42
293306
#: templates/djangocms_alias/detach_alias.html:16
294307
msgid "No, take me back"
295308
msgstr "Nein, zurück!"

0 commit comments

Comments
 (0)