Fix checkboxes

This commit is contained in:
Sonny 2020-05-26 22:20:21 +02:00
parent e930096249
commit 89556e225c
16 changed files with 59 additions and 13 deletions

View file

@ -31,6 +31,7 @@ INSTALLED_APPS = [
"axes",
# app modules
"newsreader.accounts",
"newsreader.utils",
"newsreader.news",
"newsreader.news.core",
"newsreader.news.collection",
@ -70,6 +71,8 @@ TEMPLATES = [
}
]
FORM_RENDERER = "newsreader.utils.form.FormRenderer"
WSGI_APPLICATION = "newsreader.wsgi.application"
# Database

View file

@ -1,5 +1,5 @@
{% extends "base.html" %}
{% load i18n static %}
{% load i18n static filters %}
{% block content %}
<main id="rules--page" class="main">
@ -37,7 +37,7 @@
{% for rule in rules %}
<tr class="table__row rules-table__row">
<td class="table__item rules-table__item">
{% with "rules_"|add:rule.pk as id_for_label %}
{% with rule|id_for_label:"rules" as id_for_label %}
{% include "components/form/checkbox.html" with name="rules" value=rule.pk id=id_for_label id_for_label=id_for_label %}
{% endwith %}
</td>

View file

@ -1,5 +1,8 @@
<input class="input category-form__input" type="{{ option.type }}"
name="{{ option.name }}" value="{{ option.value|stringformat:'s' }}"{% if option.selected %} checked{% endif %} />
{% load filters %}
{% with option.instance|id_for_label:"category" as id_for_label %}
{% include "components/form/checkbox.html" with name=option.name value=option.value|stringformat:'s' id=id_for_label id_for_label=id_for_label checked=option.selected only %}
{% endwith %}
{% if option.instance.favicon %}
<img class="favicon" src="{{ option.instance.favicon }}" />

View file

@ -14,7 +14,7 @@
&:checked + .checkbox__label {
.checkbox__box {
background-color: $focus-blue;
background-color: $checkbox-blue;
}
}
}

View file

@ -32,6 +32,7 @@ $border-gray: rgba(227, 227, 227, 1);
$button-blue: rgba(111, 164, 196, 1);
$focus-blue: darken($azureish-white, +10%);
$checkbox-blue: rgba(34, 170, 253, 1);
$font-color: rgba(48, 51, 53, 1);
$header-color: rgba(100, 101, 102, 1);

View file

@ -2,7 +2,9 @@
{% if field %}
{{ field }}
{% else %}
<input id="{{ id }}" name="{{ name }}" type="checkbox" value="{{ value }}" data-input="{{ data_input }}" />
<input id="{{ id }}" name="{{ name }}" type="checkbox" value="{{ value }}"
{% if data_input %}data-input="{{ data_input }}"{% endif %}
{% if checked %}checked{% endif %} />
{% endif %}
<label class="checkbox__label" for="{% if field %}{{ field.id_for_label }}{% else %}{{ id_for_label }}{% endif %}">
<span class="checkbox__box"/>

View file

@ -23,14 +23,9 @@
{% for field in form.visible_fields %}
<fieldset class="fieldset form__fieldset">
{% include "components/form/label.html" %}
{{ field.errors }}
{% if field.field.widget.input_type == "checkbox" %}
{% include "components/form/checkbox.html" with field=field %}
{% else %}
{{ field }}
{% endif %}
{{ field }}
{% include "components/form/help-text.html" %}
</fieldset>
{% endfor %}

View file

View file

@ -0,0 +1,3 @@
# Register your models here.

View file

@ -0,0 +1,5 @@
from django.apps import AppConfig
class UtilsConfig(AppConfig):
name = "utils"

View file

@ -0,0 +1,16 @@
from django.forms.renderers import DjangoTemplates
from django.template.exceptions import TemplateDoesNotExist
from django.template.loader import get_template
class FormRenderer(DjangoTemplates):
"""
Prioritizes templates from TEMPLATES setting and fall's back to django's
default FormRenderer behaviour
"""
def get_template(self, template_name):
try:
return get_template(template_name)
except TemplateDoesNotExist:
return super().get_template(template_name)

View file

@ -0,0 +1,3 @@
# Create your models here.

View file

@ -0,0 +1,9 @@
from django import template
register = template.Library()
@register.filter
def id_for_label(instance, arg):
return f"{arg}_{instance.pk}"

View file

@ -0,0 +1,3 @@
# Create your tests here.

View file

@ -0,0 +1,3 @@
# Create your views here.