Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Maják
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
Maják
Commits
b1ff2ff6
Commit
b1ff2ff6
authored
4 years ago
by
jarmil
Browse files
Options
Downloads
Patches
Plain Diff
Cache na API requesty
parent
5c701a76
No related branches found
No related tags found
2 merge requests
!173
Release
,
!134
Weby pro MS
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.isort.cfg
+1
-1
1 addition, 1 deletion
.isort.cfg
requirements/base.in
+1
-0
1 addition, 0 deletions
requirements/base.in
shared/models.py
+8
-6
8 additions, 6 deletions
shared/models.py
with
10 additions
and
7 deletions
.isort.cfg
+
1
−
1
View file @
b1ff2ff6
...
@@ -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
This diff is collapsed.
Click to expand it.
requirements/base.in
+
1
−
0
View file @
b1ff2ff6
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
shared/models.py
+
8
−
6
View file @
b1ff2ff6
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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment