-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2397 from uktrade/uat
Production release
- Loading branch information
Showing
16 changed files
with
490 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,57 @@ | ||
from api.cases.models import Case | ||
from api.staticdata.statuses.libraries.get_case_status import get_status_value_from_case_status_enum | ||
from api.staticdata.statuses.models import CaseStatus | ||
from rest_framework import serializers | ||
|
||
from api.staticdata.statuses.enums import CaseStatusEnum | ||
|
||
|
||
class ApplicationChangeStatusSerializer(serializers.Serializer): | ||
|
||
status = serializers.ChoiceField(choices=CaseStatusEnum.all()) | ||
note = serializers.CharField(required=False, allow_blank=True, allow_null=True, max_length=2000) | ||
|
||
|
||
class ApplicationStatusSerializer(serializers.ModelSerializer): | ||
status_display = serializers.SerializerMethodField() | ||
|
||
class Meta: | ||
model = CaseStatus | ||
fields = ("status", "status_display") | ||
|
||
def get_status_display(self, obj): | ||
return get_status_value_from_case_status_enum(obj.status) | ||
|
||
|
||
class CaseAmendmentSerializer(serializers.Serializer): | ||
status = serializers.SerializerMethodField() | ||
ecju_query_count = serializers.SerializerMethodField() | ||
reference_code = serializers.CharField() | ||
submitted_at = serializers.DateTimeField() | ||
id = serializers.UUIDField() | ||
status = ApplicationStatusSerializer() | ||
|
||
def get_ecju_query_count(self, instance): | ||
return instance.case_ecju_query.all().count() | ||
|
||
|
||
class ApplicationHistorySerializer(serializers.ModelSerializer): | ||
amendment_history = serializers.SerializerMethodField() | ||
|
||
def get_amendment_history(self, instance): | ||
amendments = [] | ||
case_amended = instance | ||
|
||
# Go backwards through amendment chain until we find the original case | ||
while case_amended.superseded_by: | ||
case_amended = case_amended.superseded_by | ||
|
||
# Travel forwards in amendment chain to find the latest amended case | ||
while case_amended: | ||
case_amended_data = CaseAmendmentSerializer(case_amended).data | ||
amendments.append(case_amended_data) | ||
case_amended = case_amended.amendment_of | ||
return amendments | ||
|
||
class Meta: | ||
model = Case | ||
fields = ("id", "reference_code", "amendment_history") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from django.core.exceptions import ObjectDoesNotExist | ||
from django.http import Http404 | ||
from api.core.authentication import ExporterAuthentication | ||
from api.core.exceptions import NotFoundError | ||
|
||
from api.applications.libraries.get_applications import get_application | ||
from api.core.permissions import IsExporterInOrganisation | ||
|
||
|
||
class ExporterApplicationMixin: | ||
# Mixin for views which checks the exporter is within same organisation as the application | ||
# Checks Exporter is authenticated | ||
|
||
authentication_classes = (ExporterAuthentication,) | ||
permission_classes = [ | ||
IsExporterInOrganisation, | ||
] | ||
|
||
def setup(self, request, *args, **kwargs): | ||
super().setup(request, *args, **kwargs) | ||
try: | ||
self.application = get_application(self.kwargs["pk"]) | ||
except (ObjectDoesNotExist, NotFoundError): | ||
raise Http404() | ||
|
||
def get_object(self): | ||
self.check_object_permissions(self.request, self.application) | ||
return self.application | ||
|
||
def get_organisation(self): | ||
return self.application.organisation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.