Skip to content

Commit

Permalink
Check Country an AppealDocType for AppealDocs sync
Browse files Browse the repository at this point in the history
  • Loading branch information
szabozoltan69 committed Feb 16, 2024
1 parent 2dc65aa commit db613c3
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions api/management/commands/sync_appealdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
from datetime import datetime, timezone
from dateutil.relativedelta import relativedelta
from django.core.management.base import BaseCommand
from django.core.exceptions import ObjectDoesNotExist
from api.models import Appeal, AppealDocument, CronJob, CronJobStatus
from api.models import Appeal, AppealDocument, AppealDocumentType, CronJob, CronJobStatus
from api.logger import logger
from collections import defaultdict
from django.conf import settings

CRON_NAME = "sync_appealdocs"
Expand All @@ -32,6 +30,7 @@ def handle(self, *args, **options):
logger.info("Starting appeal document ingest")

if options["fullscan"]:
# FIXME: should be inserted to cron jobs, 4 monthly or so. Or create a calendar note for maintainer.
# If the `--fullscan` option is passed (at the end of command), check ALL appeals. Runs an hour!
print("Doing a full scan of all Appeals")
qset = Appeal.objects.all()
Expand Down Expand Up @@ -69,6 +68,16 @@ def handle(self, *args, **options):
existing.append(document_url)
else:
try:
iso = result["LocationCountryCode"]
if not iso:
iso = Appeal.objects.get(pk=appeal_id).country.iso
if not iso:
logger.warning("Wrong AppealDocument data – unknown country.")
continue
appealtype_id = result["AppealsTypeId"]
if not appealtype_id or not AppealDocumentType.objects.filter(id=appealtype_id): # not pk=...!
logger.warning("Wrong AppealDocument data – unknown type_id: %s", appealtype_id)
continue
created_at = None
if "AppealsDate" in result:
created_at = self.parse_date(result["AppealsDate"])
Expand All @@ -79,8 +88,8 @@ def handle(self, *args, **options):
appeal_id=appeal_id,
name=result["AppealsName"],
description=result["AppealOrigType"],
type_id=result["AppealsTypeId"],
iso_id=result["LocationCountryCode"],
type_id=appealtype_id,
iso_id=iso,
created_at=created_at
)
created.append(document_url)
Expand Down

0 comments on commit db613c3

Please sign in to comment.