-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcache.py.example
More file actions
47 lines (35 loc) · 1.37 KB
/
Copy pathcache.py.example
File metadata and controls
47 lines (35 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from django.core.cache import cache
from openclass.api import OpenClassAPI
from openclass.core import OpenClass
from settings import OPENCLASS_ADMIN_EMAIL, OPENCLASS_ADMIN_PASSWORD, OPENCLASS_API_KEY
# Inherits from OpenClass but adds ClassOwl specific caching.
# OMG I LOVE THIS!!! iz so eeee zzzz
class OpenClassIntegration(OpenClass):
# Cache keys
AUTH_TOKEN_CACHE_KEY = 'openclass_authentication_token'
REFRESH_TOKEN_CACHE_KEY = 'openclass_refresh_token'
def __init__(
self,
admin_email = OPENCLASS_ADMIN_EMAIL,
admin_pw = OPENCLASS_ADMIN_PASSWORD,
api_key = OPENCLASS_API_KEY,
debug = False
):
if not cache.has_key(self.AUTH_TOKEN_CACHE_KEY) or not cache.has_key(self.REFRESH_TOKEN_CACHE_KEY):
oc_api = OpenClassAPI(admin_email, admin_pw, api_key)
# Now set the items in the cache. Yay!!!!
cache.set(self.AUTH_TOKEN_CACHE_KEY, oc_api.auth_token)
cache.set(self.REFRESH_TOKEN_CACHE_KEY, oc_api.refresh_token)
super(OpenClassIntegration, self).__init__(
admin_email,
admin_pw,
api_key,
cache.get(self.AUTH_TOKEN_CACHE_KEY),
cache.get(self.REFRESH_TOKEN_CACHE_KEY),
debug
)
# Reset the cache when we refresh
def refresh_auth_tokens(self):
super(OpenClassIntegration, self).refresh_auth_tokens()
cache.set(self.AUTH_TOKEN_CACHE_KEY, self.auth_token)
cache.set(self.REFRESH_TOKEN_CACHE_KEY, self.refresh_token)