diff --git a/compensation/tables/compensation.py b/compensation/tables/compensation.py index 032ab67..fe3efe0 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 @@ -170,20 +148,3 @@ class CompensationTable(BaseTable, TableRenderMixin): ) return format_html(html) - def render_e(self, value, record: Compensation): - """ Renders the editable column for a compensation - - Args: - value (str): The identifier value - record (Compensation): The compensation record - - Returns: - - """ - has_access = record.is_shared_with(self.user) - - html = self.render_icn( - tooltip=_("Full access granted") if has_access else _("Access not granted"), - icn_class="fas fa-edit rlp-r-inv" if has_access else "far fa-edit", - ) - return format_html(html) diff --git a/compensation/tables/eco_account.py b/compensation/tables/eco_account.py index 7cd121f..da1444e 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 @@ -156,23 +134,3 @@ class EcoAccountTable(BaseTable, TableRenderMixin): icn_filled=checked, ) return format_html(html) - - def render_e(self, value, record: EcoAccount): - """ Renders the editable column for an eco account - - Args: - value (str): The identifier value - record (EcoAccount): The eco account record - - Returns: - - """ - html = "" - # Do not use value in here, since value does use unprefetched 'users' manager, where record has already - # prefetched users data - has_access = record.is_shared_with(self.user) - html += self.render_icn( - tooltip=_("Full access granted") if has_access else _("Access not granted"), - icn_class="fas fa-edit rlp-r-inv" if has_access else "far fa-edit", - ) - return format_html(html) diff --git a/ema/tables.py b/ema/tables.py index d26a31d..aa043c2 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 @@ -136,22 +111,3 @@ class EmaTable(BaseTable, TableRenderMixin): icn_filled=recorded, ) return format_html(html) - - def render_e(self, value, record: Ema): - """ Renders the editable column for a EMA - - Args: - value (str): The identifier value - record (Ema): The EMA record - - Returns: - - """ - html = "" - has_access = record.is_shared_with(self.user) - - html += self.render_icn( - tooltip=_("Full access granted") if has_access else _("Access not granted"), - icn_class="fas fa-edit rlp-r-inv" if has_access else "far fa-edit", - ) - return format_html(html) diff --git a/ema/views/ema.py b/ema/views/ema.py index b298959..b4ad6fd 100644 --- a/ema/views/ema.py +++ b/ema/views/ema.py @@ -39,9 +39,8 @@ def index_view(request: HttpRequest): template = "generic_index.html" emas = Ema.objects.filter( deleted=None, - ).order_by( - "-modified" ) + table = EmaTable( request, queryset=emas diff --git a/intervention/tables.py b/intervention/tables.py index cff9391..39cae2a 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 @@ -168,22 +146,3 @@ class InterventionTable(BaseTable, TableRenderMixin): ) return format_html(html) - def render_e(self, value, record: Intervention): - """ Renders the editable column for an intervention - - Args: - value (str): The identifier value - record (Intervention): The intervention record - - Returns: - - """ - html = "" - has_access = record.is_shared_with(self.user) - - html += self.render_icn( - tooltip=_("Full access granted") if has_access else _("Access not granted"), - icn_class="fas fa-edit rlp-r-inv" if has_access else "far fa-edit", - ) - return format_html(html) - diff --git a/konova/models/geometry.py b/konova/models/geometry.py index f69fcc7..f8c272f 100644 --- a/konova/models/geometry.py +++ b/konova/models/geometry.py @@ -213,12 +213,9 @@ class Geometry(BaseResource): geojson (dict): The FeatureCollection json (as dict) """ geom = self.geom - geom.transform(ct=srid) + if geom.srid != srid: + geom.transform(ct=srid) - polygons = [] - for coords in geom.coords: - p = Polygon(coords[0], srid=geom.srid) - polygons.append(p) geojson = { "type": "FeatureCollection", "crs": { @@ -230,8 +227,8 @@ class Geometry(BaseResource): "features": [ { "type": "Feature", - "geometry": json.loads(x.geojson) - } for x in polygons + "geometry": json.loads(geom.json), + } ] } return geojson diff --git a/konova/sub_settings/context_settings.py b/konova/sub_settings/context_settings.py index d4b1821..4d34a8f 100644 --- a/konova/sub_settings/context_settings.py +++ b/konova/sub_settings/context_settings.py @@ -10,5 +10,5 @@ BASE_TITLE_SHORT = "KSP" BASE_TITLE = "KSP - Kompensationsverzeichnis Service Portal" BASE_FRONTEND_TITLE = "Kompensationsverzeichnis Service Portal" TAB_TITLE_IDENTIFIER = "tab_title" -HELP_LINK = "https://dienste.naturschutz.rlp.de/doku/doku.php?id=ksp:start" +HELP_LINK = "https://dienste.naturschutz.rlp.de/doku/doku.php?id=ksp2:start" IMPRESSUM_LINK = "https://naturschutz.rlp.de/index.php?q=impressum" diff --git a/konova/templates/konova/includes/parcels/parcel_table_frame.html b/konova/templates/konova/includes/parcels/parcel_table_frame.html index 21b75b7..8adc2e8 100644 --- a/konova/templates/konova/includes/parcels/parcel_table_frame.html +++ b/konova/templates/konova/includes/parcels/parcel_table_frame.html @@ -1,7 +1,8 @@ -{% load i18n l10n %} +{% load i18n l10n fontawesome_5 %}
{% if parcels|length == 0 %}
+ {% fa5_icon 'search-location' %} {% trans 'Parcels can not be calculated, since no geometry is given.' %}
{% else %} diff --git a/konova/templates/konova/includes/parcels/parcels.html b/konova/templates/konova/includes/parcels/parcels.html index a8a882e..9512c09 100644 --- a/konova/templates/konova/includes/parcels/parcels.html +++ b/konova/templates/konova/includes/parcels/parcels.html @@ -2,10 +2,19 @@
-
- {% fa5_icon 'search-location' %} - {% trans 'Spatial reference' %} -
+
+
+
+ {% fa5_icon 'search-location' %} + {% trans 'Spatial reference' %} +
+
+
+
+ {{ obj.geometry.geom.area|floatformat:2 }} m² +
+
+
diff --git a/konova/utils/tables.py b/konova/utils/tables.py index d746872..d64c766 100644 --- a/konova/utils/tables.py +++ b/konova/utils/tables.py @@ -7,11 +7,14 @@ 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 django.utils.translation import gettext_lazy as _ -from konova.models import BaseObject +from konova.models import BaseObject, GeoReferencedMixin, ShareableObjectMixin from konova.settings import PAGE_SIZE_DEFAULT, PAGE_PARAM, RESULTS_PER_PAGE_PARAM, PAGE_SIZE_OPTIONS @@ -173,4 +176,56 @@ 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 + + def render_e(self, value, record: ShareableObjectMixin): + """ Renders the editable column + + Args: + value (str): The identifier value + record (ShareableObjectMixin): The record + + Returns: + + """ + html = "" + has_access = record.is_shared_with(self.user) + + html += self.render_icn( + tooltip=_("Full access granted") if has_access else _("Access not granted"), + icn_class="fas fa-edit rlp-r-inv" if has_access else "far fa-edit", + ) + return format_html(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/konova/views/home.py b/konova/views/home.py index 3118956..98cbaee 100644 --- a/konova/views/home.py +++ b/konova/views/home.py @@ -6,6 +6,7 @@ Created on: 19.08.22 """ from django.contrib.auth.decorators import login_required +from django.db.models import Q from django.http import HttpRequest from django.shortcuts import render from django.utils import timezone @@ -50,22 +51,22 @@ def home_view(request: HttpRequest): ) # Then fetch only user related ones user_interventions = interventions.filter( - users__in=[user] - ) + Q(users__in=[user]) | Q(teams__in=user.shared_teams) + ).distinct() # Repeat for other objects comps = Compensation.objects.filter( deleted=None, ) user_comps = comps.filter( - intervention__users__in=[user] - ) + Q(intervention__users__in=[user]) | Q(intervention__teams__in=user.shared_teams) + ).distinct() eco_accs = EcoAccount.objects.filter( deleted=None, ) user_ecco_accs = eco_accs.filter( - users__in=[user] - ) + Q(users__in=[user]) | Q(teams__in=user.shared_teams) + ).distinct() additional_context = { "msgs": msgs, diff --git a/templates/map/geom_form.html b/templates/map/geom_form.html index 363c940..5cc5bdd 100644 --- a/templates/map/geom_form.html +++ b/templates/map/geom_form.html @@ -1,4 +1,4 @@ -{% load i18n %} +{% load i18n fontawesome_5 %} {% comment %} Encapsules the rendering and initializing of a geometry view component, e.g. used in the detail views. @@ -6,7 +6,10 @@ {% if geom_form.empty %}
-
{% trans 'No geometry added, yet.' %}
+
+ {% fa5_icon 'search-location' %} + {% trans 'No geometry added, yet.' %} +
{% endif %} diff --git a/templates/table/gmrkng_col.html b/templates/table/gmrkng_col.html index bd8878d..4dd5d39 100644 --- a/templates/table/gmrkng_col.html +++ b/templates/table/gmrkng_col.html @@ -1,9 +1,16 @@ {% load i18n fontawesome_5 %} -{% for entry in entries %} - {{entry}} -{% empty %} - - {% fa5_icon 'hourglass-half' %} +{% if geometry.geom is None or geometry.geom.empty %} + + {% fa5_icon 'search-location' %} + {% fa5_icon 'question' %} -{% endfor %} \ No newline at end of file +{% else %} + {% for entry in entries %} + {{entry}} + {% empty %} + + {% fa5_icon 'hourglass-half' %} + + {% endfor %} +{% endif %} \ No newline at end of file diff --git a/user/templates/user/index.html b/user/templates/user/index.html index cfe3bd0..9e7ac78 100644 --- a/user/templates/user/index.html +++ b/user/templates/user/index.html @@ -38,14 +38,6 @@