Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,7 @@ class Meta:
read_only_fields = fields

uuid = BaseReportSerializer().fields['uuid']
short_id = BaseReportSerializer().fields['short_id']
# NOTE: user_uuid is used by AIMA for knowing who to send notifications.
user_uuid = BaseReportSerializer().fields['user_uuid']
created_at = BaseReportSerializer().fields['created_at']
Expand All @@ -724,6 +725,7 @@ class Meta:
model = BaseReportSerializer.Meta.model
fields = (
"uuid",
"short_id",
"user_uuid",
"created_at",
"created_at_local",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ variables:
response_data_validation: &retrieve_validation
observation:
uuid: !re_fullmatch "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"
short_id: !anystr
user:
uuid: !re_fullmatch "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"
locale: !anystr
Expand Down
1 change: 1 addition & 0 deletions api/tests/integration/identification_tasks/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ variables:
response_data_validation: &retrieve_validation
observation:
uuid: !re_fullmatch "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"
short_id: !anystr
user_uuid: !re_fullmatch "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"
created_at: !re_fullmatch \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{6}Z
created_at_local: !re_fullmatch \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{6}([+-]\d{2}:\d{2}|Z)
Expand Down
17 changes: 16 additions & 1 deletion api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from rest_framework import status
from rest_framework.decorators import action
from rest_framework.exceptions import ValidationError
from rest_framework.filters import SearchFilter
from rest_framework.mixins import (
CreateModelMixin,
ListModelMixin,
Expand Down Expand Up @@ -238,11 +239,14 @@ class BaseReportViewSet(
"photos",
queryset=Photo.objects.visible()
)
).annotate(
pk_str=models.functions.Cast('pk', output_field=models.CharField()),
).non_deleted().filter(point__isnull=False).order_by('-server_upload_time')

lookup_url_kwarg = "uuid"

filter_backends = (DjangoFilterBackend,)
filter_backends = (DjangoFilterBackend, SearchFilter)
search_fields = ("report_id", "pk_str")

permission_classes = (ReportPermissions,)

Expand Down Expand Up @@ -535,9 +539,13 @@ class IdentificationTaskViewSet(RetrieveModelMixin, ListModelMixin, GenericNoMob
"report__photos",
queryset=Photo.objects.visible(),
)
).annotate(
pk_str=models.functions.Cast('pk', output_field=models.CharField()),
)
serializer_class = IdentificationTaskSerializer
filterset_class = IdentificationTaskFilter
filter_backends = (DjangoFilterBackend, SearchFilter)
search_fields = ("report__report_id", "pk_str")
permission_classes = (IdentificationTaskPermissions | UserRolePermission,)

lookup_field = 'pk'
Expand Down Expand Up @@ -678,9 +686,14 @@ class AnnotationViewSet(IdentificationTaskNestedAttribute, NestedViewSetMixin, L
report=models.OuterRef('report')
)
)
).annotate(
report_pk_str=models.functions.Cast('report_id', output_field=models.CharField()),
)

serializer_class = AnnotationSerializer
filter_backends = (DjangoFilterBackend, SearchFilter)
filterset_class = AnnotationFilter
search_fields = ("report_pk_str",) #NOTE: not filtering by 'report__report_id' because in not being shown in the response.
permission_classes = (AnnotationPermissions | UserRolePermission, )

parent_lookup_kwargs = {
Expand Down Expand Up @@ -736,7 +749,9 @@ def get_queryset(self):
class MyAnnotationViewSet(ListModelMixin, GenericNoMobileViewSet):
queryset = IdentificationTaskViewSet.AnnotationViewSet.queryset
serializer_class = IdentificationTaskViewSet.AnnotationViewSet.serializer_class
filter_backends = IdentificationTaskViewSet.AnnotationViewSet.filter_backends
filterset_class = IdentificationTaskViewSet.AnnotationViewSet.filterset_class
search_fields = IdentificationTaskViewSet.AnnotationViewSet.search_fields
permission_classes = (MyAnnotationPermissions, )

lookup_field = 'pk'
Expand Down