From d2f048f8fed9facff5a8ca1ade85f9fea11f1d83 Mon Sep 17 00:00:00 2001 From: Peter Pfeufer Date: Wed, 14 Aug 2024 12:45:47 +0200 Subject: [PATCH] [ADD Example template for admin overrides For when we might want to add syntax highlight ti it, which is a completely different can of worms though. --- allianceauth/custom_css/admin.py | 3 ++ allianceauth/custom_css/forms.py | 10 +++- .../custom_css/admin/change_form.html | 48 +++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 allianceauth/custom_css/templates/custom_css/admin/change_form.html diff --git a/allianceauth/custom_css/admin.py b/allianceauth/custom_css/admin.py index 0b5f79ec..debc4f16 100644 --- a/allianceauth/custom_css/admin.py +++ b/allianceauth/custom_css/admin.py @@ -20,3 +20,6 @@ class CustomCSSAdmin(SingletonModelAdmin): """ form = CustomCSSAdminForm + + # Leave this here for when we decide to add syntax highlighting to the CSS editor + # change_form_template = 'custom_css/admin/change_form.html' diff --git a/allianceauth/custom_css/forms.py b/allianceauth/custom_css/forms.py index f9a1f205..6823b204 100644 --- a/allianceauth/custom_css/forms.py +++ b/allianceauth/custom_css/forms.py @@ -18,4 +18,12 @@ class CustomCSSAdminForm(forms.ModelForm): class Meta: model = CustomCSS fields = ("css",) - widgets = {"css": CssEditorWidget(attrs={"style": "width: 90%; height: 100%;"})} + widgets = { + "css": CssEditorWidget( + attrs={ + "style": "width: 90%; height: 100%;", + "data-editor": "code-highlight", + "data-language": "css", + } + ) + } diff --git a/allianceauth/custom_css/templates/custom_css/admin/change_form.html b/allianceauth/custom_css/templates/custom_css/admin/change_form.html new file mode 100644 index 00000000..d8c921f2 --- /dev/null +++ b/allianceauth/custom_css/templates/custom_css/admin/change_form.html @@ -0,0 +1,48 @@ +{% extends "admin/change_form.html" %} + +{% block field_sets %} + {% for fieldset in adminform %} +
+ {% if fieldset.name %}

{{ fieldset.name }}

{% endif %} + + {% if fieldset.description %} +
{{ fieldset.description|safe }}
+ {% endif %} + + {% for line in fieldset %} +
+ {% if line.fields|length == 1 %}{{ line.errors }}{% else %}
{% endif %} + + {% for field in line %} +
+ {% if not line.fields|length == 1 and not field.is_readonly %}{{ field.errors }}{% endif %} + +
+ {% if field.is_checkbox %} + {{ field.field }}{{ field.label_tag }} + {% else %} + {{ field.label_tag }} + {% if field.is_readonly %} +
{{ field.contents }}
+ {% else %} + {{ field.field }} + {% endif %} + {% endif %} +
+ + {% if field.field.help_text %} +
+
{{ field.field.help_text|safe }}
+
+ {% endif %} +
+ {% endfor %} + + {% if not line.fields|length == 1 %}
{% endif %} +
+ {% endfor %} +
+ {% endfor %} +{% endblock %} + +{% block after_field_sets %}{% endblock %}