Skip to content

Commit

Permalink
Merge pull request #2220 from IFRCGo/feature/donor-response-documents
Browse files Browse the repository at this point in the history
Appealdocs URL cleansing
  • Loading branch information
szabozoltan69 authored Jul 13, 2024
2 parents 949e4cd + 3b7f4d1 commit 279b899
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion api/management/commands/sync_appealdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
CRON_NAME = "sync_appealdocs"
PUBLIC_SOURCE = "https://go-api.ifrc.org/api/publicsiteappeals?Hidden=false&BaseAppealnumber="
FEDNET_SOURCE = "https://go-api.ifrc.org/Api/FedNetAppeals?Hidden=false&BaseAppealnumber="
# Recently not needed, due to all docs are in the above ^ ones:
# DONOR_SOURCE = "https://go-api.ifrc.org/api/PublicSiteDonorResponses?AppealCode="


class Command(BaseCommand):
Expand Down Expand Up @@ -66,14 +68,16 @@ def handle(self, *args, **options):
code = code.replace(" ", "")
listone = requests.get(PUBLIC_SOURCE + str(code), auth=auth, headers=headers).json()
listtwo = requests.get(FEDNET_SOURCE + str(code), auth=auth, headers=headers).json()
# list3 = requests.get(DONOR_SOURCE + str(code), auth=auth, headers=headers).json()
results = listone + listtwo # do not tempt list(set(...)), because: unhashable type: 'dict'
for result in results:
appeals = Appeal.objects.filter(code=code).values_list("id", flat=True)
appeal_id = appeals[0]
# Should be always True due to we started from appeals:
if appeal_id:
# Filter BaseDirectory + BaseFileName == document_url and via code, like 'MGR00001':
document_url = result["BaseDirectory"] + result["BaseFileName"]
pre = "https://www.ifrc.org" if result["BaseDirectory"][:21] == "/docs/appeals/Active/" else ""
document_url = pre + result["BaseDirectory"] + result["BaseFileName"]
already_exists = AppealDocument.objects.filter(document_url=document_url).filter(appeal_id=appeal_id)
if already_exists:
existing.append(document_url)
Expand Down

0 comments on commit 279b899

Please sign in to comment.