bulma templates from kadenios
This commit is contained in:
parent
aeb680128a
commit
a047241079
20 changed files with 376 additions and 0 deletions
0
hackens_orga/shared/__init__.py
Normal file
0
hackens_orga/shared/__init__.py
Normal file
3
hackens_orga/shared/admin.py
Normal file
3
hackens_orga/shared/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
6
hackens_orga/shared/apps.py
Normal file
6
hackens_orga/shared/apps.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class SharedConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'shared'
|
0
hackens_orga/shared/migrations/__init__.py
Normal file
0
hackens_orga/shared/migrations/__init__.py
Normal file
3
hackens_orga/shared/models.py
Normal file
3
hackens_orga/shared/models.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.db import models
|
||||
|
||||
# Create your models here.
|
16
hackens_orga/shared/templates/forms/checkbox.html
Normal file
16
hackens_orga/shared/templates/forms/checkbox.html
Normal file
|
@ -0,0 +1,16 @@
|
|||
<div class="control">
|
||||
{% if field.auto_id %}
|
||||
<label class="checkbox {% if field.field.required %}{{ form.required_css_class }}{% endif %}" {% if field.field.disabled %}disabled="" {% endif %}>
|
||||
{{ field }} {{ field.label }}
|
||||
</label>
|
||||
{% endif %}
|
||||
{% for error in field.errors %}
|
||||
<span class="help is-danger {{ form.error_css_class }}">{{ error }}</span>
|
||||
{% endfor %}
|
||||
|
||||
{% if field.help_text %}
|
||||
<p class="help">
|
||||
{{ field.help_text|safe }}
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
31
hackens_orga/shared/templates/forms/common-form.html
Normal file
31
hackens_orga/shared/templates/forms/common-form.html
Normal file
|
@ -0,0 +1,31 @@
|
|||
{% load i18n %}
|
||||
|
||||
<div class="columns is-centered">
|
||||
<div class="column {% if c_size %}{{ c_size }}{% else %}is-two-thirds{% endif %}">
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
|
||||
{% include "forms/form.html" %}
|
||||
|
||||
<div class="field is-grouped">
|
||||
<div class="control is-expanded">
|
||||
<button class="button is-fullwidth is-outlined is-primary is-light" type="submit">
|
||||
<span class="icon">
|
||||
<i class="fas fa-{% if f_icon %}{{ f_icon }}{% else %}check{% endif %}"></i>
|
||||
</span>
|
||||
<span>{% if f_submit %}{{ f_submit }}{% else %}{% trans "Enregister" %}{% endif %}</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="control">
|
||||
<a class="button is-primary" href="{{ r_url }}{% if r_anchor %}#{{ r_anchor }}{% endif %}">
|
||||
<span class="icon">
|
||||
<i class="fas fa-undo-alt"></i>
|
||||
</span>
|
||||
<span>{% if f_return %}{{ f_return }}{% else %}{% trans "Retour" %}{% endif %}</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
33
hackens_orga/shared/templates/forms/field.html
Normal file
33
hackens_orga/shared/templates/forms/field.html
Normal file
|
@ -0,0 +1,33 @@
|
|||
{% load bulma %}
|
||||
|
||||
<div class="field">
|
||||
{% 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 %}
|
||||
</div>
|
35
hackens_orga/shared/templates/forms/file.html
Normal file
35
hackens_orga/shared/templates/forms/file.html
Normal file
|
@ -0,0 +1,35 @@
|
|||
{% load i18n bulma %}
|
||||
|
||||
<label class="label {% if field.field.required %}{{ form.required_css_class }}{% endif %}">
|
||||
{{ field.label_tag }}
|
||||
</label>
|
||||
|
||||
<div class="control">
|
||||
|
||||
<div class="file has-name is-fullwidth">
|
||||
<label class="file-label">
|
||||
{{ field|bulmafy:'file-input' }}
|
||||
<span class="file-cta">
|
||||
<span class="file-icon">
|
||||
<i class="fas fa-upload"></i>
|
||||
</span>
|
||||
<span class="file-label">
|
||||
{% trans "Choisissez un fichier..." %}
|
||||
</span>
|
||||
</span>
|
||||
<span class="file-name is-expanded has-text-centered">
|
||||
{% trans "Aucun fichier sélectionné" %}
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
{% for error in field.errors %}
|
||||
<span class="help is-danger {{ form.error_css_class }}">{{ error }}</span>
|
||||
{% endfor %}
|
||||
|
||||
{% if field.help_text %}
|
||||
<p class="help">
|
||||
{{ field.help_text|safe }}
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
18
hackens_orga/shared/templates/forms/form.html
Normal file
18
hackens_orga/shared/templates/forms/form.html
Normal file
|
@ -0,0 +1,18 @@
|
|||
{% if errors %}
|
||||
{% if form.non_field_errors %}
|
||||
<div class="notification is-danger px-3 has-text-centered">
|
||||
{% for non_field_error in form.non_field_errors %}
|
||||
{{ non_field_error }}
|
||||
{% if not forloop.last %}<hr>{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% for field in form.hidden_fields %}
|
||||
{{ field }}
|
||||
{% endfor %}
|
||||
|
||||
{% for field in form.visible_fields %}
|
||||
{% include 'forms/field.html' %}
|
||||
{% endfor %}
|
14
hackens_orga/shared/templates/forms/formset.html
Normal file
14
hackens_orga/shared/templates/forms/formset.html
Normal file
|
@ -0,0 +1,14 @@
|
|||
{% if formset.non_form_errors %}
|
||||
<div class="message is-danger">
|
||||
<p class="message-body">
|
||||
{% for error in formset.non_form_errors %}
|
||||
{{ error }}<br>
|
||||
{% endfor %}
|
||||
</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{{ formset.management_form }}
|
||||
{% for form in formset %}
|
||||
{% include 'forms/form.html' %}
|
||||
{% endfor %}
|
19
hackens_orga/shared/templates/forms/input.html
Normal file
19
hackens_orga/shared/templates/forms/input.html
Normal file
|
@ -0,0 +1,19 @@
|
|||
{% load bulma %}
|
||||
|
||||
<label class="label {% if field.field.required %}{{ form.required_css_class }}{% endif %}">
|
||||
{{ field.label_tag }}
|
||||
</label>
|
||||
|
||||
<div class="control">
|
||||
{{ field|bulmafy:'input' }}
|
||||
|
||||
{% for error in field.errors %}
|
||||
<span class="help is-danger {{ form.error_css_class }}">{{ error }}</span>
|
||||
{% endfor %}
|
||||
|
||||
{% if field.help_text %}
|
||||
<div class="help">
|
||||
{{ field.help_text|safe }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
35
hackens_orga/shared/templates/forms/modal-form.html
Normal file
35
hackens_orga/shared/templates/forms/modal-form.html
Normal file
|
@ -0,0 +1,35 @@
|
|||
{% load i18n %}
|
||||
|
||||
<div class="modal" id="modal-{{ modal_id }}">
|
||||
<div class="modal-background" data-closes="modal-{{ modal_id }}"></div>
|
||||
<div class="modal-card">
|
||||
|
||||
<header class="modal-card-head">
|
||||
<p class="modal-card-title">{{ modal_title }}</p>
|
||||
<button class="delete" aria-label="close" data-closes="modal-{{ modal_id }}"></button>
|
||||
</header>
|
||||
|
||||
<section class="modal-card-body">
|
||||
<form method="post" action="{{ post_url }}" id="form-{{ modal_id }}" data-modal="modal-{{ modal_id }}">
|
||||
{% csrf_token %}
|
||||
{% include "forms/form.html" %}
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<footer class="modal-card-foot">
|
||||
<button class="button is-fullwidth is-outlined is-primary is-light" form="form-{{ modal_id }}" type="submit">
|
||||
<span class="icon">
|
||||
<i class="fas fa-check"></i>
|
||||
</span>
|
||||
<span>{% trans "Enregistrer" %}</span>
|
||||
</button>
|
||||
|
||||
<button class="button is-primary button-close" data-closes="modal-{{ modal_id }}">
|
||||
<span class="icon">
|
||||
<i class="fas fa-times"></i>
|
||||
</span>
|
||||
<span>{% trans "Annuler" %}</span>
|
||||
</button>
|
||||
</footer>
|
||||
</div>
|
||||
</div>
|
19
hackens_orga/shared/templates/forms/other.html
Normal file
19
hackens_orga/shared/templates/forms/other.html
Normal file
|
@ -0,0 +1,19 @@
|
|||
{% if field.auto_id %}
|
||||
<label class="label {% if field.field.required %}{{ form.required_css_class }}{% endif %}" for="{{ field.auto_id }}">
|
||||
{{ field.label }}
|
||||
</label>
|
||||
{% endif %}
|
||||
|
||||
<div class="control {% if field|is_multiple_checkbox %}multiple-checkbox{% endif %}">
|
||||
{{ field }}
|
||||
|
||||
{% for error in field.errors %}
|
||||
<span class="help is-danger {{ form.error_css_class }}">{{ error }}</span>
|
||||
{% endfor %}
|
||||
|
||||
{% if field.help_text %}
|
||||
<p class="help">
|
||||
{{ field.help_text|safe }}
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
24
hackens_orga/shared/templates/forms/radio.html
Normal file
24
hackens_orga/shared/templates/forms/radio.html
Normal file
|
@ -0,0 +1,24 @@
|
|||
{% if field.auto_id %}
|
||||
<label class="label {% if field.field.required %}{{ form.required_css_class }}{% endif %}">
|
||||
{{ field.label_tag }}
|
||||
</label>
|
||||
{% endif %}
|
||||
|
||||
<div class="control">
|
||||
{% for choice in field %}
|
||||
<label class="radio">
|
||||
{{ choice.tag }}
|
||||
{{ choice.choice_label }}
|
||||
</label>
|
||||
{% endfor %}
|
||||
|
||||
{% for error in field.errors %}
|
||||
<span class="help is-danger {{ form.error_css_class }}">{{ error }}</span>
|
||||
{% endfor %}
|
||||
|
||||
{% if field.help_text %}
|
||||
<p class="help">
|
||||
{{ field.help_text|safe }}
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
21
hackens_orga/shared/templates/forms/select.html
Normal file
21
hackens_orga/shared/templates/forms/select.html
Normal file
|
@ -0,0 +1,21 @@
|
|||
{% load bulma %}
|
||||
|
||||
<label class="label {% if field.field.required %}{{ form.required_css_class }}{% endif %}">
|
||||
{{ field.label_tag }}
|
||||
</label>
|
||||
|
||||
<div class="control is-expanded">
|
||||
<span class="select is-fullwidth{% if field|is_multiple_select %} is-multiple{% endif %}{% if field.errors|length > 0 %} is-danger{% endif %}">
|
||||
{{ field }}
|
||||
</span>
|
||||
|
||||
{% for error in field.errors %}
|
||||
<span class="help is-danger {{ form.error_css_class }}">{{ error }}</span>
|
||||
{% endfor %}
|
||||
|
||||
{% if field.help_text %}
|
||||
<p class="help">
|
||||
{{ field.help_text|safe }}
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
19
hackens_orga/shared/templates/forms/textarea.html
Normal file
19
hackens_orga/shared/templates/forms/textarea.html
Normal file
|
@ -0,0 +1,19 @@
|
|||
{% load bulma %}
|
||||
|
||||
<label class="label {% if field.field.required %}{{ form.required_css_class }}{% endif %}">
|
||||
{{ field.label_tag }}
|
||||
</label>
|
||||
|
||||
<div class="control">
|
||||
{{ field|bulmafy:'textarea' }}
|
||||
|
||||
{% for error in field.errors %}
|
||||
<span class="help is-danger {{ form.error_css_class }}">{{ error }}</span>
|
||||
{% endfor %}
|
||||
|
||||
{% if field.help_text %}
|
||||
<p class="help">
|
||||
{{ field.help_text|safe }}
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
74
hackens_orga/shared/templatetags/bulma.py
Normal file
74
hackens_orga/shared/templatetags/bulma.py
Normal file
|
@ -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
|
3
hackens_orga/shared/tests.py
Normal file
3
hackens_orga/shared/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
3
hackens_orga/shared/views.py
Normal file
3
hackens_orga/shared/views.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
Loading…
Reference in a new issue