Skip to content
Snippets Groups Projects
Commit 496d67c8 authored by jarmil's avatar jarmil Committed by jan.bednarik
Browse files

Cache na API requesty

parent 475f4a71
No related branches found
No related tags found
2 merge requests!173Release,!134Weby pro MS
...@@ -4,4 +4,4 @@ line_length = 88 ...@@ -4,4 +4,4 @@ line_length = 88
multi_line_output = 3 multi_line_output = 3
default_sectiont = "THIRDPARTY" default_sectiont = "THIRDPARTY"
include_trailing_comma = true include_trailing_comma = true
known_third_party = arrow,django,environ,faker,ics,markdown,modelcluster,nbconvert,pirates,pytest,pytz,requests,sentry_sdk,snapshottest,taggit,traitlets,wagtail,wagtailmetadata known_third_party = arrow,django,environ,faker,ics,markdown,modelcluster,nbconvert,pirates,pytest,pytz,requests,requests_cache,sentry_sdk,snapshottest,taggit,traitlets,wagtail,wagtailmetadata
...@@ -9,6 +9,7 @@ pirates<=0.4 ...@@ -9,6 +9,7 @@ pirates<=0.4
whitenoise whitenoise
opencv-python opencv-python
requests requests
requests-cache
ics ics
arrow arrow
sentry-sdk sentry-sdk
......
import requests import requests
import requests_cache
from django.db import models from django.db import models
from modelcluster.contrib.taggit import ClusterTaggableManager from modelcluster.contrib.taggit import ClusterTaggableManager
from modelcluster.fields import ParentalKey from modelcluster.fields import ParentalKey
...@@ -8,6 +9,11 @@ from wagtail.core.models import Page ...@@ -8,6 +9,11 @@ from wagtail.core.models import Page
from wagtail.images.edit_handlers import ImageChooserPanel from wagtail.images.edit_handlers import ImageChooserPanel
from wagtailmetadata.models import MetadataPageMixin from wagtailmetadata.models import MetadataPageMixin
# cacheovani requestu na piratska api, ttl 1 hodina
requests_cache.install_cache(
cache_name="shared_models", backend="memory", expire_after=3600
)
class SharedSubpageMixin: class SharedSubpageMixin:
"""Must be used in class definition before MetadataPageMixin!""" """Must be used in class definition before MetadataPageMixin!"""
...@@ -76,17 +82,13 @@ class PersonPage(SharedSubpageMixin, MetadataPageMixin, Page): ...@@ -76,17 +82,13 @@ class PersonPage(SharedSubpageMixin, MetadataPageMixin, Page):
] ]
def _iapi(self): def _iapi(self):
""" Vrati data o osobe z piratskeho IAPI jako json """ Vrati data o osobe z piratskeho IAPI jako json. Cached via requests_cache """
TODO: neni cacheovano
"""
return requests.get( return requests.get(
"https://iapi.pirati.cz/v1/user?username=%s" % self.pirate_id "https://iapi.pirati.cz/v1/user?username=%s" % self.pirate_id
).json() ).json()
def _graph(self): def _graph(self):
""" Vrati data o osobe z graph.pirati.cz (forum) jako json """ Vrati data o osobe z graph.pirati.cz (forum) jako json. Cached via requests_cache """
TODO: neni cacheovano
"""
return requests.get("https://graph.pirati.cz/user/%s" % self.pirate_id).json() return requests.get("https://graph.pirati.cz/user/%s" % self.pirate_id).json()
@property @property
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment