-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcontext.py
More file actions
66 lines (51 loc) · 1.31 KB
/
context.py
File metadata and controls
66 lines (51 loc) · 1.31 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import os
import sys
import json
import functools
is_cloud = os.environ.get('is_cloud', "0") == "1"
if is_cloud and not sys.stdin.isatty():
context_data = sys.stdin.read()
try:
context_data = json.loads(context_data)
except:
context_data = None
else:
context_data = None
def need_data(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
if not context_data:
return None
return func(*args, **kwargs)
return wrapper
class Context:
@property
def server_url(self):
return os.environ.get('dtable_web_url')
@property
def api_token(self):
return os.environ.get('api_token')
@property
@need_data
def current_row(self):
return context_data.get('row')
@property
@need_data
def current_table(self):
return context_data.get('table')
@property
@need_data
def current_user_id(self):
return context_data.get('current_user_id')
@property
@need_data
def current_username(self):
return context_data.get('current_username')
@property
@need_data
def current_id_in_org(self):
return context_data.get('current_id_in_org')
@need_data
def get_setting_by_key(self, key):
return context_data.get(key)
context = Context()