# 61 General table enhancements
* enhances rendering of tables * enhances rendering of filter section * reorganizes table filter codes into konova/filters/ folder and splits into mixins and table_filters
This commit is contained in:
parent
d57478ee09
commit
4c5e170b85
@ -10,7 +10,7 @@ from django.utils.translation import gettext_lazy as _
|
||||
from django import forms
|
||||
from django.db.models import QuerySet, Q
|
||||
|
||||
from konova.filters import QueryTableFilter, CheckboxTableFilter, SelectionTableFilter, AbstractTableFilter
|
||||
from konova.filters.table_filters import QueryTableFilter, CheckboxTableFilter, SelectionTableFilter, AbstractTableFilter
|
||||
|
||||
|
||||
class SelectionCompensationTableFilter(SelectionTableFilter):
|
||||
|
@ -16,11 +16,11 @@ from django.utils.translation import gettext_lazy as _
|
||||
from compensation.filters import CompensationTableFilter, EcoAccountTableFilter
|
||||
from compensation.models import Compensation, EcoAccount
|
||||
from konova.sub_settings.django_settings import DEFAULT_DATE_TIME_FORMAT
|
||||
from konova.utils.tables import BaseTable
|
||||
from konova.utils.tables import BaseTable, TableRenderMixin
|
||||
import django_tables2 as tables
|
||||
|
||||
|
||||
class CompensationTable(BaseTable):
|
||||
class CompensationTable(BaseTable, TableRenderMixin):
|
||||
id = tables.Column(
|
||||
verbose_name=_("Identifier"),
|
||||
orderable=True,
|
||||
@ -162,7 +162,7 @@ class CompensationTable(BaseTable):
|
||||
return format_html(html)
|
||||
|
||||
|
||||
class EcoAccountTable(BaseTable):
|
||||
class EcoAccountTable(BaseTable, TableRenderMixin):
|
||||
id = tables.Column(
|
||||
verbose_name=_("Identifier"),
|
||||
orderable=True,
|
||||
|
@ -5,8 +5,6 @@ Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 19.08.21
|
||||
|
||||
"""
|
||||
from django.db.models import QuerySet
|
||||
|
||||
from compensation.filters import EcoAccountTableFilter
|
||||
|
||||
|
||||
|
@ -14,12 +14,12 @@ from django.urls import reverse
|
||||
import django_tables2 as tables
|
||||
|
||||
from konova.sub_settings.django_settings import DEFAULT_DATE_TIME_FORMAT
|
||||
from konova.utils.tables import BaseTable
|
||||
from konova.utils.tables import BaseTable, TableRenderMixin
|
||||
from ema.filters import EmaTableFilter
|
||||
from ema.models import Ema
|
||||
|
||||
|
||||
class EmaTable(BaseTable):
|
||||
class EmaTable(BaseTable, TableRenderMixin):
|
||||
"""
|
||||
Since EMA and compensation are basically the same, we can reuse CompensationTableFilter and extend the EMA filter
|
||||
in the future by inheriting.
|
||||
|
@ -5,7 +5,7 @@ Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 22.07.21
|
||||
|
||||
"""
|
||||
from konova.filters import AbstractTableFilter, SelectionTableFilter, QueryTableFilter, CheckboxTableFilter
|
||||
from konova.filters.table_filters import AbstractTableFilter, SelectionTableFilter, QueryTableFilter, CheckboxTableFilter
|
||||
|
||||
|
||||
class InterventionTableFilter(AbstractTableFilter):
|
||||
|
@ -14,11 +14,11 @@ from django.utils.translation import gettext_lazy as _
|
||||
from intervention.filters import InterventionTableFilter
|
||||
from intervention.models import Intervention
|
||||
from konova.sub_settings.django_settings import DEFAULT_DATE_TIME_FORMAT, DEFAULT_DATE_FORMAT
|
||||
from konova.utils.tables import BaseTable
|
||||
from konova.utils.tables import BaseTable, TableRenderMixin
|
||||
import django_tables2 as tables
|
||||
|
||||
|
||||
class InterventionTable(BaseTable):
|
||||
class InterventionTable(BaseTable, TableRenderMixin):
|
||||
id = tables.Column(
|
||||
verbose_name=_("Identifier"),
|
||||
orderable=True,
|
||||
|
7
konova/filters/__init__.py
Normal file
7
konova/filters/__init__.py
Normal file
@ -0,0 +1,7 @@
|
||||
"""
|
||||
Author: Michel Peltriaux
|
||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 12.01.22
|
||||
|
||||
"""
|
@ -2,36 +2,21 @@
|
||||
Author: Michel Peltriaux
|
||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 11.01.22
|
||||
Created on: 12.01.22
|
||||
|
||||
"""
|
||||
import django_filters
|
||||
from dal_select2.widgets import ModelSelect2
|
||||
from django import forms
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.contrib.auth.models import User
|
||||
from django.db.models import QuerySet, Q
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from dal_select2.widgets import ModelSelect2
|
||||
|
||||
from codelist.models import KonovaCode
|
||||
from codelist.settings import CODELIST_REGISTRATION_OFFICE_ID, CODELIST_CONSERVATION_OFFICE_ID
|
||||
from codelist.settings import CODELIST_CONSERVATION_OFFICE_ID, CODELIST_REGISTRATION_OFFICE_ID
|
||||
from intervention.inputs import DummyFilterInput
|
||||
from konova.models import Parcel, District
|
||||
|
||||
|
||||
class AbstractTableFilter(django_filters.FilterSet):
|
||||
""" Base TableFilter for all models
|
||||
|
||||
"""
|
||||
selection_filter = None
|
||||
query_filter = None
|
||||
checkbox_filter = None
|
||||
qs = None
|
||||
user = None
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
class KeywordTableFilterMixin(django_filters.FilterSet):
|
||||
q = django_filters.Filter(
|
||||
method='filter_by_keyword',
|
||||
@ -419,27 +404,3 @@ class ConservationOfficeTableFilterMixin(django_filters.FilterSet):
|
||||
responsible__conservation_office=value
|
||||
)
|
||||
return qs
|
||||
|
||||
|
||||
class SelectionTableFilter(RegistrationOfficeTableFilterMixin,
|
||||
ConservationOfficeTableFilterMixin):
|
||||
""" TableFilter holding different filter options for selection related filtering
|
||||
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class QueryTableFilter(KeywordTableFilterMixin,
|
||||
FileNumberTableFilterMixin,
|
||||
GeoReferencedTableFilterMixin):
|
||||
""" TableFilter holding different filter options for query related filtering
|
||||
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class CheckboxTableFilter(ShareableTableFilterMixin, RecordableTableFilterMixin):
|
||||
""" TableFilter holding different filter options for checkbox related filtering
|
||||
|
||||
"""
|
||||
pass
|
50
konova/filters/table_filters.py
Normal file
50
konova/filters/table_filters.py
Normal file
@ -0,0 +1,50 @@
|
||||
"""
|
||||
Author: Michel Peltriaux
|
||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 12.01.22
|
||||
|
||||
"""
|
||||
import django_filters
|
||||
|
||||
from konova.filters.mixins import RegistrationOfficeTableFilterMixin, ConservationOfficeTableFilterMixin, \
|
||||
KeywordTableFilterMixin, FileNumberTableFilterMixin, GeoReferencedTableFilterMixin, ShareableTableFilterMixin, \
|
||||
RecordableTableFilterMixin
|
||||
|
||||
|
||||
class AbstractTableFilter(django_filters.FilterSet):
|
||||
""" Base TableFilter for all models
|
||||
|
||||
"""
|
||||
selection_filter = None
|
||||
query_filter = None
|
||||
checkbox_filter = None
|
||||
qs = None
|
||||
user = None
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
class SelectionTableFilter(RegistrationOfficeTableFilterMixin,
|
||||
ConservationOfficeTableFilterMixin):
|
||||
""" TableFilter holding different filter options for selection related filtering
|
||||
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class QueryTableFilter(KeywordTableFilterMixin,
|
||||
FileNumberTableFilterMixin,
|
||||
GeoReferencedTableFilterMixin):
|
||||
""" TableFilter holding different filter options for query related filtering
|
||||
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class CheckboxTableFilter(ShareableTableFilterMixin, RecordableTableFilterMixin):
|
||||
""" TableFilter holding different filter options for checkbox related filtering
|
||||
|
||||
"""
|
||||
pass
|
@ -5,15 +5,13 @@ Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 25.11.20
|
||||
|
||||
"""
|
||||
import uuid
|
||||
|
||||
from django import forms
|
||||
from django.core.paginator import PageNotAnInteger, EmptyPage
|
||||
from django.http import HttpRequest
|
||||
from django.utils.html import format_html
|
||||
import django_tables2 as tables
|
||||
|
||||
from konova.forms import BaseForm
|
||||
from konova.models import BaseObject
|
||||
from konova.settings import PAGE_SIZE_DEFAULT, PAGE_PARAM, RESULTS_PER_PAGE_PARAM, PAGE_SIZE_OPTIONS
|
||||
|
||||
|
||||
@ -147,22 +145,21 @@ class BaseTable(tables.tables.Table):
|
||||
)
|
||||
|
||||
|
||||
class ChoicesColumnForm(BaseForm):
|
||||
select = forms.ChoiceField(
|
||||
choices=[],
|
||||
label="",
|
||||
label_suffix="",
|
||||
widget=forms.Select(
|
||||
attrs={
|
||||
"onchange": "submit();",
|
||||
}
|
||||
)
|
||||
)
|
||||
class TableRenderMixin:
|
||||
""" Holds different render methods for general purposes
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.action_url = kwargs.pop("action_url", None)
|
||||
self.choices = kwargs.pop("choices", [])
|
||||
super().__init__(*args, **kwargs)
|
||||
self.auto_id += "_" + str(uuid.uuid4())
|
||||
if len(self.choices) > 0:
|
||||
self.fields["select"].choices = self.choices
|
||||
"""
|
||||
def render_t(self, value, record: BaseObject):
|
||||
""" Renders a BaseObject title
|
||||
|
||||
Args:
|
||||
value ():
|
||||
record ():
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
max_length = 75
|
||||
if len(value) > max_length:
|
||||
value = f"{value[:max_length]}..."
|
||||
return value
|
@ -92,27 +92,31 @@
|
||||
</div>
|
||||
<div id="filter" class="collapse" aria-labelledby="filterHeader">
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
{% with table.filter.selection_filter.form as form %}
|
||||
{% include 'filter/query_filter.html' %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
<div class="row mt-3">
|
||||
{% with table.filter.query_filter.form as form %}
|
||||
{% include 'filter/query_filter.html' %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
<div class="row mt-3">
|
||||
{% with table.filter.checkbox_filter.form as form %}
|
||||
{% include 'filter/checkbox_filter.html' %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
<hr>
|
||||
<div class="row mt-3">
|
||||
<button class="btn btn-default" title="{% trans 'Filter' %}">
|
||||
{% fa5_icon 'filter' %}
|
||||
{% trans 'Apply filter' %}
|
||||
</button>
|
||||
<div class="">
|
||||
<div class="">
|
||||
{% with table.filter.selection_filter.form as form %}
|
||||
{% include 'filter/query_filter.html' %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
<hr>
|
||||
<div class="mt-3">
|
||||
{% with table.filter.query_filter.form as form %}
|
||||
{% include 'filter/query_filter.html' %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
<hr>
|
||||
<div class="mt-3">
|
||||
{% with table.filter.checkbox_filter.form as form %}
|
||||
{% include 'filter/checkbox_filter.html' %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
<hr>
|
||||
<div class="mt-3">
|
||||
<button class="btn btn-default" title="{% trans 'Filter' %}">
|
||||
{% fa5_icon 'filter' %}
|
||||
{% trans 'Apply filter' %}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user