@@ -0,0 +1,1 | |||||
|
1 | {% extends "campaign_edit.html" %} No newline at end of file |
@@ -0,0 +1,1 | |||||
|
1 | {% extends "experiment_edit.html" %} No newline at end of file |
@@ -1,173 +1,182 | |||||
1 | from django.db import models |
|
1 | from django.db import models | |
2 | from apps.main.models import Configuration |
|
2 | from apps.main.models import Configuration | |
3 | from django.core.validators import MinValueValidator, MaxValueValidator |
|
3 | from django.core.validators import MinValueValidator, MaxValueValidator | |
4 |
|
4 | |||
5 |
|
5 | |||
6 | from apps.main.models import Device, Experiment |
|
6 | from apps.main.models import Device, Experiment | |
7 |
|
7 | |||
8 | from files import read_json_file |
|
8 | from files import read_json_file | |
9 | # Create your models here. validators=[MinValueValidator(62.5e6), MaxValueValidator(450e6)] |
|
9 | # Create your models here. validators=[MinValueValidator(62.5e6), MaxValueValidator(450e6)] | |
10 |
|
10 | |||
11 | class CGSConfiguration(Configuration): |
|
11 | class CGSConfiguration(Configuration): | |
12 |
|
12 | |||
13 | freq0 = models.PositiveIntegerField(verbose_name='Frequency 0',validators=[MaxValueValidator(450e6)], default = 60) |
|
13 | freq0 = models.PositiveIntegerField(verbose_name='Frequency 0',validators=[MaxValueValidator(450e6)], default = 60) | |
14 | freq1 = models.PositiveIntegerField(verbose_name='Frequency 1',validators=[MaxValueValidator(450e6)], default = 60) |
|
14 | freq1 = models.PositiveIntegerField(verbose_name='Frequency 1',validators=[MaxValueValidator(450e6)], default = 60) | |
15 | freq2 = models.PositiveIntegerField(verbose_name='Frequency 2',validators=[MaxValueValidator(450e6)], default = 60) |
|
15 | freq2 = models.PositiveIntegerField(verbose_name='Frequency 2',validators=[MaxValueValidator(450e6)], default = 60) | |
16 | freq3 = models.PositiveIntegerField(verbose_name='Frequency 3',validators=[MaxValueValidator(450e6)], default = 60) |
|
16 | freq3 = models.PositiveIntegerField(verbose_name='Frequency 3',validators=[MaxValueValidator(450e6)], default = 60) | |
17 |
|
17 | |||
18 | def verify_frequencies(self): |
|
18 | def verify_frequencies(self): | |
19 |
|
19 | |||
20 | return True |
|
20 | return True | |
21 |
|
21 | |||
22 |
|
22 | |||
23 | def update_from_file(self, fp): |
|
23 | def update_from_file(self, fp): | |
24 |
|
24 | |||
25 | kwargs = read_json_file(fp) |
|
25 | kwargs = read_json_file(fp) | |
26 |
|
26 | |||
27 | if not kwargs: |
|
27 | if not kwargs: | |
28 | return False |
|
28 | return False | |
29 |
|
29 | |||
30 | self.freq0 = kwargs['freq0'] |
|
30 | self.freq0 = kwargs['freq0'] | |
31 | self.freq1 = kwargs['freq1'] |
|
31 | self.freq1 = kwargs['freq1'] | |
32 | self.freq2 = kwargs['freq2'] |
|
32 | self.freq2 = kwargs['freq2'] | |
33 | self.freq3 = kwargs['freq3'] |
|
33 | self.freq3 = kwargs['freq3'] | |
34 |
|
34 | |||
35 | return True |
|
35 | return True | |
36 |
|
36 | |||
37 | def parms_to_dict(self): |
|
37 | def parms_to_dict(self): | |
38 |
|
38 | |||
39 | parameters = {} |
|
39 | parameters = {} | |
40 |
|
40 | |||
|
41 | parameters['device_id'] = self.device.id | |||
|
42 | ||||
41 | if self.freq0 == None or self.freq0 == '': |
|
43 | if self.freq0 == None or self.freq0 == '': | |
42 | parameters['freq0'] = 0 |
|
44 | parameters['freq0'] = 0 | |
43 | else: |
|
45 | else: | |
44 | parameters['freq0'] = self.freq0 |
|
46 | parameters['freq0'] = self.freq0 | |
45 |
|
47 | |||
46 | if self.freq1 == None or self.freq1 == '': |
|
48 | if self.freq1 == None or self.freq1 == '': | |
47 | parameters['freq1'] = 0 |
|
49 | parameters['freq1'] = 0 | |
48 | else: |
|
50 | else: | |
49 | parameters['freq1'] = self.freq1 |
|
51 | parameters['freq1'] = self.freq1 | |
50 |
|
52 | |||
51 | if self.freq2 == None or self.freq2 == '': |
|
53 | if self.freq2 == None or self.freq2 == '': | |
52 | parameters['freq2'] = 0 |
|
54 | parameters['freq2'] = 0 | |
53 | else: |
|
55 | else: | |
54 | parameters['freq2'] = self.freq2 |
|
56 | parameters['freq2'] = self.freq2 | |
55 |
|
57 | |||
56 | if self.freq3 == None or self.freq3 == '': |
|
58 | if self.freq3 == None or self.freq3 == '': | |
57 | parameters['freq3'] = 0 |
|
59 | parameters['freq3'] = 0 | |
58 | else: |
|
60 | else: | |
59 | parameters['freq3'] = self.freq3 |
|
61 | parameters['freq3'] = self.freq3 | |
60 |
|
62 | |||
61 |
|
||||
62 | return parameters |
|
63 | return parameters | |
63 |
|
64 | |||
64 |
|
65 | |||
|
66 | def dict_to_parms(self, parameters): | |||
|
67 | ||||
|
68 | self.freq0 = parameters['freq0'] | |||
|
69 | self.freq1 = parameters['freq1'] | |||
|
70 | self.freq2 = parameters['freq2'] | |||
|
71 | self.freq3 = parameters['freq3'] | |||
|
72 | ||||
|
73 | ||||
65 | def status_device(self): |
|
74 | def status_device(self): | |
66 |
|
75 | |||
67 | import requests |
|
76 | import requests | |
68 |
|
77 | |||
69 | ip=self.device.ip_address |
|
78 | ip=self.device.ip_address | |
70 | port=self.device.port_address |
|
79 | port=self.device.port_address | |
71 |
|
80 | |||
72 | route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" |
|
81 | route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" | |
73 | try: |
|
82 | try: | |
74 | r = requests.get(route,timeout=0.5) |
|
83 | r = requests.get(route,timeout=0.5) | |
75 | except: |
|
84 | except: | |
76 | self.device.status = 0 |
|
85 | self.device.status = 0 | |
77 | self.device.save() |
|
86 | self.device.save() | |
78 | return self.device.status |
|
87 | return self.device.status | |
79 |
|
88 | |||
80 | response = str(r.text) |
|
89 | response = str(r.text) | |
81 | response = response.split(";") |
|
90 | response = response.split(";") | |
82 | icon = response[0] |
|
91 | icon = response[0] | |
83 | status = response[-1] |
|
92 | status = response[-1] | |
84 |
|
93 | |||
85 | print icon, status |
|
94 | print icon, status | |
86 | #"icon" could be: "alert" or "okay" |
|
95 | #"icon" could be: "alert" or "okay" | |
87 | if "alert" in icon: |
|
96 | if "alert" in icon: | |
88 | if "Starting Up" in status: #No Esta conectado |
|
97 | if "Starting Up" in status: #No Esta conectado | |
89 | self.device.status = 0 |
|
98 | self.device.status = 0 | |
90 | else: |
|
99 | else: | |
91 | self.device.status = 1 |
|
100 | self.device.status = 1 | |
92 | elif "okay" in icon: |
|
101 | elif "okay" in icon: | |
93 | self.device.status = 3 |
|
102 | self.device.status = 3 | |
94 | else: |
|
103 | else: | |
95 | self.device.status = 1 |
|
104 | self.device.status = 1 | |
96 |
|
105 | |||
97 | self.message = status |
|
106 | self.message = status | |
98 | self.device.save() |
|
107 | self.device.save() | |
99 |
|
108 | |||
100 |
|
109 | |||
101 | return self.device.status |
|
110 | return self.device.status | |
102 |
|
111 | |||
103 |
|
112 | |||
104 | def read_device(self): |
|
113 | def read_device(self): | |
105 |
|
114 | |||
106 | import requests |
|
115 | import requests | |
107 |
|
116 | |||
108 | ip=self.device.ip_address |
|
117 | ip=self.device.ip_address | |
109 | port=self.device.port_address |
|
118 | port=self.device.port_address | |
110 |
|
119 | |||
111 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" |
|
120 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" | |
112 | try: |
|
121 | try: | |
113 | frequencies = requests.get(route,timeout=0.5) |
|
122 | frequencies = requests.get(route,timeout=0.5) | |
114 |
|
123 | |||
115 | except: |
|
124 | except: | |
116 | self.message = "Could not read CGS parameters from this device" |
|
125 | self.message = "Could not read CGS parameters from this device" | |
117 | return None |
|
126 | return None | |
118 |
|
127 | |||
119 | frequencies = frequencies.json() |
|
128 | frequencies = frequencies.json() | |
120 | frequencies = frequencies.get("Frecuencias") |
|
129 | frequencies = frequencies.get("Frecuencias") | |
121 | f0 = frequencies.get("f0") |
|
130 | f0 = frequencies.get("f0") | |
122 | f1 = frequencies.get("f1") |
|
131 | f1 = frequencies.get("f1") | |
123 | f2 = frequencies.get("f2") |
|
132 | f2 = frequencies.get("f2") | |
124 | f3 = frequencies.get("f3") |
|
133 | f3 = frequencies.get("f3") | |
125 |
|
134 | |||
126 | parms = {'freq0': f0, |
|
135 | parms = {'freq0': f0, | |
127 | 'freq1': f1, |
|
136 | 'freq1': f1, | |
128 | 'freq2': f2, |
|
137 | 'freq2': f2, | |
129 | 'freq3': f3} |
|
138 | 'freq3': f3} | |
130 |
|
139 | |||
131 | self.message = "" |
|
140 | self.message = "" | |
132 | return parms |
|
141 | return parms | |
133 |
|
142 | |||
134 |
|
143 | |||
135 | def write_device(self): |
|
144 | def write_device(self): | |
136 |
|
145 | |||
137 | import requests |
|
146 | import requests | |
138 |
|
147 | |||
139 | ip=self.device.ip_address |
|
148 | ip=self.device.ip_address | |
140 | port=self.device.port_address |
|
149 | port=self.device.port_address | |
141 |
|
150 | |||
142 | #---Frequencies from form |
|
151 | #---Frequencies from form | |
143 | f0 = self.freq0 |
|
152 | f0 = self.freq0 | |
144 | f1 = self.freq1 |
|
153 | f1 = self.freq1 | |
145 | f2 = self.freq2 |
|
154 | f2 = self.freq2 | |
146 | f3 = self.freq3 |
|
155 | f3 = self.freq3 | |
147 | post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} |
|
156 | post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} | |
148 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" |
|
157 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" | |
149 |
|
158 | |||
150 | try: |
|
159 | try: | |
151 | r = requests.post(route, post_data, timeout=0.5) |
|
160 | r = requests.post(route, post_data, timeout=0.5) | |
152 | except: |
|
161 | except: | |
153 | self.message = "Could not write CGS parameters" |
|
162 | self.message = "Could not write CGS parameters" | |
154 | return None |
|
163 | return None | |
155 |
|
164 | |||
156 | text = r.text |
|
165 | text = r.text | |
157 | text = text.split(',') |
|
166 | text = text.split(',') | |
158 |
|
167 | |||
159 | if len(text)>1: |
|
168 | if len(text)>1: | |
160 | title = text[0] |
|
169 | title = text[0] | |
161 | status = text[1] |
|
170 | status = text[1] | |
162 | if title == "okay": |
|
171 | if title == "okay": | |
163 | self.message = status |
|
172 | self.message = status | |
164 | return 3 |
|
173 | return 3 | |
165 | else: |
|
174 | else: | |
166 | self.message = title + ", " + status |
|
175 | self.message = title + ", " + status | |
167 | return 1 |
|
176 | return 1 | |
168 |
|
177 | |||
169 | return 1 |
|
178 | return 1 | |
170 |
|
179 | |||
171 |
|
180 | |||
172 | class Meta: |
|
181 | class Meta: | |
173 | db_table = 'cgs_configurations' |
|
182 | db_table = 'cgs_configurations' |
@@ -1,228 +1,230 | |||||
1 | from django.db import models |
|
1 | from django.db import models | |
2 | from apps.main.models import Configuration |
|
2 | from apps.main.models import Configuration | |
3 | # Create your models here. |
|
3 | # Create your models here. | |
4 |
|
4 | |||
5 | from django.core.validators import MinValueValidator, MaxValueValidator |
|
5 | from django.core.validators import MinValueValidator, MaxValueValidator | |
6 | from django.core.exceptions import ValidationError |
|
6 | from django.core.exceptions import ValidationError | |
7 |
|
7 | |||
8 | from devices.dds import api, data |
|
8 | from devices.dds import api, data | |
9 |
|
9 | |||
10 | ENABLE_TYPE = ( |
|
10 | ENABLE_TYPE = ( | |
11 | (False, 'Disabled'), |
|
11 | (False, 'Disabled'), | |
12 | (True, 'Enabled'), |
|
12 | (True, 'Enabled'), | |
13 | ) |
|
13 | ) | |
14 | MOD_TYPES = ( |
|
14 | MOD_TYPES = ( | |
15 | (0, 'Single Tone'), |
|
15 | (0, 'Single Tone'), | |
16 | (1, 'FSK'), |
|
16 | (1, 'FSK'), | |
17 | (2, 'Ramped FSK'), |
|
17 | (2, 'Ramped FSK'), | |
18 | (3, 'Chirp'), |
|
18 | (3, 'Chirp'), | |
19 | (4, 'BPSK'), |
|
19 | (4, 'BPSK'), | |
20 | ) |
|
20 | ) | |
21 |
|
21 | |||
22 | class DDSConfiguration(Configuration): |
|
22 | class DDSConfiguration(Configuration): | |
23 |
|
23 | |||
24 | DDS_NBITS = 48 |
|
24 | DDS_NBITS = 48 | |
25 |
|
25 | |||
26 | clock = models.FloatField(verbose_name='Clock Input (MHz)',validators=[MinValueValidator(5), MaxValueValidator(75)], null=True, default=60) |
|
26 | clock = models.FloatField(verbose_name='Clock Input (MHz)',validators=[MinValueValidator(5), MaxValueValidator(75)], null=True, default=60) | |
27 | multiplier = models.PositiveIntegerField(verbose_name='Multiplier',validators=[MinValueValidator(1), MaxValueValidator(20)], default=4) |
|
27 | multiplier = models.PositiveIntegerField(verbose_name='Multiplier',validators=[MinValueValidator(1), MaxValueValidator(20)], default=4) | |
28 |
|
28 | |||
29 | frequencyA_Mhz = models.DecimalField(verbose_name='Frequency A (MHz)', validators=[MinValueValidator(0), MaxValueValidator(150)], max_digits=19, decimal_places=16, null=True, default=49.9200) |
|
29 | frequencyA_Mhz = models.DecimalField(verbose_name='Frequency A (MHz)', validators=[MinValueValidator(0), MaxValueValidator(150)], max_digits=19, decimal_places=16, null=True, default=49.9200) | |
30 | frequencyA = models.BigIntegerField(verbose_name='Frequency A (Decimal)',validators=[MinValueValidator(0), MaxValueValidator(2**DDS_NBITS-1)], blank=True, null=True) |
|
30 | frequencyA = models.BigIntegerField(verbose_name='Frequency A (Decimal)',validators=[MinValueValidator(0), MaxValueValidator(2**DDS_NBITS-1)], blank=True, null=True) | |
31 |
|
31 | |||
32 | frequencyB_Mhz = models.DecimalField(verbose_name='Frequency B (MHz)', validators=[MinValueValidator(0), MaxValueValidator(150)], max_digits=19, decimal_places=16, blank=True, null=True) |
|
32 | frequencyB_Mhz = models.DecimalField(verbose_name='Frequency B (MHz)', validators=[MinValueValidator(0), MaxValueValidator(150)], max_digits=19, decimal_places=16, blank=True, null=True) | |
33 | frequencyB = models.BigIntegerField(verbose_name='Frequency B (Decimal)',validators=[MinValueValidator(0), MaxValueValidator(2**DDS_NBITS-1)], blank=True, null=True) |
|
33 | frequencyB = models.BigIntegerField(verbose_name='Frequency B (Decimal)',validators=[MinValueValidator(0), MaxValueValidator(2**DDS_NBITS-1)], blank=True, null=True) | |
34 |
|
34 | |||
35 | phaseA_degrees = models.FloatField(verbose_name='Phase A (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)], default=0) |
|
35 | phaseA_degrees = models.FloatField(verbose_name='Phase A (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)], default=0) | |
36 |
|
36 | |||
37 | phaseB_degrees = models.FloatField(verbose_name='Phase B (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)], blank=True, null=True) |
|
37 | phaseB_degrees = models.FloatField(verbose_name='Phase B (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)], blank=True, null=True) | |
38 |
|
38 | |||
39 | modulation = models.PositiveIntegerField(verbose_name='Modulation Type', choices = MOD_TYPES, default = 0) |
|
39 | modulation = models.PositiveIntegerField(verbose_name='Modulation Type', choices = MOD_TYPES, default = 0) | |
40 |
|
40 | |||
41 | amplitude_enabled = models.BooleanField(verbose_name='Amplitude Control', choices=ENABLE_TYPE, default=False) |
|
41 | amplitude_enabled = models.BooleanField(verbose_name='Amplitude Control', choices=ENABLE_TYPE, default=False) | |
42 |
|
42 | |||
43 | amplitudeI = models.PositiveIntegerField(verbose_name='Amplitude CH1',validators=[MinValueValidator(0), MaxValueValidator(2**12-1)], blank=True, null=True) |
|
43 | amplitudeI = models.PositiveIntegerField(verbose_name='Amplitude CH1',validators=[MinValueValidator(0), MaxValueValidator(2**12-1)], blank=True, null=True) | |
44 | amplitudeQ = models.PositiveIntegerField(verbose_name='Amplitude CH2',validators=[MinValueValidator(0), MaxValueValidator(2**12-1)], blank=True, null=True) |
|
44 | amplitudeQ = models.PositiveIntegerField(verbose_name='Amplitude CH2',validators=[MinValueValidator(0), MaxValueValidator(2**12-1)], blank=True, null=True) | |
45 |
|
45 | |||
46 |
|
46 | |||
47 | def get_nbits(self): |
|
47 | def get_nbits(self): | |
48 |
|
48 | |||
49 | return self.DDS_NBITS |
|
49 | return self.DDS_NBITS | |
50 |
|
50 | |||
51 | def clean(self): |
|
51 | def clean(self): | |
52 |
|
52 | |||
53 | if self.modulation in [1,2,3]: |
|
53 | if self.modulation in [1,2,3]: | |
54 | if self.frequencyB is None or self.frequencyB_Mhz is None: |
|
54 | if self.frequencyB is None or self.frequencyB_Mhz is None: | |
55 | raise ValidationError({ |
|
55 | raise ValidationError({ | |
56 | 'frequencyB': 'Frequency modulation has to be defined when FSK or Chirp modulation is selected' |
|
56 | 'frequencyB': 'Frequency modulation has to be defined when FSK or Chirp modulation is selected' | |
57 | }) |
|
57 | }) | |
58 |
|
58 | |||
59 | if self.modulation in [4,]: |
|
59 | if self.modulation in [4,]: | |
60 | if self.phaseB_degrees is None: |
|
60 | if self.phaseB_degrees is None: | |
61 | raise ValidationError({ |
|
61 | raise ValidationError({ | |
62 | 'phaseB': 'Phase modulation has to be defined when BPSK modulation is selected' |
|
62 | 'phaseB': 'Phase modulation has to be defined when BPSK modulation is selected' | |
63 | }) |
|
63 | }) | |
64 |
|
64 | |||
65 | self.frequencyA_Mhz = data.binary_to_freq(self.frequencyA, self.clock*self.multiplier) |
|
65 | self.frequencyA_Mhz = data.binary_to_freq(self.frequencyA, self.clock*self.multiplier) | |
66 | self.frequencyB_Mhz = data.binary_to_freq(self.frequencyB, self.clock*self.multiplier) |
|
66 | self.frequencyB_Mhz = data.binary_to_freq(self.frequencyB, self.clock*self.multiplier) | |
67 |
|
67 | |||
68 | def verify_frequencies(self): |
|
68 | def verify_frequencies(self): | |
69 |
|
69 | |||
70 | return True |
|
70 | return True | |
71 |
|
71 | |||
72 | def parms_to_dict(self): |
|
72 | def parms_to_dict(self): | |
73 |
|
73 | |||
74 | parameters = {} |
|
74 | parameters = {} | |
75 |
|
75 | |||
|
76 | parameters['device_id'] = self.device.id | |||
|
77 | ||||
76 | parameters['clock'] = float(self.clock) |
|
78 | parameters['clock'] = float(self.clock) | |
77 | parameters['multiplier'] = int(self.multiplier) |
|
79 | parameters['multiplier'] = int(self.multiplier) | |
78 |
|
80 | |||
79 | parameters['frequencyA'] = int(self.frequencyA) |
|
81 | parameters['frequencyA'] = int(self.frequencyA) | |
80 | parameters['frequencyA_Mhz'] = float(self.frequencyA_Mhz) |
|
82 | parameters['frequencyA_Mhz'] = float(self.frequencyA_Mhz) | |
81 |
|
83 | |||
82 | parameters['phaseA'] = data.phase_to_binary(self.phaseA_degrees) |
|
84 | parameters['phaseA'] = data.phase_to_binary(self.phaseA_degrees) | |
83 | parameters['phaseA_degrees'] = float(self.phaseA_degrees) |
|
85 | parameters['phaseA_degrees'] = float(self.phaseA_degrees) | |
84 |
|
86 | |||
85 | parameters['modulation'] = int(self.modulation) |
|
87 | parameters['modulation'] = int(self.modulation) | |
86 | parameters['amplitude_enabled'] = bool(self.amplitude_enabled) |
|
88 | parameters['amplitude_enabled'] = bool(self.amplitude_enabled) | |
87 |
|
89 | |||
88 | if self.frequencyB: |
|
90 | if self.frequencyB: | |
89 | parameters['frequencyB'] = int(self.frequencyB) |
|
91 | parameters['frequencyB'] = int(self.frequencyB) | |
90 | parameters['frequencyB_Mhz'] = float(self.frequencyB_Mhz) |
|
92 | parameters['frequencyB_Mhz'] = float(self.frequencyB_Mhz) | |
91 | else: |
|
93 | else: | |
92 | parameters['frequencyB'] = 0 |
|
94 | parameters['frequencyB'] = 0 | |
93 | parameters['frequencyB_Mhz'] = 0 |
|
95 | parameters['frequencyB_Mhz'] = 0 | |
94 |
|
96 | |||
95 | if self.phaseB_degrees: |
|
97 | if self.phaseB_degrees: | |
96 | parameters['phaseB_degrees'] = float(self.phaseB_degrees) |
|
98 | parameters['phaseB_degrees'] = float(self.phaseB_degrees) | |
97 | parameters['phaseB'] = data.phase_to_binary(self.phaseB_degrees) |
|
99 | parameters['phaseB'] = data.phase_to_binary(self.phaseB_degrees) | |
98 | else: |
|
100 | else: | |
99 | parameters['phaseB_degrees'] = 0 |
|
101 | parameters['phaseB_degrees'] = 0 | |
100 | parameters['phaseB'] = 0 |
|
102 | parameters['phaseB'] = 0 | |
101 |
|
103 | |||
102 | if self.amplitudeI: |
|
104 | if self.amplitudeI: | |
103 | parameters['amplitudeI'] = int(self.amplitudeI) |
|
105 | parameters['amplitudeI'] = int(self.amplitudeI) | |
104 | else: |
|
106 | else: | |
105 | parameters['amplitudeI'] = 0 |
|
107 | parameters['amplitudeI'] = 0 | |
106 |
|
108 | |||
107 | if self.amplitudeQ: |
|
109 | if self.amplitudeQ: | |
108 | parameters['amplitudeQ'] = int(self.amplitudeQ) |
|
110 | parameters['amplitudeQ'] = int(self.amplitudeQ) | |
109 | else: |
|
111 | else: | |
110 | parameters['amplitudeQ'] = 0 |
|
112 | parameters['amplitudeQ'] = 0 | |
111 |
|
113 | |||
112 | return parameters |
|
114 | return parameters | |
113 |
|
115 | |||
114 | def parms_to_text(self): |
|
116 | def parms_to_text(self): | |
115 |
|
117 | |||
116 | my_dict = self.parms_to_dict() |
|
118 | my_dict = self.parms_to_dict() | |
117 |
|
119 | |||
118 | text = data.dict_to_text(my_dict) |
|
120 | text = data.dict_to_text(my_dict) | |
119 |
|
121 | |||
120 | return text |
|
122 | return text | |
121 |
|
123 | |||
122 | def dict_to_parms(self, parameters): |
|
124 | def dict_to_parms(self, parameters): | |
123 |
|
125 | |||
124 | self.clock = parameters['clock'] |
|
126 | self.clock = parameters['clock'] | |
125 | self.multiplier = parameters['multiplier'] |
|
127 | self.multiplier = parameters['multiplier'] | |
126 | self.frequencyA = parameters['frequencyA'] |
|
128 | self.frequencyA = parameters['frequencyA'] | |
127 | self.frequencyB = parameters['frequencyB'] |
|
129 | self.frequencyB = parameters['frequencyB'] | |
128 | self.frequencyA_Mhz = parameters['frequencyA_Mhz'] |
|
130 | self.frequencyA_Mhz = parameters['frequencyA_Mhz'] | |
129 | self.frequencyB_Mhz = parameters['frequencyB_Mhz'] |
|
131 | self.frequencyB_Mhz = parameters['frequencyB_Mhz'] | |
130 | self.phaseA_degrees = parameters['phaseA_degrees'] |
|
132 | self.phaseA_degrees = parameters['phaseA_degrees'] | |
131 | self.phaseB_degrees = parameters['phaseB_degrees'] |
|
133 | self.phaseB_degrees = parameters['phaseB_degrees'] | |
132 | self.modulation = parameters['modulation'] |
|
134 | self.modulation = parameters['modulation'] | |
133 | self.amplitude_enabled = parameters['amplitude_enabled'] |
|
135 | self.amplitude_enabled = parameters['amplitude_enabled'] | |
134 |
|
136 | |||
135 | def import_from_file(self, fp): |
|
137 | def import_from_file(self, fp): | |
136 |
|
138 | |||
137 | import os, json |
|
139 | import os, json | |
138 |
|
140 | |||
139 | parms = {} |
|
141 | parms = {} | |
140 |
|
142 | |||
141 | path, ext = os.path.splitext(fp.name) |
|
143 | path, ext = os.path.splitext(fp.name) | |
142 |
|
144 | |||
143 | if ext == '.json': |
|
145 | if ext == '.json': | |
144 | parms = json.load(fp) |
|
146 | parms = json.load(fp) | |
145 |
|
147 | |||
146 | if ext == '.dds': |
|
148 | if ext == '.dds': | |
147 | lines = fp.readlines() |
|
149 | lines = fp.readlines() | |
148 | parms = data.text_to_dict(lines) |
|
150 | parms = data.text_to_dict(lines) | |
149 |
|
151 | |||
150 | return parms |
|
152 | return parms | |
151 |
|
153 | |||
152 | def status_device(self): |
|
154 | def status_device(self): | |
153 |
|
155 | |||
154 | answer = api.status(ip = self.device.ip_address, |
|
156 | answer = api.status(ip = self.device.ip_address, | |
155 | port = self.device.port_address) |
|
157 | port = self.device.port_address) | |
156 |
|
158 | |||
157 | self.device.status = int(answer[0]) |
|
159 | self.device.status = int(answer[0]) | |
158 | self.message = answer[2:] |
|
160 | self.message = answer[2:] | |
159 |
|
161 | |||
160 | self.device.save() |
|
162 | self.device.save() | |
161 |
|
163 | |||
162 | return self.device.status |
|
164 | return self.device.status | |
163 |
|
165 | |||
164 | def reset_device(self): |
|
166 | def reset_device(self): | |
165 |
|
167 | |||
166 | answer = api.reset(ip = self.device.ip_address, |
|
168 | answer = api.reset(ip = self.device.ip_address, | |
167 | port = self.device.port_address) |
|
169 | port = self.device.port_address) | |
168 |
|
170 | |||
169 | if answer[0] != "1": |
|
171 | if answer[0] != "1": | |
170 | self.message = answer[0:] |
|
172 | self.message = answer[0:] | |
171 | return 0 |
|
173 | return 0 | |
172 |
|
174 | |||
173 | self.message = answer[2:] |
|
175 | self.message = answer[2:] | |
174 | return 1 |
|
176 | return 1 | |
175 |
|
177 | |||
176 | def stop_device(self): |
|
178 | def stop_device(self): | |
177 |
|
179 | |||
178 | answer = api.disable_rf(ip = self.device.ip_address, |
|
180 | answer = api.disable_rf(ip = self.device.ip_address, | |
179 | port = self.device.port_address) |
|
181 | port = self.device.port_address) | |
180 |
|
182 | |||
181 | if answer[0] != "1": |
|
183 | if answer[0] != "1": | |
182 | self.message = answer[0:] |
|
184 | self.message = answer[0:] | |
183 | return 0 |
|
185 | return 0 | |
184 |
|
186 | |||
185 | self.message = answer[2:] |
|
187 | self.message = answer[2:] | |
186 | return 1 |
|
188 | return 1 | |
187 |
|
189 | |||
188 | def start_device(self): |
|
190 | def start_device(self): | |
189 |
|
191 | |||
190 | answer = api.enable_rf(ip = self.device.ip_address, |
|
192 | answer = api.enable_rf(ip = self.device.ip_address, | |
191 | port = self.device.port_address) |
|
193 | port = self.device.port_address) | |
192 |
|
194 | |||
193 | if answer[0] != "1": |
|
195 | if answer[0] != "1": | |
194 | self.message = answer[0:] |
|
196 | self.message = answer[0:] | |
195 | return 0 |
|
197 | return 0 | |
196 |
|
198 | |||
197 | self.message = answer[2:] |
|
199 | self.message = answer[2:] | |
198 | return 1 |
|
200 | return 1 | |
199 |
|
201 | |||
200 | def read_device(self): |
|
202 | def read_device(self): | |
201 |
|
203 | |||
202 | parms = api.read_config(ip = self.device.ip_address, |
|
204 | parms = api.read_config(ip = self.device.ip_address, | |
203 | port = self.device.port_address) |
|
205 | port = self.device.port_address) | |
204 |
|
206 | |||
205 | if not parms: |
|
207 | if not parms: | |
206 | self.message = "Could not read DDS parameters from this device" |
|
208 | self.message = "Could not read DDS parameters from this device" | |
207 | return parms |
|
209 | return parms | |
208 |
|
210 | |||
209 | self.message = "" |
|
211 | self.message = "" | |
210 | return parms |
|
212 | return parms | |
211 |
|
213 | |||
212 |
|
214 | |||
213 | def write_device(self): |
|
215 | def write_device(self): | |
214 |
|
216 | |||
215 | answer = api.write_config(ip = self.device.ip_address, |
|
217 | answer = api.write_config(ip = self.device.ip_address, | |
216 | port = self.device.port_address, |
|
218 | port = self.device.port_address, | |
217 | parms = self.parms_to_dict()) |
|
219 | parms = self.parms_to_dict()) | |
218 |
|
220 | |||
219 | if answer[0] != "1": |
|
221 | if answer[0] != "1": | |
220 | self.message = answer[0:] |
|
222 | self.message = answer[0:] | |
221 | return 0 |
|
223 | return 0 | |
222 |
|
224 | |||
223 | self.message = answer[2:] |
|
225 | self.message = answer[2:] | |
224 | return 1 |
|
226 | return 1 | |
225 |
|
227 | |||
226 | class Meta: |
|
228 | class Meta: | |
227 | db_table = 'dds_configurations' |
|
229 | db_table = 'dds_configurations' | |
228 | No newline at end of file |
|
230 |
@@ -1,449 +1,541 | |||||
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 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 | ||||
9 | CONF_STATES = ( |
|
10 | CONF_STATES = ( | |
10 | (0, 'Disconnected'), |
|
11 | (0, 'Disconnected'), | |
11 | (1, 'Connected'), |
|
12 | (1, 'Connected'), | |
12 | (2, 'Running'), |
|
13 | (2, 'Running'), | |
13 | ) |
|
14 | ) | |
14 |
|
15 | |||
15 | EXP_STATES = ( |
|
16 | EXP_STATES = ( | |
16 | (0,'Error'), #RED |
|
17 | (0,'Error'), #RED | |
17 | (1,'Configurated'), #BLUE |
|
18 | (1,'Configurated'), #BLUE | |
18 | (2,'Running'), #GREEN |
|
19 | (2,'Running'), #GREEN | |
19 | (3,'Waiting'), #YELLOW |
|
20 | (3,'Waiting'), #YELLOW | |
20 | (4,'Not Configured'), #WHITE |
|
21 | (4,'Not Configured'), #WHITE | |
21 | ) |
|
22 | ) | |
22 |
|
23 | |||
23 | CONF_TYPES = ( |
|
24 | CONF_TYPES = ( | |
24 | (0, 'Active'), |
|
25 | (0, 'Active'), | |
25 | (1, 'Historical'), |
|
26 | (1, 'Historical'), | |
26 | ) |
|
27 | ) | |
27 |
|
28 | |||
28 | DEV_STATES = ( |
|
29 | DEV_STATES = ( | |
29 | (0, 'No connected'), |
|
30 | (0, 'No connected'), | |
30 | (1, 'Connected'), |
|
31 | (1, 'Connected'), | |
31 | (2, 'Configured'), |
|
32 | (2, 'Configured'), | |
32 | (3, 'Running'), |
|
33 | (3, 'Running'), | |
33 | ) |
|
34 | ) | |
34 |
|
35 | |||
35 | DEV_TYPES = ( |
|
36 | DEV_TYPES = ( | |
36 | ('', 'Select a device type'), |
|
37 | ('', 'Select a device type'), | |
37 | ('rc', 'Radar Controller'), |
|
38 | ('rc', 'Radar Controller'), | |
38 | ('rc_mix', 'Radar Controller (Mix)'), |
|
39 | ('rc_mix', 'Radar Controller (Mix)'), | |
39 | ('dds', 'Direct Digital Synthesizer'), |
|
40 | ('dds', 'Direct Digital Synthesizer'), | |
40 | ('jars', 'Jicamarca Radar Acquisition System'), |
|
41 | ('jars', 'Jicamarca Radar Acquisition System'), | |
41 | ('usrp', 'Universal Software Radio Peripheral'), |
|
42 | ('usrp', 'Universal Software Radio Peripheral'), | |
42 | ('cgs', 'Clock Generator System'), |
|
43 | ('cgs', 'Clock Generator System'), | |
43 | ('abs', 'Automatic Beam Switching'), |
|
44 | ('abs', 'Automatic Beam Switching'), | |
44 | ) |
|
45 | ) | |
45 |
|
46 | |||
46 | DEV_PORTS = { |
|
47 | DEV_PORTS = { | |
47 | 'rc' : 2000, |
|
48 | 'rc' : 2000, | |
48 | 'rc_mix': 2000, |
|
49 | 'rc_mix': 2000, | |
49 | 'dds' : 2000, |
|
50 | 'dds' : 2000, | |
50 | 'jars' : 2000, |
|
51 | 'jars' : 2000, | |
51 | 'usrp' : 2000, |
|
52 | 'usrp' : 2000, | |
52 | 'cgs' : 8080, |
|
53 | 'cgs' : 8080, | |
53 | 'abs' : 8080 |
|
54 | 'abs' : 8080 | |
54 | } |
|
55 | } | |
55 |
|
56 | |||
56 | RADAR_STATES = ( |
|
57 | RADAR_STATES = ( | |
57 | (0, 'No connected'), |
|
58 | (0, 'No connected'), | |
58 | (1, 'Connected'), |
|
59 | (1, 'Connected'), | |
59 | (2, 'Configured'), |
|
60 | (2, 'Configured'), | |
60 | (3, 'Running'), |
|
61 | (3, 'Running'), | |
61 | (4, 'Scheduled'), |
|
62 | (4, 'Scheduled'), | |
62 | ) |
|
63 | ) | |
63 | # Create your models here. |
|
64 | # Create your models here. | |
64 |
|
65 | |||
65 | class Location(models.Model): |
|
66 | class Location(models.Model): | |
66 |
|
67 | |||
67 | name = models.CharField(max_length = 30) |
|
68 | name = models.CharField(max_length = 30) | |
68 | description = models.TextField(blank=True, null=True) |
|
69 | description = models.TextField(blank=True, null=True) | |
69 |
|
70 | |||
70 | class Meta: |
|
71 | class Meta: | |
71 | db_table = 'db_location' |
|
72 | db_table = 'db_location' | |
72 |
|
73 | |||
73 | def __unicode__(self): |
|
74 | def __unicode__(self): | |
74 | return u'%s' % self.name |
|
75 | return u'%s' % self.name | |
75 |
|
76 | |||
76 | def get_absolute_url(self): |
|
77 | def get_absolute_url(self): | |
77 | return reverse('url_device', args=[str(self.id)]) |
|
78 | return reverse('url_device', args=[str(self.id)]) | |
78 |
|
79 | |||
79 |
|
80 | |||
80 | class DeviceType(models.Model): |
|
81 | class DeviceType(models.Model): | |
81 |
|
82 | |||
82 | name = models.CharField(max_length = 10, choices = DEV_TYPES, default = 'rc') |
|
83 | name = models.CharField(max_length = 10, choices = DEV_TYPES, default = 'rc') | |
83 | description = models.TextField(blank=True, null=True) |
|
84 | description = models.TextField(blank=True, null=True) | |
84 |
|
85 | |||
85 | class Meta: |
|
86 | class Meta: | |
86 | db_table = 'db_device_types' |
|
87 | db_table = 'db_device_types' | |
87 |
|
88 | |||
88 | def __unicode__(self): |
|
89 | def __unicode__(self): | |
89 | return u'%s' % self.get_name_display() |
|
90 | return u'%s' % self.get_name_display() | |
90 |
|
91 | |||
91 | class Device(models.Model): |
|
92 | class Device(models.Model): | |
92 |
|
93 | |||
93 | device_type = models.ForeignKey(DeviceType, on_delete=models.CASCADE) |
|
94 | device_type = models.ForeignKey(DeviceType, on_delete=models.CASCADE) | |
94 | location = models.ForeignKey(Location, on_delete=models.CASCADE) |
|
95 | location = models.ForeignKey(Location, on_delete=models.CASCADE) | |
95 |
|
96 | |||
96 | name = models.CharField(max_length=40, default='') |
|
97 | name = models.CharField(max_length=40, default='') | |
97 | ip_address = models.GenericIPAddressField(protocol='IPv4', default='0.0.0.0') |
|
98 | ip_address = models.GenericIPAddressField(protocol='IPv4', default='0.0.0.0') | |
98 | port_address = models.PositiveSmallIntegerField(default=2000) |
|
99 | port_address = models.PositiveSmallIntegerField(default=2000) | |
99 | description = models.TextField(blank=True, null=True) |
|
100 | description = models.TextField(blank=True, null=True) | |
100 | status = models.PositiveSmallIntegerField(default=0, choices=DEV_STATES) |
|
101 | status = models.PositiveSmallIntegerField(default=0, choices=DEV_STATES) | |
101 |
|
102 | |||
102 | class Meta: |
|
103 | class Meta: | |
103 | db_table = 'db_devices' |
|
104 | db_table = 'db_devices' | |
104 |
|
105 | |||
105 | def __unicode__(self): |
|
106 | def __unicode__(self): | |
106 | return u'%s | %s' % (self.name, self.ip_address) |
|
107 | return u'%s | %s' % (self.name, self.ip_address) | |
107 |
|
108 | |||
108 | def get_status(self): |
|
109 | def get_status(self): | |
109 | return self.status |
|
110 | return self.status | |
110 |
|
111 | |||
111 | def get_absolute_url(self): |
|
112 | def get_absolute_url(self): | |
112 | return reverse('url_device', args=[str(self.id)]) |
|
113 | return reverse('url_device', args=[str(self.id)]) | |
113 |
|
114 | |||
114 |
|
115 | |||
115 | class Campaign(models.Model): |
|
116 | class Campaign(models.Model): | |
116 |
|
117 | |||
117 | template = models.BooleanField(default=False) |
|
118 | template = models.BooleanField(default=False) | |
118 | name = models.CharField(max_length=60, unique=True) |
|
119 | name = models.CharField(max_length=60, unique=True) | |
119 | start_date = models.DateTimeField(blank=True, null=True) |
|
120 | start_date = models.DateTimeField(blank=True, null=True) | |
120 | end_date = models.DateTimeField(blank=True, null=True) |
|
121 | end_date = models.DateTimeField(blank=True, null=True) | |
121 | tags = models.CharField(max_length=40) |
|
122 | tags = models.CharField(max_length=40) | |
122 | description = models.TextField(blank=True, null=True) |
|
123 | description = models.TextField(blank=True, null=True) | |
123 | experiments = models.ManyToManyField('Experiment', blank=True) |
|
124 | experiments = models.ManyToManyField('Experiment', blank=True) | |
124 |
|
125 | |||
125 | class Meta: |
|
126 | class Meta: | |
126 | db_table = 'db_campaigns' |
|
127 | db_table = 'db_campaigns' | |
127 | ordering = ('name',) |
|
128 | ordering = ('name',) | |
128 |
|
129 | |||
129 | def __unicode__(self): |
|
130 | def __unicode__(self): | |
130 | return u'%s' % (self.name) |
|
131 | return u'%s' % (self.name) | |
131 |
|
132 | |||
132 | def get_absolute_url(self): |
|
133 | def get_absolute_url(self): | |
133 | return reverse('url_campaign', args=[str(self.id)]) |
|
134 | return reverse('url_campaign', args=[str(self.id)]) | |
134 |
|
135 | |||
135 | def parms_to_dict(self): |
|
136 | def parms_to_dict(self): | |
136 |
|
137 | |||
137 | import json |
|
138 | import json | |
138 |
|
139 | |||
139 | parameters = {} |
|
140 | parameters = {} | |
140 | exp_parameters = {} |
|
141 | exp_parameters = {} | |
141 | experiments = Experiment.objects.filter(campaign = self) |
|
142 | experiments = Experiment.objects.filter(campaign = self) | |
142 |
|
143 | |||
143 | i=1 |
|
144 | i=1 | |
144 | for experiment in experiments: |
|
145 | for experiment in experiments: | |
145 | exp_parameters['experiment-'+str(i)] = json.loads(experiment.parms_to_dict()) |
|
146 | exp_parameters['experiment-'+str(i)] = json.loads(experiment.parms_to_dict()) | |
146 | i += 1 |
|
147 | i += 1 | |
147 |
|
148 | |||
148 |
|
149 | |||
149 | parameters['experimets'] =exp_parameters |
|
150 | parameters['experiments'] = exp_parameters | |
150 | parameters['end_date'] = self.end_date.strftime("%Y-%m-%d") |
|
151 | parameters['end_date'] = self.end_date.strftime("%Y-%m-%d") | |
151 | parameters['start_date'] = self.start_date.strftime("%Y-%m-%d") |
|
152 | parameters['start_date'] = self.start_date.strftime("%Y-%m-%d") | |
152 | parameters['campaign'] = self.__unicode__() |
|
153 | parameters['campaign'] = self.__unicode__() | |
|
154 | parameters['tags'] =self.tags | |||
153 |
|
155 | |||
154 | parameters = json.dumps(parameters, indent=2, sort_keys=False) |
|
156 | parameters = json.dumps(parameters, indent=2, sort_keys=False) | |
155 |
|
157 | |||
156 | return parameters |
|
158 | return parameters | |
157 |
|
159 | |||
|
160 | def import_from_file(self, fp): | |||
|
161 | ||||
|
162 | import os, json | |||
|
163 | ||||
|
164 | parms = {} | |||
|
165 | ||||
|
166 | path, ext = os.path.splitext(fp.name) | |||
|
167 | ||||
|
168 | if ext == '.json': | |||
|
169 | parms = json.load(fp) | |||
|
170 | ||||
|
171 | return parms | |||
|
172 | ||||
|
173 | def get_absolute_url(self): | |||
|
174 | return reverse('url_campaign', args=[str(self.id)]) | |||
|
175 | ||||
|
176 | def get_absolute_url_edit(self): | |||
|
177 | return reverse('url_edit_campaign', args=[str(self.id)]) | |||
|
178 | ||||
158 | def get_absolute_url_export(self): |
|
179 | def get_absolute_url_export(self): | |
159 | return reverse('url_export_campaign', args=[str(self.id)]) |
|
180 | return reverse('url_export_campaign', args=[str(self.id)]) | |
160 |
|
181 | |||
|
182 | def get_absolute_url_import(self): | |||
|
183 | return reverse('url_import_campaign', args=[str(self.id)]) | |||
|
184 | ||||
161 |
|
185 | |||
162 |
|
186 | |||
163 | class RunningExperiment(models.Model): |
|
187 | class RunningExperiment(models.Model): | |
164 | radar = models.OneToOneField('Location', on_delete=models.CASCADE) |
|
188 | radar = models.OneToOneField('Location', on_delete=models.CASCADE) | |
165 | running_experiment = models.ManyToManyField('Experiment', blank = True) |
|
189 | running_experiment = models.ManyToManyField('Experiment', blank = True) | |
166 | status = models.PositiveSmallIntegerField(default=0, choices=RADAR_STATES) |
|
190 | status = models.PositiveSmallIntegerField(default=0, choices=RADAR_STATES) | |
167 |
|
191 | |||
168 |
|
192 | |||
169 | class Experiment(models.Model): |
|
193 | class Experiment(models.Model): | |
170 |
|
194 | |||
171 | template = models.BooleanField(default=False) |
|
195 | template = models.BooleanField(default=False) | |
172 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) |
|
|||
173 | name = models.CharField(max_length=40, default='', unique=True) |
|
196 | name = models.CharField(max_length=40, default='', unique=True) | |
174 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) |
|
197 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) | |
175 | start_time = models.TimeField(default='00:00:00') |
|
198 | start_time = models.TimeField(default='00:00:00') | |
176 | end_time = models.TimeField(default='23:59:59') |
|
199 | end_time = models.TimeField(default='23:59:59') | |
177 | status = models.PositiveSmallIntegerField(default=0, choices=EXP_STATES) |
|
200 | status = models.PositiveSmallIntegerField(default=0, choices=EXP_STATES) | |
178 |
|
201 | |||
179 | class Meta: |
|
202 | class Meta: | |
180 | db_table = 'db_experiments' |
|
203 | db_table = 'db_experiments' | |
181 | ordering = ('template', 'name') |
|
204 | ordering = ('template', 'name') | |
182 |
|
205 | |||
183 | def __unicode__(self): |
|
206 | def __unicode__(self): | |
184 | if self.template: |
|
207 | if self.template: | |
185 | return u'%s (template)' % (self.name) |
|
208 | return u'%s (template)' % (self.name) | |
186 | else: |
|
209 | else: | |
187 | return u'%s' % (self.name) |
|
210 | return u'%s' % (self.name) | |
188 |
|
211 | |||
189 | @property |
|
212 | @property | |
190 | def radar(self): |
|
213 | def radar(self): | |
191 | return self.location |
|
214 | return self.location | |
192 |
|
215 | |||
193 | def clone(self, **kwargs): |
|
216 | def clone(self, **kwargs): | |
194 |
|
217 | |||
195 | confs = Configuration.objects.filter(experiment=self, type=0) |
|
218 | confs = Configuration.objects.filter(experiment=self, type=0) | |
196 | self.pk = None |
|
219 | self.pk = None | |
197 | self.name = '{} [{:%Y/%m/%d}]'.format(self.name, datetime.now()) |
|
220 | self.name = '{} [{:%Y/%m/%d}]'.format(self.name, datetime.now()) | |
198 | for attr, value in kwargs.items(): |
|
221 | for attr, value in kwargs.items(): | |
199 | setattr(self, attr, value) |
|
222 | setattr(self, attr, value) | |
200 |
|
223 | |||
201 | self.save() |
|
224 | self.save() | |
202 |
|
225 | |||
203 | for conf in confs: |
|
226 | for conf in confs: | |
204 | conf.clone(experiment=self, template=False) |
|
227 | conf.clone(experiment=self, template=False) | |
205 |
|
228 | |||
206 | return self |
|
229 | return self | |
207 |
|
230 | |||
208 | def get_status(self): |
|
231 | def get_status(self): | |
209 | configurations = Configuration.objects.filter(experiment=self) |
|
232 | configurations = Configuration.objects.filter(experiment=self) | |
210 | exp_status=[] |
|
233 | exp_status=[] | |
211 | for conf in configurations: |
|
234 | for conf in configurations: | |
212 | print conf.status_device() |
|
235 | print conf.status_device() | |
213 | exp_status.append(conf.status_device()) |
|
236 | exp_status.append(conf.status_device()) | |
214 |
|
237 | |||
215 | if not exp_status: #No Configuration |
|
238 | if not exp_status: #No Configuration | |
216 | self.status = 4 |
|
239 | self.status = 4 | |
217 | self.save() |
|
240 | self.save() | |
218 | return |
|
241 | return | |
219 |
|
242 | |||
220 | total = 1 |
|
243 | total = 1 | |
221 | for e_s in exp_status: |
|
244 | for e_s in exp_status: | |
222 | total = total*e_s |
|
245 | total = total*e_s | |
223 |
|
246 | |||
224 | if total == 0: #Error |
|
247 | if total == 0: #Error | |
225 | status = 0 |
|
248 | status = 0 | |
226 | elif total == (3**len(exp_status)): #Running |
|
249 | elif total == (3**len(exp_status)): #Running | |
227 | status = 2 |
|
250 | status = 2 | |
228 | else: |
|
251 | else: | |
229 | status = 1 #Configurated |
|
252 | status = 1 #Configurated | |
230 |
|
253 | |||
231 | self.status = status |
|
254 | self.status = status | |
232 | self.save() |
|
255 | self.save() | |
233 |
|
256 | |||
234 | def status_color(self): |
|
257 | def status_color(self): | |
235 | color = 'danger' |
|
258 | color = 'danger' | |
236 | if self.status == 0: |
|
259 | if self.status == 0: | |
237 | color = "danger" |
|
260 | color = "danger" | |
238 | elif self.status == 1: |
|
261 | elif self.status == 1: | |
239 | color = "info" |
|
262 | color = "info" | |
240 | elif self.status == 2: |
|
263 | elif self.status == 2: | |
241 | color = "success" |
|
264 | color = "success" | |
242 | elif self.status == 3: |
|
265 | elif self.status == 3: | |
243 | color = "warning" |
|
266 | color = "warning" | |
244 | else: |
|
267 | else: | |
245 | color = "muted" |
|
268 | color = "muted" | |
246 |
|
269 | |||
247 | return color |
|
270 | return color | |
248 |
|
271 | |||
249 | def get_absolute_url(self): |
|
272 | def get_absolute_url(self): | |
250 | return reverse('url_experiment', args=[str(self.id)]) |
|
273 | return reverse('url_experiment', args=[str(self.id)]) | |
251 |
|
274 | |||
252 | def parms_to_dict(self): |
|
275 | def parms_to_dict(self): | |
253 |
|
276 | |||
254 | import json |
|
277 | import json | |
255 |
|
278 | |||
256 | configurations = Configuration.objects.filter(experiment=self) |
|
279 | configurations = Configuration.objects.filter(experiment=self) | |
257 | conf_parameters = {} |
|
280 | conf_parameters = {} | |
258 | parameters={} |
|
281 | parameters={} | |
259 |
|
282 | |||
260 | for configuration in configurations: |
|
283 | for configuration in configurations: | |
261 | if 'cgs' in configuration.device.device_type.name: |
|
284 | if 'cgs' in configuration.device.device_type.name: | |
262 | conf_parameters['cgs'] = configuration.parms_to_dict() |
|
285 | conf_parameters['cgs'] = configuration.parms_to_dict() | |
263 | if 'dds' in configuration.device.device_type.name: |
|
286 | if 'dds' in configuration.device.device_type.name: | |
264 | conf_parameters['dds'] = configuration.parms_to_dict() |
|
287 | conf_parameters['dds'] = configuration.parms_to_dict() | |
265 | if 'rc' in configuration.device.device_type.name: |
|
288 | if 'rc' in configuration.device.device_type.name: | |
266 | conf_parameters['rc'] = configuration.parms_to_dict() |
|
289 | conf_parameters['rc'] = configuration.parms_to_dict() | |
267 | if 'jars' in configuration.device.device_type.name: |
|
290 | if 'jars' in configuration.device.device_type.name: | |
268 | conf_parameters['jars'] = configuration.parms_to_dict() |
|
291 | conf_parameters['jars'] = configuration.parms_to_dict() | |
269 | if 'usrp' in configuration.device.device_type.name: |
|
292 | if 'usrp' in configuration.device.device_type.name: | |
270 | conf_parameters['usrp'] = configuration.parms_to_dict() |
|
293 | conf_parameters['usrp'] = configuration.parms_to_dict() | |
271 | if 'abs' in configuration.device.device_type.name: |
|
294 | if 'abs' in configuration.device.device_type.name: | |
272 | conf_parameters['abs'] = configuration.parms_to_dict() |
|
295 | conf_parameters['abs'] = configuration.parms_to_dict() | |
273 |
|
296 | |||
274 | parameters['configurations'] = conf_parameters |
|
297 | parameters['configurations'] = conf_parameters | |
275 |
parameters['end_time'] = self.end_time.strftime("% |
|
298 | parameters['end_time'] = self.end_time.strftime("%H:%M:%S") | |
276 |
parameters['start_time'] = self.start_time.strftime("% |
|
299 | parameters['start_time'] = self.start_time.strftime("%H:%M:%S") | |
277 | parameters['radar'] = self.radar.name |
|
300 | parameters['radar'] = self.radar.name | |
278 | parameters['experiment'] = self.name |
|
301 | parameters['experiment'] = self.name | |
279 | parameters = json.dumps(parameters, indent=2) |
|
302 | parameters = json.dumps(parameters, indent=2) | |
280 | #parameters = json.dumps(parameters) |
|
|||
281 |
|
303 | |||
282 | return parameters |
|
304 | return parameters | |
283 |
|
305 | |||
|
306 | def import_from_file(self, fp): | |||
|
307 | ||||
|
308 | import os, json | |||
|
309 | ||||
|
310 | parms = {} | |||
|
311 | ||||
|
312 | path, ext = os.path.splitext(fp.name) | |||
|
313 | ||||
|
314 | if ext == '.json': | |||
|
315 | parms = json.load(fp) | |||
|
316 | ||||
|
317 | return parms | |||
|
318 | ||||
|
319 | def dict_to_parms(self, parms, CONF_MODELS): | |||
|
320 | ||||
|
321 | #self.name = parameters['experiment'] | |||
|
322 | #self.location = parameters['radar'] | |||
|
323 | #self.start_time = parameters['start_time'] | |||
|
324 | #self.end_time = parameters['end_time'] | |||
|
325 | ||||
|
326 | configurations = Configuration.objects.filter(experiment=self) | |||
|
327 | ||||
|
328 | if configurations: | |||
|
329 | for configuration in configurations: | |||
|
330 | configuration.delete() | |||
|
331 | ||||
|
332 | for conf_type in parms['configurations']: | |||
|
333 | #--For ABS Device: | |||
|
334 | #--For USRP Device: | |||
|
335 | #--For JARS Device: | |||
|
336 | #--For RC Device: | |||
|
337 | if conf_type == 'rc': | |||
|
338 | device = get_object_or_404(Device, pk=parms['configurations']['rc']['device_id']) | |||
|
339 | DevConfModel = CONF_MODELS[conf_type] | |||
|
340 | confrc_form = DevConfModel( | |||
|
341 | experiment = self, | |||
|
342 | name = 'RC', | |||
|
343 | device=device, | |||
|
344 | ) | |||
|
345 | confrc_form.dict_to_parms(parms['configurations']['rc']) | |||
|
346 | confrc_form.save() | |||
|
347 | #--For DDS Device: | |||
|
348 | if conf_type == 'dds': | |||
|
349 | device = get_object_or_404(Device, pk=parms['configurations']['dds']['device_id']) | |||
|
350 | DevConfModel = CONF_MODELS[conf_type] | |||
|
351 | confdds_form = DevConfModel( | |||
|
352 | experiment = self, | |||
|
353 | name = 'DDS', | |||
|
354 | device=device, | |||
|
355 | ) | |||
|
356 | confdds_form.dict_to_parms(parms['configurations']['dds']) | |||
|
357 | confdds_form.save() | |||
|
358 | #--For CGS Device: | |||
|
359 | if conf_type == 'cgs': | |||
|
360 | device = get_object_or_404(Device, pk=parms['configurations']['cgs']['device_id']) | |||
|
361 | DevConfModel = CONF_MODELS[conf_type] | |||
|
362 | confcgs_form = DevConfModel( | |||
|
363 | experiment = self, | |||
|
364 | name = 'CGS', | |||
|
365 | device=device, | |||
|
366 | ) | |||
|
367 | confcgs_form.dict_to_parms(parms['configurations']['cgs']) | |||
|
368 | confcgs_form.save() | |||
|
369 | ||||
|
370 | def get_absolute_url_edit(self): | |||
|
371 | return reverse('url_edit_experiment', args=[str(self.id)]) | |||
|
372 | ||||
|
373 | def get_absolute_url_import(self): | |||
|
374 | return reverse('url_import_experiment', args=[str(self.id)]) | |||
|
375 | ||||
284 | def get_absolute_url_export(self): |
|
376 | def get_absolute_url_export(self): | |
285 | return reverse('url_export_experiment', args=[str(self.id)]) |
|
377 | return reverse('url_export_experiment', args=[str(self.id)]) | |
286 |
|
378 | |||
287 |
|
379 | |||
288 | class Configuration(PolymorphicModel): |
|
380 | class Configuration(PolymorphicModel): | |
289 |
|
381 | |||
290 | template = models.BooleanField(default=False) |
|
382 | template = models.BooleanField(default=False) | |
291 |
|
383 | |||
292 | name = models.CharField(verbose_name="Configuration Name", max_length=40, default='') |
|
384 | name = models.CharField(verbose_name="Configuration Name", max_length=40, default='') | |
293 |
|
385 | |||
294 | experiment = models.ForeignKey('Experiment', null=True, blank=True, on_delete=models.CASCADE) |
|
386 | experiment = models.ForeignKey('Experiment', null=True, blank=True, on_delete=models.CASCADE) | |
295 | device = models.ForeignKey(Device, null=True, on_delete=models.CASCADE) |
|
387 | device = models.ForeignKey(Device, null=True, on_delete=models.CASCADE) | |
296 |
|
388 | |||
297 | type = models.PositiveSmallIntegerField(default=0, choices=CONF_TYPES) |
|
389 | type = models.PositiveSmallIntegerField(default=0, choices=CONF_TYPES) | |
298 |
|
390 | |||
299 | created_date = models.DateTimeField(auto_now_add=True) |
|
391 | created_date = models.DateTimeField(auto_now_add=True) | |
300 | programmed_date = models.DateTimeField(auto_now=True) |
|
392 | programmed_date = models.DateTimeField(auto_now=True) | |
301 |
|
393 | |||
302 | parameters = models.TextField(default='{}') |
|
394 | parameters = models.TextField(default='{}') | |
303 |
|
395 | |||
304 | message = "" |
|
396 | message = "" | |
305 |
|
397 | |||
306 | class Meta: |
|
398 | class Meta: | |
307 | db_table = 'db_configurations' |
|
399 | db_table = 'db_configurations' | |
308 |
|
400 | |||
309 | def __unicode__(self): |
|
401 | def __unicode__(self): | |
310 |
|
402 | |||
311 | return u'[%s]: %s' % (self.device.name, self.name) |
|
403 | return u'[%s]: %s' % (self.device.name, self.name) | |
312 |
|
404 | |||
313 | def clone(self, **kwargs): |
|
405 | def clone(self, **kwargs): | |
314 |
|
406 | |||
315 | self.pk = None |
|
407 | self.pk = None | |
316 | self.id = None |
|
408 | self.id = None | |
317 | for attr, value in kwargs.items(): |
|
409 | for attr, value in kwargs.items(): | |
318 | setattr(self, attr, value) |
|
410 | setattr(self, attr, value) | |
319 |
|
411 | |||
320 | self.save() |
|
412 | self.save() | |
321 |
|
413 | |||
322 | return self |
|
414 | return self | |
323 |
|
415 | |||
324 | def parms_to_dict(self): |
|
416 | def parms_to_dict(self): | |
325 |
|
417 | |||
326 | parameters = {} |
|
418 | parameters = {} | |
327 |
|
419 | |||
328 | for key in self.__dict__.keys(): |
|
420 | for key in self.__dict__.keys(): | |
329 | parameters[key] = getattr(self, key) |
|
421 | parameters[key] = getattr(self, key) | |
330 |
|
422 | |||
331 | return parameters |
|
423 | return parameters | |
332 |
|
424 | |||
333 | def parms_to_text(self): |
|
425 | def parms_to_text(self): | |
334 |
|
426 | |||
335 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
427 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
336 |
|
428 | |||
337 | return '' |
|
429 | return '' | |
338 |
|
430 | |||
339 | def parms_to_binary(self): |
|
431 | def parms_to_binary(self): | |
340 |
|
432 | |||
341 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
433 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
342 |
|
434 | |||
343 | return '' |
|
435 | return '' | |
344 |
|
436 | |||
345 | def dict_to_parms(self, parameters): |
|
437 | def dict_to_parms(self, parameters): | |
346 |
|
438 | |||
347 | if type(parameters) != type({}): |
|
439 | if type(parameters) != type({}): | |
348 | return |
|
440 | return | |
349 |
|
441 | |||
350 | for key in parameters.keys(): |
|
442 | for key in parameters.keys(): | |
351 | setattr(self, key, parameters[key]) |
|
443 | setattr(self, key, parameters[key]) | |
352 |
|
444 | |||
353 | def export_to_file(self, format="json"): |
|
445 | def export_to_file(self, format="json"): | |
354 |
|
446 | |||
355 | import json |
|
447 | import json | |
356 |
|
448 | |||
357 | content_type = '' |
|
449 | content_type = '' | |
358 |
|
450 | |||
359 | if format == 'text': |
|
451 | if format == 'text': | |
360 | content_type = 'text/plain' |
|
452 | content_type = 'text/plain' | |
361 | filename = '%s_%s.%s' %(self.device.device_type.name, self.name, self.device.device_type.name) |
|
453 | filename = '%s_%s.%s' %(self.device.device_type.name, self.name, self.device.device_type.name) | |
362 | content = self.parms_to_text() |
|
454 | content = self.parms_to_text() | |
363 |
|
455 | |||
364 | if format == 'binary': |
|
456 | if format == 'binary': | |
365 | content_type = 'application/octet-stream' |
|
457 | content_type = 'application/octet-stream' | |
366 | filename = '%s_%s.bin' %(self.device.device_type.name, self.name) |
|
458 | filename = '%s_%s.bin' %(self.device.device_type.name, self.name) | |
367 | content = self.parms_to_binary() |
|
459 | content = self.parms_to_binary() | |
368 |
|
460 | |||
369 | if not content_type: |
|
461 | if not content_type: | |
370 | content_type = 'application/json' |
|
462 | content_type = 'application/json' | |
371 | filename = '%s_%s.json' %(self.device.device_type.name, self.name) |
|
463 | filename = '%s_%s.json' %(self.device.device_type.name, self.name) | |
372 | content = json.dumps(self.parms_to_dict(), indent=2) |
|
464 | content = json.dumps(self.parms_to_dict(), indent=2) | |
373 |
|
465 | |||
374 | fields = {'content_type':content_type, |
|
466 | fields = {'content_type':content_type, | |
375 | 'filename':filename, |
|
467 | 'filename':filename, | |
376 | 'content':content |
|
468 | 'content':content | |
377 | } |
|
469 | } | |
378 |
|
470 | |||
379 | return fields |
|
471 | return fields | |
380 |
|
472 | |||
381 | def import_from_file(self, fp): |
|
473 | def import_from_file(self, fp): | |
382 |
|
474 | |||
383 | import os, json |
|
475 | import os, json | |
384 |
|
476 | |||
385 | parms = {} |
|
477 | parms = {} | |
386 |
|
478 | |||
387 | path, ext = os.path.splitext(fp.name) |
|
479 | path, ext = os.path.splitext(fp.name) | |
388 |
|
480 | |||
389 | if ext == '.json': |
|
481 | if ext == '.json': | |
390 | parms = json.load(fp) |
|
482 | parms = json.load(fp) | |
391 |
|
483 | |||
392 | return parms |
|
484 | return parms | |
393 |
|
485 | |||
394 | def status_device(self): |
|
486 | def status_device(self): | |
395 |
|
487 | |||
396 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
488 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
397 |
|
489 | |||
398 | return None |
|
490 | return None | |
399 |
|
491 | |||
400 | def stop_device(self): |
|
492 | def stop_device(self): | |
401 |
|
493 | |||
402 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
494 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
403 |
|
495 | |||
404 | return None |
|
496 | return None | |
405 |
|
497 | |||
406 | def start_device(self): |
|
498 | def start_device(self): | |
407 |
|
499 | |||
408 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
500 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
409 |
|
501 | |||
410 | return None |
|
502 | return None | |
411 |
|
503 | |||
412 | def write_device(self, parms): |
|
504 | def write_device(self, parms): | |
413 |
|
505 | |||
414 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
506 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
415 |
|
507 | |||
416 | return None |
|
508 | return None | |
417 |
|
509 | |||
418 | def read_device(self): |
|
510 | def read_device(self): | |
419 |
|
511 | |||
420 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
512 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
421 |
|
513 | |||
422 | return None |
|
514 | return None | |
423 |
|
515 | |||
424 | def get_absolute_url(self): |
|
516 | def get_absolute_url(self): | |
425 | return reverse('url_%s_conf' % self.device.device_type.name, args=[str(self.id)]) |
|
517 | return reverse('url_%s_conf' % self.device.device_type.name, args=[str(self.id)]) | |
426 |
|
518 | |||
427 | def get_absolute_url_edit(self): |
|
519 | def get_absolute_url_edit(self): | |
428 | return reverse('url_edit_%s_conf' % self.device.device_type.name, args=[str(self.id)]) |
|
520 | return reverse('url_edit_%s_conf' % self.device.device_type.name, args=[str(self.id)]) | |
429 |
|
521 | |||
430 | def get_absolute_url_import(self): |
|
522 | def get_absolute_url_import(self): | |
431 | return reverse('url_import_dev_conf', args=[str(self.id)]) |
|
523 | return reverse('url_import_dev_conf', args=[str(self.id)]) | |
432 |
|
524 | |||
433 | def get_absolute_url_export(self): |
|
525 | def get_absolute_url_export(self): | |
434 | return reverse('url_export_dev_conf', args=[str(self.id)]) |
|
526 | return reverse('url_export_dev_conf', args=[str(self.id)]) | |
435 |
|
527 | |||
436 | def get_absolute_url_write(self): |
|
528 | def get_absolute_url_write(self): | |
437 | return reverse('url_write_dev_conf', args=[str(self.id)]) |
|
529 | return reverse('url_write_dev_conf', args=[str(self.id)]) | |
438 |
|
530 | |||
439 | def get_absolute_url_read(self): |
|
531 | def get_absolute_url_read(self): | |
440 | return reverse('url_read_dev_conf', args=[str(self.id)]) |
|
532 | return reverse('url_read_dev_conf', args=[str(self.id)]) | |
441 |
|
533 | |||
442 | def get_absolute_url_start(self): |
|
534 | def get_absolute_url_start(self): | |
443 | return reverse('url_start_dev_conf', args=[str(self.id)]) |
|
535 | return reverse('url_start_dev_conf', args=[str(self.id)]) | |
444 |
|
536 | |||
445 | def get_absolute_url_stop(self): |
|
537 | def get_absolute_url_stop(self): | |
446 | return reverse('url_stop_dev_conf', args=[str(self.id)]) |
|
538 | return reverse('url_stop_dev_conf', args=[str(self.id)]) | |
447 |
|
539 | |||
448 | def get_absolute_url_status(self): |
|
540 | def get_absolute_url_status(self): | |
449 | return reverse('url_status_dev_conf', args=[str(self.id)]) No newline at end of file |
|
541 | return reverse('url_status_dev_conf', args=[str(self.id)]) |
@@ -1,107 +1,107 | |||||
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 |
|
15 | |||
16 | {% block menu-actions %} |
|
16 | {% block menu-actions %} | |
17 | <span class=" dropdown pull-right"> |
|
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> |
|
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"> |
|
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> |
|
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" aria-hidden="true"></span> Delete</a></li> |
|
21 | <li><a href="{% url 'url_delete_campaign' campaign.id %}"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Delete</a></li> | |
22 |
<li><a href="{{ |
|
22 | <li><a href="{{ campaign.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> |
|
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 %} |
|
24 | {% block extra-menu-actions %} | |
25 | {% endblock %} |
|
25 | {% endblock %} | |
26 | <li><a>----------------</a></li> |
|
26 | <li><a>----------------</a></li> | |
27 | <!--<li><a href="{{ dev_conf.get_absolute_url_status }}"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Status</a></li> |
|
27 | <!--<li><a href="{{ dev_conf.get_absolute_url_status }}"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Status</a></li> | |
28 | {% if not no_play %} |
|
28 | {% if not no_play %} | |
29 | <li><a href="{{ dev_conf.get_absolute_url_start}}"><span class="glyphicon glyphicon-play" aria-hidden="true"></span> Start</a></li> |
|
29 | <li><a href="{{ dev_conf.get_absolute_url_start}}"><span class="glyphicon glyphicon-play" aria-hidden="true"></span> Start</a></li> | |
30 | <li><a href="{{ dev_conf.get_absolute_url_stop }}"><span class="glyphicon glyphicon-stop" aria-hidden="true"></span> Stop</a></li> |
|
30 | <li><a href="{{ dev_conf.get_absolute_url_stop }}"><span class="glyphicon glyphicon-stop" aria-hidden="true"></span> Stop</a></li> | |
31 | {% endif %} |
|
31 | {% endif %} | |
32 | <li><a href="{{ dev_conf.get_absolute_url_write }}"><span class="glyphicon glyphicon-download" aria-hidden="true"></span> Write</a></li> |
|
32 | <li><a href="{{ dev_conf.get_absolute_url_write }}"><span class="glyphicon glyphicon-download" aria-hidden="true"></span> Write</a></li> | |
33 | <li><a href="{{ dev_conf.get_absolute_url_read }}"><span class="glyphicon glyphicon-upload" aria-hidden="true"></span> Read</a></li>--> |
|
33 | <li><a href="{{ dev_conf.get_absolute_url_read }}"><span class="glyphicon glyphicon-upload" aria-hidden="true"></span> Read</a></li>--> | |
34 | </ul> |
|
34 | </ul> | |
35 | </span> |
|
35 | </span> | |
36 | {% endblock %} |
|
36 | {% endblock %} | |
37 |
|
37 | |||
38 | <table class="table table-bordered"> |
|
38 | <table class="table table-bordered"> | |
39 | {% for key in campaign_keys %} |
|
39 | {% for key in campaign_keys %} | |
40 | <tr><th>{{key|title}}</th><td>{{campaign|attr:key}}</td></tr> |
|
40 | <tr><th>{{key|title}}</th><td>{{campaign|attr:key}}</td></tr> | |
41 | {% endfor %} |
|
41 | {% endfor %} | |
42 | </table> |
|
42 | </table> | |
43 |
|
43 | |||
44 | <!--<button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_export">Export</button>--> |
|
44 | <!--<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_edit">Edit</button>--> |
|
45 | <!--<button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_edit">Edit</button>--> | |
46 |
|
46 | |||
47 | <br></br> |
|
47 | <br></br> | |
48 | <br></br> |
|
48 | <br></br> | |
49 |
|
49 | |||
50 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> |
|
50 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> | |
51 |
|
51 | |||
52 | <div class="panel panel-default"> |
|
52 | <div class="panel panel-default"> | |
53 | <div class="panel-heading" role="tab" id="headingTwo"> |
|
53 | <div class="panel-heading" role="tab" id="headingTwo"> | |
54 | <h4 class="panel-title"> |
|
54 | <h4 class="panel-title"> | |
55 | <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo"> |
|
55 | <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo"> | |
56 | Experiment List |
|
56 | Experiment List | |
57 | </a> |
|
57 | </a> | |
58 | </h4> |
|
58 | </h4> | |
59 | </div> |
|
59 | </div> | |
60 |
|
60 | |||
61 | <div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> |
|
61 | <div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> | |
62 | <div class="panel-body"> |
|
62 | <div class="panel-body"> | |
63 | <table class="table table-hover"> |
|
63 | <table class="table table-hover"> | |
64 | <tr> |
|
64 | <tr> | |
65 | <th>#</th> |
|
65 | <th>#</th> | |
66 | {% for header in experiment_keys %} |
|
66 | {% for header in experiment_keys %} | |
67 | <th>{{ header|title }}</th> |
|
67 | <th>{{ header|title }}</th> | |
68 | {% endfor%} |
|
68 | {% endfor%} | |
69 | </tr> |
|
69 | </tr> | |
70 | {% for item in experiments %} |
|
70 | {% for item in experiments %} | |
71 | <tr class="clickable-row" data-href="{% url 'url_experiment' item.id %}"> |
|
71 | <tr class="clickable-row" data-href="{% url 'url_experiment' item.id %}"> | |
72 | <td>{{ forloop.counter }}</td> |
|
72 | <td>{{ forloop.counter }}</td> | |
73 | {% for key in experiment_keys %} |
|
73 | {% for key in experiment_keys %} | |
74 | <td>{{ item|attr:key }}</td> |
|
74 | <td>{{ item|attr:key }}</td> | |
75 | {% endfor %} |
|
75 | {% endfor %} | |
76 | </tr> |
|
76 | </tr> | |
77 | {% endfor %} |
|
77 | {% endfor %} | |
78 | </table> |
|
78 | </table> | |
79 | </div> |
|
79 | </div> | |
80 | </div> |
|
80 | </div> | |
81 | </div> |
|
81 | </div> | |
82 | </div> |
|
82 | </div> | |
83 | <br> |
|
83 | <br> | |
84 | <!--<button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_mix">Mix Experiments</button>--> |
|
84 | <!--<button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_mix">Mix Experiments</button>--> | |
85 | {% endblock %} |
|
85 | {% endblock %} | |
86 |
|
86 | |||
87 | {% block sidebar%} |
|
87 | {% block sidebar%} | |
88 | {% include "sidebar_devices.html" %} |
|
88 | {% include "sidebar_devices.html" %} | |
89 | {% endblock %} |
|
89 | {% endblock %} | |
90 |
|
90 | |||
91 | {% block extra-js%} |
|
91 | {% block extra-js%} | |
92 | <script type="text/javascript"> |
|
92 | <script type="text/javascript"> | |
93 |
|
93 | |||
94 | $(".clickable-row").click(function() { |
|
94 | $(".clickable-row").click(function() { | |
95 | document.location = $(this).data("href"); |
|
95 | document.location = $(this).data("href"); | |
96 | }); |
|
96 | }); | |
97 |
|
97 | |||
98 | // $("#bt_edit").click(function() { |
|
98 | // $("#bt_edit").click(function() { | |
99 | // document.location = "{% url 'url_edit_campaign' campaign.id %}"; |
|
99 | // document.location = "{% url 'url_edit_campaign' campaign.id %}"; | |
100 | // }); |
|
100 | // }); | |
101 |
|
101 | |||
102 | $("#bt_mix").click(function() { |
|
102 | $("#bt_mix").click(function() { | |
103 |
|
103 | |||
104 | }); |
|
104 | }); | |
105 |
|
105 | |||
106 | </script> |
|
106 | </script> | |
107 | {% endblock %} No newline at end of file |
|
107 | {% endblock %} |
@@ -1,95 +1,96 | |||||
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 |
|
15 | |||
16 | {% block menu-actions %} |
|
16 | {% block menu-actions %} | |
17 | <span class=" dropdown pull-right"> |
|
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> |
|
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"> |
|
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> |
|
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" aria-hidden="true"></span> Delete</a></li> |
|
21 | <li><a href="{% url 'url_delete_experiment' experiment.id %}"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Delete</a></li> | |
22 |
<li><a href="{{ |
|
22 | <li><a href="{{ experiment.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> |
|
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 %} |
|
24 | {% block extra-menu-actions %} | |
25 | {% endblock %} |
|
25 | {% endblock %} | |
26 | <li><a>----------------</a></li> |
|
26 | <li><a>----------------</a></li> | |
27 | <li><a href="{% url 'url_mix_experiment' experiment.id %}"><span class="glyphicon glyphicon-random" aria-hidden="true"></span> Mix RC Configurations </a></li> |
|
27 | <li><a href="{% url 'url_mix_experiment' experiment.id %}"><span class="glyphicon glyphicon-random" aria-hidden="true"></span> Mix RC Configurations </a></li> | |
28 | <li><a href="{% url 'url_add_dev_conf' experiment.id %}"><span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span> Add Configuration</a></li> |
|
28 | <li><a href="{% url 'url_add_dev_conf' experiment.id %}"><span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span> Add Configuration</a></li> | |
|
29 | ||||
29 | </ul> |
|
30 | </ul> | |
30 | </span> |
|
31 | </span> | |
31 | {% endblock %} |
|
32 | {% endblock %} | |
32 |
|
33 | |||
33 | <table class="table table-bordered"> |
|
34 | <table class="table table-bordered"> | |
34 | {% for key in experiment_keys %} |
|
35 | {% for key in experiment_keys %} | |
35 | <tr><th>{{key|title}}</th><td>{{experiment|attr:key}}</td></tr> |
|
36 | <tr><th>{{key|title}}</th><td>{{experiment|attr:key}}</td></tr> | |
36 | {% endfor %} |
|
37 | {% endfor %} | |
37 | </table> |
|
38 | </table> | |
38 | <br></br> |
|
39 | <br></br> | |
39 | <br></br> |
|
40 | <br></br> | |
40 |
|
41 | |||
41 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> |
|
42 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> | |
42 |
|
43 | |||
43 | <div class="panel panel-default"> |
|
44 | <div class="panel panel-default"> | |
44 | <div class="panel-heading" role="tab" id="headingTwo"> |
|
45 | <div class="panel-heading" role="tab" id="headingTwo"> | |
45 | <h4 class="panel-title"> |
|
46 | <h4 class="panel-title"> | |
46 | <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseThree"> |
|
47 | <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseThree"> | |
47 | Device Configurations |
|
48 | Device Configurations | |
48 | </a> |
|
49 | </a> | |
49 | </h4> |
|
50 | </h4> | |
50 | </div> |
|
51 | </div> | |
51 | <div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> |
|
52 | <div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> | |
52 | <div class="panel-body"> |
|
53 | <div class="panel-body"> | |
53 | <table class="table table-hover"> |
|
54 | <table class="table table-hover"> | |
54 | <tr> |
|
55 | <tr> | |
55 | <th>#</th> |
|
56 | <th>#</th> | |
56 | {% for key in configuration_keys %} |
|
57 | {% for key in configuration_keys %} | |
57 | <th>{{ key|title }}</th> |
|
58 | <th>{{ key|title }}</th> | |
58 | {% endfor%} |
|
59 | {% endfor%} | |
59 | </tr> |
|
60 | </tr> | |
60 | {% for item in configurations %} |
|
61 | {% for item in configurations %} | |
61 | <tr class="clickable-row" data-href="{{item.get_absolute_url}}"> |
|
62 | <tr class="clickable-row" data-href="{{item.get_absolute_url}}"> | |
62 | <td>{{ forloop.counter }}</td> |
|
63 | <td>{{ forloop.counter }}</td> | |
63 | {% for key in configuration_keys %} |
|
64 | {% for key in configuration_keys %} | |
64 | <td>{{ item|value:key }}</td> |
|
65 | <td>{{ item|value:key }}</td> | |
65 | {% endfor %} |
|
66 | {% endfor %} | |
66 | </tr> |
|
67 | </tr> | |
67 | {% endfor %} |
|
68 | {% endfor %} | |
68 | </table> |
|
69 | </table> | |
69 | </div> |
|
70 | </div> | |
70 | </div> |
|
71 | </div> | |
71 | </div> |
|
72 | </div> | |
72 | </div> |
|
73 | </div> | |
73 | {% endblock %} |
|
74 | {% endblock %} | |
74 |
|
75 | |||
75 | {% block sidebar%} |
|
76 | {% block sidebar%} | |
76 | {% include "sidebar_devices.html" %} |
|
77 | {% include "sidebar_devices.html" %} | |
77 | {% endblock %} |
|
78 | {% endblock %} | |
78 |
|
79 | |||
79 | {% block extra-js%} |
|
80 | {% block extra-js%} | |
80 | <script type="text/javascript"> |
|
81 | <script type="text/javascript"> | |
81 |
|
82 | |||
82 | $(".clickable-row").click(function() { |
|
83 | $(".clickable-row").click(function() { | |
83 | document.location = $(this).data("href"); |
|
84 | document.location = $(this).data("href"); | |
84 | }); |
|
85 | }); | |
85 |
|
86 | |||
86 | $("#bt_edit").click(function() { |
|
87 | $("#bt_edit").click(function() { | |
87 | document.location = "{% url 'url_edit_experiment' experiment.id%}"; |
|
88 | document.location = "{% url 'url_edit_experiment' experiment.id%}"; | |
88 | }); |
|
89 | }); | |
89 |
|
90 | |||
90 | $("#bt_add_conf").click(function() { |
|
91 | $("#bt_add_conf").click(function() { | |
91 | document.location = "{% url 'url_add_dev_conf' experiment.id %}"; |
|
92 | document.location = "{% url 'url_add_dev_conf' experiment.id %}"; | |
92 | }); |
|
93 | }); | |
93 |
|
94 | |||
94 | </script> |
|
95 | </script> | |
95 | {% endblock %} No newline at end of file |
|
96 | {% endblock %} |
@@ -1,55 +1,57 | |||||
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 | url(r'^campaign/(?P<id_camp>-?\d+)/export/$', 'apps.main.views.campaign_export', name='url_export_campaign'), | |
|
22 | url(r'^campaign/(?P<id_camp>-?\d+)/import/$', 'apps.main.views.campaign_import', name='url_import_campaign'), | |||
22 |
|
23 | |||
23 | url(r'^experiment/new/$', 'apps.main.views.experiment_new', name='url_add_experiment'), |
|
24 | url(r'^experiment/new/$', 'apps.main.views.experiment_new', name='url_add_experiment'), | |
24 | url(r'^experiment/$', 'apps.main.views.experiments', name='url_experiments'), |
|
25 | url(r'^experiment/$', 'apps.main.views.experiments', name='url_experiments'), | |
25 | url(r'^experiment/(?P<id_exp>-?\d+)/$', 'apps.main.views.experiment', name='url_experiment'), |
|
26 | url(r'^experiment/(?P<id_exp>-?\d+)/$', 'apps.main.views.experiment', name='url_experiment'), | |
26 | url(r'^experiment/(?P<id_exp>-?\d+)/edit/$', 'apps.main.views.experiment_edit', name='url_edit_experiment'), |
|
27 | url(r'^experiment/(?P<id_exp>-?\d+)/edit/$', 'apps.main.views.experiment_edit', name='url_edit_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+)/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'), |
|
29 | url(r'^experiment/(?P<id_exp>-?\d+)/export/$', 'apps.main.views.experiment_export', name='url_export_experiment'), | |
|
30 | url(r'^experiment/(?P<id_exp>-?\d+)/import/$', 'apps.main.views.experiment_import', name='url_import_experiment'), | |||
29 | url(r'^experiment/(?P<id_exp>-?\d+)/mix/$', 'apps.main.views.experiment_mix', name='url_mix_experiment'), |
|
31 | url(r'^experiment/(?P<id_exp>-?\d+)/mix/$', 'apps.main.views.experiment_mix', name='url_mix_experiment'), | |
30 | url(r'^experiment/(?P<id_exp>-?\d+)/mix/delete/$', 'apps.main.views.experiment_mix_delete', name='url_delete_mix_experiment'), |
|
32 | url(r'^experiment/(?P<id_exp>-?\d+)/mix/delete/$', 'apps.main.views.experiment_mix_delete', name='url_delete_mix_experiment'), | |
31 |
|
33 | |||
32 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), |
|
34 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), | |
33 | 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'), |
|
35 | 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'), | |
34 | url(r'^dev_conf/$', 'apps.main.views.dev_confs', name='url_dev_confs'), |
|
36 | url(r'^dev_conf/$', 'apps.main.views.dev_confs', name='url_dev_confs'), | |
35 | url(r'^dev_conf/(?P<id_conf>-?\d+)/$', 'apps.main.views.dev_conf', name='url_dev_conf'), |
|
37 | url(r'^dev_conf/(?P<id_conf>-?\d+)/$', 'apps.main.views.dev_conf', name='url_dev_conf'), | |
36 | url(r'^dev_conf/(?P<id_conf>-?\d+)/edit/$', 'apps.main.views.dev_conf_edit', name='url_edit_dev_conf'), |
|
38 | url(r'^dev_conf/(?P<id_conf>-?\d+)/edit/$', 'apps.main.views.dev_conf_edit', name='url_edit_dev_conf'), | |
37 | url(r'^dev_conf/(?P<id_conf>-?\d+)/delete/$', 'apps.main.views.dev_conf_delete', name='url_delete_dev_conf'), |
|
39 | url(r'^dev_conf/(?P<id_conf>-?\d+)/delete/$', 'apps.main.views.dev_conf_delete', name='url_delete_dev_conf'), | |
38 |
|
40 | |||
39 | url(r'^dev_conf/(?P<id_conf>-?\d+)/write/$', 'apps.main.views.dev_conf_write', name='url_write_dev_conf'), |
|
41 | url(r'^dev_conf/(?P<id_conf>-?\d+)/write/$', 'apps.main.views.dev_conf_write', name='url_write_dev_conf'), | |
40 | url(r'^dev_conf/(?P<id_conf>-?\d+)/read/$', 'apps.main.views.dev_conf_read', name='url_read_dev_conf'), |
|
42 | url(r'^dev_conf/(?P<id_conf>-?\d+)/read/$', 'apps.main.views.dev_conf_read', name='url_read_dev_conf'), | |
41 | url(r'^dev_conf/(?P<id_conf>-?\d+)/import/$', 'apps.main.views.dev_conf_import', name='url_import_dev_conf'), |
|
43 | url(r'^dev_conf/(?P<id_conf>-?\d+)/import/$', 'apps.main.views.dev_conf_import', name='url_import_dev_conf'), | |
42 | url(r'^dev_conf/(?P<id_conf>-?\d+)/export/$', 'apps.main.views.dev_conf_export', name='url_export_dev_conf'), |
|
44 | url(r'^dev_conf/(?P<id_conf>-?\d+)/export/$', 'apps.main.views.dev_conf_export', name='url_export_dev_conf'), | |
43 | url(r'^dev_conf/(?P<id_conf>-?\d+)/start/$', 'apps.main.views.dev_conf_start', name='url_start_dev_conf'), |
|
45 | url(r'^dev_conf/(?P<id_conf>-?\d+)/start/$', 'apps.main.views.dev_conf_start', name='url_start_dev_conf'), | |
44 | url(r'^dev_conf/(?P<id_conf>-?\d+)/stop/$', 'apps.main.views.dev_conf_stop', name='url_stop_dev_conf'), |
|
46 | url(r'^dev_conf/(?P<id_conf>-?\d+)/stop/$', 'apps.main.views.dev_conf_stop', name='url_stop_dev_conf'), | |
45 | url(r'^dev_conf/(?P<id_conf>-?\d+)/status/$', 'apps.main.views.dev_conf_status', name='url_status_dev_conf'), |
|
47 | url(r'^dev_conf/(?P<id_conf>-?\d+)/status/$', 'apps.main.views.dev_conf_status', name='url_status_dev_conf'), | |
46 |
|
48 | |||
47 | url(r'^operation/$', 'apps.main.views.operation', name='url_operation'), |
|
49 | url(r'^operation/$', 'apps.main.views.operation', name='url_operation'), | |
48 | url(r'^operation/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation', name='url_operation'), |
|
50 | url(r'^operation/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation', name='url_operation'), | |
49 | url(r'^operation/search/$', 'apps.main.views.operation_search', name='url_operation_search'), |
|
51 | url(r'^operation/search/$', 'apps.main.views.operation_search', name='url_operation_search'), | |
50 | url(r'^operation/search/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation_search', name='url_operation_search'), |
|
52 | url(r'^operation/search/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation_search', name='url_operation_search'), | |
51 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/play/$', 'apps.main.views.radar_play', name='url_radar_play'), |
|
53 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/play/$', 'apps.main.views.radar_play', name='url_radar_play'), | |
52 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/stop/$', 'apps.main.views.radar_stop', name='url_radar_stop'), |
|
54 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/stop/$', 'apps.main.views.radar_stop', name='url_radar_stop'), | |
53 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/refresh/$', 'apps.main.views.radar_refresh', name='url_radar_refresh'), |
|
55 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/refresh/$', 'apps.main.views.radar_refresh', name='url_radar_refresh'), | |
54 |
|
56 | |||
55 | ) |
|
57 | ) |
@@ -1,1294 +1,1405 | |||||
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.utils.safestring import mark_safe |
|
2 | from django.utils.safestring import mark_safe | |
3 | from django.http import HttpResponseRedirect |
|
3 | from django.http import HttpResponseRedirect | |
4 | from django.core.urlresolvers import reverse |
|
4 | from django.core.urlresolvers import reverse | |
5 | from django.contrib import messages |
|
5 | from django.contrib import messages | |
6 | from datetime import datetime |
|
6 | from datetime import datetime | |
7 |
|
7 | |||
8 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm, NewForm |
|
8 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm, NewForm | |
9 | from .forms import OperationSearchForm |
|
9 | from .forms import OperationSearchForm | |
10 | from apps.cgs.forms import CGSConfigurationForm |
|
10 | from apps.cgs.forms import CGSConfigurationForm | |
11 | from apps.jars.forms import JARSConfigurationForm |
|
11 | from apps.jars.forms import JARSConfigurationForm | |
12 | from apps.usrp.forms import USRPConfigurationForm |
|
12 | from apps.usrp.forms import USRPConfigurationForm | |
13 | from apps.abs.forms import ABSConfigurationForm |
|
13 | from apps.abs.forms import ABSConfigurationForm | |
14 | from apps.rc.forms import RCConfigurationForm, RCMixConfigurationForm |
|
14 | from apps.rc.forms import RCConfigurationForm, RCMixConfigurationForm | |
15 | from apps.dds.forms import DDSConfigurationForm |
|
15 | from apps.dds.forms import DDSConfigurationForm | |
16 |
|
16 | |||
17 | from .models import Campaign, Experiment, Device, Configuration, Location, RunningExperiment |
|
17 | from .models import Campaign, Experiment, Device, Configuration, Location, RunningExperiment | |
18 | from apps.cgs.models import CGSConfiguration |
|
18 | from apps.cgs.models import CGSConfiguration | |
19 | from apps.jars.models import JARSConfiguration |
|
19 | from apps.jars.models import JARSConfiguration | |
20 | from apps.usrp.models import USRPConfiguration |
|
20 | from apps.usrp.models import USRPConfiguration | |
21 | from apps.abs.models import ABSConfiguration |
|
21 | from apps.abs.models import ABSConfiguration | |
22 | from apps.rc.models import RCConfiguration, RCLine, RCLineType |
|
22 | from apps.rc.models import RCConfiguration, RCLine, RCLineType | |
23 | from apps.dds.models import DDSConfiguration |
|
23 | from apps.dds.models import DDSConfiguration | |
24 |
|
24 | |||
25 | # Create your views here. |
|
25 | # Create your views here. | |
26 |
|
26 | |||
27 | CONF_FORMS = { |
|
27 | CONF_FORMS = { | |
28 | 'rc': RCConfigurationForm, |
|
28 | 'rc': RCConfigurationForm, | |
29 | 'rc_mix': RCMixConfigurationForm, |
|
29 | 'rc_mix': RCMixConfigurationForm, | |
30 | 'dds': DDSConfigurationForm, |
|
30 | 'dds': DDSConfigurationForm, | |
31 | 'jars': JARSConfigurationForm, |
|
31 | 'jars': JARSConfigurationForm, | |
32 | 'cgs': CGSConfigurationForm, |
|
32 | 'cgs': CGSConfigurationForm, | |
33 | 'abs': ABSConfigurationForm, |
|
33 | 'abs': ABSConfigurationForm, | |
34 | 'usrp': USRPConfigurationForm, |
|
34 | 'usrp': USRPConfigurationForm, | |
35 | } |
|
35 | } | |
36 |
|
36 | |||
37 | CONF_MODELS = { |
|
37 | CONF_MODELS = { | |
38 | 'rc': RCConfiguration, |
|
38 | 'rc': RCConfiguration, | |
39 | 'dds': DDSConfiguration, |
|
39 | 'dds': DDSConfiguration, | |
40 | 'jars': JARSConfiguration, |
|
40 | 'jars': JARSConfiguration, | |
41 | 'cgs': CGSConfiguration, |
|
41 | 'cgs': CGSConfiguration, | |
42 | 'abs': ABSConfiguration, |
|
42 | 'abs': ABSConfiguration, | |
43 | 'usrp': USRPConfiguration, |
|
43 | 'usrp': USRPConfiguration, | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | MIX_MODES = { |
|
46 | MIX_MODES = { | |
47 | '0': 'OR', |
|
47 | '0': 'OR', | |
48 | '1': 'XOR', |
|
48 | '1': 'XOR', | |
49 | '2': 'AND', |
|
49 | '2': 'AND', | |
50 | '3': 'NAND' |
|
50 | '3': 'NAND' | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 |
|
53 | |||
54 | def index(request): |
|
54 | def index(request): | |
55 | kwargs = {} |
|
55 | kwargs = {} | |
56 |
|
56 | |||
57 | return render(request, 'index.html', kwargs) |
|
57 | return render(request, 'index.html', kwargs) | |
58 |
|
58 | |||
59 |
|
59 | |||
60 | def locations(request): |
|
60 | def locations(request): | |
61 |
|
61 | |||
62 | locations = Location.objects.all().order_by('name') |
|
62 | locations = Location.objects.all().order_by('name') | |
63 |
|
63 | |||
64 | keys = ['id', 'name', 'description'] |
|
64 | keys = ['id', 'name', 'description'] | |
65 |
|
65 | |||
66 | kwargs = {} |
|
66 | kwargs = {} | |
67 | kwargs['location_keys'] = keys[1:] |
|
67 | kwargs['location_keys'] = keys[1:] | |
68 | kwargs['locations'] = locations |
|
68 | kwargs['locations'] = locations | |
69 | kwargs['title'] = 'Location' |
|
69 | kwargs['title'] = 'Location' | |
70 | kwargs['suptitle'] = 'List' |
|
70 | kwargs['suptitle'] = 'List' | |
71 | kwargs['button'] = 'New Location' |
|
71 | kwargs['button'] = 'New Location' | |
72 |
|
72 | |||
73 | return render(request, 'locations.html', kwargs) |
|
73 | return render(request, 'locations.html', kwargs) | |
74 |
|
74 | |||
75 |
|
75 | |||
76 | def location(request, id_loc): |
|
76 | def location(request, id_loc): | |
77 |
|
77 | |||
78 | location = get_object_or_404(Location, pk=id_loc) |
|
78 | location = get_object_or_404(Location, pk=id_loc) | |
79 |
|
79 | |||
80 | kwargs = {} |
|
80 | kwargs = {} | |
81 | kwargs['location'] = location |
|
81 | kwargs['location'] = location | |
82 | kwargs['location_keys'] = ['name', 'description'] |
|
82 | kwargs['location_keys'] = ['name', 'description'] | |
83 |
|
83 | |||
84 | kwargs['title'] = 'Location' |
|
84 | kwargs['title'] = 'Location' | |
85 | kwargs['suptitle'] = 'Details' |
|
85 | kwargs['suptitle'] = 'Details' | |
86 |
|
86 | |||
87 | return render(request, 'location.html', kwargs) |
|
87 | return render(request, 'location.html', kwargs) | |
88 |
|
88 | |||
89 |
|
89 | |||
90 | def location_new(request): |
|
90 | def location_new(request): | |
91 |
|
91 | |||
92 | if request.method == 'GET': |
|
92 | if request.method == 'GET': | |
93 | form = LocationForm() |
|
93 | form = LocationForm() | |
94 |
|
94 | |||
95 | if request.method == 'POST': |
|
95 | if request.method == 'POST': | |
96 | form = LocationForm(request.POST) |
|
96 | form = LocationForm(request.POST) | |
97 |
|
97 | |||
98 | if form.is_valid(): |
|
98 | if form.is_valid(): | |
99 | form.save() |
|
99 | form.save() | |
100 | return redirect('url_locations') |
|
100 | return redirect('url_locations') | |
101 |
|
101 | |||
102 | kwargs = {} |
|
102 | kwargs = {} | |
103 | kwargs['form'] = form |
|
103 | kwargs['form'] = form | |
104 | kwargs['title'] = 'Location' |
|
104 | kwargs['title'] = 'Location' | |
105 | kwargs['suptitle'] = 'New' |
|
105 | kwargs['suptitle'] = 'New' | |
106 | kwargs['button'] = 'Create' |
|
106 | kwargs['button'] = 'Create' | |
107 |
|
107 | |||
108 | return render(request, 'location_edit.html', kwargs) |
|
108 | return render(request, 'location_edit.html', kwargs) | |
109 |
|
109 | |||
110 |
|
110 | |||
111 | def location_edit(request, id_loc): |
|
111 | def location_edit(request, id_loc): | |
112 |
|
112 | |||
113 | location = get_object_or_404(Location, pk=id_loc) |
|
113 | location = get_object_or_404(Location, pk=id_loc) | |
114 |
|
114 | |||
115 | if request.method=='GET': |
|
115 | if request.method=='GET': | |
116 | form = LocationForm(instance=location) |
|
116 | form = LocationForm(instance=location) | |
117 |
|
117 | |||
118 | if request.method=='POST': |
|
118 | if request.method=='POST': | |
119 | form = LocationForm(request.POST, instance=location) |
|
119 | form = LocationForm(request.POST, instance=location) | |
120 |
|
120 | |||
121 | if form.is_valid(): |
|
121 | if form.is_valid(): | |
122 | form.save() |
|
122 | form.save() | |
123 | return redirect('url_locations') |
|
123 | return redirect('url_locations') | |
124 |
|
124 | |||
125 | kwargs = {} |
|
125 | kwargs = {} | |
126 | kwargs['form'] = form |
|
126 | kwargs['form'] = form | |
127 | kwargs['title'] = 'Location' |
|
127 | kwargs['title'] = 'Location' | |
128 | kwargs['suptitle'] = 'Edit' |
|
128 | kwargs['suptitle'] = 'Edit' | |
129 | kwargs['button'] = 'Update' |
|
129 | kwargs['button'] = 'Update' | |
130 |
|
130 | |||
131 | return render(request, 'location_edit.html', kwargs) |
|
131 | return render(request, 'location_edit.html', kwargs) | |
132 |
|
132 | |||
133 |
|
133 | |||
134 | def location_delete(request, id_loc): |
|
134 | def location_delete(request, id_loc): | |
135 |
|
135 | |||
136 | location = get_object_or_404(Location, pk=id_loc) |
|
136 | location = get_object_or_404(Location, pk=id_loc) | |
137 |
|
137 | |||
138 | if request.method=='POST': |
|
138 | if request.method=='POST': | |
139 |
|
139 | |||
140 | if request.user.is_staff: |
|
140 | if request.user.is_staff: | |
141 | location.delete() |
|
141 | location.delete() | |
142 | return redirect('url_locations') |
|
142 | return redirect('url_locations') | |
143 |
|
143 | |||
144 | messages.error(request, 'Not enough permission to delete this object') |
|
144 | messages.error(request, 'Not enough permission to delete this object') | |
145 | return redirect(location.get_absolute_url()) |
|
145 | return redirect(location.get_absolute_url()) | |
146 |
|
146 | |||
147 | kwargs = { |
|
147 | kwargs = { | |
148 | 'title': 'Delete', |
|
148 | 'title': 'Delete', | |
149 | 'suptitle': 'Location', |
|
149 | 'suptitle': 'Location', | |
150 | 'object': location, |
|
150 | 'object': location, | |
151 | 'previous': location.get_absolute_url(), |
|
151 | 'previous': location.get_absolute_url(), | |
152 | 'delete': True |
|
152 | 'delete': True | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | return render(request, 'confirm.html', kwargs) |
|
155 | return render(request, 'confirm.html', kwargs) | |
156 |
|
156 | |||
157 |
|
157 | |||
158 | def devices(request): |
|
158 | def devices(request): | |
159 |
|
159 | |||
160 | devices = Device.objects.all().order_by('device_type__name') |
|
160 | devices = Device.objects.all().order_by('device_type__name') | |
161 |
|
161 | |||
162 | # keys = ['id', 'device_type__name', 'name', 'ip_address'] |
|
162 | # keys = ['id', 'device_type__name', 'name', 'ip_address'] | |
163 | keys = ['id', 'name', 'ip_address', 'port_address', 'device_type'] |
|
163 | keys = ['id', 'name', 'ip_address', 'port_address', 'device_type'] | |
164 |
|
164 | |||
165 | kwargs = {} |
|
165 | kwargs = {} | |
166 | kwargs['device_keys'] = keys[1:] |
|
166 | kwargs['device_keys'] = keys[1:] | |
167 | kwargs['devices'] = devices#.values(*keys) |
|
167 | kwargs['devices'] = devices#.values(*keys) | |
168 | kwargs['title'] = 'Device' |
|
168 | kwargs['title'] = 'Device' | |
169 | kwargs['suptitle'] = 'List' |
|
169 | kwargs['suptitle'] = 'List' | |
170 | kwargs['button'] = 'New Device' |
|
170 | kwargs['button'] = 'New Device' | |
171 |
|
171 | |||
172 | return render(request, 'devices.html', kwargs) |
|
172 | return render(request, 'devices.html', kwargs) | |
173 |
|
173 | |||
174 |
|
174 | |||
175 | def device(request, id_dev): |
|
175 | def device(request, id_dev): | |
176 |
|
176 | |||
177 | device = get_object_or_404(Device, pk=id_dev) |
|
177 | device = get_object_or_404(Device, pk=id_dev) | |
178 |
|
178 | |||
179 | kwargs = {} |
|
179 | kwargs = {} | |
180 | kwargs['device'] = device |
|
180 | kwargs['device'] = device | |
181 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] |
|
181 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] | |
182 |
|
182 | |||
183 | kwargs['title'] = 'Device' |
|
183 | kwargs['title'] = 'Device' | |
184 | kwargs['suptitle'] = 'Details' |
|
184 | kwargs['suptitle'] = 'Details' | |
185 |
|
185 | |||
186 | return render(request, 'device.html', kwargs) |
|
186 | return render(request, 'device.html', kwargs) | |
187 |
|
187 | |||
188 |
|
188 | |||
189 | def device_new(request): |
|
189 | def device_new(request): | |
190 |
|
190 | |||
191 | if request.method == 'GET': |
|
191 | if request.method == 'GET': | |
192 | form = DeviceForm() |
|
192 | form = DeviceForm() | |
193 |
|
193 | |||
194 | if request.method == 'POST': |
|
194 | if request.method == 'POST': | |
195 | form = DeviceForm(request.POST) |
|
195 | form = DeviceForm(request.POST) | |
196 |
|
196 | |||
197 | if form.is_valid(): |
|
197 | if form.is_valid(): | |
198 | form.save() |
|
198 | form.save() | |
199 | return redirect('url_devices') |
|
199 | return redirect('url_devices') | |
200 |
|
200 | |||
201 | kwargs = {} |
|
201 | kwargs = {} | |
202 | kwargs['form'] = form |
|
202 | kwargs['form'] = form | |
203 | kwargs['title'] = 'Device' |
|
203 | kwargs['title'] = 'Device' | |
204 | kwargs['suptitle'] = 'New' |
|
204 | kwargs['suptitle'] = 'New' | |
205 | kwargs['button'] = 'Create' |
|
205 | kwargs['button'] = 'Create' | |
206 |
|
206 | |||
207 | return render(request, 'device_edit.html', kwargs) |
|
207 | return render(request, 'device_edit.html', kwargs) | |
208 |
|
208 | |||
209 |
|
209 | |||
210 | def device_edit(request, id_dev): |
|
210 | def device_edit(request, id_dev): | |
211 |
|
211 | |||
212 | device = get_object_or_404(Device, pk=id_dev) |
|
212 | device = get_object_or_404(Device, pk=id_dev) | |
213 |
|
213 | |||
214 | if request.method=='GET': |
|
214 | if request.method=='GET': | |
215 | form = DeviceForm(instance=device) |
|
215 | form = DeviceForm(instance=device) | |
216 |
|
216 | |||
217 | if request.method=='POST': |
|
217 | if request.method=='POST': | |
218 | form = DeviceForm(request.POST, instance=device) |
|
218 | form = DeviceForm(request.POST, instance=device) | |
219 |
|
219 | |||
220 | if form.is_valid(): |
|
220 | if form.is_valid(): | |
221 | form.save() |
|
221 | form.save() | |
222 | return redirect(device.get_absolute_url()) |
|
222 | return redirect(device.get_absolute_url()) | |
223 |
|
223 | |||
224 | kwargs = {} |
|
224 | kwargs = {} | |
225 | kwargs['form'] = form |
|
225 | kwargs['form'] = form | |
226 | kwargs['title'] = 'Device' |
|
226 | kwargs['title'] = 'Device' | |
227 | kwargs['suptitle'] = 'Edit' |
|
227 | kwargs['suptitle'] = 'Edit' | |
228 | kwargs['button'] = 'Update' |
|
228 | kwargs['button'] = 'Update' | |
229 |
|
229 | |||
230 | return render(request, 'device_edit.html', kwargs) |
|
230 | return render(request, 'device_edit.html', kwargs) | |
231 |
|
231 | |||
232 |
|
232 | |||
233 | def device_delete(request, id_dev): |
|
233 | def device_delete(request, id_dev): | |
234 |
|
234 | |||
235 | device = get_object_or_404(Device, pk=id_dev) |
|
235 | device = get_object_or_404(Device, pk=id_dev) | |
236 |
|
236 | |||
237 | if request.method=='POST': |
|
237 | if request.method=='POST': | |
238 |
|
238 | |||
239 | if request.user.is_staff: |
|
239 | if request.user.is_staff: | |
240 | device.delete() |
|
240 | device.delete() | |
241 | return redirect('url_devices') |
|
241 | return redirect('url_devices') | |
242 |
|
242 | |||
243 | messages.error(request, 'Not enough permission to delete this object') |
|
243 | messages.error(request, 'Not enough permission to delete this object') | |
244 | return redirect(device.get_absolute_url()) |
|
244 | return redirect(device.get_absolute_url()) | |
245 |
|
245 | |||
246 | kwargs = { |
|
246 | kwargs = { | |
247 | 'title': 'Delete', |
|
247 | 'title': 'Delete', | |
248 | 'suptitle': 'Device', |
|
248 | 'suptitle': 'Device', | |
249 | 'object': device, |
|
249 | 'object': device, | |
250 | 'previous': device.get_absolute_url(), |
|
250 | 'previous': device.get_absolute_url(), | |
251 | 'delete': True |
|
251 | 'delete': True | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | return render(request, 'confirm.html', kwargs) |
|
254 | return render(request, 'confirm.html', kwargs) | |
255 |
|
255 | |||
256 |
|
256 | |||
257 | def campaigns(request): |
|
257 | def campaigns(request): | |
258 |
|
258 | |||
259 | campaigns = Campaign.objects.all().order_by('start_date') |
|
259 | campaigns = Campaign.objects.all().order_by('start_date') | |
260 |
|
260 | |||
261 | keys = ['id', 'name', 'start_date', 'end_date'] |
|
261 | keys = ['id', 'name', 'start_date', 'end_date'] | |
262 |
|
262 | |||
263 | kwargs = {} |
|
263 | kwargs = {} | |
264 | kwargs['campaign_keys'] = keys[1:] |
|
264 | kwargs['campaign_keys'] = keys[1:] | |
265 | kwargs['campaigns'] = campaigns#.values(*keys) |
|
265 | kwargs['campaigns'] = campaigns#.values(*keys) | |
266 | kwargs['title'] = 'Campaign' |
|
266 | kwargs['title'] = 'Campaign' | |
267 | kwargs['suptitle'] = 'List' |
|
267 | kwargs['suptitle'] = 'List' | |
268 | kwargs['button'] = 'New Campaign' |
|
268 | kwargs['button'] = 'New Campaign' | |
269 |
|
269 | |||
270 | return render(request, 'campaigns.html', kwargs) |
|
270 | return render(request, 'campaigns.html', kwargs) | |
271 |
|
271 | |||
272 |
|
272 | |||
273 | def campaign(request, id_camp): |
|
273 | def campaign(request, id_camp): | |
274 |
|
274 | |||
275 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
275 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
276 | experiments = Experiment.objects.filter(campaign=campaign) |
|
276 | experiments = Experiment.objects.filter(campaign=campaign) | |
277 |
|
277 | |||
278 | form = CampaignForm(instance=campaign) |
|
278 | form = CampaignForm(instance=campaign) | |
279 |
|
279 | |||
280 | kwargs = {} |
|
280 | kwargs = {} | |
281 | kwargs['campaign'] = campaign |
|
281 | kwargs['campaign'] = campaign | |
282 | kwargs['campaign_keys'] = ['template', 'name', 'start_date', 'end_date', 'tags', 'description'] |
|
282 | kwargs['campaign_keys'] = ['template', 'name', 'start_date', 'end_date', 'tags', 'description'] | |
283 |
|
283 | |||
284 | kwargs['experiments'] = experiments |
|
284 | kwargs['experiments'] = experiments | |
285 | kwargs['experiment_keys'] = ['name', 'radar', 'start_time', 'end_time'] |
|
285 | kwargs['experiment_keys'] = ['name', 'radar', 'start_time', 'end_time'] | |
286 |
|
286 | |||
287 | kwargs['title'] = 'Campaign' |
|
287 | kwargs['title'] = 'Campaign' | |
288 | kwargs['suptitle'] = 'Details' |
|
288 | kwargs['suptitle'] = 'Details' | |
289 |
|
289 | |||
290 | kwargs['form'] = form |
|
290 | kwargs['form'] = form | |
291 | kwargs['button'] = 'Add Experiment' |
|
291 | kwargs['button'] = 'Add Experiment' | |
292 |
|
292 | |||
293 | return render(request, 'campaign.html', kwargs) |
|
293 | return render(request, 'campaign.html', kwargs) | |
294 |
|
294 | |||
295 |
|
295 | |||
296 | def campaign_new(request): |
|
296 | def campaign_new(request): | |
297 |
|
297 | |||
298 | kwargs = {} |
|
298 | kwargs = {} | |
299 |
|
299 | |||
300 | if request.method == 'GET': |
|
300 | if request.method == 'GET': | |
301 |
|
301 | |||
302 | if 'template' in request.GET: |
|
302 | if 'template' in request.GET: | |
303 | if request.GET['template']=='0': |
|
303 | if request.GET['template']=='0': | |
304 | form = NewForm(initial={'create_from':2}, |
|
304 | form = NewForm(initial={'create_from':2}, | |
305 | template_choices=Campaign.objects.filter(template=True).values_list('id', 'name')) |
|
305 | template_choices=Campaign.objects.filter(template=True).values_list('id', 'name')) | |
306 | else: |
|
306 | else: | |
307 | kwargs['button'] = 'Create' |
|
307 | kwargs['button'] = 'Create' | |
308 | kwargs['experiments'] = Configuration.objects.filter(experiment=request.GET['template']) |
|
308 | kwargs['experiments'] = Configuration.objects.filter(experiment=request.GET['template']) | |
309 | kwargs['experiment_keys'] = ['name', 'start_time', 'end_time'] |
|
309 | kwargs['experiment_keys'] = ['name', 'start_time', 'end_time'] | |
310 | camp = Campaign.objects.get(pk=request.GET['template']) |
|
310 | camp = Campaign.objects.get(pk=request.GET['template']) | |
311 | form = CampaignForm(instance=camp, |
|
311 | form = CampaignForm(instance=camp, | |
312 | initial={'name':'{} [{:%Y/%m/%d}]'.format(camp.name, datetime.now()), |
|
312 | initial={'name':'{} [{:%Y/%m/%d}]'.format(camp.name, datetime.now()), | |
313 | 'template':False}) |
|
313 | 'template':False}) | |
314 | elif 'blank' in request.GET: |
|
314 | elif 'blank' in request.GET: | |
315 | kwargs['button'] = 'Create' |
|
315 | kwargs['button'] = 'Create' | |
316 | form = CampaignForm() |
|
316 | form = CampaignForm() | |
317 | else: |
|
317 | else: | |
318 | form = NewForm() |
|
318 | form = NewForm() | |
319 |
|
319 | |||
320 | if request.method == 'POST': |
|
320 | if request.method == 'POST': | |
321 | kwargs['button'] = 'Create' |
|
321 | kwargs['button'] = 'Create' | |
322 | post = request.POST.copy() |
|
322 | post = request.POST.copy() | |
323 | experiments = [] |
|
323 | experiments = [] | |
324 |
|
324 | |||
325 | for id_exp in post.getlist('experiments'): |
|
325 | for id_exp in post.getlist('experiments'): | |
326 | exp = Experiment.objects.get(pk=id_exp) |
|
326 | exp = Experiment.objects.get(pk=id_exp) | |
327 | new_exp = exp.clone(template=False) |
|
327 | new_exp = exp.clone(template=False) | |
328 | experiments.append(new_exp) |
|
328 | experiments.append(new_exp) | |
329 |
|
329 | |||
330 | post.setlist('experiments', []) |
|
330 | post.setlist('experiments', []) | |
331 |
|
331 | |||
332 | form = CampaignForm(post) |
|
332 | form = CampaignForm(post) | |
333 |
|
333 | |||
334 | if form.is_valid(): |
|
334 | if form.is_valid(): | |
335 | campaign = form.save() |
|
335 | campaign = form.save() | |
336 | for exp in experiments: |
|
336 | for exp in experiments: | |
337 | campaign.experiments.add(exp) |
|
337 | campaign.experiments.add(exp) | |
338 | campaign.save() |
|
338 | campaign.save() | |
339 | return redirect('url_campaign', id_camp=campaign.id) |
|
339 | return redirect('url_campaign', id_camp=campaign.id) | |
340 |
|
340 | |||
341 | kwargs['form'] = form |
|
341 | kwargs['form'] = form | |
342 | kwargs['title'] = 'Campaign' |
|
342 | kwargs['title'] = 'Campaign' | |
343 | kwargs['suptitle'] = 'New' |
|
343 | kwargs['suptitle'] = 'New' | |
344 |
|
344 | |||
345 | return render(request, 'campaign_edit.html', kwargs) |
|
345 | return render(request, 'campaign_edit.html', kwargs) | |
346 |
|
346 | |||
347 |
|
347 | |||
348 | def campaign_edit(request, id_camp): |
|
348 | def campaign_edit(request, id_camp): | |
349 |
|
349 | |||
350 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
350 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
351 |
|
351 | |||
352 | if request.method=='GET': |
|
352 | if request.method=='GET': | |
353 | form = CampaignForm(instance=campaign) |
|
353 | form = CampaignForm(instance=campaign) | |
354 |
|
354 | |||
355 | if request.method=='POST': |
|
355 | if request.method=='POST': | |
356 | exps = campaign.experiments.all().values_list('pk', flat=True) |
|
356 | exps = campaign.experiments.all().values_list('pk', flat=True) | |
357 | post = request.POST.copy() |
|
357 | post = request.POST.copy() | |
358 | new_exps = post.getlist('experiments') |
|
358 | new_exps = post.getlist('experiments') | |
359 | post.setlist('experiments', []) |
|
359 | post.setlist('experiments', []) | |
360 | form = CampaignForm(post, instance=campaign) |
|
360 | form = CampaignForm(post, instance=campaign) | |
361 |
|
361 | |||
362 | if form.is_valid(): |
|
362 | if form.is_valid(): | |
363 | camp = form.save() |
|
363 | camp = form.save() | |
364 | for id_exp in new_exps: |
|
364 | for id_exp in new_exps: | |
365 | if int(id_exp) in exps: |
|
365 | if int(id_exp) in exps: | |
366 | exps.pop(id_exp) |
|
366 | exps.pop(id_exp) | |
367 | else: |
|
367 | else: | |
368 | exp = Experiment.objects.get(pk=id_exp) |
|
368 | exp = Experiment.objects.get(pk=id_exp) | |
369 | if exp.template: |
|
369 | if exp.template: | |
370 | camp.experiments.add(exp.clone(template=False)) |
|
370 | camp.experiments.add(exp.clone(template=False)) | |
371 | else: |
|
371 | else: | |
372 | camp.experiments.add(exp) |
|
372 | camp.experiments.add(exp) | |
373 |
|
373 | |||
374 | for id_exp in exps: |
|
374 | for id_exp in exps: | |
375 | camp.experiments.remove(Experiment.objects.get(pk=id_exp)) |
|
375 | camp.experiments.remove(Experiment.objects.get(pk=id_exp)) | |
376 |
|
376 | |||
377 | return redirect('url_campaign', id_camp=id_camp) |
|
377 | return redirect('url_campaign', id_camp=id_camp) | |
378 |
|
378 | |||
379 | kwargs = {} |
|
379 | kwargs = {} | |
380 | kwargs['form'] = form |
|
380 | kwargs['form'] = form | |
381 | kwargs['title'] = 'Campaign' |
|
381 | kwargs['title'] = 'Campaign' | |
382 | kwargs['suptitle'] = 'Edit' |
|
382 | kwargs['suptitle'] = 'Edit' | |
383 | kwargs['button'] = 'Update' |
|
383 | kwargs['button'] = 'Update' | |
384 |
|
384 | |||
385 | return render(request, 'campaign_edit.html', kwargs) |
|
385 | return render(request, 'campaign_edit.html', kwargs) | |
386 |
|
386 | |||
387 |
|
387 | |||
388 | def campaign_delete(request, id_camp): |
|
388 | def campaign_delete(request, id_camp): | |
389 |
|
389 | |||
390 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
390 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
391 |
|
391 | |||
392 | if request.method=='POST': |
|
392 | if request.method=='POST': | |
393 | if request.user.is_staff: |
|
393 | if request.user.is_staff: | |
394 |
|
394 | |||
395 | for exp in campaign.experiments.all(): |
|
395 | for exp in campaign.experiments.all(): | |
396 | for conf in Configuration.objects.filter(experiment=exp): |
|
396 | for conf in Configuration.objects.filter(experiment=exp): | |
397 | conf.delete() |
|
397 | conf.delete() | |
398 | exp.delete() |
|
398 | exp.delete() | |
399 | campaign.delete() |
|
399 | campaign.delete() | |
400 |
|
400 | |||
401 | return redirect('url_campaigns') |
|
401 | return redirect('url_campaigns') | |
402 |
|
402 | |||
403 | messages.error(request, 'Not enough permission to delete this object') |
|
403 | messages.error(request, 'Not enough permission to delete this object') | |
404 | return redirect(campaign.get_absolute_url()) |
|
404 | return redirect(campaign.get_absolute_url()) | |
405 |
|
405 | |||
406 | kwargs = { |
|
406 | kwargs = { | |
407 | 'title': 'Delete', |
|
407 | 'title': 'Delete', | |
408 | 'suptitle': 'Campaign', |
|
408 | 'suptitle': 'Campaign', | |
409 | 'object': campaign, |
|
409 | 'object': campaign, | |
410 | 'previous': campaign.get_absolute_url(), |
|
410 | 'previous': campaign.get_absolute_url(), | |
411 | 'delete': True |
|
411 | 'delete': True | |
412 | } |
|
412 | } | |
413 |
|
413 | |||
414 | return render(request, 'confirm.html', kwargs) |
|
414 | return render(request, 'confirm.html', kwargs) | |
415 |
|
415 | |||
416 | def campaign_export(request, id_camp): |
|
416 | def campaign_export(request, id_camp): | |
417 |
|
417 | |||
418 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
418 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
419 | content = campaign.parms_to_dict() |
|
419 | content = campaign.parms_to_dict() | |
420 | content_type = 'application/json' |
|
420 | content_type = 'application/json' | |
421 | filename = '%s_%s.json' %(campaign.name, campaign.id) |
|
421 | filename = '%s_%s.json' %(campaign.name, campaign.id) | |
422 |
|
422 | |||
423 | response = HttpResponse(content_type=content_type) |
|
423 | response = HttpResponse(content_type=content_type) | |
424 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename |
|
424 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename | |
425 | response.write(content) |
|
425 | response.write(content) | |
426 |
|
426 | |||
427 | return response |
|
427 | return response | |
428 |
|
428 | |||
|
429 | ||||
|
430 | def campaign_import(request, id_camp): | |||
|
431 | ###------FALTA CORREGIR!!!!!-----### | |||
|
432 | campaign = get_object_or_404(Campaign, pk=id_camp) | |||
|
433 | experiments = Experiment.objects.filter(campaign=campaign) | |||
|
434 | configurations = Configuration.objects.filter(experiment=experiments) | |||
|
435 | ||||
|
436 | if request.method == 'GET': | |||
|
437 | file_form = UploadFileForm() | |||
|
438 | ||||
|
439 | if request.method == 'POST': | |||
|
440 | file_form = UploadFileForm(request.POST, request.FILES) | |||
|
441 | ||||
|
442 | if file_form.is_valid(): | |||
|
443 | ||||
|
444 | parms = campaign.import_from_file(request.FILES['file']) | |||
|
445 | ||||
|
446 | if parms: | |||
|
447 | location = Location.objects.get(name = parms['radar']) | |||
|
448 | parms['location'] = location.id | |||
|
449 | parms['name'] = parms['experiment'] | |||
|
450 | ||||
|
451 | campaign.dict_to_parms(parms, CONF_MODELS) | |||
|
452 | ||||
|
453 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) | |||
|
454 | ||||
|
455 | form = CampaignForm(initial=parms, instance=campaign) | |||
|
456 | ||||
|
457 | kwargs = {} | |||
|
458 | #kwargs['id_dev'] = conf.id | |||
|
459 | kwargs['form'] = form | |||
|
460 | kwargs['title'] = 'Campaign' | |||
|
461 | kwargs['suptitle'] = 'Parameters imported' | |||
|
462 | kwargs['button'] = 'Save' | |||
|
463 | kwargs['action'] = campaign.get_absolute_url_edit() | |||
|
464 | kwargs['previous'] = campaign.get_absolute_url() | |||
|
465 | ||||
|
466 | ||||
|
467 | ###### SIDEBAR ###### | |||
|
468 | #kwargs.update(sidebar(conf=conf)) | |||
|
469 | #kwargs.update(sidebar(campaign=campaign)) | |||
|
470 | ||||
|
471 | return render(request, 'campaign_edit.html', kwargs) | |||
|
472 | ||||
|
473 | messages.error(request, "Could not import parameters from file") | |||
|
474 | ||||
|
475 | kwargs = {} | |||
|
476 | #kwargs['id_dev'] = conf.id | |||
|
477 | kwargs['title'] = 'Campaign' | |||
|
478 | kwargs['form'] = file_form | |||
|
479 | kwargs['suptitle'] = 'Importing file' | |||
|
480 | kwargs['button'] = 'Import' | |||
|
481 | ||||
|
482 | #kwargs.update(sidebar(campaign=campaign)) | |||
|
483 | ||||
|
484 | return render(request, 'campaign_import.html', kwargs) | |||
|
485 | ||||
|
486 | ||||
429 | def experiments(request): |
|
487 | def experiments(request): | |
430 |
|
488 | |||
431 | experiment_list = Experiment.objects.all() |
|
489 | experiment_list = Experiment.objects.all() | |
432 |
|
490 | |||
433 | keys = ['id', 'name', 'start_time', 'end_time'] |
|
491 | keys = ['id', 'name', 'start_time', 'end_time'] | |
434 |
|
492 | |||
435 | kwargs = {} |
|
493 | kwargs = {} | |
436 |
|
494 | |||
437 | kwargs['experiment_keys'] = keys[1:] |
|
495 | kwargs['experiment_keys'] = keys[1:] | |
438 | kwargs['experiments'] = experiment_list |
|
496 | kwargs['experiments'] = experiment_list | |
439 |
|
497 | |||
440 | kwargs['title'] = 'Experiment' |
|
498 | kwargs['title'] = 'Experiment' | |
441 | kwargs['suptitle'] = 'List' |
|
499 | kwargs['suptitle'] = 'List' | |
442 | kwargs['button'] = 'New Experiment' |
|
500 | kwargs['button'] = 'New Experiment' | |
443 |
|
501 | |||
444 | return render(request, 'experiments.html', kwargs) |
|
502 | return render(request, 'experiments.html', kwargs) | |
445 |
|
503 | |||
446 |
|
504 | |||
447 | def experiment(request, id_exp): |
|
505 | def experiment(request, id_exp): | |
448 |
|
506 | |||
449 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
507 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
450 |
|
508 | |||
451 | configurations = Configuration.objects.filter(experiment=experiment, type=0) |
|
509 | configurations = Configuration.objects.filter(experiment=experiment, type=0) | |
452 |
|
510 | |||
453 | kwargs = {} |
|
511 | kwargs = {} | |
454 |
|
512 | |||
455 | kwargs['experiment_keys'] = ['template', 'radar', 'name', 'start_time', 'end_time'] |
|
513 | kwargs['experiment_keys'] = ['template', 'radar', 'name', 'start_time', 'end_time'] | |
456 | kwargs['experiment'] = experiment |
|
514 | kwargs['experiment'] = experiment | |
457 |
|
515 | |||
458 | kwargs['configuration_keys'] = ['name', 'device__device_type', 'device__ip_address', 'device__port_address'] |
|
516 | kwargs['configuration_keys'] = ['name', 'device__device_type', 'device__ip_address', 'device__port_address'] | |
459 | kwargs['configurations'] = configurations |
|
517 | kwargs['configurations'] = configurations | |
460 |
|
518 | |||
461 | kwargs['title'] = 'Experiment' |
|
519 | kwargs['title'] = 'Experiment' | |
462 | kwargs['suptitle'] = 'Details' |
|
520 | kwargs['suptitle'] = 'Details' | |
463 |
|
521 | |||
464 | kwargs['button'] = 'Add Configuration' |
|
522 | kwargs['button'] = 'Add Configuration' | |
465 |
|
523 | |||
466 | ###### SIDEBAR ###### |
|
524 | ###### SIDEBAR ###### | |
467 | kwargs.update(sidebar(experiment=experiment)) |
|
525 | kwargs.update(sidebar(experiment=experiment)) | |
468 |
|
526 | |||
469 | return render(request, 'experiment.html', kwargs) |
|
527 | return render(request, 'experiment.html', kwargs) | |
470 |
|
528 | |||
471 |
|
529 | |||
472 | def experiment_new(request, id_camp=None): |
|
530 | def experiment_new(request, id_camp=None): | |
473 |
|
531 | |||
474 | kwargs = {} |
|
532 | kwargs = {} | |
475 |
|
533 | |||
476 | if request.method == 'GET': |
|
534 | if request.method == 'GET': | |
477 | if 'template' in request.GET: |
|
535 | if 'template' in request.GET: | |
478 | if request.GET['template']=='0': |
|
536 | if request.GET['template']=='0': | |
479 | form = NewForm(initial={'create_from':2}, |
|
537 | form = NewForm(initial={'create_from':2}, | |
480 | template_choices=Experiment.objects.filter(template=True).values_list('id', 'name')) |
|
538 | template_choices=Experiment.objects.filter(template=True).values_list('id', 'name')) | |
481 | else: |
|
539 | else: | |
482 | kwargs['button'] = 'Create' |
|
540 | kwargs['button'] = 'Create' | |
483 | kwargs['configurations'] = Configuration.objects.filter(experiment=request.GET['template']) |
|
541 | kwargs['configurations'] = Configuration.objects.filter(experiment=request.GET['template']) | |
484 | kwargs['configuration_keys'] = ['name', 'device__name', 'device__ip_address', 'device__port_address'] |
|
542 | kwargs['configuration_keys'] = ['name', 'device__name', 'device__ip_address', 'device__port_address'] | |
485 | exp=Experiment.objects.get(pk=request.GET['template']) |
|
543 | exp=Experiment.objects.get(pk=request.GET['template']) | |
486 | form = ExperimentForm(instance=exp, |
|
544 | form = ExperimentForm(instance=exp, | |
487 | initial={'name': '{} [{:%Y/%m/%d}]'.format(exp.name, datetime.now()), |
|
545 | initial={'name': '{} [{:%Y/%m/%d}]'.format(exp.name, datetime.now()), | |
488 | 'template': False}) |
|
546 | 'template': False}) | |
489 | elif 'blank' in request.GET: |
|
547 | elif 'blank' in request.GET: | |
490 | kwargs['button'] = 'Create' |
|
548 | kwargs['button'] = 'Create' | |
491 | form = ExperimentForm() |
|
549 | form = ExperimentForm() | |
492 | else: |
|
550 | else: | |
493 | form = NewForm() |
|
551 | form = NewForm() | |
494 |
|
552 | |||
495 | if request.method == 'POST': |
|
553 | if request.method == 'POST': | |
496 | form = ExperimentForm(request.POST) |
|
554 | form = ExperimentForm(request.POST) | |
497 | if form.is_valid(): |
|
555 | if form.is_valid(): | |
498 | experiment = form.save() |
|
556 | experiment = form.save() | |
499 |
|
557 | |||
500 | if 'template' in request.GET: |
|
558 | if 'template' in request.GET: | |
501 | configurations = Configuration.objects.filter(experiment=request.GET['template'], type=0) |
|
559 | configurations = Configuration.objects.filter(experiment=request.GET['template'], type=0) | |
502 | for conf in configurations: |
|
560 | for conf in configurations: | |
503 | conf.clone(experiment=experiment, template=False) |
|
561 | conf.clone(experiment=experiment, template=False) | |
504 |
|
562 | |||
505 | return redirect('url_experiment', id_exp=experiment.id) |
|
563 | return redirect('url_experiment', id_exp=experiment.id) | |
506 |
|
564 | |||
507 | kwargs['form'] = form |
|
565 | kwargs['form'] = form | |
508 | kwargs['title'] = 'Experiment' |
|
566 | kwargs['title'] = 'Experiment' | |
509 | kwargs['suptitle'] = 'New' |
|
567 | kwargs['suptitle'] = 'New' | |
510 |
|
568 | |||
511 | return render(request, 'experiment_edit.html', kwargs) |
|
569 | return render(request, 'experiment_edit.html', kwargs) | |
512 |
|
570 | |||
513 |
|
571 | |||
514 | def experiment_edit(request, id_exp): |
|
572 | def experiment_edit(request, id_exp): | |
515 |
|
573 | |||
516 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
574 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
517 |
|
575 | |||
518 | if request.method == 'GET': |
|
576 | if request.method == 'GET': | |
519 | form = ExperimentForm(instance=experiment) |
|
577 | form = ExperimentForm(instance=experiment) | |
520 |
|
578 | |||
521 | if request.method=='POST': |
|
579 | if request.method=='POST': | |
522 | form = ExperimentForm(request.POST, instance=experiment) |
|
580 | form = ExperimentForm(request.POST, instance=experiment) | |
523 |
|
581 | |||
524 | if form.is_valid(): |
|
582 | if form.is_valid(): | |
525 | experiment = form.save() |
|
583 | experiment = form.save() | |
526 | return redirect('url_experiment', id_exp=experiment.id) |
|
584 | return redirect('url_experiment', id_exp=experiment.id) | |
527 |
|
585 | |||
528 | kwargs = {} |
|
586 | kwargs = {} | |
529 | kwargs['form'] = form |
|
587 | kwargs['form'] = form | |
530 | kwargs['title'] = 'Experiment' |
|
588 | kwargs['title'] = 'Experiment' | |
531 | kwargs['suptitle'] = 'Edit' |
|
589 | kwargs['suptitle'] = 'Edit' | |
532 | kwargs['button'] = 'Update' |
|
590 | kwargs['button'] = 'Update' | |
533 |
|
591 | |||
534 | return render(request, 'experiment_edit.html', kwargs) |
|
592 | return render(request, 'experiment_edit.html', kwargs) | |
535 |
|
593 | |||
536 |
|
594 | |||
537 | def experiment_delete(request, id_exp): |
|
595 | def experiment_delete(request, id_exp): | |
538 |
|
596 | |||
539 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
597 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
540 |
|
598 | |||
541 | if request.method=='POST': |
|
599 | if request.method=='POST': | |
542 | if request.user.is_staff: |
|
600 | if request.user.is_staff: | |
543 | for conf in Configuration.objects.filter(experiment=experiment): |
|
601 | for conf in Configuration.objects.filter(experiment=experiment): | |
544 | conf.delete() |
|
602 | conf.delete() | |
545 | experiment.delete() |
|
603 | experiment.delete() | |
546 | return redirect('url_experiments') |
|
604 | return redirect('url_experiments') | |
547 |
|
605 | |||
548 | messages.error(request, 'Not enough permission to delete this object') |
|
606 | messages.error(request, 'Not enough permission to delete this object') | |
549 | return redirect(experiment.get_absolute_url()) |
|
607 | return redirect(experiment.get_absolute_url()) | |
550 |
|
608 | |||
551 | kwargs = { |
|
609 | kwargs = { | |
552 | 'title': 'Delete', |
|
610 | 'title': 'Delete', | |
553 | 'suptitle': 'Experiment', |
|
611 | 'suptitle': 'Experiment', | |
554 | 'object': experiment, |
|
612 | 'object': experiment, | |
555 | 'previous': experiment.get_absolute_url(), |
|
613 | 'previous': experiment.get_absolute_url(), | |
556 | 'delete': True |
|
614 | 'delete': True | |
557 | } |
|
615 | } | |
558 |
|
616 | |||
559 | return render(request, 'confirm.html', kwargs) |
|
617 | return render(request, 'confirm.html', kwargs) | |
560 |
|
618 | |||
561 |
|
619 | |||
562 | def experiment_export(request, id_exp): |
|
620 | def experiment_export(request, id_exp): | |
563 |
|
621 | |||
564 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
622 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
565 | content = experiment.parms_to_dict() |
|
623 | content = experiment.parms_to_dict() | |
566 | content_type = 'application/json' |
|
624 | content_type = 'application/json' | |
567 | filename = '%s_%s.json' %(experiment.name, experiment.id) |
|
625 | filename = '%s_%s.json' %(experiment.name, experiment.id) | |
568 |
|
626 | |||
569 | response = HttpResponse(content_type=content_type) |
|
627 | response = HttpResponse(content_type=content_type) | |
570 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename |
|
628 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename | |
571 | response.write(content) |
|
629 | response.write(content) | |
572 |
|
630 | |||
573 | return response |
|
631 | return response | |
574 |
|
632 | |||
|
633 | def experiment_import(request, id_exp): | |||
|
634 | ||||
|
635 | experiment = get_object_or_404(Experiment, pk=id_exp) | |||
|
636 | configurations = Configuration.objects.filter(experiment=experiment) | |||
|
637 | ||||
|
638 | if request.method == 'GET': | |||
|
639 | file_form = UploadFileForm() | |||
|
640 | ||||
|
641 | if request.method == 'POST': | |||
|
642 | file_form = UploadFileForm(request.POST, request.FILES) | |||
|
643 | ||||
|
644 | if file_form.is_valid(): | |||
|
645 | ||||
|
646 | parms = experiment.import_from_file(request.FILES['file']) | |||
|
647 | ||||
|
648 | if parms: | |||
|
649 | location = Location.objects.get(name = parms['radar']) | |||
|
650 | parms['location'] = location.id | |||
|
651 | parms['name'] = parms['experiment'] | |||
|
652 | ||||
|
653 | experiment.dict_to_parms(parms, CONF_MODELS) | |||
|
654 | ||||
|
655 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) | |||
|
656 | ||||
|
657 | form = ExperimentForm(initial=parms, instance=experiment) | |||
|
658 | ||||
|
659 | kwargs = {} | |||
|
660 | #kwargs['id_dev'] = conf.id | |||
|
661 | kwargs['form'] = form | |||
|
662 | kwargs['title'] = 'Experiment' | |||
|
663 | kwargs['suptitle'] = 'Parameters imported' | |||
|
664 | kwargs['button'] = 'Save' | |||
|
665 | kwargs['action'] = experiment.get_absolute_url_edit() | |||
|
666 | kwargs['previous'] = experiment.get_absolute_url() | |||
|
667 | ||||
|
668 | ###### SIDEBAR ###### | |||
|
669 | #kwargs.update(sidebar(conf=conf)) | |||
|
670 | kwargs.update(sidebar(experiment=experiment)) | |||
|
671 | ||||
|
672 | return render(request, 'experiment_edit.html', kwargs) | |||
|
673 | ||||
|
674 | messages.error(request, "Could not import parameters from file") | |||
|
675 | ||||
|
676 | kwargs = {} | |||
|
677 | #kwargs['id_dev'] = conf.id | |||
|
678 | kwargs['title'] = 'Experiment' | |||
|
679 | kwargs['form'] = file_form | |||
|
680 | kwargs['suptitle'] = 'Importing file' | |||
|
681 | kwargs['button'] = 'Import' | |||
|
682 | ||||
|
683 | kwargs.update(sidebar(experiment=experiment)) | |||
|
684 | ||||
|
685 | return render(request, 'experiment_import.html', kwargs) | |||
575 |
|
686 | |||
576 | def experiment_mix(request, id_exp): |
|
687 | def experiment_mix(request, id_exp): | |
577 |
|
688 | |||
578 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
689 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
579 | rc_confs = [conf for conf in RCConfiguration.objects.filter(experiment=id_exp, |
|
690 | rc_confs = [conf for conf in RCConfiguration.objects.filter(experiment=id_exp, | |
580 | mix=False)] |
|
691 | mix=False)] | |
581 |
|
692 | |||
582 | if len(rc_confs)<2: |
|
693 | if len(rc_confs)<2: | |
583 | messages.warning(request, 'You need at least two RC Configurations to make a mix') |
|
694 | messages.warning(request, 'You need at least two RC Configurations to make a mix') | |
584 | return redirect(experiment.get_absolute_url()) |
|
695 | return redirect(experiment.get_absolute_url()) | |
585 |
|
696 | |||
586 | mix_confs = RCConfiguration.objects.filter(experiment=id_exp, mix=True) |
|
697 | mix_confs = RCConfiguration.objects.filter(experiment=id_exp, mix=True) | |
587 |
|
698 | |||
588 | if mix_confs: |
|
699 | if mix_confs: | |
589 | mix = mix_confs[0] |
|
700 | mix = mix_confs[0] | |
590 | else: |
|
701 | else: | |
591 | mix = RCConfiguration(experiment=experiment, |
|
702 | mix = RCConfiguration(experiment=experiment, | |
592 | device=rc_confs[0].device, |
|
703 | device=rc_confs[0].device, | |
593 | ipp=rc_confs[0].ipp, |
|
704 | ipp=rc_confs[0].ipp, | |
594 | clock_in=rc_confs[0].clock_in, |
|
705 | clock_in=rc_confs[0].clock_in, | |
595 | clock_divider=rc_confs[0].clock_divider, |
|
706 | clock_divider=rc_confs[0].clock_divider, | |
596 | mix=True, |
|
707 | mix=True, | |
597 | parameters='') |
|
708 | parameters='') | |
598 | mix.save() |
|
709 | mix.save() | |
599 |
|
710 | |||
600 | line_type = RCLineType.objects.get(name='mix') |
|
711 | line_type = RCLineType.objects.get(name='mix') | |
601 | for i in range(len(rc_confs[0].get_lines())): |
|
712 | for i in range(len(rc_confs[0].get_lines())): | |
602 | line = RCLine(rc_configuration=mix, line_type=line_type, channel=i) |
|
713 | line = RCLine(rc_configuration=mix, line_type=line_type, channel=i) | |
603 | line.save() |
|
714 | line.save() | |
604 |
|
715 | |||
605 | initial = {'name': mix.name, |
|
716 | initial = {'name': mix.name, | |
606 | 'result': parse_mix_result(mix.parameters), |
|
717 | 'result': parse_mix_result(mix.parameters), | |
607 | 'delay': 0, |
|
718 | 'delay': 0, | |
608 | 'mask': [0,1,2,3,4,5,6,7] |
|
719 | 'mask': [0,1,2,3,4,5,6,7] | |
609 | } |
|
720 | } | |
610 |
|
721 | |||
611 | if request.method=='GET': |
|
722 | if request.method=='GET': | |
612 | form = RCMixConfigurationForm(confs=rc_confs, initial=initial) |
|
723 | form = RCMixConfigurationForm(confs=rc_confs, initial=initial) | |
613 |
|
724 | |||
614 | if request.method=='POST': |
|
725 | if request.method=='POST': | |
615 |
|
726 | |||
616 | result = mix.parameters |
|
727 | result = mix.parameters | |
617 |
|
728 | |||
618 | if '{}|'.format(request.POST['experiment']) in result: |
|
729 | if '{}|'.format(request.POST['experiment']) in result: | |
619 | messages.error(request, 'Configuration already added') |
|
730 | messages.error(request, 'Configuration already added') | |
620 | else: |
|
731 | else: | |
621 | if result: |
|
732 | if result: | |
622 | result = '{}-{}|{}|{}|{}'.format(mix.parameters, |
|
733 | result = '{}-{}|{}|{}|{}'.format(mix.parameters, | |
623 | request.POST['experiment'], |
|
734 | request.POST['experiment'], | |
624 | MIX_MODES[request.POST['operation']], |
|
735 | MIX_MODES[request.POST['operation']], | |
625 | float(request.POST['delay']), |
|
736 | float(request.POST['delay']), | |
626 | parse_mask(request.POST.getlist('mask')) |
|
737 | parse_mask(request.POST.getlist('mask')) | |
627 | ) |
|
738 | ) | |
628 | else: |
|
739 | else: | |
629 | result = '{}|{}|{}|{}'.format(request.POST['experiment'], |
|
740 | result = '{}|{}|{}|{}'.format(request.POST['experiment'], | |
630 | MIX_MODES[request.POST['operation']], |
|
741 | MIX_MODES[request.POST['operation']], | |
631 | float(request.POST['delay']), |
|
742 | float(request.POST['delay']), | |
632 | parse_mask(request.POST.getlist('mask')) |
|
743 | parse_mask(request.POST.getlist('mask')) | |
633 | ) |
|
744 | ) | |
634 |
|
745 | |||
635 | mix.parameters = result |
|
746 | mix.parameters = result | |
636 | mix.name = request.POST['name'] |
|
747 | mix.name = request.POST['name'] | |
637 | mix.save() |
|
748 | mix.save() | |
638 | mix.update_pulses() |
|
749 | mix.update_pulses() | |
639 |
|
750 | |||
640 |
|
751 | |||
641 | initial['result'] = parse_mix_result(result) |
|
752 | initial['result'] = parse_mix_result(result) | |
642 | initial['name'] = mix.name |
|
753 | initial['name'] = mix.name | |
643 |
|
754 | |||
644 | form = RCMixConfigurationForm(initial=initial, confs=rc_confs) |
|
755 | form = RCMixConfigurationForm(initial=initial, confs=rc_confs) | |
645 |
|
756 | |||
646 |
|
757 | |||
647 | kwargs = { |
|
758 | kwargs = { | |
648 | 'title': 'Experiment', |
|
759 | 'title': 'Experiment', | |
649 | 'suptitle': 'Mix Configurations', |
|
760 | 'suptitle': 'Mix Configurations', | |
650 | 'form' : form, |
|
761 | 'form' : form, | |
651 | 'extra_button': 'Delete', |
|
762 | 'extra_button': 'Delete', | |
652 | 'button': 'Add', |
|
763 | 'button': 'Add', | |
653 | 'cancel': 'Back', |
|
764 | 'cancel': 'Back', | |
654 | 'previous': experiment.get_absolute_url(), |
|
765 | 'previous': experiment.get_absolute_url(), | |
655 | 'id_exp':id_exp, |
|
766 | 'id_exp':id_exp, | |
656 |
|
767 | |||
657 | } |
|
768 | } | |
658 |
|
769 | |||
659 | return render(request, 'experiment_mix.html', kwargs) |
|
770 | return render(request, 'experiment_mix.html', kwargs) | |
660 |
|
771 | |||
661 |
|
772 | |||
662 | def experiment_mix_delete(request, id_exp): |
|
773 | def experiment_mix_delete(request, id_exp): | |
663 |
|
774 | |||
664 | conf = RCConfiguration.objects.get(experiment=id_exp, mix=True) |
|
775 | conf = RCConfiguration.objects.get(experiment=id_exp, mix=True) | |
665 | values = conf.parameters.split('-') |
|
776 | values = conf.parameters.split('-') | |
666 | conf.parameters = '-'.join(values[:-1]) |
|
777 | conf.parameters = '-'.join(values[:-1]) | |
667 | conf.save() |
|
778 | conf.save() | |
668 |
|
779 | |||
669 | return redirect('url_mix_experiment', id_exp=id_exp) |
|
780 | return redirect('url_mix_experiment', id_exp=id_exp) | |
670 |
|
781 | |||
671 |
|
782 | |||
672 | def parse_mix_result(s): |
|
783 | def parse_mix_result(s): | |
673 |
|
784 | |||
674 | values = s.split('-') |
|
785 | values = s.split('-') | |
675 | html = '' |
|
786 | html = '' | |
676 |
|
787 | |||
677 |
|
788 | |||
678 | for i, value in enumerate(values): |
|
789 | for i, value in enumerate(values): | |
679 | if not value: |
|
790 | if not value: | |
680 | continue |
|
791 | continue | |
681 | pk, mode, delay, mask = value.split('|') |
|
792 | pk, mode, delay, mask = value.split('|') | |
682 | conf = RCConfiguration.objects.get(pk=pk) |
|
793 | conf = RCConfiguration.objects.get(pk=pk) | |
683 | if i==0: |
|
794 | if i==0: | |
684 | html += '{:20.18}{:4}{:9}km{:>6}\r\n'.format( |
|
795 | html += '{:20.18}{:4}{:9}km{:>6}\r\n'.format( | |
685 | conf.name[:18], |
|
796 | conf.name[:18], | |
686 | '---', |
|
797 | '---', | |
687 | delay, |
|
798 | delay, | |
688 | mask) |
|
799 | mask) | |
689 | else: |
|
800 | else: | |
690 | html += '{:20.18}{:4}{:9}km{:>6}\r\n'.format( |
|
801 | html += '{:20.18}{:4}{:9}km{:>6}\r\n'.format( | |
691 | conf.name[:18], |
|
802 | conf.name[:18], | |
692 | mode, |
|
803 | mode, | |
693 | delay, |
|
804 | delay, | |
694 | mask) |
|
805 | mask) | |
695 |
|
806 | |||
696 | return mark_safe(html) |
|
807 | return mark_safe(html) | |
697 |
|
808 | |||
698 | def parse_mask(l): |
|
809 | def parse_mask(l): | |
699 |
|
810 | |||
700 | values = [] |
|
811 | values = [] | |
701 |
|
812 | |||
702 | for x in range(8): |
|
813 | for x in range(8): | |
703 | if '{}'.format(x) in l: |
|
814 | if '{}'.format(x) in l: | |
704 | values.append(1) |
|
815 | values.append(1) | |
705 | else: |
|
816 | else: | |
706 | values.append(0) |
|
817 | values.append(0) | |
707 |
|
818 | |||
708 | values.reverse() |
|
819 | values.reverse() | |
709 |
|
820 | |||
710 | return int(''.join([str(x) for x in values]), 2) |
|
821 | return int(''.join([str(x) for x in values]), 2) | |
711 |
|
822 | |||
712 |
|
823 | |||
713 | def dev_confs(request): |
|
824 | def dev_confs(request): | |
714 |
|
825 | |||
715 | configurations = Configuration.objects.all().order_by('type', 'device__device_type', 'experiment') |
|
826 | configurations = Configuration.objects.all().order_by('type', 'device__device_type', 'experiment') | |
716 |
|
827 | |||
717 | kwargs = {} |
|
828 | kwargs = {} | |
718 |
|
829 | |||
719 | kwargs['configuration_keys'] = ['device', 'name', 'experiment', 'type', 'programmed_date'] |
|
830 | kwargs['configuration_keys'] = ['device', 'name', 'experiment', 'type', 'programmed_date'] | |
720 | kwargs['configurations'] = configurations |
|
831 | kwargs['configurations'] = configurations | |
721 |
|
832 | |||
722 | kwargs['title'] = 'Configuration' |
|
833 | kwargs['title'] = 'Configuration' | |
723 | kwargs['suptitle'] = 'List' |
|
834 | kwargs['suptitle'] = 'List' | |
724 |
|
835 | |||
725 | return render(request, 'dev_confs.html', kwargs) |
|
836 | return render(request, 'dev_confs.html', kwargs) | |
726 |
|
837 | |||
727 |
|
838 | |||
728 | def dev_conf(request, id_conf): |
|
839 | def dev_conf(request, id_conf): | |
729 |
|
840 | |||
730 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
841 | conf = get_object_or_404(Configuration, pk=id_conf) | |
731 |
|
842 | |||
732 | return redirect(conf.get_absolute_url()) |
|
843 | return redirect(conf.get_absolute_url()) | |
733 |
|
844 | |||
734 |
|
845 | |||
735 | def dev_conf_new(request, id_exp=0, id_dev=0): |
|
846 | def dev_conf_new(request, id_exp=0, id_dev=0): | |
736 |
|
847 | |||
737 | initial = {} |
|
848 | initial = {} | |
738 | kwargs = {} |
|
849 | kwargs = {} | |
739 |
|
850 | |||
740 | if id_exp<>0: |
|
851 | if id_exp<>0: | |
741 | initial['experiment'] = id_exp |
|
852 | initial['experiment'] = id_exp | |
742 |
|
853 | |||
743 | if id_dev<>0: |
|
854 | if id_dev<>0: | |
744 | initial['device'] = id_dev |
|
855 | initial['device'] = id_dev | |
745 |
|
856 | |||
746 | if request.method == 'GET': |
|
857 | if request.method == 'GET': | |
747 |
|
858 | |||
748 | if id_dev: |
|
859 | if id_dev: | |
749 | kwargs['button'] = 'Create' |
|
860 | kwargs['button'] = 'Create' | |
750 | device = Device.objects.get(pk=id_dev) |
|
861 | device = Device.objects.get(pk=id_dev) | |
751 | DevConfForm = CONF_FORMS[device.device_type.name] |
|
862 | DevConfForm = CONF_FORMS[device.device_type.name] | |
752 | initial['name'] = request.GET['name'] |
|
863 | initial['name'] = request.GET['name'] | |
753 | form = DevConfForm(initial=initial) |
|
864 | form = DevConfForm(initial=initial) | |
754 | else: |
|
865 | else: | |
755 | if 'template' in request.GET: |
|
866 | if 'template' in request.GET: | |
756 | if request.GET['template']=='0': |
|
867 | if request.GET['template']=='0': | |
757 | form = NewForm(initial={'create_from':2}, |
|
868 | form = NewForm(initial={'create_from':2}, | |
758 | template_choices=Configuration.objects.filter(template=True).values_list('id', 'name')) |
|
869 | template_choices=Configuration.objects.filter(template=True).values_list('id', 'name')) | |
759 | else: |
|
870 | else: | |
760 | kwargs['button'] = 'Create' |
|
871 | kwargs['button'] = 'Create' | |
761 | conf = Configuration.objects.get(pk=request.GET['template']) |
|
872 | conf = Configuration.objects.get(pk=request.GET['template']) | |
762 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
873 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
763 | form = DevConfForm(instance=conf, |
|
874 | form = DevConfForm(instance=conf, | |
764 | initial={'name': '{} [{:%Y/%m/%d}]'.format(conf.name, datetime.now()), |
|
875 | initial={'name': '{} [{:%Y/%m/%d}]'.format(conf.name, datetime.now()), | |
765 | 'template': False}) |
|
876 | 'template': False}) | |
766 | elif 'blank' in request.GET: |
|
877 | elif 'blank' in request.GET: | |
767 | kwargs['button'] = 'Create' |
|
878 | kwargs['button'] = 'Create' | |
768 | form = ConfigurationForm(initial=initial) |
|
879 | form = ConfigurationForm(initial=initial) | |
769 | else: |
|
880 | else: | |
770 | form = NewForm() |
|
881 | form = NewForm() | |
771 |
|
882 | |||
772 | if request.method == 'POST': |
|
883 | if request.method == 'POST': | |
773 |
|
884 | |||
774 | device = Device.objects.get(pk=request.POST['device']) |
|
885 | device = Device.objects.get(pk=request.POST['device']) | |
775 | DevConfForm = CONF_FORMS[device.device_type.name] |
|
886 | DevConfForm = CONF_FORMS[device.device_type.name] | |
776 |
|
887 | |||
777 | form = DevConfForm(request.POST) |
|
888 | form = DevConfForm(request.POST) | |
778 |
|
889 | |||
779 | if form.is_valid(): |
|
890 | if form.is_valid(): | |
780 | conf = form.save() |
|
891 | conf = form.save() | |
781 |
|
892 | |||
782 | if 'template' in request.GET and conf.device.device_type.name=='rc': |
|
893 | if 'template' in request.GET and conf.device.device_type.name=='rc': | |
783 | lines = RCLine.objects.filter(rc_configuration=request.GET['template']) |
|
894 | lines = RCLine.objects.filter(rc_configuration=request.GET['template']) | |
784 | for line in lines: |
|
895 | for line in lines: | |
785 | line.clone(rc_configuration=conf) |
|
896 | line.clone(rc_configuration=conf) | |
786 |
|
897 | |||
787 | return redirect('url_dev_conf', id_conf=conf.pk) |
|
898 | return redirect('url_dev_conf', id_conf=conf.pk) | |
788 |
|
899 | |||
789 |
|
900 | |||
790 | kwargs['id_exp'] = id_exp |
|
901 | kwargs['id_exp'] = id_exp | |
791 | kwargs['form'] = form |
|
902 | kwargs['form'] = form | |
792 | kwargs['title'] = 'Configuration' |
|
903 | kwargs['title'] = 'Configuration' | |
793 | kwargs['suptitle'] = 'New' |
|
904 | kwargs['suptitle'] = 'New' | |
794 |
|
905 | |||
795 |
|
906 | |||
796 | if id_dev != 0: |
|
907 | if id_dev != 0: | |
797 | device = Device.objects.get(pk=id_dev) |
|
908 | device = Device.objects.get(pk=id_dev) | |
798 | if 'dds' in device.device_type.name: |
|
909 | if 'dds' in device.device_type.name: | |
799 | kwargs['dds_device'] = True |
|
910 | kwargs['dds_device'] = True | |
800 |
|
911 | |||
801 | return render(request, 'dev_conf_edit.html', kwargs) |
|
912 | return render(request, 'dev_conf_edit.html', kwargs) | |
802 |
|
913 | |||
803 |
|
914 | |||
804 | def dev_conf_edit(request, id_conf): |
|
915 | def dev_conf_edit(request, id_conf): | |
805 |
|
916 | |||
806 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
917 | conf = get_object_or_404(Configuration, pk=id_conf) | |
807 |
|
918 | |||
808 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
919 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
809 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
920 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
810 |
|
921 | |||
811 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
922 | dev_conf = DevConfModel.objects.get(pk=id_conf) | |
812 |
|
923 | |||
813 | if request.method=='GET': |
|
924 | if request.method=='GET': | |
814 | form = DevConfForm(instance=dev_conf) |
|
925 | form = DevConfForm(instance=dev_conf) | |
815 |
|
926 | |||
816 | if request.method=='POST': |
|
927 | if request.method=='POST': | |
817 | form = DevConfForm(request.POST, instance=dev_conf) |
|
928 | form = DevConfForm(request.POST, instance=dev_conf) | |
818 |
|
929 | |||
819 | if form.is_valid(): |
|
930 | if form.is_valid(): | |
820 | form.save() |
|
931 | form.save() | |
821 | return redirect('url_dev_conf', id_conf=id_conf) |
|
932 | return redirect('url_dev_conf', id_conf=id_conf) | |
822 |
|
933 | |||
823 | kwargs = {} |
|
934 | kwargs = {} | |
824 | kwargs['form'] = form |
|
935 | kwargs['form'] = form | |
825 | kwargs['title'] = 'Device Configuration' |
|
936 | kwargs['title'] = 'Device Configuration' | |
826 | kwargs['suptitle'] = 'Edit' |
|
937 | kwargs['suptitle'] = 'Edit' | |
827 | kwargs['button'] = 'Update' |
|
938 | kwargs['button'] = 'Update' | |
828 |
|
939 | |||
829 | ###### SIDEBAR ###### |
|
940 | ###### SIDEBAR ###### | |
830 | kwargs.update(sidebar(conf=conf)) |
|
941 | kwargs.update(sidebar(conf=conf)) | |
831 |
|
942 | |||
832 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) |
|
943 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) | |
833 |
|
944 | |||
834 |
|
945 | |||
835 | def dev_conf_start(request, id_conf): |
|
946 | def dev_conf_start(request, id_conf): | |
836 |
|
947 | |||
837 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
948 | conf = get_object_or_404(Configuration, pk=id_conf) | |
838 |
|
949 | |||
839 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
950 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
840 |
|
951 | |||
841 | conf = DevConfModel.objects.get(pk=id_conf) |
|
952 | conf = DevConfModel.objects.get(pk=id_conf) | |
842 |
|
953 | |||
843 | if conf.start_device(): |
|
954 | if conf.start_device(): | |
844 | messages.success(request, conf.message) |
|
955 | messages.success(request, conf.message) | |
845 | else: |
|
956 | else: | |
846 | messages.error(request, conf.message) |
|
957 | messages.error(request, conf.message) | |
847 |
|
958 | |||
848 | conf.status_device() |
|
959 | conf.status_device() | |
849 |
|
960 | |||
850 | return redirect(conf.get_absolute_url()) |
|
961 | return redirect(conf.get_absolute_url()) | |
851 |
|
962 | |||
852 |
|
963 | |||
853 | def dev_conf_stop(request, id_conf): |
|
964 | def dev_conf_stop(request, id_conf): | |
854 |
|
965 | |||
855 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
966 | conf = get_object_or_404(Configuration, pk=id_conf) | |
856 |
|
967 | |||
857 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
968 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
858 |
|
969 | |||
859 | conf = DevConfModel.objects.get(pk=id_conf) |
|
970 | conf = DevConfModel.objects.get(pk=id_conf) | |
860 |
|
971 | |||
861 | if conf.stop_device(): |
|
972 | if conf.stop_device(): | |
862 | messages.success(request, conf.message) |
|
973 | messages.success(request, conf.message) | |
863 | else: |
|
974 | else: | |
864 | messages.error(request, conf.message) |
|
975 | messages.error(request, conf.message) | |
865 |
|
976 | |||
866 | conf.status_device() |
|
977 | conf.status_device() | |
867 |
|
978 | |||
868 | return redirect(conf.get_absolute_url()) |
|
979 | return redirect(conf.get_absolute_url()) | |
869 |
|
980 | |||
870 |
|
981 | |||
871 | def dev_conf_status(request, id_conf): |
|
982 | def dev_conf_status(request, id_conf): | |
872 |
|
983 | |||
873 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
984 | conf = get_object_or_404(Configuration, pk=id_conf) | |
874 |
|
985 | |||
875 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
986 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
876 |
|
987 | |||
877 | conf = DevConfModel.objects.get(pk=id_conf) |
|
988 | conf = DevConfModel.objects.get(pk=id_conf) | |
878 |
|
989 | |||
879 | if conf.status_device(): |
|
990 | if conf.status_device(): | |
880 | messages.success(request, conf.message) |
|
991 | messages.success(request, conf.message) | |
881 | else: |
|
992 | else: | |
882 | messages.error(request, conf.message) |
|
993 | messages.error(request, conf.message) | |
883 |
|
994 | |||
884 | return redirect(conf.get_absolute_url()) |
|
995 | return redirect(conf.get_absolute_url()) | |
885 |
|
996 | |||
886 |
|
997 | |||
887 | def dev_conf_write(request, id_conf): |
|
998 | def dev_conf_write(request, id_conf): | |
888 |
|
999 | |||
889 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1000 | conf = get_object_or_404(Configuration, pk=id_conf) | |
890 |
|
1001 | |||
891 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
1002 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
892 |
|
1003 | |||
893 | conf = DevConfModel.objects.get(pk=id_conf) |
|
1004 | conf = DevConfModel.objects.get(pk=id_conf) | |
894 |
|
1005 | |||
895 | answer = conf.write_device() |
|
1006 | answer = conf.write_device() | |
896 | conf.status_device() |
|
1007 | conf.status_device() | |
897 |
|
1008 | |||
898 | if answer: |
|
1009 | if answer: | |
899 | messages.success(request, conf.message) |
|
1010 | messages.success(request, conf.message) | |
900 |
|
1011 | |||
901 | #Creating a historical configuration |
|
1012 | #Creating a historical configuration | |
902 | conf.clone(type=0, template=False) |
|
1013 | conf.clone(type=0, template=False) | |
903 |
|
1014 | |||
904 | #Original configuration |
|
1015 | #Original configuration | |
905 | conf = DevConfModel.objects.get(pk=id_conf) |
|
1016 | conf = DevConfModel.objects.get(pk=id_conf) | |
906 | else: |
|
1017 | else: | |
907 | messages.error(request, conf.message) |
|
1018 | messages.error(request, conf.message) | |
908 |
|
1019 | |||
909 | return redirect(conf.get_absolute_url()) |
|
1020 | return redirect(conf.get_absolute_url()) | |
910 |
|
1021 | |||
911 |
|
1022 | |||
912 | def dev_conf_read(request, id_conf): |
|
1023 | def dev_conf_read(request, id_conf): | |
913 |
|
1024 | |||
914 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1025 | conf = get_object_or_404(Configuration, pk=id_conf) | |
915 |
|
1026 | |||
916 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
1027 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
917 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
1028 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
918 |
|
1029 | |||
919 | conf = DevConfModel.objects.get(pk=id_conf) |
|
1030 | conf = DevConfModel.objects.get(pk=id_conf) | |
920 |
|
1031 | |||
921 | if request.method=='GET': |
|
1032 | if request.method=='GET': | |
922 |
|
1033 | |||
923 | parms = conf.read_device() |
|
1034 | parms = conf.read_device() | |
924 | conf.status_device() |
|
1035 | conf.status_device() | |
925 |
|
1036 | |||
926 | if not parms: |
|
1037 | if not parms: | |
927 | messages.error(request, conf.message) |
|
1038 | messages.error(request, conf.message) | |
928 | return redirect(conf.get_absolute_url()) |
|
1039 | return redirect(conf.get_absolute_url()) | |
929 |
|
1040 | |||
930 | form = DevConfForm(initial=parms, instance=conf) |
|
1041 | form = DevConfForm(initial=parms, instance=conf) | |
931 |
|
1042 | |||
932 | if request.method=='POST': |
|
1043 | if request.method=='POST': | |
933 | form = DevConfForm(request.POST, instance=conf) |
|
1044 | form = DevConfForm(request.POST, instance=conf) | |
934 |
|
1045 | |||
935 | if form.is_valid(): |
|
1046 | if form.is_valid(): | |
936 | form.save() |
|
1047 | form.save() | |
937 | return redirect(conf.get_absolute_url()) |
|
1048 | return redirect(conf.get_absolute_url()) | |
938 |
|
1049 | |||
939 | messages.error(request, "Parameters could not be saved") |
|
1050 | messages.error(request, "Parameters could not be saved") | |
940 |
|
1051 | |||
941 | kwargs = {} |
|
1052 | kwargs = {} | |
942 | kwargs['id_dev'] = conf.id |
|
1053 | kwargs['id_dev'] = conf.id | |
943 | kwargs['form'] = form |
|
1054 | kwargs['form'] = form | |
944 | kwargs['title'] = 'Device Configuration' |
|
1055 | kwargs['title'] = 'Device Configuration' | |
945 | kwargs['suptitle'] = 'Parameters read from device' |
|
1056 | kwargs['suptitle'] = 'Parameters read from device' | |
946 | kwargs['button'] = 'Save' |
|
1057 | kwargs['button'] = 'Save' | |
947 |
|
1058 | |||
948 | ###### SIDEBAR ###### |
|
1059 | ###### SIDEBAR ###### | |
949 | kwargs.update(sidebar(conf=conf)) |
|
1060 | kwargs.update(sidebar(conf=conf)) | |
950 |
|
1061 | |||
951 | return render(request, '%s_conf_edit.html' %conf.device.device_type.name, kwargs) |
|
1062 | return render(request, '%s_conf_edit.html' %conf.device.device_type.name, kwargs) | |
952 |
|
1063 | |||
953 |
|
1064 | |||
954 | def dev_conf_import(request, id_conf): |
|
1065 | def dev_conf_import(request, id_conf): | |
955 |
|
1066 | |||
956 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1067 | conf = get_object_or_404(Configuration, pk=id_conf) | |
957 |
|
1068 | |||
958 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
1069 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
959 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
1070 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
960 | conf = DevConfModel.objects.get(pk=id_conf) |
|
1071 | conf = DevConfModel.objects.get(pk=id_conf) | |
961 |
|
1072 | |||
962 | if request.method == 'GET': |
|
1073 | if request.method == 'GET': | |
963 | file_form = UploadFileForm() |
|
1074 | file_form = UploadFileForm() | |
964 |
|
1075 | |||
965 | if request.method == 'POST': |
|
1076 | if request.method == 'POST': | |
966 | file_form = UploadFileForm(request.POST, request.FILES) |
|
1077 | file_form = UploadFileForm(request.POST, request.FILES) | |
967 |
|
1078 | |||
968 | if file_form.is_valid(): |
|
1079 | if file_form.is_valid(): | |
969 |
|
1080 | |||
970 | parms = conf.import_from_file(request.FILES['file']) |
|
1081 | parms = conf.import_from_file(request.FILES['file']) | |
971 |
|
1082 | |||
972 | if parms: |
|
1083 | if parms: | |
973 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) |
|
1084 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) | |
974 | form = DevConfForm(initial=parms, instance=conf) |
|
1085 | form = DevConfForm(initial=parms, instance=conf) | |
975 |
|
1086 | |||
976 | kwargs = {} |
|
1087 | kwargs = {} | |
977 | kwargs['id_dev'] = conf.id |
|
1088 | kwargs['id_dev'] = conf.id | |
978 | kwargs['form'] = form |
|
1089 | kwargs['form'] = form | |
979 | kwargs['title'] = 'Device Configuration' |
|
1090 | kwargs['title'] = 'Device Configuration' | |
980 | kwargs['suptitle'] = 'Parameters imported' |
|
1091 | kwargs['suptitle'] = 'Parameters imported' | |
981 | kwargs['button'] = 'Save' |
|
1092 | kwargs['button'] = 'Save' | |
982 | kwargs['action'] = conf.get_absolute_url_edit() |
|
1093 | kwargs['action'] = conf.get_absolute_url_edit() | |
983 | kwargs['previous'] = conf.get_absolute_url() |
|
1094 | kwargs['previous'] = conf.get_absolute_url() | |
984 |
|
1095 | |||
985 | ###### SIDEBAR ###### |
|
1096 | ###### SIDEBAR ###### | |
986 | kwargs.update(sidebar(conf=conf)) |
|
1097 | kwargs.update(sidebar(conf=conf)) | |
987 |
|
1098 | |||
988 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) |
|
1099 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) | |
989 |
|
1100 | |||
990 | messages.error(request, "Could not import parameters from file") |
|
1101 | messages.error(request, "Could not import parameters from file") | |
991 |
|
1102 | |||
992 | kwargs = {} |
|
1103 | kwargs = {} | |
993 | kwargs['id_dev'] = conf.id |
|
1104 | kwargs['id_dev'] = conf.id | |
994 | kwargs['title'] = 'Device Configuration' |
|
1105 | kwargs['title'] = 'Device Configuration' | |
995 | kwargs['form'] = file_form |
|
1106 | kwargs['form'] = file_form | |
996 | kwargs['suptitle'] = 'Importing file' |
|
1107 | kwargs['suptitle'] = 'Importing file' | |
997 | kwargs['button'] = 'Import' |
|
1108 | kwargs['button'] = 'Import' | |
998 |
|
1109 | |||
999 | kwargs.update(sidebar(conf=conf)) |
|
1110 | kwargs.update(sidebar(conf=conf)) | |
1000 |
|
1111 | |||
1001 | return render(request, 'dev_conf_import.html', kwargs) |
|
1112 | return render(request, 'dev_conf_import.html', kwargs) | |
1002 |
|
1113 | |||
1003 |
|
1114 | |||
1004 | def dev_conf_export(request, id_conf): |
|
1115 | def dev_conf_export(request, id_conf): | |
1005 |
|
1116 | |||
1006 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1117 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1007 |
|
1118 | |||
1008 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
1119 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
1009 |
|
1120 | |||
1010 | conf = DevConfModel.objects.get(pk=id_conf) |
|
1121 | conf = DevConfModel.objects.get(pk=id_conf) | |
1011 |
|
1122 | |||
1012 | if request.method == 'GET': |
|
1123 | if request.method == 'GET': | |
1013 | file_form = DownloadFileForm(conf.device.device_type.name) |
|
1124 | file_form = DownloadFileForm(conf.device.device_type.name) | |
1014 |
|
1125 | |||
1015 | if request.method == 'POST': |
|
1126 | if request.method == 'POST': | |
1016 | file_form = DownloadFileForm(conf.device.device_type.name, request.POST) |
|
1127 | file_form = DownloadFileForm(conf.device.device_type.name, request.POST) | |
1017 |
|
1128 | |||
1018 | if file_form.is_valid(): |
|
1129 | if file_form.is_valid(): | |
1019 | fields = conf.export_to_file(format = file_form.cleaned_data['format']) |
|
1130 | fields = conf.export_to_file(format = file_form.cleaned_data['format']) | |
1020 |
|
1131 | |||
1021 | response = HttpResponse(content_type=fields['content_type']) |
|
1132 | response = HttpResponse(content_type=fields['content_type']) | |
1022 | response['Content-Disposition'] = 'attachment; filename="%s"' %fields['filename'] |
|
1133 | response['Content-Disposition'] = 'attachment; filename="%s"' %fields['filename'] | |
1023 | response.write(fields['content']) |
|
1134 | response.write(fields['content']) | |
1024 |
|
1135 | |||
1025 | return response |
|
1136 | return response | |
1026 |
|
1137 | |||
1027 | messages.error(request, "Could not export parameters") |
|
1138 | messages.error(request, "Could not export parameters") | |
1028 |
|
1139 | |||
1029 | kwargs = {} |
|
1140 | kwargs = {} | |
1030 | kwargs['id_dev'] = conf.id |
|
1141 | kwargs['id_dev'] = conf.id | |
1031 | kwargs['title'] = 'Device Configuration' |
|
1142 | kwargs['title'] = 'Device Configuration' | |
1032 | kwargs['form'] = file_form |
|
1143 | kwargs['form'] = file_form | |
1033 | kwargs['suptitle'] = 'Exporting file' |
|
1144 | kwargs['suptitle'] = 'Exporting file' | |
1034 | kwargs['button'] = 'Export' |
|
1145 | kwargs['button'] = 'Export' | |
1035 |
|
1146 | |||
1036 | return render(request, 'dev_conf_export.html', kwargs) |
|
1147 | return render(request, 'dev_conf_export.html', kwargs) | |
1037 |
|
1148 | |||
1038 |
|
1149 | |||
1039 | def dev_conf_delete(request, id_conf): |
|
1150 | def dev_conf_delete(request, id_conf): | |
1040 |
|
1151 | |||
1041 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1152 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1042 |
|
1153 | |||
1043 | if request.method=='POST': |
|
1154 | if request.method=='POST': | |
1044 | if request.user.is_staff: |
|
1155 | if request.user.is_staff: | |
1045 | conf.delete() |
|
1156 | conf.delete() | |
1046 | return redirect('url_dev_confs') |
|
1157 | return redirect('url_dev_confs') | |
1047 |
|
1158 | |||
1048 | messages.error(request, 'Not enough permission to delete this object') |
|
1159 | messages.error(request, 'Not enough permission to delete this object') | |
1049 | return redirect(conf.get_absolute_url()) |
|
1160 | return redirect(conf.get_absolute_url()) | |
1050 |
|
1161 | |||
1051 | kwargs = { |
|
1162 | kwargs = { | |
1052 | 'title': 'Delete', |
|
1163 | 'title': 'Delete', | |
1053 | 'suptitle': 'Experiment', |
|
1164 | 'suptitle': 'Experiment', | |
1054 | 'object': conf, |
|
1165 | 'object': conf, | |
1055 | 'previous': conf.get_absolute_url(), |
|
1166 | 'previous': conf.get_absolute_url(), | |
1056 | 'delete': True |
|
1167 | 'delete': True | |
1057 | } |
|
1168 | } | |
1058 |
|
1169 | |||
1059 | return render(request, 'confirm.html', kwargs) |
|
1170 | return render(request, 'confirm.html', kwargs) | |
1060 |
|
1171 | |||
1061 |
|
1172 | |||
1062 | def sidebar(**kwargs): |
|
1173 | def sidebar(**kwargs): | |
1063 |
|
1174 | |||
1064 | side_data = {} |
|
1175 | side_data = {} | |
1065 |
|
1176 | |||
1066 | conf = kwargs.get('conf', None) |
|
1177 | conf = kwargs.get('conf', None) | |
1067 | experiment = kwargs.get('experiment', None) |
|
1178 | experiment = kwargs.get('experiment', None) | |
1068 |
|
1179 | |||
1069 | if not experiment: |
|
1180 | if not experiment: | |
1070 | experiment = conf.experiment |
|
1181 | experiment = conf.experiment | |
1071 |
|
1182 | |||
1072 | if experiment: |
|
1183 | if experiment: | |
1073 | side_data['experiment'] = experiment |
|
1184 | side_data['experiment'] = experiment | |
1074 | campaign = experiment.campaign_set.all() |
|
1185 | campaign = experiment.campaign_set.all() | |
1075 | if campaign: |
|
1186 | if campaign: | |
1076 | side_data['campaign'] = campaign[0] |
|
1187 | side_data['campaign'] = campaign[0] | |
1077 | experiments = campaign[0].experiments.all() |
|
1188 | experiments = campaign[0].experiments.all() | |
1078 | else: |
|
1189 | else: | |
1079 | experiments = [experiment] |
|
1190 | experiments = [experiment] | |
1080 | configurations = experiment.configuration_set.filter(type=0) |
|
1191 | configurations = experiment.configuration_set.filter(type=0) | |
1081 | side_data['side_experiments'] = experiments |
|
1192 | side_data['side_experiments'] = experiments | |
1082 | side_data['side_configurations'] = configurations |
|
1193 | side_data['side_configurations'] = configurations | |
1083 |
|
1194 | |||
1084 | return side_data |
|
1195 | return side_data | |
1085 |
|
1196 | |||
1086 |
|
1197 | |||
1087 | def operation(request, id_camp=None): |
|
1198 | def operation(request, id_camp=None): | |
1088 |
|
1199 | |||
1089 | if not id_camp: |
|
1200 | if not id_camp: | |
1090 | campaigns = Campaign.objects.all().order_by('-start_date') |
|
1201 | campaigns = Campaign.objects.all().order_by('-start_date') | |
1091 |
|
1202 | |||
1092 | if not campaigns: |
|
1203 | if not campaigns: | |
1093 | kwargs = {} |
|
1204 | kwargs = {} | |
1094 | kwargs['title'] = 'No Campaigns' |
|
1205 | kwargs['title'] = 'No Campaigns' | |
1095 | kwargs['suptitle'] = 'Empty' |
|
1206 | kwargs['suptitle'] = 'Empty' | |
1096 | return render(request, 'operation.html', kwargs) |
|
1207 | return render(request, 'operation.html', kwargs) | |
1097 |
|
1208 | |||
1098 | id_camp = campaigns[0].id |
|
1209 | id_camp = campaigns[0].id | |
1099 |
|
1210 | |||
1100 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1211 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
1101 |
|
1212 | |||
1102 | if request.method=='GET': |
|
1213 | if request.method=='GET': | |
1103 | form = OperationForm(initial={'campaign': campaign.id}, length = 5) |
|
1214 | form = OperationForm(initial={'campaign': campaign.id}, length = 5) | |
1104 |
|
1215 | |||
1105 | if request.method=='POST': |
|
1216 | if request.method=='POST': | |
1106 | form = OperationForm(request.POST, initial={'campaign':campaign.id}, length = 5) |
|
1217 | form = OperationForm(request.POST, initial={'campaign':campaign.id}, length = 5) | |
1107 |
|
1218 | |||
1108 | if form.is_valid(): |
|
1219 | if form.is_valid(): | |
1109 | return redirect('url_operation', id_camp=campaign.id) |
|
1220 | return redirect('url_operation', id_camp=campaign.id) | |
1110 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() |
|
1221 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() | |
1111 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) |
|
1222 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) | |
1112 | #for exs in experiments: |
|
1223 | #for exs in experiments: | |
1113 | # exs.get_status() |
|
1224 | # exs.get_status() | |
1114 | locations= Location.objects.filter(experiment=experiments).distinct() |
|
1225 | locations= Location.objects.filter(experiment=experiments).distinct() | |
1115 | #experiments = [Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) for location in locations] |
|
1226 | #experiments = [Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) for location in locations] | |
1116 | kwargs = {} |
|
1227 | kwargs = {} | |
1117 | #---Campaign |
|
1228 | #---Campaign | |
1118 | kwargs['campaign'] = campaign |
|
1229 | kwargs['campaign'] = campaign | |
1119 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
1230 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
1120 | #---Experiment |
|
1231 | #---Experiment | |
1121 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] |
|
1232 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] | |
1122 | kwargs['experiment_keys'] = keys[1:] |
|
1233 | kwargs['experiment_keys'] = keys[1:] | |
1123 | kwargs['experiments'] = experiments |
|
1234 | kwargs['experiments'] = experiments | |
1124 | #---Radar |
|
1235 | #---Radar | |
1125 | kwargs['locations'] = locations |
|
1236 | kwargs['locations'] = locations | |
1126 | #---Else |
|
1237 | #---Else | |
1127 | kwargs['title'] = 'Campaign' |
|
1238 | kwargs['title'] = 'Campaign' | |
1128 | kwargs['suptitle'] = campaign.name |
|
1239 | kwargs['suptitle'] = campaign.name | |
1129 | kwargs['form'] = form |
|
1240 | kwargs['form'] = form | |
1130 | kwargs['button'] = 'Search' |
|
1241 | kwargs['button'] = 'Search' | |
1131 | kwargs['details'] = True |
|
1242 | kwargs['details'] = True | |
1132 | kwargs['search_button'] = True |
|
1243 | kwargs['search_button'] = True | |
1133 |
|
1244 | |||
1134 | return render(request, 'operation.html', kwargs) |
|
1245 | return render(request, 'operation.html', kwargs) | |
1135 |
|
1246 | |||
1136 |
|
1247 | |||
1137 | def operation_search(request, id_camp=None): |
|
1248 | def operation_search(request, id_camp=None): | |
1138 |
|
1249 | |||
1139 |
|
1250 | |||
1140 | if not id_camp: |
|
1251 | if not id_camp: | |
1141 | campaigns = Campaign.objects.all().order_by('-start_date') |
|
1252 | campaigns = Campaign.objects.all().order_by('-start_date') | |
1142 |
|
1253 | |||
1143 | if not campaigns: |
|
1254 | if not campaigns: | |
1144 | return render(request, 'operation.html', {}) |
|
1255 | return render(request, 'operation.html', {}) | |
1145 |
|
1256 | |||
1146 | id_camp = campaigns[0].id |
|
1257 | id_camp = campaigns[0].id | |
1147 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1258 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
1148 |
|
1259 | |||
1149 | if request.method=='GET': |
|
1260 | if request.method=='GET': | |
1150 | form = OperationSearchForm(initial={'campaign': campaign.id}) |
|
1261 | form = OperationSearchForm(initial={'campaign': campaign.id}) | |
1151 |
|
1262 | |||
1152 | if request.method=='POST': |
|
1263 | if request.method=='POST': | |
1153 | form = OperationSearchForm(request.POST, initial={'campaign':campaign.id}) |
|
1264 | form = OperationSearchForm(request.POST, initial={'campaign':campaign.id}) | |
1154 |
|
1265 | |||
1155 | if form.is_valid(): |
|
1266 | if form.is_valid(): | |
1156 | return redirect('url_operation', id_camp=campaign.id) |
|
1267 | return redirect('url_operation', id_camp=campaign.id) | |
1157 |
|
1268 | |||
1158 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() |
|
1269 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() | |
1159 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) |
|
1270 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) | |
1160 | #for exs in experiments: |
|
1271 | #for exs in experiments: | |
1161 | # exs.get_status() |
|
1272 | # exs.get_status() | |
1162 | locations= Location.objects.filter(experiment=experiments).distinct() |
|
1273 | locations= Location.objects.filter(experiment=experiments).distinct() | |
1163 | form = OperationSearchForm(initial={'campaign': campaign.id}) |
|
1274 | form = OperationSearchForm(initial={'campaign': campaign.id}) | |
1164 |
|
1275 | |||
1165 | kwargs = {} |
|
1276 | kwargs = {} | |
1166 | #---Campaign |
|
1277 | #---Campaign | |
1167 | kwargs['campaign'] = campaign |
|
1278 | kwargs['campaign'] = campaign | |
1168 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
1279 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
1169 | #---Experiment |
|
1280 | #---Experiment | |
1170 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] |
|
1281 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] | |
1171 | kwargs['experiment_keys'] = keys[1:] |
|
1282 | kwargs['experiment_keys'] = keys[1:] | |
1172 | kwargs['experiments'] = experiments |
|
1283 | kwargs['experiments'] = experiments | |
1173 | #---Radar |
|
1284 | #---Radar | |
1174 | kwargs['locations'] = locations |
|
1285 | kwargs['locations'] = locations | |
1175 | #---Else |
|
1286 | #---Else | |
1176 | kwargs['title'] = 'Campaign' |
|
1287 | kwargs['title'] = 'Campaign' | |
1177 | kwargs['suptitle'] = campaign.name |
|
1288 | kwargs['suptitle'] = campaign.name | |
1178 | kwargs['form'] = form |
|
1289 | kwargs['form'] = form | |
1179 | kwargs['button'] = 'Select' |
|
1290 | kwargs['button'] = 'Select' | |
1180 | kwargs['details'] = True |
|
1291 | kwargs['details'] = True | |
1181 | kwargs['search_button'] = False |
|
1292 | kwargs['search_button'] = False | |
1182 |
|
1293 | |||
1183 | return render(request, 'operation.html', kwargs) |
|
1294 | return render(request, 'operation.html', kwargs) | |
1184 |
|
1295 | |||
1185 |
|
1296 | |||
1186 | def radar_play(request, id_camp, id_radar): |
|
1297 | def radar_play(request, id_camp, id_radar): | |
1187 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1298 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
1188 | radar = get_object_or_404(Location, pk = id_radar) |
|
1299 | radar = get_object_or_404(Location, pk = id_radar) | |
1189 | today = datetime.today() |
|
1300 | today = datetime.today() | |
1190 | now = today.time() |
|
1301 | now = today.time() | |
1191 |
|
1302 | |||
1192 | #--Clear Old Experiments From RunningExperiment Object |
|
1303 | #--Clear Old Experiments From RunningExperiment Object | |
1193 | running_experiment = RunningExperiment.objects.filter(radar=radar) |
|
1304 | running_experiment = RunningExperiment.objects.filter(radar=radar) | |
1194 | if running_experiment: |
|
1305 | if running_experiment: | |
1195 | running_experiment = running_experiment[0] |
|
1306 | running_experiment = running_experiment[0] | |
1196 | running_experiment.running_experiment.clear() |
|
1307 | running_experiment.running_experiment.clear() | |
1197 | running_experiment.save() |
|
1308 | running_experiment.save() | |
1198 |
|
1309 | |||
1199 | #--If campaign datetime is ok: |
|
1310 | #--If campaign datetime is ok: | |
1200 | if today >= campaign.start_date and today <= campaign.end_date: |
|
1311 | if today >= campaign.start_date and today <= campaign.end_date: | |
1201 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) |
|
1312 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) | |
1202 | for exp in experiments: |
|
1313 | for exp in experiments: | |
1203 | #--If experiment time is ok: |
|
1314 | #--If experiment time is ok: | |
1204 | if now >= exp.start_time and now <= exp.end_time: |
|
1315 | if now >= exp.start_time and now <= exp.end_time: | |
1205 | configurations = Configuration.objects.filter(experiment = exp) |
|
1316 | configurations = Configuration.objects.filter(experiment = exp) | |
1206 | for conf in configurations: |
|
1317 | for conf in configurations: | |
1207 | if 'cgs' in conf.device.device_type.name: |
|
1318 | if 'cgs' in conf.device.device_type.name: | |
1208 | conf.status_device() |
|
1319 | conf.status_device() | |
1209 | else: |
|
1320 | else: | |
1210 | answer = conf.start_device() |
|
1321 | answer = conf.start_device() | |
1211 | conf.status_device() |
|
1322 | conf.status_device() | |
1212 | #--Running Experiment |
|
1323 | #--Running Experiment | |
1213 | old_running_experiment = RunningExperiment.objects.filter(radar=radar) |
|
1324 | old_running_experiment = RunningExperiment.objects.filter(radar=radar) | |
1214 | #--If RunningExperiment element exists |
|
1325 | #--If RunningExperiment element exists | |
1215 | if old_running_experiment: |
|
1326 | if old_running_experiment: | |
1216 | old_running_experiment = old_running_experiment[0] |
|
1327 | old_running_experiment = old_running_experiment[0] | |
1217 | old_running_experiment.running_experiment.add(exp) |
|
1328 | old_running_experiment.running_experiment.add(exp) | |
1218 | old_running_experiment.status = 3 |
|
1329 | old_running_experiment.status = 3 | |
1219 | old_running_experiment.save() |
|
1330 | old_running_experiment.save() | |
1220 | #--Create a new Running_Experiment Object |
|
1331 | #--Create a new Running_Experiment Object | |
1221 | else: |
|
1332 | else: | |
1222 | new_running_experiment = RunningExperiment( |
|
1333 | new_running_experiment = RunningExperiment( | |
1223 | radar = radar, |
|
1334 | radar = radar, | |
1224 | status = 3, |
|
1335 | status = 3, | |
1225 | ) |
|
1336 | ) | |
1226 | new_running_experiment.save() |
|
1337 | new_running_experiment.save() | |
1227 | new_running_experiment.running_experiment.add(exp) |
|
1338 | new_running_experiment.running_experiment.add(exp) | |
1228 | new_running_experiment.save() |
|
1339 | new_running_experiment.save() | |
1229 |
|
1340 | |||
1230 | if answer: |
|
1341 | if answer: | |
1231 | messages.success(request, conf.message) |
|
1342 | messages.success(request, conf.message) | |
1232 | exp.status=2 |
|
1343 | exp.status=2 | |
1233 | exp.save() |
|
1344 | exp.save() | |
1234 | else: |
|
1345 | else: | |
1235 | messages.error(request, conf.message) |
|
1346 | messages.error(request, conf.message) | |
1236 | else: |
|
1347 | else: | |
1237 | if exp.status == 1 or exp.status == 3: |
|
1348 | if exp.status == 1 or exp.status == 3: | |
1238 | exp.status=3 |
|
1349 | exp.status=3 | |
1239 | exp.save() |
|
1350 | exp.save() | |
1240 |
|
1351 | |||
1241 |
|
1352 | |||
1242 | route = request.META['HTTP_REFERER'] |
|
1353 | route = request.META['HTTP_REFERER'] | |
1243 | route = str(route) |
|
1354 | route = str(route) | |
1244 | if 'search' in route: |
|
1355 | if 'search' in route: | |
1245 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) |
|
1356 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) | |
1246 | else: |
|
1357 | else: | |
1247 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1358 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) | |
1248 |
|
1359 | |||
1249 |
|
1360 | |||
1250 | def radar_stop(request, id_camp, id_radar): |
|
1361 | def radar_stop(request, id_camp, id_radar): | |
1251 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1362 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
1252 | radar = get_object_or_404(Location, pk = id_radar) |
|
1363 | radar = get_object_or_404(Location, pk = id_radar) | |
1253 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) |
|
1364 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) | |
1254 |
|
1365 | |||
1255 | for exp in experiments: |
|
1366 | for exp in experiments: | |
1256 | configurations = Configuration.objects.filter(experiment = exp) |
|
1367 | configurations = Configuration.objects.filter(experiment = exp) | |
1257 | for conf in configurations: |
|
1368 | for conf in configurations: | |
1258 | if 'cgs' in conf.device.device_type.name: |
|
1369 | if 'cgs' in conf.device.device_type.name: | |
1259 | conf.status_device() |
|
1370 | conf.status_device() | |
1260 | else: |
|
1371 | else: | |
1261 | answer = conf.stop_device() |
|
1372 | answer = conf.stop_device() | |
1262 | conf.status_device() |
|
1373 | conf.status_device() | |
1263 |
|
1374 | |||
1264 | if answer: |
|
1375 | if answer: | |
1265 | messages.success(request, conf.message) |
|
1376 | messages.success(request, conf.message) | |
1266 | exp.status=1 |
|
1377 | exp.status=1 | |
1267 | exp.save() |
|
1378 | exp.save() | |
1268 | else: |
|
1379 | else: | |
1269 | messages.error(request, conf.message) |
|
1380 | messages.error(request, conf.message) | |
1270 |
|
1381 | |||
1271 |
|
1382 | |||
1272 | route = request.META['HTTP_REFERER'] |
|
1383 | route = request.META['HTTP_REFERER'] | |
1273 | route = str(route) |
|
1384 | route = str(route) | |
1274 | if 'search' in route: |
|
1385 | if 'search' in route: | |
1275 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) |
|
1386 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) | |
1276 | else: |
|
1387 | else: | |
1277 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1388 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) | |
1278 |
|
1389 | |||
1279 |
|
1390 | |||
1280 | def radar_refresh(request, id_camp, id_radar): |
|
1391 | def radar_refresh(request, id_camp, id_radar): | |
1281 |
|
1392 | |||
1282 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1393 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
1283 | radar = get_object_or_404(Location, pk = id_radar) |
|
1394 | radar = get_object_or_404(Location, pk = id_radar) | |
1284 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) |
|
1395 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) | |
1285 | for exs in experiments: |
|
1396 | for exs in experiments: | |
1286 | exs.get_status() |
|
1397 | exs.get_status() | |
1287 |
|
1398 | |||
1288 | route = request.META['HTTP_REFERER'] |
|
1399 | route = request.META['HTTP_REFERER'] | |
1289 | route = str(route) |
|
1400 | route = str(route) | |
1290 | if 'search' in route: |
|
1401 | if 'search' in route: | |
1291 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) |
|
1402 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) | |
1292 | else: |
|
1403 | else: | |
1293 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1404 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) | |
1294 |
|
1405 |
General Comments 0
You need to be logged in to leave comments.
Login now