Skip to content

Commit dc7a428

Browse files
Improve event registration admin UI.
1 parent 62239ce commit dc7a428

3 files changed

Lines changed: 77 additions & 29 deletions

File tree

django/geno/admin.py

Lines changed: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,15 @@ def __init__(self, model, admin_site):
130130
and module_name in settings.COHIVA_ADMIN_FIELDS
131131
):
132132
class_name = type(self).__name__
133-
for attr in ("fields", "readonly_fields", "list_display", "list_filter"):
133+
for attr in (
134+
"fields",
135+
"fieldsets",
136+
"readonly_fields",
137+
"search_fields",
138+
"autocomplete_fields",
139+
"list_display",
140+
"list_filter",
141+
):
134142
setting_name = f"{class_name}.{attr}"
135143
if setting_name in settings.COHIVA_ADMIN_FIELDS[module_name]:
136144
setattr(self, attr, settings.COHIVA_ADMIN_FIELDS[module_name][setting_name])
@@ -892,7 +900,7 @@ class RegistrationSlotAdmin(GenoBaseAdmin):
892900
autocomplete_fields = ["event", "is_backup_for"]
893901

894902

895-
class RegistrationSlotInline(admin.TabularInline):
903+
class RegistrationSlotInline(TabularInline):
896904
model = RegistrationSlot
897905
fields = ["name", "alt_text", "max_places", "is_backup_for", "comment"]
898906

@@ -909,32 +917,57 @@ def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
909917
@admin.register(RegistrationEvent)
910918
class RegistrationEventAdmin(GenoBaseAdmin):
911919
model = RegistrationEvent
912-
fields = [
920+
fieldsets = (
921+
(
922+
None,
923+
{
924+
"fields": (
925+
"name",
926+
"description",
927+
"confirmation_mail_sender",
928+
"confirmation_mail_text",
929+
("publication_type", "active"),
930+
("publication_start", "publication_end"),
931+
"show_counter",
932+
)
933+
},
934+
),
935+
(
936+
"Anmeldeformular",
937+
{
938+
"fields": (
939+
("enable_notes", "enable_telephone"),
940+
"check1_label",
941+
"check2_label",
942+
"check3_label",
943+
"check4_label",
944+
"check5_label",
945+
"text1_label",
946+
"text2_label",
947+
"text3_label",
948+
"text4_label",
949+
"text5_label",
950+
),
951+
"classes": ["tab"],
952+
},
953+
),
954+
(
955+
"Zusatzinfos",
956+
{
957+
"fields": ("registration_link", "comment", "ts_created", "ts_modified"),
958+
"classes": ["tab"],
959+
},
960+
),
961+
("Verknüpfungen", {"fields": ("links", "backlinks"), "classes": ["tab"]}),
962+
)
963+
readonly_fields = ["registration_link", "ts_created", "ts_modified", "links", "backlinks"]
964+
list_display = [
913965
"name",
914-
"description",
966+
"registration_link",
915967
"confirmation_mail_sender",
916-
"confirmation_mail_text",
917-
("publication_type", "active"),
918-
("publication_start", "publication_end"),
919-
"show_counter",
920-
("enable_notes", "enable_telephone"),
921-
"check1_label",
922-
"check2_label",
923-
"check3_label",
924-
"check4_label",
925-
"check5_label",
926-
"text1_label",
927-
"text2_label",
928-
"text3_label",
929-
"text4_label",
930-
"text5_label",
931-
"comment",
932-
("ts_created", "ts_modified"),
933-
"links",
934-
"backlinks",
968+
"active",
969+
"ts_created",
935970
]
936-
readonly_fields = ["ts_created", "ts_modified", "links", "backlinks"]
937-
list_display = ["name", "confirmation_mail_sender", "active", "ts_created"]
938971
ordering = ("-active", "-ts_created")
939972
list_editable = ["active"]
940973
search_fields = ["name", "description", "confirmation_mail_sender", "comment"]

django/geno/models.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from django.db.models.signals import post_save, pre_delete
1717
from django.dispatch.dispatcher import receiver
1818
from django.template import Template
19+
from django.urls import NoReverseMatch, reverse
1920
from django.utils import timezone
2021
from django.utils.html import format_html, format_html_join, mark_safe
2122
from filer.fields.file import FilerFileField
@@ -1114,9 +1115,7 @@ class RegistrationEvent(GenoBase):
11141115
publication_end = models.DateTimeField("Ende Anmeldefrist", blank=True, null=True)
11151116
active = models.BooleanField("Aktiv", db_index=True, default=True)
11161117
enable_notes = models.BooleanField("Kommentarfeld anzeigen?", default=False)
1117-
enable_telephone = models.BooleanField(
1118-
"Telefonnummer abfragen (zwingend wegen Covid-19)?", default=False
1119-
)
1118+
enable_telephone = models.BooleanField("Telefonnummer abfragen?", default=False)
11201119
show_counter = models.BooleanField("Anzahl bisherige Anmeldungen anzeigen?", default=True)
11211120
check1_label = models.CharField(
11221121
"Checkbox-Frage 1",
@@ -1142,6 +1141,22 @@ class RegistrationEvent(GenoBase):
11421141
text4_label = models.CharField("Textfeld-Frage 4", max_length=100, blank=True)
11431142
text5_label = models.CharField("Textfeld-Frage 5", max_length=100, blank=True)
11441143

1144+
@property
1145+
@admin.display(description="Link zum Anmelde-Formular")
1146+
def registration_link(self):
1147+
registration_form_viewname = "registration-form"
1148+
if self.pk:
1149+
if self.publication_type == "public":
1150+
try:
1151+
url = settings.BASE_URL + reverse(
1152+
registration_form_viewname, kwargs={"registration_id": self.pk}
1153+
)
1154+
return mark_safe(f"<a href='{url}'>{url}</a>")
1155+
except NoReverseMatch:
1156+
return f"[Fehler: Keine URL für '{registration_form_viewname}' gefunden]"
1157+
return "[Kein öffentlicher Link]"
1158+
return "Bitte zuerst speichern."
1159+
11451160
class Meta:
11461161
verbose_name = "Anmeldung-Anlass"
11471162
verbose_name_plural = "Anmeldung-Anlässe"

django/website_example/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
## Redirect root to /admin as long as there is no website in place.
88
path("", RedirectView.as_view(url="/admin/", permanent=False), name="root-redirect"),
99
# path("", TemplateView.as_view(template_name="website/main.html"), name="website-main"),
10-
path("anmeldung/<int:registration_id>/", website_views.registration),
10+
path("anmeldung/<int:registration_id>/", website_views.registration, name="registration-form"),
1111
]

0 commit comments

Comments
 (0)