151_Parcel_table_infinite_scroll #153

Merged
mpeltriaux merged 2 commits from 151_Parcel_table_infinite_scroll into master 2 years ago

@ -122,7 +122,7 @@
{% include 'map/geom_form.html' %} {% include 'map/geom_form.html' %}
</div> </div>
<div class="row"> <div class="row">
{% include 'konova/includes/parcels.html' %} {% include 'konova/includes/parcels/parcels.html' %}
</div> </div>
<div class="row"> <div class="row">
{% include 'konova/includes/comment_card.html' %} {% include 'konova/includes/comment_card.html' %}

@ -104,7 +104,7 @@
{% include 'map/geom_form.html' %} {% include 'map/geom_form.html' %}
</div> </div>
<div class="row"> <div class="row">
{% include 'konova/includes/parcels.html' %} {% include 'konova/includes/parcels/parcels.html' %}
</div> </div>
<div class="row"> <div class="row">
{% include 'konova/includes/comment_card.html' %} {% include 'konova/includes/comment_card.html' %}

@ -38,7 +38,7 @@
{% include 'map/geom_form.html' %} {% include 'map/geom_form.html' %}
</div> </div>
<div class="row"> <div class="row">
{% include 'konova/includes/parcels.html' %} {% include 'konova/includes/parcels/parcels.html' %}
</div> </div>
<div class="row"> <div class="row">
{% include 'konova/includes/report/qrcodes.html' %} {% include 'konova/includes/report/qrcodes.html' %}

@ -51,7 +51,7 @@
{% include 'map/geom_form.html' %} {% include 'map/geom_form.html' %}
</div> </div>
<div class="row"> <div class="row">
{% include 'konova/includes/parcels.html' %} {% include 'konova/includes/parcels/parcels.html' %}
</div> </div>
<div class="row"> <div class="row">
{% include 'konova/includes/report/qrcodes.html' %} {% include 'konova/includes/report/qrcodes.html' %}

@ -90,7 +90,7 @@
{% include 'map/geom_form.html' %} {% include 'map/geom_form.html' %}
</div> </div>
<div class="row"> <div class="row">
{% include 'konova/includes/parcels.html' %} {% include 'konova/includes/parcels/parcels.html' %}
</div> </div>
<div class="row"> <div class="row">
{% include 'konova/includes/comment_card.html' %} {% include 'konova/includes/comment_card.html' %}

@ -38,7 +38,7 @@
{% include 'map/geom_form.html' %} {% include 'map/geom_form.html' %}
</div> </div>
<div class="row"> <div class="row">
{% include 'konova/includes/parcels.html' %} {% include 'konova/includes/parcels/parcels.html' %}
</div> </div>
<div class="row"> <div class="row">
{% include 'konova/includes/report/qrcodes.html' %} {% include 'konova/includes/report/qrcodes.html' %}

@ -137,7 +137,7 @@
{% include 'map/geom_form.html' %} {% include 'map/geom_form.html' %}
</div> </div>
<div class="row"> <div class="row">
{% include 'konova/includes/parcels.html' %} {% include 'konova/includes/parcels/parcels.html' %}
</div> </div>
<div class="row"> <div class="row">
{% include 'konova/includes/comment_card.html' %} {% include 'konova/includes/comment_card.html' %}

@ -97,7 +97,7 @@
{% include 'map/geom_form.html' %} {% include 'map/geom_form.html' %}
</div> </div>
<div class="row"> <div class="row">
{% include 'konova/includes/parcels.html' %} {% include 'konova/includes/parcels/parcels.html' %}
</div> </div>
<div class="row"> <div class="row">
{% include 'konova/includes/report/qrcodes.html' %} {% include 'konova/includes/report/qrcodes.html' %}

@ -0,0 +1,22 @@
{% load l10n i18n %}
{% for parcel in parcels %}
{% if forloop.last and next_page %}
<tr hx-get="{% url 'geometry-parcels-content' geom_id next_page %}"
hx-trigger="intersect once"
hx-swap="afterend">
<td>{{parcel.parcel_group.name|default_if_none:"-"}}</td>
<td>{{parcel.parcel_group.key|default_if_none:"-"}}</td>
<td>{{parcel.flr|default_if_none:"-"|unlocalize}}</td>
<td>{{parcel.flrstck_zhlr|default_if_none:"-"|unlocalize}}</td>
<td>{{parcel.flrstck_nnr|default_if_none:"-"|unlocalize}}</td>
</tr>
{% else %}
<tr>
<td>{{parcel.parcel_group.name|default_if_none:"-"}}</td>
<td>{{parcel.parcel_group.key|default_if_none:"-"}}</td>
<td>{{parcel.flr|default_if_none:"-"|unlocalize}}</td>
<td>{{parcel.flrstck_zhlr|default_if_none:"-"|unlocalize}}</td>
<td>{{parcel.flrstck_nnr|default_if_none:"-"|unlocalize}}</td>
</tr>
{% endif %}
{% endfor %}

@ -37,16 +37,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for parcel in parcels %} {% include 'konova/includes/parcels/parcel_table_content.html' %}
<tr>
<td>{{parcel.parcel_group.name|default_if_none:"-"}}</td>
<td>{{parcel.parcel_group.key|default_if_none:"-"}}</td>
<td>{{parcel.flr|default_if_none:"-"|unlocalize}}</td>
<td>{{parcel.flrstck_zhlr|default_if_none:"-"|unlocalize}}</td>
<td>{{parcel.flrstck_nnr|default_if_none:"-"|unlocalize}}</td>
</tr>
{% endfor %}
</tbody> </tbody>
</table> </table>
{% endif %} {% endif %}

@ -24,7 +24,7 @@ from konova.autocompletes import EcoAccountAutocomplete, \
ShareTeamAutocomplete, HandlerCodeAutocomplete ShareTeamAutocomplete, HandlerCodeAutocomplete
from konova.settings import SSO_SERVER, SSO_PUBLIC_KEY, SSO_PRIVATE_KEY, DEBUG from konova.settings import SSO_SERVER, SSO_PUBLIC_KEY, SSO_PRIVATE_KEY, DEBUG
from konova.sso.sso import KonovaSSOClient from konova.sso.sso import KonovaSSOClient
from konova.views import logout_view, home_view, get_geom_parcels from konova.views import logout_view, home_view, get_geom_parcels, get_geom_parcels_content
sso_client = KonovaSSOClient(SSO_SERVER, SSO_PUBLIC_KEY, SSO_PRIVATE_KEY) sso_client = KonovaSSOClient(SSO_SERVER, SSO_PUBLIC_KEY, SSO_PRIVATE_KEY)
urlpatterns = [ urlpatterns = [
@ -40,7 +40,8 @@ urlpatterns = [
path('cl/', include("codelist.urls")), path('cl/', include("codelist.urls")),
path('analysis/', include("analysis.urls")), path('analysis/', include("analysis.urls")),
path('api/', include("api.urls")), path('api/', include("api.urls")),
path('geom/<id>/parcels', get_geom_parcels, name="geometry-parcels"), path('geom/<id>/parcels/', get_geom_parcels, name="geometry-parcels"),
path('geom/<id>/parcels/<int:page>', get_geom_parcels_content, name="geometry-parcels-content"),
# Autocomplete paths for all apps # Autocomplete paths for all apps
path("atcmplt/eco-accounts", EcoAccountAutocomplete.as_view(), name="accounts-autocomplete"), path("atcmplt/eco-accounts", EcoAccountAutocomplete.as_view(), name="accounts-autocomplete"),

@ -110,12 +110,12 @@ def get_geom_parcels(request: HttpRequest, id: str):
id (str): The geometry's id id (str): The geometry's id
Returns: Returns:
A rendered piece of HTML
""" """
# HTTP code 286 states that the HTMX should stop polling for updates # HTTP code 286 states that the HTMX should stop polling for updates
# https://htmx.org/docs/#polling # https://htmx.org/docs/#polling
status_code = 286 status_code = 286
template = "konova/includes/parcel_table.html" template = "konova/includes/parcels/parcel_table_frame.html"
geom = get_object_or_404(Geometry, id=id) geom = get_object_or_404(Geometry, id=id)
parcels = geom.get_underlying_parcels() parcels = geom.get_underlying_parcels()
geos_geom = geom.geom geos_geom = geom.geom
@ -133,9 +133,18 @@ def get_geom_parcels(request: HttpRequest, id: str):
parcels = parcels.order_by("-municipal", "flr", "flrstck_zhlr", "flrstck_nnr") parcels = parcels.order_by("-municipal", "flr", "flrstck_zhlr", "flrstck_nnr")
municipals = parcels.order_by("municipal").distinct("municipal").values("municipal__id") municipals = parcels.order_by("municipal").distinct("municipal").values("municipal__id")
municipals = Municipal.objects.filter(id__in=municipals) municipals = Municipal.objects.filter(id__in=municipals)
rpp = 100
parcels = parcels[:rpp]
next_page = 1
if len(parcels) < rpp:
next_page = None
context = { context = {
"parcels": parcels, "parcels": parcels,
"municipals": municipals, "municipals": municipals,
"geom_id": str(id),
"next_page": next_page,
} }
html = render_to_string(template, context, request) html = render_to_string(template, context, request)
return HttpResponse(html, status=status_code) return HttpResponse(html, status=status_code)
@ -143,6 +152,49 @@ def get_geom_parcels(request: HttpRequest, id: str):
return HttpResponse(None, status=404) return HttpResponse(None, status=404)
@login_required
def get_geom_parcels_content(request: HttpRequest, id: str, page: int):
""" Getter for infinite scroll of HTMX
Returns parcels of a specific page/slice of the found parcel set.
Implementation of infinite scroll htmx example: https://htmx.org/examples/infinite-scroll/
Args:
request (HttpRequest): The incoming request
id (str): The geometry's id
page (int): The requested page number
Returns:
A rendered piece of HTML
"""
if page < 0:
raise AssertionError("Parcel page can not be negative")
# HTTP code 286 states that the HTMX should stop polling for updates
# https://htmx.org/docs/#polling
status_code = 286
template = "konova/includes/parcels/parcel_table_content.html"
geom = get_object_or_404(Geometry, id=id)
parcels = geom.get_underlying_parcels()
parcels = parcels.order_by("-municipal", "flr", "flrstck_zhlr", "flrstck_nnr")
rpp = 100
from_p = rpp * (page-1)
to_p = rpp * (page)
next_page = page + 1
parcels = parcels[from_p:to_p]
if len(parcels) < rpp:
next_page = None
context = {
"parcels": parcels,
"geom_id": str(id),
"next_page": next_page,
}
html = render_to_string(template, context, request)
return HttpResponse(html, status=status_code)
def get_404_view(request: HttpRequest, exception=None): def get_404_view(request: HttpRequest, exception=None):
""" Returns a 404 handling view """ Returns a 404 handling view

Binary file not shown.

@ -26,7 +26,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-04-19 13:28+0200\n" "POT-Creation-Date: 2022-04-21 14:16+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -1582,7 +1582,7 @@ msgid "Search for file number"
msgstr "Nach Aktenzeichen suchen" msgstr "Nach Aktenzeichen suchen"
#: konova/filters/mixins.py:85 #: konova/filters/mixins.py:85
#: konova/templates/konova/includes/parcel_table.html:13 #: konova/templates/konova/includes/parcels/parcel_table_frame.html:13
msgid "District" msgid "District"
msgstr "Kreis" msgstr "Kreis"
@ -1595,7 +1595,7 @@ msgid "Search for parcel gmrkng"
msgstr "Nach Gemarkung suchen" msgstr "Nach Gemarkung suchen"
#: konova/filters/mixins.py:111 #: konova/filters/mixins.py:111
#: konova/templates/konova/includes/parcel_table.html:34 #: konova/templates/konova/includes/parcels/parcel_table_frame.html:34
msgid "Parcel" msgid "Parcel"
msgstr "Flur" msgstr "Flur"
@ -1604,7 +1604,7 @@ msgid "Search for parcel"
msgstr "Nach Flur suchen" msgstr "Nach Flur suchen"
#: konova/filters/mixins.py:124 #: konova/filters/mixins.py:124
#: konova/templates/konova/includes/parcel_table.html:35 #: konova/templates/konova/includes/parcels/parcel_table_frame.html:35
msgid "Parcel counter" msgid "Parcel counter"
msgstr "Flurstückzähler" msgstr "Flurstückzähler"
@ -1613,7 +1613,7 @@ msgid "Search for parcel counter"
msgstr "Nach Flurstückzähler suchen" msgstr "Nach Flurstückzähler suchen"
#: konova/filters/mixins.py:138 #: konova/filters/mixins.py:138
#: konova/templates/konova/includes/parcel_table.html:36 #: konova/templates/konova/includes/parcels/parcel_table_frame.html:36
msgid "Parcel number" msgid "Parcel number"
msgstr "Flurstücknenner" msgstr "Flurstücknenner"
@ -1748,33 +1748,37 @@ msgstr ""
msgid "English" msgid "English"
msgstr "" msgstr ""
#: konova/templates/konova/includes/parcel_table.html:5 #: konova/templates/konova/includes/parcels/parcel_table_content.html:18
msgid "Show more..."
msgstr "Mehr anzeigen..."
#: konova/templates/konova/includes/parcels/parcel_table_frame.html:5
msgid "Parcels can not be calculated, since no geometry is given." msgid "Parcels can not be calculated, since no geometry is given."
msgstr "" msgstr ""
"Flurstücke können nicht berechnet werden, da keine Geometrie eingegeben " "Flurstücke können nicht berechnet werden, da keine Geometrie eingegeben "
"wurde." "wurde."
#: konova/templates/konova/includes/parcel_table.html:11 #: konova/templates/konova/includes/parcels/parcel_table_frame.html:11
msgid "Municipal" msgid "Municipal"
msgstr "Gemeinde" msgstr "Gemeinde"
#: konova/templates/konova/includes/parcel_table.html:12 #: konova/templates/konova/includes/parcels/parcel_table_frame.html:12
msgid "Municipal key" msgid "Municipal key"
msgstr "Gemeindeschlüssel" msgstr "Gemeindeschlüssel"
#: konova/templates/konova/includes/parcel_table.html:14 #: konova/templates/konova/includes/parcels/parcel_table_frame.html:14
msgid "District key" msgid "District key"
msgstr "Kreisschlüssel" msgstr "Kreisschlüssel"
#: konova/templates/konova/includes/parcel_table.html:32 #: konova/templates/konova/includes/parcels/parcel_table_frame.html:32
msgid "Parcel group" msgid "Parcel group"
msgstr "Gemarkung" msgstr "Gemarkung"
#: konova/templates/konova/includes/parcel_table.html:33 #: konova/templates/konova/includes/parcels/parcel_table_frame.html:33
msgid "Parcel group key" msgid "Parcel group key"
msgstr "Gemarkungsschlüssel" msgstr "Gemarkungsschlüssel"
#: konova/templates/konova/includes/parcels.html:7 #: konova/templates/konova/includes/parcels/parcels.html:7
msgid "Spatial reference" msgid "Spatial reference"
msgstr "Raumreferenz" msgstr "Raumreferenz"

Loading…
Cancel
Save