Skip to content

Commit

Permalink
Merge pull request dbca-wa#393 from awf-dbca/ocr-cleanup
Browse files Browse the repository at this point in the history
OCR/OCC cleanup
  • Loading branch information
xzzy authored Jun 14, 2024
2 parents c48784d + d901179 commit dc98f9a
Show file tree
Hide file tree
Showing 24 changed files with 487 additions and 999 deletions.
78 changes: 19 additions & 59 deletions boranga/components/occurrence/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,46 +236,16 @@ def get_date(filter_date):
if filter_submitted_to_date and not filter_submitted_from_date:
queryset = queryset.filter(reported_date__lte=filter_submitted_to_date)

filter_from_effective_from_date = request.GET.get(
"filter_from_effective_from_date"
)
filter_to_effective_from_date = request.GET.get(
"filter_to_effective_from_date"
)

filter_from_effective_to_date = request.GET.get(
"filter_from_effective_to_date"
)
filter_to_effective_to_date = request.GET.get("filter_to_effective_to_date")

if filter_from_effective_from_date:
queryset = queryset.filter(
effective_from__gte=filter_from_effective_from_date
)
if filter_to_effective_from_date:
queryset = queryset.filter(
effective_from__lte=filter_to_effective_from_date
)

if filter_from_effective_to_date:
queryset = queryset.filter(
effective_to__gte=filter_from_effective_to_date
)
if filter_to_effective_to_date:
queryset = queryset.filter(
effective_to__lte=filter_to_effective_to_date
)

filter_from_review_due_date = request.GET.get("filter_from_review_due_date")
filter_to_review_due_date = request.GET.get("filter_to_review_due_date")
filter_from_observation_date = request.GET.get("filter_observation_from_date")
filter_to_observation_date = request.GET.get("filter_observation_to_date")

if filter_from_review_due_date:
if filter_from_observation_date:
queryset = queryset.filter(
review_due_date__gte=filter_from_review_due_date
observation_date__gte=filter_from_observation_date
)
if filter_to_review_due_date:
if filter_to_observation_date:
queryset = queryset.filter(
review_due_date__lte=filter_to_review_due_date
observation_date__lte=filter_to_observation_date
)

else:
Expand Down Expand Up @@ -308,7 +278,19 @@ def get_date(filter_date):
if len(ordering):
queryset = queryset.order_by(*ordering)

queryset = super().filter_queryset(request, queryset, view)
search_text = request.GET.get('search[value]')
search_queryset = queryset
#for search values that cannot be accommodated by DRF
if search_text:
if "internal" in view.name:
observer_ids = OCRObserverDetail.objects.filter(main_observer=True).filter(observer_name__icontains=search_text).values_list("occurrence_report__id", flat=True)
search_queryset = queryset.filter(
Q(submitter_information__name__icontains=search_text) |
Q(id__in=observer_ids)
)

super_queryset = super().filter_queryset(request, queryset, view)
queryset = search_queryset.union(super_queryset)

setattr(view, "_datatables_total_count", total_count)
return queryset
Expand Down Expand Up @@ -2936,28 +2918,6 @@ def filter_queryset(self, request, queryset, view):
if filter_status and not filter_status.lower() == "all":
queryset = queryset.filter(processing_status=filter_status)

filter_from_effective_from_date = request.GET.get(
"filter_from_effective_from_date"
)
filter_to_effective_from_date = request.GET.get("filter_to_effective_from_date")

filter_from_effective_to_date = request.GET.get("filter_from_effective_to_date")
filter_to_effective_to_date = request.GET.get("filter_to_effective_to_date")

if filter_from_effective_from_date:
queryset = queryset.filter(
effective_from__gte=filter_from_effective_from_date
)
if filter_to_effective_from_date:
queryset = queryset.filter(
effective_from__lte=filter_to_effective_from_date
)

if filter_from_effective_to_date:
queryset = queryset.filter(effective_to__gte=filter_from_effective_to_date)
if filter_to_effective_to_date:
queryset = queryset.filter(effective_to__lte=filter_to_effective_to_date)

filter_from_review_due_date = request.GET.get("filter_from_review_due_date")
filter_to_review_due_date = request.GET.get("filter_to_review_due_date")

Expand Down
26 changes: 0 additions & 26 deletions boranga/components/occurrence/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,32 +70,6 @@ def get_date(filter_date):
occurrence_report__reported_date__lte=filter_submitted_to_date
)

filter_from_effective_from_date = request.GET.get(
"filter_from_effective_from_date"
)
filter_to_effective_from_date = request.GET.get("filter_to_effective_from_date")

filter_from_effective_to_date = request.GET.get("filter_from_effective_to_date")
filter_to_effective_to_date = request.GET.get("filter_to_effective_to_date")

if filter_from_effective_from_date:
queryset = queryset.filter(
occurrence_report__effective_from__gte=filter_from_effective_from_date
)
if filter_to_effective_from_date:
queryset = queryset.filter(
occurrence_report__effective_from__lte=filter_to_effective_from_date
)

if filter_from_effective_to_date:
queryset = queryset.filter(
occurrence_report__effective_to__gte=filter_from_effective_to_date
)
if filter_to_effective_to_date:
queryset = queryset.filter(
occurrence_report__effective_to__lte=filter_to_effective_to_date
)

filter_from_review_due_date = request.GET.get("filter_from_review_due_date")
filter_to_review_due_date = request.GET.get("filter_to_review_due_date")

Expand Down
59 changes: 21 additions & 38 deletions boranga/components/occurrence/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,6 @@ class OccurrenceReport(SubmitterInformationModelMixin, RevisionedMixin):
PROCESSING_STATUS_CLOSED,
]

REVIEW_STATUS_CHOICES = (
("not_reviewed", "Not Reviewed"),
("awaiting_amendments", "Awaiting Amendments"),
("amended", "Amended"),
("accepted", "Accepted"),
)
customer_status = models.CharField(
"Customer Status",
max_length=40,
Expand Down Expand Up @@ -262,8 +256,6 @@ class OccurrenceReport(SubmitterInformationModelMixin, RevisionedMixin):

observation_date = models.DateTimeField(null=True, blank=True)
reported_date = models.DateTimeField(auto_now_add=True, null=False, blank=False)
effective_from = models.DateTimeField(null=True, blank=True)
effective_to = models.DateTimeField(null=True, blank=True)
submitter_information = models.OneToOneField(
SubmitterInformation,
on_delete=models.SET_NULL,
Expand All @@ -289,16 +281,6 @@ class OccurrenceReport(SubmitterInformationModelMixin, RevisionedMixin):
)
prev_processing_status = models.CharField(max_length=30, blank=True, null=True)

review_due_date = models.DateField(null=True, blank=True)
review_date = models.DateField(null=True, blank=True)
reviewed_by = models.IntegerField(null=True) # EmailUserRO
review_status = models.CharField(
"Review Status",
max_length=30,
choices=REVIEW_STATUS_CHOICES,
default=REVIEW_STATUS_CHOICES[0][0],
)

proposed_decline_status = models.BooleanField(default=False)
deficiency_data = models.TextField(null=True, blank=True) # deficiency comment
assessor_data = models.TextField(null=True, blank=True) # assessor comment
Expand Down Expand Up @@ -770,20 +752,25 @@ def propose_approve(self, request, validated_data):
except Occurrence.DoesNotExist:
raise ValidationError(
f"Occurrence with id {occurrence_id} does not exist"
)

)
details = validated_data.get("details", None)
new_occurrence_name = validated_data.get("new_occurrence_name", None)
effective_from_date = validated_data.get("effective_from_date")
effective_to_date = validated_data.get("effective_to_date")

if (new_occurrence_name and
Occurrence.objects.filter(occurrence_name=new_occurrence_name).exists() or
OccurrenceReportApprovalDetails.objects.filter(new_occurrence_name=new_occurrence_name).exists()):
raise ValidationError(
f"Occurrence with name \"{new_occurrence_name}\" already exists or has been proposed for approval"
)


OccurrenceReportApprovalDetails.objects.update_or_create(
occurrence_report=self,
defaults={
"officer": request.user.id,
"occurrence": occurrence,
"new_occurrence_name": new_occurrence_name,
"effective_from_date": effective_from_date,
"effective_to_date": effective_to_date,
"details": details,
},
)
Expand Down Expand Up @@ -1001,8 +988,6 @@ class OccurrenceReportApprovalDetails(models.Model):
) # If being added to an existing occurrence
new_occurrence_name = models.CharField(max_length=200, null=True, blank=True)
officer = models.IntegerField() # EmailUserRO
effective_from_date = models.DateField(null=True, blank=True)
effective_to_date = models.DateField(null=True, blank=True)
details = models.TextField(blank=True)

class Meta:
Expand Down Expand Up @@ -2809,6 +2794,13 @@ def get_queryset(self):

class Occurrence(RevisionedMixin):

REVIEW_STATUS_CHOICES = (
("not_reviewed", "Not Reviewed"),
("awaiting_amendments", "Awaiting Amendments"),
("amended", "Amended"),
("accepted", "Accepted"),
)

RELATED_ITEM_CHOICES = [
("species", "Species"),
("community", "Community"),
Expand Down Expand Up @@ -2838,8 +2830,7 @@ class Occurrence(RevisionedMixin):
blank=True,
related_name="occurrences",
)
effective_from = models.DateTimeField(null=True, blank=True)
effective_to = models.DateTimeField(null=True, blank=True)

submitter = models.IntegerField(null=True) # EmailUserRO
wild_status = models.ForeignKey(
WildStatus, on_delete=models.PROTECT, null=True, blank=True
Expand All @@ -2856,8 +2847,8 @@ class Occurrence(RevisionedMixin):
review_status = models.CharField(
"Review Status",
max_length=30,
choices=OccurrenceReport.REVIEW_STATUS_CHOICES,
default=OccurrenceReport.REVIEW_STATUS_CHOICES[0][0],
choices=REVIEW_STATUS_CHOICES,
default=REVIEW_STATUS_CHOICES[0][0],
)

created_date = models.DateTimeField(auto_now_add=True, null=False, blank=False)
Expand Down Expand Up @@ -3072,14 +3063,6 @@ def clone_from_occurrence_report(self, occurrence_report):
occurrence.species = occurrence_report.species
occurrence.community = occurrence_report.community

occurrence.effective_from = occurrence_report.effective_from
occurrence.effective_to = occurrence_report.effective_to

occurrence.review_due_date = occurrence_report.review_due_date
occurrence.review_date = occurrence_report.review_date
occurrence.reviewed_by = occurrence_report.reviewed_by
occurrence.review_status = occurrence_report.review_status

occurrence.save(no_revision=True)

# Clone all the associated models
Expand Down
Loading

0 comments on commit dc98f9a

Please sign in to comment.