Skip to content

Commit

Permalink
Display last comment date in incident API response, add corresponding
Browse files Browse the repository at this point in the history
filters
  • Loading branch information
Augustin-FL committed Jan 7, 2025
1 parent eb08124 commit a39a4fd
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 19 deletions.
17 changes: 15 additions & 2 deletions fir_api/filters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.apps import apps
from django.utils.translation import gettext_lazy as _
from django_filters.rest_framework import (
FilterSet,
DateTimeFilter,
Expand Down Expand Up @@ -70,7 +71,10 @@ class IncidentFilter(FilterSet):
subject = CharFilter(field_name="subject", lookup_expr="icontains")
status = ValueChoiceFilter(field_name="status", choices=STATUS_CHOICES)
status__not = ValueChoiceFilter(
field_name="status", choices=STATUS_CHOICES, exclude=True
field_name="status",
choices=STATUS_CHOICES,
exclude=True,
label=_("Status is not"),
)
confidentiality = ValueChoiceFilter(
field_name="confidentiality", choices=CONFIDENTIALITY_LEVEL
Expand All @@ -91,12 +95,21 @@ class IncidentFilter(FilterSet):
)
is_incident = BooleanFilter(field_name="is_incident")
is_major = BooleanFilter(field_name="is_major")
last_comment_date_before = DateTimeFilter(
field_name="last_comment_date",
lookup_expr="lte",
label=_("Last comment date is less than or equal to"),
)
last_comment_date_after = DateTimeFilter(
field_name="last_comment_date",
lookup_expr="gte",
label=_("Last comment date is greater than or equal to"),
)

class Meta:
model = Incident
fields = [
"id",
"date",
"subject",
"status",
"concerned_business_lines",
Expand Down
24 changes: 19 additions & 5 deletions fir_api/locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-12-29 06:34-0500\n"
"POT-Creation-Date: 2025-01-07 21:46+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand All @@ -18,6 +18,18 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"

#: filters.py:77
msgid "Status is not"
msgstr "Status n'est pas"

#: filters.py:101
msgid "Last comment date is less than or equal to"
msgstr "Date du dernier commentaire est inférieure ou égale à"

#: filters.py:106
msgid "Last comment date is greater than or equal to"
msgstr "Date du dernier commentaire est supérieure ou égale à"

#: templates/fir_api/plugins/user_profile.html:7
msgid "API Access"
msgstr "Accès à l'API"
Expand All @@ -26,15 +38,17 @@ msgstr "Accès à l'API"
msgid ""
"You need to be authenticated in order to use the API. It will accept session "
"or token based authentication."
msgstr "Vous devez être authentifié pour utiliser l'API, à l'aide d'un jeton "
"ou d'une session."
msgstr ""
"Vous devez être authentifié pour utiliser l'API, à l'aide d'un jeton ou "
"d'une session."

#: templates/fir_api/plugins/user_profile.html:10
msgid ""
"Tokens can be managed in the administration interface and should be "
"specified as a <strong>request header</strong>.</p>"
msgstr "Les jetons peuvent être gérés dans l'interface d'administration et doivent être "
"spécifiés dans les <strong>en-têtes des requêtes</strong>.</p>"
msgstr ""
"Les jetons peuvent être gérés dans l'interface d'administration et doivent "
"être spécifiés dans les <strong>en-têtes des requêtes</strong>.</p>"

#: templates/fir_api/plugins/user_profile.html:11
msgid "Example:"
Expand Down
1 change: 1 addition & 0 deletions fir_api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ class IncidentSerializer(serializers.ModelSerializer):
description = serializers.CharField(
style={"base_template": "textarea.html"}, required=False
)
last_comment_date = serializers.DateTimeField(read_only=True)

if apps.is_installed("fir_todos"):
todoitem_set = TodoSerializer(many=True, read_only=True)
Expand Down
15 changes: 3 additions & 12 deletions fir_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,7 @@
from rest_framework import renderers
from rest_framework.response import Response
from rest_framework.filters import OrderingFilter
from django_filters.rest_framework import (
DjangoFilterBackend,
FilterSet,
DateTimeFilter,
CharFilter,
NumberFilter,
MultipleChoiceFilter,
AllValuesFilter,
BooleanFilter,
)
from django_filters.rest_framework import DjangoFilterBackend

from fir_api.serializers import (
UserSerializer,
Expand Down Expand Up @@ -94,8 +85,8 @@ class IncidentViewSet(
API endpoints for viewing, creating and editing incidents
"""

queryset = (
Incident.objects.all()
queryset = (Incident.objects.all()).annotate(
last_comment_date=Max("comments__date")
) # Will be overriden by get_queryset(). We still need to define this property as DRF use it to get the basename
serializer_class = IncidentSerializer
permission_classes = (IsAuthenticated, IsIncidentHandler)
Expand Down

0 comments on commit a39a4fd

Please sign in to comment.