Skip to content

Commit

Permalink
Merge pull request #533 from oakdbca/cs-uat-changes
Browse files Browse the repository at this point in the history
CS UAT Changes
  • Loading branch information
xzzy authored Nov 15, 2024
2 parents 283ce8d + 1ff0630 commit 105578f
Show file tree
Hide file tree
Showing 70 changed files with 2,729 additions and 1,402 deletions.
13 changes: 12 additions & 1 deletion boranga/components/conservation_status/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ class ProposalAmendmentReasonAdmin(


class AbstractListAdmin(DeleteProtectedModelAdmin):
list_display = ["code", "label", "applies_to_species", "applies_to_communities"]
list_display = [
"code",
"label",
"applies_to_flora",
"applies_to_fauna",
"applies_to_communities",
]


class AbstractCategoryAdmin(DeleteProtectedModelAdmin):
Expand All @@ -27,6 +33,10 @@ class WAPriorityCategoryAdmin(ArchivableModelAdminMixin, AbstractCategoryAdmin):
filter_horizontal = ("wa_priority_lists",)


class IUCNVersionAdmin(ArchivableModelAdminMixin, AbstractListAdmin):
pass


class WALegislativeListAdmin(ArchivableModelAdminMixin, AbstractListAdmin):
pass

Expand All @@ -47,6 +57,7 @@ class ConservationChangeCodeAdmin(ArchivableModelAdminMixin, DeleteProtectedMode
admin.site.register(models.WAPriorityCategory, WAPriorityCategoryAdmin)
admin.site.register(models.WALegislativeList, WALegislativeListAdmin)
admin.site.register(models.WALegislativeCategory, WALegislativeCategoryAdmin)
admin.site.register(models.IUCNVersion, IUCNVersionAdmin)
admin.site.register(
models.CommonwealthConservationList, CommonwealthConservationListAdmin
)
Expand Down
108 changes: 89 additions & 19 deletions boranga/components/conservation_status/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
ConservationStatusReferral,
ConservationStatusUserAction,
CSExternalRefereeInvite,
IUCNVersion,
ProposalAmendmentReason,
WALegislativeCategory,
WALegislativeList,
Expand Down Expand Up @@ -171,6 +172,7 @@ def get(self, request, format=None):
"wa_legislative_categories": WALegislativeCategory.get_categories_dict(
group_type, active_only=True
),
"iucn_versions": IUCNVersion.get_lists_dict(group_type, active_only=True),
"commonwealth_conservation_lists": CommonwealthConservationList.get_lists_dict(
group_type, active_only=True
),
Expand Down Expand Up @@ -326,10 +328,10 @@ def filter_queryset(self, request, queryset, view):
)
if filter_international_relevance == "true":
if queryset.model is ConservationStatus:
queryset = queryset.exclude(international_conservation__isnull=True)
queryset = queryset.exclude(other_conservation_assessment__isnull=True)
elif queryset.model is ConservationStatusReferral:
queryset = queryset.exclude(
conservation_status__international_conservation__isnull=True
conservation_status__other_conservation_assessment__isnull=True
)

filter_from_effective_from_date = request.POST.get(
Expand Down Expand Up @@ -414,6 +416,27 @@ def filter_queryset(self, request, queryset, view):
submitter=request.user.id,
processing_status=ConservationStatus.PROCESSING_STATUS_DISCARDED,
)
elif (
filter_application_status
== ConservationStatus.PROCESSING_STATUS_AWAITING_ASSESSOR_ACTION
):
queryset = queryset.filter(
processing_status__in=ConservationStatus.PROCESSING_STATUSES_AWAITING_ASSESSOR_ACTION
)
elif (
filter_application_status
== ConservationStatus.PROCESSING_STATUS_AWAITING_APPROVER_ACTION
):
queryset = queryset.filter(
processing_status__in=ConservationStatus.PROCESSING_STATUSES_AWAITING_APPROVER_ACTION
)
elif (
filter_application_status
== ConservationStatus.PROCESSING_STATUS_INACTIVE
):
queryset = queryset.filter(
processing_status__in=ConservationStatus.PROCESSING_STATUSES_INACTIVE
)
else:
queryset = queryset.filter(
processing_status=filter_application_status
Expand Down Expand Up @@ -567,21 +590,23 @@ def species_cs_internal_export(self, request, *args, **kwargs):
"genus",
"phylogenetic_group",
"processing_status",
"effective_from_date",
"effective_to_date",
"effective_from",
"effective_to",
"conservation_status_number",
]

serializer = ListSpeciesConservationStatusSerializer(
qs, context={"request": request}, many=True
)
serialized_data = serializer.data

filtered_data = []
for obj in serialized_data:
filtered_obj = {
key: value for key, value in obj.items() if key in allowed_fields
}
for key, value in obj.items():
if key == "phylogenetic_group":
filtered_obj[key] = ", ".join(value)
filtered_data.append(filtered_obj)

def flatten_dict(d, parent_key="", sep="_"):
Expand All @@ -603,7 +628,7 @@ def flatten_dict(d, parent_key="", sep="_"):
"Common Name",
"Family",
"Genera",
"Phylo Group",
"Phylo Group(s)",
"Processing Status",
"Effective From Date",
"Effective To Date",
Expand All @@ -618,6 +643,7 @@ def flatten_dict(d, parent_key="", sep="_"):
"Effective To Date",
"Family",
"Genera",
"Phylo Group(s)",
"Processing Status",
]
df = df[column_order]
Expand Down Expand Up @@ -913,10 +939,10 @@ def filter_queryset(self, request, queryset, view):
)
if filter_international_relevance == "true":
if queryset.model is ConservationStatus:
queryset = queryset.exclude(international_conservation__isnull=True)
queryset = queryset.exclude(other_conservation_assessment__isnull=True)
elif queryset.model is ConservationStatusReferral:
queryset = queryset.exclude(
conservation_status__international_conservation__isnull=True
conservation_status__other_conservation_assessment__isnull=True
)

filter_from_effective_from_date = request.POST.get(
Expand Down Expand Up @@ -1000,6 +1026,27 @@ def filter_queryset(self, request, queryset, view):
submitter=request.user.id,
processing_status=ConservationStatus.PROCESSING_STATUS_DISCARDED,
)
elif (
filter_application_status
== ConservationStatus.PROCESSING_STATUS_AWAITING_ASSESSOR_ACTION
):
queryset = queryset.filter(
processing_status__in=ConservationStatus.PROCESSING_STATUSES_AWAITING_ASSESSOR_ACTION
)
elif (
filter_application_status
== ConservationStatus.PROCESSING_STATUS_AWAITING_APPROVER_ACTION
):
queryset = queryset.filter(
processing_status__in=ConservationStatus.PROCESSING_STATUSES_AWAITING_APPROVER_ACTION
)
elif (
filter_application_status
== ConservationStatus.PROCESSING_STATUS_INACTIVE
):
queryset = queryset.filter(
processing_status__in=ConservationStatus.PROCESSING_STATUSES_INACTIVE
)
else:
queryset = queryset.filter(
processing_status=filter_application_status
Expand Down Expand Up @@ -1149,11 +1196,9 @@ def community_cs_internal_export(self, request, *args, **kwargs):
"community_number",
"community_migrated_id",
"community_name",
"region",
"district",
"processing_status",
"effective_from_date",
"effective_to_date",
"effective_from",
"effective_to",
]

serializer = ListCommunityConservationStatusSerializer(
Expand All @@ -1167,6 +1212,7 @@ def community_cs_internal_export(self, request, *args, **kwargs):
key: value for key, value in obj.items() if key in allowed_fields
}
filtered_data.append(filtered_obj)
logger.debug(filtered_data)

def flatten_dict(d, parent_key="", sep="_"):
flattened_dict = {}
Expand All @@ -1185,8 +1231,6 @@ def flatten_dict(d, parent_key="", sep="_"):
"Community",
"Community Id",
"Community Name",
"Region",
"District",
"Processing Status",
"Effective From Date",
"Effective To Date",
Expand All @@ -1197,8 +1241,6 @@ def flatten_dict(d, parent_key="", sep="_"):
"Community",
"Community Id",
"Community Name",
"Region",
"District",
"Effective From Date",
"Effective To Date",
"Processing Status",
Expand Down Expand Up @@ -1935,14 +1977,28 @@ def switch_status(self, request, *args, **kwargs):

@detail_route(
methods=[
"POST",
"PATCH",
],
detail=True,
permission_classes=[ConservationStatusPermission],
)
def proposed_ready_for_agenda(self, request, *args, **kwargs):
def proposed_for_agenda(self, request, *args, **kwargs):
instance = self.get_object()
instance.proposed_ready_for_agenda(request)
instance.proposed_for_agenda(request)
serializer_class = self.internal_serializer_class()
serializer = serializer_class(instance, context={"request": request})
return Response(serializer.data)

@detail_route(
methods=[
"PATCH",
],
detail=True,
permission_classes=[ConservationStatusPermission],
)
def ready_for_agenda(self, request, *args, **kwargs):
instance = self.get_object()
instance.ready_for_agenda(request)
serializer_class = self.internal_serializer_class()
serializer = serializer_class(instance, context={"request": request})
return Response(serializer.data)
Expand Down Expand Up @@ -2012,6 +2068,18 @@ def reinstate(self, request, *args, **kwargs):
serializer = self.get_serializer(instance)
return Response(serializer.data)

@detail_route(methods=["patch"], detail=True)
def defer(self, request, *args, **kwargs):
instance = self.get_object()
reason = request.data.get("reason")
review_due_date = request.data.get("review_due_date", None)
if not reason:
raise serializers.ValidationError("Reason is required")
instance.defer(request, reason, review_due_date)
serializer_class = self.internal_serializer_class()
serializer = serializer_class(instance, context={"request": request})
return Response(serializer.data)

@detail_route(
methods=["patch"],
detail=True,
Expand Down Expand Up @@ -2267,6 +2335,7 @@ def filter_list(self, request, *args, **kwargs):
"wa_legislative_categories": WALegislativeCategory.get_categories_dict(
group_type
),
"iucn_versions": IUCNVersion.get_lists_dict(group_type),
"commonwealth_conservation_lists": CommonwealthConservationList.get_lists_dict(
group_type
),
Expand Down Expand Up @@ -2330,6 +2399,7 @@ def community_filter_list(self, request, *args, **kwargs):
"wa_legislative_categories": WALegislativeCategory.get_categories_dict(
group_type
),
"iucn_versions": IUCNVersion.get_lists_dict(group_type),
"commonwealth_conservation_lists": CommonwealthConservationList.get_lists_dict(
group_type
),
Expand Down
Loading

0 comments on commit 105578f

Please sign in to comment.