From e13ceba8c405a606a5c55b35a8e626057f783930 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 20 Mar 2024 17:54:22 +0900 Subject: [PATCH 1/5] :necktie: don't reinitialize inputs --- semantic_forms/static/semantic_forms/semanticCheckbox.js | 2 ++ semantic_forms/static/semantic_forms/semanticChooser.js | 1 - semantic_forms/static/semantic_forms/semanticDropdown.js | 1 - .../static/semantic_forms/semanticTranslatedCalendar.js | 6 ++++++ .../static/semantic_forms/semanticUntranslatedCalendar.js | 6 ++++++ 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/semantic_forms/static/semantic_forms/semanticCheckbox.js b/semantic_forms/static/semantic_forms/semanticCheckbox.js index b972f9f..64655b6 100644 --- a/semantic_forms/static/semantic_forms/semanticCheckbox.js +++ b/semantic_forms/static/semantic_forms/semanticCheckbox.js @@ -1,7 +1,9 @@ $(document).ready(function () { $(".ui.checkbox") + .not(".initialized") .not("[name*=__prefix__]") .each(function () { $(this).checkbox(); + $(this).addClass("initialized"); }); }); diff --git a/semantic_forms/static/semantic_forms/semanticChooser.js b/semantic_forms/static/semantic_forms/semanticChooser.js index 1927de0..d965ce1 100644 --- a/semantic_forms/static/semantic_forms/semanticChooser.js +++ b/semantic_forms/static/semantic_forms/semanticChooser.js @@ -54,7 +54,6 @@ function semanticChooser() { forceSelection: false, saveRemoteData: false, }); - // b/c not idempotent. $(this).addClass("initialized"); }); } diff --git a/semantic_forms/static/semantic_forms/semanticDropdown.js b/semantic_forms/static/semantic_forms/semanticDropdown.js index 5c0fbfa..10487dd 100644 --- a/semantic_forms/static/semantic_forms/semanticDropdown.js +++ b/semantic_forms/static/semantic_forms/semanticDropdown.js @@ -9,7 +9,6 @@ $(document).ready(function () { fullTextSearch: true, forceSelection: false, // https://github.com/Semantic-Org/Semantic-UI/issues/4506 }); - // b/c not idempotent. $(this).addClass("initialized"); }); }); diff --git a/semantic_forms/static/semantic_forms/semanticTranslatedCalendar.js b/semantic_forms/static/semantic_forms/semanticTranslatedCalendar.js index acf19fd..90ce2ea 100644 --- a/semantic_forms/static/semantic_forms/semanticTranslatedCalendar.js +++ b/semantic_forms/static/semantic_forms/semanticTranslatedCalendar.js @@ -2,20 +2,26 @@ $(document).ready(function () { const hasJavascriptCatalog = true; $(".ui.calendar.datetime") + .not(".initialized") .not("[name*=__prefix__]") .each(function () { $(this).calendar(getCalendarOptions("datetime", hasJavascriptCatalog)); + $(this).addClass("initialized"); }); $(".ui.calendar.date") + .not(".initialized") .not("[name*=__prefix__]") .each(function () { $(this).calendar(getCalendarOptions("date", hasJavascriptCatalog)); + $(this).addClass("initialized"); }); $(".ui.calendar.time") + .not(".initialized") .not("[name*=__prefix__]") .each(function () { $(this).calendar(getCalendarOptions("time", hasJavascriptCatalog)); + $(this).addClass("initialized"); }); }); diff --git a/semantic_forms/static/semantic_forms/semanticUntranslatedCalendar.js b/semantic_forms/static/semantic_forms/semanticUntranslatedCalendar.js index 9365111..9807821 100644 --- a/semantic_forms/static/semantic_forms/semanticUntranslatedCalendar.js +++ b/semantic_forms/static/semantic_forms/semanticUntranslatedCalendar.js @@ -2,20 +2,26 @@ $(document).ready(function () { const hasJavascriptCatalog = false; $(".ui.calendar.datetime") + .not(".initialized") .not("[name*=__prefix__]") .each(function () { $(this).calendar(getCalendarOptions("datetime", hasJavascriptCatalog)); + $(this).addClass("initialized"); }); $(".ui.calendar.date") + .not(".initialized") .not("[name*=__prefix__]") .each(function () { $(this).calendar(getCalendarOptions("date", hasJavascriptCatalog)); + $(this).addClass("initialized"); }); $(".ui.calendar.time") + .not(".initialized") .not("[name*=__prefix__]") .each(function () { $(this).calendar(getCalendarOptions("time", hasJavascriptCatalog)); + $(this).addClass("initialized"); }); }); From 729d663d0c37fe47d8c3d64fecd9e144897f1e2e Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 20 Mar 2024 17:55:06 +0900 Subject: [PATCH 2/5] :bookmark: release 0.1.5 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c419dc9..8b06f90 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "django-semantic-forms" -version = "0.1.4" +version = "0.1.5" description = "Django Semantic UI forms" authors = ["Alex "] readme = "README.md" From 9d574adbcd04972d55e9ee944bc42cdb0b8230c8 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 24 Mar 2024 15:17:50 +0900 Subject: [PATCH 3/5] :package: update deps --- poetry.lock | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/poetry.lock b/poetry.lock index 086d152..1aa7f27 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2,13 +2,13 @@ [[package]] name = "asgiref" -version = "3.7.2" +version = "3.8.1" description = "ASGI specs, helper code, and adapters" optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "asgiref-3.7.2-py3-none-any.whl", hash = "sha256:89b2ef2247e3b562a16eef663bc0e2e703ec6468e2fa8a5cd61cd449786d4f6e"}, - {file = "asgiref-3.7.2.tar.gz", hash = "sha256:9e0ce3aa93a819ba5b45120216b23878cf6e8525eb3848653452b4192b92afed"}, + {file = "asgiref-3.8.1-py3-none-any.whl", hash = "sha256:3e1e3ecc849832fe52ccf2cb6686b7a55f82bb1d6aee72a58826471390335e47"}, + {file = "asgiref-3.8.1.tar.gz", hash = "sha256:c343bd80a0bec947a9860adb4c432ffa7db769836c64238fc34bdc3fec84d590"}, ] [package.dependencies] @@ -171,13 +171,13 @@ dev = ["flake8", "markdown", "twine", "wheel"] [[package]] name = "importlib-metadata" -version = "7.0.2" +version = "7.1.0" description = "Read metadata from Python packages" optional = false python-versions = ">=3.8" files = [ - {file = "importlib_metadata-7.0.2-py3-none-any.whl", hash = "sha256:f4bc4c0c070c490abf4ce96d715f68e95923320370efb66143df00199bb6c100"}, - {file = "importlib_metadata-7.0.2.tar.gz", hash = "sha256:198f568f3230878cb1b44fbd7975f87906c22336dba2e4a7f05278c281fbd792"}, + {file = "importlib_metadata-7.1.0-py3-none-any.whl", hash = "sha256:30962b96c0c223483ed6cc7280e7f0199feb01a0e40cfae4d4450fc6fab1f570"}, + {file = "importlib_metadata-7.1.0.tar.gz", hash = "sha256:b78938b926ee8d5f020fc4772d487045805a55ddbad2ecf21c6d60938dc7fcd2"}, ] [package.dependencies] @@ -186,7 +186,7 @@ zipp = ">=0.5" [package.extras] docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] perf = ["ipython"] -testing = ["flufl.flake8", "importlib-resources (>=1.3)", "packaging", "pyfakefs", "pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-mypy", "pytest-perf (>=0.9.2)", "pytest-ruff (>=0.2.1)"] +testing = ["flufl.flake8", "importlib-resources (>=1.3)", "jaraco.test (>=5.4)", "packaging", "pyfakefs", "pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-mypy", "pytest-perf (>=0.9.2)", "pytest-ruff (>=0.2.1)"] [[package]] name = "jinja2" @@ -482,28 +482,28 @@ pyyaml = "*" [[package]] name = "ruff" -version = "0.3.3" +version = "0.3.4" description = "An extremely fast Python linter and code formatter, written in Rust." optional = false python-versions = ">=3.7" files = [ - {file = "ruff-0.3.3-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:973a0e388b7bc2e9148c7f9be8b8c6ae7471b9be37e1cc732f8f44a6f6d7720d"}, - {file = "ruff-0.3.3-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:cfa60d23269d6e2031129b053fdb4e5a7b0637fc6c9c0586737b962b2f834493"}, - {file = "ruff-0.3.3-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1eca7ff7a47043cf6ce5c7f45f603b09121a7cc047447744b029d1b719278eb5"}, - {file = "ruff-0.3.3-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:e7d3f6762217c1da954de24b4a1a70515630d29f71e268ec5000afe81377642d"}, - {file = "ruff-0.3.3-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:b24c19e8598916d9c6f5a5437671f55ee93c212a2c4c569605dc3842b6820386"}, - {file = "ruff-0.3.3-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:5a6cbf216b69c7090f0fe4669501a27326c34e119068c1494f35aaf4cc683778"}, - {file = "ruff-0.3.3-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:352e95ead6964974b234e16ba8a66dad102ec7bf8ac064a23f95371d8b198aab"}, - {file = "ruff-0.3.3-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:8d6ab88c81c4040a817aa432484e838aaddf8bfd7ca70e4e615482757acb64f8"}, - {file = "ruff-0.3.3-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:79bca3a03a759cc773fca69e0bdeac8abd1c13c31b798d5bb3c9da4a03144a9f"}, - {file = "ruff-0.3.3-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:2700a804d5336bcffe063fd789ca2c7b02b552d2e323a336700abb8ae9e6a3f8"}, - {file = "ruff-0.3.3-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:fd66469f1a18fdb9d32e22b79f486223052ddf057dc56dea0caaf1a47bdfaf4e"}, - {file = "ruff-0.3.3-py3-none-musllinux_1_2_i686.whl", hash = "sha256:45817af234605525cdf6317005923bf532514e1ea3d9270acf61ca2440691376"}, - {file = "ruff-0.3.3-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:0da458989ce0159555ef224d5b7c24d3d2e4bf4c300b85467b08c3261c6bc6a8"}, - {file = "ruff-0.3.3-py3-none-win32.whl", hash = "sha256:f2831ec6a580a97f1ea82ea1eda0401c3cdf512cf2045fa3c85e8ef109e87de0"}, - {file = "ruff-0.3.3-py3-none-win_amd64.whl", hash = "sha256:be90bcae57c24d9f9d023b12d627e958eb55f595428bafcb7fec0791ad25ddfc"}, - {file = "ruff-0.3.3-py3-none-win_arm64.whl", hash = "sha256:0171aab5fecdc54383993389710a3d1227f2da124d76a2784a7098e818f92d61"}, - {file = "ruff-0.3.3.tar.gz", hash = "sha256:38671be06f57a2f8aba957d9f701ea889aa5736be806f18c0cd03d6ff0cbca8d"}, + {file = "ruff-0.3.4-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:60c870a7d46efcbc8385d27ec07fe534ac32f3b251e4fc44b3cbfd9e09609ef4"}, + {file = "ruff-0.3.4-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:6fc14fa742e1d8f24910e1fff0bd5e26d395b0e0e04cc1b15c7c5e5fe5b4af91"}, + {file = "ruff-0.3.4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d3ee7880f653cc03749a3bfea720cf2a192e4f884925b0cf7eecce82f0ce5854"}, + {file = "ruff-0.3.4-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:cf133dd744f2470b347f602452a88e70dadfbe0fcfb5fd46e093d55da65f82f7"}, + {file = "ruff-0.3.4-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:3f3860057590e810c7ffea75669bdc6927bfd91e29b4baa9258fd48b540a4365"}, + {file = "ruff-0.3.4-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:986f2377f7cf12efac1f515fc1a5b753c000ed1e0a6de96747cdf2da20a1b369"}, + {file = "ruff-0.3.4-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:c4fd98e85869603e65f554fdc5cddf0712e352fe6e61d29d5a6fe087ec82b76c"}, + {file = "ruff-0.3.4-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:64abeed785dad51801b423fa51840b1764b35d6c461ea8caef9cf9e5e5ab34d9"}, + {file = "ruff-0.3.4-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:df52972138318bc7546d92348a1ee58449bc3f9eaf0db278906eb511889c4b50"}, + {file = "ruff-0.3.4-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:98e98300056445ba2cc27d0b325fd044dc17fcc38e4e4d2c7711585bd0a958ed"}, + {file = "ruff-0.3.4-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:519cf6a0ebed244dce1dc8aecd3dc99add7a2ee15bb68cf19588bb5bf58e0488"}, + {file = "ruff-0.3.4-py3-none-musllinux_1_2_i686.whl", hash = "sha256:bb0acfb921030d00070539c038cd24bb1df73a2981e9f55942514af8b17be94e"}, + {file = "ruff-0.3.4-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:cf187a7e7098233d0d0c71175375c5162f880126c4c716fa28a8ac418dcf3378"}, + {file = "ruff-0.3.4-py3-none-win32.whl", hash = "sha256:af27ac187c0a331e8ef91d84bf1c3c6a5dea97e912a7560ac0cef25c526a4102"}, + {file = "ruff-0.3.4-py3-none-win_amd64.whl", hash = "sha256:de0d5069b165e5a32b3c6ffbb81c350b1e3d3483347196ffdf86dc0ef9e37dd6"}, + {file = "ruff-0.3.4-py3-none-win_arm64.whl", hash = "sha256:6810563cc08ad0096b57c717bd78aeac888a1bfd38654d9113cb3dc4d3f74232"}, + {file = "ruff-0.3.4.tar.gz", hash = "sha256:f0f4484c6541a99862b693e13a151435a279b271cff20e37101116a21e2a1ad1"}, ] [[package]] From 5dbdecae925960b088fe57205aa55c1c2f9182b6 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 24 Mar 2024 15:18:36 +0900 Subject: [PATCH 4/5] :memo: add docs to form view --- demo/demo/urls.py | 4 +- demo/demo_app/forms.py | 57 +++++++++++++++---- demo/demo_app/views.py | 16 +++++- .../semantic_forms/demo/kitchen_sink.html | 48 ++++++++++++++++ 4 files changed, 113 insertions(+), 12 deletions(-) diff --git a/demo/demo/urls.py b/demo/demo/urls.py index c1a9094..19928fc 100644 --- a/demo/demo/urls.py +++ b/demo/demo/urls.py @@ -17,8 +17,10 @@ from demo_app.views import semantic_forms_kitchen_sink from django.urls import include, path +from django.views.i18n import JavaScriptCatalog urlpatterns = [ path("__debug__/", include("debug_toolbar.urls")), - path("forms/", semantic_forms_kitchen_sink), + path("jsi18n/", JavaScriptCatalog.as_view(), name="javascript-catalog"), + path("forms/", semantic_forms_kitchen_sink, name="semantic-forms-kitchen-sink"), ] diff --git a/demo/demo_app/forms.py b/demo/demo_app/forms.py index 28472bc..938b827 100644 --- a/demo/demo_app/forms.py +++ b/demo/demo_app/forms.py @@ -1,4 +1,5 @@ from django.db import models +from django.utils.html import format_html from semantic_forms import SemanticForm from semantic_forms.fields import ( @@ -31,31 +32,67 @@ class Colors(models.TextChoices): class SemanticKitchenSinkForm(SemanticForm): """Semantic kitchen sink form""" - char_field = SemanticCharField(label=_("Char"), help_text=_("Helpful text")) + char_field = SemanticCharField( + label=_("Char"), + help_text=format_html( + "
char_field = SemanticCharField()
" + ), + ) datetime_field = SemanticDateTimeField( - label=_("Datetime"), help_text=_("Helpful text") + label=_("Datetime"), + help_text=format_html( + "
datetime_field = SemanticDateTimeField()
" + ), + ) + date_field = SemanticDateField( + label=_("Date"), + help_text=format_html( + "
date_field = SemanticDateField()
" + ), + ) + time_field = SemanticTimeField( + label=_("Time"), + help_text=format_html( + "
time_field = SemanticTimeField()
" + ), + ) + textarea_field = SemanticTextareaField( + label=_("Text"), + help_text=format_html( + "
textarea_field = SemanticTextareaField()
" + ), ) - date_field = SemanticDateField(label=_("Date"), help_text=_("Helpful text")) - time_field = SemanticTimeField(label=_("Time"), help_text=_("Helpful text")) - text_field = SemanticTextareaField(label=_("Text"), help_text=_("Helpful text")) checkbox_field = SemanticCheckboxField( - label=_("Checkbox"), help_text=_("Helpful text") + label=_("Checkbox"), + help_text=format_html( + "
checkbox_field = SemanticCheckboxField()
" + ), ) radio_field = SemanticRadioChoiceField( label=_("Radio"), - help_text=_("Helpful text"), + help_text=format_html( + "
radio_field = SemanticRadioChoiceField()
" + ), choices=Colors.choices, ) checkbox_select_field = SemanticCheckboxMultipleChoiceField( label=_("Checkbox select"), - help_text=_("Helpful text"), + help_text=format_html( + "
checkbox_select_field = SemanticCheckboxMultipleChoiceField()
" + ), choices=Colors.choices, ) select_field = SemanticChoiceField( - label=_("Select"), help_text=_("Helpful text"), choices=Colors.choices + label=_("Select"), + help_text=format_html( + "select_field = SemanticChoiceField()" + ), + choices=Colors.choices, ) select_muliple_field = SemanticMultipleChoiceField( label=_("Select multiple"), - help_text=_("Helpful text"), + help_text=format_html( + "
select_multiple_field = SemanticMultipleChoiceField()
" + ), choices=Colors.choices, ) diff --git a/demo/demo_app/views.py b/demo/demo_app/views.py index 4059a4f..00342f4 100644 --- a/demo/demo_app/views.py +++ b/demo/demo_app/views.py @@ -9,6 +9,16 @@ except ImportError: from django.utils.translation import ugettext_lazy as _ +BASIC_TEMPLATE = """{% extends "semantic_forms/base.html" %} + +{% block extrahead %}{{ form.media }}{% endblock %} + +{% block content %} +
+ {% csrf_token %}{{ form }} +
+{% endblock %}""" + def semantic_forms_kitchen_sink(request: HttpResponse) -> HttpResponse: """Semantic forms kitchen sink.""" @@ -18,4 +28,8 @@ def semantic_forms_kitchen_sink(request: HttpResponse) -> HttpResponse: messages.success(request, _("Thank you for your submission.")) else: form = SemanticKitchenSinkForm() - return render(request, "semantic_forms/demo/kitchen_sink.html", {"form": form}) + return render( + request, + "semantic_forms/demo/kitchen_sink.html", + {"form": form, "basic_template": BASIC_TEMPLATE}, + ) diff --git a/semantic_forms/templates/semantic_forms/demo/kitchen_sink.html b/semantic_forms/templates/semantic_forms/demo/kitchen_sink.html index bc010cd..a4f4101 100644 --- a/semantic_forms/templates/semantic_forms/demo/kitchen_sink.html +++ b/semantic_forms/templates/semantic_forms/demo/kitchen_sink.html @@ -5,12 +5,50 @@ {% block extrahead %} {{ form.media }} + + + + + + + + {% endblock %} {% block content %}

Semantic Forms

+ +
+ Import from semantic_forms +
from semantic_forms import SemanticForm, SemanticModelForm, SemanticCharField, SemanticDateTimeField, SemanticDateField, SemanticTimeField, SemanticTextareaField, SemanticCheckboxField, SemanticRadioChoiceField, SemanticCheckboxMultipleChoiceField, SemanticChoiceField, SemanticMultipleChoiceField
+ + Subclass SemanticForm or SemanticModelForm + +
class AwesomeForm(SemanticForm):
+    field = SemanticCharField()
+ + Inherit from semantic_ui/base.html +
{{ basic_template }}
+
{% block messages %} {% if messages %} @@ -50,3 +88,13 @@

Semantic Forms

{% endblock %} + +{% block extrascript %} + +{% endblock %} From 29aac9356c3258974fe698c9bc4c282736b08f7f Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 24 Mar 2024 15:28:45 +0900 Subject: [PATCH 5/5] :necktie: fix html tag --- demo/demo_app/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/demo_app/forms.py b/demo/demo_app/forms.py index 938b827..27d9004 100644 --- a/demo/demo_app/forms.py +++ b/demo/demo_app/forms.py @@ -85,7 +85,7 @@ class SemanticKitchenSinkForm(SemanticForm): select_field = SemanticChoiceField( label=_("Select"), help_text=format_html( - "select_field = SemanticChoiceField()" + "
select_field = SemanticChoiceField()
" ), choices=Colors.choices, )