Skip to content

Commit bcf3775

Browse files
authored
Merge branch 'master' into dependabot/pip/app/workers/pip-512858e340
2 parents 64ce68c + 200dfa0 commit bcf3775

5 files changed

Lines changed: 132 additions & 43 deletions

File tree

app/api/api/serializers.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,6 @@ class Meta:
707707

708708

709709
class ScanReportTableListSerializerV2(DynamicFieldsMixin, serializers.ModelSerializer):
710-
711710
date_event = ScanReportFieldListSerializerV2()
712711
person_id = ScanReportFieldListSerializerV2()
713712

@@ -754,6 +753,29 @@ class Meta:
754753
fields = "__all__"
755754

756755

756+
class ScanReportConceptSerializerV2(DynamicFieldsMixin, serializers.ModelSerializer):
757+
concept = ConceptSerializerV2()
758+
759+
class Meta:
760+
model = ScanReportConcept
761+
fields = ["id", "object_id", "creation_type", "content_type", "concept"]
762+
763+
764+
class ScanReportValueViewSerializerV3(serializers.ModelSerializer):
765+
concepts = ScanReportConceptSerializerV2(many=True, read_only=True)
766+
767+
class Meta:
768+
model = ScanReportValue
769+
fields = [
770+
"id",
771+
"value",
772+
"frequency",
773+
"value_description",
774+
"scan_report_field",
775+
"concepts",
776+
]
777+
778+
757779
class ScanReportValueViewSerializerV2(serializers.ModelSerializer):
758780
class Meta:
759781
model = ScanReportValue

app/api/api/urls.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@
9898
views.ScanReportValueListV2.as_view(),
9999
name="scan-report-values",
100100
),
101+
path(
102+
"v3/scanreports/<int:pk>/tables/<int:table_pk>/fields/<int:field_pk>/values/",
103+
views.ScanReportValueListV3.as_view(),
104+
name="scan-report-values",
105+
),
101106
path(r"user/me/", views.UserDetailView.as_view(), name="currentuser"),
102107
path(r"v2/users/", views.UserViewSet.as_view(), name="users-list"),
103108
path(r"v2/usersfilter/", views.UserFilterViewSet.as_view(), name="usersfilter"),

app/api/api/views.py

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
ScanReportTableEditSerializer,
1919
ScanReportTableListSerializerV2,
2020
ScanReportValueViewSerializerV2,
21+
ScanReportValueViewSerializerV3,
2122
ScanReportViewSerializerV2,
2223
UserSerializer,
2324
)
@@ -866,11 +867,72 @@ def get(self, request, *args, **kwargs):
866867

867868
return self.list(request, *args, **kwargs)
868869

870+
def get_queryset(self):
871+
return ScanReportValue.objects.filter(scan_report_field=self.field).order_by(
872+
"id"
873+
)
874+
875+
@method_decorator(cache_page(60 * 15))
876+
@method_decorator(vary_on_cookie)
877+
def list(self, request, *args, **kwargs):
878+
return super().list(request, *args, **kwargs)
879+
880+
881+
class ScanReportValueListV3(ScanReportPermissionMixin, GenericAPIView, ListModelMixin):
882+
"""
883+
A view for listing ScanReportValue objects associated with a
884+
specific ScanReportField. This view provides filtering,
885+
pagination, and caching capabilities for the ScanReportValue
886+
objects. It uses DjangoFilterBackend for filtering and a custom
887+
pagination class for paginated responses. The view also caches the
888+
list response for 15 minutes.
889+
890+
Attributes:
891+
filterset_fields (dict): Specifies the fields and lookup types
892+
available for filtering.
893+
filter_backends (list): Specifies the filter backends to be
894+
used.
895+
pagination_class (class): Specifies the pagination class to be
896+
used.
897+
serializer_class (class): Specifies the serializer class to be
898+
used for the response.
899+
900+
Methods:
901+
get(request, *args, **kwargs):
902+
Handles GET requests and retrieves the ScanReportField
903+
object based on the provided field_pk. Returns the list of
904+
ScanReportValue objects associated with the field.
905+
906+
get_queryset():
907+
Returns the queryset of ScanReportValue objects filtered by
908+
the associated ScanReportField. The queryset is ordered by
909+
ID and only includes specific fields.
910+
911+
list(request, *args, **kwargs):
912+
Overrides the default list method to add caching and
913+
vary-on-cookie functionality. Returns the paginated list of
914+
ScanReportValue objects.
915+
"""
916+
917+
filterset_fields = {
918+
"value": ["in", "icontains"],
919+
}
920+
filter_backends = [DjangoFilterBackend]
921+
pagination_class = CustomPagination
922+
serializer_class = ScanReportValueViewSerializerV3
923+
924+
@extend_schema(responses=ScanReportValueViewSerializerV3)
925+
def get(self, request, *args, **kwargs):
926+
self.field = get_object_or_404(ScanReportField, pk=kwargs["field_pk"])
927+
928+
return self.list(request, *args, **kwargs)
929+
869930
def get_queryset(self):
870931
return (
871932
ScanReportValue.objects.filter(scan_report_field=self.field)
872933
.order_by("id")
873-
.only("id", "value", "frequency", "value_description", "scan_report_field")
934+
.select_related("scan_report_field")
935+
.prefetch_related("concepts", "concepts__concept")
874936
)
875937

876938
@method_decorator(cache_page(60 * 15))

app/next-client-app/package-lock.json

Lines changed: 40 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/next-client-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"framer-motion": "^11.11.8",
3434
"lucide": "^0.414.0",
3535
"lucide-react": "^0.510.0",
36-
"next": "^15.3.2",
36+
"next": "^15.3.5",
3737
"next-auth": "^4.24.7",
3838
"next-runtime-env": "^3.3.0",
3939
"next-themes": "^0.4.6",

0 commit comments

Comments
 (0)