-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviews.py
More file actions
35 lines (29 loc) · 1016 Bytes
/
views.py
File metadata and controls
35 lines (29 loc) · 1016 Bytes
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
from django.http import JsonResponse
from django.shortcuts import get_object_or_404, render
from django.views.generic.list import ListView
from labdash.models import ButtonGroup, Button
import labdash.mqtt
class Dashboard(ListView):
model = ButtonGroup
context_object_name = "groups"
queryset = ButtonGroup.objects.filter(screen="main", hide=False).order_by(
"priority"
)
def custom_screen(req, name):
groups = (
ButtonGroup.objects.filter(screen=name, hide=False).order_by("priority").all()
)
return render(
req,
"labdash/buttongroup_list.html",
context={
"groups": groups,
"do_home_timeout": req.GET.get("kiosk", False) != False,
},
)
def trigger_button(request, pk):
btn = get_object_or_404(Button, pk=pk)
mqtt = labdash.mqtt.client()
for action in btn.actions.all():
mqtt.publish(action.topic, payload=action.payload, retain=action.retain)
return JsonResponse({"status": "ok"})