#151 Parcel table infinite scroll
* refactors button for further loading to infinite scroll * adds code documentation
This commit is contained in:
		
							parent
							
								
									48e3e84b4c
								
							
						
					
					
						commit
						9c2bdcdacf
					
				@ -1,22 +1,22 @@
 | 
			
		||||
{% load l10n i18n %}
 | 
			
		||||
{% for parcel in parcels %}
 | 
			
		||||
    <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 %}
 | 
			
		||||
{% if next_page %}
 | 
			
		||||
<tr id="nextButton">
 | 
			
		||||
    <td class="text-center" colspan="5">
 | 
			
		||||
        <button class="btn btn-default w-50"
 | 
			
		||||
                hx-get="{% url 'geometry-parcels-content' geom_id next_page %}"
 | 
			
		||||
                hx-target="#nextButton"
 | 
			
		||||
                hx-swap="outerHTML">
 | 
			
		||||
            {% trans 'Show more...' %}
 | 
			
		||||
        </button>
 | 
			
		||||
    </td>
 | 
			
		||||
</tr>
 | 
			
		||||
{% endif %}
 | 
			
		||||
    {% 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 %}
 | 
			
		||||
@ -36,7 +36,7 @@
 | 
			
		||||
                <th scope="col">{% trans 'Parcel number' %}</th>
 | 
			
		||||
            </tr>
 | 
			
		||||
        </thead>
 | 
			
		||||
        <tbody class="m5">
 | 
			
		||||
        <tbody>
 | 
			
		||||
        {% include 'konova/includes/parcels/parcel_table_content.html' %}
 | 
			
		||||
        </tbody>
 | 
			
		||||
    </table>
 | 
			
		||||
 | 
			
		||||
@ -110,7 +110,7 @@ def get_geom_parcels(request: HttpRequest, id: str):
 | 
			
		||||
        id (str): The geometry's id
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
 | 
			
		||||
        A rendered piece of HTML
 | 
			
		||||
    """
 | 
			
		||||
    # HTTP code 286 states that the HTMX should stop polling for updates
 | 
			
		||||
    # https://htmx.org/docs/#polling
 | 
			
		||||
@ -134,7 +134,7 @@ def get_geom_parcels(request: HttpRequest, id: str):
 | 
			
		||||
        municipals = parcels.order_by("municipal").distinct("municipal").values("municipal__id")
 | 
			
		||||
        municipals = Municipal.objects.filter(id__in=municipals)
 | 
			
		||||
 | 
			
		||||
        rpp = 50
 | 
			
		||||
        rpp = 100
 | 
			
		||||
        parcels = parcels[:rpp]
 | 
			
		||||
        next_page = 1
 | 
			
		||||
        if len(parcels) < rpp:
 | 
			
		||||
@ -153,7 +153,20 @@ def get_geom_parcels(request: HttpRequest, id: str):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@login_required
 | 
			
		||||
def get_geom_parcels_content(request:HttpRequest, id: str, page: int):
 | 
			
		||||
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")
 | 
			
		||||
 | 
			
		||||
@ -165,7 +178,7 @@ def get_geom_parcels_content(request:HttpRequest, id: str, page: int):
 | 
			
		||||
    parcels = geom.get_underlying_parcels()
 | 
			
		||||
 | 
			
		||||
    parcels = parcels.order_by("-municipal", "flr", "flrstck_zhlr", "flrstck_nnr")
 | 
			
		||||
    rpp = 50
 | 
			
		||||
    rpp = 100
 | 
			
		||||
    from_p = rpp * (page-1)
 | 
			
		||||
    to_p = rpp * (page)
 | 
			
		||||
    next_page = page + 1
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user