@@ -1,75 +1,75 | |||
|
1 | 1 | from django.shortcuts import redirect, render, get_object_or_404 |
|
2 | 2 | from django.contrib import messages |
|
3 | 3 | from django.http import HttpResponse |
|
4 | 4 | |
|
5 | 5 | from apps.main.models import Experiment |
|
6 | 6 | from .models import CGSConfiguration |
|
7 | 7 | |
|
8 | 8 | from .forms import CGSConfigurationForm, UploadFileForm |
|
9 | 9 | from apps.main.views import sidebar |
|
10 | 10 | |
|
11 | 11 | import requests |
|
12 | 12 | import json |
|
13 | 13 | #from __builtin__ import None |
|
14 | 14 | # Create your views here. |
|
15 | 15 | |
|
16 | 16 | def cgs_conf(request, id_conf): |
|
17 | 17 | |
|
18 | 18 | conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
19 | 19 | |
|
20 | 20 | ip=conf.device.ip_address |
|
21 | 21 | port=conf.device.port_address |
|
22 | 22 | |
|
23 | 23 | kwargs = {} |
|
24 | 24 | |
|
25 | 25 | kwargs['status'] = conf.device.get_status_display() |
|
26 | 26 | |
|
27 | 27 | kwargs['dev_conf'] = conf |
|
28 |
kwargs['dev_conf_keys'] = [' |
|
|
28 | kwargs['dev_conf_keys'] = ['label', | |
|
29 | 29 | 'freq0', 'freq1', |
|
30 | 30 | 'freq2', 'freq3'] |
|
31 | 31 | |
|
32 | 32 | kwargs['title'] = 'CGS Configuration' |
|
33 | 33 | kwargs['suptitle'] = 'Details' |
|
34 | 34 | |
|
35 | 35 | kwargs['button'] = 'Edit Configuration' |
|
36 | 36 | |
|
37 | 37 | #kwargs['no_play'] = True |
|
38 | 38 | |
|
39 | 39 | ###### SIDEBAR ###### |
|
40 | 40 | kwargs.update(sidebar(conf=conf)) |
|
41 | 41 | |
|
42 | 42 | return render(request, 'cgs_conf.html', kwargs) |
|
43 | 43 | |
|
44 | 44 | def cgs_conf_edit(request, id_conf): |
|
45 | 45 | |
|
46 | 46 | conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
47 | 47 | |
|
48 | 48 | if request.method=='GET': |
|
49 | 49 | form = CGSConfigurationForm(instance=conf) |
|
50 | 50 | |
|
51 | 51 | if request.method=='POST': |
|
52 | 52 | form = CGSConfigurationForm(request.POST, instance=conf) |
|
53 | 53 | |
|
54 | 54 | if form.is_valid(): |
|
55 | 55 | if conf.freq0 == None: conf.freq0 = 0 |
|
56 | 56 | if conf.freq1 == None: conf.freq1 = 0 |
|
57 | 57 | if conf.freq2 == None: conf.freq2 = 0 |
|
58 | 58 | if conf.freq3 == None: conf.freq3 = 0 |
|
59 | 59 | |
|
60 | 60 | conf = form.save(commit=False) |
|
61 | 61 | |
|
62 | 62 | if conf.verify_frequencies(): |
|
63 | 63 | conf.save() |
|
64 | 64 | return redirect('url_cgs_conf', id_conf=conf.id) |
|
65 | 65 | |
|
66 | 66 | ##ERRORS |
|
67 | 67 | |
|
68 | 68 | kwargs = {} |
|
69 | 69 | kwargs['id_dev'] = conf.id |
|
70 | 70 | kwargs['form'] = form |
|
71 | 71 | kwargs['title'] = 'Device Configuration' |
|
72 | 72 | kwargs['suptitle'] = 'Edit' |
|
73 | 73 | kwargs['button'] = 'Save' |
|
74 | 74 | |
|
75 | 75 | return render(request, 'cgs_conf_edit.html', kwargs) |
General Comments 0
You need to be logged in to leave comments.
Login now