Skip to content

Commit

Permalink
[#2098] Paginate questions in case detail view
Browse files Browse the repository at this point in the history
  • Loading branch information
pi-sigma committed Feb 29, 2024
1 parent 1dc8d3d commit 75f91e7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
19 changes: 14 additions & 5 deletions src/open_inwoner/cms/cases/views/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.conf import settings
from django.contrib import messages
from django.core.exceptions import ObjectDoesNotExist, PermissionDenied
from django.core.paginator import Paginator
from django.http import Http404, StreamingHttpResponse
from django.urls import reverse
from django.utils.functional import cached_property
Expand Down Expand Up @@ -146,6 +147,9 @@ def get_context_data(self, **kwargs):
objectcontactmomenten = self.get_objectcontactmomenten(
client=contactmoment_client
)
questions, question_paginator = self.paginate_questions(
objectcontactmomenten
)
self.store_statustype_mapping(self.case.zaaktype.identificatie)
self.store_resulttype_mapping(self.case.zaaktype.identificatie)

Expand Down Expand Up @@ -183,9 +187,6 @@ def get_context_data(self, **kwargs):
hooks.case_status_seen(self.request.user, self.case)
hooks.case_documents_seen(self.request.user, self.case)

# TODO: remove
from .. import dev_snippets

context["case"] = {
"id": str(self.case.uuid),
"identification": self.case.identification,
Expand All @@ -212,8 +213,9 @@ def get_context_data(self, **kwargs):
"created",
dt.timedelta(days=settings.DOCUMENT_RECENT_DAYS),
),
# "questions": [ocm.contactmoment for ocm in objectcontactmomenten],
"questions": dev_snippets.questions,
"questions": questions,
"page_obj": questions,
"paginator": question_paginator,
}
context["case"].update(self.get_upload_info_context(self.case))
context["anchors"] = self.get_anchors(statuses, documents)
Expand Down Expand Up @@ -645,6 +647,13 @@ def get_anchors(self, statuses, documents):

return anchors

def paginate_questions(self, objectcontactmomenten: list[ObjectContactMoment]):
questions = [ocm.contactmoment for ocm in objectcontactmomenten]
paginator = Paginator(questions, 4)
page = self.request.GET.get("page")
paginated_questions = paginator.get_page(page)
return (paginated_questions, paginator)


class CaseDocumentDownloadView(LogMixin, CaseAccessMixin, View):
def get(self, request, *args, **kwargs):
Expand Down
6 changes: 4 additions & 2 deletions src/open_inwoner/templates/pages/cases/status_inner.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load i18n utils anchor_menu_tags card_tags file_tags grid_tags list_tags table_tags solo_tags link_tags button_tags icon_tags notification_tags %}
{% load i18n utils anchor_menu_tags card_tags file_tags grid_tags list_tags table_tags solo_tags link_tags button_tags icon_tags notification_tags pagination_tags %}

{# Messages #}
<div class="container container--no-margin" id="cases-status-messages-oob" hx-swap-oob="true">
Expand Down Expand Up @@ -73,11 +73,13 @@ <h2 class="h2 {% if case.new_docs %}indicator{% endif %}" id="documents">{% tran
</section>
{% endif %}

{# TODO: pagination for questions #}

{# Questions/contactmomenten #}
{% if case.questions %}
<div class="contactmomenten">
<h2 class="h3 contactmomenten__title">{% trans "Vragen" %}</h2>
{% for question in case.questions %}
{% for question in case.questions.object_list %}
<div class="card card--compact card--stretch">
<div class="card__body">
<a href="{{ question.url }}" class="contactmomenten__link">
Expand Down

0 comments on commit 75f91e7

Please sign in to comment.