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
98ced150
Commit
98ced150
authored
4 years ago
by
jarmil
Browse files
Options
Downloads
Patches
Plain Diff
Cacheovani dotazu na iapi predelano z requests-cache na django cache
parent
927c8ea8
No related branches found
No related tags found
2 merge requests
!173
Release
,
!134
Weby pro MS
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.isort.cfg
+1
-1
1 addition, 1 deletion
.isort.cfg
requirements/base.in
+0
-1
0 additions, 1 deletion
requirements/base.in
requirements/base.txt
+1
-2
1 addition, 2 deletions
requirements/base.txt
shared/models.py
+10
-10
10 additions, 10 deletions
shared/models.py
with
12 additions
and
14 deletions
.isort.cfg
+
1
−
1
View file @
98ced150
...
...
@@ -4,4 +4,4 @@ line_length = 88
multi_line_output
=
3
default_section
=
"THIRDPARTY"
include_trailing_comma
=
true
known_third_party
=
arrow,django,environ,faker,ics,markdown,modelcluster,nbconvert,pirates,pytest,pytz,requests,
requests_cache,
sentry_sdk,snapshottest,taggit,traitlets,wagtail,wagtailmetadata
known_third_party
=
arrow,django,environ,faker,ics,markdown,modelcluster,nbconvert,pirates,pytest,pytz,requests,sentry_sdk,snapshottest,taggit,traitlets,wagtail,wagtailmetadata
This diff is collapsed.
Click to expand it.
requirements/base.in
+
0
−
1
View file @
98ced150
...
...
@@ -9,7 +9,6 @@ pirates<=0.4
whitenoise
opencv-python
requests
requests-cache
ics
arrow
sentry-sdk
...
...
This diff is collapsed.
Click to expand it.
requirements/base.txt
+
1
−
2
View file @
98ced150
...
...
@@ -69,8 +69,7 @@ python-ldap==3.3.1 # via pirates
pytz==2020.4 # via django, django-modelcluster, l18n
pyzmq==19.0.2 # via jupyter-client
redis==3.5.3 # via django-redis
requests-cache==0.5.2 # via -r base.in
requests==2.24.0 # via -r base.in, mozilla-django-oidc, requests-cache, wagtail
requests==2.24.0 # via -r base.in, mozilla-django-oidc, wagtail
sentry-sdk==0.19.2 # via -r base.in
six==1.15.0 # via bleach, cryptography, html5lib, ics, josepy, jsonschema, l18n, mozilla-django-oidc, packaging, pyopenssl, python-dateutil
soupsieve==2.0.1 # via beautifulsoup4
...
...
This diff is collapsed.
Click to expand it.
shared/models.py
+
10
−
10
View file @
98ced150
...
...
@@ -2,7 +2,7 @@ import datetime
import
random
import
requests
import
requests_
cache
from
django.core.cache
import
cache
from
django.core.validators
import
MaxValueValidator
,
MinValueValidator
from
django.db
import
models
from
modelcluster.contrib.taggit
import
ClusterTaggableManager
...
...
@@ -14,11 +14,6 @@ from wagtail.core.models import Page
from
wagtail.images.edit_handlers
import
ImageChooserPanel
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
:
"""
Must be used in class definition before MetadataPageMixin!
"""
...
...
@@ -116,10 +111,15 @@ class PersonPage(SharedSubpageMixin, MetadataPageMixin, Page):
]
def
_iapi
(
self
):
"""
Vrati data o osobe z piratskeho IAPI jako json. Cached via requests_cache
"""
return
requests
.
get
(
"
https://iapi.pirati.cz/v1/user?username=%s
"
%
self
.
username
).
json
()
"""
Vrati data o osobe z piratskeho IAPI jako json. Cached via django cache
"""
key
=
f
"
profile_
{
self
.
username
}
"
profile
=
cache
.
get
(
key
)
if
profile
is
None
:
profile
=
requests
.
get
(
f
"
https://iapi.pirati.cz/v1/user?username=
{
self
.
username
}
"
).
json
()
cache
.
set
(
key
,
profile
,
3600
)
return
profile
@property
def
name
(
self
):
...
...
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