Skip to content

Commit

Permalink
[#1798] Updated document list element
Browse files Browse the repository at this point in the history
  - Added date
  - Added 'new' indicator to documents created no more than 24h in the
    past
  • Loading branch information
pi-sigma committed Nov 1, 2023
1 parent f97d8be commit b64f3e2
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 20 deletions.
21 changes: 17 additions & 4 deletions src/open_inwoner/cms/cases/views/status.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import dataclasses
import datetime as dt
from collections import defaultdict
from typing import List
from datetime import datetime
from typing import List, Optional

from django.conf import settings
from django.contrib import messages
from django.core.exceptions import ObjectDoesNotExist, PermissionDenied
from django.http import Http404, StreamingHttpResponse
Expand Down Expand Up @@ -45,6 +48,7 @@
ZaakTypeInformatieObjectTypeConfig,
)
from open_inwoner.openzaak.utils import get_role_name_display, is_info_object_visible
from open_inwoner.utils.time import has_fresh_elements
from open_inwoner.utils.translate import TranslationLookup
from open_inwoner.utils.views import CommonPageMixin, LogMixin

Expand All @@ -57,6 +61,7 @@ class SimpleFile:
name: str
size: int
url: str
created: Optional[datetime] = None


class OuterCaseDetailView(
Expand All @@ -82,12 +87,13 @@ def get_context_data(self, **kwargs):


class InnerCaseDetailView(
CaseLogMixin, CommonPageMixin, BaseBreadcrumbMixin, CaseAccessMixin, FormView
CaseLogMixin, CommonPageMixin, CaseAccessMixin, BaseBreadcrumbMixin, FormView
):
template_name = "pages/cases/status_inner.html"
form_class = CaseUploadForm
contact_form_class = CaseContactForm
case: Zaak = None

case = None

@cached_property
def crumbs(self):
Expand Down Expand Up @@ -154,6 +160,11 @@ def get_context_data(self, **kwargs):
"statuses": self.get_statuses_data(statuses, status_translate),
"documents": documents,
"allowed_file_extensions": sorted(config.allowed_file_extensions),
"new_docs": has_fresh_elements(
documents,
"created",
dt.timedelta(days=settings.DOCUMENT_RECENT_DAYS),
),
}
context["case"].update(self.get_upload_info_context(self.case))
context["anchors"] = self.get_anchors(statuses, documents)
Expand Down Expand Up @@ -201,7 +212,7 @@ def get_upload_info_context(self, case: Zaak):
zt_statustype_config = ztc.zaaktypestatustypeconfig_set.get(
statustype_url=case.status.statustype.url
)
# case has no status, or status type not found
# case has no status, or statustype config not found
except (AttributeError, ObjectDoesNotExist):
pass
else:
Expand Down Expand Up @@ -285,8 +296,10 @@ def get_case_document_files(self, case: Zaak) -> List[SimpleFile]:
"info_id": info_obj.uuid,
},
),
created=case_info_obj.registratiedatum,
)
)

return documents

def get_form_kwargs(self):
Expand Down
23 changes: 17 additions & 6 deletions src/open_inwoner/components/templates/components/File/File.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
{% load i18n link_tags utils icon_tags form_tags dropdown_tags button_tags string_tags %}
{% load i18n l10n link_tags utils icon_tags form_tags dropdown_tags button_tags string_tags %}

<aside class="file" aria-label="{% trans "Bestand" %} {{ name }}">
<div class="file__file">
{% if is_image %}
{% icon icon="image" outlined=True %}
{% else %}
{% icon icon="description" outlined=True %}
{% endif %}
<p class="file__symbol">
{% if is_image %}
{% icon icon="image" outlined=True %}
{% else %}
{% icon icon="description" outlined=True %}
{% endif %}
</p>


<p class="p">
{% if recently_added %}
{% icon icon="fiber_manual_record" outlined=False extra_classes="file__file--recent" %}
<span class="file__file--recent">{% trans "Nieuw" %}</span>
<br>
{% endif %}
{{ name }}
{% if extension and size %}
({{extension}}, {{size|readable_size}})
Expand All @@ -16,6 +25,8 @@
{% elif size %}
({{size|readable_size}})
{% endif %}
<br>
<span class="file__date">{{ created|date:'d.m.Y' }}</span>
</p>
{% if allow_delete %}
{% dropdown icon="more_horiz" %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h3 class="h3" id="files">{{ title }}</h3>
{% for file in files %}
{% url download_view uuid=file.uuid as download_url %}
<li class="file-list__list-item">
{% file file=file.file name=file.name uuid=file.uuid allow_delete=allow_delete download_url=download_url show_download=show_download %}
{% file file=file.file created=created name=file.name uuid=file.uuid allow_delete=allow_delete download_url=download_url show_download=show_download %}
</li>
{% empty %}
<li><p class="p">{% trans "Er zijn nog geen bestanden geupload" %}</p></li>
Expand Down
15 changes: 13 additions & 2 deletions src/open_inwoner/components/templatetags/file_tags.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import datetime
import pathlib

from django import template
from django.conf import settings

from filer.models.filemodels import File

from open_inwoner.openzaak.api_models import ZaakInformatieObject
from open_inwoner.cms.cases.views.status import SimpleFile
from open_inwoner.utils.time import is_fresh

register = template.Library()

Expand Down Expand Up @@ -46,7 +49,7 @@ def file_list(files, **kwargs):


@register.inclusion_tag("components/File/FileList.html")
def case_document_list(documents: list[ZaakInformatieObject], **kwargs) -> dict:
def case_document_list(documents: list[SimpleFile], **kwargs) -> dict:
"""
Shows multiple case documents in a file_list.
Expand Down Expand Up @@ -141,6 +144,14 @@ def file(file, **kwargs):
if kwargs.get("download_url"):
kwargs["url"] = kwargs["download_url"]

created = getattr(file, "created", None)
kwargs["created"] = created

if is_fresh(
file, "created", datetime.timedelta(days=settings.DOCUMENT_RECENT_DAYS)
):
kwargs["recently_added"] = True

if "show_download" not in kwargs:
kwargs["show_download"] = True

Expand Down
7 changes: 4 additions & 3 deletions src/open_inwoner/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,7 @@
#
LOG_OUTGOING_REQUESTS_DB_SAVE = config("LOG_OUTGOING_REQUESTS_DB_SAVE", default=True)
LOG_OUTGOING_REQUESTS_RESET_DB_SAVE_AFTER = None # reset config after $ minutes
LOG_OUTGOING_REQUESTS_MAX_AGE = config(
"LOG_OUTGOING_REQUESTS_MAX_AGE", default=30
) # clean logs after 30 days


#
# AUTH settings - user accounts, passwords, backends...
Expand Down Expand Up @@ -801,6 +799,9 @@
"ZGW_LIMIT_NOTIFICATIONS_FREQUENCY", default=60 * 15
)

# recent documents: created/added no longer than n days in the past
DOCUMENT_RECENT_DAYS = config("DOCUMENT_RECENT_DAYS", default=1)

#
# Maykin fork of DJANGO-TWO-FACTOR-AUTH
#
Expand Down
12 changes: 12 additions & 0 deletions src/open_inwoner/openzaak/tests/test_case_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import requests_mock
from django_webtest import WebTest
from freezegun import freeze_time
from timeline_logger.models import TimelineLog
from webtest import Upload
from webtest.forms import Hidden
Expand Down Expand Up @@ -289,6 +290,7 @@ def setUpTestData(cls):
"info_id": cls.informatie_object["uuid"],
},
),
created=datetime.datetime(2021, 1, 12, 0, 0, 0),
)

def _setUpOASMocks(self, m):
Expand Down Expand Up @@ -350,6 +352,7 @@ def _setUpMocks(self, m):
text="document content",
)

@freeze_time("2021-01-12 17:00:00")
def test_status_is_retrieved_when_user_logged_in_via_digid(self, m):
self.maxDiff = None

Expand Down Expand Up @@ -394,9 +397,18 @@ def test_status_is_retrieved_when_user_logged_in_via_digid(self, m):
"external_upload_url": "",
"allowed_file_extensions": sorted(self.config.allowed_file_extensions),
"contact_form_enabled": False,
"new_docs": True,
},
)

@freeze_time("2021-01-12 17:00:00")
def test_new_docs(self, m):
self._setUpMocks(m)

response = self.app.get(self.case_detail_url, user=self.user)

self.assertEqual(response.context.get("case")["new_docs"], True)

def test_page_displays_expected_data(self, m):
self._setUpMocks(m)

Expand Down
26 changes: 23 additions & 3 deletions src/open_inwoner/scss/components/File/File.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@
display: flex;
}

&__file > *[class*='icon']:first-child,
&__file > *[class*='Icon']:first-child {
background-color: var(--color-gray-light);
&__symbol {
display: flex;
align-items: center;
background-color: var(--color-gray-lightest);
padding: var(--spacing-large);
margin: 0;
box-sizing: content-box;

align-self: stretch;

*[class*='icon'],
*[class*='Icon'] {
padding: var(--spacing-large);
}
}

&__file .link,
Expand All @@ -25,6 +34,7 @@
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
line-height: var(--spacing-extra-large);
}

&__file .link__text {
Expand All @@ -46,4 +56,14 @@
&__file + .p {
margin-top: var(--spacing-small);
}

&__file--recent {
color: var(--color-red);
font-size: var(--font-size-body-extra-small);
vertical-align: middle;
}

&__date {
font-size: var(--font-size-body-extra-small);
}
}
3 changes: 3 additions & 0 deletions src/open_inwoner/scss/components/Status/_Status.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#documents {
justify-content: left;
}
1 change: 1 addition & 0 deletions src/open_inwoner/scss/components/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
@import './Social/Social.scss';
@import './Spinner/Spinner.scss';
@import './Status/StatusList.scss';
@import './Status/Status.scss';
@import './Step/StepIndicator.scss';
@import './Sticky/Sticky.scss';
@import './Table/Table.scss';
Expand Down
1 change: 1 addition & 0 deletions src/open_inwoner/scss/views/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@
--font-size-body: 16px;
--font-line-height-body: 21px;

--font-size-body-extra-small: 12px;
--font-size-body-small: 14px;
--font-size-body-large: 20px;
--font-line-height-body-small: 20px;
Expand Down
2 changes: 1 addition & 1 deletion src/open_inwoner/templates/pages/cases/status_inner.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ <h2 class="h2" id="statuses">{% trans 'Status' %}</h2>

{# Documents. #}
{% if case.documents %}
<h2 class="h2" id="documents">{% trans 'Documenten' %}</h2>
<h2 class="h2" id="documents">{% trans 'Documenten' %}{% if case.new_docs %}{% icon icon="fiber_manual_record" outlined=False extra_classes="file__file--recent" %}{% endif %}</h2>
{% case_document_list case.documents %}
{% endif %}

Expand Down
40 changes: 40 additions & 0 deletions src/open_inwoner/utils/time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
Utility functions/classes related to (date-)times
"""

import datetime as dt
from typing import Sequence

from django.utils import timezone


def is_fresh(instance: object, attribute_name: str, delta: dt.timedelta) -> bool:
"""
Return `True` if `instance` is "fresh", `False` otherwise
An object is fresh iff it has an attribute named `$attribute_name`
which has been set no earlier than some point in the past calculated
on the basis of `delta`.
"""
fresh = False

date_time = getattr(instance, attribute_name, None)

if not date_time:
return False
try:
fresh = (timezone.now() - date_time) <= delta
except TypeError: # instance has naive datetime
fresh = (dt.datetime.now() - date_time) <= delta

return fresh


def has_fresh_elements(
collection: Sequence, attribute_name: str, delta: dt.timedelta
) -> bool:
"""
Return `True` if `collection` has at least one "fresh" element, `False`
otherwise
"""
return any(is_fresh(elem, attribute_name, delta) for elem in collection)

0 comments on commit b64f3e2

Please sign in to comment.