minor_order_by_timestamp_improvement #223

Merged
mpeltriaux merged 8 commits from minor_order_by_timestamp_improvement into master 2022-10-19 07:34:29 +02:00
6 changed files with 60 additions and 112 deletions
Showing only changes of commit 67df63af0f - Show all commits

View File

@ -14,11 +14,11 @@ from django.utils.translation import gettext_lazy as _
from compensation.filters.compensation import CompensationTableFilter from compensation.filters.compensation import CompensationTableFilter
from compensation.models import Compensation 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.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 import django_tables2 as tables
class CompensationTable(BaseTable, TableRenderMixin): class CompensationTable(BaseTable, TableRenderMixin, TableOrderMixin):
id = tables.Column( id = tables.Column(
verbose_name=_("Identifier"), verbose_name=_("Identifier"),
orderable=True, orderable=True,
@ -31,7 +31,7 @@ class CompensationTable(BaseTable, TableRenderMixin):
) )
d = tables.Column( d = tables.Column(
verbose_name=_("Parcel gmrkng"), verbose_name=_("Parcel gmrkng"),
orderable=True, orderable=False,
accessor="geometry", accessor="geometry",
) )
c = tables.Column( c = tables.Column(
@ -126,28 +126,6 @@ class CompensationTable(BaseTable, TableRenderMixin):
) )
return format_html(html) 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): def render_r(self, value, record: Compensation):
""" Renders the registered column for a compensation """ Renders the registered column for a compensation

View File

@ -13,12 +13,12 @@ from django.utils.translation import gettext_lazy as _
from compensation.filters.eco_account import EcoAccountTableFilter from compensation.filters.eco_account import EcoAccountTableFilter
from compensation.models import EcoAccount 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 import django_tables2 as tables
class EcoAccountTable(BaseTable, TableRenderMixin): class EcoAccountTable(BaseTable, TableRenderMixin, TableOrderMixin):
id = tables.Column( id = tables.Column(
verbose_name=_("Identifier"), verbose_name=_("Identifier"),
orderable=True, orderable=True,
@ -31,7 +31,7 @@ class EcoAccountTable(BaseTable, TableRenderMixin):
) )
d = tables.Column( d = tables.Column(
verbose_name=_("Parcel gmrkng"), verbose_name=_("Parcel gmrkng"),
orderable=True, orderable=False,
accessor="geometry", accessor="geometry",
) )
av = tables.Column( av = tables.Column(
@ -113,28 +113,6 @@ class EcoAccountTable(BaseTable, TableRenderMixin):
html = render_to_string("konova/widgets/progressbar.html", {"value": value_relative}) html = render_to_string("konova/widgets/progressbar.html", {"value": value_relative})
return format_html(html) 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): def render_r(self, value, record: EcoAccount):
""" Renders the recorded column for an eco account """ Renders the recorded column for an eco account

View File

@ -6,21 +6,18 @@ Created on: 19.08.21
""" """
from django.http import HttpRequest from django.http import HttpRequest
from django.template.loader import render_to_string
from django.utils.html import format_html from django.utils.html import format_html
from django.utils.timezone import localtime
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.urls import reverse 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.utils.tables import BaseTable, TableRenderMixin, TableOrderMixin
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, TableRenderMixin): class EmaTable(BaseTable, TableRenderMixin, TableOrderMixin):
""" """
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.
@ -37,7 +34,7 @@ class EmaTable(BaseTable, TableRenderMixin):
) )
d = tables.Column( d = tables.Column(
verbose_name=_("Parcel gmrkng"), verbose_name=_("Parcel gmrkng"),
orderable=True, orderable=False,
accessor="geometry", accessor="geometry",
) )
r = tables.Column( r = tables.Column(
@ -93,28 +90,6 @@ class EmaTable(BaseTable, TableRenderMixin):
) )
return format_html(html) 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): def render_r(self, value, record: Ema):
""" Renders the registered column for a EMA """ Renders the registered column for a EMA

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.utils.message_templates import DATA_CHECKED_ON_TEMPLATE, DATA_IS_UNCHECKED, DATA_CHECKED_PREVIOUSLY_TEMPLATE 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 import django_tables2 as tables
class InterventionTable(BaseTable, TableRenderMixin): class InterventionTable(BaseTable, TableRenderMixin, TableOrderMixin):
id = tables.Column( id = tables.Column(
verbose_name=_("Identifier"), verbose_name=_("Identifier"),
orderable=True, orderable=True,
@ -31,7 +31,7 @@ class InterventionTable(BaseTable, TableRenderMixin):
) )
d = tables.Column( d = tables.Column(
verbose_name=_("Parcel gmrkng"), verbose_name=_("Parcel gmrkng"),
orderable=True, orderable=False,
accessor="geometry", accessor="geometry",
) )
c = tables.Column( c = tables.Column(
@ -124,28 +124,6 @@ class InterventionTable(BaseTable, TableRenderMixin):
) )
return format_html(html) 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): def render_r(self, value, record: Intervention):
""" Renders the recorded column for an intervention """ Renders the recorded column for an intervention

View File

@ -7,11 +7,13 @@ Created on: 25.11.20
""" """
from django.core.paginator import PageNotAnInteger, EmptyPage from django.core.paginator import PageNotAnInteger, EmptyPage
from django.db.models import F
from django.http import HttpRequest from django.http import HttpRequest
from django.template.loader import render_to_string
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.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 from konova.settings import PAGE_SIZE_DEFAULT, PAGE_PARAM, RESULTS_PER_PAGE_PARAM, PAGE_SIZE_OPTIONS
@ -174,3 +176,36 @@ class TableRenderMixin:
if len(value) > max_length: if len(value) > max_length:
value = f"{value[:max_length]}..." value = f"{value[:max_length]}..."
return value 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)

View File

@ -1,5 +1,6 @@
{% load i18n fontawesome_5 %} {% load i18n fontawesome_5 %}
{% if geometry.geom is not None %}
{% for entry in entries %} {% for entry in entries %}
<span class="badge pill-badge rlp-r">{{entry}}</span> <span class="badge pill-badge rlp-r">{{entry}}</span>
{% empty %} {% empty %}
@ -7,3 +8,6 @@
{% fa5_icon 'hourglass-half' %} {% fa5_icon 'hourglass-half' %}
</span> </span>
{% endfor %} {% endfor %}
{% else %}
<span class="badge pill-badge rlp-r-inv">{% translate 'No geometry added, yet.' %}</span>
{% endif %}