configurable_label_input_ratio #269
@ -19,7 +19,7 @@ class GeoReferencedTableFilterMixin(django_filters.FilterSet):
|
|||||||
Specialized on filtering GeoReferenced model types
|
Specialized on filtering GeoReferenced model types
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# Parcel gmrkng
|
# District
|
||||||
di = django_filters.CharFilter(
|
di = django_filters.CharFilter(
|
||||||
method="filter_district",
|
method="filter_district",
|
||||||
label=_(""),
|
label=_(""),
|
||||||
@ -72,7 +72,7 @@ class GeoReferencedTableFilterMixin(django_filters.FilterSet):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
# Parcel counter
|
# Parcel number
|
||||||
pn = django_filters.NumberFilter(
|
pn = django_filters.NumberFilter(
|
||||||
method="filter_parcel_number",
|
method="filter_parcel_number",
|
||||||
label=_(""),
|
label=_(""),
|
||||||
@ -112,7 +112,7 @@ class GeoReferencedTableFilterMixin(django_filters.FilterSet):
|
|||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
def filter_district(self, queryset, name, value) -> QuerySet:
|
def filter_district(self, queryset, name, value) -> QuerySet:
|
||||||
""" Filters queryset depending on value for 'Gemarkung'
|
""" Filters queryset depending on value for 'Kreis'
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
queryset ():
|
queryset ():
|
||||||
@ -122,10 +122,13 @@ class GeoReferencedTableFilterMixin(django_filters.FilterSet):
|
|||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
matching_districts = District.objects.filter(
|
values = value.split(",")
|
||||||
Q(name__icontains=value) |
|
q = Q()
|
||||||
Q(key__icontains=value)
|
for val in values:
|
||||||
).distinct()
|
val = val.strip()
|
||||||
|
q |= Q(name__icontains=val) | Q(key__icontains=val)
|
||||||
|
|
||||||
|
matching_districts = District.objects.filter(q).distinct()
|
||||||
matching_parcels = Parcel.objects.filter(
|
matching_parcels = Parcel.objects.filter(
|
||||||
district__in=matching_districts
|
district__in=matching_districts
|
||||||
)
|
)
|
||||||
@ -148,9 +151,14 @@ class GeoReferencedTableFilterMixin(django_filters.FilterSet):
|
|||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
values = value.split(",")
|
||||||
|
q = Q()
|
||||||
|
for val in values:
|
||||||
|
val = val.strip()
|
||||||
|
q |= Q(parcel_group__name__icontains=val) | Q(parcel_group__key__icontains=val)
|
||||||
queryset = self._filter_parcel_reference(
|
queryset = self._filter_parcel_reference(
|
||||||
queryset,
|
queryset,
|
||||||
Q(parcel_group__name__icontains=value) | Q(parcel_group__key__icontains=value),
|
q,
|
||||||
)
|
)
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ class BaseForm(forms.Form):
|
|||||||
form_attrs = {} # Holds additional attributes, that can be used in the template
|
form_attrs = {} # Holds additional attributes, that can be used in the template
|
||||||
has_required_fields = False # Automatically set. Triggers hint rendering in templates
|
has_required_fields = False # Automatically set. Triggers hint rendering in templates
|
||||||
show_cancel_btn = True
|
show_cancel_btn = True
|
||||||
|
label_input_ratio = (3, 9) # used for col-sm-xy in the template. Must sum up to 12. Specify on inheriting forms
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.instance = kwargs.pop("instance", None)
|
self.instance = kwargs.pop("instance", None)
|
||||||
@ -42,12 +43,26 @@ class BaseForm(forms.Form):
|
|||||||
break
|
break
|
||||||
|
|
||||||
self.check_for_recorded_instance()
|
self.check_for_recorded_instance()
|
||||||
|
self.__check_valid_label_input_ratio()
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def save(self):
|
def save(self):
|
||||||
# To be implemented in subclasses!
|
# To be implemented in subclasses!
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def __check_valid_label_input_ratio(self):
|
||||||
|
""" Checks whether the configured label-input ratio is valid
|
||||||
|
|
||||||
|
If not valid an AssertionError will be raised.
|
||||||
|
The valid sum of label-input ratio is defined by bootstrap's column layout system.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
ratio = self.label_input_ratio[0] + self.label_input_ratio[1]
|
||||||
|
if ratio != 12:
|
||||||
|
raise AssertionError(f"Label-input ratio on form must sum up to 12! It's {self.label_input_ratio}")
|
||||||
|
|
||||||
def disable_form_field(self, field: str):
|
def disable_form_field(self, field: str):
|
||||||
"""
|
"""
|
||||||
Disables a form field for user editing
|
Disables a form field for user editing
|
||||||
|
@ -24,6 +24,7 @@ class RemoveModalForm(BaseModalForm):
|
|||||||
widget=forms.CheckboxInput(),
|
widget=forms.CheckboxInput(),
|
||||||
required=True,
|
required=True,
|
||||||
)
|
)
|
||||||
|
label_input_ratio = (2, 10)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.template = "modal/modal_form.html"
|
self.template = "modal/modal_form.html"
|
||||||
|
@ -60,6 +60,10 @@ a {
|
|||||||
color: var(--rlp-red);
|
color: var(--rlp-red);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
label {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
.form-control:focus{
|
.form-control:focus{
|
||||||
outline: none;
|
outline: none;
|
||||||
border-color: var(--rlp-red);
|
border-color: var(--rlp-red);
|
||||||
|
@ -4,12 +4,18 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{% for field in form %}
|
{% for field in form %}
|
||||||
<tr title="{{ field.help_text }}" class="{% if field.errors %}alert-danger{% endif %}">
|
<tr title="{{ field.help_text }}" class="{% if field.errors %}alert-danger{% endif %}">
|
||||||
<th scope="row" class="col-sm-3">
|
{{form.small_label_column}}
|
||||||
<label for="id_{{ field.name }}">{{ field.label }}<span class="label-required">{% if field.field.required %}*{% endif %}</span></label>
|
<th scope="row" class="col-sm-{{form.label_input_ratio.0}}">
|
||||||
<br>
|
<label for="id_{{ field.name }}">
|
||||||
<small>{{ field.help_text }}</small>
|
{{ field.label }}
|
||||||
|
<span class="label-required">
|
||||||
|
{% if field.field.required %}*{% endif %}
|
||||||
|
</span>
|
||||||
|
<br>
|
||||||
|
<small>{{ field.help_text }}</small>
|
||||||
|
</label>
|
||||||
</th>
|
</th>
|
||||||
<td class="col-sm-9">
|
<td class="col-sm-{{form.label_input_ratio.1}}">
|
||||||
{{ field }}
|
{{ field }}
|
||||||
{% for error in field.errors %}
|
{% for error in field.errors %}
|
||||||
<br>
|
<br>
|
||||||
|
Loading…
Reference in New Issue
Block a user