-
Notifications
You must be signed in to change notification settings - Fork 832
/
views.py
38 lines (32 loc) · 1.05 KB
/
views.py
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
import json
from jadi import component
from aj.api.http import url, HttpPlugin
from aj.api.endpoint import endpoint
from aj.plugins.dashboard.api import Widget
@component(HttpPlugin)
class Handler(HttpPlugin):
def __init__(self, context):
self.context = context
self.widgets = dict((x.id, x) for x in Widget.all(self.context))
@url(r'/api/dashboard/widgets')
@endpoint(api=True)
def handle_api_widgets(self, http_context):
return [
{
'id': w.id,
'name': w.name,
'template': w.template,
'config_template': w.config_template,
} for w in self.widgets.values()
]
@url(r'/api/dashboard/get-values')
@endpoint(api=True)
def handle_api_get_values(self, http_context):
data = http_context.json_body()
return [
{
'id': rq['id'],
'data': self.widgets[rq['typeId']].get_value(rq['config']),
} for rq in data
if rq['typeId'] in self.widgets
]