@@ -1,390 +1,443 | |||||
1 |
|
1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse | ||
2 | from datetime import datetime |
|
2 | from datetime import datetime | |
3 |
|
3 | |||
4 | from django.db import models |
|
4 | from django.db import models | |
5 | from polymorphic import PolymorphicModel |
|
5 | from polymorphic import PolymorphicModel | |
6 |
|
6 | |||
7 | from django.core.urlresolvers import reverse |
|
7 | from django.core.urlresolvers import reverse | |
8 |
|
8 | |||
9 | CONF_STATES = ( |
|
9 | CONF_STATES = ( | |
10 | (0, 'Disconnected'), |
|
10 | (0, 'Disconnected'), | |
11 | (1, 'Connected'), |
|
11 | (1, 'Connected'), | |
12 | (2, 'Running'), |
|
12 | (2, 'Running'), | |
13 | ) |
|
13 | ) | |
14 |
|
14 | |||
15 | EXP_STATES = ( |
|
15 | EXP_STATES = ( | |
16 | (0,'Error'), #RED |
|
16 | (0,'Error'), #RED | |
17 | (1,'Configurated'), #BLUE |
|
17 | (1,'Configurated'), #BLUE | |
18 | (2,'Running'), #GREEN |
|
18 | (2,'Running'), #GREEN | |
19 | (3,'Waiting'), #YELLOW |
|
19 | (3,'Waiting'), #YELLOW | |
20 | (4,'Not Configured'), #WHITE |
|
20 | (4,'Not Configured'), #WHITE | |
21 | ) |
|
21 | ) | |
22 |
|
22 | |||
23 | CONF_TYPES = ( |
|
23 | CONF_TYPES = ( | |
24 | (0, 'Active'), |
|
24 | (0, 'Active'), | |
25 | (1, 'Historical'), |
|
25 | (1, 'Historical'), | |
26 | ) |
|
26 | ) | |
27 |
|
27 | |||
28 | DEV_STATES = ( |
|
28 | DEV_STATES = ( | |
29 | (0, 'No connected'), |
|
29 | (0, 'No connected'), | |
30 | (1, 'Connected'), |
|
30 | (1, 'Connected'), | |
31 | (2, 'Configured'), |
|
31 | (2, 'Configured'), | |
32 | (3, 'Running'), |
|
32 | (3, 'Running'), | |
33 | ) |
|
33 | ) | |
34 |
|
34 | |||
35 | DEV_TYPES = ( |
|
35 | DEV_TYPES = ( | |
36 | ('', 'Select a device type'), |
|
36 | ('', 'Select a device type'), | |
37 | ('rc', 'Radar Controller'), |
|
37 | ('rc', 'Radar Controller'), | |
38 | ('dds', 'Direct Digital Synthesizer'), |
|
38 | ('dds', 'Direct Digital Synthesizer'), | |
39 | ('jars', 'Jicamarca Radar Acquisition System'), |
|
39 | ('jars', 'Jicamarca Radar Acquisition System'), | |
40 | ('usrp', 'Universal Software Radio Peripheral'), |
|
40 | ('usrp', 'Universal Software Radio Peripheral'), | |
41 | ('cgs', 'Clock Generator System'), |
|
41 | ('cgs', 'Clock Generator System'), | |
42 | ('abs', 'Automatic Beam Switching'), |
|
42 | ('abs', 'Automatic Beam Switching'), | |
43 | ) |
|
43 | ) | |
44 |
|
44 | |||
45 | DEV_PORTS = { |
|
45 | DEV_PORTS = { | |
46 | 'rc' : 2000, |
|
46 | 'rc' : 2000, | |
47 | 'dds' : 2000, |
|
47 | 'dds' : 2000, | |
48 | 'jars' : 2000, |
|
48 | 'jars' : 2000, | |
49 | 'usrp' : 2000, |
|
49 | 'usrp' : 2000, | |
50 | 'cgs' : 8080, |
|
50 | 'cgs' : 8080, | |
51 | 'abs' : 8080 |
|
51 | 'abs' : 8080 | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | RADAR_STATES = ( |
|
54 | RADAR_STATES = ( | |
55 | (0, 'No connected'), |
|
55 | (0, 'No connected'), | |
56 | (1, 'Connected'), |
|
56 | (1, 'Connected'), | |
57 | (2, 'Configured'), |
|
57 | (2, 'Configured'), | |
58 | (3, 'Running'), |
|
58 | (3, 'Running'), | |
59 | (4, 'Scheduled'), |
|
59 | (4, 'Scheduled'), | |
60 | ) |
|
60 | ) | |
61 | # Create your models here. |
|
61 | # Create your models here. | |
62 |
|
62 | |||
63 | class Location(models.Model): |
|
63 | class Location(models.Model): | |
64 |
|
64 | |||
65 | name = models.CharField(max_length = 30) |
|
65 | name = models.CharField(max_length = 30) | |
66 | description = models.TextField(blank=True, null=True) |
|
66 | description = models.TextField(blank=True, null=True) | |
67 |
|
67 | |||
68 | class Meta: |
|
68 | class Meta: | |
69 | db_table = 'db_location' |
|
69 | db_table = 'db_location' | |
70 |
|
70 | |||
71 | def __unicode__(self): |
|
71 | def __unicode__(self): | |
72 | return u'%s' % self.name |
|
72 | return u'%s' % self.name | |
73 |
|
73 | |||
74 | def get_absolute_url(self): |
|
74 | def get_absolute_url(self): | |
75 | return reverse('url_device', args=[str(self.id)]) |
|
75 | return reverse('url_device', args=[str(self.id)]) | |
76 |
|
76 | |||
77 |
|
77 | |||
78 | class DeviceType(models.Model): |
|
78 | class DeviceType(models.Model): | |
79 |
|
79 | |||
80 | name = models.CharField(max_length = 10, choices = DEV_TYPES, default = 'rc') |
|
80 | name = models.CharField(max_length = 10, choices = DEV_TYPES, default = 'rc') | |
81 | description = models.TextField(blank=True, null=True) |
|
81 | description = models.TextField(blank=True, null=True) | |
82 |
|
82 | |||
83 | class Meta: |
|
83 | class Meta: | |
84 | db_table = 'db_device_types' |
|
84 | db_table = 'db_device_types' | |
85 |
|
85 | |||
86 | def __unicode__(self): |
|
86 | def __unicode__(self): | |
87 | return u'%s' % self.get_name_display() |
|
87 | return u'%s' % self.get_name_display() | |
88 |
|
88 | |||
89 | class Device(models.Model): |
|
89 | class Device(models.Model): | |
90 |
|
90 | |||
91 | device_type = models.ForeignKey(DeviceType, on_delete=models.CASCADE) |
|
91 | device_type = models.ForeignKey(DeviceType, on_delete=models.CASCADE) | |
92 | location = models.ForeignKey(Location, on_delete=models.CASCADE) |
|
92 | location = models.ForeignKey(Location, on_delete=models.CASCADE) | |
93 |
|
93 | |||
94 | name = models.CharField(max_length=40, default='') |
|
94 | name = models.CharField(max_length=40, default='') | |
95 | ip_address = models.GenericIPAddressField(protocol='IPv4', default='0.0.0.0') |
|
95 | ip_address = models.GenericIPAddressField(protocol='IPv4', default='0.0.0.0') | |
96 | port_address = models.PositiveSmallIntegerField(default=2000) |
|
96 | port_address = models.PositiveSmallIntegerField(default=2000) | |
97 | description = models.TextField(blank=True, null=True) |
|
97 | description = models.TextField(blank=True, null=True) | |
98 | status = models.PositiveSmallIntegerField(default=0, choices=DEV_STATES) |
|
98 | status = models.PositiveSmallIntegerField(default=0, choices=DEV_STATES) | |
99 |
|
99 | |||
100 | class Meta: |
|
100 | class Meta: | |
101 | db_table = 'db_devices' |
|
101 | db_table = 'db_devices' | |
102 |
|
102 | |||
103 | def __unicode__(self): |
|
103 | def __unicode__(self): | |
104 | return u'%s | %s' % (self.name, self.ip_address) |
|
104 | return u'%s | %s' % (self.name, self.ip_address) | |
105 |
|
105 | |||
106 | def get_status(self): |
|
106 | def get_status(self): | |
107 | return self.status |
|
107 | return self.status | |
108 |
|
108 | |||
109 | def get_absolute_url(self): |
|
109 | def get_absolute_url(self): | |
110 | return reverse('url_device', args=[str(self.id)]) |
|
110 | return reverse('url_device', args=[str(self.id)]) | |
111 |
|
111 | |||
112 |
|
112 | |||
113 | class Campaign(models.Model): |
|
113 | class Campaign(models.Model): | |
114 |
|
114 | |||
115 | template = models.BooleanField(default=False) |
|
115 | template = models.BooleanField(default=False) | |
116 | name = models.CharField(max_length=60, unique=True) |
|
116 | name = models.CharField(max_length=60, unique=True) | |
117 | start_date = models.DateTimeField(blank=True, null=True) |
|
117 | start_date = models.DateTimeField(blank=True, null=True) | |
118 | end_date = models.DateTimeField(blank=True, null=True) |
|
118 | end_date = models.DateTimeField(blank=True, null=True) | |
119 | tags = models.CharField(max_length=40) |
|
119 | tags = models.CharField(max_length=40) | |
120 | description = models.TextField(blank=True, null=True) |
|
120 | description = models.TextField(blank=True, null=True) | |
121 | experiments = models.ManyToManyField('Experiment', blank=True) |
|
121 | experiments = models.ManyToManyField('Experiment', blank=True) | |
122 |
|
122 | |||
123 | class Meta: |
|
123 | class Meta: | |
124 | db_table = 'db_campaigns' |
|
124 | db_table = 'db_campaigns' | |
125 | ordering = ('name',) |
|
125 | ordering = ('name',) | |
126 |
|
126 | |||
127 | def __unicode__(self): |
|
127 | def __unicode__(self): | |
128 | return u'%s' % (self.name) |
|
128 | return u'%s' % (self.name) | |
129 |
|
129 | |||
130 | def get_absolute_url(self): |
|
130 | def get_absolute_url(self): | |
131 | return reverse('url_campaign', args=[str(self.id)]) |
|
131 | return reverse('url_campaign', args=[str(self.id)]) | |
132 |
|
132 | |||
|
133 | def parms_to_dict(self): | |||
|
134 | ||||
|
135 | import json | |||
|
136 | ||||
|
137 | parameters = {} | |||
|
138 | experiments = Experiment.objects.filter(campaign = campaign) | |||
|
139 | ||||
|
140 | ||||
|
141 | parameters['campaign'] = self.name | |||
|
142 | ||||
|
143 | #parameters = json.dumps(parameters, indent=2) | |||
|
144 | parameters = json.dumps(parameters) | |||
|
145 | return parameters | |||
|
146 | ||||
|
147 | def get_absolute_url_export(self): | |||
|
148 | return reverse('url_export_campaign', args=[str(self.id)]) | |||
|
149 | ||||
|
150 | ||||
133 |
|
151 | |||
134 | class RunningExperiment(models.Model): |
|
152 | class RunningExperiment(models.Model): | |
135 | radar = models.OneToOneField('Location', on_delete=models.CASCADE) |
|
153 | radar = models.OneToOneField('Location', on_delete=models.CASCADE) | |
136 | running_experiment = models.ManyToManyField('Experiment', blank = True) |
|
154 | running_experiment = models.ManyToManyField('Experiment', blank = True) | |
137 | status = models.PositiveSmallIntegerField(default=0, choices=RADAR_STATES) |
|
155 | status = models.PositiveSmallIntegerField(default=0, choices=RADAR_STATES) | |
138 |
|
156 | |||
139 |
|
157 | |||
140 | class Experiment(models.Model): |
|
158 | class Experiment(models.Model): | |
141 |
|
159 | |||
142 | template = models.BooleanField(default=False) |
|
160 | template = models.BooleanField(default=False) | |
143 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) |
|
161 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) | |
144 | name = models.CharField(max_length=40, default='', unique=True) |
|
162 | name = models.CharField(max_length=40, default='', unique=True) | |
145 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) |
|
163 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) | |
146 | start_time = models.TimeField(default='00:00:00') |
|
164 | start_time = models.TimeField(default='00:00:00') | |
147 | end_time = models.TimeField(default='23:59:59') |
|
165 | end_time = models.TimeField(default='23:59:59') | |
148 | status = models.PositiveSmallIntegerField(default=0, choices=EXP_STATES) |
|
166 | status = models.PositiveSmallIntegerField(default=0, choices=EXP_STATES) | |
149 |
|
167 | |||
150 | class Meta: |
|
168 | class Meta: | |
151 | db_table = 'db_experiments' |
|
169 | db_table = 'db_experiments' | |
152 | ordering = ('template', 'name') |
|
170 | ordering = ('template', 'name') | |
153 |
|
171 | |||
154 | def __unicode__(self): |
|
172 | def __unicode__(self): | |
155 | if self.template: |
|
173 | if self.template: | |
156 | return u'%s (template)' % (self.name) |
|
174 | return u'%s (template)' % (self.name) | |
157 | else: |
|
175 | else: | |
158 | return u'%s' % (self.name) |
|
176 | return u'%s' % (self.name) | |
159 |
|
177 | |||
160 | @property |
|
178 | @property | |
161 | def radar(self): |
|
179 | def radar(self): | |
162 | return self.location |
|
180 | return self.location | |
163 |
|
181 | |||
164 | def clone(self, **kwargs): |
|
182 | def clone(self, **kwargs): | |
165 |
|
183 | |||
166 | confs = Configuration.objects.filter(experiment=self, type=0) |
|
184 | confs = Configuration.objects.filter(experiment=self, type=0) | |
167 | self.pk = None |
|
185 | self.pk = None | |
168 | self.name = '{} [{:%Y/%m/%d}]'.format(self.name, datetime.now()) |
|
186 | self.name = '{} [{:%Y/%m/%d}]'.format(self.name, datetime.now()) | |
169 | for attr, value in kwargs.items(): |
|
187 | for attr, value in kwargs.items(): | |
170 | setattr(self, attr, value) |
|
188 | setattr(self, attr, value) | |
171 |
|
189 | |||
172 | self.save() |
|
190 | self.save() | |
173 |
|
191 | |||
174 | for conf in confs: |
|
192 | for conf in confs: | |
175 | conf.clone(experiment=self, template=False) |
|
193 | conf.clone(experiment=self, template=False) | |
176 |
|
194 | |||
177 | return self |
|
195 | return self | |
178 |
|
196 | |||
179 | def get_status(self): |
|
197 | def get_status(self): | |
180 | configurations = Configuration.objects.filter(experiment=self) |
|
198 | configurations = Configuration.objects.filter(experiment=self) | |
181 | exp_status=[] |
|
199 | exp_status=[] | |
182 | for conf in configurations: |
|
200 | for conf in configurations: | |
183 | print conf.status_device() |
|
201 | print conf.status_device() | |
184 | exp_status.append(conf.status_device()) |
|
202 | exp_status.append(conf.status_device()) | |
185 |
|
203 | |||
186 | if not exp_status: #No Configuration |
|
204 | if not exp_status: #No Configuration | |
187 | self.status = 4 |
|
205 | self.status = 4 | |
188 | self.save() |
|
206 | self.save() | |
189 | return |
|
207 | return | |
190 |
|
208 | |||
191 | total = 1 |
|
209 | total = 1 | |
192 | for e_s in exp_status: |
|
210 | for e_s in exp_status: | |
193 | total = total*e_s |
|
211 | total = total*e_s | |
194 |
|
212 | |||
195 | if total == 0: #Error |
|
213 | if total == 0: #Error | |
196 | status = 0 |
|
214 | status = 0 | |
197 | elif total == (3**len(exp_status)): #Running |
|
215 | elif total == (3**len(exp_status)): #Running | |
198 | status = 2 |
|
216 | status = 2 | |
199 | else: |
|
217 | else: | |
200 | status = 1 #Configurated |
|
218 | status = 1 #Configurated | |
201 |
|
219 | |||
202 | self.status = status |
|
220 | self.status = status | |
203 | self.save() |
|
221 | self.save() | |
204 |
|
222 | |||
205 | def status_color(self): |
|
223 | def status_color(self): | |
206 | color = 'danger' |
|
224 | color = 'danger' | |
207 | if self.status == 0: |
|
225 | if self.status == 0: | |
208 | color = "danger" |
|
226 | color = "danger" | |
209 | elif self.status == 1: |
|
227 | elif self.status == 1: | |
210 | color = "info" |
|
228 | color = "info" | |
211 | elif self.status == 2: |
|
229 | elif self.status == 2: | |
212 | color = "success" |
|
230 | color = "success" | |
213 | elif self.status == 3: |
|
231 | elif self.status == 3: | |
214 | color = "warning" |
|
232 | color = "warning" | |
215 | else: |
|
233 | else: | |
216 | color = "muted" |
|
234 | color = "muted" | |
217 |
|
235 | |||
218 | return color |
|
236 | return color | |
219 |
|
237 | |||
220 | def get_absolute_url(self): |
|
238 | def get_absolute_url(self): | |
221 | return reverse('url_experiment', args=[str(self.id)]) |
|
239 | return reverse('url_experiment', args=[str(self.id)]) | |
222 |
|
240 | |||
|
241 | def parms_to_dict(self): | |||
|
242 | ||||
|
243 | import json | |||
|
244 | ||||
|
245 | configurations = Configuration.objects.filter(experiment=self) | |||
|
246 | conf_parameters = {} | |||
|
247 | parameters={} | |||
|
248 | ||||
|
249 | for configuration in configurations: | |||
|
250 | if 'cgs' in configuration.device.device_type.name: | |||
|
251 | conf_parameters['cgs'] = configuration.parms_to_dict() | |||
|
252 | if 'dds' in configuration.device.device_type.name: | |||
|
253 | conf_parameters['dds'] = configuration.parms_to_dict() | |||
|
254 | if 'rc' in configuration.device.device_type.name: | |||
|
255 | conf_parameters['rc'] = configuration.parms_to_dict() | |||
|
256 | if 'jars' in configuration.device.device_type.name: | |||
|
257 | conf_parameters['jars'] = configuration.parms_to_dict() | |||
|
258 | if 'usrp' in configuration.device.device_type.name: | |||
|
259 | conf_parameters['usrp'] = configuration.parms_to_dict() | |||
|
260 | if 'abs' in configuration.device.device_type.name: | |||
|
261 | conf_parameters['abs'] = configuration.parms_to_dict() | |||
|
262 | ||||
|
263 | parameters['configurations'] = conf_parameters | |||
|
264 | parameters['end_time'] = self.end_time.strftime("%Y-%m-%d") | |||
|
265 | parameters['start_time'] = self.start_time.strftime("%Y-%m-%d") | |||
|
266 | parameters['radar'] = self.radar.name | |||
|
267 | parameters['experiment'] = self.name | |||
|
268 | parameters = json.dumps(parameters, indent=2) | |||
|
269 | #parameters = json.dumps(parameters) | |||
|
270 | ||||
|
271 | return parameters | |||
|
272 | ||||
|
273 | def get_absolute_url_export(self): | |||
|
274 | return reverse('url_export_experiment', args=[str(self.id)]) | |||
|
275 | ||||
223 |
|
276 | |||
224 | class Configuration(PolymorphicModel): |
|
277 | class Configuration(PolymorphicModel): | |
225 |
|
278 | |||
226 | template = models.BooleanField(default=False) |
|
279 | template = models.BooleanField(default=False) | |
227 |
|
280 | |||
228 | name = models.CharField(verbose_name="Configuration Name", max_length=40, default='') |
|
281 | name = models.CharField(verbose_name="Configuration Name", max_length=40, default='') | |
229 |
|
282 | |||
230 | experiment = models.ForeignKey('Experiment', null=True, blank=True, on_delete=models.CASCADE) |
|
283 | experiment = models.ForeignKey('Experiment', null=True, blank=True, on_delete=models.CASCADE) | |
231 | device = models.ForeignKey(Device, on_delete=models.CASCADE) |
|
284 | device = models.ForeignKey(Device, on_delete=models.CASCADE) | |
232 |
|
285 | |||
233 | type = models.PositiveSmallIntegerField(default=0, choices=CONF_TYPES) |
|
286 | type = models.PositiveSmallIntegerField(default=0, choices=CONF_TYPES) | |
234 |
|
287 | |||
235 | created_date = models.DateTimeField(auto_now_add=True) |
|
288 | created_date = models.DateTimeField(auto_now_add=True) | |
236 | programmed_date = models.DateTimeField(auto_now=True) |
|
289 | programmed_date = models.DateTimeField(auto_now=True) | |
237 |
|
290 | |||
238 | parameters = models.TextField(default='{}') |
|
291 | parameters = models.TextField(default='{}') | |
239 |
|
292 | |||
240 | message = "" |
|
293 | message = "" | |
241 |
|
294 | |||
242 | class Meta: |
|
295 | class Meta: | |
243 | db_table = 'db_configurations' |
|
296 | db_table = 'db_configurations' | |
244 |
|
297 | |||
245 | def __unicode__(self): |
|
298 | def __unicode__(self): | |
246 |
|
299 | |||
247 | if self.experiment: |
|
300 | if self.experiment: | |
248 | return u'[%s, %s]: %s' % (self.experiment.name, |
|
301 | return u'[%s, %s]: %s' % (self.experiment.name, | |
249 | self.device.name, |
|
302 | self.device.name, | |
250 | self.name) |
|
303 | self.name) | |
251 | else: |
|
304 | else: | |
252 | return u'%s' % self.device.name |
|
305 | return u'%s' % self.device.name | |
253 |
|
306 | |||
254 | def clone(self, **kwargs): |
|
307 | def clone(self, **kwargs): | |
255 |
|
308 | |||
256 | self.pk = None |
|
309 | self.pk = None | |
257 | self.id = None |
|
310 | self.id = None | |
258 | for attr, value in kwargs.items(): |
|
311 | for attr, value in kwargs.items(): | |
259 | setattr(self, attr, value) |
|
312 | setattr(self, attr, value) | |
260 |
|
313 | |||
261 | self.save() |
|
314 | self.save() | |
262 |
|
315 | |||
263 | return self |
|
316 | return self | |
264 |
|
317 | |||
265 | def parms_to_dict(self): |
|
318 | def parms_to_dict(self): | |
266 |
|
319 | |||
267 | parameters = {} |
|
320 | parameters = {} | |
268 |
|
321 | |||
269 | for key in self.__dict__.keys(): |
|
322 | for key in self.__dict__.keys(): | |
270 | parameters[key] = getattr(self, key) |
|
323 | parameters[key] = getattr(self, key) | |
271 |
|
324 | |||
272 | return parameters |
|
325 | return parameters | |
273 |
|
326 | |||
274 | def parms_to_text(self): |
|
327 | def parms_to_text(self): | |
275 |
|
328 | |||
276 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
329 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
277 |
|
330 | |||
278 | return '' |
|
331 | return '' | |
279 |
|
332 | |||
280 | def parms_to_binary(self): |
|
333 | def parms_to_binary(self): | |
281 |
|
334 | |||
282 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
335 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
283 |
|
336 | |||
284 | return '' |
|
337 | return '' | |
285 |
|
338 | |||
286 | def dict_to_parms(self, parameters): |
|
339 | def dict_to_parms(self, parameters): | |
287 |
|
340 | |||
288 | if type(parameters) != type({}): |
|
341 | if type(parameters) != type({}): | |
289 | return |
|
342 | return | |
290 |
|
343 | |||
291 | for key in parameters.keys(): |
|
344 | for key in parameters.keys(): | |
292 | setattr(self, key, parameters[key]) |
|
345 | setattr(self, key, parameters[key]) | |
293 |
|
346 | |||
294 | def export_to_file(self, format="json"): |
|
347 | def export_to_file(self, format="json"): | |
295 |
|
348 | |||
296 | import json |
|
349 | import json | |
297 |
|
350 | |||
298 | content_type = '' |
|
351 | content_type = '' | |
299 |
|
352 | |||
300 | if format == 'text': |
|
353 | if format == 'text': | |
301 | content_type = 'text/plain' |
|
354 | content_type = 'text/plain' | |
302 | filename = '%s_%s.%s' %(self.device.device_type.name, self.name, self.device.device_type.name) |
|
355 | filename = '%s_%s.%s' %(self.device.device_type.name, self.name, self.device.device_type.name) | |
303 | content = self.parms_to_text() |
|
356 | content = self.parms_to_text() | |
304 |
|
357 | |||
305 | if format == 'binary': |
|
358 | if format == 'binary': | |
306 | content_type = 'application/octet-stream' |
|
359 | content_type = 'application/octet-stream' | |
307 | filename = '%s_%s.bin' %(self.device.device_type.name, self.name) |
|
360 | filename = '%s_%s.bin' %(self.device.device_type.name, self.name) | |
308 | content = self.parms_to_binary() |
|
361 | content = self.parms_to_binary() | |
309 |
|
362 | |||
310 | if not content_type: |
|
363 | if not content_type: | |
311 | content_type = 'application/json' |
|
364 | content_type = 'application/json' | |
312 | filename = '%s_%s.json' %(self.device.device_type.name, self.name) |
|
365 | filename = '%s_%s.json' %(self.device.device_type.name, self.name) | |
313 | content = json.dumps(self.parms_to_dict(), indent=2) |
|
366 | content = json.dumps(self.parms_to_dict(), indent=2) | |
314 |
|
367 | |||
315 | fields = {'content_type':content_type, |
|
368 | fields = {'content_type':content_type, | |
316 | 'filename':filename, |
|
369 | 'filename':filename, | |
317 | 'content':content |
|
370 | 'content':content | |
318 | } |
|
371 | } | |
319 |
|
372 | |||
320 | return fields |
|
373 | return fields | |
321 |
|
374 | |||
322 | def import_from_file(self, fp): |
|
375 | def import_from_file(self, fp): | |
323 |
|
376 | |||
324 | import os, json |
|
377 | import os, json | |
325 |
|
378 | |||
326 | parms = {} |
|
379 | parms = {} | |
327 |
|
380 | |||
328 | path, ext = os.path.splitext(fp.name) |
|
381 | path, ext = os.path.splitext(fp.name) | |
329 |
|
382 | |||
330 | if ext == '.json': |
|
383 | if ext == '.json': | |
331 | parms = json.load(fp) |
|
384 | parms = json.load(fp) | |
332 |
|
385 | |||
333 | return parms |
|
386 | return parms | |
334 |
|
387 | |||
335 | def status_device(self): |
|
388 | def status_device(self): | |
336 |
|
389 | |||
337 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
390 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
338 |
|
391 | |||
339 | return None |
|
392 | return None | |
340 |
|
393 | |||
341 | def stop_device(self): |
|
394 | def stop_device(self): | |
342 |
|
395 | |||
343 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
396 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
344 |
|
397 | |||
345 | return None |
|
398 | return None | |
346 |
|
399 | |||
347 | def start_device(self): |
|
400 | def start_device(self): | |
348 |
|
401 | |||
349 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
402 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
350 |
|
403 | |||
351 | return None |
|
404 | return None | |
352 |
|
405 | |||
353 | def write_device(self, parms): |
|
406 | def write_device(self, parms): | |
354 |
|
407 | |||
355 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
408 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
356 |
|
409 | |||
357 | return None |
|
410 | return None | |
358 |
|
411 | |||
359 | def read_device(self): |
|
412 | def read_device(self): | |
360 |
|
413 | |||
361 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
414 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
362 |
|
415 | |||
363 | return None |
|
416 | return None | |
364 |
|
417 | |||
365 | def get_absolute_url(self): |
|
418 | def get_absolute_url(self): | |
366 | return reverse('url_%s_conf' % self.device.device_type.name, args=[str(self.id)]) |
|
419 | return reverse('url_%s_conf' % self.device.device_type.name, args=[str(self.id)]) | |
367 |
|
420 | |||
368 | def get_absolute_url_edit(self): |
|
421 | def get_absolute_url_edit(self): | |
369 | return reverse('url_edit_%s_conf' % self.device.device_type.name, args=[str(self.id)]) |
|
422 | return reverse('url_edit_%s_conf' % self.device.device_type.name, args=[str(self.id)]) | |
370 |
|
423 | |||
371 | def get_absolute_url_import(self): |
|
424 | def get_absolute_url_import(self): | |
372 | return reverse('url_import_dev_conf', args=[str(self.id)]) |
|
425 | return reverse('url_import_dev_conf', args=[str(self.id)]) | |
373 |
|
426 | |||
374 | def get_absolute_url_export(self): |
|
427 | def get_absolute_url_export(self): | |
375 | return reverse('url_export_dev_conf', args=[str(self.id)]) |
|
428 | return reverse('url_export_dev_conf', args=[str(self.id)]) | |
376 |
|
429 | |||
377 | def get_absolute_url_write(self): |
|
430 | def get_absolute_url_write(self): | |
378 | return reverse('url_write_dev_conf', args=[str(self.id)]) |
|
431 | return reverse('url_write_dev_conf', args=[str(self.id)]) | |
379 |
|
432 | |||
380 | def get_absolute_url_read(self): |
|
433 | def get_absolute_url_read(self): | |
381 | return reverse('url_read_dev_conf', args=[str(self.id)]) |
|
434 | return reverse('url_read_dev_conf', args=[str(self.id)]) | |
382 |
|
435 | |||
383 | def get_absolute_url_start(self): |
|
436 | def get_absolute_url_start(self): | |
384 | return reverse('url_start_dev_conf', args=[str(self.id)]) |
|
437 | return reverse('url_start_dev_conf', args=[str(self.id)]) | |
385 |
|
438 | |||
386 | def get_absolute_url_stop(self): |
|
439 | def get_absolute_url_stop(self): | |
387 | return reverse('url_stop_dev_conf', args=[str(self.id)]) |
|
440 | return reverse('url_stop_dev_conf', args=[str(self.id)]) | |
388 |
|
441 | |||
389 | def get_absolute_url_status(self): |
|
442 | def get_absolute_url_status(self): | |
390 | return reverse('url_status_dev_conf', args=[str(self.id)]) No newline at end of file |
|
443 | return reverse('url_status_dev_conf', args=[str(self.id)]) |
@@ -1,84 +1,108 | |||||
1 | {% extends "base.html" %} |
|
1 | {% extends "base.html" %} | |
2 | {% load bootstrap3 %} |
|
2 | {% load bootstrap3 %} | |
3 | {% load static %} |
|
3 | {% load static %} | |
4 | {% load main_tags %} |
|
4 | {% load main_tags %} | |
5 | {% block extra-head %} |
|
5 | {% block extra-head %} | |
6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> |
|
6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> | |
7 | {% endblock %} |
|
7 | {% endblock %} | |
8 |
|
8 | |||
9 | {% block camp-active %}active{% endblock %} |
|
9 | {% block camp-active %}active{% endblock %} | |
10 |
|
10 | |||
11 | {% block content-title %}{{title}}{% endblock %} |
|
11 | {% block content-title %}{{title}}{% endblock %} | |
12 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
12 | {% block content-suptitle %}{{suptitle}}{% endblock %} | |
13 |
|
13 | |||
14 | {% block content %} |
|
14 | {% block content %} | |
|
15 | ||||
|
16 | {% block menu-actions %} | |||
|
17 | <span class=" dropdown pull-right"> | |||
|
18 | <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-menu-hamburger gi-2x" aria-hidden="true"></span></a> | |||
|
19 | <ul class="dropdown-menu" role="menu"> | |||
|
20 | <li><a href="{% url 'url_edit_campaign' campaign.id %}"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a></li> | |||
|
21 | <li><a href="{% url 'url_delete_campaign' campaign.id %}"><span class="glyphicon glyphicon-remove-sign" aria-hidden="true"></span> Delete</a></li> | |||
|
22 | <li><a href="{{ dev_conf.get_absolute_url_import }}"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Import </a></li> | |||
|
23 | <li><a href="{{ campaign.get_absolute_url_export }}"><span class="glyphicon glyphicon-export" aria-hidden="true"></span> Export </a></li> | |||
|
24 | {% block extra-menu-actions %} | |||
|
25 | {% endblock %} | |||
|
26 | <li><a>----------------</a></li> | |||
|
27 | <li><a href="#"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Mix Experiments</a></li> | |||
|
28 | <!--<li><a href="{{ dev_conf.get_absolute_url_status }}"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Status</a></li> | |||
|
29 | {% if not no_play %} | |||
|
30 | <li><a href="{{ dev_conf.get_absolute_url_start}}"><span class="glyphicon glyphicon-play" aria-hidden="true"></span> Start</a></li> | |||
|
31 | <li><a href="{{ dev_conf.get_absolute_url_stop }}"><span class="glyphicon glyphicon-stop" aria-hidden="true"></span> Stop</a></li> | |||
|
32 | {% endif %} | |||
|
33 | <li><a href="{{ dev_conf.get_absolute_url_write }}"><span class="glyphicon glyphicon-download" aria-hidden="true"></span> Write</a></li> | |||
|
34 | <li><a href="{{ dev_conf.get_absolute_url_read }}"><span class="glyphicon glyphicon-upload" aria-hidden="true"></span> Read</a></li>--> | |||
|
35 | </ul> | |||
|
36 | </span> | |||
|
37 | {% endblock %} | |||
|
38 | ||||
15 | <table class="table table-bordered"> |
|
39 | <table class="table table-bordered"> | |
16 | {% for key in campaign_keys %} |
|
40 | {% for key in campaign_keys %} | |
17 | <tr><th>{{key|title}}</th><td>{{campaign|attr:key}}</td></tr> |
|
41 | <tr><th>{{key|title}}</th><td>{{campaign|attr:key}}</td></tr> | |
18 | {% endfor %} |
|
42 | {% endfor %} | |
19 | </table> |
|
43 | </table> | |
20 |
|
44 | |||
21 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_export">Export</button> |
|
45 | <!--<button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_export">Export</button>--> | |
22 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_edit">Edit</button> |
|
46 | <!--<button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_edit">Edit</button>--> | |
23 |
|
47 | |||
24 | <br></br> |
|
48 | <br></br> | |
25 | <br></br> |
|
49 | <br></br> | |
26 |
|
50 | |||
27 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> |
|
51 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> | |
28 |
|
52 | |||
29 | <div class="panel panel-default"> |
|
53 | <div class="panel panel-default"> | |
30 | <div class="panel-heading" role="tab" id="headingTwo"> |
|
54 | <div class="panel-heading" role="tab" id="headingTwo"> | |
31 | <h4 class="panel-title"> |
|
55 | <h4 class="panel-title"> | |
32 | <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo"> |
|
56 | <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo"> | |
33 | Experiment List |
|
57 | Experiment List | |
34 | </a> |
|
58 | </a> | |
35 | </h4> |
|
59 | </h4> | |
36 | </div> |
|
60 | </div> | |
37 |
|
61 | |||
38 | <div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> |
|
62 | <div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> | |
39 | <div class="panel-body"> |
|
63 | <div class="panel-body"> | |
40 | <table class="table table-hover"> |
|
64 | <table class="table table-hover"> | |
41 | <tr> |
|
65 | <tr> | |
42 | <th>#</th> |
|
66 | <th>#</th> | |
43 | {% for header in experiment_keys %} |
|
67 | {% for header in experiment_keys %} | |
44 | <th>{{ header|title }}</th> |
|
68 | <th>{{ header|title }}</th> | |
45 | {% endfor%} |
|
69 | {% endfor%} | |
46 | </tr> |
|
70 | </tr> | |
47 | {% for item in experiments %} |
|
71 | {% for item in experiments %} | |
48 | <tr class="clickable-row" data-href="{% url 'url_experiment' item.id %}"> |
|
72 | <tr class="clickable-row" data-href="{% url 'url_experiment' item.id %}"> | |
49 | <td>{{ forloop.counter }}</td> |
|
73 | <td>{{ forloop.counter }}</td> | |
50 | {% for key in experiment_keys %} |
|
74 | {% for key in experiment_keys %} | |
51 | <td>{{ item|attr:key }}</td> |
|
75 | <td>{{ item|attr:key }}</td> | |
52 | {% endfor %} |
|
76 | {% endfor %} | |
53 | </tr> |
|
77 | </tr> | |
54 | {% endfor %} |
|
78 | {% endfor %} | |
55 | </table> |
|
79 | </table> | |
56 | </div> |
|
80 | </div> | |
57 | </div> |
|
81 | </div> | |
58 | </div> |
|
82 | </div> | |
59 | </div> |
|
83 | </div> | |
60 | <br> |
|
84 | <br> | |
61 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_mix">Mix Experiments</button> |
|
85 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_mix">Mix Experiments</button> | |
62 | {% endblock %} |
|
86 | {% endblock %} | |
63 |
|
87 | |||
64 | {% block sidebar%} |
|
88 | {% block sidebar%} | |
65 | {% include "sidebar_devices.html" %} |
|
89 | {% include "sidebar_devices.html" %} | |
66 | {% endblock %} |
|
90 | {% endblock %} | |
67 |
|
91 | |||
68 | {% block extra-js%} |
|
92 | {% block extra-js%} | |
69 | <script type="text/javascript"> |
|
93 | <script type="text/javascript"> | |
70 |
|
94 | |||
71 | $(".clickable-row").click(function() { |
|
95 | $(".clickable-row").click(function() { | |
72 | document.location = $(this).data("href"); |
|
96 | document.location = $(this).data("href"); | |
73 | }); |
|
97 | }); | |
74 |
|
98 | |||
75 |
|
|
99 | // $("#bt_edit").click(function() { | |
76 |
|
|
100 | // document.location = "{% url 'url_edit_campaign' campaign.id %}"; | |
77 |
|
|
101 | // }); | |
78 |
|
102 | |||
79 | $("#bt_mix").click(function() { |
|
103 | $("#bt_mix").click(function() { | |
80 | document.location = "{% url 'url_mix_campaign' campaign.id %}"; |
|
104 | ||
81 | }); |
|
105 | }); | |
82 |
|
106 | |||
83 | </script> |
|
107 | </script> | |
84 | {% endblock %} No newline at end of file |
|
108 | {% endblock %} |
@@ -1,80 +1,95 | |||||
1 | {% extends "base.html" %} |
|
1 | {% extends "base.html" %} | |
2 | {% load bootstrap3 %} |
|
2 | {% load bootstrap3 %} | |
3 | {% load static %} |
|
3 | {% load static %} | |
4 | {% load main_tags %} |
|
4 | {% load main_tags %} | |
5 | {% block extra-head %} |
|
5 | {% block extra-head %} | |
6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> |
|
6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> | |
7 | {% endblock %} |
|
7 | {% endblock %} | |
8 |
|
8 | |||
9 | {% block exp-active %}active{% endblock %} |
|
9 | {% block exp-active %}active{% endblock %} | |
10 |
|
10 | |||
11 | {% block content-title %}{{title}}{% endblock %} |
|
11 | {% block content-title %}{{title}}{% endblock %} | |
12 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
12 | {% block content-suptitle %}{{suptitle}}{% endblock %} | |
13 |
|
13 | |||
14 | {% block content %} |
|
14 | {% block content %} | |
|
15 | ||||
|
16 | {% block menu-actions %} | |||
|
17 | <span class=" dropdown pull-right"> | |||
|
18 | <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-menu-hamburger gi-2x" aria-hidden="true"></span></a> | |||
|
19 | <ul class="dropdown-menu" role="menu"> | |||
|
20 | <li><a href="{% url 'url_edit_experiment' experiment.id %}"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a></li> | |||
|
21 | <li><a href="{% url 'url_delete_experiment' experiment.id %}"><span class="glyphicon glyphicon-remove-sign" aria-hidden="true"></span> Delete</a></li> | |||
|
22 | <li><a href="{{ dev_conf.get_absolute_url_import }}"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Import </a></li> | |||
|
23 | <li><a href="{{ experiment.get_absolute_url_export }}"><span class="glyphicon glyphicon-export" aria-hidden="true"></span> Export </a></li> | |||
|
24 | {% block extra-menu-actions %} | |||
|
25 | {% endblock %} | |||
|
26 | <li><a>----------------</a></li> | |||
|
27 | <li><a href="#"><span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span> Add Configuration</a></li> | |||
|
28 | </ul> | |||
|
29 | </span> | |||
|
30 | {% endblock %} | |||
|
31 | ||||
15 | <table class="table table-bordered"> |
|
32 | <table class="table table-bordered"> | |
16 | {% for key in experiment_keys %} |
|
33 | {% for key in experiment_keys %} | |
17 | <tr><th>{{key|title}}</th><td>{{experiment|attr:key}}</td></tr> |
|
34 | <tr><th>{{key|title}}</th><td>{{experiment|attr:key}}</td></tr> | |
18 | {% endfor %} |
|
35 | {% endfor %} | |
19 | </table> |
|
36 | </table> | |
20 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_export">Export</button> |
|
|||
21 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_edit">Edit</button> |
|
|||
22 | <br></br> |
|
37 | <br></br> | |
23 | <br></br> |
|
38 | <br></br> | |
24 |
|
39 | |||
25 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> |
|
40 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> | |
26 |
|
41 | |||
27 | <div class="panel panel-default"> |
|
42 | <div class="panel panel-default"> | |
28 | <div class="panel-heading" role="tab" id="headingTwo"> |
|
43 | <div class="panel-heading" role="tab" id="headingTwo"> | |
29 | <h4 class="panel-title"> |
|
44 | <h4 class="panel-title"> | |
30 | <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseThree"> |
|
45 | <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseThree"> | |
31 | Device Configurations |
|
46 | Device Configurations | |
32 | </a> |
|
47 | </a> | |
33 | </h4> |
|
48 | </h4> | |
34 | </div> |
|
49 | </div> | |
35 | <div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> |
|
50 | <div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> | |
36 | <div class="panel-body"> |
|
51 | <div class="panel-body"> | |
37 | <table class="table table-hover"> |
|
52 | <table class="table table-hover"> | |
38 | <tr> |
|
53 | <tr> | |
39 | <th>#</th> |
|
54 | <th>#</th> | |
40 | {% for key in configuration_keys %} |
|
55 | {% for key in configuration_keys %} | |
41 | <th>{{ key|title }}</th> |
|
56 | <th>{{ key|title }}</th> | |
42 | {% endfor%} |
|
57 | {% endfor%} | |
43 | </tr> |
|
58 | </tr> | |
44 | {% for item in configurations %} |
|
59 | {% for item in configurations %} | |
45 | <tr class="clickable-row" data-href="{{item.get_absolute_url}}"> |
|
60 | <tr class="clickable-row" data-href="{{item.get_absolute_url}}"> | |
46 | <td>{{ forloop.counter }}</td> |
|
61 | <td>{{ forloop.counter }}</td> | |
47 | {% for key in configuration_keys %} |
|
62 | {% for key in configuration_keys %} | |
48 | <td>{{ item|value:key }}</td> |
|
63 | <td>{{ item|value:key }}</td> | |
49 | {% endfor %} |
|
64 | {% endfor %} | |
50 | </tr> |
|
65 | </tr> | |
51 | {% endfor %} |
|
66 | {% endfor %} | |
52 | </table> |
|
67 | </table> | |
53 | <button class="btn btn-primary pull-right" id="bt_add_conf">{{button}}</button> |
|
68 | <button class="btn btn-primary pull-right" id="bt_add_conf">{{button}}</button> | |
54 | </div> |
|
69 | </div> | |
55 | </div> |
|
70 | </div> | |
56 | </div> |
|
71 | </div> | |
57 | </div> |
|
72 | </div> | |
58 | {% endblock %} |
|
73 | {% endblock %} | |
59 |
|
74 | |||
60 | {% block sidebar%} |
|
75 | {% block sidebar%} | |
61 | {% include "sidebar_devices.html" %} |
|
76 | {% include "sidebar_devices.html" %} | |
62 | {% endblock %} |
|
77 | {% endblock %} | |
63 |
|
78 | |||
64 | {% block extra-js%} |
|
79 | {% block extra-js%} | |
65 | <script type="text/javascript"> |
|
80 | <script type="text/javascript"> | |
66 |
|
81 | |||
67 | $(".clickable-row").click(function() { |
|
82 | $(".clickable-row").click(function() { | |
68 | document.location = $(this).data("href"); |
|
83 | document.location = $(this).data("href"); | |
69 | }); |
|
84 | }); | |
70 |
|
85 | |||
71 | $("#bt_edit").click(function() { |
|
86 | $("#bt_edit").click(function() { | |
72 | document.location = "{% url 'url_edit_experiment' experiment.id%}"; |
|
87 | document.location = "{% url 'url_edit_experiment' experiment.id%}"; | |
73 | }); |
|
88 | }); | |
74 |
|
89 | |||
75 | $("#bt_add_conf").click(function() { |
|
90 | $("#bt_add_conf").click(function() { | |
76 | document.location = "{% url 'url_add_dev_conf' experiment.id %}"; |
|
91 | document.location = "{% url 'url_add_dev_conf' experiment.id %}"; | |
77 | }); |
|
92 | }); | |
78 |
|
93 | |||
79 | </script> |
|
94 | </script> | |
80 | {% endblock %} No newline at end of file |
|
95 | {% endblock %} |
@@ -1,51 +1,53 | |||||
1 | from django.conf.urls import url |
|
1 | from django.conf.urls import url | |
2 |
|
2 | |||
3 | urlpatterns = ( |
|
3 | urlpatterns = ( | |
4 | url(r'^location/new/$', 'apps.main.views.location_new', name='url_add_location'), |
|
4 | url(r'^location/new/$', 'apps.main.views.location_new', name='url_add_location'), | |
5 | url(r'^location/$', 'apps.main.views.locations', name='url_locations'), |
|
5 | url(r'^location/$', 'apps.main.views.locations', name='url_locations'), | |
6 | url(r'^location/(?P<id_loc>-?\d+)/$', 'apps.main.views.location', name='url_location'), |
|
6 | url(r'^location/(?P<id_loc>-?\d+)/$', 'apps.main.views.location', name='url_location'), | |
7 | url(r'^location/(?P<id_loc>-?\d+)/edit/$', 'apps.main.views.location_edit', name='url_edit_location'), |
|
7 | url(r'^location/(?P<id_loc>-?\d+)/edit/$', 'apps.main.views.location_edit', name='url_edit_location'), | |
8 | url(r'^location/(?P<id_loc>-?\d+)/delete/$', 'apps.main.views.location_delete', name='url_delete_location'), |
|
8 | url(r'^location/(?P<id_loc>-?\d+)/delete/$', 'apps.main.views.location_delete', name='url_delete_location'), | |
9 |
|
9 | |||
10 | url(r'^device/new/$', 'apps.main.views.device_new', name='url_add_device'), |
|
10 | url(r'^device/new/$', 'apps.main.views.device_new', name='url_add_device'), | |
11 | url(r'^device/$', 'apps.main.views.devices', name='url_devices'), |
|
11 | url(r'^device/$', 'apps.main.views.devices', name='url_devices'), | |
12 | url(r'^device/(?P<id_dev>-?\d+)/$', 'apps.main.views.device', name='url_device'), |
|
12 | url(r'^device/(?P<id_dev>-?\d+)/$', 'apps.main.views.device', name='url_device'), | |
13 | url(r'^device/(?P<id_dev>-?\d+)/edit/$', 'apps.main.views.device_edit', name='url_edit_device'), |
|
13 | url(r'^device/(?P<id_dev>-?\d+)/edit/$', 'apps.main.views.device_edit', name='url_edit_device'), | |
14 | url(r'^device/(?P<id_dev>-?\d+)/delete/$', 'apps.main.views.device_delete', name='url_delete_device'), |
|
14 | url(r'^device/(?P<id_dev>-?\d+)/delete/$', 'apps.main.views.device_delete', name='url_delete_device'), | |
15 |
|
15 | |||
16 | url(r'^campaign/new/$', 'apps.main.views.campaign_new', name='url_add_campaign'), |
|
16 | url(r'^campaign/new/$', 'apps.main.views.campaign_new', name='url_add_campaign'), | |
17 | url(r'^campaign/$', 'apps.main.views.campaigns', name='url_campaigns'), |
|
17 | url(r'^campaign/$', 'apps.main.views.campaigns', name='url_campaigns'), | |
18 | url(r'^campaign/(?P<id_camp>-?\d+)/$', 'apps.main.views.campaign', name='url_campaign'), |
|
18 | url(r'^campaign/(?P<id_camp>-?\d+)/$', 'apps.main.views.campaign', name='url_campaign'), | |
19 | url(r'^campaign/(?P<id_camp>-?\d+)/edit/$', 'apps.main.views.campaign_edit', name='url_edit_campaign'), |
|
19 | url(r'^campaign/(?P<id_camp>-?\d+)/edit/$', 'apps.main.views.campaign_edit', name='url_edit_campaign'), | |
20 | url(r'^campaign/(?P<id_camp>-?\d+)/delete/$', 'apps.main.views.campaign_delete', name='url_delete_campaign'), |
|
20 | url(r'^campaign/(?P<id_camp>-?\d+)/delete/$', 'apps.main.views.campaign_delete', name='url_delete_campaign'), | |
|
21 | url(r'^campaign/(?P<id_camp>-?\d+)/export/$', 'apps.main.views.campaign_export', name='url_export_campaign'), | |||
21 |
|
22 | |||
22 | url(r'^experiment/new/$', 'apps.main.views.experiment_new', name='url_add_experiment'), |
|
23 | url(r'^experiment/new/$', 'apps.main.views.experiment_new', name='url_add_experiment'), | |
23 | url(r'^experiment/$', 'apps.main.views.experiments', name='url_experiments'), |
|
24 | url(r'^experiment/$', 'apps.main.views.experiments', name='url_experiments'), | |
24 | url(r'^experiment/(?P<id_exp>-?\d+)/$', 'apps.main.views.experiment', name='url_experiment'), |
|
25 | url(r'^experiment/(?P<id_exp>-?\d+)/$', 'apps.main.views.experiment', name='url_experiment'), | |
25 | url(r'^experiment/(?P<id_exp>-?\d+)/edit/$', 'apps.main.views.experiment_edit', name='url_edit_experiment'), |
|
26 | url(r'^experiment/(?P<id_exp>-?\d+)/edit/$', 'apps.main.views.experiment_edit', name='url_edit_experiment'), | |
26 | url(r'^experiment/(?P<id_exp>-?\d+)/delete/$', 'apps.main.views.experiment_delete', name='url_delete_experiment'), |
|
27 | url(r'^experiment/(?P<id_exp>-?\d+)/delete/$', 'apps.main.views.experiment_delete', name='url_delete_experiment'), | |
|
28 | url(r'^experiment/(?P<id_exp>-?\d+)/export/$', 'apps.main.views.experiment_export', name='url_export_experiment'), | |||
27 |
|
29 | |||
28 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), |
|
30 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), | |
29 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/(?P<id_dev>-?\d+)/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), |
|
31 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/(?P<id_dev>-?\d+)/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), | |
30 | url(r'^dev_conf/$', 'apps.main.views.dev_confs', name='url_dev_confs'), |
|
32 | url(r'^dev_conf/$', 'apps.main.views.dev_confs', name='url_dev_confs'), | |
31 | url(r'^dev_conf/(?P<id_conf>-?\d+)/$', 'apps.main.views.dev_conf', name='url_dev_conf'), |
|
33 | url(r'^dev_conf/(?P<id_conf>-?\d+)/$', 'apps.main.views.dev_conf', name='url_dev_conf'), | |
32 | url(r'^dev_conf/(?P<id_conf>-?\d+)/edit/$', 'apps.main.views.dev_conf_edit', name='url_edit_dev_conf'), |
|
34 | url(r'^dev_conf/(?P<id_conf>-?\d+)/edit/$', 'apps.main.views.dev_conf_edit', name='url_edit_dev_conf'), | |
33 | url(r'^dev_conf/(?P<id_conf>-?\d+)/delete/$', 'apps.main.views.dev_conf_delete', name='url_delete_dev_conf'), |
|
35 | url(r'^dev_conf/(?P<id_conf>-?\d+)/delete/$', 'apps.main.views.dev_conf_delete', name='url_delete_dev_conf'), | |
34 |
|
36 | |||
35 | url(r'^dev_conf/(?P<id_conf>-?\d+)/write/$', 'apps.main.views.dev_conf_write', name='url_write_dev_conf'), |
|
37 | url(r'^dev_conf/(?P<id_conf>-?\d+)/write/$', 'apps.main.views.dev_conf_write', name='url_write_dev_conf'), | |
36 | url(r'^dev_conf/(?P<id_conf>-?\d+)/read/$', 'apps.main.views.dev_conf_read', name='url_read_dev_conf'), |
|
38 | url(r'^dev_conf/(?P<id_conf>-?\d+)/read/$', 'apps.main.views.dev_conf_read', name='url_read_dev_conf'), | |
37 | url(r'^dev_conf/(?P<id_conf>-?\d+)/import/$', 'apps.main.views.dev_conf_import', name='url_import_dev_conf'), |
|
39 | url(r'^dev_conf/(?P<id_conf>-?\d+)/import/$', 'apps.main.views.dev_conf_import', name='url_import_dev_conf'), | |
38 | url(r'^dev_conf/(?P<id_conf>-?\d+)/export/$', 'apps.main.views.dev_conf_export', name='url_export_dev_conf'), |
|
40 | url(r'^dev_conf/(?P<id_conf>-?\d+)/export/$', 'apps.main.views.dev_conf_export', name='url_export_dev_conf'), | |
39 | url(r'^dev_conf/(?P<id_conf>-?\d+)/start/$', 'apps.main.views.dev_conf_start', name='url_start_dev_conf'), |
|
41 | url(r'^dev_conf/(?P<id_conf>-?\d+)/start/$', 'apps.main.views.dev_conf_start', name='url_start_dev_conf'), | |
40 | url(r'^dev_conf/(?P<id_conf>-?\d+)/stop/$', 'apps.main.views.dev_conf_stop', name='url_stop_dev_conf'), |
|
42 | url(r'^dev_conf/(?P<id_conf>-?\d+)/stop/$', 'apps.main.views.dev_conf_stop', name='url_stop_dev_conf'), | |
41 | url(r'^dev_conf/(?P<id_conf>-?\d+)/status/$', 'apps.main.views.dev_conf_status', name='url_status_dev_conf'), |
|
43 | url(r'^dev_conf/(?P<id_conf>-?\d+)/status/$', 'apps.main.views.dev_conf_status', name='url_status_dev_conf'), | |
42 |
|
44 | |||
43 | url(r'^operation/$', 'apps.main.views.operation', name='url_operation'), |
|
45 | url(r'^operation/$', 'apps.main.views.operation', name='url_operation'), | |
44 | url(r'^operation/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation', name='url_operation'), |
|
46 | url(r'^operation/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation', name='url_operation'), | |
45 | url(r'^operation/search/$', 'apps.main.views.operation_search', name='url_operation_search'), |
|
47 | url(r'^operation/search/$', 'apps.main.views.operation_search', name='url_operation_search'), | |
46 | url(r'^operation/search/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation_search', name='url_operation_search'), |
|
48 | url(r'^operation/search/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation_search', name='url_operation_search'), | |
47 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/play/$', 'apps.main.views.radar_play', name='url_radar_play'), |
|
49 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/play/$', 'apps.main.views.radar_play', name='url_radar_play'), | |
48 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/stop/$', 'apps.main.views.radar_stop', name='url_radar_stop'), |
|
50 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/stop/$', 'apps.main.views.radar_stop', name='url_radar_stop'), | |
49 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/refresh/$', 'apps.main.views.radar_refresh', name='url_radar_refresh'), |
|
51 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/refresh/$', 'apps.main.views.radar_refresh', name='url_radar_refresh'), | |
50 |
|
52 | |||
51 | ) |
|
53 | ) |
@@ -1,1099 +1,1125 | |||||
1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse |
|
1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse | |
2 | from django.http import HttpResponseRedirect |
|
2 | from django.http import HttpResponseRedirect | |
3 | from django.core.urlresolvers import reverse |
|
3 | from django.core.urlresolvers import reverse | |
4 | from django.contrib import messages |
|
4 | from django.contrib import messages | |
5 | from datetime import datetime |
|
5 | from datetime import datetime | |
6 |
|
6 | |||
7 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm, NewForm |
|
7 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm, NewForm | |
8 | from .forms import OperationSearchForm |
|
8 | from .forms import OperationSearchForm | |
9 | from apps.cgs.forms import CGSConfigurationForm |
|
9 | from apps.cgs.forms import CGSConfigurationForm | |
10 | from apps.jars.forms import JARSConfigurationForm |
|
10 | from apps.jars.forms import JARSConfigurationForm | |
11 | from apps.usrp.forms import USRPConfigurationForm |
|
11 | from apps.usrp.forms import USRPConfigurationForm | |
12 | from apps.abs.forms import ABSConfigurationForm |
|
12 | from apps.abs.forms import ABSConfigurationForm | |
13 | from apps.rc.forms import RCConfigurationForm |
|
13 | from apps.rc.forms import RCConfigurationForm | |
14 | from apps.dds.forms import DDSConfigurationForm |
|
14 | from apps.dds.forms import DDSConfigurationForm | |
15 |
|
15 | |||
16 | from .models import Campaign, Experiment, Device, Configuration, Location, RunningExperiment |
|
16 | from .models import Campaign, Experiment, Device, Configuration, Location, RunningExperiment | |
17 | from apps.cgs.models import CGSConfiguration |
|
17 | from apps.cgs.models import CGSConfiguration | |
18 | from apps.jars.models import JARSConfiguration |
|
18 | from apps.jars.models import JARSConfiguration | |
19 | from apps.usrp.models import USRPConfiguration |
|
19 | from apps.usrp.models import USRPConfiguration | |
20 | from apps.abs.models import ABSConfiguration |
|
20 | from apps.abs.models import ABSConfiguration | |
21 | from apps.rc.models import RCConfiguration |
|
21 | from apps.rc.models import RCConfiguration | |
22 | from apps.dds.models import DDSConfiguration |
|
22 | from apps.dds.models import DDSConfiguration | |
23 |
|
23 | |||
24 | # Create your views here. |
|
24 | # Create your views here. | |
25 |
|
25 | |||
26 | CONF_FORMS = { |
|
26 | CONF_FORMS = { | |
27 | 'rc': RCConfigurationForm, |
|
27 | 'rc': RCConfigurationForm, | |
28 | 'dds': DDSConfigurationForm, |
|
28 | 'dds': DDSConfigurationForm, | |
29 | 'jars': JARSConfigurationForm, |
|
29 | 'jars': JARSConfigurationForm, | |
30 | 'cgs': CGSConfigurationForm, |
|
30 | 'cgs': CGSConfigurationForm, | |
31 | 'abs': ABSConfigurationForm, |
|
31 | 'abs': ABSConfigurationForm, | |
32 | 'usrp': USRPConfigurationForm, |
|
32 | 'usrp': USRPConfigurationForm, | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | CONF_MODELS = { |
|
35 | CONF_MODELS = { | |
36 | 'rc': RCConfiguration, |
|
36 | 'rc': RCConfiguration, | |
37 | 'dds': DDSConfiguration, |
|
37 | 'dds': DDSConfiguration, | |
38 | 'jars': JARSConfiguration, |
|
38 | 'jars': JARSConfiguration, | |
39 | 'cgs': CGSConfiguration, |
|
39 | 'cgs': CGSConfiguration, | |
40 | 'abs': ABSConfiguration, |
|
40 | 'abs': ABSConfiguration, | |
41 | 'usrp': USRPConfiguration, |
|
41 | 'usrp': USRPConfiguration, | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 |
|
44 | |||
45 | def index(request): |
|
45 | def index(request): | |
46 | kwargs = {} |
|
46 | kwargs = {} | |
47 |
|
47 | |||
48 | return render(request, 'index.html', kwargs) |
|
48 | return render(request, 'index.html', kwargs) | |
49 |
|
49 | |||
50 |
|
50 | |||
51 | def locations(request): |
|
51 | def locations(request): | |
52 |
|
52 | |||
53 | locations = Location.objects.all().order_by('name') |
|
53 | locations = Location.objects.all().order_by('name') | |
54 |
|
54 | |||
55 | keys = ['id', 'name', 'description'] |
|
55 | keys = ['id', 'name', 'description'] | |
56 |
|
56 | |||
57 | kwargs = {} |
|
57 | kwargs = {} | |
58 | kwargs['location_keys'] = keys[1:] |
|
58 | kwargs['location_keys'] = keys[1:] | |
59 | kwargs['locations'] = locations |
|
59 | kwargs['locations'] = locations | |
60 | kwargs['title'] = 'Location' |
|
60 | kwargs['title'] = 'Location' | |
61 | kwargs['suptitle'] = 'List' |
|
61 | kwargs['suptitle'] = 'List' | |
62 | kwargs['button'] = 'New Location' |
|
62 | kwargs['button'] = 'New Location' | |
63 |
|
63 | |||
64 | return render(request, 'locations.html', kwargs) |
|
64 | return render(request, 'locations.html', kwargs) | |
65 |
|
65 | |||
66 |
|
66 | |||
67 | def location(request, id_loc): |
|
67 | def location(request, id_loc): | |
68 |
|
68 | |||
69 | location = get_object_or_404(Location, pk=id_loc) |
|
69 | location = get_object_or_404(Location, pk=id_loc) | |
70 |
|
70 | |||
71 | kwargs = {} |
|
71 | kwargs = {} | |
72 | kwargs['location'] = location |
|
72 | kwargs['location'] = location | |
73 | kwargs['location_keys'] = ['name', 'description'] |
|
73 | kwargs['location_keys'] = ['name', 'description'] | |
74 |
|
74 | |||
75 | kwargs['title'] = 'Location' |
|
75 | kwargs['title'] = 'Location' | |
76 | kwargs['suptitle'] = 'Details' |
|
76 | kwargs['suptitle'] = 'Details' | |
77 |
|
77 | |||
78 | return render(request, 'location.html', kwargs) |
|
78 | return render(request, 'location.html', kwargs) | |
79 |
|
79 | |||
80 |
|
80 | |||
81 | def location_new(request): |
|
81 | def location_new(request): | |
82 |
|
82 | |||
83 | if request.method == 'GET': |
|
83 | if request.method == 'GET': | |
84 | form = LocationForm() |
|
84 | form = LocationForm() | |
85 |
|
85 | |||
86 | if request.method == 'POST': |
|
86 | if request.method == 'POST': | |
87 | form = LocationForm(request.POST) |
|
87 | form = LocationForm(request.POST) | |
88 |
|
88 | |||
89 | if form.is_valid(): |
|
89 | if form.is_valid(): | |
90 | form.save() |
|
90 | form.save() | |
91 | return redirect('url_locations') |
|
91 | return redirect('url_locations') | |
92 |
|
92 | |||
93 | kwargs = {} |
|
93 | kwargs = {} | |
94 | kwargs['form'] = form |
|
94 | kwargs['form'] = form | |
95 | kwargs['title'] = 'Location' |
|
95 | kwargs['title'] = 'Location' | |
96 | kwargs['suptitle'] = 'New' |
|
96 | kwargs['suptitle'] = 'New' | |
97 | kwargs['button'] = 'Create' |
|
97 | kwargs['button'] = 'Create' | |
98 |
|
98 | |||
99 | return render(request, 'location_edit.html', kwargs) |
|
99 | return render(request, 'location_edit.html', kwargs) | |
100 |
|
100 | |||
101 |
|
101 | |||
102 | def location_edit(request, id_loc): |
|
102 | def location_edit(request, id_loc): | |
103 |
|
103 | |||
104 | location = get_object_or_404(Location, pk=id_loc) |
|
104 | location = get_object_or_404(Location, pk=id_loc) | |
105 |
|
105 | |||
106 | if request.method=='GET': |
|
106 | if request.method=='GET': | |
107 | form = LocationForm(instance=location) |
|
107 | form = LocationForm(instance=location) | |
108 |
|
108 | |||
109 | if request.method=='POST': |
|
109 | if request.method=='POST': | |
110 | form = LocationForm(request.POST, instance=location) |
|
110 | form = LocationForm(request.POST, instance=location) | |
111 |
|
111 | |||
112 | if form.is_valid(): |
|
112 | if form.is_valid(): | |
113 | form.save() |
|
113 | form.save() | |
114 | return redirect('url_locations') |
|
114 | return redirect('url_locations') | |
115 |
|
115 | |||
116 | kwargs = {} |
|
116 | kwargs = {} | |
117 | kwargs['form'] = form |
|
117 | kwargs['form'] = form | |
118 | kwargs['title'] = 'Location' |
|
118 | kwargs['title'] = 'Location' | |
119 | kwargs['suptitle'] = 'Edit' |
|
119 | kwargs['suptitle'] = 'Edit' | |
120 | kwargs['button'] = 'Update' |
|
120 | kwargs['button'] = 'Update' | |
121 |
|
121 | |||
122 | return render(request, 'location_edit.html', kwargs) |
|
122 | return render(request, 'location_edit.html', kwargs) | |
123 |
|
123 | |||
124 |
|
124 | |||
125 | def location_delete(request, id_loc): |
|
125 | def location_delete(request, id_loc): | |
126 |
|
126 | |||
127 | location = get_object_or_404(Location, pk=id_loc) |
|
127 | location = get_object_or_404(Location, pk=id_loc) | |
128 |
|
128 | |||
129 | if request.method=='POST': |
|
129 | if request.method=='POST': | |
130 |
|
130 | |||
131 | if request.user.is_staff: |
|
131 | if request.user.is_staff: | |
132 | location.delete() |
|
132 | location.delete() | |
133 | return redirect('url_locations') |
|
133 | return redirect('url_locations') | |
134 |
|
134 | |||
135 | messages.error(request, 'Not enough permission to delete this object') |
|
135 | messages.error(request, 'Not enough permission to delete this object') | |
136 | return redirect(location.get_absolute_url()) |
|
136 | return redirect(location.get_absolute_url()) | |
137 |
|
137 | |||
138 | kwargs = { |
|
138 | kwargs = { | |
139 | 'title': 'Delete', |
|
139 | 'title': 'Delete', | |
140 | 'suptitle': 'Location', |
|
140 | 'suptitle': 'Location', | |
141 | 'object': location, |
|
141 | 'object': location, | |
142 | 'previous': location.get_absolute_url(), |
|
142 | 'previous': location.get_absolute_url(), | |
143 | 'delete': True |
|
143 | 'delete': True | |
144 | } |
|
144 | } | |
145 |
|
145 | |||
146 | return render(request, 'confirm.html', kwargs) |
|
146 | return render(request, 'confirm.html', kwargs) | |
147 |
|
147 | |||
148 |
|
148 | |||
149 | def devices(request): |
|
149 | def devices(request): | |
150 |
|
150 | |||
151 | devices = Device.objects.all().order_by('device_type__name') |
|
151 | devices = Device.objects.all().order_by('device_type__name') | |
152 |
|
152 | |||
153 | # keys = ['id', 'device_type__name', 'name', 'ip_address'] |
|
153 | # keys = ['id', 'device_type__name', 'name', 'ip_address'] | |
154 | keys = ['id', 'name', 'ip_address', 'port_address', 'device_type'] |
|
154 | keys = ['id', 'name', 'ip_address', 'port_address', 'device_type'] | |
155 |
|
155 | |||
156 | kwargs = {} |
|
156 | kwargs = {} | |
157 | kwargs['device_keys'] = keys[1:] |
|
157 | kwargs['device_keys'] = keys[1:] | |
158 | kwargs['devices'] = devices#.values(*keys) |
|
158 | kwargs['devices'] = devices#.values(*keys) | |
159 | kwargs['title'] = 'Device' |
|
159 | kwargs['title'] = 'Device' | |
160 | kwargs['suptitle'] = 'List' |
|
160 | kwargs['suptitle'] = 'List' | |
161 | kwargs['button'] = 'New Device' |
|
161 | kwargs['button'] = 'New Device' | |
162 |
|
162 | |||
163 | return render(request, 'devices.html', kwargs) |
|
163 | return render(request, 'devices.html', kwargs) | |
164 |
|
164 | |||
165 |
|
165 | |||
166 | def device(request, id_dev): |
|
166 | def device(request, id_dev): | |
167 |
|
167 | |||
168 | device = get_object_or_404(Device, pk=id_dev) |
|
168 | device = get_object_or_404(Device, pk=id_dev) | |
169 |
|
169 | |||
170 | kwargs = {} |
|
170 | kwargs = {} | |
171 | kwargs['device'] = device |
|
171 | kwargs['device'] = device | |
172 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] |
|
172 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] | |
173 |
|
173 | |||
174 | kwargs['title'] = 'Device' |
|
174 | kwargs['title'] = 'Device' | |
175 | kwargs['suptitle'] = 'Details' |
|
175 | kwargs['suptitle'] = 'Details' | |
176 |
|
176 | |||
177 | return render(request, 'device.html', kwargs) |
|
177 | return render(request, 'device.html', kwargs) | |
178 |
|
178 | |||
179 |
|
179 | |||
180 | def device_new(request): |
|
180 | def device_new(request): | |
181 |
|
181 | |||
182 | if request.method == 'GET': |
|
182 | if request.method == 'GET': | |
183 | form = DeviceForm() |
|
183 | form = DeviceForm() | |
184 |
|
184 | |||
185 | if request.method == 'POST': |
|
185 | if request.method == 'POST': | |
186 | form = DeviceForm(request.POST) |
|
186 | form = DeviceForm(request.POST) | |
187 |
|
187 | |||
188 | if form.is_valid(): |
|
188 | if form.is_valid(): | |
189 | form.save() |
|
189 | form.save() | |
190 | return redirect('url_devices') |
|
190 | return redirect('url_devices') | |
191 |
|
191 | |||
192 | kwargs = {} |
|
192 | kwargs = {} | |
193 | kwargs['form'] = form |
|
193 | kwargs['form'] = form | |
194 | kwargs['title'] = 'Device' |
|
194 | kwargs['title'] = 'Device' | |
195 | kwargs['suptitle'] = 'New' |
|
195 | kwargs['suptitle'] = 'New' | |
196 | kwargs['button'] = 'Create' |
|
196 | kwargs['button'] = 'Create' | |
197 |
|
197 | |||
198 | return render(request, 'device_edit.html', kwargs) |
|
198 | return render(request, 'device_edit.html', kwargs) | |
199 |
|
199 | |||
200 |
|
200 | |||
201 | def device_edit(request, id_dev): |
|
201 | def device_edit(request, id_dev): | |
202 |
|
202 | |||
203 | device = get_object_or_404(Device, pk=id_dev) |
|
203 | device = get_object_or_404(Device, pk=id_dev) | |
204 |
|
204 | |||
205 | if request.method=='GET': |
|
205 | if request.method=='GET': | |
206 | form = DeviceForm(instance=device) |
|
206 | form = DeviceForm(instance=device) | |
207 |
|
207 | |||
208 | if request.method=='POST': |
|
208 | if request.method=='POST': | |
209 | form = DeviceForm(request.POST, instance=device) |
|
209 | form = DeviceForm(request.POST, instance=device) | |
210 |
|
210 | |||
211 | if form.is_valid(): |
|
211 | if form.is_valid(): | |
212 | form.save() |
|
212 | form.save() | |
213 | return redirect(device.get_absolute_url()) |
|
213 | return redirect(device.get_absolute_url()) | |
214 |
|
214 | |||
215 | kwargs = {} |
|
215 | kwargs = {} | |
216 | kwargs['form'] = form |
|
216 | kwargs['form'] = form | |
217 | kwargs['title'] = 'Device' |
|
217 | kwargs['title'] = 'Device' | |
218 | kwargs['suptitle'] = 'Edit' |
|
218 | kwargs['suptitle'] = 'Edit' | |
219 | kwargs['button'] = 'Update' |
|
219 | kwargs['button'] = 'Update' | |
220 |
|
220 | |||
221 | return render(request, 'device_edit.html', kwargs) |
|
221 | return render(request, 'device_edit.html', kwargs) | |
222 |
|
222 | |||
223 |
|
223 | |||
224 | def device_delete(request, id_dev): |
|
224 | def device_delete(request, id_dev): | |
225 |
|
225 | |||
226 | device = get_object_or_404(Device, pk=id_dev) |
|
226 | device = get_object_or_404(Device, pk=id_dev) | |
227 |
|
227 | |||
228 | if request.method=='POST': |
|
228 | if request.method=='POST': | |
229 |
|
229 | |||
230 | if request.user.is_staff: |
|
230 | if request.user.is_staff: | |
231 | device.delete() |
|
231 | device.delete() | |
232 | return redirect('url_devices') |
|
232 | return redirect('url_devices') | |
233 |
|
233 | |||
234 | messages.error(request, 'Not enough permission to delete this object') |
|
234 | messages.error(request, 'Not enough permission to delete this object') | |
235 | return redirect(device.get_absolute_url()) |
|
235 | return redirect(device.get_absolute_url()) | |
236 |
|
236 | |||
237 | kwargs = { |
|
237 | kwargs = { | |
238 | 'title': 'Delete', |
|
238 | 'title': 'Delete', | |
239 | 'suptitle': 'Device', |
|
239 | 'suptitle': 'Device', | |
240 | 'object': device, |
|
240 | 'object': device, | |
241 | 'previous': device.get_absolute_url(), |
|
241 | 'previous': device.get_absolute_url(), | |
242 | 'delete': True |
|
242 | 'delete': True | |
243 | } |
|
243 | } | |
244 |
|
244 | |||
245 | return render(request, 'confirm.html', kwargs) |
|
245 | return render(request, 'confirm.html', kwargs) | |
246 |
|
246 | |||
247 |
|
247 | |||
248 | def campaigns(request): |
|
248 | def campaigns(request): | |
249 |
|
249 | |||
250 | campaigns = Campaign.objects.all().order_by('start_date') |
|
250 | campaigns = Campaign.objects.all().order_by('start_date') | |
251 |
|
251 | |||
252 | keys = ['id', 'name', 'start_date', 'end_date'] |
|
252 | keys = ['id', 'name', 'start_date', 'end_date'] | |
253 |
|
253 | |||
254 | kwargs = {} |
|
254 | kwargs = {} | |
255 | kwargs['campaign_keys'] = keys[1:] |
|
255 | kwargs['campaign_keys'] = keys[1:] | |
256 | kwargs['campaigns'] = campaigns#.values(*keys) |
|
256 | kwargs['campaigns'] = campaigns#.values(*keys) | |
257 | kwargs['title'] = 'Campaign' |
|
257 | kwargs['title'] = 'Campaign' | |
258 | kwargs['suptitle'] = 'List' |
|
258 | kwargs['suptitle'] = 'List' | |
259 | kwargs['button'] = 'New Campaign' |
|
259 | kwargs['button'] = 'New Campaign' | |
260 |
|
260 | |||
261 | return render(request, 'campaigns.html', kwargs) |
|
261 | return render(request, 'campaigns.html', kwargs) | |
262 |
|
262 | |||
263 |
|
263 | |||
264 | def campaign(request, id_camp): |
|
264 | def campaign(request, id_camp): | |
265 |
|
265 | |||
266 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
266 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
267 | experiments = Experiment.objects.filter(campaign=campaign) |
|
267 | experiments = Experiment.objects.filter(campaign=campaign) | |
268 |
|
268 | |||
269 | form = CampaignForm(instance=campaign) |
|
269 | form = CampaignForm(instance=campaign) | |
270 |
|
270 | |||
271 | kwargs = {} |
|
271 | kwargs = {} | |
272 | kwargs['campaign'] = campaign |
|
272 | kwargs['campaign'] = campaign | |
273 | kwargs['campaign_keys'] = ['template', 'name', 'start_date', 'end_date', 'tags', 'description'] |
|
273 | kwargs['campaign_keys'] = ['template', 'name', 'start_date', 'end_date', 'tags', 'description'] | |
274 |
|
274 | |||
275 | kwargs['experiments'] = experiments |
|
275 | kwargs['experiments'] = experiments | |
276 | kwargs['experiment_keys'] = ['name', 'radar', 'start_time', 'end_time'] |
|
276 | kwargs['experiment_keys'] = ['name', 'radar', 'start_time', 'end_time'] | |
277 |
|
277 | |||
278 | kwargs['title'] = 'Campaign' |
|
278 | kwargs['title'] = 'Campaign' | |
279 | kwargs['suptitle'] = 'Details' |
|
279 | kwargs['suptitle'] = 'Details' | |
280 |
|
280 | |||
281 | kwargs['form'] = form |
|
281 | kwargs['form'] = form | |
282 | kwargs['button'] = 'Add Experiment' |
|
282 | kwargs['button'] = 'Add Experiment' | |
283 |
|
283 | |||
284 | return render(request, 'campaign.html', kwargs) |
|
284 | return render(request, 'campaign.html', kwargs) | |
285 |
|
285 | |||
286 |
|
286 | |||
287 | def campaign_new(request): |
|
287 | def campaign_new(request): | |
288 |
|
288 | |||
289 | kwargs = {} |
|
289 | kwargs = {} | |
290 |
|
290 | |||
291 | if request.method == 'GET': |
|
291 | if request.method == 'GET': | |
292 |
|
292 | |||
293 | if 'template' in request.GET: |
|
293 | if 'template' in request.GET: | |
294 | if request.GET['template']=='0': |
|
294 | if request.GET['template']=='0': | |
295 | form = NewForm(initial={'create_from':2}, |
|
295 | form = NewForm(initial={'create_from':2}, | |
296 | template_choices=Campaign.objects.filter(template=True).values_list('id', 'name')) |
|
296 | template_choices=Campaign.objects.filter(template=True).values_list('id', 'name')) | |
297 | else: |
|
297 | else: | |
298 | kwargs['button'] = 'Create' |
|
298 | kwargs['button'] = 'Create' | |
299 | kwargs['experiments'] = Configuration.objects.filter(experiment=request.GET['template']) |
|
299 | kwargs['experiments'] = Configuration.objects.filter(experiment=request.GET['template']) | |
300 | kwargs['experiment_keys'] = ['name', 'start_time', 'end_time'] |
|
300 | kwargs['experiment_keys'] = ['name', 'start_time', 'end_time'] | |
301 | camp = Campaign.objects.get(pk=request.GET['template']) |
|
301 | camp = Campaign.objects.get(pk=request.GET['template']) | |
302 | form = CampaignForm(instance=camp, |
|
302 | form = CampaignForm(instance=camp, | |
303 | initial={'name':'{} [{:%Y/%m/%d}]'.format(camp.name, datetime.now()), |
|
303 | initial={'name':'{} [{:%Y/%m/%d}]'.format(camp.name, datetime.now()), | |
304 | 'template':False}) |
|
304 | 'template':False}) | |
305 | elif 'blank' in request.GET: |
|
305 | elif 'blank' in request.GET: | |
306 | kwargs['button'] = 'Create' |
|
306 | kwargs['button'] = 'Create' | |
307 | form = CampaignForm() |
|
307 | form = CampaignForm() | |
308 | else: |
|
308 | else: | |
309 | form = NewForm() |
|
309 | form = NewForm() | |
310 |
|
310 | |||
311 | if request.method == 'POST': |
|
311 | if request.method == 'POST': | |
312 | kwargs['button'] = 'Create' |
|
312 | kwargs['button'] = 'Create' | |
313 | post = request.POST.copy() |
|
313 | post = request.POST.copy() | |
314 | experiments = [] |
|
314 | experiments = [] | |
315 |
|
315 | |||
316 | for id_exp in post.getlist('experiments'): |
|
316 | for id_exp in post.getlist('experiments'): | |
317 | exp = Experiment.objects.get(pk=id_exp) |
|
317 | exp = Experiment.objects.get(pk=id_exp) | |
318 | new_exp = exp.clone(template=False) |
|
318 | new_exp = exp.clone(template=False) | |
319 | experiments.append(new_exp) |
|
319 | experiments.append(new_exp) | |
320 |
|
320 | |||
321 | post.setlist('experiments', []) |
|
321 | post.setlist('experiments', []) | |
322 |
|
322 | |||
323 | form = CampaignForm(post) |
|
323 | form = CampaignForm(post) | |
324 |
|
324 | |||
325 | if form.is_valid(): |
|
325 | if form.is_valid(): | |
326 | campaign = form.save() |
|
326 | campaign = form.save() | |
327 | for exp in experiments: |
|
327 | for exp in experiments: | |
328 | campaign.experiments.add(exp) |
|
328 | campaign.experiments.add(exp) | |
329 | campaign.save() |
|
329 | campaign.save() | |
330 | return redirect('url_campaign', id_camp=campaign.id) |
|
330 | return redirect('url_campaign', id_camp=campaign.id) | |
331 |
|
331 | |||
332 | kwargs['form'] = form |
|
332 | kwargs['form'] = form | |
333 | kwargs['title'] = 'Campaign' |
|
333 | kwargs['title'] = 'Campaign' | |
334 | kwargs['suptitle'] = 'New' |
|
334 | kwargs['suptitle'] = 'New' | |
335 |
|
335 | |||
336 | return render(request, 'campaign_edit.html', kwargs) |
|
336 | return render(request, 'campaign_edit.html', kwargs) | |
337 |
|
337 | |||
338 |
|
338 | |||
339 | def campaign_edit(request, id_camp): |
|
339 | def campaign_edit(request, id_camp): | |
340 |
|
340 | |||
341 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
341 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
342 |
|
342 | |||
343 | if request.method=='GET': |
|
343 | if request.method=='GET': | |
344 | form = CampaignForm(instance=campaign) |
|
344 | form = CampaignForm(instance=campaign) | |
345 |
|
345 | |||
346 | if request.method=='POST': |
|
346 | if request.method=='POST': | |
347 | exps = campaign.experiments.all().values_list('pk', flat=True) |
|
347 | exps = campaign.experiments.all().values_list('pk', flat=True) | |
348 | post = request.POST.copy() |
|
348 | post = request.POST.copy() | |
349 | new_exps = post.getlist('experiments') |
|
349 | new_exps = post.getlist('experiments') | |
350 | post.setlist('experiments', []) |
|
350 | post.setlist('experiments', []) | |
351 | form = CampaignForm(post, instance=campaign) |
|
351 | form = CampaignForm(post, instance=campaign) | |
352 |
|
352 | |||
353 | if form.is_valid(): |
|
353 | if form.is_valid(): | |
354 | camp = form.save() |
|
354 | camp = form.save() | |
355 | for id_exp in new_exps: |
|
355 | for id_exp in new_exps: | |
356 | if int(id_exp) in exps: |
|
356 | if int(id_exp) in exps: | |
357 | exps.pop(id_exp) |
|
357 | exps.pop(id_exp) | |
358 | else: |
|
358 | else: | |
359 | exp = Experiment.objects.get(pk=id_exp) |
|
359 | exp = Experiment.objects.get(pk=id_exp) | |
360 | if exp.template: |
|
360 | if exp.template: | |
361 | camp.experiments.add(exp.clone(template=False)) |
|
361 | camp.experiments.add(exp.clone(template=False)) | |
362 | else: |
|
362 | else: | |
363 | camp.experiments.add(exp) |
|
363 | camp.experiments.add(exp) | |
364 |
|
364 | |||
365 | for id_exp in exps: |
|
365 | for id_exp in exps: | |
366 | camp.experiments.remove(Experiment.objects.get(pk=id_exp)) |
|
366 | camp.experiments.remove(Experiment.objects.get(pk=id_exp)) | |
367 |
|
367 | |||
368 | return redirect('url_campaign', id_camp=id_camp) |
|
368 | return redirect('url_campaign', id_camp=id_camp) | |
369 |
|
369 | |||
370 | kwargs = {} |
|
370 | kwargs = {} | |
371 | kwargs['form'] = form |
|
371 | kwargs['form'] = form | |
372 | kwargs['title'] = 'Campaign' |
|
372 | kwargs['title'] = 'Campaign' | |
373 | kwargs['suptitle'] = 'Edit' |
|
373 | kwargs['suptitle'] = 'Edit' | |
374 | kwargs['button'] = 'Update' |
|
374 | kwargs['button'] = 'Update' | |
375 |
|
375 | |||
376 | return render(request, 'campaign_edit.html', kwargs) |
|
376 | return render(request, 'campaign_edit.html', kwargs) | |
377 |
|
377 | |||
378 |
|
378 | |||
379 | def campaign_delete(request, id_camp): |
|
379 | def campaign_delete(request, id_camp): | |
380 |
|
380 | |||
381 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
381 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
382 |
|
382 | |||
383 | if request.method=='POST': |
|
383 | if request.method=='POST': | |
384 | if request.user.is_staff: |
|
384 | if request.user.is_staff: | |
385 |
|
385 | |||
386 | for exp in campaign.experiments.all(): |
|
386 | for exp in campaign.experiments.all(): | |
387 | for conf in Configuration.objects.filter(experiment=exp): |
|
387 | for conf in Configuration.objects.filter(experiment=exp): | |
388 | conf.delete() |
|
388 | conf.delete() | |
389 | exp.delete() |
|
389 | exp.delete() | |
390 | campaign.delete() |
|
390 | campaign.delete() | |
391 |
|
391 | |||
392 | return redirect('url_campaigns') |
|
392 | return redirect('url_campaigns') | |
393 |
|
393 | |||
394 | messages.error(request, 'Not enough permission to delete this object') |
|
394 | messages.error(request, 'Not enough permission to delete this object') | |
395 | return redirect(campaign.get_absolute_url()) |
|
395 | return redirect(campaign.get_absolute_url()) | |
396 |
|
396 | |||
397 | kwargs = { |
|
397 | kwargs = { | |
398 | 'title': 'Delete', |
|
398 | 'title': 'Delete', | |
399 | 'suptitle': 'Campaign', |
|
399 | 'suptitle': 'Campaign', | |
400 | 'object': campaign, |
|
400 | 'object': campaign, | |
401 | 'previous': campaign.get_absolute_url(), |
|
401 | 'previous': campaign.get_absolute_url(), | |
402 | 'delete': True |
|
402 | 'delete': True | |
403 | } |
|
403 | } | |
404 |
|
404 | |||
405 | return render(request, 'confirm.html', kwargs) |
|
405 | return render(request, 'confirm.html', kwargs) | |
406 |
|
406 | |||
|
407 | def campaign_export(request, id_camp): | |||
|
408 | ||||
|
409 | campaign = get_object_or_404(Campaign, pk=id_camp) | |||
|
410 | content = campaign.parms_to_dict() | |||
|
411 | content_type = 'application/json' | |||
|
412 | filename = '%s_%s.json' %(campaign.name, campaign.id) | |||
|
413 | ||||
|
414 | response = HttpResponse(content_type=content_type) | |||
|
415 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename | |||
|
416 | response.write(content) | |||
|
417 | ||||
|
418 | return response | |||
407 |
|
419 | |||
408 | def experiments(request): |
|
420 | def experiments(request): | |
409 |
|
421 | |||
410 | experiment_list = Experiment.objects.all() |
|
422 | experiment_list = Experiment.objects.all() | |
411 |
|
423 | |||
412 | keys = ['id', 'name', 'start_time', 'end_time'] |
|
424 | keys = ['id', 'name', 'start_time', 'end_time'] | |
413 |
|
425 | |||
414 | kwargs = {} |
|
426 | kwargs = {} | |
415 |
|
427 | |||
416 | kwargs['experiment_keys'] = keys[1:] |
|
428 | kwargs['experiment_keys'] = keys[1:] | |
417 | kwargs['experiments'] = experiment_list |
|
429 | kwargs['experiments'] = experiment_list | |
418 |
|
430 | |||
419 | kwargs['title'] = 'Experiment' |
|
431 | kwargs['title'] = 'Experiment' | |
420 | kwargs['suptitle'] = 'List' |
|
432 | kwargs['suptitle'] = 'List' | |
421 | kwargs['button'] = 'New Experiment' |
|
433 | kwargs['button'] = 'New Experiment' | |
422 |
|
434 | |||
423 | return render(request, 'experiments.html', kwargs) |
|
435 | return render(request, 'experiments.html', kwargs) | |
424 |
|
436 | |||
425 |
|
437 | |||
426 | def experiment(request, id_exp): |
|
438 | def experiment(request, id_exp): | |
427 |
|
439 | |||
428 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
440 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
429 |
|
441 | |||
430 | configurations = Configuration.objects.filter(experiment=experiment, type=0) |
|
442 | configurations = Configuration.objects.filter(experiment=experiment, type=0) | |
431 |
|
443 | |||
432 | kwargs = {} |
|
444 | kwargs = {} | |
433 |
|
445 | |||
434 | kwargs['experiment_keys'] = ['template', 'radar', 'name', 'start_time', 'end_time'] |
|
446 | kwargs['experiment_keys'] = ['template', 'radar', 'name', 'start_time', 'end_time'] | |
435 | kwargs['experiment'] = experiment |
|
447 | kwargs['experiment'] = experiment | |
436 |
|
448 | |||
437 | kwargs['configuration_keys'] = ['device__name', 'device__device_type', 'device__ip_address', 'device__port_address'] |
|
449 | kwargs['configuration_keys'] = ['device__name', 'device__device_type', 'device__ip_address', 'device__port_address'] | |
438 | kwargs['configurations'] = configurations |
|
450 | kwargs['configurations'] = configurations | |
439 |
|
451 | |||
440 | kwargs['title'] = 'Experiment' |
|
452 | kwargs['title'] = 'Experiment' | |
441 | kwargs['suptitle'] = 'Details' |
|
453 | kwargs['suptitle'] = 'Details' | |
442 |
|
454 | |||
443 | kwargs['button'] = 'Add Configuration' |
|
455 | kwargs['button'] = 'Add Configuration' | |
444 |
|
456 | |||
445 | ###### SIDEBAR ###### |
|
457 | ###### SIDEBAR ###### | |
446 | kwargs.update(sidebar(experiment=experiment)) |
|
458 | kwargs.update(sidebar(experiment=experiment)) | |
447 |
|
459 | |||
448 | return render(request, 'experiment.html', kwargs) |
|
460 | return render(request, 'experiment.html', kwargs) | |
449 |
|
461 | |||
450 |
|
462 | |||
451 | def experiment_new(request, id_camp=None): |
|
463 | def experiment_new(request, id_camp=None): | |
452 |
|
464 | |||
453 | kwargs = {} |
|
465 | kwargs = {} | |
454 |
|
466 | |||
455 | if request.method == 'GET': |
|
467 | if request.method == 'GET': | |
456 | if 'template' in request.GET: |
|
468 | if 'template' in request.GET: | |
457 | if request.GET['template']=='0': |
|
469 | if request.GET['template']=='0': | |
458 | form = NewForm(initial={'create_from':2}, |
|
470 | form = NewForm(initial={'create_from':2}, | |
459 | template_choices=Experiment.objects.filter(template=True).values_list('id', 'name')) |
|
471 | template_choices=Experiment.objects.filter(template=True).values_list('id', 'name')) | |
460 | else: |
|
472 | else: | |
461 | kwargs['button'] = 'Create' |
|
473 | kwargs['button'] = 'Create' | |
462 | kwargs['configurations'] = Configuration.objects.filter(experiment=request.GET['template']) |
|
474 | kwargs['configurations'] = Configuration.objects.filter(experiment=request.GET['template']) | |
463 | kwargs['configuration_keys'] = ['name', 'device__name', 'device__ip_address', 'device__port_address'] |
|
475 | kwargs['configuration_keys'] = ['name', 'device__name', 'device__ip_address', 'device__port_address'] | |
464 | exp=Experiment.objects.get(pk=request.GET['template']) |
|
476 | exp=Experiment.objects.get(pk=request.GET['template']) | |
465 | form = ExperimentForm(instance=exp, |
|
477 | form = ExperimentForm(instance=exp, | |
466 | initial={'name': '{} [{:%Y/%m/%d}]'.format(exp.name, datetime.now()), |
|
478 | initial={'name': '{} [{:%Y/%m/%d}]'.format(exp.name, datetime.now()), | |
467 | 'template': False}) |
|
479 | 'template': False}) | |
468 | elif 'blank' in request.GET: |
|
480 | elif 'blank' in request.GET: | |
469 | kwargs['button'] = 'Create' |
|
481 | kwargs['button'] = 'Create' | |
470 | form = ExperimentForm() |
|
482 | form = ExperimentForm() | |
471 | else: |
|
483 | else: | |
472 | form = NewForm() |
|
484 | form = NewForm() | |
473 |
|
485 | |||
474 | if request.method == 'POST': |
|
486 | if request.method == 'POST': | |
475 | form = ExperimentForm(request.POST) |
|
487 | form = ExperimentForm(request.POST) | |
476 | if form.is_valid(): |
|
488 | if form.is_valid(): | |
477 | experiment = form.save() |
|
489 | experiment = form.save() | |
478 |
|
490 | |||
479 | if 'template' in request.GET: |
|
491 | if 'template' in request.GET: | |
480 | configurations = Configuration.objects.filter(experiment=request.GET['template'], type=0) |
|
492 | configurations = Configuration.objects.filter(experiment=request.GET['template'], type=0) | |
481 | for conf in configurations: |
|
493 | for conf in configurations: | |
482 | conf.clone(experiment=experiment, template=False) |
|
494 | conf.clone(experiment=experiment, template=False) | |
483 |
|
495 | |||
484 | return redirect('url_experiment', id_exp=experiment.id) |
|
496 | return redirect('url_experiment', id_exp=experiment.id) | |
485 |
|
497 | |||
486 | kwargs['form'] = form |
|
498 | kwargs['form'] = form | |
487 | kwargs['title'] = 'Experiment' |
|
499 | kwargs['title'] = 'Experiment' | |
488 | kwargs['suptitle'] = 'New' |
|
500 | kwargs['suptitle'] = 'New' | |
489 |
|
501 | |||
490 | return render(request, 'experiment_edit.html', kwargs) |
|
502 | return render(request, 'experiment_edit.html', kwargs) | |
491 |
|
503 | |||
492 |
|
504 | |||
493 | def experiment_edit(request, id_exp): |
|
505 | def experiment_edit(request, id_exp): | |
494 |
|
506 | |||
495 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
507 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
496 |
|
508 | |||
497 | if request.method == 'GET': |
|
509 | if request.method == 'GET': | |
498 | form = ExperimentForm(instance=experiment) |
|
510 | form = ExperimentForm(instance=experiment) | |
499 |
|
511 | |||
500 | if request.method=='POST': |
|
512 | if request.method=='POST': | |
501 | form = ExperimentForm(request.POST, instance=experiment) |
|
513 | form = ExperimentForm(request.POST, instance=experiment) | |
502 |
|
514 | |||
503 | if form.is_valid(): |
|
515 | if form.is_valid(): | |
504 | experiment = form.save() |
|
516 | experiment = form.save() | |
505 | return redirect('url_experiment', id_exp=experiment.id) |
|
517 | return redirect('url_experiment', id_exp=experiment.id) | |
506 |
|
518 | |||
507 | kwargs = {} |
|
519 | kwargs = {} | |
508 | kwargs['form'] = form |
|
520 | kwargs['form'] = form | |
509 | kwargs['title'] = 'Experiment' |
|
521 | kwargs['title'] = 'Experiment' | |
510 | kwargs['suptitle'] = 'Edit' |
|
522 | kwargs['suptitle'] = 'Edit' | |
511 | kwargs['button'] = 'Update' |
|
523 | kwargs['button'] = 'Update' | |
512 |
|
524 | |||
513 | return render(request, 'experiment_edit.html', kwargs) |
|
525 | return render(request, 'experiment_edit.html', kwargs) | |
514 |
|
526 | |||
515 |
|
527 | |||
516 | def experiment_delete(request, id_exp): |
|
528 | def experiment_delete(request, id_exp): | |
517 |
|
529 | |||
518 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
530 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
519 |
|
531 | |||
520 | if request.method=='POST': |
|
532 | if request.method=='POST': | |
521 | if request.user.is_staff: |
|
533 | if request.user.is_staff: | |
522 | for conf in Configuration.objects.filter(experiment=experiment): |
|
534 | for conf in Configuration.objects.filter(experiment=experiment): | |
523 | conf.delete() |
|
535 | conf.delete() | |
524 | experiment.delete() |
|
536 | experiment.delete() | |
525 | return redirect('url_experiments') |
|
537 | return redirect('url_experiments') | |
526 |
|
538 | |||
527 | messages.error(request, 'Not enough permission to delete this object') |
|
539 | messages.error(request, 'Not enough permission to delete this object') | |
528 | return redirect(experiment.get_absolute_url()) |
|
540 | return redirect(experiment.get_absolute_url()) | |
529 |
|
541 | |||
530 | kwargs = { |
|
542 | kwargs = { | |
531 | 'title': 'Delete', |
|
543 | 'title': 'Delete', | |
532 | 'suptitle': 'Experiment', |
|
544 | 'suptitle': 'Experiment', | |
533 | 'object': experiment, |
|
545 | 'object': experiment, | |
534 | 'previous': experiment.get_absolute_url(), |
|
546 | 'previous': experiment.get_absolute_url(), | |
535 | 'delete': True |
|
547 | 'delete': True | |
536 | } |
|
548 | } | |
537 |
|
549 | |||
538 | return render(request, 'confirm.html', kwargs) |
|
550 | return render(request, 'confirm.html', kwargs) | |
539 |
|
551 | |||
540 |
|
552 | |||
|
553 | def experiment_export(request, id_exp): | |||
|
554 | ||||
|
555 | experiment = get_object_or_404(Experiment, pk=id_exp) | |||
|
556 | content = experiment.parms_to_dict() | |||
|
557 | content_type = 'application/json' | |||
|
558 | filename = '%s_%s.json' %(experiment.name, experiment.id) | |||
|
559 | ||||
|
560 | response = HttpResponse(content_type=content_type) | |||
|
561 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename | |||
|
562 | response.write(content) | |||
|
563 | ||||
|
564 | return response | |||
|
565 | ||||
|
566 | ||||
541 | def dev_confs(request): |
|
567 | def dev_confs(request): | |
542 |
|
568 | |||
543 | configurations = Configuration.objects.all().order_by('type', 'device__device_type', 'experiment') |
|
569 | configurations = Configuration.objects.all().order_by('type', 'device__device_type', 'experiment') | |
544 |
|
570 | |||
545 | kwargs = {} |
|
571 | kwargs = {} | |
546 |
|
572 | |||
547 | kwargs['configuration_keys'] = ['device', 'experiment', 'type', 'programmed_date'] |
|
573 | kwargs['configuration_keys'] = ['device', 'experiment', 'type', 'programmed_date'] | |
548 | kwargs['configurations'] = configurations |
|
574 | kwargs['configurations'] = configurations | |
549 |
|
575 | |||
550 | kwargs['title'] = 'Configuration' |
|
576 | kwargs['title'] = 'Configuration' | |
551 | kwargs['suptitle'] = 'List' |
|
577 | kwargs['suptitle'] = 'List' | |
552 |
|
578 | |||
553 | return render(request, 'dev_confs.html', kwargs) |
|
579 | return render(request, 'dev_confs.html', kwargs) | |
554 |
|
580 | |||
555 |
|
581 | |||
556 | def dev_conf(request, id_conf): |
|
582 | def dev_conf(request, id_conf): | |
557 |
|
583 | |||
558 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
584 | conf = get_object_or_404(Configuration, pk=id_conf) | |
559 |
|
585 | |||
560 | return redirect(conf.get_absolute_url()) |
|
586 | return redirect(conf.get_absolute_url()) | |
561 |
|
587 | |||
562 |
|
588 | |||
563 | def dev_conf_new(request, id_exp=0, id_dev=0): |
|
589 | def dev_conf_new(request, id_exp=0, id_dev=0): | |
564 |
|
590 | |||
565 | initial = {} |
|
591 | initial = {} | |
566 |
|
592 | |||
567 | if id_exp<>0: |
|
593 | if id_exp<>0: | |
568 | initial['experiment'] = id_exp |
|
594 | initial['experiment'] = id_exp | |
569 |
|
595 | |||
570 | if id_dev<>0: |
|
596 | if id_dev<>0: | |
571 | initial['device'] = id_dev |
|
597 | initial['device'] = id_dev | |
572 |
|
598 | |||
573 | if request.method == 'GET': |
|
599 | if request.method == 'GET': | |
574 | if id_dev==0: |
|
600 | if id_dev==0: | |
575 | form = ConfigurationForm(initial=initial) |
|
601 | form = ConfigurationForm(initial=initial) | |
576 | else: |
|
602 | else: | |
577 | device = Device.objects.get(pk=id_dev) |
|
603 | device = Device.objects.get(pk=id_dev) | |
578 | DevConfForm = CONF_FORMS[device.device_type.name] |
|
604 | DevConfForm = CONF_FORMS[device.device_type.name] | |
579 |
|
605 | |||
580 | form = DevConfForm(initial=initial) |
|
606 | form = DevConfForm(initial=initial) | |
581 |
|
607 | |||
582 | if request.method == 'POST': |
|
608 | if request.method == 'POST': | |
583 |
|
609 | |||
584 | device = Device.objects.get(pk=request.POST['device']) |
|
610 | device = Device.objects.get(pk=request.POST['device']) | |
585 | DevConfForm = CONF_FORMS[device.device_type.name] |
|
611 | DevConfForm = CONF_FORMS[device.device_type.name] | |
586 |
|
612 | |||
587 | form = DevConfForm(request.POST) |
|
613 | form = DevConfForm(request.POST) | |
588 |
|
614 | |||
589 | if form.is_valid(): |
|
615 | if form.is_valid(): | |
590 | dev_conf = form.save() |
|
616 | dev_conf = form.save() | |
591 |
|
617 | |||
592 | return redirect('url_dev_confs') |
|
618 | return redirect('url_dev_confs') | |
593 |
|
619 | |||
594 | kwargs = {} |
|
620 | kwargs = {} | |
595 | kwargs['id_exp'] = id_exp |
|
621 | kwargs['id_exp'] = id_exp | |
596 | kwargs['form'] = form |
|
622 | kwargs['form'] = form | |
597 | kwargs['title'] = 'Configuration' |
|
623 | kwargs['title'] = 'Configuration' | |
598 | kwargs['suptitle'] = 'New' |
|
624 | kwargs['suptitle'] = 'New' | |
599 | kwargs['button'] = 'Create' |
|
625 | kwargs['button'] = 'Create' | |
600 |
|
626 | |||
601 | if id_dev != 0: |
|
627 | if id_dev != 0: | |
602 | device = Device.objects.get(pk=id_dev) |
|
628 | device = Device.objects.get(pk=id_dev) | |
603 | if 'dds' in device.device_type.name: |
|
629 | if 'dds' in device.device_type.name: | |
604 | kwargs['dds_device'] = True |
|
630 | kwargs['dds_device'] = True | |
605 |
|
631 | |||
606 | return render(request, 'dev_conf_edit.html', kwargs) |
|
632 | return render(request, 'dev_conf_edit.html', kwargs) | |
607 |
|
633 | |||
608 |
|
634 | |||
609 | def dev_conf_edit(request, id_conf): |
|
635 | def dev_conf_edit(request, id_conf): | |
610 |
|
636 | |||
611 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
637 | conf = get_object_or_404(Configuration, pk=id_conf) | |
612 |
|
638 | |||
613 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
639 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
614 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
640 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
615 |
|
641 | |||
616 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
642 | dev_conf = DevConfModel.objects.get(pk=id_conf) | |
617 |
|
643 | |||
618 | if request.method=='GET': |
|
644 | if request.method=='GET': | |
619 | form = DevConfForm(instance=dev_conf) |
|
645 | form = DevConfForm(instance=dev_conf) | |
620 |
|
646 | |||
621 | if request.method=='POST': |
|
647 | if request.method=='POST': | |
622 | form = DevConfForm(request.POST, instance=dev_conf) |
|
648 | form = DevConfForm(request.POST, instance=dev_conf) | |
623 |
|
649 | |||
624 | if form.is_valid(): |
|
650 | if form.is_valid(): | |
625 | form.save() |
|
651 | form.save() | |
626 | return redirect('url_dev_conf', id_conf=id_conf) |
|
652 | return redirect('url_dev_conf', id_conf=id_conf) | |
627 |
|
653 | |||
628 | kwargs = {} |
|
654 | kwargs = {} | |
629 | kwargs['form'] = form |
|
655 | kwargs['form'] = form | |
630 | kwargs['title'] = 'Device Configuration' |
|
656 | kwargs['title'] = 'Device Configuration' | |
631 | kwargs['suptitle'] = 'Edit' |
|
657 | kwargs['suptitle'] = 'Edit' | |
632 | kwargs['button'] = 'Update' |
|
658 | kwargs['button'] = 'Update' | |
633 |
|
659 | |||
634 | ###### SIDEBAR ###### |
|
660 | ###### SIDEBAR ###### | |
635 | kwargs.update(sidebar(conf=conf)) |
|
661 | kwargs.update(sidebar(conf=conf)) | |
636 |
|
662 | |||
637 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) |
|
663 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) | |
638 |
|
664 | |||
639 |
|
665 | |||
640 | def dev_conf_start(request, id_conf): |
|
666 | def dev_conf_start(request, id_conf): | |
641 |
|
667 | |||
642 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
668 | conf = get_object_or_404(Configuration, pk=id_conf) | |
643 |
|
669 | |||
644 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
670 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
645 |
|
671 | |||
646 | conf = DevConfModel.objects.get(pk=id_conf) |
|
672 | conf = DevConfModel.objects.get(pk=id_conf) | |
647 |
|
673 | |||
648 | if conf.start_device(): |
|
674 | if conf.start_device(): | |
649 | messages.success(request, conf.message) |
|
675 | messages.success(request, conf.message) | |
650 | else: |
|
676 | else: | |
651 | messages.error(request, conf.message) |
|
677 | messages.error(request, conf.message) | |
652 |
|
678 | |||
653 | conf.status_device() |
|
679 | conf.status_device() | |
654 |
|
680 | |||
655 | return redirect(conf.get_absolute_url()) |
|
681 | return redirect(conf.get_absolute_url()) | |
656 |
|
682 | |||
657 |
|
683 | |||
658 | def dev_conf_stop(request, id_conf): |
|
684 | def dev_conf_stop(request, id_conf): | |
659 |
|
685 | |||
660 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
686 | conf = get_object_or_404(Configuration, pk=id_conf) | |
661 |
|
687 | |||
662 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
688 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
663 |
|
689 | |||
664 | conf = DevConfModel.objects.get(pk=id_conf) |
|
690 | conf = DevConfModel.objects.get(pk=id_conf) | |
665 |
|
691 | |||
666 | if conf.stop_device(): |
|
692 | if conf.stop_device(): | |
667 | messages.success(request, conf.message) |
|
693 | messages.success(request, conf.message) | |
668 | else: |
|
694 | else: | |
669 | messages.error(request, conf.message) |
|
695 | messages.error(request, conf.message) | |
670 |
|
696 | |||
671 | conf.status_device() |
|
697 | conf.status_device() | |
672 |
|
698 | |||
673 | return redirect(conf.get_absolute_url()) |
|
699 | return redirect(conf.get_absolute_url()) | |
674 |
|
700 | |||
675 |
|
701 | |||
676 | def dev_conf_status(request, id_conf): |
|
702 | def dev_conf_status(request, id_conf): | |
677 |
|
703 | |||
678 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
704 | conf = get_object_or_404(Configuration, pk=id_conf) | |
679 |
|
705 | |||
680 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
706 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
681 |
|
707 | |||
682 | conf = DevConfModel.objects.get(pk=id_conf) |
|
708 | conf = DevConfModel.objects.get(pk=id_conf) | |
683 |
|
709 | |||
684 | if conf.status_device(): |
|
710 | if conf.status_device(): | |
685 | messages.success(request, conf.message) |
|
711 | messages.success(request, conf.message) | |
686 | else: |
|
712 | else: | |
687 | messages.error(request, conf.message) |
|
713 | messages.error(request, conf.message) | |
688 |
|
714 | |||
689 | return redirect(conf.get_absolute_url()) |
|
715 | return redirect(conf.get_absolute_url()) | |
690 |
|
716 | |||
691 |
|
717 | |||
692 | def dev_conf_write(request, id_conf): |
|
718 | def dev_conf_write(request, id_conf): | |
693 |
|
719 | |||
694 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
720 | conf = get_object_or_404(Configuration, pk=id_conf) | |
695 |
|
721 | |||
696 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
722 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
697 |
|
723 | |||
698 | conf = DevConfModel.objects.get(pk=id_conf) |
|
724 | conf = DevConfModel.objects.get(pk=id_conf) | |
699 |
|
725 | |||
700 | answer = conf.write_device() |
|
726 | answer = conf.write_device() | |
701 | conf.status_device() |
|
727 | conf.status_device() | |
702 |
|
728 | |||
703 | if answer: |
|
729 | if answer: | |
704 | messages.success(request, conf.message) |
|
730 | messages.success(request, conf.message) | |
705 |
|
731 | |||
706 | #Creating a historical configuration |
|
732 | #Creating a historical configuration | |
707 | conf.clone(type=0, template=False) |
|
733 | conf.clone(type=0, template=False) | |
708 |
|
734 | |||
709 | #Original configuration |
|
735 | #Original configuration | |
710 | conf = DevConfModel.objects.get(pk=id_conf) |
|
736 | conf = DevConfModel.objects.get(pk=id_conf) | |
711 | else: |
|
737 | else: | |
712 | messages.error(request, conf.message) |
|
738 | messages.error(request, conf.message) | |
713 |
|
739 | |||
714 | return redirect(conf.get_absolute_url()) |
|
740 | return redirect(conf.get_absolute_url()) | |
715 |
|
741 | |||
716 |
|
742 | |||
717 | def dev_conf_read(request, id_conf): |
|
743 | def dev_conf_read(request, id_conf): | |
718 |
|
744 | |||
719 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
745 | conf = get_object_or_404(Configuration, pk=id_conf) | |
720 |
|
746 | |||
721 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
747 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
722 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
748 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
723 |
|
749 | |||
724 | conf = DevConfModel.objects.get(pk=id_conf) |
|
750 | conf = DevConfModel.objects.get(pk=id_conf) | |
725 |
|
751 | |||
726 | if request.method=='GET': |
|
752 | if request.method=='GET': | |
727 |
|
753 | |||
728 | parms = conf.read_device() |
|
754 | parms = conf.read_device() | |
729 | conf.status_device() |
|
755 | conf.status_device() | |
730 |
|
756 | |||
731 | if not parms: |
|
757 | if not parms: | |
732 | messages.error(request, conf.message) |
|
758 | messages.error(request, conf.message) | |
733 | return redirect(conf.get_absolute_url()) |
|
759 | return redirect(conf.get_absolute_url()) | |
734 |
|
760 | |||
735 | form = DevConfForm(initial=parms, instance=conf) |
|
761 | form = DevConfForm(initial=parms, instance=conf) | |
736 |
|
762 | |||
737 | if request.method=='POST': |
|
763 | if request.method=='POST': | |
738 | form = DevConfForm(request.POST, instance=conf) |
|
764 | form = DevConfForm(request.POST, instance=conf) | |
739 |
|
765 | |||
740 | if form.is_valid(): |
|
766 | if form.is_valid(): | |
741 | form.save() |
|
767 | form.save() | |
742 | return redirect(conf.get_absolute_url()) |
|
768 | return redirect(conf.get_absolute_url()) | |
743 |
|
769 | |||
744 | messages.error(request, "Parameters could not be saved") |
|
770 | messages.error(request, "Parameters could not be saved") | |
745 |
|
771 | |||
746 | kwargs = {} |
|
772 | kwargs = {} | |
747 | kwargs['id_dev'] = conf.id |
|
773 | kwargs['id_dev'] = conf.id | |
748 | kwargs['form'] = form |
|
774 | kwargs['form'] = form | |
749 | kwargs['title'] = 'Device Configuration' |
|
775 | kwargs['title'] = 'Device Configuration' | |
750 | kwargs['suptitle'] = 'Parameters read from device' |
|
776 | kwargs['suptitle'] = 'Parameters read from device' | |
751 | kwargs['button'] = 'Save' |
|
777 | kwargs['button'] = 'Save' | |
752 |
|
778 | |||
753 | ###### SIDEBAR ###### |
|
779 | ###### SIDEBAR ###### | |
754 | kwargs.update(sidebar(conf=conf)) |
|
780 | kwargs.update(sidebar(conf=conf)) | |
755 |
|
781 | |||
756 | return render(request, '%s_conf_edit.html' %conf.device.device_type.name, kwargs) |
|
782 | return render(request, '%s_conf_edit.html' %conf.device.device_type.name, kwargs) | |
757 |
|
783 | |||
758 |
|
784 | |||
759 | def dev_conf_import(request, id_conf): |
|
785 | def dev_conf_import(request, id_conf): | |
760 |
|
786 | |||
761 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
787 | conf = get_object_or_404(Configuration, pk=id_conf) | |
762 |
|
788 | |||
763 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
789 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
764 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
790 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
765 | conf = DevConfModel.objects.get(pk=id_conf) |
|
791 | conf = DevConfModel.objects.get(pk=id_conf) | |
766 |
|
792 | |||
767 | if request.method == 'GET': |
|
793 | if request.method == 'GET': | |
768 | file_form = UploadFileForm() |
|
794 | file_form = UploadFileForm() | |
769 |
|
795 | |||
770 | if request.method == 'POST': |
|
796 | if request.method == 'POST': | |
771 | file_form = UploadFileForm(request.POST, request.FILES) |
|
797 | file_form = UploadFileForm(request.POST, request.FILES) | |
772 |
|
798 | |||
773 | if file_form.is_valid(): |
|
799 | if file_form.is_valid(): | |
774 |
|
800 | |||
775 | parms = conf.import_from_file(request.FILES['file']) |
|
801 | parms = conf.import_from_file(request.FILES['file']) | |
776 |
|
802 | |||
777 | if parms: |
|
803 | if parms: | |
778 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) |
|
804 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) | |
779 | form = DevConfForm(initial=parms, instance=conf) |
|
805 | form = DevConfForm(initial=parms, instance=conf) | |
780 |
|
806 | |||
781 | kwargs = {} |
|
807 | kwargs = {} | |
782 | kwargs['id_dev'] = conf.id |
|
808 | kwargs['id_dev'] = conf.id | |
783 | kwargs['form'] = form |
|
809 | kwargs['form'] = form | |
784 | kwargs['title'] = 'Device Configuration' |
|
810 | kwargs['title'] = 'Device Configuration' | |
785 | kwargs['suptitle'] = 'Parameters imported' |
|
811 | kwargs['suptitle'] = 'Parameters imported' | |
786 | kwargs['button'] = 'Save' |
|
812 | kwargs['button'] = 'Save' | |
787 | kwargs['action'] = conf.get_absolute_url_edit() |
|
813 | kwargs['action'] = conf.get_absolute_url_edit() | |
788 | kwargs['previous'] = conf.get_absolute_url() |
|
814 | kwargs['previous'] = conf.get_absolute_url() | |
789 |
|
815 | |||
790 | ###### SIDEBAR ###### |
|
816 | ###### SIDEBAR ###### | |
791 | kwargs.update(sidebar(conf=conf)) |
|
817 | kwargs.update(sidebar(conf=conf)) | |
792 |
|
818 | |||
793 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) |
|
819 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) | |
794 |
|
820 | |||
795 | messages.error(request, "Could not import parameters from file") |
|
821 | messages.error(request, "Could not import parameters from file") | |
796 |
|
822 | |||
797 | kwargs = {} |
|
823 | kwargs = {} | |
798 | kwargs['id_dev'] = conf.id |
|
824 | kwargs['id_dev'] = conf.id | |
799 | kwargs['title'] = 'Device Configuration' |
|
825 | kwargs['title'] = 'Device Configuration' | |
800 | kwargs['form'] = file_form |
|
826 | kwargs['form'] = file_form | |
801 | kwargs['suptitle'] = 'Importing file' |
|
827 | kwargs['suptitle'] = 'Importing file' | |
802 | kwargs['button'] = 'Import' |
|
828 | kwargs['button'] = 'Import' | |
803 |
|
829 | |||
804 | kwargs.update(sidebar(conf=conf)) |
|
830 | kwargs.update(sidebar(conf=conf)) | |
805 |
|
831 | |||
806 | return render(request, 'dev_conf_import.html', kwargs) |
|
832 | return render(request, 'dev_conf_import.html', kwargs) | |
807 |
|
833 | |||
808 |
|
834 | |||
809 | def dev_conf_export(request, id_conf): |
|
835 | def dev_conf_export(request, id_conf): | |
810 |
|
836 | |||
811 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
837 | conf = get_object_or_404(Configuration, pk=id_conf) | |
812 |
|
838 | |||
813 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
839 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
814 |
|
840 | |||
815 | conf = DevConfModel.objects.get(pk=id_conf) |
|
841 | conf = DevConfModel.objects.get(pk=id_conf) | |
816 |
|
842 | |||
817 | if request.method == 'GET': |
|
843 | if request.method == 'GET': | |
818 | file_form = DownloadFileForm(conf.device.device_type.name) |
|
844 | file_form = DownloadFileForm(conf.device.device_type.name) | |
819 |
|
845 | |||
820 | if request.method == 'POST': |
|
846 | if request.method == 'POST': | |
821 | file_form = DownloadFileForm(conf.device.device_type.name, request.POST) |
|
847 | file_form = DownloadFileForm(conf.device.device_type.name, request.POST) | |
822 |
|
848 | |||
823 | if file_form.is_valid(): |
|
849 | if file_form.is_valid(): | |
824 | fields = conf.export_to_file(format = file_form.cleaned_data['format']) |
|
850 | fields = conf.export_to_file(format = file_form.cleaned_data['format']) | |
825 |
|
851 | |||
826 | response = HttpResponse(content_type=fields['content_type']) |
|
852 | response = HttpResponse(content_type=fields['content_type']) | |
827 | response['Content-Disposition'] = 'attachment; filename="%s"' %fields['filename'] |
|
853 | response['Content-Disposition'] = 'attachment; filename="%s"' %fields['filename'] | |
828 | response.write(fields['content']) |
|
854 | response.write(fields['content']) | |
829 |
|
855 | |||
830 | return response |
|
856 | return response | |
831 |
|
857 | |||
832 | messages.error(request, "Could not export parameters") |
|
858 | messages.error(request, "Could not export parameters") | |
833 |
|
859 | |||
834 | kwargs = {} |
|
860 | kwargs = {} | |
835 | kwargs['id_dev'] = conf.id |
|
861 | kwargs['id_dev'] = conf.id | |
836 | kwargs['title'] = 'Device Configuration' |
|
862 | kwargs['title'] = 'Device Configuration' | |
837 | kwargs['form'] = file_form |
|
863 | kwargs['form'] = file_form | |
838 | kwargs['suptitle'] = 'Exporting file' |
|
864 | kwargs['suptitle'] = 'Exporting file' | |
839 | kwargs['button'] = 'Export' |
|
865 | kwargs['button'] = 'Export' | |
840 |
|
866 | |||
841 | return render(request, 'dev_conf_export.html', kwargs) |
|
867 | return render(request, 'dev_conf_export.html', kwargs) | |
842 |
|
868 | |||
843 |
|
869 | |||
844 | def dev_conf_delete(request, id_conf): |
|
870 | def dev_conf_delete(request, id_conf): | |
845 |
|
871 | |||
846 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
872 | conf = get_object_or_404(Configuration, pk=id_conf) | |
847 |
|
873 | |||
848 | if request.method=='POST': |
|
874 | if request.method=='POST': | |
849 | if request.user.is_staff: |
|
875 | if request.user.is_staff: | |
850 | conf.delete() |
|
876 | conf.delete() | |
851 | return redirect('url_dev_confs') |
|
877 | return redirect('url_dev_confs') | |
852 |
|
878 | |||
853 | messages.error(request, 'Not enough permission to delete this object') |
|
879 | messages.error(request, 'Not enough permission to delete this object') | |
854 | return redirect(conf.get_absolute_url()) |
|
880 | return redirect(conf.get_absolute_url()) | |
855 |
|
881 | |||
856 | kwargs = { |
|
882 | kwargs = { | |
857 | 'title': 'Delete', |
|
883 | 'title': 'Delete', | |
858 | 'suptitle': 'Experiment', |
|
884 | 'suptitle': 'Experiment', | |
859 | 'object': conf, |
|
885 | 'object': conf, | |
860 | 'previous': conf.get_absolute_url(), |
|
886 | 'previous': conf.get_absolute_url(), | |
861 | 'delete': True |
|
887 | 'delete': True | |
862 | } |
|
888 | } | |
863 |
|
889 | |||
864 | return render(request, 'confirm.html', kwargs) |
|
890 | return render(request, 'confirm.html', kwargs) | |
865 |
|
891 | |||
866 |
|
892 | |||
867 | def sidebar(**kwargs): |
|
893 | def sidebar(**kwargs): | |
868 |
|
894 | |||
869 | side_data = {} |
|
895 | side_data = {} | |
870 |
|
896 | |||
871 | conf = kwargs.get('conf', None) |
|
897 | conf = kwargs.get('conf', None) | |
872 | experiment = kwargs.get('experiment', None) |
|
898 | experiment = kwargs.get('experiment', None) | |
873 |
|
899 | |||
874 | if not experiment: |
|
900 | if not experiment: | |
875 | experiment = conf.experiment |
|
901 | experiment = conf.experiment | |
876 |
|
902 | |||
877 | if experiment: |
|
903 | if experiment: | |
878 | side_data['experiment'] = experiment |
|
904 | side_data['experiment'] = experiment | |
879 | campaign = experiment.campaign_set.all() |
|
905 | campaign = experiment.campaign_set.all() | |
880 | if campaign: |
|
906 | if campaign: | |
881 | side_data['campaign'] = campaign[0] |
|
907 | side_data['campaign'] = campaign[0] | |
882 | experiments = campaign[0].experiments.all() |
|
908 | experiments = campaign[0].experiments.all() | |
883 | else: |
|
909 | else: | |
884 | experiments = [experiment] |
|
910 | experiments = [experiment] | |
885 | configurations = experiment.configuration_set.filter(type=0) |
|
911 | configurations = experiment.configuration_set.filter(type=0) | |
886 | side_data['side_experiments'] = experiments |
|
912 | side_data['side_experiments'] = experiments | |
887 | side_data['side_configurations'] = configurations |
|
913 | side_data['side_configurations'] = configurations | |
888 |
|
914 | |||
889 | return side_data |
|
915 | return side_data | |
890 |
|
916 | |||
891 |
|
917 | |||
892 | def operation(request, id_camp=None): |
|
918 | def operation(request, id_camp=None): | |
893 |
|
919 | |||
894 | if not id_camp: |
|
920 | if not id_camp: | |
895 | campaigns = Campaign.objects.all().order_by('-start_date') |
|
921 | campaigns = Campaign.objects.all().order_by('-start_date') | |
896 |
|
922 | |||
897 | if not campaigns: |
|
923 | if not campaigns: | |
898 | kwargs = {} |
|
924 | kwargs = {} | |
899 | kwargs['title'] = 'No Campaigns' |
|
925 | kwargs['title'] = 'No Campaigns' | |
900 | kwargs['suptitle'] = 'Empty' |
|
926 | kwargs['suptitle'] = 'Empty' | |
901 | return render(request, 'operation.html', kwargs) |
|
927 | return render(request, 'operation.html', kwargs) | |
902 |
|
928 | |||
903 | id_camp = campaigns[0].id |
|
929 | id_camp = campaigns[0].id | |
904 |
|
930 | |||
905 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
931 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
906 |
|
932 | |||
907 | if request.method=='GET': |
|
933 | if request.method=='GET': | |
908 | form = OperationForm(initial={'campaign': campaign.id}, length = 5) |
|
934 | form = OperationForm(initial={'campaign': campaign.id}, length = 5) | |
909 |
|
935 | |||
910 | if request.method=='POST': |
|
936 | if request.method=='POST': | |
911 | form = OperationForm(request.POST, initial={'campaign':campaign.id}, length = 5) |
|
937 | form = OperationForm(request.POST, initial={'campaign':campaign.id}, length = 5) | |
912 |
|
938 | |||
913 | if form.is_valid(): |
|
939 | if form.is_valid(): | |
914 | return redirect('url_operation', id_camp=campaign.id) |
|
940 | return redirect('url_operation', id_camp=campaign.id) | |
915 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() |
|
941 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() | |
916 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) |
|
942 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) | |
917 | #for exs in experiments: |
|
943 | #for exs in experiments: | |
918 | # exs.get_status() |
|
944 | # exs.get_status() | |
919 | locations= Location.objects.filter(experiment=experiments).distinct() |
|
945 | locations= Location.objects.filter(experiment=experiments).distinct() | |
920 | #experiments = [Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) for location in locations] |
|
946 | #experiments = [Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) for location in locations] | |
921 | kwargs = {} |
|
947 | kwargs = {} | |
922 | #---Campaign |
|
948 | #---Campaign | |
923 | kwargs['campaign'] = campaign |
|
949 | kwargs['campaign'] = campaign | |
924 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
950 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
925 | #---Experiment |
|
951 | #---Experiment | |
926 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] |
|
952 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] | |
927 | kwargs['experiment_keys'] = keys[1:] |
|
953 | kwargs['experiment_keys'] = keys[1:] | |
928 | kwargs['experiments'] = experiments |
|
954 | kwargs['experiments'] = experiments | |
929 | #---Radar |
|
955 | #---Radar | |
930 | kwargs['locations'] = locations |
|
956 | kwargs['locations'] = locations | |
931 | #---Else |
|
957 | #---Else | |
932 | kwargs['title'] = 'Campaign' |
|
958 | kwargs['title'] = 'Campaign' | |
933 | kwargs['suptitle'] = campaign.name |
|
959 | kwargs['suptitle'] = campaign.name | |
934 | kwargs['form'] = form |
|
960 | kwargs['form'] = form | |
935 | kwargs['button'] = 'Search' |
|
961 | kwargs['button'] = 'Search' | |
936 | kwargs['details'] = True |
|
962 | kwargs['details'] = True | |
937 | kwargs['search_button'] = True |
|
963 | kwargs['search_button'] = True | |
938 |
|
964 | |||
939 | return render(request, 'operation.html', kwargs) |
|
965 | return render(request, 'operation.html', kwargs) | |
940 |
|
966 | |||
941 |
|
967 | |||
942 | def operation_search(request, id_camp=None): |
|
968 | def operation_search(request, id_camp=None): | |
943 |
|
969 | |||
944 |
|
970 | |||
945 | if not id_camp: |
|
971 | if not id_camp: | |
946 | campaigns = Campaign.objects.all().order_by('-start_date') |
|
972 | campaigns = Campaign.objects.all().order_by('-start_date') | |
947 |
|
973 | |||
948 | if not campaigns: |
|
974 | if not campaigns: | |
949 | return render(request, 'operation.html', {}) |
|
975 | return render(request, 'operation.html', {}) | |
950 |
|
976 | |||
951 | id_camp = campaigns[0].id |
|
977 | id_camp = campaigns[0].id | |
952 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
978 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
953 |
|
979 | |||
954 | if request.method=='GET': |
|
980 | if request.method=='GET': | |
955 | form = OperationSearchForm(initial={'campaign': campaign.id}) |
|
981 | form = OperationSearchForm(initial={'campaign': campaign.id}) | |
956 |
|
982 | |||
957 | if request.method=='POST': |
|
983 | if request.method=='POST': | |
958 | form = OperationSearchForm(request.POST, initial={'campaign':campaign.id}) |
|
984 | form = OperationSearchForm(request.POST, initial={'campaign':campaign.id}) | |
959 |
|
985 | |||
960 | if form.is_valid(): |
|
986 | if form.is_valid(): | |
961 | return redirect('url_operation', id_camp=campaign.id) |
|
987 | return redirect('url_operation', id_camp=campaign.id) | |
962 |
|
988 | |||
963 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() |
|
989 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() | |
964 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) |
|
990 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) | |
965 | #for exs in experiments: |
|
991 | #for exs in experiments: | |
966 | # exs.get_status() |
|
992 | # exs.get_status() | |
967 | locations= Location.objects.filter(experiment=experiments).distinct() |
|
993 | locations= Location.objects.filter(experiment=experiments).distinct() | |
968 | form = OperationSearchForm(initial={'campaign': campaign.id}) |
|
994 | form = OperationSearchForm(initial={'campaign': campaign.id}) | |
969 |
|
995 | |||
970 | kwargs = {} |
|
996 | kwargs = {} | |
971 | #---Campaign |
|
997 | #---Campaign | |
972 | kwargs['campaign'] = campaign |
|
998 | kwargs['campaign'] = campaign | |
973 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
999 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
974 | #---Experiment |
|
1000 | #---Experiment | |
975 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] |
|
1001 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] | |
976 | kwargs['experiment_keys'] = keys[1:] |
|
1002 | kwargs['experiment_keys'] = keys[1:] | |
977 | kwargs['experiments'] = experiments |
|
1003 | kwargs['experiments'] = experiments | |
978 | #---Radar |
|
1004 | #---Radar | |
979 | kwargs['locations'] = locations |
|
1005 | kwargs['locations'] = locations | |
980 | #---Else |
|
1006 | #---Else | |
981 | kwargs['title'] = 'Campaign' |
|
1007 | kwargs['title'] = 'Campaign' | |
982 | kwargs['suptitle'] = campaign.name |
|
1008 | kwargs['suptitle'] = campaign.name | |
983 | kwargs['form'] = form |
|
1009 | kwargs['form'] = form | |
984 | kwargs['button'] = 'Select' |
|
1010 | kwargs['button'] = 'Select' | |
985 | kwargs['details'] = True |
|
1011 | kwargs['details'] = True | |
986 | kwargs['search_button'] = False |
|
1012 | kwargs['search_button'] = False | |
987 |
|
1013 | |||
988 | return render(request, 'operation.html', kwargs) |
|
1014 | return render(request, 'operation.html', kwargs) | |
989 |
|
1015 | |||
990 |
|
1016 | |||
991 | def radar_play(request, id_camp, id_radar): |
|
1017 | def radar_play(request, id_camp, id_radar): | |
992 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1018 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
993 | radar = get_object_or_404(Location, pk = id_radar) |
|
1019 | radar = get_object_or_404(Location, pk = id_radar) | |
994 | today = datetime.today() |
|
1020 | today = datetime.today() | |
995 | now = today.time() |
|
1021 | now = today.time() | |
996 |
|
1022 | |||
997 | #--Clear Old Experiments From RunningExperiment Object |
|
1023 | #--Clear Old Experiments From RunningExperiment Object | |
998 | running_experiment = RunningExperiment.objects.filter(radar=radar) |
|
1024 | running_experiment = RunningExperiment.objects.filter(radar=radar) | |
999 | if running_experiment: |
|
1025 | if running_experiment: | |
1000 | running_experiment = running_experiment[0] |
|
1026 | running_experiment = running_experiment[0] | |
1001 | running_experiment.running_experiment.clear() |
|
1027 | running_experiment.running_experiment.clear() | |
1002 | running_experiment.save() |
|
1028 | running_experiment.save() | |
1003 |
|
1029 | |||
1004 | #--If campaign datetime is ok: |
|
1030 | #--If campaign datetime is ok: | |
1005 | if today >= campaign.start_date and today <= campaign.end_date: |
|
1031 | if today >= campaign.start_date and today <= campaign.end_date: | |
1006 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) |
|
1032 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) | |
1007 | for exp in experiments: |
|
1033 | for exp in experiments: | |
1008 | #--If experiment time is ok: |
|
1034 | #--If experiment time is ok: | |
1009 | if now >= exp.start_time and now <= exp.end_time: |
|
1035 | if now >= exp.start_time and now <= exp.end_time: | |
1010 | configurations = Configuration.objects.filter(experiment = exp) |
|
1036 | configurations = Configuration.objects.filter(experiment = exp) | |
1011 | for conf in configurations: |
|
1037 | for conf in configurations: | |
1012 | if 'cgs' in conf.device.device_type.name: |
|
1038 | if 'cgs' in conf.device.device_type.name: | |
1013 | conf.status_device() |
|
1039 | conf.status_device() | |
1014 | else: |
|
1040 | else: | |
1015 | answer = conf.start_device() |
|
1041 | answer = conf.start_device() | |
1016 | conf.status_device() |
|
1042 | conf.status_device() | |
1017 | #--Running Experiment |
|
1043 | #--Running Experiment | |
1018 | old_running_experiment = RunningExperiment.objects.filter(radar=radar) |
|
1044 | old_running_experiment = RunningExperiment.objects.filter(radar=radar) | |
1019 | #--If RunningExperiment element exists |
|
1045 | #--If RunningExperiment element exists | |
1020 | if old_running_experiment: |
|
1046 | if old_running_experiment: | |
1021 | old_running_experiment = old_running_experiment[0] |
|
1047 | old_running_experiment = old_running_experiment[0] | |
1022 | old_running_experiment.running_experiment.add(exp) |
|
1048 | old_running_experiment.running_experiment.add(exp) | |
1023 | old_running_experiment.status = 3 |
|
1049 | old_running_experiment.status = 3 | |
1024 | old_running_experiment.save() |
|
1050 | old_running_experiment.save() | |
1025 | #--Create a new Running_Experiment Object |
|
1051 | #--Create a new Running_Experiment Object | |
1026 | else: |
|
1052 | else: | |
1027 | new_running_experiment = RunningExperiment( |
|
1053 | new_running_experiment = RunningExperiment( | |
1028 | radar = radar, |
|
1054 | radar = radar, | |
1029 | status = 3, |
|
1055 | status = 3, | |
1030 | ) |
|
1056 | ) | |
1031 | new_running_experiment.save() |
|
1057 | new_running_experiment.save() | |
1032 | new_running_experiment.running_experiment.add(exp) |
|
1058 | new_running_experiment.running_experiment.add(exp) | |
1033 | new_running_experiment.save() |
|
1059 | new_running_experiment.save() | |
1034 |
|
1060 | |||
1035 | if answer: |
|
1061 | if answer: | |
1036 | messages.success(request, conf.message) |
|
1062 | messages.success(request, conf.message) | |
1037 | exp.status=2 |
|
1063 | exp.status=2 | |
1038 | exp.save() |
|
1064 | exp.save() | |
1039 | else: |
|
1065 | else: | |
1040 | messages.error(request, conf.message) |
|
1066 | messages.error(request, conf.message) | |
1041 | else: |
|
1067 | else: | |
1042 | if exp.status == 1 or exp.status == 3: |
|
1068 | if exp.status == 1 or exp.status == 3: | |
1043 | exp.status=3 |
|
1069 | exp.status=3 | |
1044 | exp.save() |
|
1070 | exp.save() | |
1045 |
|
1071 | |||
1046 |
|
1072 | |||
1047 | route = request.META['HTTP_REFERER'] |
|
1073 | route = request.META['HTTP_REFERER'] | |
1048 | route = str(route) |
|
1074 | route = str(route) | |
1049 | if 'search' in route: |
|
1075 | if 'search' in route: | |
1050 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) |
|
1076 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) | |
1051 | else: |
|
1077 | else: | |
1052 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1078 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) | |
1053 |
|
1079 | |||
1054 |
|
1080 | |||
1055 | def radar_stop(request, id_camp, id_radar): |
|
1081 | def radar_stop(request, id_camp, id_radar): | |
1056 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1082 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
1057 | radar = get_object_or_404(Location, pk = id_radar) |
|
1083 | radar = get_object_or_404(Location, pk = id_radar) | |
1058 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) |
|
1084 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) | |
1059 |
|
1085 | |||
1060 | for exp in experiments: |
|
1086 | for exp in experiments: | |
1061 | configurations = Configuration.objects.filter(experiment = exp) |
|
1087 | configurations = Configuration.objects.filter(experiment = exp) | |
1062 | for conf in configurations: |
|
1088 | for conf in configurations: | |
1063 | if 'cgs' in conf.device.device_type.name: |
|
1089 | if 'cgs' in conf.device.device_type.name: | |
1064 | conf.status_device() |
|
1090 | conf.status_device() | |
1065 | else: |
|
1091 | else: | |
1066 | answer = conf.stop_device() |
|
1092 | answer = conf.stop_device() | |
1067 | conf.status_device() |
|
1093 | conf.status_device() | |
1068 |
|
1094 | |||
1069 | if answer: |
|
1095 | if answer: | |
1070 | messages.success(request, conf.message) |
|
1096 | messages.success(request, conf.message) | |
1071 | exp.status=1 |
|
1097 | exp.status=1 | |
1072 | exp.save() |
|
1098 | exp.save() | |
1073 | else: |
|
1099 | else: | |
1074 | messages.error(request, conf.message) |
|
1100 | messages.error(request, conf.message) | |
1075 |
|
1101 | |||
1076 |
|
1102 | |||
1077 | route = request.META['HTTP_REFERER'] |
|
1103 | route = request.META['HTTP_REFERER'] | |
1078 | route = str(route) |
|
1104 | route = str(route) | |
1079 | if 'search' in route: |
|
1105 | if 'search' in route: | |
1080 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) |
|
1106 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) | |
1081 | else: |
|
1107 | else: | |
1082 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1108 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) | |
1083 |
|
1109 | |||
1084 |
|
1110 | |||
1085 | def radar_refresh(request, id_camp, id_radar): |
|
1111 | def radar_refresh(request, id_camp, id_radar): | |
1086 |
|
1112 | |||
1087 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1113 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
1088 | radar = get_object_or_404(Location, pk = id_radar) |
|
1114 | radar = get_object_or_404(Location, pk = id_radar) | |
1089 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) |
|
1115 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) | |
1090 | for exs in experiments: |
|
1116 | for exs in experiments: | |
1091 | exs.get_status() |
|
1117 | exs.get_status() | |
1092 |
|
1118 | |||
1093 | route = request.META['HTTP_REFERER'] |
|
1119 | route = request.META['HTTP_REFERER'] | |
1094 | route = str(route) |
|
1120 | route = str(route) | |
1095 | if 'search' in route: |
|
1121 | if 'search' in route: | |
1096 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) |
|
1122 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) | |
1097 | else: |
|
1123 | else: | |
1098 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1124 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) | |
1099 |
|
1125 |
General Comments 0
You need to be logged in to leave comments.
Login now