feat: Add custom form rendering to support bulma
This commit is contained in:
		@@ -193,6 +193,8 @@ class CustomRegistrationForm(RegistrationForm):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class AdoptionNoticeSearchForm(forms.Form):
 | 
			
		||||
    template_name = "fellchensammlung/forms/form_snippets.html"
 | 
			
		||||
 | 
			
		||||
    sex = forms.ChoiceField(choices=SexChoicesWithAll, label=_("Geschlecht"), required=False,
 | 
			
		||||
                            initial=SexChoicesWithAll.ALL)
 | 
			
		||||
    max_distance = forms.ChoiceField(choices=DistanceChoices, initial=DistanceChoices.ONE_HUNDRED, label=_("Suchradius"))
 | 
			
		||||
 
 | 
			
		||||
@@ -15,20 +15,20 @@
 | 
			
		||||
            <input type="hidden" name="latitude" maxlength="200" id="latitude">
 | 
			
		||||
            <input type="hidden" id="place_id" name="place_id">
 | 
			
		||||
            <!--- https://docs.djangoproject.com/en/5.2/topics/forms/#reusable-form-templates -->
 | 
			
		||||
            {{ search_form.as_p }}
 | 
			
		||||
            {{ search_form }}
 | 
			
		||||
            <ul id="results"></ul>
 | 
			
		||||
            <div class="container-edit-buttons">
 | 
			
		||||
                <button class="btn" type="submit" value="search" name="search">
 | 
			
		||||
                <button class="button is-primary" type="submit" value="search" name="search">
 | 
			
		||||
                    <i class="fas fa-search"></i> {% trans 'Suchen' %}
 | 
			
		||||
                </button>
 | 
			
		||||
                {% if searched %}
 | 
			
		||||
                    {% if subscribed_search %}
 | 
			
		||||
                        <button class="btn" type="submit" value="{{ subscribed_search.pk }}"
 | 
			
		||||
                        <button class="button" type="submit" value="{{ subscribed_search.pk }}"
 | 
			
		||||
                                name="unsubscribe_to_search">
 | 
			
		||||
                            <i class="fas fa-bell-slash"></i> {% trans 'Suche nicht mehr abonnieren' %}
 | 
			
		||||
                        </button>
 | 
			
		||||
                    {% else %}
 | 
			
		||||
                        <button class="btn" type="submit" name="subscribe_to_search">
 | 
			
		||||
                        <button class="button" type="submit" name="subscribe_to_search">
 | 
			
		||||
                            <i class="fas fa-bell"></i> {% trans 'Suche abonnieren' %}
 | 
			
		||||
                        </button>
 | 
			
		||||
                    {% endif %}
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,26 @@
 | 
			
		||||
<!--- See https://docs.djangoproject.com/en/5.2/topics/forms/#reusable-form-templates -->
 | 
			
		||||
 | 
			
		||||
{% load custom_tags %}
 | 
			
		||||
{% for field in form %}
 | 
			
		||||
    <div class="field">
 | 
			
		||||
 | 
			
		||||
        <label class="label">
 | 
			
		||||
            {{ field.label }}
 | 
			
		||||
        </label>
 | 
			
		||||
        <div class="control">
 | 
			
		||||
            {% if field|widget_type == 'TextInput' %}
 | 
			
		||||
                {{ field|add_class:"input" }}
 | 
			
		||||
            {% elif field|widget_type == 'Select' %}
 | 
			
		||||
                <div class="select">
 | 
			
		||||
                    {{ field }}
 | 
			
		||||
                </div>
 | 
			
		||||
            {% else %}
 | 
			
		||||
                {{ field|add_class:"input" }}
 | 
			
		||||
            {% endif %}
 | 
			
		||||
        </div>
 | 
			
		||||
        <div class="help is-danger">
 | 
			
		||||
            {{ field.errors }}
 | 
			
		||||
        </div>
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
{% endfor %}
 | 
			
		||||
@@ -11,7 +11,7 @@
 | 
			
		||||
            <input type="hidden" name="longitude" maxlength="200" id="longitude">
 | 
			
		||||
            <input type="hidden" name="latitude" maxlength="200" id="latitude">
 | 
			
		||||
            <input type="hidden" id="place_id" name="place_id">
 | 
			
		||||
            {{ search_form.as_p }}
 | 
			
		||||
            {{ search_form }}
 | 
			
		||||
            <ul id="results"></ul>
 | 
			
		||||
            <div class="container-edit-buttons">
 | 
			
		||||
                <button class="btn" type="submit" value="search" name="search">
 | 
			
		||||
 
 | 
			
		||||
@@ -49,6 +49,7 @@ def get_oxitraffic_script_if_enabled():
 | 
			
		||||
    else:
 | 
			
		||||
        return ""
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@register.filter
 | 
			
		||||
@stringfilter
 | 
			
		||||
def pointdecimal(value):
 | 
			
		||||
@@ -57,6 +58,7 @@ def pointdecimal(value):
 | 
			
		||||
    except ValueError:
 | 
			
		||||
        return value
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@register.filter
 | 
			
		||||
@stringfilter
 | 
			
		||||
def domain(url):
 | 
			
		||||
@@ -68,6 +70,17 @@ def domain(url):
 | 
			
		||||
    except ValueError:
 | 
			
		||||
        return url
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@register.simple_tag
 | 
			
		||||
def settings_value(name):
 | 
			
		||||
    return getattr(settings, name)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@register.filter(name='add_class')
 | 
			
		||||
def add_class(field, css_class):
 | 
			
		||||
    return field.as_widget(attrs={"class": css_class})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@register.filter
 | 
			
		||||
def widget_type(field):
 | 
			
		||||
    return field.field.widget.__class__.__name__
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user