From a7d72b867091fe88ef4597a89a3d4b9d6f1c6208 Mon Sep 17 00:00:00 2001 From: alexbainter Date: Mon, 21 Apr 2025 14:39:48 -0500 Subject: [PATCH 1/2] Improve lucide loading and error recovery --- templates/_base.html | 17 +++++++++++++++++ templates/core/article.html | 3 --- templates/core/article_list.html | 4 ---- templates/core/index.html | 7 ------- templates/core/thankyou.html | 7 ------- 5 files changed, 17 insertions(+), 21 deletions(-) diff --git a/templates/_base.html b/templates/_base.html index 17e97f7..1d88e9f 100644 --- a/templates/_base.html +++ b/templates/_base.html @@ -10,7 +10,24 @@ {% block full_title %}{% block title %}{% endblock title %} | {{ PROJECT_NAME }}{% endblock full_title %} + + {% block header %}{% endblock header %} diff --git a/templates/core/article.html b/templates/core/article.html index 3a524ac..6b9409d 100644 --- a/templates/core/article.html +++ b/templates/core/article.html @@ -1,9 +1,6 @@ {% extends '_base.html' %} {% load static %} {% load i18n %} -{% block header %} - -{% endblock header %} {% block full_title %}{{ article.title }}{% endblock full_title %} {% block content %}
diff --git a/templates/core/article_list.html b/templates/core/article_list.html index cc2ed50..309bc93 100644 --- a/templates/core/article_list.html +++ b/templates/core/article_list.html @@ -3,7 +3,6 @@ {% load i18n %} {% block full_title %}{{ PROJECT_NAME }}{% endblock full_title %} {% block content %} -
{% include "includes/nav-bar.html" with route="articles" %} {% include "includes/messages.html" %} @@ -26,7 +25,4 @@ {% endif %}
- {% endblock content %} diff --git a/templates/core/index.html b/templates/core/index.html index 0041f63..8434436 100644 --- a/templates/core/index.html +++ b/templates/core/index.html @@ -2,9 +2,6 @@ {% load static %} {% load i18n %} {% block full_title %}{{ PROJECT_NAME }}{% endblock full_title %} -{% block header %} - -{% endblock header %} {% block content %}
@@ -93,8 +90,4 @@

- - {% endblock content %} diff --git a/templates/core/thankyou.html b/templates/core/thankyou.html index 32f240e..e886fb6 100644 --- a/templates/core/thankyou.html +++ b/templates/core/thankyou.html @@ -1,9 +1,6 @@ {% extends '_base.html' %} {% load static %} {% load i18n %} -{% block header %} - -{% endblock header %} {% block content %}
@@ -20,8 +17,4 @@

Thank you!

  • Home
  • - - {% endblock content %} From 467daf21b369f12297fa335ca0f8dcaa7b7b3eb4 Mon Sep 17 00:00:00 2001 From: alexbainter Date: Tue, 22 Apr 2025 12:25:27 -0500 Subject: [PATCH 2/2] Update article feedback to use lucide markup instead of JS --- portmap/core/forms.py | 18 ++++++++++-------- static/js/article.js | 18 ------------------ templates/forms/widgets/icon_radio_option.html | 3 +++ .../forms/widgets/unwrapped_radio_option.html | 1 - 4 files changed, 13 insertions(+), 27 deletions(-) create mode 100644 templates/forms/widgets/icon_radio_option.html delete mode 100644 templates/forms/widgets/unwrapped_radio_option.html diff --git a/portmap/core/forms.py b/portmap/core/forms.py index 5ba62e1..d1ae0b1 100644 --- a/portmap/core/forms.py +++ b/portmap/core/forms.py @@ -4,11 +4,10 @@ from .models import User, UseCaseFeedback -# The included RadioSelect widget wraps the input element inside of a label, -# which makes it difficult to style the label based on the input's checked state. -# This custom widget structures the label and input as siblings instead. -class UnwrappedRadioSelect(forms.RadioSelect): - option_template_name = "forms/widgets/unwrapped_radio_option.html" +# Renders the radio option as a Lucide icon +class IconRadioSelect(forms.RadioSelect): + option_template_name = "forms/widgets/icon_radio_option.html" + class CustomFormRenderer(TemplatesSetting): form_template_name = "forms/custom.html" @@ -33,6 +32,7 @@ class Meta: model = User fields = ("first_name", "last_name") + class QueryIndexForm(forms.Form): data_type_choices = (('error', 'data missing')) datatype = forms.ChoiceField(label="Select Type to transfer", choices=data_type_choices, required=True) @@ -46,14 +46,16 @@ def __init__(self, data, datatypes=None): self.fields['datadest'].disabled = True self.label_suffix = ' ' + class ArticleFeedbackForm(forms.Form): - CHOICES = [('happy', 'Yes'), - ('sad', 'No')] - reaction = forms.ChoiceField(label="Did this article help?", widget=UnwrappedRadioSelect, choices=CHOICES) + CHOICES = [('happy', 'smile'), + ('sad', 'frown')] + reaction = forms.ChoiceField(label="Did this article help?", widget=IconRadioSelect, choices=CHOICES) explanation = forms.CharField(widget=forms.Textarea, required=False, label="What is your use case? What would make this article better?") + class UseCaseFeedbackForm(forms.ModelForm): class Meta: model = UseCaseFeedback diff --git a/static/js/article.js b/static/js/article.js index d12e49c..f2411c1 100644 --- a/static/js/article.js +++ b/static/js/article.js @@ -1,28 +1,10 @@ -/* global lucide */ - (function () { - function lucideElement(name) { - const element = document.createElement('i'); - element.setAttribute('data-lucide', name); - return element; - } - document.addEventListener('DOMContentLoaded', function () { const happyButton = document.getElementById('id_reaction_0').nextElementSibling; const sadButton = document.getElementById('id_reaction_1').nextElementSibling; - // replaces "yes" string with smily face - happyButton.innerHTML = ''; - happyButton.appendChild(lucideElement('smile')); - - // replaces "no" with frown - sadButton.innerHTML = ''; - sadButton.appendChild(lucideElement('frown')); - - lucide.createIcons(); - const explanationText = document.getElementById('id_explanation'); explanationText.hidden = true; const explanationLabel = diff --git a/templates/forms/widgets/icon_radio_option.html b/templates/forms/widgets/icon_radio_option.html new file mode 100644 index 0000000..505688c --- /dev/null +++ b/templates/forms/widgets/icon_radio_option.html @@ -0,0 +1,3 @@ +{% include "django/forms/widgets/input.html" %} + + {{widget.label}} diff --git a/templates/forms/widgets/unwrapped_radio_option.html b/templates/forms/widgets/unwrapped_radio_option.html deleted file mode 100644 index cdc98a0..0000000 --- a/templates/forms/widgets/unwrapped_radio_option.html +++ /dev/null @@ -1 +0,0 @@ -{% include "django/forms/widgets/input.html" %}{% if widget.wrap_label %}{% endif %}{% if widget.wrap_label %} {{ widget.label }}{% endif %}