From 07b079d1b69990152a87acb0414d8659d7a9ae26 Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Wed, 12 Jan 2022 10:11:47 +0100 Subject: [PATCH] # 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 --- compensation/filters.py | 2 +- compensation/tables.py | 6 +-- ema/filters.py | 2 - ema/tables.py | 4 +- intervention/filters.py | 2 +- intervention/tables.py | 4 +- konova/filters/__init__.py | 7 ++++ konova/{filters.py => filters/mixins.py} | 47 ++-------------------- konova/filters/table_filters.py | 50 ++++++++++++++++++++++++ konova/utils/tables.py | 39 +++++++++--------- templates/generic_index.html | 46 ++++++++++++---------- 11 files changed, 113 insertions(+), 96 deletions(-) create mode 100644 konova/filters/__init__.py rename konova/{filters.py => filters/mixins.py} (91%) create mode 100644 konova/filters/table_filters.py diff --git a/compensation/filters.py b/compensation/filters.py index 62c22bd1..eb8a5b7d 100644 --- a/compensation/filters.py +++ b/compensation/filters.py @@ -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): diff --git a/compensation/tables.py b/compensation/tables.py index 2784af23..6e6a190b 100644 --- a/compensation/tables.py +++ b/compensation/tables.py @@ -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, diff --git a/ema/filters.py b/ema/filters.py index 2817d6dc..70b93da0 100644 --- a/ema/filters.py +++ b/ema/filters.py @@ -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 diff --git a/ema/tables.py b/ema/tables.py index 884bac54..d30f3e36 100644 --- a/ema/tables.py +++ b/ema/tables.py @@ -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. diff --git a/intervention/filters.py b/intervention/filters.py index 0d927573..976c9767 100644 --- a/intervention/filters.py +++ b/intervention/filters.py @@ -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): diff --git a/intervention/tables.py b/intervention/tables.py index b0da7d04..0ed003fa 100644 --- a/intervention/tables.py +++ b/intervention/tables.py @@ -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, diff --git a/konova/filters/__init__.py b/konova/filters/__init__.py new file mode 100644 index 00000000..0529e022 --- /dev/null +++ b/konova/filters/__init__.py @@ -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 + +""" diff --git a/konova/filters.py b/konova/filters/mixins.py similarity index 91% rename from konova/filters.py rename to konova/filters/mixins.py index 6244c35a..5625ff36 100644 --- a/konova/filters.py +++ b/konova/filters/mixins.py @@ -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 diff --git a/konova/filters/table_filters.py b/konova/filters/table_filters.py new file mode 100644 index 00000000..8dca6d5f --- /dev/null +++ b/konova/filters/table_filters.py @@ -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 \ No newline at end of file diff --git a/konova/utils/tables.py b/konova/utils/tables.py index 6a3ef88e..d3a0406b 100644 --- a/konova/utils/tables.py +++ b/konova/utils/tables.py @@ -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 \ No newline at end of file diff --git a/templates/generic_index.html b/templates/generic_index.html index 13080726..729be8e4 100644 --- a/templates/generic_index.html +++ b/templates/generic_index.html @@ -92,27 +92,31 @@
-
- {% with table.filter.selection_filter.form as form %} - {% include 'filter/query_filter.html' %} - {% endwith %} -
-
- {% with table.filter.query_filter.form as form %} - {% include 'filter/query_filter.html' %} - {% endwith %} -
-
- {% with table.filter.checkbox_filter.form as form %} - {% include 'filter/checkbox_filter.html' %} - {% endwith %} -
-
-
- +
+
+ {% with table.filter.selection_filter.form as form %} + {% include 'filter/query_filter.html' %} + {% endwith %} +
+
+
+ {% with table.filter.query_filter.form as form %} + {% include 'filter/query_filter.html' %} + {% endwith %} +
+
+
+ {% with table.filter.checkbox_filter.form as form %} + {% include 'filter/checkbox_filter.html' %} + {% endwith %} +
+
+
+ +