diff --git a/compensation/tables/compensation.py b/compensation/tables/compensation.py index 032ab67..02fe00e 100644 --- a/compensation/tables/compensation.py +++ b/compensation/tables/compensation.py @@ -14,11 +14,11 @@ from django.utils.translation import gettext_lazy as _ from compensation.filters.compensation import CompensationTableFilter from compensation.models import Compensation from konova.utils.message_templates import DATA_IS_UNCHECKED, DATA_CHECKED_ON_TEMPLATE, DATA_CHECKED_PREVIOUSLY_TEMPLATE -from konova.utils.tables import BaseTable, TableRenderMixin +from konova.utils.tables import BaseTable, TableRenderMixin, TableOrderMixin import django_tables2 as tables -class CompensationTable(BaseTable, TableRenderMixin): +class CompensationTable(BaseTable, TableRenderMixin, TableOrderMixin): id = tables.Column( verbose_name=_("Identifier"), orderable=True, @@ -31,7 +31,7 @@ class CompensationTable(BaseTable, TableRenderMixin): ) d = tables.Column( verbose_name=_("Parcel gmrkng"), - orderable=True, + orderable=False, accessor="geometry", ) c = tables.Column( @@ -126,28 +126,6 @@ class CompensationTable(BaseTable, TableRenderMixin): ) return format_html(html) - def render_d(self, value, record: Compensation): - """ Renders the parcel district column for a compensation - - Args: - value (str): The geometry - record (Compensation): The compensation record - - Returns: - - """ - parcels = value.get_underlying_parcels().values_list( - "parcel_group__name", - flat=True - ).distinct() - html = render_to_string( - "table/gmrkng_col.html", - { - "entries": parcels - } - ) - return html - def render_r(self, value, record: Compensation): """ Renders the registered column for a compensation diff --git a/compensation/tables/eco_account.py b/compensation/tables/eco_account.py index 7cd121f..65489b5 100644 --- a/compensation/tables/eco_account.py +++ b/compensation/tables/eco_account.py @@ -13,12 +13,12 @@ from django.utils.translation import gettext_lazy as _ from compensation.filters.eco_account import EcoAccountTableFilter from compensation.models import EcoAccount -from konova.utils.tables import TableRenderMixin, BaseTable +from konova.utils.tables import TableRenderMixin, BaseTable, TableOrderMixin import django_tables2 as tables -class EcoAccountTable(BaseTable, TableRenderMixin): +class EcoAccountTable(BaseTable, TableRenderMixin, TableOrderMixin): id = tables.Column( verbose_name=_("Identifier"), orderable=True, @@ -31,7 +31,7 @@ class EcoAccountTable(BaseTable, TableRenderMixin): ) d = tables.Column( verbose_name=_("Parcel gmrkng"), - orderable=True, + orderable=False, accessor="geometry", ) av = tables.Column( @@ -113,28 +113,6 @@ class EcoAccountTable(BaseTable, TableRenderMixin): html = render_to_string("konova/widgets/progressbar.html", {"value": value_relative}) return format_html(html) - def render_d(self, value, record): - """ Renders the parcel district column for a compensation - - Args: - value (str): The geometry - record (Compensation): The compensation record - - Returns: - - """ - parcels = value.get_underlying_parcels().values_list( - "parcel_group__name", - flat=True - ).distinct() - html = render_to_string( - "table/gmrkng_col.html", - { - "entries": parcels - } - ) - return html - def render_r(self, value, record: EcoAccount): """ Renders the recorded column for an eco account diff --git a/ema/tables.py b/ema/tables.py index d26a31d..928b3e2 100644 --- a/ema/tables.py +++ b/ema/tables.py @@ -6,21 +6,18 @@ Created on: 19.08.21 """ from django.http import HttpRequest -from django.template.loader import render_to_string from django.utils.html import format_html -from django.utils.timezone import localtime from django.utils.translation import gettext_lazy as _ 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, TableRenderMixin +from konova.utils.tables import BaseTable, TableRenderMixin, TableOrderMixin from ema.filters import EmaTableFilter from ema.models import Ema -class EmaTable(BaseTable, TableRenderMixin): +class EmaTable(BaseTable, TableRenderMixin, TableOrderMixin): """ Since EMA and compensation are basically the same, we can reuse CompensationTableFilter and extend the EMA filter in the future by inheriting. @@ -37,7 +34,7 @@ class EmaTable(BaseTable, TableRenderMixin): ) d = tables.Column( verbose_name=_("Parcel gmrkng"), - orderable=True, + orderable=False, accessor="geometry", ) r = tables.Column( @@ -93,28 +90,6 @@ class EmaTable(BaseTable, TableRenderMixin): ) return format_html(html) - def render_d(self, value, record: Ema): - """ Renders the parcel district column for a ema - - Args: - value (str): The geometry - record (Ema): The ema record - - Returns: - - """ - parcels = value.get_underlying_parcels().values_list( - "parcel_group__name", - flat=True - ).distinct() - html = render_to_string( - "table/gmrkng_col.html", - { - "entries": parcels - } - ) - return html - def render_r(self, value, record: Ema): """ Renders the registered column for a EMA diff --git a/intervention/tables.py b/intervention/tables.py index cff9391..bdcdc07 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.utils.message_templates import DATA_CHECKED_ON_TEMPLATE, DATA_IS_UNCHECKED, DATA_CHECKED_PREVIOUSLY_TEMPLATE -from konova.utils.tables import BaseTable, TableRenderMixin +from konova.utils.tables import BaseTable, TableRenderMixin, TableOrderMixin import django_tables2 as tables -class InterventionTable(BaseTable, TableRenderMixin): +class InterventionTable(BaseTable, TableRenderMixin, TableOrderMixin): id = tables.Column( verbose_name=_("Identifier"), orderable=True, @@ -31,7 +31,7 @@ class InterventionTable(BaseTable, TableRenderMixin): ) d = tables.Column( verbose_name=_("Parcel gmrkng"), - orderable=True, + orderable=False, accessor="geometry", ) c = tables.Column( @@ -124,28 +124,6 @@ class InterventionTable(BaseTable, TableRenderMixin): ) return format_html(html) - def render_d(self, value, record: Intervention): - """ Renders the parcel district column for an intervention - - Args: - value (str): The intervention geometry - record (Intervention): The intervention record - - Returns: - - """ - parcels = value.get_underlying_parcels().values_list( - "parcel_group__name", - flat=True - ).distinct() - html = render_to_string( - "table/gmrkng_col.html", - { - "entries": parcels - } - ) - return html - def render_r(self, value, record: Intervention): """ Renders the recorded column for an intervention diff --git a/konova/utils/tables.py b/konova/utils/tables.py index d746872..1953724 100644 --- a/konova/utils/tables.py +++ b/konova/utils/tables.py @@ -7,11 +7,13 @@ Created on: 25.11.20 """ from django.core.paginator import PageNotAnInteger, EmptyPage +from django.db.models import F from django.http import HttpRequest +from django.template.loader import render_to_string from django.utils.html import format_html import django_tables2 as tables -from konova.models import BaseObject +from konova.models import BaseObject, GeoReferencedMixin from konova.settings import PAGE_SIZE_DEFAULT, PAGE_PARAM, RESULTS_PER_PAGE_PARAM, PAGE_SIZE_OPTIONS @@ -173,4 +175,37 @@ class TableRenderMixin: max_length = 75 if len(value) > max_length: value = f"{value[:max_length]}..." - return value \ No newline at end of file + return value + + def render_d(self, value, record: GeoReferencedMixin): + """ Renders the parcel district column + + Args: + value (str): The intervention geometry + record (GeoReferencedMixin): The record + + Returns: + + """ + parcels = value.get_underlying_parcels().values_list( + "parcel_group__name", + flat=True + ).distinct() + html = render_to_string( + "table/gmrkng_col.html", + { + "entries": parcels, + "geometry": record.geometry + } + ) + return html + + +class TableOrderMixin: + """ + Holds different order_by methods for general purposes + + """ + def order_lm(self, queryset, is_asc): + queryset = queryset.order_by(F('modified__timestamp').desc(nulls_last=True)) + return (queryset, is_asc) diff --git a/templates/table/gmrkng_col.html b/templates/table/gmrkng_col.html index bd8878d..569c4c1 100644 --- a/templates/table/gmrkng_col.html +++ b/templates/table/gmrkng_col.html @@ -1,9 +1,13 @@ {% load i18n fontawesome_5 %} -{% for entry in entries %} - {{entry}} -{% empty %} - - {% fa5_icon 'hourglass-half' %} - -{% endfor %} \ No newline at end of file +{% if geometry.geom is not None %} + {% for entry in entries %} + {{entry}} + {% empty %} + + {% fa5_icon 'hourglass-half' %} + + {% endfor %} +{% else %} + {% translate 'No geometry added, yet.' %} +{% endif %} \ No newline at end of file