# 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:
mpeltriaux 2022-01-12 10:11:47 +01:00
parent 59a541397e
commit 07b079d1b6
11 changed files with 113 additions and 96 deletions

View File

@ -10,7 +10,7 @@ from django.utils.translation import gettext_lazy as _
from django import forms from django import forms
from django.db.models import QuerySet, Q 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): class SelectionCompensationTableFilter(SelectionTableFilter):

View File

@ -16,11 +16,11 @@ from django.utils.translation import gettext_lazy as _
from compensation.filters import CompensationTableFilter, EcoAccountTableFilter from compensation.filters import CompensationTableFilter, EcoAccountTableFilter
from compensation.models import Compensation, EcoAccount from compensation.models import Compensation, EcoAccount
from konova.sub_settings.django_settings import DEFAULT_DATE_TIME_FORMAT 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 import django_tables2 as tables
class CompensationTable(BaseTable): class CompensationTable(BaseTable, TableRenderMixin):
id = tables.Column( id = tables.Column(
verbose_name=_("Identifier"), verbose_name=_("Identifier"),
orderable=True, orderable=True,
@ -162,7 +162,7 @@ class CompensationTable(BaseTable):
return format_html(html) return format_html(html)
class EcoAccountTable(BaseTable): class EcoAccountTable(BaseTable, TableRenderMixin):
id = tables.Column( id = tables.Column(
verbose_name=_("Identifier"), verbose_name=_("Identifier"),
orderable=True, orderable=True,

View File

@ -5,8 +5,6 @@ Contact: michel.peltriaux@sgdnord.rlp.de
Created on: 19.08.21 Created on: 19.08.21
""" """
from django.db.models import QuerySet
from compensation.filters import EcoAccountTableFilter from compensation.filters import EcoAccountTableFilter

View File

@ -14,12 +14,12 @@ from django.urls import reverse
import django_tables2 as tables import django_tables2 as tables
from konova.sub_settings.django_settings import DEFAULT_DATE_TIME_FORMAT 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.filters import EmaTableFilter
from ema.models import Ema 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 Since EMA and compensation are basically the same, we can reuse CompensationTableFilter and extend the EMA filter
in the future by inheriting. in the future by inheriting.

View File

@ -5,7 +5,7 @@ Contact: michel.peltriaux@sgdnord.rlp.de
Created on: 22.07.21 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): class InterventionTableFilter(AbstractTableFilter):

View File

@ -14,11 +14,11 @@ from django.utils.translation import gettext_lazy as _
from intervention.filters import InterventionTableFilter from intervention.filters import InterventionTableFilter
from intervention.models import Intervention from intervention.models import Intervention
from konova.sub_settings.django_settings import DEFAULT_DATE_TIME_FORMAT, DEFAULT_DATE_FORMAT 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 import django_tables2 as tables
class InterventionTable(BaseTable): class InterventionTable(BaseTable, TableRenderMixin):
id = tables.Column( id = tables.Column(
verbose_name=_("Identifier"), verbose_name=_("Identifier"),
orderable=True, orderable=True,

View 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
"""

View File

@ -2,36 +2,21 @@
Author: Michel Peltriaux Author: Michel Peltriaux
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
Contact: michel.peltriaux@sgdnord.rlp.de Contact: michel.peltriaux@sgdnord.rlp.de
Created on: 11.01.22 Created on: 12.01.22
""" """
import django_filters import django_filters
from dal_select2.widgets import ModelSelect2
from django import forms 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.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.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 intervention.inputs import DummyFilterInput
from konova.models import Parcel, District 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): class KeywordTableFilterMixin(django_filters.FilterSet):
q = django_filters.Filter( q = django_filters.Filter(
method='filter_by_keyword', method='filter_by_keyword',
@ -419,27 +404,3 @@ class ConservationOfficeTableFilterMixin(django_filters.FilterSet):
responsible__conservation_office=value responsible__conservation_office=value
) )
return qs 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

View 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

View File

@ -5,15 +5,13 @@ Contact: michel.peltriaux@sgdnord.rlp.de
Created on: 25.11.20 Created on: 25.11.20
""" """
import uuid
from django import forms
from django.core.paginator import PageNotAnInteger, EmptyPage from django.core.paginator import PageNotAnInteger, EmptyPage
from django.http import HttpRequest from django.http import HttpRequest
from django.utils.html import format_html from django.utils.html import format_html
import django_tables2 as tables 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 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): class TableRenderMixin:
select = forms.ChoiceField( """ Holds different render methods for general purposes
choices=[],
label="",
label_suffix="",
widget=forms.Select(
attrs={
"onchange": "submit();",
}
)
)
def __init__(self, *args, **kwargs): """
self.action_url = kwargs.pop("action_url", None) def render_t(self, value, record: BaseObject):
self.choices = kwargs.pop("choices", []) """ Renders a BaseObject title
super().__init__(*args, **kwargs)
self.auto_id += "_" + str(uuid.uuid4()) Args:
if len(self.choices) > 0: value ():
self.fields["select"].choices = self.choices record ():
Returns:
"""
max_length = 75
if len(value) > max_length:
value = f"{value[:max_length]}..."
return value

View File

@ -92,27 +92,31 @@
</div> </div>
<div id="filter" class="collapse" aria-labelledby="filterHeader"> <div id="filter" class="collapse" aria-labelledby="filterHeader">
<div class="card-body"> <div class="card-body">
<div class="row"> <div class="">
{% with table.filter.selection_filter.form as form %} <div class="">
{% include 'filter/query_filter.html' %} {% with table.filter.selection_filter.form as form %}
{% endwith %} {% include 'filter/query_filter.html' %}
</div> {% endwith %}
<div class="row mt-3"> </div>
{% with table.filter.query_filter.form as form %} <hr>
{% include 'filter/query_filter.html' %} <div class="mt-3">
{% endwith %} {% with table.filter.query_filter.form as form %}
</div> {% include 'filter/query_filter.html' %}
<div class="row mt-3"> {% endwith %}
{% with table.filter.checkbox_filter.form as form %} </div>
{% include 'filter/checkbox_filter.html' %} <hr>
{% endwith %} <div class="mt-3">
</div> {% with table.filter.checkbox_filter.form as form %}
<hr> {% include 'filter/checkbox_filter.html' %}
<div class="row mt-3"> {% endwith %}
<button class="btn btn-default" title="{% trans 'Filter' %}"> </div>
{% fa5_icon 'filter' %} <hr>
{% trans 'Apply filter' %} <div class="mt-3">
</button> <button class="btn btn-default" title="{% trans 'Filter' %}">
{% fa5_icon 'filter' %}
{% trans 'Apply filter' %}
</button>
</div>
</div> </div>
</div> </div>
</div> </div>