Skip to content
Snippets Groups Projects
Commit 1c7f1bc0 authored by jan.bednarik's avatar jan.bednarik
Browse files

donate: Fix portal API calls for non existing project IDs

parent f2feaa2e
Branches
No related tags found
2 merge requests!78donate: Fix portal API calls for non existing project IDs,!77donate: Fix portal API calls for non existing project IDs
Pipeline #1075 passed
......@@ -428,15 +428,22 @@ class DonateProjectPage(DonateFormMixin, Page, SubpageMixin, MetadataPageMixin):
return self.perex
def get_donated_amount(self):
key = f"donated_amount_{self.portal_project_id}"
amount = cache.get(key)
if amount is None:
amount = get_donated_amount_from_api(self.portal_project_id)
if amount is not None:
self.donated_amount = amount
self.save()
cache.set(key, amount)
return self.donated_amount
if self.portal_project_id is None:
return 0
# instance caching for multiple method calls during one request
if not hasattr(self, "_donated_amount"):
# cache portal API calls (defaults to 5 min)
key = f"donated_amount_{self.portal_project_id}"
amount = cache.get(key)
if amount is None:
amount = get_donated_amount_from_api(self.portal_project_id)
if amount is not None:
# save amount into database to be used if next API calls fails
self.donated_amount = amount
self.save()
cache.set(key, amount)
self._donated_amount = self.donated_amount or 0
return self._donated_amount
@property
def donated_percentage(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment