From a047241079f03d88eb57f679bc31fded961954fa Mon Sep 17 00:00:00 2001 From: sinavir Date: Thu, 9 Feb 2023 17:07:33 +0100 Subject: [PATCH] bulma templates from kadenios --- hackens_orga/shared/__init__.py | 0 hackens_orga/shared/admin.py | 3 + hackens_orga/shared/apps.py | 6 ++ hackens_orga/shared/migrations/__init__.py | 0 hackens_orga/shared/models.py | 3 + .../shared/templates/forms/checkbox.html | 16 ++++ .../shared/templates/forms/common-form.html | 31 ++++++++ .../shared/templates/forms/field.html | 33 +++++++++ hackens_orga/shared/templates/forms/file.html | 35 +++++++++ hackens_orga/shared/templates/forms/form.html | 18 +++++ .../shared/templates/forms/formset.html | 14 ++++ .../shared/templates/forms/input.html | 19 +++++ .../shared/templates/forms/modal-form.html | 35 +++++++++ .../shared/templates/forms/other.html | 19 +++++ .../shared/templates/forms/radio.html | 24 ++++++ .../shared/templates/forms/select.html | 21 ++++++ .../shared/templates/forms/textarea.html | 19 +++++ hackens_orga/shared/templatetags/bulma.py | 74 +++++++++++++++++++ hackens_orga/shared/tests.py | 3 + hackens_orga/shared/views.py | 3 + 20 files changed, 376 insertions(+) create mode 100644 hackens_orga/shared/__init__.py create mode 100644 hackens_orga/shared/admin.py create mode 100644 hackens_orga/shared/apps.py create mode 100644 hackens_orga/shared/migrations/__init__.py create mode 100644 hackens_orga/shared/models.py create mode 100644 hackens_orga/shared/templates/forms/checkbox.html create mode 100644 hackens_orga/shared/templates/forms/common-form.html create mode 100644 hackens_orga/shared/templates/forms/field.html create mode 100644 hackens_orga/shared/templates/forms/file.html create mode 100644 hackens_orga/shared/templates/forms/form.html create mode 100644 hackens_orga/shared/templates/forms/formset.html create mode 100644 hackens_orga/shared/templates/forms/input.html create mode 100644 hackens_orga/shared/templates/forms/modal-form.html create mode 100644 hackens_orga/shared/templates/forms/other.html create mode 100644 hackens_orga/shared/templates/forms/radio.html create mode 100644 hackens_orga/shared/templates/forms/select.html create mode 100644 hackens_orga/shared/templates/forms/textarea.html create mode 100644 hackens_orga/shared/templatetags/bulma.py create mode 100644 hackens_orga/shared/tests.py create mode 100644 hackens_orga/shared/views.py diff --git a/hackens_orga/shared/__init__.py b/hackens_orga/shared/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/hackens_orga/shared/admin.py b/hackens_orga/shared/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/hackens_orga/shared/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/hackens_orga/shared/apps.py b/hackens_orga/shared/apps.py new file mode 100644 index 0000000..87efe00 --- /dev/null +++ b/hackens_orga/shared/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class SharedConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'shared' diff --git a/hackens_orga/shared/migrations/__init__.py b/hackens_orga/shared/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/hackens_orga/shared/models.py b/hackens_orga/shared/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/hackens_orga/shared/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/hackens_orga/shared/templates/forms/checkbox.html b/hackens_orga/shared/templates/forms/checkbox.html new file mode 100644 index 0000000..f50ad04 --- /dev/null +++ b/hackens_orga/shared/templates/forms/checkbox.html @@ -0,0 +1,16 @@ +
+ {% if field.auto_id %} + + {% endif %} + {% for error in field.errors %} + {{ error }} + {% endfor %} + + {% if field.help_text %} +

+ {{ field.help_text|safe }} +

+ {% endif %} +
diff --git a/hackens_orga/shared/templates/forms/common-form.html b/hackens_orga/shared/templates/forms/common-form.html new file mode 100644 index 0000000..46a6611 --- /dev/null +++ b/hackens_orga/shared/templates/forms/common-form.html @@ -0,0 +1,31 @@ +{% load i18n %} + +
+
+
+ {% csrf_token %} + + {% include "forms/form.html" %} + +
+
+ +
+ + +
+
+
+
diff --git a/hackens_orga/shared/templates/forms/field.html b/hackens_orga/shared/templates/forms/field.html new file mode 100644 index 0000000..8072a7d --- /dev/null +++ b/hackens_orga/shared/templates/forms/field.html @@ -0,0 +1,33 @@ +{% load bulma %} + +
+ {% if field|is_checkbox %} + + {% include "forms/checkbox.html" %} + + {% elif field|is_radio %} + + {% include "forms/radio.html" %} + + {% elif field|is_input %} + + {% include "forms/input.html" %} + + {% elif field|is_textarea %} + + {% include "forms/textarea.html" %} + + {% elif field|is_select %} + + {% include "forms/select.html" %} + + {% elif field|is_file %} + + {% include "forms/file.html" %} + + {% else %} + + {% include "forms/other.html" %} + + {% endif %} +
diff --git a/hackens_orga/shared/templates/forms/file.html b/hackens_orga/shared/templates/forms/file.html new file mode 100644 index 0000000..8d83d84 --- /dev/null +++ b/hackens_orga/shared/templates/forms/file.html @@ -0,0 +1,35 @@ +{% load i18n bulma %} + + + +
+ +
+ +
+ + {% for error in field.errors %} + {{ error }} + {% endfor %} + + {% if field.help_text %} +

+ {{ field.help_text|safe }} +

+ {% endif %} +
diff --git a/hackens_orga/shared/templates/forms/form.html b/hackens_orga/shared/templates/forms/form.html new file mode 100644 index 0000000..1159714 --- /dev/null +++ b/hackens_orga/shared/templates/forms/form.html @@ -0,0 +1,18 @@ +{% if errors %} +{% if form.non_field_errors %} +
+ {% for non_field_error in form.non_field_errors %} + {{ non_field_error }} + {% if not forloop.last %}
{% endif %} + {% endfor %} +
+{% endif %} +{% endif %} + +{% for field in form.hidden_fields %} +{{ field }} +{% endfor %} + +{% for field in form.visible_fields %} +{% include 'forms/field.html' %} +{% endfor %} diff --git a/hackens_orga/shared/templates/forms/formset.html b/hackens_orga/shared/templates/forms/formset.html new file mode 100644 index 0000000..276821c --- /dev/null +++ b/hackens_orga/shared/templates/forms/formset.html @@ -0,0 +1,14 @@ +{% if formset.non_form_errors %} +
+

+ {% for error in formset.non_form_errors %} + {{ error }}
+ {% endfor %} +

+
+{% endif %} + +{{ formset.management_form }} +{% for form in formset %} +{% include 'forms/form.html' %} +{% endfor %} diff --git a/hackens_orga/shared/templates/forms/input.html b/hackens_orga/shared/templates/forms/input.html new file mode 100644 index 0000000..7e74dbd --- /dev/null +++ b/hackens_orga/shared/templates/forms/input.html @@ -0,0 +1,19 @@ +{% load bulma %} + + + +
+ {{ field|bulmafy:'input' }} + + {% for error in field.errors %} + {{ error }} + {% endfor %} + + {% if field.help_text %} +
+ {{ field.help_text|safe }} +
+ {% endif %} +
diff --git a/hackens_orga/shared/templates/forms/modal-form.html b/hackens_orga/shared/templates/forms/modal-form.html new file mode 100644 index 0000000..ecbddb2 --- /dev/null +++ b/hackens_orga/shared/templates/forms/modal-form.html @@ -0,0 +1,35 @@ +{% load i18n %} + + diff --git a/hackens_orga/shared/templates/forms/other.html b/hackens_orga/shared/templates/forms/other.html new file mode 100644 index 0000000..0a2a84a --- /dev/null +++ b/hackens_orga/shared/templates/forms/other.html @@ -0,0 +1,19 @@ +{% if field.auto_id %} + +{% endif %} + +
+ {{ field }} + + {% for error in field.errors %} + {{ error }} + {% endfor %} + + {% if field.help_text %} +

+ {{ field.help_text|safe }} +

+ {% endif %} +
diff --git a/hackens_orga/shared/templates/forms/radio.html b/hackens_orga/shared/templates/forms/radio.html new file mode 100644 index 0000000..6fc8b8a --- /dev/null +++ b/hackens_orga/shared/templates/forms/radio.html @@ -0,0 +1,24 @@ +{% if field.auto_id %} + +{% endif %} + +
+ {% for choice in field %} + + {% endfor %} + + {% for error in field.errors %} + {{ error }} + {% endfor %} + + {% if field.help_text %} +

+ {{ field.help_text|safe }} +

+ {% endif %} +
diff --git a/hackens_orga/shared/templates/forms/select.html b/hackens_orga/shared/templates/forms/select.html new file mode 100644 index 0000000..f23fcde --- /dev/null +++ b/hackens_orga/shared/templates/forms/select.html @@ -0,0 +1,21 @@ +{% load bulma %} + + + +
+ + {{ field }} + + + {% for error in field.errors %} + {{ error }} + {% endfor %} + + {% if field.help_text %} +

+ {{ field.help_text|safe }} +

+ {% endif %} +
diff --git a/hackens_orga/shared/templates/forms/textarea.html b/hackens_orga/shared/templates/forms/textarea.html new file mode 100644 index 0000000..1bc2d78 --- /dev/null +++ b/hackens_orga/shared/templates/forms/textarea.html @@ -0,0 +1,19 @@ +{% load bulma %} + + + +
+ {{ field|bulmafy:'textarea' }} + + {% for error in field.errors %} + {{ error }} + {% endfor %} + + {% if field.help_text %} +

+ {{ field.help_text|safe }} +

+ {% endif %} +
diff --git a/hackens_orga/shared/templatetags/bulma.py b/hackens_orga/shared/templatetags/bulma.py new file mode 100644 index 0000000..e0e15e2 --- /dev/null +++ b/hackens_orga/shared/templatetags/bulma.py @@ -0,0 +1,74 @@ +from django import forms, template + +register = template.Library() + + +@register.filter +def widget_type(field): + return field.field.widget + + +@register.filter +def is_select(field): + return isinstance(field.field.widget, forms.Select) + + +@register.filter +def is_multiple_select(field): + return isinstance(field.field.widget, forms.SelectMultiple) + + +@register.filter +def is_textarea(field): + return isinstance(field.field.widget, forms.Textarea) + + +@register.filter +def is_input(field): + return isinstance( + field.field.widget, + ( + forms.TextInput, + forms.NumberInput, + forms.EmailInput, + forms.PasswordInput, + forms.URLInput, + ), + ) + + +@register.filter +def is_checkbox(field): + return isinstance(field.field.widget, forms.CheckboxInput) + + +@register.filter +def is_multiple_checkbox(field): + return isinstance(field.field.widget, forms.CheckboxSelectMultiple) + + +@register.filter +def is_radio(field): + return isinstance(field.field.widget, forms.RadioSelect) + + +@register.filter +def is_file(field): + return isinstance(field.field.widget, forms.FileInput) + + +@register.filter +def bulmafy(field, css_class): + if len(field.errors) > 0: + css_class += " is-danger" + field_classes = field.field.widget.attrs.get("class", "") + field_classes += f" {css_class}" + return field.as_widget(attrs={"class": field_classes}) + + +@register.filter +def bulma_message_tag(tag): + if tag == "error": + return "danger" + + return tag diff --git a/hackens_orga/shared/tests.py b/hackens_orga/shared/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/hackens_orga/shared/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/hackens_orga/shared/views.py b/hackens_orga/shared/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/hackens_orga/shared/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here.