# 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:
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
|
||||
Reference in New Issue
Block a user