@@ -1,184 +1,261 | |||
|
1 | 1 | from django.db import models |
|
2 | 2 | from apps.main.models import Configuration |
|
3 | 3 | from django.core.validators import MinValueValidator, MaxValueValidator |
|
4 | 4 | |
|
5 | 5 | from .files import read_json_file |
|
6 | import requests | |
|
6 | 7 | # Create your models here. validators=[MinValueValidator(62.5e6), MaxValueValidator(450e6)] |
|
7 | 8 | |
|
8 | 9 | class CGSConfiguration(Configuration): |
|
9 | 10 | |
|
10 | 11 | freq0 = models.PositiveIntegerField(verbose_name='Frequency 0',validators=[MaxValueValidator(450e6)], default = 60) |
|
11 | 12 | freq1 = models.PositiveIntegerField(verbose_name='Frequency 1',validators=[MaxValueValidator(450e6)], default = 60) |
|
12 | 13 | freq2 = models.PositiveIntegerField(verbose_name='Frequency 2',validators=[MaxValueValidator(450e6)], default = 60) |
|
13 | 14 | freq3 = models.PositiveIntegerField(verbose_name='Frequency 3',validators=[MaxValueValidator(450e6)], default = 60) |
|
14 | 15 | |
|
15 | 16 | def verify_frequencies(self): |
|
16 | 17 | |
|
17 | 18 | return True |
|
18 | 19 | |
|
19 | 20 | |
|
20 | 21 | def update_from_file(self, fp): |
|
21 | 22 | |
|
22 | 23 | kwargs = read_json_file(fp) |
|
23 | 24 | |
|
24 | 25 | if not kwargs: |
|
25 | 26 | return False |
|
26 | 27 | |
|
27 | 28 | self.freq0 = kwargs['freq0'] |
|
28 | 29 | self.freq1 = kwargs['freq1'] |
|
29 | 30 | self.freq2 = kwargs['freq2'] |
|
30 | 31 | self.freq3 = kwargs['freq3'] |
|
31 | 32 | |
|
32 | 33 | return True |
|
33 | 34 | |
|
34 | 35 | def parms_to_dict(self): |
|
35 | 36 | |
|
36 | 37 | parameters = {} |
|
37 | 38 | |
|
38 | 39 | parameters['device_id'] = self.device.id |
|
39 | 40 | |
|
40 | 41 | if self.freq0 == None or self.freq0 == '': |
|
41 | 42 | parameters['freq0'] = 0 |
|
42 | 43 | else: |
|
43 | 44 | parameters['freq0'] = self.freq0 |
|
44 | 45 | |
|
45 | 46 | if self.freq1 == None or self.freq1 == '': |
|
46 | 47 | parameters['freq1'] = 0 |
|
47 | 48 | else: |
|
48 | 49 | parameters['freq1'] = self.freq1 |
|
49 | 50 | |
|
50 | 51 | if self.freq2 == None or self.freq2 == '': |
|
51 | 52 | parameters['freq2'] = 0 |
|
52 | 53 | else: |
|
53 | 54 | parameters['freq2'] = self.freq2 |
|
54 | 55 | |
|
55 | 56 | if self.freq3 == None or self.freq3 == '': |
|
56 | 57 | parameters['freq3'] = 0 |
|
57 | 58 | else: |
|
58 | 59 | parameters['freq3'] = self.freq3 |
|
59 | 60 | |
|
60 | 61 | return parameters |
|
61 | 62 | |
|
62 | 63 | |
|
63 | 64 | def dict_to_parms(self, parameters): |
|
64 | 65 | |
|
65 | 66 | self.freq0 = parameters['freq0'] |
|
66 | 67 | self.freq1 = parameters['freq1'] |
|
67 | 68 | self.freq2 = parameters['freq2'] |
|
68 | 69 | self.freq3 = parameters['freq3'] |
|
69 | 70 | |
|
70 | 71 | |
|
71 | 72 | def status_device(self): |
|
72 | 73 | |
|
73 | 74 | import requests |
|
74 | 75 | |
|
75 | 76 | ip=self.device.ip_address |
|
76 | 77 | port=self.device.port_address |
|
77 | 78 | |
|
78 | 79 | route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" |
|
79 | 80 | try: |
|
80 | 81 | r = requests.get(route,timeout=0.5) |
|
81 | 82 | except: |
|
82 | 83 | self.device.status = 0 |
|
83 | 84 | self.device.save() |
|
84 | 85 | self.message = 'Could not read CGS status' |
|
85 | 86 | return False |
|
86 | 87 | |
|
87 | 88 | response = str(r.text) |
|
88 | 89 | response = response.split(";") |
|
89 | 90 | icon = response[0] |
|
90 | 91 | status = response[-1] |
|
91 | 92 | |
|
92 | 93 | #print(icon, status) |
|
93 | 94 | #"icon" could be: "alert" or "okay" |
|
94 | 95 | if "alert" in icon: |
|
95 | 96 | if "Starting Up" in status: #No Esta conectado |
|
96 | 97 | self.device.status = 0 |
|
97 | 98 | else: |
|
98 | 99 | self.device.status = 1 |
|
99 | 100 | elif "okay" in icon: |
|
100 | 101 | self.device.status = 3 |
|
101 | 102 | else: |
|
102 | 103 | self.device.status = 1 |
|
103 | 104 | |
|
104 | 105 | self.message = status |
|
105 | 106 | self.device.save() |
|
106 | 107 | |
|
107 | 108 | |
|
108 | 109 | return True |
|
109 | 110 | |
|
110 | 111 | |
|
112 | def start_device(self): | |
|
113 | ||
|
114 | ip=self.device.ip_address | |
|
115 | port=self.device.port_address | |
|
116 | ||
|
117 | #---Frequencies from form | |
|
118 | f0 = self.freq0 | |
|
119 | f1 = self.freq1 | |
|
120 | f2 = self.freq2 | |
|
121 | f3 = self.freq3 | |
|
122 | post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} | |
|
123 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" | |
|
124 | ||
|
125 | try: | |
|
126 | r = requests.post(route, post_data, timeout=0.7) | |
|
127 | except: | |
|
128 | self.message = "Could not start CGS device" | |
|
129 | return False | |
|
130 | ||
|
131 | text = r.text | |
|
132 | text = text.split(',') | |
|
133 | ||
|
134 | if len(text)>1: | |
|
135 | title = text[0] | |
|
136 | status = text[1] | |
|
137 | if title == "okay": | |
|
138 | self.message = status | |
|
139 | self.device.status = 3 | |
|
140 | self.device.save() | |
|
141 | return True | |
|
142 | else: | |
|
143 | self.message = title + ", " + status | |
|
144 | self.device.status = 1 | |
|
145 | self.device.save() | |
|
146 | return False | |
|
147 | ||
|
148 | return False | |
|
149 | ||
|
150 | ||
|
151 | def stop_device(self): | |
|
152 | ||
|
153 | ip=self.device.ip_address | |
|
154 | port=self.device.port_address | |
|
155 | ||
|
156 | f0 = 0 | |
|
157 | f1 = 0 | |
|
158 | f2 = 0 | |
|
159 | f3 = 0 | |
|
160 | post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} | |
|
161 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" | |
|
162 | ||
|
163 | try: | |
|
164 | r = requests.post(route, post_data, timeout=0.7) | |
|
165 | except: | |
|
166 | self.message = "Could not stop CGS device" | |
|
167 | return False | |
|
168 | ||
|
169 | text = r.text | |
|
170 | text = text.split(',') | |
|
171 | ||
|
172 | if len(text)>1: | |
|
173 | title = text[0] | |
|
174 | status = text[1] | |
|
175 | if title == "okay": | |
|
176 | self.message = status | |
|
177 | self.device.status = 1 | |
|
178 | self.device.save() | |
|
179 | self.message = "CGS device has been stopped" | |
|
180 | return True | |
|
181 | else: | |
|
182 | self.message = title + ", " + status | |
|
183 | self.device.status = 0 | |
|
184 | self.device.save() | |
|
185 | return False | |
|
186 | ||
|
187 | return False | |
|
188 | ||
|
189 | ||
|
111 | 190 | def read_device(self): |
|
112 | 191 | |
|
113 | 192 | import requests |
|
114 | 193 | |
|
115 | 194 | ip=self.device.ip_address |
|
116 | 195 | port=self.device.port_address |
|
117 | 196 | |
|
118 | 197 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" |
|
119 | 198 | try: |
|
120 |
frequencies = requests.get(route,timeout=0. |
|
|
199 | frequencies = requests.get(route,timeout=0.7) | |
|
121 | 200 | |
|
122 | 201 | except: |
|
123 | 202 | self.message = "Could not read CGS parameters from this device" |
|
124 | 203 | return None |
|
125 | 204 | |
|
126 | 205 | frequencies = frequencies.json() |
|
127 | 206 | frequencies = frequencies.get("Frecuencias") |
|
128 | 207 | f0 = frequencies.get("f0") |
|
129 | 208 | f1 = frequencies.get("f1") |
|
130 | 209 | f2 = frequencies.get("f2") |
|
131 | 210 | f3 = frequencies.get("f3") |
|
132 | 211 | |
|
133 | 212 | parms = {'freq0': f0, |
|
134 | 213 | 'freq1': f1, |
|
135 | 214 | 'freq2': f2, |
|
136 | 215 | 'freq3': f3} |
|
137 | 216 | |
|
138 | 217 | self.message = "" |
|
139 | 218 | return parms |
|
140 | 219 | |
|
141 | 220 | |
|
142 | 221 | def write_device(self): |
|
143 | 222 | |
|
144 | import requests | |
|
145 | ||
|
146 | 223 | ip=self.device.ip_address |
|
147 | 224 | port=self.device.port_address |
|
148 | 225 | |
|
149 | 226 | #---Frequencies from form |
|
150 | 227 | f0 = self.freq0 |
|
151 | 228 | f1 = self.freq1 |
|
152 | 229 | f2 = self.freq2 |
|
153 | 230 | f3 = self.freq3 |
|
154 | 231 | post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} |
|
155 | 232 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" |
|
156 | 233 | |
|
157 | 234 | try: |
|
158 |
r = requests.post(route, post_data, timeout=0. |
|
|
235 | r = requests.post(route, post_data, timeout=0.7) | |
|
159 | 236 | except: |
|
160 | 237 | self.message = "Could not write CGS parameters" |
|
161 | 238 | return False |
|
162 | 239 | |
|
163 | 240 | text = r.text |
|
164 | 241 | text = text.split(',') |
|
165 | 242 | |
|
166 | 243 | if len(text)>1: |
|
167 | 244 | title = text[0] |
|
168 | 245 | status = text[1] |
|
169 | 246 | if title == "okay": |
|
170 | 247 | self.message = status |
|
171 | 248 | self.device.status = 3 |
|
172 | 249 | self.device.save() |
|
173 | 250 | return True |
|
174 | 251 | else: |
|
175 | 252 | self.message = title + ", " + status |
|
176 | 253 | self.device.status = 1 |
|
177 | 254 | self.device.save() |
|
178 | 255 | return False |
|
179 | 256 | |
|
180 | 257 | return False |
|
181 | 258 | |
|
182 | 259 | |
|
183 | 260 | class Meta: |
|
184 | 261 | db_table = 'cgs_configurations' |
@@ -1,322 +1,322 | |||
|
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 | #if request.method=='GET': |
|
28 | 28 | #r: response = icon, status |
|
29 | 29 | # try: |
|
30 | 30 | # route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" |
|
31 | 31 | # r = requests.get(route) |
|
32 | 32 | # response = str(r.text) |
|
33 | 33 | # response = response.split(";") |
|
34 | 34 | # icon = response[0] |
|
35 | 35 | # status = response[-1] |
|
36 | 36 | #print r.text |
|
37 | 37 | #"icon" could be: "alert" or "okay" |
|
38 | 38 | # Si hay alerta pero esta conectado |
|
39 | 39 | # if "alert" in icon: |
|
40 | 40 | # if "Starting Up" in status: #No Esta conectado |
|
41 | 41 | # kwargs['connected'] = False |
|
42 | 42 | # else: |
|
43 | 43 | # kwargs['connected'] = True |
|
44 | 44 | # elif "okay" in icon: |
|
45 | 45 | # kwargs['connected'] = True |
|
46 | 46 | # else: |
|
47 | 47 | # kwargs['connected'] = False |
|
48 | 48 | |
|
49 | 49 | # except: |
|
50 | 50 | # kwargs['connected'] = False |
|
51 | 51 | # status = "The Device is not connected." |
|
52 | 52 | |
|
53 | 53 | #if not kwargs['connected']: |
|
54 | 54 | # messages.error(request, message=status) |
|
55 | 55 | |
|
56 | 56 | kwargs['dev_conf'] = conf |
|
57 | 57 | kwargs['dev_conf_keys'] = ['name', |
|
58 | 58 | 'freq0', 'freq1', |
|
59 | 59 | 'freq2', 'freq3'] |
|
60 | 60 | |
|
61 | 61 | kwargs['title'] = 'CGS Configuration' |
|
62 | 62 | kwargs['suptitle'] = 'Details' |
|
63 | 63 | |
|
64 | 64 | kwargs['button'] = 'Edit Configuration' |
|
65 | 65 | |
|
66 | kwargs['no_play'] = True | |
|
66 | #kwargs['no_play'] = True | |
|
67 | 67 | |
|
68 | 68 | ###### SIDEBAR ###### |
|
69 | 69 | kwargs.update(sidebar(conf=conf)) |
|
70 | 70 | |
|
71 | 71 | return render(request, 'cgs_conf.html', kwargs) |
|
72 | 72 | |
|
73 | 73 | def cgs_conf_edit(request, id_conf): |
|
74 | 74 | |
|
75 | 75 | conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
76 | 76 | |
|
77 | 77 | if request.method=='GET': |
|
78 | 78 | form = CGSConfigurationForm(instance=conf) |
|
79 | 79 | |
|
80 | 80 | if request.method=='POST': |
|
81 | 81 | form = CGSConfigurationForm(request.POST, instance=conf) |
|
82 | 82 | |
|
83 | 83 | if form.is_valid(): |
|
84 | 84 | if conf.freq0 == None: conf.freq0 = 0 |
|
85 | 85 | if conf.freq1 == None: conf.freq1 = 0 |
|
86 | 86 | if conf.freq2 == None: conf.freq2 = 0 |
|
87 | 87 | if conf.freq3 == None: conf.freq3 = 0 |
|
88 | 88 | |
|
89 | 89 | conf = form.save(commit=False) |
|
90 | 90 | |
|
91 | 91 | if conf.verify_frequencies(): |
|
92 | 92 | conf.save() |
|
93 | 93 | return redirect('url_cgs_conf', id_conf=conf.id) |
|
94 | 94 | |
|
95 | 95 | ##ERRORS |
|
96 | 96 | |
|
97 | 97 | kwargs = {} |
|
98 | 98 | kwargs['id_dev'] = conf.id |
|
99 | 99 | kwargs['form'] = form |
|
100 | 100 | kwargs['title'] = 'Device Configuration' |
|
101 | 101 | kwargs['suptitle'] = 'Edit' |
|
102 | 102 | kwargs['button'] = 'Save' |
|
103 | 103 | |
|
104 | 104 | return render(request, 'cgs_conf_edit.html', kwargs) |
|
105 | 105 | # |
|
106 | 106 | # def cgs_conf_write(request, id_conf): |
|
107 | 107 | # |
|
108 | 108 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
109 | 109 | # ip=conf.device.ip_address |
|
110 | 110 | # port=conf.device.port_address |
|
111 | 111 | # |
|
112 | 112 | # #Frequencies from form |
|
113 | 113 | # f0 = conf.freq0 |
|
114 | 114 | # f1 = conf.freq1 |
|
115 | 115 | # f2 = conf.freq2 |
|
116 | 116 | # f3 = conf.freq3 |
|
117 | 117 | # |
|
118 | 118 | # try: |
|
119 | 119 | # post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} |
|
120 | 120 | # route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" |
|
121 | 121 | # r = requests.post(route, post_data) |
|
122 | 122 | # text = r.text |
|
123 | 123 | # text = text.split(',') |
|
124 | 124 | # |
|
125 | 125 | # try: |
|
126 | 126 | # if len(text)>1: |
|
127 | 127 | # title = text[0] |
|
128 | 128 | # status = text[1] |
|
129 | 129 | # status_ok = r.status_code |
|
130 | 130 | # if title == "okay": |
|
131 | 131 | # messages.success(request, status) |
|
132 | 132 | # else: |
|
133 | 133 | # messages.error(request, status) |
|
134 | 134 | # |
|
135 | 135 | # else: |
|
136 | 136 | # title = text[0] |
|
137 | 137 | # messages.error(request, title) |
|
138 | 138 | # |
|
139 | 139 | # except: |
|
140 | 140 | # messages.error(request, "An hardware error was found.") |
|
141 | 141 | # |
|
142 | 142 | # except: |
|
143 | 143 | # messages.error(request, "Could not write parameters.") |
|
144 | 144 | # |
|
145 | 145 | # |
|
146 | 146 | # |
|
147 | 147 | # |
|
148 | 148 | # return redirect('url_cgs_conf', id_conf=conf.id) |
|
149 | 149 | # |
|
150 | 150 | # def cgs_conf_read(request, id_conf): |
|
151 | 151 | # |
|
152 | 152 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
153 | 153 | # |
|
154 | 154 | # ip=conf.device.ip_address |
|
155 | 155 | # port=conf.device.port_address |
|
156 | 156 | # |
|
157 | 157 | # if request.method=='POST': |
|
158 | 158 | # form = CGSConfigurationForm(request.POST, instance=conf) |
|
159 | 159 | # |
|
160 | 160 | # if form.is_valid(): |
|
161 | 161 | # cgs_model = form.save(commit=False) |
|
162 | 162 | # |
|
163 | 163 | # if cgs_model.verify_frequencies(): |
|
164 | 164 | # |
|
165 | 165 | # cgs_model.save() |
|
166 | 166 | # return redirect('url_cgs_conf', id_conf=conf.id) |
|
167 | 167 | # |
|
168 | 168 | # messages.error(request, "Parameters could not be saved. Invalid parameters") |
|
169 | 169 | # |
|
170 | 170 | # data = {} |
|
171 | 171 | # |
|
172 | 172 | # |
|
173 | 173 | # if request.method=='GET': |
|
174 | 174 | # #r: response = icon, status |
|
175 | 175 | # route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" |
|
176 | 176 | # try: |
|
177 | 177 | # r = requests.get(route) |
|
178 | 178 | # response = str(r.text) |
|
179 | 179 | # response = response.split(";") |
|
180 | 180 | # icon = response[0] |
|
181 | 181 | # status = response[-1] |
|
182 | 182 | # print r.text |
|
183 | 183 | # #"icon" could be: "alert" or "okay" |
|
184 | 184 | # if "okay" in icon: |
|
185 | 185 | # messages.success(request, status) |
|
186 | 186 | # else: |
|
187 | 187 | # messages.error(request, status) |
|
188 | 188 | # #Get Frequencies |
|
189 | 189 | # route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" |
|
190 | 190 | # #frequencies = requests.get('http://10.10.10.175:8080/frequencies/') |
|
191 | 191 | # frequencies = requests.get(route) |
|
192 | 192 | # frequencies = frequencies.json() |
|
193 | 193 | # frequencies = frequencies.get("Frecuencias") |
|
194 | 194 | # f0 = frequencies.get("f0") |
|
195 | 195 | # f1 = frequencies.get("f1") |
|
196 | 196 | # f2 = frequencies.get("f2") |
|
197 | 197 | # f3 = frequencies.get("f3") |
|
198 | 198 | # print f0,f1,f2,f3 |
|
199 | 199 | # |
|
200 | 200 | # |
|
201 | 201 | # if not response: |
|
202 | 202 | # messages.error(request, "Could not read parameters from Device") |
|
203 | 203 | # return redirect('url_cgs_conf', id_conf=conf.id) |
|
204 | 204 | # |
|
205 | 205 | # data = {'experiment' : conf.experiment.id, |
|
206 | 206 | # 'device' : conf.device.id, |
|
207 | 207 | # 'freq0' : f0, |
|
208 | 208 | # 'freq1' : f1, |
|
209 | 209 | # 'freq2' : f2, |
|
210 | 210 | # 'freq3' : f3, |
|
211 | 211 | # } |
|
212 | 212 | # except: |
|
213 | 213 | # messages.error(request, "Could not read parameters from Device") |
|
214 | 214 | # data = {'experiment' : conf.experiment.id, |
|
215 | 215 | # 'device' : conf.device.id, |
|
216 | 216 | # 'freq0' : None, |
|
217 | 217 | # 'freq1' : None, |
|
218 | 218 | # 'freq2' : None, |
|
219 | 219 | # 'freq3' : None, |
|
220 | 220 | # } |
|
221 | 221 | # return redirect('url_cgs_conf', id_conf=conf.id) |
|
222 | 222 | # |
|
223 | 223 | # form = CGSConfigurationForm(initial = data) |
|
224 | 224 | # |
|
225 | 225 | # kwargs = {} |
|
226 | 226 | # kwargs['id_dev'] = conf.id |
|
227 | 227 | # kwargs['form'] = form |
|
228 | 228 | # kwargs['title'] = 'Device Configuration' |
|
229 | 229 | # kwargs['suptitle'] = 'Parameters read from device' |
|
230 | 230 | # kwargs['button'] = 'Save' |
|
231 | 231 | # |
|
232 | 232 | # ###### SIDEBAR ###### |
|
233 | 233 | # kwargs.update(sidebar(conf)) |
|
234 | 234 | # |
|
235 | 235 | # return render(request, 'cgs_conf_edit.html', kwargs) |
|
236 | 236 | # |
|
237 | 237 | # def cgs_conf_import(request, id_conf): |
|
238 | 238 | # |
|
239 | 239 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
240 | 240 | # |
|
241 | 241 | # if request.method == 'POST': |
|
242 | 242 | # file_form = UploadFileForm(request.POST, request.FILES) |
|
243 | 243 | # |
|
244 | 244 | # if file_form.is_valid(): |
|
245 | 245 | # |
|
246 | 246 | # try: |
|
247 | 247 | # if conf.update_from_file(request.FILES['file']): |
|
248 | 248 | # |
|
249 | 249 | # try: |
|
250 | 250 | # conf.full_clean() |
|
251 | 251 | # except ValidationError as e: |
|
252 | 252 | # messages.error(request, e) |
|
253 | 253 | # else: |
|
254 | 254 | # conf.save() |
|
255 | 255 | # |
|
256 | 256 | # messages.success(request, "Parameters imported from file: '%s'." %request.FILES['file'].name) |
|
257 | 257 | # #messages.warning(request,"") |
|
258 | 258 | # return redirect('url_cgs_conf', id_conf=conf.id) |
|
259 | 259 | # except: |
|
260 | 260 | # messages.error(request, "No JSON object could be decoded.") |
|
261 | 261 | # |
|
262 | 262 | # messages.error(request, "Could not import parameters from file") |
|
263 | 263 | # |
|
264 | 264 | # else: |
|
265 | 265 | # file_form = UploadFileForm(initial={'title': '.json'}) |
|
266 | 266 | # |
|
267 | 267 | # |
|
268 | 268 | # kwargs = {} |
|
269 | 269 | # kwargs['id_dev'] = conf.id |
|
270 | 270 | # kwargs['title'] = 'Device Configuration' |
|
271 | 271 | # kwargs['form'] = file_form |
|
272 | 272 | # kwargs['suptitle'] = 'Importing file' |
|
273 | 273 | # kwargs['button'] = 'Import' |
|
274 | 274 | # |
|
275 | 275 | # kwargs.update(sidebar(conf)) |
|
276 | 276 | # |
|
277 | 277 | # return render(request, 'cgs_conf_import.html', kwargs) |
|
278 | 278 | # |
|
279 | 279 | # def handle_uploaded_file(f): |
|
280 | 280 | # |
|
281 | 281 | # data = {'freq0' : 62500000, |
|
282 | 282 | # 'freq1' : 62500000, |
|
283 | 283 | # 'freq2' : 62500000, |
|
284 | 284 | # 'freq3' : 62500000, |
|
285 | 285 | # } |
|
286 | 286 | # |
|
287 | 287 | # return data |
|
288 | 288 | # |
|
289 | 289 | # def cgs_conf_export(request, id_conf): |
|
290 | 290 | # |
|
291 | 291 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
292 | 292 | # ip=conf.device.ip_address |
|
293 | 293 | # port=conf.device.port_address |
|
294 | 294 | # |
|
295 | 295 | # #if request.method=='GET': |
|
296 | 296 | # # data = {"Frequencies": [ |
|
297 | 297 | # # ["freq0", conf.freq0], |
|
298 | 298 | # # ["freq1", conf.freq1], |
|
299 | 299 | # # ["freq2", conf.freq2], |
|
300 | 300 | # # ["freq3", conf.freq3] |
|
301 | 301 | # # ]} |
|
302 | 302 | # # json_data = json.dumps(data) |
|
303 | 303 | # # conf.parameters = json_data |
|
304 | 304 | # # response = HttpResponse(conf.parameters, content_type="application/json") |
|
305 | 305 | # # response['Content-Disposition'] = 'attachment; filename="data.json"' |
|
306 | 306 | # |
|
307 | 307 | # # return response |
|
308 | 308 | # |
|
309 | 309 | # kwargs = {} |
|
310 | 310 | # kwargs['dev_conf'] = conf |
|
311 | 311 | # kwargs['dev_conf_keys'] = ['experiment', 'device', |
|
312 | 312 | # 'freq0', 'freq1', |
|
313 | 313 | # 'freq2', 'freq3'] |
|
314 | 314 | # |
|
315 | 315 | # kwargs['title'] = 'CGS Configuration' |
|
316 | 316 | # kwargs['suptitle'] = 'Details' |
|
317 | 317 | # |
|
318 | 318 | # kwargs['button'] = 'Edit Configuration' |
|
319 | 319 | # |
|
320 | 320 | # ###### SIDEBAR ###### |
|
321 | 321 | # kwargs.update(sidebar(conf)) |
|
322 | 322 | # return render(request, 'cgs_conf.html', kwargs) |
General Comments 0
You need to be logged in to leave comments.
Login now