@@ -1,19 +1,14 | |||||
1 | ## DJANGO |
|
1 | ## DJANGO | |
2 |
|
2 | |||
3 | WSGIScriptAlias / /usr/local/radarsys/radarsys/wsgi.py |
|
3 | WSGIScriptAlias / /usr/local/radarsys/radarsys/wsgi.py | |
4 | WSGIPythonPath /usr/local/radarsys/:/usr/local/virtuals/radarsys/lib/python2.7/site-packages |
|
4 | WSGIPythonPath /usr/local/radarsys/:/usr/local/virtuals/radarsys/lib/python2.7/site-packages | |
5 |
|
5 | |||
6 |
Alias /static/ / |
|
6 | Alias /static/ /var/www/html/static/ | |
7 | <Directory /usr/local/radarsys/apps/main/static> |
|
|||
8 | Require all granted |
|
|||
9 | </Directory> |
|
|||
10 |
|
7 | |||
11 | <Directory /usr/local/radarsys/> |
|
8 | <Directory /usr/local/radarsys/> | |
12 | <Files wsgi.py> |
|
9 | <Files wsgi.py> | |
13 | #Order deny,allow |
|
10 | #Order deny,allow | |
14 | Require all granted |
|
11 | Require all granted | |
15 | #Allow from all |
|
12 | #Allow from all | |
16 | </Files> |
|
13 | </Files> | |
17 | </Directory> |
|
14 | </Directory> No newline at end of file | |
18 |
|
||||
19 |
|
@@ -1,34 +1,34 | |||||
1 | from django import forms |
|
1 | from django import forms | |
2 | from apps.main.models import Device |
|
2 | from apps.main.models import Device | |
3 | from .models import CGSConfiguration |
|
3 | from .models import CGSConfiguration | |
4 |
|
4 | |||
5 | class CGSConfigurationForm(forms.ModelForm): |
|
5 | class CGSConfigurationForm(forms.ModelForm): | |
6 | #freq0.widget = te |
|
6 | ||
7 | def __init__(self, *args, **kwargs): |
|
7 | def __init__(self, *args, **kwargs): | |
8 | #request = kwargs.pop('request') |
|
8 | #request = kwargs.pop('request') | |
9 | super(CGSConfigurationForm, self).__init__(*args, **kwargs) |
|
9 | super(CGSConfigurationForm, self).__init__(*args, **kwargs) | |
10 |
|
10 | |||
11 | instance = getattr(self, 'instance', None) |
|
11 | instance = getattr(self, 'instance', None) | |
12 |
|
12 | |||
13 | if instance and instance.pk: |
|
13 | if instance and instance.pk: | |
14 |
|
14 | |||
15 | devices = Device.objects.filter(device_type__name='cgs') |
|
15 | devices = Device.objects.filter(device_type__name='cgs') | |
16 | items = devices.values('id', 'name', 'device_type__name', 'ip_address') |
|
|||
17 |
|
16 | |||
18 | self.fields['experiment'].widget.attrs['readonly'] = True |
|
17 | if instance.experiment: | |
19 | self.fields['device'].widget.choices = [(item['id'], '[%s]: %s | %s' % (item['device_type__name'], item['name'], item['ip_address'])) for item in items] |
|
18 | self.fields['experiment'].widget.attrs['disabled'] = 'disabled' | |
|
19 | ||||
|
20 | self.fields['device'].widget.choices = [(device.id, device) for device in devices] | |||
20 |
|
21 | |||
21 | def clean(self): |
|
22 | def clean(self): | |
22 | return |
|
23 | return | |
23 | # |
|
24 | # | |
24 |
|
25 | |||
25 | class Meta: |
|
26 | class Meta: | |
26 | model = CGSConfiguration |
|
27 | model = CGSConfiguration | |
27 | #exclude = ('freqs', 'clk_in', 'mult','div',) |
|
28 | exclude = ('type', 'parameters', 'status') | |
28 | # exclude = ('freqs',) |
|
29 | #fields = ('experiment', 'device', 'freq0', 'freq1', 'freq2', 'freq3') | |
29 | fields = ('experiment', 'device', 'freq0', 'freq1', 'freq2', 'freq3') |
|
|||
30 |
|
30 | |||
31 |
|
31 | |||
32 | class UploadFileForm(forms.Form): |
|
32 | class UploadFileForm(forms.Form): | |
33 | title = forms.CharField(label='Extension Type', widget=forms.TextInput(attrs={'readonly':'readonly'})) |
|
33 | title = forms.CharField(label='Extension Type', widget=forms.TextInput(attrs={'readonly':'readonly'})) | |
34 | file = forms.FileField() No newline at end of file |
|
34 | file = forms.FileField() |
@@ -1,176 +1,174 | |||||
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 json_field import JSONField |
|
3 | #from json_field import JSONField | |
4 | from django.core.validators import MinValueValidator, MaxValueValidator |
|
4 | from django.core.validators import MinValueValidator, MaxValueValidator | |
5 |
|
5 | |||
6 |
|
6 | |||
7 | from apps.main.models import Device, Experiment |
|
7 | from apps.main.models import Device, Experiment | |
8 |
|
8 | |||
9 | from files import read_json_file |
|
9 | from files import read_json_file | |
10 | # Create your models here. validators=[MinValueValidator(62.5e6), MaxValueValidator(450e6)] |
|
10 | # Create your models here. validators=[MinValueValidator(62.5e6), MaxValueValidator(450e6)] | |
11 |
|
11 | |||
12 | class CGSConfiguration(Configuration): |
|
12 | class CGSConfiguration(Configuration): | |
13 |
|
13 | |||
14 | freq0 = models.IntegerField(verbose_name='Frequency 0',validators=[MinValueValidator(0), MaxValueValidator(450e6)], blank=True, null=True) |
|
14 | freq0 = models.IntegerField(verbose_name='Frequency 0',validators=[MinValueValidator(0), MaxValueValidator(450e6)], blank=True, null=True) | |
15 | freq1 = models.IntegerField(verbose_name='Frequency 1',validators=[MinValueValidator(0), MaxValueValidator(450e6)], blank=True, null=True) |
|
15 | freq1 = models.IntegerField(verbose_name='Frequency 1',validators=[MinValueValidator(0), MaxValueValidator(450e6)], blank=True, null=True) | |
16 | freq2 = models.IntegerField(verbose_name='Frequency 2',validators=[MinValueValidator(0), MaxValueValidator(450e6)], blank=True, null=True) |
|
16 | freq2 = models.IntegerField(verbose_name='Frequency 2',validators=[MinValueValidator(0), MaxValueValidator(450e6)], blank=True, null=True) | |
17 | freq3 = models.IntegerField(verbose_name='Frequency 3',validators=[MinValueValidator(0), MaxValueValidator(450e6)], blank=True, null=True) |
|
17 | freq3 = models.IntegerField(verbose_name='Frequency 3',validators=[MinValueValidator(0), MaxValueValidator(450e6)], blank=True, null=True) | |
18 | #jfreqs = JSONField(default={"frequencies":[{"f0":freq0,"f1":freq1,"f2":freq2,"f3":freq3}]}, blank=True) |
|
|||
19 |
|
||||
20 |
|
18 | |||
21 | def verify_frequencies(self): |
|
19 | def verify_frequencies(self): | |
22 |
|
20 | |||
23 | return True |
|
21 | return True | |
24 |
|
22 | |||
25 |
|
23 | |||
26 | def update_from_file(self, fp): |
|
24 | def update_from_file(self, fp): | |
27 |
|
25 | |||
28 | kwargs = read_json_file(fp) |
|
26 | kwargs = read_json_file(fp) | |
29 |
|
27 | |||
30 | if not kwargs: |
|
28 | if not kwargs: | |
31 | return False |
|
29 | return False | |
32 |
|
30 | |||
33 | self.freq0 = kwargs['freq0'] |
|
31 | self.freq0 = kwargs['freq0'] | |
34 | self.freq1 = kwargs['freq1'] |
|
32 | self.freq1 = kwargs['freq1'] | |
35 | self.freq2 = kwargs['freq2'] |
|
33 | self.freq2 = kwargs['freq2'] | |
36 | self.freq3 = kwargs['freq3'] |
|
34 | self.freq3 = kwargs['freq3'] | |
37 |
|
35 | |||
38 | return True |
|
36 | return True | |
39 |
|
37 | |||
40 | def parms_to_dict(self): |
|
38 | def parms_to_dict(self): | |
41 |
|
39 | |||
42 | parameters = {} |
|
40 | parameters = {} | |
43 |
|
41 | |||
44 | if self.freq0 == None or self.freq0 == '': |
|
42 | if self.freq0 == None or self.freq0 == '': | |
45 | parameters['freq0'] = 0 |
|
43 | parameters['freq0'] = 0 | |
46 | else: |
|
44 | else: | |
47 | parameters['freq0'] = self.freq0 |
|
45 | parameters['freq0'] = self.freq0 | |
48 |
|
46 | |||
49 | if self.freq1 == None or self.freq1 == '': |
|
47 | if self.freq1 == None or self.freq1 == '': | |
50 | parameters['freq1'] = 0 |
|
48 | parameters['freq1'] = 0 | |
51 | else: |
|
49 | else: | |
52 | parameters['freq1'] = self.freq1 |
|
50 | parameters['freq1'] = self.freq1 | |
53 |
|
51 | |||
54 | if self.freq2 == None or self.freq2 == '': |
|
52 | if self.freq2 == None or self.freq2 == '': | |
55 | parameters['freq2'] = 0 |
|
53 | parameters['freq2'] = 0 | |
56 | else: |
|
54 | else: | |
57 | parameters['freq2'] = self.freq2 |
|
55 | parameters['freq2'] = self.freq2 | |
58 |
|
56 | |||
59 | if self.freq3 == None or self.freq3 == '': |
|
57 | if self.freq3 == None or self.freq3 == '': | |
60 | parameters['freq3'] = 0 |
|
58 | parameters['freq3'] = 0 | |
61 | else: |
|
59 | else: | |
62 | parameters['freq3'] = self.freq3 |
|
60 | parameters['freq3'] = self.freq3 | |
63 |
|
61 | |||
64 |
|
62 | |||
65 | return parameters |
|
63 | return parameters | |
66 |
|
64 | |||
67 |
|
65 | |||
68 | def status_device(self): |
|
66 | def status_device(self): | |
69 |
|
67 | |||
70 | import requests |
|
68 | import requests | |
71 |
|
69 | |||
72 | ip=self.device.ip_address |
|
70 | ip=self.device.ip_address | |
73 | port=self.device.port_address |
|
71 | port=self.device.port_address | |
74 |
|
72 | |||
75 | route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" |
|
73 | route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" | |
76 | try: |
|
74 | try: | |
77 | r = requests.get(route) |
|
75 | r = requests.get(route) | |
78 | except: |
|
76 | except: | |
79 | self.device.status = 0 |
|
77 | self.device.status = 0 | |
80 | self.device.save() |
|
78 | self.device.save() | |
81 | return self.device.status |
|
79 | return self.device.status | |
82 |
|
80 | |||
83 | response = str(r.text) |
|
81 | response = str(r.text) | |
84 | response = response.split(";") |
|
82 | response = response.split(";") | |
85 | icon = response[0] |
|
83 | icon = response[0] | |
86 | status = response[-1] |
|
84 | status = response[-1] | |
87 |
|
85 | |||
88 | print icon, status |
|
86 | print icon, status | |
89 | #"icon" could be: "alert" or "okay" |
|
87 | #"icon" could be: "alert" or "okay" | |
90 | if "alert" in icon: |
|
88 | if "alert" in icon: | |
91 | if "Starting Up" in status: #No Esta conectado |
|
89 | if "Starting Up" in status: #No Esta conectado | |
92 | self.device.status = 0 |
|
90 | self.device.status = 0 | |
93 | else: |
|
91 | else: | |
94 | self.device.status = 1 |
|
92 | self.device.status = 1 | |
95 | elif "okay" in icon: |
|
93 | elif "okay" in icon: | |
96 | self.device.status = 3 |
|
94 | self.device.status = 3 | |
97 | else: |
|
95 | else: | |
98 | self.device.status = 1 |
|
96 | self.device.status = 1 | |
99 |
|
97 | |||
100 | self.message = status |
|
98 | self.message = status | |
101 | self.device.save() |
|
99 | self.device.save() | |
102 |
|
100 | |||
103 |
|
101 | |||
104 | return self.device.status |
|
102 | return self.device.status | |
105 |
|
103 | |||
106 |
|
104 | |||
107 | def read_device(self): |
|
105 | def read_device(self): | |
108 |
|
106 | |||
109 | import requests |
|
107 | import requests | |
110 |
|
108 | |||
111 | ip=self.device.ip_address |
|
109 | ip=self.device.ip_address | |
112 | port=self.device.port_address |
|
110 | port=self.device.port_address | |
113 |
|
111 | |||
114 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" |
|
112 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" | |
115 | try: |
|
113 | try: | |
116 | frequencies = requests.get(route) |
|
114 | frequencies = requests.get(route) | |
117 |
|
115 | |||
118 | except: |
|
116 | except: | |
119 | self.message = "Could not read CGS parameters from this device" |
|
117 | self.message = "Could not read CGS parameters from this device" | |
120 | return None |
|
118 | return None | |
121 |
|
119 | |||
122 | frequencies = frequencies.json() |
|
120 | frequencies = frequencies.json() | |
123 | frequencies = frequencies.get("Frecuencias") |
|
121 | frequencies = frequencies.get("Frecuencias") | |
124 | f0 = frequencies.get("f0") |
|
122 | f0 = frequencies.get("f0") | |
125 | f1 = frequencies.get("f1") |
|
123 | f1 = frequencies.get("f1") | |
126 | f2 = frequencies.get("f2") |
|
124 | f2 = frequencies.get("f2") | |
127 | f3 = frequencies.get("f3") |
|
125 | f3 = frequencies.get("f3") | |
128 |
|
126 | |||
129 | parms = {'freq0': f0, |
|
127 | parms = {'freq0': f0, | |
130 | 'freq1': f1, |
|
128 | 'freq1': f1, | |
131 | 'freq2': f2, |
|
129 | 'freq2': f2, | |
132 | 'freq3': f3} |
|
130 | 'freq3': f3} | |
133 |
|
131 | |||
134 | self.message = "" |
|
132 | self.message = "" | |
135 | return parms |
|
133 | return parms | |
136 |
|
134 | |||
137 |
|
135 | |||
138 | def write_device(self): |
|
136 | def write_device(self): | |
139 |
|
137 | |||
140 | import requests |
|
138 | import requests | |
141 |
|
139 | |||
142 | ip=self.device.ip_address |
|
140 | ip=self.device.ip_address | |
143 | port=self.device.port_address |
|
141 | port=self.device.port_address | |
144 |
|
142 | |||
145 | #---Frequencies from form |
|
143 | #---Frequencies from form | |
146 | f0 = self.freq0 |
|
144 | f0 = self.freq0 | |
147 | f1 = self.freq1 |
|
145 | f1 = self.freq1 | |
148 | f2 = self.freq2 |
|
146 | f2 = self.freq2 | |
149 | f3 = self.freq3 |
|
147 | f3 = self.freq3 | |
150 | post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} |
|
148 | post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} | |
151 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" |
|
149 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" | |
152 |
|
150 | |||
153 | try: |
|
151 | try: | |
154 | r = requests.post(route, post_data) |
|
152 | r = requests.post(route, post_data) | |
155 | except: |
|
153 | except: | |
156 | self.message = "Could not write CGS parameters" |
|
154 | self.message = "Could not write CGS parameters" | |
157 | return None |
|
155 | return None | |
158 |
|
156 | |||
159 | text = r.text |
|
157 | text = r.text | |
160 | text = text.split(',') |
|
158 | text = text.split(',') | |
161 |
|
159 | |||
162 | if len(text)>1: |
|
160 | if len(text)>1: | |
163 | title = text[0] |
|
161 | title = text[0] | |
164 | status = text[1] |
|
162 | status = text[1] | |
165 | if title == "okay": |
|
163 | if title == "okay": | |
166 | self.message = status |
|
164 | self.message = status | |
167 | return 3 |
|
165 | return 3 | |
168 | else: |
|
166 | else: | |
169 | self.message = title + ", " + status |
|
167 | self.message = title + ", " + status | |
170 | return 1 |
|
168 | return 1 | |
171 |
|
169 | |||
172 | return 1 |
|
170 | return 1 | |
173 |
|
171 | |||
174 |
|
172 | |||
175 | class Meta: |
|
173 | class Meta: | |
176 | db_table = 'cgs_configurations' |
|
174 | db_table = 'cgs_configurations' |
@@ -1,326 +1,322 | |||||
1 | from django.shortcuts import redirect, render, get_object_or_404 |
|
1 | from django.shortcuts import redirect, render, get_object_or_404 | |
2 | from django.contrib import messages |
|
2 | from django.contrib import messages | |
3 | from django.http import HttpResponse |
|
3 | from django.http import HttpResponse | |
4 |
|
4 | |||
5 | from apps.main.models import Experiment, Configuration |
|
5 | from apps.main.models import Experiment, Configuration | |
6 | from .models import CGSConfiguration |
|
6 | from .models import CGSConfiguration | |
7 |
|
7 | |||
8 | from .forms import CGSConfigurationForm, UploadFileForm |
|
8 | from .forms import CGSConfigurationForm, UploadFileForm | |
9 | from apps.main.views import sidebar |
|
9 | from apps.main.views import sidebar | |
10 |
|
10 | |||
11 | import requests |
|
11 | import requests | |
12 | import json |
|
12 | import json | |
13 | #from __builtin__ import None |
|
13 | #from __builtin__ import None | |
14 | # Create your views here. |
|
14 | # Create your views here. | |
15 |
|
15 | |||
16 | def cgs_conf(request, id_conf): |
|
16 | def cgs_conf(request, id_conf): | |
17 |
|
17 | |||
18 | conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
18 | conf = get_object_or_404(CGSConfiguration, pk=id_conf) | |
19 |
|
19 | |||
20 | ip=conf.device.ip_address |
|
20 | ip=conf.device.ip_address | |
21 | port=conf.device.port_address |
|
21 | port=conf.device.port_address | |
22 |
|
22 | |||
23 | kwargs = {} |
|
23 | kwargs = {} | |
24 |
|
24 | |||
25 | kwargs['status'] = conf.device.get_status_display() |
|
25 | kwargs['status'] = conf.device.get_status_display() | |
26 |
|
26 | |||
27 | #if request.method=='GET': |
|
27 | #if request.method=='GET': | |
28 | #r: response = icon, status |
|
28 | #r: response = icon, status | |
29 | # try: |
|
29 | # try: | |
30 | # route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" |
|
30 | # route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" | |
31 | # r = requests.get(route) |
|
31 | # r = requests.get(route) | |
32 | # response = str(r.text) |
|
32 | # response = str(r.text) | |
33 | # response = response.split(";") |
|
33 | # response = response.split(";") | |
34 | # icon = response[0] |
|
34 | # icon = response[0] | |
35 | # status = response[-1] |
|
35 | # status = response[-1] | |
36 | #print r.text |
|
36 | #print r.text | |
37 | #"icon" could be: "alert" or "okay" |
|
37 | #"icon" could be: "alert" or "okay" | |
38 | # Si hay alerta pero esta conectado |
|
38 | # Si hay alerta pero esta conectado | |
39 | # if "alert" in icon: |
|
39 | # if "alert" in icon: | |
40 | # if "Starting Up" in status: #No Esta conectado |
|
40 | # if "Starting Up" in status: #No Esta conectado | |
41 | # kwargs['connected'] = False |
|
41 | # kwargs['connected'] = False | |
42 | # else: |
|
42 | # else: | |
43 | # kwargs['connected'] = True |
|
43 | # kwargs['connected'] = True | |
44 | # elif "okay" in icon: |
|
44 | # elif "okay" in icon: | |
45 | # kwargs['connected'] = True |
|
45 | # kwargs['connected'] = True | |
46 | # else: |
|
46 | # else: | |
47 | # kwargs['connected'] = False |
|
47 | # kwargs['connected'] = False | |
48 |
|
48 | |||
49 | # except: |
|
49 | # except: | |
50 | # kwargs['connected'] = False |
|
50 | # kwargs['connected'] = False | |
51 | # status = "The Device is not connected." |
|
51 | # status = "The Device is not connected." | |
52 |
|
52 | |||
53 | #if not kwargs['connected']: |
|
53 | #if not kwargs['connected']: | |
54 | # messages.error(request, message=status) |
|
54 | # messages.error(request, message=status) | |
55 |
|
55 | |||
56 | kwargs['dev_conf'] = conf |
|
56 | kwargs['dev_conf'] = conf | |
57 | kwargs['dev_conf_keys'] = ['experiment', 'device', |
|
57 | kwargs['dev_conf_keys'] = ['experiment', 'device', | |
58 | 'freq0', 'freq1', |
|
58 | 'freq0', 'freq1', | |
59 | 'freq2', 'freq3'] |
|
59 | 'freq2', 'freq3'] | |
60 |
|
60 | |||
61 | kwargs['title'] = 'CGS Configuration' |
|
61 | kwargs['title'] = 'CGS Configuration' | |
62 | kwargs['suptitle'] = 'Details' |
|
62 | kwargs['suptitle'] = 'Details' | |
63 |
|
63 | |||
64 | kwargs['button'] = 'Edit Configuration' |
|
64 | kwargs['button'] = 'Edit Configuration' | |
65 |
|
65 | |||
66 | kwargs['no_play'] = True |
|
66 | kwargs['no_play'] = True | |
67 |
|
67 | |||
68 | ###### SIDEBAR ###### |
|
68 | ###### SIDEBAR ###### | |
69 | kwargs.update(sidebar(conf)) |
|
69 | kwargs.update(sidebar(conf=conf)) | |
70 |
|
70 | |||
71 | return render(request, 'cgs_conf.html', kwargs) |
|
71 | return render(request, 'cgs_conf.html', kwargs) | |
72 |
|
72 | |||
73 | def cgs_conf_edit(request, id_conf): |
|
73 | def cgs_conf_edit(request, id_conf): | |
74 |
|
74 | |||
75 | conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
75 | conf = get_object_or_404(CGSConfiguration, pk=id_conf) | |
76 |
|
76 | |||
77 | if request.method=='GET': |
|
77 | if request.method=='GET': | |
78 | form = CGSConfigurationForm(instance=conf) |
|
78 | form = CGSConfigurationForm(instance=conf) | |
79 |
|
79 | |||
80 | if request.method=='POST': |
|
80 | if request.method=='POST': | |
81 | form = CGSConfigurationForm(request.POST, instance=conf) |
|
81 | form = CGSConfigurationForm(request.POST, instance=conf) | |
82 |
|
82 | |||
83 | if form.is_valid(): |
|
83 | if form.is_valid(): | |
84 | if conf.freq0 == None: conf.freq0 = 0 |
|
84 | if conf.freq0 == None: conf.freq0 = 0 | |
85 | if conf.freq1 == None: conf.freq1 = 0 |
|
85 | if conf.freq1 == None: conf.freq1 = 0 | |
86 | if conf.freq2 == None: conf.freq2 = 0 |
|
86 | if conf.freq2 == None: conf.freq2 = 0 | |
87 | if conf.freq3 == None: conf.freq3 = 0 |
|
87 | if conf.freq3 == None: conf.freq3 = 0 | |
88 |
|
88 | |||
89 | conf = form.save(commit=False) |
|
89 | conf = form.save(commit=False) | |
90 |
|
90 | |||
91 | if conf.verify_frequencies(): |
|
91 | if conf.verify_frequencies(): | |
92 | conf.save() |
|
92 | conf.save() | |
93 | return redirect('url_cgs_conf', id_conf=conf.id) |
|
93 | return redirect('url_cgs_conf', id_conf=conf.id) | |
94 |
|
94 | |||
95 | ##ERRORS |
|
95 | ##ERRORS | |
96 |
|
96 | |||
97 | kwargs = {} |
|
97 | kwargs = {} | |
98 | kwargs['id_dev'] = conf.id |
|
98 | kwargs['id_dev'] = conf.id | |
99 | kwargs['form'] = form |
|
99 | kwargs['form'] = form | |
100 | kwargs['title'] = 'Device Configuration' |
|
100 | kwargs['title'] = 'Device Configuration' | |
101 | kwargs['suptitle'] = 'Edit' |
|
101 | kwargs['suptitle'] = 'Edit' | |
102 | kwargs['button'] = 'Save' |
|
102 | kwargs['button'] = 'Save' | |
103 |
|
103 | |||
104 |
|
||||
105 | ###### SIDEBAR ###### |
|
|||
106 | kwargs.update(sidebar(conf)) |
|
|||
107 |
|
||||
108 | return render(request, 'cgs_conf_edit.html', kwargs) |
|
104 | return render(request, 'cgs_conf_edit.html', kwargs) | |
109 | # |
|
105 | # | |
110 | # def cgs_conf_write(request, id_conf): |
|
106 | # def cgs_conf_write(request, id_conf): | |
111 | # |
|
107 | # | |
112 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
108 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) | |
113 | # ip=conf.device.ip_address |
|
109 | # ip=conf.device.ip_address | |
114 | # port=conf.device.port_address |
|
110 | # port=conf.device.port_address | |
115 | # |
|
111 | # | |
116 | # #Frequencies from form |
|
112 | # #Frequencies from form | |
117 | # f0 = conf.freq0 |
|
113 | # f0 = conf.freq0 | |
118 | # f1 = conf.freq1 |
|
114 | # f1 = conf.freq1 | |
119 | # f2 = conf.freq2 |
|
115 | # f2 = conf.freq2 | |
120 | # f3 = conf.freq3 |
|
116 | # f3 = conf.freq3 | |
121 | # |
|
117 | # | |
122 | # try: |
|
118 | # try: | |
123 | # post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} |
|
119 | # post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} | |
124 | # route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" |
|
120 | # route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" | |
125 | # r = requests.post(route, post_data) |
|
121 | # r = requests.post(route, post_data) | |
126 | # text = r.text |
|
122 | # text = r.text | |
127 | # text = text.split(',') |
|
123 | # text = text.split(',') | |
128 | # |
|
124 | # | |
129 | # try: |
|
125 | # try: | |
130 | # if len(text)>1: |
|
126 | # if len(text)>1: | |
131 | # title = text[0] |
|
127 | # title = text[0] | |
132 | # status = text[1] |
|
128 | # status = text[1] | |
133 | # status_ok = r.status_code |
|
129 | # status_ok = r.status_code | |
134 | # if title == "okay": |
|
130 | # if title == "okay": | |
135 | # messages.success(request, status) |
|
131 | # messages.success(request, status) | |
136 | # else: |
|
132 | # else: | |
137 | # messages.error(request, status) |
|
133 | # messages.error(request, status) | |
138 | # |
|
134 | # | |
139 | # else: |
|
135 | # else: | |
140 | # title = text[0] |
|
136 | # title = text[0] | |
141 | # messages.error(request, title) |
|
137 | # messages.error(request, title) | |
142 | # |
|
138 | # | |
143 | # except: |
|
139 | # except: | |
144 | # messages.error(request, "An hardware error was found.") |
|
140 | # messages.error(request, "An hardware error was found.") | |
145 | # |
|
141 | # | |
146 | # except: |
|
142 | # except: | |
147 | # messages.error(request, "Could not write parameters.") |
|
143 | # messages.error(request, "Could not write parameters.") | |
148 | # |
|
144 | # | |
149 | # |
|
145 | # | |
150 | # |
|
146 | # | |
151 | # |
|
147 | # | |
152 | # return redirect('url_cgs_conf', id_conf=conf.id) |
|
148 | # return redirect('url_cgs_conf', id_conf=conf.id) | |
153 | # |
|
149 | # | |
154 | # def cgs_conf_read(request, id_conf): |
|
150 | # def cgs_conf_read(request, id_conf): | |
155 | # |
|
151 | # | |
156 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
152 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) | |
157 | # |
|
153 | # | |
158 | # ip=conf.device.ip_address |
|
154 | # ip=conf.device.ip_address | |
159 | # port=conf.device.port_address |
|
155 | # port=conf.device.port_address | |
160 | # |
|
156 | # | |
161 | # if request.method=='POST': |
|
157 | # if request.method=='POST': | |
162 | # form = CGSConfigurationForm(request.POST, instance=conf) |
|
158 | # form = CGSConfigurationForm(request.POST, instance=conf) | |
163 | # |
|
159 | # | |
164 | # if form.is_valid(): |
|
160 | # if form.is_valid(): | |
165 | # cgs_model = form.save(commit=False) |
|
161 | # cgs_model = form.save(commit=False) | |
166 | # |
|
162 | # | |
167 | # if cgs_model.verify_frequencies(): |
|
163 | # if cgs_model.verify_frequencies(): | |
168 | # |
|
164 | # | |
169 | # cgs_model.save() |
|
165 | # cgs_model.save() | |
170 | # return redirect('url_cgs_conf', id_conf=conf.id) |
|
166 | # return redirect('url_cgs_conf', id_conf=conf.id) | |
171 | # |
|
167 | # | |
172 | # messages.error(request, "Parameters could not be saved. Invalid parameters") |
|
168 | # messages.error(request, "Parameters could not be saved. Invalid parameters") | |
173 | # |
|
169 | # | |
174 | # data = {} |
|
170 | # data = {} | |
175 | # |
|
171 | # | |
176 | # |
|
172 | # | |
177 | # if request.method=='GET': |
|
173 | # if request.method=='GET': | |
178 | # #r: response = icon, status |
|
174 | # #r: response = icon, status | |
179 | # route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" |
|
175 | # route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" | |
180 | # try: |
|
176 | # try: | |
181 | # r = requests.get(route) |
|
177 | # r = requests.get(route) | |
182 | # response = str(r.text) |
|
178 | # response = str(r.text) | |
183 | # response = response.split(";") |
|
179 | # response = response.split(";") | |
184 | # icon = response[0] |
|
180 | # icon = response[0] | |
185 | # status = response[-1] |
|
181 | # status = response[-1] | |
186 | # print r.text |
|
182 | # print r.text | |
187 | # #"icon" could be: "alert" or "okay" |
|
183 | # #"icon" could be: "alert" or "okay" | |
188 | # if "okay" in icon: |
|
184 | # if "okay" in icon: | |
189 | # messages.success(request, status) |
|
185 | # messages.success(request, status) | |
190 | # else: |
|
186 | # else: | |
191 | # messages.error(request, status) |
|
187 | # messages.error(request, status) | |
192 | # #Get Frequencies |
|
188 | # #Get Frequencies | |
193 | # route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" |
|
189 | # route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" | |
194 | # #frequencies = requests.get('http://10.10.10.175:8080/frequencies/') |
|
190 | # #frequencies = requests.get('http://10.10.10.175:8080/frequencies/') | |
195 | # frequencies = requests.get(route) |
|
191 | # frequencies = requests.get(route) | |
196 | # frequencies = frequencies.json() |
|
192 | # frequencies = frequencies.json() | |
197 | # frequencies = frequencies.get("Frecuencias") |
|
193 | # frequencies = frequencies.get("Frecuencias") | |
198 | # f0 = frequencies.get("f0") |
|
194 | # f0 = frequencies.get("f0") | |
199 | # f1 = frequencies.get("f1") |
|
195 | # f1 = frequencies.get("f1") | |
200 | # f2 = frequencies.get("f2") |
|
196 | # f2 = frequencies.get("f2") | |
201 | # f3 = frequencies.get("f3") |
|
197 | # f3 = frequencies.get("f3") | |
202 | # print f0,f1,f2,f3 |
|
198 | # print f0,f1,f2,f3 | |
203 | # |
|
199 | # | |
204 | # |
|
200 | # | |
205 | # if not response: |
|
201 | # if not response: | |
206 | # messages.error(request, "Could not read parameters from Device") |
|
202 | # messages.error(request, "Could not read parameters from Device") | |
207 | # return redirect('url_cgs_conf', id_conf=conf.id) |
|
203 | # return redirect('url_cgs_conf', id_conf=conf.id) | |
208 | # |
|
204 | # | |
209 | # data = {'experiment' : conf.experiment.id, |
|
205 | # data = {'experiment' : conf.experiment.id, | |
210 | # 'device' : conf.device.id, |
|
206 | # 'device' : conf.device.id, | |
211 | # 'freq0' : f0, |
|
207 | # 'freq0' : f0, | |
212 | # 'freq1' : f1, |
|
208 | # 'freq1' : f1, | |
213 | # 'freq2' : f2, |
|
209 | # 'freq2' : f2, | |
214 | # 'freq3' : f3, |
|
210 | # 'freq3' : f3, | |
215 | # } |
|
211 | # } | |
216 | # except: |
|
212 | # except: | |
217 | # messages.error(request, "Could not read parameters from Device") |
|
213 | # messages.error(request, "Could not read parameters from Device") | |
218 | # data = {'experiment' : conf.experiment.id, |
|
214 | # data = {'experiment' : conf.experiment.id, | |
219 | # 'device' : conf.device.id, |
|
215 | # 'device' : conf.device.id, | |
220 | # 'freq0' : None, |
|
216 | # 'freq0' : None, | |
221 | # 'freq1' : None, |
|
217 | # 'freq1' : None, | |
222 | # 'freq2' : None, |
|
218 | # 'freq2' : None, | |
223 | # 'freq3' : None, |
|
219 | # 'freq3' : None, | |
224 | # } |
|
220 | # } | |
225 | # return redirect('url_cgs_conf', id_conf=conf.id) |
|
221 | # return redirect('url_cgs_conf', id_conf=conf.id) | |
226 | # |
|
222 | # | |
227 | # form = CGSConfigurationForm(initial = data) |
|
223 | # form = CGSConfigurationForm(initial = data) | |
228 | # |
|
224 | # | |
229 | # kwargs = {} |
|
225 | # kwargs = {} | |
230 | # kwargs['id_dev'] = conf.id |
|
226 | # kwargs['id_dev'] = conf.id | |
231 | # kwargs['form'] = form |
|
227 | # kwargs['form'] = form | |
232 | # kwargs['title'] = 'Device Configuration' |
|
228 | # kwargs['title'] = 'Device Configuration' | |
233 | # kwargs['suptitle'] = 'Parameters read from device' |
|
229 | # kwargs['suptitle'] = 'Parameters read from device' | |
234 | # kwargs['button'] = 'Save' |
|
230 | # kwargs['button'] = 'Save' | |
235 | # |
|
231 | # | |
236 | # ###### SIDEBAR ###### |
|
232 | # ###### SIDEBAR ###### | |
237 | # kwargs.update(sidebar(conf)) |
|
233 | # kwargs.update(sidebar(conf)) | |
238 | # |
|
234 | # | |
239 | # return render(request, 'cgs_conf_edit.html', kwargs) |
|
235 | # return render(request, 'cgs_conf_edit.html', kwargs) | |
240 | # |
|
236 | # | |
241 | # def cgs_conf_import(request, id_conf): |
|
237 | # def cgs_conf_import(request, id_conf): | |
242 | # |
|
238 | # | |
243 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
239 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) | |
244 | # |
|
240 | # | |
245 | # if request.method == 'POST': |
|
241 | # if request.method == 'POST': | |
246 | # file_form = UploadFileForm(request.POST, request.FILES) |
|
242 | # file_form = UploadFileForm(request.POST, request.FILES) | |
247 | # |
|
243 | # | |
248 | # if file_form.is_valid(): |
|
244 | # if file_form.is_valid(): | |
249 | # |
|
245 | # | |
250 | # try: |
|
246 | # try: | |
251 | # if conf.update_from_file(request.FILES['file']): |
|
247 | # if conf.update_from_file(request.FILES['file']): | |
252 | # |
|
248 | # | |
253 | # try: |
|
249 | # try: | |
254 | # conf.full_clean() |
|
250 | # conf.full_clean() | |
255 | # except ValidationError as e: |
|
251 | # except ValidationError as e: | |
256 | # messages.error(request, e) |
|
252 | # messages.error(request, e) | |
257 | # else: |
|
253 | # else: | |
258 | # conf.save() |
|
254 | # conf.save() | |
259 | # |
|
255 | # | |
260 | # messages.success(request, "Parameters imported from file: '%s'." %request.FILES['file'].name) |
|
256 | # messages.success(request, "Parameters imported from file: '%s'." %request.FILES['file'].name) | |
261 | # #messages.warning(request,"") |
|
257 | # #messages.warning(request,"") | |
262 | # return redirect('url_cgs_conf', id_conf=conf.id) |
|
258 | # return redirect('url_cgs_conf', id_conf=conf.id) | |
263 | # except: |
|
259 | # except: | |
264 | # messages.error(request, "No JSON object could be decoded.") |
|
260 | # messages.error(request, "No JSON object could be decoded.") | |
265 | # |
|
261 | # | |
266 | # messages.error(request, "Could not import parameters from file") |
|
262 | # messages.error(request, "Could not import parameters from file") | |
267 | # |
|
263 | # | |
268 | # else: |
|
264 | # else: | |
269 | # file_form = UploadFileForm(initial={'title': '.json'}) |
|
265 | # file_form = UploadFileForm(initial={'title': '.json'}) | |
270 | # |
|
266 | # | |
271 | # |
|
267 | # | |
272 | # kwargs = {} |
|
268 | # kwargs = {} | |
273 | # kwargs['id_dev'] = conf.id |
|
269 | # kwargs['id_dev'] = conf.id | |
274 | # kwargs['title'] = 'Device Configuration' |
|
270 | # kwargs['title'] = 'Device Configuration' | |
275 | # kwargs['form'] = file_form |
|
271 | # kwargs['form'] = file_form | |
276 | # kwargs['suptitle'] = 'Importing file' |
|
272 | # kwargs['suptitle'] = 'Importing file' | |
277 | # kwargs['button'] = 'Import' |
|
273 | # kwargs['button'] = 'Import' | |
278 | # |
|
274 | # | |
279 | # kwargs.update(sidebar(conf)) |
|
275 | # kwargs.update(sidebar(conf)) | |
280 | # |
|
276 | # | |
281 | # return render(request, 'cgs_conf_import.html', kwargs) |
|
277 | # return render(request, 'cgs_conf_import.html', kwargs) | |
282 | # |
|
278 | # | |
283 | # def handle_uploaded_file(f): |
|
279 | # def handle_uploaded_file(f): | |
284 | # |
|
280 | # | |
285 | # data = {'freq0' : 62500000, |
|
281 | # data = {'freq0' : 62500000, | |
286 | # 'freq1' : 62500000, |
|
282 | # 'freq1' : 62500000, | |
287 | # 'freq2' : 62500000, |
|
283 | # 'freq2' : 62500000, | |
288 | # 'freq3' : 62500000, |
|
284 | # 'freq3' : 62500000, | |
289 | # } |
|
285 | # } | |
290 | # |
|
286 | # | |
291 | # return data |
|
287 | # return data | |
292 | # |
|
288 | # | |
293 | # def cgs_conf_export(request, id_conf): |
|
289 | # def cgs_conf_export(request, id_conf): | |
294 | # |
|
290 | # | |
295 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
291 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) | |
296 | # ip=conf.device.ip_address |
|
292 | # ip=conf.device.ip_address | |
297 | # port=conf.device.port_address |
|
293 | # port=conf.device.port_address | |
298 | # |
|
294 | # | |
299 | # #if request.method=='GET': |
|
295 | # #if request.method=='GET': | |
300 | # # data = {"Frequencies": [ |
|
296 | # # data = {"Frequencies": [ | |
301 | # # ["freq0", conf.freq0], |
|
297 | # # ["freq0", conf.freq0], | |
302 | # # ["freq1", conf.freq1], |
|
298 | # # ["freq1", conf.freq1], | |
303 | # # ["freq2", conf.freq2], |
|
299 | # # ["freq2", conf.freq2], | |
304 | # # ["freq3", conf.freq3] |
|
300 | # # ["freq3", conf.freq3] | |
305 | # # ]} |
|
301 | # # ]} | |
306 | # # json_data = json.dumps(data) |
|
302 | # # json_data = json.dumps(data) | |
307 | # # conf.parameters = json_data |
|
303 | # # conf.parameters = json_data | |
308 | # # response = HttpResponse(conf.parameters, content_type="application/json") |
|
304 | # # response = HttpResponse(conf.parameters, content_type="application/json") | |
309 | # # response['Content-Disposition'] = 'attachment; filename="data.json"' |
|
305 | # # response['Content-Disposition'] = 'attachment; filename="data.json"' | |
310 | # |
|
306 | # | |
311 | # # return response |
|
307 | # # return response | |
312 | # |
|
308 | # | |
313 | # kwargs = {} |
|
309 | # kwargs = {} | |
314 | # kwargs['dev_conf'] = conf |
|
310 | # kwargs['dev_conf'] = conf | |
315 | # kwargs['dev_conf_keys'] = ['experiment', 'device', |
|
311 | # kwargs['dev_conf_keys'] = ['experiment', 'device', | |
316 | # 'freq0', 'freq1', |
|
312 | # 'freq0', 'freq1', | |
317 | # 'freq2', 'freq3'] |
|
313 | # 'freq2', 'freq3'] | |
318 | # |
|
314 | # | |
319 | # kwargs['title'] = 'CGS Configuration' |
|
315 | # kwargs['title'] = 'CGS Configuration' | |
320 | # kwargs['suptitle'] = 'Details' |
|
316 | # kwargs['suptitle'] = 'Details' | |
321 | # |
|
317 | # | |
322 | # kwargs['button'] = 'Edit Configuration' |
|
318 | # kwargs['button'] = 'Edit Configuration' | |
323 | # |
|
319 | # | |
324 | # ###### SIDEBAR ###### |
|
320 | # ###### SIDEBAR ###### | |
325 | # kwargs.update(sidebar(conf)) |
|
321 | # kwargs.update(sidebar(conf)) | |
326 | # return render(request, 'cgs_conf.html', kwargs) No newline at end of file |
|
322 | # return render(request, 'cgs_conf.html', kwargs) |
@@ -1,29 +1,27 | |||||
1 | from django import forms |
|
1 | from django import forms | |
2 | from apps.main.models import Device |
|
2 | from apps.main.models import Device | |
3 | from .models import DDSConfiguration |
|
3 | from .models import DDSConfiguration | |
4 |
|
4 | |||
5 | # from django.core.validators import MinValueValidator, MaxValueValidator |
|
5 | # from django.core.validators import MinValueValidator, MaxValueValidator | |
6 |
|
6 | |||
7 | class DDSConfigurationForm(forms.ModelForm): |
|
7 | class DDSConfigurationForm(forms.ModelForm): | |
8 |
|
8 | |||
9 | def __init__(self, *args, **kwargs): |
|
9 | def __init__(self, *args, **kwargs): | |
10 | #request = kwargs.pop('request') |
|
10 | #request = kwargs.pop('request') | |
11 | super(DDSConfigurationForm, self).__init__(*args, **kwargs) |
|
11 | super(DDSConfigurationForm, self).__init__(*args, **kwargs) | |
12 |
|
12 | |||
13 | instance = getattr(self, 'instance', None) |
|
13 | instance = getattr(self, 'instance', None) | |
14 |
|
14 | |||
15 | if instance and instance.pk: |
|
15 | if instance and instance.pk: | |
16 |
|
16 | |||
17 | devices = Device.objects.filter(device_type__name='dds') |
|
17 | devices = Device.objects.filter(device_type__name='dds') | |
18 |
|
18 | |||
19 | self.fields['experiment'].widget.attrs['readonly'] = True |
|
19 | if instance.experiment: | |
20 |
|
20 | self.fields['experiment'].widget.attrs['disabled'] = 'disabled' | ||
21 | if instance.experiment is not None: |
|
|||
22 | self.fields['experiment'].widget.choices = [(instance.experiment.id, instance.experiment)] |
|
|||
23 |
|
21 | |||
24 | self.fields['device'].widget.choices = [(device.id, device) for device in devices] |
|
22 | self.fields['device'].widget.choices = [(device.id, device) for device in devices] | |
25 |
|
23 | |||
26 |
|
24 | |||
27 | class Meta: |
|
25 | class Meta: | |
28 | model = DDSConfiguration |
|
26 | model = DDSConfiguration | |
29 | exclude = ('type', 'parameters', 'status') No newline at end of file |
|
27 | exclude = ('type', 'parameters', 'status') |
@@ -1,234 +1,231 | |||||
1 | # Create your views here. |
|
1 | # Create your views here. | |
2 | from django.shortcuts import redirect, render, get_object_or_404 |
|
2 | from django.shortcuts import redirect, render, get_object_or_404 | |
3 |
|
3 | |||
4 | # from apps.main.models import Experiment, Configuration |
|
4 | # from apps.main.models import Experiment, Configuration | |
5 | from apps.main.views import sidebar |
|
5 | from apps.main.views import sidebar | |
6 |
|
6 | |||
7 | from .models import DDSConfiguration |
|
7 | from .models import DDSConfiguration | |
8 | from .forms import DDSConfigurationForm |
|
8 | from .forms import DDSConfigurationForm | |
9 | # Create your views here. |
|
9 | # Create your views here. | |
10 |
|
10 | |||
11 | def dds_conf(request, id_conf): |
|
11 | def dds_conf(request, id_conf): | |
12 |
|
12 | |||
13 | conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
13 | conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
14 |
|
14 | |||
15 | kwargs = {} |
|
15 | kwargs = {} | |
16 |
|
16 | |||
17 | kwargs['status'] = conf.device.get_status_display() |
|
17 | kwargs['status'] = conf.device.get_status_display() | |
18 |
|
18 | |||
19 | # if not kwargs['connected']: |
|
19 | # if not kwargs['connected']: | |
20 | # messages.error(request, message=answer) |
|
20 | # messages.error(request, message=answer) | |
21 |
|
21 | |||
22 | kwargs['dev_conf'] = conf |
|
22 | kwargs['dev_conf'] = conf | |
23 | kwargs['dev_conf_keys'] = ['name', |
|
23 | kwargs['dev_conf_keys'] = ['name', | |
24 | 'experiment', |
|
24 | 'experiment', | |
25 | 'device', |
|
25 | 'device', | |
26 | 'clock', |
|
26 | 'clock', | |
27 | 'multiplier', |
|
27 | 'multiplier', | |
28 | 'frequencyA_Mhz', |
|
28 | 'frequencyA_Mhz', | |
29 | 'frequencyA', |
|
29 | 'frequencyA', | |
30 | 'frequencyB_Mhz', |
|
30 | 'frequencyB_Mhz', | |
31 | 'frequencyB', |
|
31 | 'frequencyB', | |
32 | 'phaseA_degrees', |
|
32 | 'phaseA_degrees', | |
33 | 'phaseB_degrees', |
|
33 | 'phaseB_degrees', | |
34 | 'modulation', |
|
34 | 'modulation', | |
35 | 'amplitude_enabled', |
|
35 | 'amplitude_enabled', | |
36 | 'amplitudeI', |
|
36 | 'amplitudeI', | |
37 | 'amplitudeQ'] |
|
37 | 'amplitudeQ'] | |
38 |
|
38 | |||
39 | kwargs['title'] = 'DDS Configuration' |
|
39 | kwargs['title'] = 'DDS Configuration' | |
40 | kwargs['suptitle'] = 'Details' |
|
40 | kwargs['suptitle'] = 'Details' | |
41 |
|
41 | |||
42 | kwargs['button'] = 'Edit Configuration' |
|
42 | kwargs['button'] = 'Edit Configuration' | |
43 |
|
43 | |||
44 | ###### SIDEBAR ###### |
|
44 | ###### SIDEBAR ###### | |
45 | kwargs.update(sidebar(conf)) |
|
45 | kwargs.update(sidebar(conf=conf)) | |
46 |
|
46 | |||
47 | return render(request, 'dds_conf.html', kwargs) |
|
47 | return render(request, 'dds_conf.html', kwargs) | |
48 |
|
48 | |||
49 | def dds_conf_edit(request, id_conf): |
|
49 | def dds_conf_edit(request, id_conf): | |
50 |
|
50 | |||
51 | conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
51 | conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
52 |
|
52 | |||
53 | if request.method=='GET': |
|
53 | if request.method=='GET': | |
54 | form = DDSConfigurationForm(instance=conf) |
|
54 | form = DDSConfigurationForm(instance=conf) | |
55 |
|
55 | |||
56 | if request.method=='POST': |
|
56 | if request.method=='POST': | |
57 | form = DDSConfigurationForm(request.POST, instance=conf) |
|
57 | form = DDSConfigurationForm(request.POST, instance=conf) | |
58 |
|
58 | |||
59 | if form.is_valid(): |
|
59 | if form.is_valid(): | |
60 | conf = form.save(commit=False) |
|
60 | conf = form.save(commit=False) | |
61 |
|
61 | |||
62 | if conf.verify_frequencies(): |
|
62 | if conf.verify_frequencies(): | |
63 |
|
63 | |||
64 | conf.save() |
|
64 | conf.save() | |
65 | return redirect('url_dds_conf', id_conf=conf.id) |
|
65 | return redirect('url_dds_conf', id_conf=conf.id) | |
66 |
|
66 | |||
67 | ##ERRORS |
|
67 | ##ERRORS | |
68 |
|
68 | |||
69 | kwargs = {} |
|
69 | kwargs = {} | |
70 | kwargs['id_dev'] = conf.id |
|
70 | kwargs['id_dev'] = conf.id | |
71 | kwargs['form'] = form |
|
71 | kwargs['form'] = form | |
72 | kwargs['title'] = 'Device Configuration' |
|
72 | kwargs['title'] = 'Device Configuration' | |
73 | kwargs['suptitle'] = 'Edit' |
|
73 | kwargs['suptitle'] = 'Edit' | |
74 | kwargs['button'] = 'Save' |
|
74 | kwargs['button'] = 'Save' | |
75 |
|
75 | |||
76 | ###### SIDEBAR ###### |
|
|||
77 | kwargs.update(sidebar(conf)) |
|
|||
78 |
|
||||
79 | return render(request, 'dds_conf_edit.html', kwargs) |
|
76 | return render(request, 'dds_conf_edit.html', kwargs) | |
80 |
|
77 | |||
81 | # def dds_conf_import(request, id_conf): |
|
78 | # def dds_conf_import(request, id_conf): | |
82 | # |
|
79 | # | |
83 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
80 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
84 | # |
|
81 | # | |
85 | # if request.method == 'GET': |
|
82 | # if request.method == 'GET': | |
86 | # file_form = UploadFileForm() |
|
83 | # file_form = UploadFileForm() | |
87 | # |
|
84 | # | |
88 | # if request.method == 'POST': |
|
85 | # if request.method == 'POST': | |
89 | # file_form = UploadFileForm(request.POST, request.FILES) |
|
86 | # file_form = UploadFileForm(request.POST, request.FILES) | |
90 | # |
|
87 | # | |
91 | # if file_form.is_valid(): |
|
88 | # if file_form.is_valid(): | |
92 | # |
|
89 | # | |
93 | # parms = files.read_dds_file(request.FILES['file']) |
|
90 | # parms = files.read_dds_file(request.FILES['file']) | |
94 | # |
|
91 | # | |
95 | # if parms: |
|
92 | # if parms: | |
96 | # |
|
93 | # | |
97 | # if not parms['clock']: |
|
94 | # if not parms['clock']: | |
98 | # messages.warning(request, "Clock Input could not be imported from '%s'. Please fill it out." %request.FILES['file'].name) |
|
95 | # messages.warning(request, "Clock Input could not be imported from '%s'. Please fill it out." %request.FILES['file'].name) | |
99 | # else: |
|
96 | # else: | |
100 | # messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) |
|
97 | # messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) | |
101 | # |
|
98 | # | |
102 | # form = DDSConfigurationForm(initial=parms, instance=conf) |
|
99 | # form = DDSConfigurationForm(initial=parms, instance=conf) | |
103 | # |
|
100 | # | |
104 | # kwargs = {} |
|
101 | # kwargs = {} | |
105 | # kwargs['id_dev'] = conf.id |
|
102 | # kwargs['id_dev'] = conf.id | |
106 | # kwargs['form'] = form |
|
103 | # kwargs['form'] = form | |
107 | # kwargs['title'] = 'Device Configuration' |
|
104 | # kwargs['title'] = 'Device Configuration' | |
108 | # kwargs['suptitle'] = 'Parameters imported' |
|
105 | # kwargs['suptitle'] = 'Parameters imported' | |
109 | # kwargs['button'] = 'Save' |
|
106 | # kwargs['button'] = 'Save' | |
110 | # kwargs['action'] = conf.get_absolute_url_edit() |
|
107 | # kwargs['action'] = conf.get_absolute_url_edit() | |
111 | # kwargs['previous'] = conf.get_absolute_url() |
|
108 | # kwargs['previous'] = conf.get_absolute_url() | |
112 | # |
|
109 | # | |
113 | # ###### SIDEBAR ###### |
|
110 | # ###### SIDEBAR ###### | |
114 | # kwargs.update(sidebar(conf)) |
|
111 | # kwargs.update(sidebar(conf)) | |
115 | # |
|
112 | # | |
116 | # return render(request, 'dds_conf_edit.html', kwargs) |
|
113 | # return render(request, 'dds_conf_edit.html', kwargs) | |
117 | # |
|
114 | # | |
118 | # messages.error(request, "Could not import parameters from file") |
|
115 | # messages.error(request, "Could not import parameters from file") | |
119 | # |
|
116 | # | |
120 | # kwargs = {} |
|
117 | # kwargs = {} | |
121 | # kwargs['id_dev'] = conf.id |
|
118 | # kwargs['id_dev'] = conf.id | |
122 | # kwargs['title'] = 'Device Configuration' |
|
119 | # kwargs['title'] = 'Device Configuration' | |
123 | # kwargs['form'] = file_form |
|
120 | # kwargs['form'] = file_form | |
124 | # kwargs['suptitle'] = 'Importing file' |
|
121 | # kwargs['suptitle'] = 'Importing file' | |
125 | # kwargs['button'] = 'Import' |
|
122 | # kwargs['button'] = 'Import' | |
126 | # |
|
123 | # | |
127 | # kwargs.update(sidebar(conf)) |
|
124 | # kwargs.update(sidebar(conf)) | |
128 | # |
|
125 | # | |
129 | # return render(request, 'dds_conf_import.html', kwargs) |
|
126 | # return render(request, 'dds_conf_import.html', kwargs) | |
130 | # |
|
127 | # | |
131 | # def dds_conf_export(request, id_conf): |
|
128 | # def dds_conf_export(request, id_conf): | |
132 | # |
|
129 | # | |
133 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
130 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
134 | # |
|
131 | # | |
135 | # response = HttpResponse(content_type='text/plain') |
|
132 | # response = HttpResponse(content_type='text/plain') | |
136 | # response['Content-Disposition'] = 'attachment; filename="%s.dds"' %conf.name |
|
133 | # response['Content-Disposition'] = 'attachment; filename="%s.dds"' %conf.name | |
137 | # response.write(conf.export_parms_to_dict()) |
|
134 | # response.write(conf.export_parms_to_dict()) | |
138 | # |
|
135 | # | |
139 | # return response |
|
136 | # return response | |
140 | # |
|
137 | # | |
141 | # def dds_conf_start(request, id_conf): |
|
138 | # def dds_conf_start(request, id_conf): | |
142 | # |
|
139 | # | |
143 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
140 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
144 | # |
|
141 | # | |
145 | # if conf.start_device(): |
|
142 | # if conf.start_device(): | |
146 | # messages.success(request, conf.message) |
|
143 | # messages.success(request, conf.message) | |
147 | # else: |
|
144 | # else: | |
148 | # messages.error(request, conf.message) |
|
145 | # messages.error(request, conf.message) | |
149 | # |
|
146 | # | |
150 | # return redirect('url_dds_conf', id_conf=conf.id) |
|
147 | # return redirect('url_dds_conf', id_conf=conf.id) | |
151 | # |
|
148 | # | |
152 | # def dds_conf_stop(request, id_conf): |
|
149 | # def dds_conf_stop(request, id_conf): | |
153 | # |
|
150 | # | |
154 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
151 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
155 | # |
|
152 | # | |
156 | # if conf.stop_device(): |
|
153 | # if conf.stop_device(): | |
157 | # messages.success(request, conf.message) |
|
154 | # messages.success(request, conf.message) | |
158 | # else: |
|
155 | # else: | |
159 | # messages.error(request, conf.message) |
|
156 | # messages.error(request, conf.message) | |
160 | # |
|
157 | # | |
161 | # return redirect('url_dds_conf', id_conf=conf.id) |
|
158 | # return redirect('url_dds_conf', id_conf=conf.id) | |
162 | # |
|
159 | # | |
163 | # def dds_conf_status(request, id_conf): |
|
160 | # def dds_conf_status(request, id_conf): | |
164 | # |
|
161 | # | |
165 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
162 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
166 | # |
|
163 | # | |
167 | # if conf.status_device(): |
|
164 | # if conf.status_device(): | |
168 | # messages.success(request, conf.message) |
|
165 | # messages.success(request, conf.message) | |
169 | # else: |
|
166 | # else: | |
170 | # messages.error(request, conf.message) |
|
167 | # messages.error(request, conf.message) | |
171 | # |
|
168 | # | |
172 | # return redirect('url_dds_conf', id_conf=conf.id) |
|
169 | # return redirect('url_dds_conf', id_conf=conf.id) | |
173 | # |
|
170 | # | |
174 | # |
|
171 | # | |
175 | # def dds_conf_write(request, id_conf): |
|
172 | # def dds_conf_write(request, id_conf): | |
176 | # |
|
173 | # | |
177 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
174 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
178 | # |
|
175 | # | |
179 | # answer = conf.write_device() |
|
176 | # answer = conf.write_device() | |
180 | # |
|
177 | # | |
181 | # if answer: |
|
178 | # if answer: | |
182 | # messages.success(request, conf.message) |
|
179 | # messages.success(request, conf.message) | |
183 | # |
|
180 | # | |
184 | # conf.pk = None |
|
181 | # conf.pk = None | |
185 | # conf.id = None |
|
182 | # conf.id = None | |
186 | # conf.type = 1 |
|
183 | # conf.type = 1 | |
187 | # conf.template = 0 |
|
184 | # conf.template = 0 | |
188 | # conf.save() |
|
185 | # conf.save() | |
189 | # |
|
186 | # | |
190 | # else: |
|
187 | # else: | |
191 | # messages.error(request, conf.message) |
|
188 | # messages.error(request, conf.message) | |
192 | # |
|
189 | # | |
193 | # return redirect('url_dds_conf', id_conf=id_conf) |
|
190 | # return redirect('url_dds_conf', id_conf=id_conf) | |
194 | # |
|
191 | # | |
195 | # def dds_conf_read(request, id_conf): |
|
192 | # def dds_conf_read(request, id_conf): | |
196 | # |
|
193 | # | |
197 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
194 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
198 | # |
|
195 | # | |
199 | # if request.method=='GET': |
|
196 | # if request.method=='GET': | |
200 | # |
|
197 | # | |
201 | # parms = conf.read_device() |
|
198 | # parms = conf.read_device() | |
202 | # |
|
199 | # | |
203 | # if not parms: |
|
200 | # if not parms: | |
204 | # messages.error(request, conf.message) |
|
201 | # messages.error(request, conf.message) | |
205 | # return redirect('url_dds_conf', id_conf=conf.id) |
|
202 | # return redirect('url_dds_conf', id_conf=conf.id) | |
206 | # |
|
203 | # | |
207 | # messages.warning(request, "Clock Input cannot be read from device. Please fill it out.") |
|
204 | # messages.warning(request, "Clock Input cannot be read from device. Please fill it out.") | |
208 | # |
|
205 | # | |
209 | # form = DDSConfigurationForm(initial=parms, instance=conf) |
|
206 | # form = DDSConfigurationForm(initial=parms, instance=conf) | |
210 | # |
|
207 | # | |
211 | # if request.method=='POST': |
|
208 | # if request.method=='POST': | |
212 | # form = DDSConfigurationForm(request.POST, instance=conf) |
|
209 | # form = DDSConfigurationForm(request.POST, instance=conf) | |
213 | # |
|
210 | # | |
214 | # if form.is_valid(): |
|
211 | # if form.is_valid(): | |
215 | # dds_model = form.save(commit=False) |
|
212 | # dds_model = form.save(commit=False) | |
216 | # |
|
213 | # | |
217 | # if dds_model.verify_frequencies(): |
|
214 | # if dds_model.verify_frequencies(): | |
218 | # |
|
215 | # | |
219 | # dds_model.save() |
|
216 | # dds_model.save() | |
220 | # return redirect('url_dds_conf', id_conf=conf.id) |
|
217 | # return redirect('url_dds_conf', id_conf=conf.id) | |
221 | # |
|
218 | # | |
222 | # messages.error(request, "DDS parameters could not be saved") |
|
219 | # messages.error(request, "DDS parameters could not be saved") | |
223 | # |
|
220 | # | |
224 | # kwargs = {} |
|
221 | # kwargs = {} | |
225 | # kwargs['id_dev'] = conf.id |
|
222 | # kwargs['id_dev'] = conf.id | |
226 | # kwargs['form'] = form |
|
223 | # kwargs['form'] = form | |
227 | # kwargs['title'] = 'Device Configuration' |
|
224 | # kwargs['title'] = 'Device Configuration' | |
228 | # kwargs['suptitle'] = 'Parameters read from device' |
|
225 | # kwargs['suptitle'] = 'Parameters read from device' | |
229 | # kwargs['button'] = 'Save' |
|
226 | # kwargs['button'] = 'Save' | |
230 | # |
|
227 | # | |
231 | # ###### SIDEBAR ###### |
|
228 | # ###### SIDEBAR ###### | |
232 | # kwargs.update(sidebar(conf)) |
|
229 | # kwargs.update(sidebar(conf)) | |
233 | # |
|
230 | # | |
234 | # return render(request, 'dds_conf_edit.html', kwargs) No newline at end of file |
|
231 | # return render(request, 'dds_conf_edit.html', kwargs) |
@@ -1,9 +1,10 | |||||
1 | [ |
|
1 | [ | |
2 |
{"fields": {"name": " |
|
2 | {"fields": {"name": "MAIN RADAR", "description": ""}, "model": "main.location", "pk": 1}, | |
3 |
{"fields": {"name": "JASMET", "description": ""}, "model": "main.location", "pk": 2}, |
|
3 | {"fields": {"name": "JASMET", "description": ""}, "model": "main.location", "pk": 2}, | |
4 |
{"fields": {"name": "SOUSY", "description": ""}, "model": "main.location", "pk": 3}, |
|
4 | {"fields": {"name": "SOUSY", "description": ""}, "model": "main.location", "pk": 3}, | |
|
5 | {"fields": {"name": "JULIA", "description": ""}, "model": "main.location", "pk": 4}, | |||
5 | {"fields": {"name": "rc", "description": ""}, "model": "main.devicetype", "pk": 1}, |
|
6 | {"fields": {"name": "rc", "description": ""}, "model": "main.devicetype", "pk": 1}, | |
6 | {"fields": {"name": "dds", "description": ""}, "model": "main.devicetype", "pk": 2}, |
|
7 | {"fields": {"name": "dds", "description": ""}, "model": "main.devicetype", "pk": 2}, | |
7 | {"fields": {"name": "cgs", "description": ""}, "model": "main.devicetype", "pk": 3}, |
|
8 | {"fields": {"name": "cgs", "description": ""}, "model": "main.devicetype", "pk": 3}, | |
8 | {"fields": {"name": "jars", "description": ""}, "model": "main.devicetype", "pk": 4} |
|
9 | {"fields": {"name": "jars", "description": ""}, "model": "main.devicetype", "pk": 4} | |
9 | ] |
|
10 | ] |
@@ -1,127 +1,151 | |||||
1 | from django import forms |
|
1 | from django import forms | |
2 | from django.utils.safestring import mark_safe |
|
2 | from django.utils.safestring import mark_safe | |
3 |
|
3 | |||
4 | from .models import DeviceType, Device, Experiment, Campaign, Configuration, Location |
|
4 | from .models import DeviceType, Device, Experiment, Campaign, Configuration, Location | |
5 |
|
5 | |||
6 | FILE_FORMAT = ( |
|
6 | FILE_FORMAT = ( | |
7 | ('json', 'json'), |
|
7 | ('json', 'json'), | |
8 | ) |
|
8 | ) | |
9 |
|
9 | |||
10 | DDS_FILE_FORMAT = ( |
|
10 | DDS_FILE_FORMAT = ( | |
11 | ('json', 'json'), |
|
11 | ('json', 'json'), | |
12 | ('text', 'dds') |
|
12 | ('text', 'dds') | |
13 | ) |
|
13 | ) | |
14 |
|
14 | |||
15 | RC_FILE_FORMAT = ( |
|
15 | RC_FILE_FORMAT = ( | |
16 | ('json', 'json'), |
|
16 | ('json', 'json'), | |
17 | ('text', 'racp'), |
|
17 | ('text', 'racp'), | |
18 | ('binary', 'dat'), |
|
18 | ('binary', 'dat'), | |
19 | ) |
|
19 | ) | |
20 |
|
20 | |||
21 | def add_empty_choice(choices, pos=0, label='-----'): |
|
21 | def add_empty_choice(choices, pos=0, label='-----'): | |
22 | if len(choices)>0: |
|
22 | if len(choices)>0: | |
23 | choices = list(choices) |
|
23 | choices = list(choices) | |
24 | choices.insert(0, (0, label)) |
|
24 | choices.insert(0, (0, label)) | |
25 | return choices |
|
25 | return choices | |
26 | else: |
|
26 | else: | |
27 | return [(0, label)] |
|
27 | return [(0, label)] | |
28 |
|
28 | |||
29 | class DatepickerWidget(forms.widgets.TextInput): |
|
29 | class DatepickerWidget(forms.widgets.TextInput): | |
30 | def render(self, name, value, attrs=None): |
|
30 | def render(self, name, value, attrs=None): | |
31 | input_html = super(DatepickerWidget, self).render(name, value, attrs) |
|
31 | input_html = super(DatepickerWidget, self).render(name, value, attrs) | |
32 | html = '<div class="input-group date">'+input_html+'<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span></div>' |
|
32 | html = '<div class="input-group date">'+input_html+'<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span></div>' | |
33 | return mark_safe(html) |
|
33 | return mark_safe(html) | |
34 |
|
34 | |||
35 | class TimepickerWidget(forms.widgets.TextInput): |
|
35 | class TimepickerWidget(forms.widgets.TextInput): | |
36 | def render(self, name, value, attrs=None): |
|
36 | def render(self, name, value, attrs=None): | |
37 | input_html = super(TimepickerWidget, self).render(name, value, attrs) |
|
37 | input_html = super(TimepickerWidget, self).render(name, value, attrs) | |
38 | html = '<div class="input-group time">'+input_html+'<span class="input-group-addon"><i class="glyphicon glyphicon-time"></i></span></div>' |
|
38 | html = '<div class="input-group time">'+input_html+'<span class="input-group-addon"><i class="glyphicon glyphicon-time"></i></span></div>' | |
39 | return mark_safe(html) |
|
39 | return mark_safe(html) | |
40 |
|
40 | |||
41 | class CampaignForm(forms.ModelForm): |
|
41 | class CampaignForm(forms.ModelForm): | |
|
42 | ||||
|
43 | experiments = forms.ModelMultipleChoiceField(widget=forms.CheckboxSelectMultiple(), | |||
|
44 | queryset=Experiment.objects.filter(template=True), | |||
|
45 | required=False) | |||
|
46 | ||||
42 | def __init__(self, *args, **kwargs): |
|
47 | def __init__(self, *args, **kwargs): | |
43 | super(CampaignForm, self).__init__(*args, **kwargs) |
|
48 | super(CampaignForm, self).__init__(*args, **kwargs) | |
44 | self.fields['start_date'].widget = DatepickerWidget(self.fields['start_date'].widget.attrs) |
|
49 | self.fields['start_date'].widget = DatepickerWidget(self.fields['start_date'].widget.attrs) | |
45 | self.fields['end_date'].widget = DatepickerWidget(self.fields['end_date'].widget.attrs) |
|
50 | self.fields['end_date'].widget = DatepickerWidget(self.fields['end_date'].widget.attrs) | |
|
51 | self.fields['description'].widget.attrs = {'rows': 2} | |||
46 |
|
52 | |||
47 | class Meta: |
|
53 | class Meta: | |
48 | model = Campaign |
|
54 | model = Campaign | |
49 | exclude = [''] |
|
55 | exclude = [''] | |
50 |
|
56 | |||
51 | class ExperimentForm(forms.ModelForm): |
|
57 | class ExperimentForm(forms.ModelForm): | |
52 |
|
58 | |||
53 | def __init__(self, *args, **kwargs): |
|
59 | def __init__(self, *args, **kwargs): | |
54 | super(ExperimentForm, self).__init__(*args, **kwargs) |
|
60 | super(ExperimentForm, self).__init__(*args, **kwargs) | |
55 | self.fields['start_time'].widget = TimepickerWidget(self.fields['start_time'].widget.attrs) |
|
61 | self.fields['start_time'].widget = TimepickerWidget(self.fields['start_time'].widget.attrs) | |
56 | self.fields['end_time'].widget = TimepickerWidget(self.fields['end_time'].widget.attrs) |
|
62 | self.fields['end_time'].widget = TimepickerWidget(self.fields['end_time'].widget.attrs) | |
57 |
|
||||
58 | self.fields['campaign'].widget.attrs['readonly'] = True |
|
|||
59 |
|
63 | |||
60 | class Meta: |
|
64 | class Meta: | |
61 | model = Experiment |
|
65 | model = Experiment | |
62 | exclude = [''] |
|
66 | exclude = [''] | |
63 |
|
67 | |||
64 | class LocationForm(forms.ModelForm): |
|
68 | class LocationForm(forms.ModelForm): | |
65 | class Meta: |
|
69 | class Meta: | |
66 | model = Location |
|
70 | model = Location | |
67 | exclude = [''] |
|
71 | exclude = [''] | |
68 |
|
72 | |||
69 | class DeviceForm(forms.ModelForm): |
|
73 | class DeviceForm(forms.ModelForm): | |
70 | class Meta: |
|
74 | class Meta: | |
71 | model = Device |
|
75 | model = Device | |
72 | exclude = ['status'] |
|
76 | exclude = ['status'] | |
73 |
|
77 | |||
74 | class ConfigurationForm(forms.ModelForm): |
|
78 | class ConfigurationForm(forms.ModelForm): | |
|
79 | ||||
|
80 | def __init__(self, *args, **kwargs): | |||
|
81 | super(ConfigurationForm, self).__init__(*args, **kwargs) | |||
|
82 | ||||
|
83 | if 'initial' in kwargs and 'experiment' in kwargs['initial'] and kwargs['initial']['experiment'] not in (0, '0'): | |||
|
84 | self.fields['experiment'].widget.attrs['disabled'] = 'disabled' | |||
|
85 | ||||
75 | class Meta: |
|
86 | class Meta: | |
76 | model = Configuration |
|
87 | model = Configuration | |
77 | exclude = ['type', 'created_date', 'programmed_date', 'parameters'] |
|
88 | exclude = ['type', 'created_date', 'programmed_date', 'parameters'] | |
78 |
|
89 | |||
79 | class DeviceTypeForm(forms.Form): |
|
90 | class DeviceTypeForm(forms.Form): | |
80 | device_type = forms.ChoiceField(choices=add_empty_choice(DeviceType.objects.all().order_by('name').values_list('id', 'name'))) |
|
91 | device_type = forms.ChoiceField(choices=add_empty_choice(DeviceType.objects.all().order_by('name').values_list('id', 'name'))) | |
81 |
|
92 | |||
82 |
|
93 | |||
83 | class UploadFileForm(forms.Form): |
|
94 | class UploadFileForm(forms.Form): | |
84 |
|
95 | |||
85 | file = forms.FileField() |
|
96 | file = forms.FileField() | |
86 |
|
97 | |||
87 | class DownloadFileForm(forms.Form): |
|
98 | class DownloadFileForm(forms.Form): | |
88 |
|
99 | |||
89 | format = forms.ChoiceField(choices= ((0, 'json'),) ) |
|
100 | format = forms.ChoiceField(choices= ((0, 'json'),) ) | |
90 |
|
101 | |||
91 | def __init__(self, device_type, *args, **kwargs): |
|
102 | def __init__(self, device_type, *args, **kwargs): | |
92 |
|
103 | |||
93 | super(DownloadFileForm, self).__init__(*args, **kwargs) |
|
104 | super(DownloadFileForm, self).__init__(*args, **kwargs) | |
94 |
|
105 | |||
95 | self.fields['format'].choices = FILE_FORMAT |
|
106 | self.fields['format'].choices = FILE_FORMAT | |
96 |
|
107 | |||
97 | if device_type == 'dds': |
|
108 | if device_type == 'dds': | |
98 | self.fields['format'].choices = DDS_FILE_FORMAT |
|
109 | self.fields['format'].choices = DDS_FILE_FORMAT | |
99 |
|
110 | |||
100 | if device_type == 'rc': |
|
111 | if device_type == 'rc': | |
101 | self.fields['format'].choices = RC_FILE_FORMAT |
|
112 | self.fields['format'].choices = RC_FILE_FORMAT | |
102 |
|
113 | |||
103 | class OperationForm(forms.Form): |
|
114 | class OperationForm(forms.Form): | |
104 | # today = datetime.today() |
|
115 | # today = datetime.today() | |
105 | # -----Campaigns from this month------[:5] |
|
116 | # -----Campaigns from this month------[:5] | |
106 | campaign = forms.ChoiceField(label="Campaign") |
|
117 | campaign = forms.ChoiceField(label="Campaign") | |
107 |
|
118 | |||
108 | def __init__(self, *args, **kwargs): |
|
119 | def __init__(self, *args, **kwargs): | |
109 |
|
120 | |||
110 | if 'length' not in kwargs.keys(): |
|
121 | if 'length' not in kwargs.keys(): | |
111 | length = None |
|
122 | length = None | |
112 | else: |
|
123 | else: | |
113 | length = kwargs['length'] |
|
124 | length = kwargs['length'] | |
114 |
|
125 | |||
115 | kwargs.pop('length') |
|
126 | kwargs.pop('length') | |
116 |
|
127 | |||
117 | super(OperationForm, self).__init__(*args, **kwargs) |
|
128 | super(OperationForm, self).__init__(*args, **kwargs) | |
118 | self.fields['campaign'].choices=Campaign.objects.all().order_by('-start_date').values_list('id', 'name')[:length] |
|
129 | self.fields['campaign'].choices=Campaign.objects.all().order_by('-start_date').values_list('id', 'name')[:length] | |
119 |
|
130 | |||
120 | class OperationSearchForm(forms.Form): |
|
131 | class OperationSearchForm(forms.Form): | |
121 | # -----ALL Campaigns------ |
|
132 | # -----ALL Campaigns------ | |
122 | campaign = forms.ChoiceField(label="Campaign") |
|
133 | campaign = forms.ChoiceField(label="Campaign") | |
123 |
|
134 | |||
124 | def __init__(self, *args, **kwargs): |
|
135 | def __init__(self, *args, **kwargs): | |
125 | super(OperationSearchForm, self).__init__(*args, **kwargs) |
|
136 | super(OperationSearchForm, self).__init__(*args, **kwargs) | |
126 | self.fields['campaign'].choices=Campaign.objects.all().order_by('-start_date').values_list('id', 'name') |
|
137 | self.fields['campaign'].choices=Campaign.objects.all().order_by('-start_date').values_list('id', 'name') | |
|
138 | ||||
|
139 | class NewForm(forms.Form): | |||
|
140 | ||||
|
141 | create_from = forms.ChoiceField(choices=((0, '-----'), | |||
|
142 | (1, 'Empty (blank)'), | |||
|
143 | (2, 'Template'))) | |||
|
144 | choose_template = forms.ChoiceField() | |||
|
145 | ||||
|
146 | def __init__(self, *args, **kwargs): | |||
|
147 | ||||
|
148 | template_choices = kwargs.pop('template_choices', []) | |||
|
149 | super(NewForm, self).__init__(*args, **kwargs) | |||
|
150 | self.fields['choose_template'].choices = add_empty_choice(template_choices) | |||
127 | No newline at end of file |
|
151 |
@@ -1,358 +1,371 | |||||
|
1 | ||||
|
2 | from datetime import datetime | |||
|
3 | ||||
1 | from django.db import models |
|
4 | from django.db import models | |
2 | from polymorphic import PolymorphicModel |
|
5 | from polymorphic import PolymorphicModel | |
3 |
|
6 | |||
4 | from django.core.urlresolvers import reverse |
|
7 | from django.core.urlresolvers import reverse | |
5 |
|
8 | |||
6 | CONF_STATES = ( |
|
9 | CONF_STATES = ( | |
7 | (0, 'Disconnected'), |
|
10 | (0, 'Disconnected'), | |
8 | (1, 'Connected'), |
|
11 | (1, 'Connected'), | |
9 | (2, 'Running'), |
|
12 | (2, 'Running'), | |
10 | ) |
|
13 | ) | |
11 |
|
14 | |||
12 | EXP_STATES = ( |
|
15 | EXP_STATES = ( | |
13 | (0,'Error'), #RED |
|
16 | (0,'Error'), #RED | |
14 | (1,'Configurated'), #BLUE |
|
17 | (1,'Configurated'), #BLUE | |
15 | (2,'Running'), #GREEN |
|
18 | (2,'Running'), #GREEN | |
16 | (3,'Waiting'), #YELLOW |
|
19 | (3,'Waiting'), #YELLOW | |
17 | (4,'Not Configured'), #WHITE |
|
20 | (4,'Not Configured'), #WHITE | |
18 | ) |
|
21 | ) | |
19 |
|
22 | |||
20 | CONF_TYPES = ( |
|
23 | CONF_TYPES = ( | |
21 | (0, 'Active'), |
|
24 | (0, 'Active'), | |
22 | (1, 'Historical'), |
|
25 | (1, 'Historical'), | |
23 | ) |
|
26 | ) | |
24 |
|
27 | |||
25 | DEV_STATES = ( |
|
28 | DEV_STATES = ( | |
26 | (0, 'No connected'), |
|
29 | (0, 'No connected'), | |
27 | (1, 'Connected'), |
|
30 | (1, 'Connected'), | |
28 | (2, 'Configured'), |
|
31 | (2, 'Configured'), | |
29 | (3, 'Running'), |
|
32 | (3, 'Running'), | |
30 | ) |
|
33 | ) | |
31 |
|
34 | |||
32 | DEV_TYPES = ( |
|
35 | DEV_TYPES = ( | |
33 | ('', 'Select a device type'), |
|
36 | ('', 'Select a device type'), | |
34 | ('rc', 'Radar Controller'), |
|
37 | ('rc', 'Radar Controller'), | |
35 | ('dds', 'Direct Digital Synthesizer'), |
|
38 | ('dds', 'Direct Digital Synthesizer'), | |
36 | ('jars', 'Jicamarca Radar Acquisition System'), |
|
39 | ('jars', 'Jicamarca Radar Acquisition System'), | |
37 | ('usrp', 'Universal Software Radio Peripheral'), |
|
40 | ('usrp', 'Universal Software Radio Peripheral'), | |
38 | ('cgs', 'Clock Generator System'), |
|
41 | ('cgs', 'Clock Generator System'), | |
39 | ('abs', 'Automatic Beam Switching'), |
|
42 | ('abs', 'Automatic Beam Switching'), | |
40 | ) |
|
43 | ) | |
41 |
|
44 | |||
42 | DEV_PORTS = { |
|
45 | DEV_PORTS = { | |
43 | 'rc' : 2000, |
|
46 | 'rc' : 2000, | |
44 | 'dds' : 2000, |
|
47 | 'dds' : 2000, | |
45 | 'jars' : 2000, |
|
48 | 'jars' : 2000, | |
46 | 'usrp' : 2000, |
|
49 | 'usrp' : 2000, | |
47 | 'cgs' : 8080, |
|
50 | 'cgs' : 8080, | |
48 | 'abs' : 8080 |
|
51 | 'abs' : 8080 | |
49 | } |
|
52 | } | |
50 |
|
53 | |||
51 | RADAR_STATES = ( |
|
54 | RADAR_STATES = ( | |
52 | (0, 'No connected'), |
|
55 | (0, 'No connected'), | |
53 | (1, 'Connected'), |
|
56 | (1, 'Connected'), | |
54 | (2, 'Configured'), |
|
57 | (2, 'Configured'), | |
55 | (3, 'Running'), |
|
58 | (3, 'Running'), | |
56 | (4, 'Scheduled'), |
|
59 | (4, 'Scheduled'), | |
57 | ) |
|
60 | ) | |
58 | # Create your models here. |
|
61 | # Create your models here. | |
59 |
|
62 | |||
60 | class Location(models.Model): |
|
63 | class Location(models.Model): | |
61 |
|
64 | |||
62 | name = models.CharField(max_length = 30) |
|
65 | name = models.CharField(max_length = 30) | |
63 | description = models.TextField(blank=True, null=True) |
|
66 | description = models.TextField(blank=True, null=True) | |
64 |
|
67 | |||
65 | class Meta: |
|
68 | class Meta: | |
66 | db_table = 'db_location' |
|
69 | db_table = 'db_location' | |
67 |
|
70 | |||
68 | def __unicode__(self): |
|
71 | def __unicode__(self): | |
69 | return u'%s' % self.name |
|
72 | return u'%s' % self.name | |
70 |
|
73 | |||
71 | class DeviceType(models.Model): |
|
74 | class DeviceType(models.Model): | |
72 |
|
75 | |||
73 | name = models.CharField(max_length = 10, choices = DEV_TYPES, default = 'rc') |
|
76 | name = models.CharField(max_length = 10, choices = DEV_TYPES, default = 'rc') | |
74 | description = models.TextField(blank=True, null=True) |
|
77 | description = models.TextField(blank=True, null=True) | |
75 |
|
78 | |||
76 | class Meta: |
|
79 | class Meta: | |
77 | db_table = 'db_device_types' |
|
80 | db_table = 'db_device_types' | |
78 |
|
81 | |||
79 | def __unicode__(self): |
|
82 | def __unicode__(self): | |
80 | return u'%s' % self.get_name_display() |
|
83 | return u'%s' % self.get_name_display() | |
81 |
|
84 | |||
82 | class Device(models.Model): |
|
85 | class Device(models.Model): | |
83 |
|
86 | |||
84 | device_type = models.ForeignKey(DeviceType, on_delete=models.CASCADE) |
|
87 | device_type = models.ForeignKey(DeviceType, on_delete=models.CASCADE) | |
85 | location = models.ForeignKey(Location, on_delete=models.CASCADE) |
|
88 | location = models.ForeignKey(Location, on_delete=models.CASCADE) | |
86 |
|
89 | |||
87 | name = models.CharField(max_length=40, default='') |
|
90 | name = models.CharField(max_length=40, default='') | |
88 | ip_address = models.GenericIPAddressField(protocol='IPv4', default='0.0.0.0') |
|
91 | ip_address = models.GenericIPAddressField(protocol='IPv4', default='0.0.0.0') | |
89 | port_address = models.PositiveSmallIntegerField(default=2000) |
|
92 | port_address = models.PositiveSmallIntegerField(default=2000) | |
90 | description = models.TextField(blank=True, null=True) |
|
93 | description = models.TextField(blank=True, null=True) | |
91 | status = models.PositiveSmallIntegerField(default=0, choices=DEV_STATES) |
|
94 | status = models.PositiveSmallIntegerField(default=0, choices=DEV_STATES) | |
92 |
|
95 | |||
93 | class Meta: |
|
96 | class Meta: | |
94 | db_table = 'db_devices' |
|
97 | db_table = 'db_devices' | |
95 |
|
98 | |||
96 | def __unicode__(self): |
|
99 | def __unicode__(self): | |
97 | return u'%s | %s' % (self.name, self.ip_address) |
|
100 | return u'%s | %s' % (self.name, self.ip_address) | |
98 |
|
101 | |||
99 | def get_status(self): |
|
102 | def get_status(self): | |
100 |
|
103 | |||
101 | return self.status |
|
104 | return self.status | |
102 |
|
105 | |||
103 |
|
106 | |||
104 | class Campaign(models.Model): |
|
107 | class Campaign(models.Model): | |
105 |
|
108 | |||
106 | template = models.BooleanField(default=False) |
|
109 | template = models.BooleanField(default=False) | |
107 |
|
110 | name = models.CharField(max_length=60, unique=True) | ||
108 | name = models.CharField(max_length=40, unique=True) |
|
|||
109 | experiment = models.ManyToManyField('Experiment') |
|
|||
110 |
|
||||
111 | start_date = models.DateTimeField(blank=True, null=True) |
|
111 | start_date = models.DateTimeField(blank=True, null=True) | |
112 | end_date = models.DateTimeField(blank=True, null=True) |
|
112 | end_date = models.DateTimeField(blank=True, null=True) | |
113 | tags = models.CharField(max_length=40) |
|
113 | tags = models.CharField(max_length=40) | |
114 | description = models.TextField(blank=True, null=True) |
|
114 | description = models.TextField(blank=True, null=True) | |
|
115 | experiments = models.ManyToManyField('Experiment', blank=True) | |||
115 |
|
116 | |||
116 | class Meta: |
|
117 | class Meta: | |
117 | db_table = 'db_campaigns' |
|
118 | db_table = 'db_campaigns' | |
|
119 | ordering = ('name',) | |||
118 |
|
120 | |||
119 | def __unicode__(self): |
|
121 | def __unicode__(self): | |
120 | return u'%s' % (self.name) |
|
122 | return u'%s' % (self.name) | |
121 |
|
||||
122 | # class Radar(models.Model): |
|
|||
123 | # |
|
|||
124 | # # name = models.CharField(max_length = 30) |
|
|||
125 | # experiment = models.ForeignKey('Experiment', on_delete=models.CASCADE) |
|
|||
126 | # location = models.OneToOneField('Location', on_delete=models.CASCADE) |
|
|||
127 | # status = models.PositiveSmallIntegerField(default=0, choices=RADAR_STATES) |
|
|||
128 | # |
|
|||
129 | # class Meta: |
|
|||
130 | # db_table = 'db_radar' |
|
|||
131 | # |
|
|||
132 | # def __unicode__(self): |
|
|||
133 | # return u'%s' % self.location |
|
|||
134 |
|
123 | |||
|
124 | ||||
135 | class RunningExperiment(models.Model): |
|
125 | class RunningExperiment(models.Model): | |
136 | radar = models.OneToOneField('Location', on_delete=models.CASCADE) |
|
126 | radar = models.OneToOneField('Location', on_delete=models.CASCADE) | |
137 | running_experiment = models.ManyToManyField('Experiment') |
|
127 | running_experiment = models.ManyToManyField('Experiment') | |
138 | status = models.PositiveSmallIntegerField(default=0, choices=RADAR_STATES) |
|
128 | status = models.PositiveSmallIntegerField(default=0, choices=RADAR_STATES) | |
139 |
|
129 | |||
140 |
|
130 | |||
141 | class Experiment(models.Model): |
|
131 | class Experiment(models.Model): | |
142 |
|
132 | |||
143 | template = models.BooleanField(default=False) |
|
133 | template = models.BooleanField(default=False) | |
144 |
|
134 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) | ||
145 | #campaign = models.ForeignKey('Campaign', null=True, blank=True, on_delete=models.CASCADE) |
|
135 | name = models.CharField(max_length=40, default='', unique=True) | |
146 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) |
|
136 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) | |
147 |
|
||||
148 | name = models.CharField(max_length=40, default='') |
|
|||
149 | start_time = models.TimeField(default='00:00:00') |
|
137 | start_time = models.TimeField(default='00:00:00') | |
150 | end_time = models.TimeField(default='23:59:59') |
|
138 | end_time = models.TimeField(default='23:59:59') | |
151 | status = models.PositiveSmallIntegerField(default=0, choices=EXP_STATES) |
|
139 | status = models.PositiveSmallIntegerField(default=0, choices=EXP_STATES) | |
152 |
|
140 | |||
153 | class Meta: |
|
141 | class Meta: | |
154 | db_table = 'db_experiments' |
|
142 | db_table = 'db_experiments' | |
|
143 | ordering = ('name',) | |||
155 |
|
144 | |||
156 | def __unicode__(self): |
|
145 | def __unicode__(self): | |
157 | return u'%s' % (self.name) |
|
146 | return u'%s' % (self.name) | |
158 |
|
147 | |||
|
148 | def clone(self, **kwargs): | |||
|
149 | ||||
|
150 | confs = Configuration.objects.filter(experiment=self, type=0) | |||
|
151 | self.pk = None | |||
|
152 | self.name = '{} [{:%Y/%m/%d}]'.format(self.name, datetime.now()) | |||
|
153 | for attr, value in kwargs.items(): | |||
|
154 | setattr(self, attr, value) | |||
|
155 | ||||
|
156 | self.save() | |||
|
157 | ||||
|
158 | for conf in confs: | |||
|
159 | conf.clone(experiment=self, template=False) | |||
|
160 | ||||
|
161 | return self | |||
159 |
|
162 | |||
160 | def get_status(self): |
|
163 | def get_status(self): | |
161 | configurations = Configuration.objects.filter(experiment=self) |
|
164 | configurations = Configuration.objects.filter(experiment=self) | |
162 | exp_status=[] |
|
165 | exp_status=[] | |
163 | for conf in configurations: |
|
166 | for conf in configurations: | |
164 | print conf.status_device() |
|
167 | print conf.status_device() | |
165 | exp_status.append(conf.status_device()) |
|
168 | exp_status.append(conf.status_device()) | |
166 |
|
169 | |||
167 | if not exp_status: #No Configuration |
|
170 | if not exp_status: #No Configuration | |
168 | self.status = 4 |
|
171 | self.status = 4 | |
169 | self.save() |
|
172 | self.save() | |
170 | return |
|
173 | return | |
171 |
|
174 | |||
172 | total = 1 |
|
175 | total = 1 | |
173 | for e_s in exp_status: |
|
176 | for e_s in exp_status: | |
174 | total = total*e_s |
|
177 | total = total*e_s | |
175 |
|
178 | |||
176 | if total == 0: #Error |
|
179 | if total == 0: #Error | |
177 | status = 0 |
|
180 | status = 0 | |
178 | elif total == (3**len(exp_status)): #Running |
|
181 | elif total == (3**len(exp_status)): #Running | |
179 | status = 2 |
|
182 | status = 2 | |
180 | else: |
|
183 | else: | |
181 | status = 1 #Configurated |
|
184 | status = 1 #Configurated | |
182 |
|
185 | |||
183 | self.status = status |
|
186 | self.status = status | |
184 | self.save() |
|
187 | self.save() | |
185 |
|
188 | |||
186 | def status_color(self): |
|
189 | def status_color(self): | |
187 | color = 'danger' |
|
190 | color = 'danger' | |
188 | if self.status == 0: |
|
191 | if self.status == 0: | |
189 | color = "danger" |
|
192 | color = "danger" | |
190 | elif self.status == 1: |
|
193 | elif self.status == 1: | |
191 | color = "info" |
|
194 | color = "info" | |
192 | elif self.status == 2: |
|
195 | elif self.status == 2: | |
193 | color = "succes" |
|
196 | color = "succes" | |
194 | elif self.status == 3: |
|
197 | elif self.status == 3: | |
195 | color = "warning" |
|
198 | color = "warning" | |
196 | else: |
|
199 | else: | |
197 | color = "muted" |
|
200 | color = "muted" | |
198 |
|
201 | |||
199 | return color |
|
202 | return color | |
200 |
|
203 | |||
|
204 | ||||
201 | class Configuration(PolymorphicModel): |
|
205 | class Configuration(PolymorphicModel): | |
202 |
|
206 | |||
203 | template = models.BooleanField(default=False) |
|
207 | template = models.BooleanField(default=False) | |
204 |
|
208 | |||
205 | name = models.CharField(verbose_name="Configuration Name", max_length=40, default='') |
|
209 | name = models.CharField(verbose_name="Configuration Name", max_length=40, default='') | |
206 |
|
210 | |||
207 | experiment = models.ForeignKey('Experiment', null=True, blank=True, on_delete=models.CASCADE) |
|
211 | experiment = models.ForeignKey('Experiment', null=True, blank=True, on_delete=models.CASCADE) | |
208 | device = models.ForeignKey(Device, on_delete=models.CASCADE) |
|
212 | device = models.ForeignKey(Device, on_delete=models.CASCADE) | |
209 |
|
213 | |||
210 | type = models.PositiveSmallIntegerField(default=0, choices=CONF_TYPES) |
|
214 | type = models.PositiveSmallIntegerField(default=0, choices=CONF_TYPES) | |
211 |
|
215 | |||
212 | created_date = models.DateTimeField(auto_now_add=True) |
|
216 | created_date = models.DateTimeField(auto_now_add=True) | |
213 | programmed_date = models.DateTimeField(auto_now=True) |
|
217 | programmed_date = models.DateTimeField(auto_now=True) | |
214 |
|
218 | |||
215 | parameters = models.TextField(default='{}') |
|
219 | parameters = models.TextField(default='{}') | |
216 |
|
220 | |||
217 | message = "" |
|
221 | message = "" | |
218 |
|
222 | |||
219 | class Meta: |
|
223 | class Meta: | |
220 | db_table = 'db_configurations' |
|
224 | db_table = 'db_configurations' | |
221 |
|
225 | |||
222 | def __unicode__(self): |
|
226 | def __unicode__(self): | |
223 |
|
227 | |||
224 | if self.experiment: |
|
228 | if self.experiment: | |
225 | return u'[%s, %s]: %s' % (self.experiment.name, |
|
229 | return u'[%s, %s]: %s' % (self.experiment.name, | |
226 | self.device.name, |
|
230 | self.device.name, | |
227 | self.name) |
|
231 | self.name) | |
228 | else: |
|
232 | else: | |
229 | return u'%s' % self.device.name |
|
233 | return u'%s' % self.device.name | |
230 |
|
234 | |||
|
235 | def clone(self, **kwargs): | |||
231 |
|
236 | |||
|
237 | self.pk = None | |||
|
238 | self.id = None | |||
|
239 | for attr, value in kwargs.items(): | |||
|
240 | setattr(self, attr, value) | |||
|
241 | ||||
|
242 | self.save() | |||
|
243 | ||||
|
244 | return self | |||
232 |
|
245 | |||
233 | def parms_to_dict(self): |
|
246 | def parms_to_dict(self): | |
234 |
|
247 | |||
235 | parameters = {} |
|
248 | parameters = {} | |
236 |
|
249 | |||
237 | for key in self.__dict__.keys(): |
|
250 | for key in self.__dict__.keys(): | |
238 | parameters[key] = getattr(self, key) |
|
251 | parameters[key] = getattr(self, key) | |
239 |
|
252 | |||
240 | return parameters |
|
253 | return parameters | |
241 |
|
254 | |||
242 | def parms_to_text(self): |
|
255 | def parms_to_text(self): | |
243 |
|
256 | |||
244 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
257 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
245 |
|
258 | |||
246 | return '' |
|
259 | return '' | |
247 |
|
260 | |||
248 | def parms_to_binary(self): |
|
261 | def parms_to_binary(self): | |
249 |
|
262 | |||
250 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
263 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
251 |
|
264 | |||
252 | return '' |
|
265 | return '' | |
253 |
|
266 | |||
254 | def dict_to_parms(self, parameters): |
|
267 | def dict_to_parms(self, parameters): | |
255 |
|
268 | |||
256 | if type(parameters) != type({}): |
|
269 | if type(parameters) != type({}): | |
257 | return |
|
270 | return | |
258 |
|
271 | |||
259 | for key in parameters.keys(): |
|
272 | for key in parameters.keys(): | |
260 | setattr(self, key, parameters[key]) |
|
273 | setattr(self, key, parameters[key]) | |
261 |
|
274 | |||
262 | def export_to_file(self, format="json"): |
|
275 | def export_to_file(self, format="json"): | |
263 |
|
276 | |||
264 | import json |
|
277 | import json | |
265 |
|
278 | |||
266 | content_type = '' |
|
279 | content_type = '' | |
267 |
|
280 | |||
268 | if format == 'text': |
|
281 | if format == 'text': | |
269 | content_type = 'text/plain' |
|
282 | content_type = 'text/plain' | |
270 | filename = '%s_%s.%s' %(self.device.device_type.name, self.name, self.device.device_type.name) |
|
283 | filename = '%s_%s.%s' %(self.device.device_type.name, self.name, self.device.device_type.name) | |
271 | content = self.parms_to_text() |
|
284 | content = self.parms_to_text() | |
272 |
|
285 | |||
273 | if format == 'binary': |
|
286 | if format == 'binary': | |
274 | content_type = 'application/octet-stream' |
|
287 | content_type = 'application/octet-stream' | |
275 | filename = '%s_%s.bin' %(self.device.device_type.name, self.name) |
|
288 | filename = '%s_%s.bin' %(self.device.device_type.name, self.name) | |
276 | content = self.parms_to_binary() |
|
289 | content = self.parms_to_binary() | |
277 |
|
290 | |||
278 | if not content_type: |
|
291 | if not content_type: | |
279 | content_type = 'application/json' |
|
292 | content_type = 'application/json' | |
280 | filename = '%s_%s.json' %(self.device.device_type.name, self.name) |
|
293 | filename = '%s_%s.json' %(self.device.device_type.name, self.name) | |
281 | content = json.dumps(self.parms_to_dict(), indent=2) |
|
294 | content = json.dumps(self.parms_to_dict(), indent=2) | |
282 |
|
295 | |||
283 | fields = {'content_type':content_type, |
|
296 | fields = {'content_type':content_type, | |
284 | 'filename':filename, |
|
297 | 'filename':filename, | |
285 | 'content':content |
|
298 | 'content':content | |
286 | } |
|
299 | } | |
287 |
|
300 | |||
288 | return fields |
|
301 | return fields | |
289 |
|
302 | |||
290 | def import_from_file(self, fp): |
|
303 | def import_from_file(self, fp): | |
291 |
|
304 | |||
292 | import os, json |
|
305 | import os, json | |
293 |
|
306 | |||
294 | parms = {} |
|
307 | parms = {} | |
295 |
|
308 | |||
296 | path, ext = os.path.splitext(fp.name) |
|
309 | path, ext = os.path.splitext(fp.name) | |
297 |
|
310 | |||
298 | if ext == '.json': |
|
311 | if ext == '.json': | |
299 | parms = json.load(fp) |
|
312 | parms = json.load(fp) | |
300 |
|
313 | |||
301 | return parms |
|
314 | return parms | |
302 |
|
315 | |||
303 | def status_device(self): |
|
316 | def status_device(self): | |
304 |
|
317 | |||
305 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
318 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
306 |
|
319 | |||
307 | return None |
|
320 | return None | |
308 |
|
321 | |||
309 | def stop_device(self): |
|
322 | def stop_device(self): | |
310 |
|
323 | |||
311 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
324 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
312 |
|
325 | |||
313 | return None |
|
326 | return None | |
314 |
|
327 | |||
315 | def start_device(self): |
|
328 | def start_device(self): | |
316 |
|
329 | |||
317 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
330 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
318 |
|
331 | |||
319 | return None |
|
332 | return None | |
320 |
|
333 | |||
321 | def write_device(self, parms): |
|
334 | def write_device(self, parms): | |
322 |
|
335 | |||
323 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
336 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
324 |
|
337 | |||
325 | return None |
|
338 | return None | |
326 |
|
339 | |||
327 | def read_device(self): |
|
340 | def read_device(self): | |
328 |
|
341 | |||
329 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
342 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
330 |
|
343 | |||
331 | return None |
|
344 | return None | |
332 |
|
345 | |||
333 | def get_absolute_url(self): |
|
346 | def get_absolute_url(self): | |
334 | return reverse('url_%s_conf' % self.device.device_type.name, args=[str(self.id)]) |
|
347 | return reverse('url_%s_conf' % self.device.device_type.name, args=[str(self.id)]) | |
335 |
|
348 | |||
336 | def get_absolute_url_edit(self): |
|
349 | def get_absolute_url_edit(self): | |
337 | return reverse('url_edit_%s_conf' % self.device.device_type.name, args=[str(self.id)]) |
|
350 | return reverse('url_edit_%s_conf' % self.device.device_type.name, args=[str(self.id)]) | |
338 |
|
351 | |||
339 | def get_absolute_url_import(self): |
|
352 | def get_absolute_url_import(self): | |
340 | return reverse('url_import_dev_conf', args=[str(self.id)]) |
|
353 | return reverse('url_import_dev_conf', args=[str(self.id)]) | |
341 |
|
354 | |||
342 | def get_absolute_url_export(self): |
|
355 | def get_absolute_url_export(self): | |
343 | return reverse('url_export_dev_conf', args=[str(self.id)]) |
|
356 | return reverse('url_export_dev_conf', args=[str(self.id)]) | |
344 |
|
357 | |||
345 | def get_absolute_url_write(self): |
|
358 | def get_absolute_url_write(self): | |
346 | return reverse('url_write_dev_conf', args=[str(self.id)]) |
|
359 | return reverse('url_write_dev_conf', args=[str(self.id)]) | |
347 |
|
360 | |||
348 | def get_absolute_url_read(self): |
|
361 | def get_absolute_url_read(self): | |
349 | return reverse('url_read_dev_conf', args=[str(self.id)]) |
|
362 | return reverse('url_read_dev_conf', args=[str(self.id)]) | |
350 |
|
363 | |||
351 | def get_absolute_url_start(self): |
|
364 | def get_absolute_url_start(self): | |
352 | return reverse('url_start_dev_conf', args=[str(self.id)]) |
|
365 | return reverse('url_start_dev_conf', args=[str(self.id)]) | |
353 |
|
366 | |||
354 | def get_absolute_url_stop(self): |
|
367 | def get_absolute_url_stop(self): | |
355 | return reverse('url_stop_dev_conf', args=[str(self.id)]) |
|
368 | return reverse('url_stop_dev_conf', args=[str(self.id)]) | |
356 |
|
369 | |||
357 | def get_absolute_url_status(self): |
|
370 | def get_absolute_url_status(self): | |
358 | return reverse('url_status_dev_conf', args=[str(self.id)]) No newline at end of file |
|
371 | return reverse('url_status_dev_conf', args=[str(self.id)]) |
@@ -1,144 +1,141 | |||||
1 | <!DOCTYPE html> |
|
1 | <!DOCTYPE html> | |
2 | {% load static %} |
|
2 | {% load static %} | |
3 | <html lang="en"> |
|
3 | <html lang="en"> | |
4 | <head> |
|
4 | <head> | |
5 | <meta charset="utf-8"> |
|
5 | <meta charset="utf-8"> | |
6 | <title>{% block title %}Jicamarca Integrated Radar System:::::{% endblock %}</title> |
|
6 | <title>{% block title %}Jicamarca Integrated Radar System:::::{% endblock %}</title> | |
7 | <meta name="description" content=""> |
|
7 | <meta name="description" content=""> | |
8 | <meta name="author" content=""> |
|
8 | <meta name="author" content=""> | |
9 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
|
9 | <meta name="viewport" content="width=device-width, initial-scale=1"> | |
10 | {# bootstrap_css #} |
|
10 | {# bootstrap_css #} | |
11 | <link href="{% static 'css/bootstrap-flatly.min.css' %}" media="all" rel="stylesheet"> |
|
11 | <link href="{% static 'css/bootstrap-flatly.min.css' %}" media="all" rel="stylesheet"> | |
12 | <style type="text/css"> |
|
12 | <style type="text/css"> | |
13 | body {padding-top: 60px} |
|
13 | body {padding-top: 60px} | |
14 | .logo {padding-top: 5px; height: 50px} |
|
14 | .logo {padding-top: 5px; height: 50px} | |
15 | .clickable-row {cursor: pointer;} |
|
15 | .clickable-row {cursor: pointer;} | |
16 |
.col-no-padding { padding-left:0; |
|
16 | .col-no-padding { padding-left:0;} | |
|
17 | .gi-2x{font-size: 2em;} | |||
|
18 | .gi-3x{font-size: 3em;} | |||
|
19 | .gi-4x{font-size: 4em;} | |||
|
20 | .gi-5x{font-size: 5em;} | |||
17 | </style> |
|
21 | </style> | |
18 | <!--[if lt IE 9]> |
|
22 | <!--[if lt IE 9]> | |
19 | <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script> |
|
23 | <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script> | |
20 | <![endif]--> |
|
24 | <![endif]--> | |
21 | <script src="{% static 'js/jquery.min.js' %}"></script> |
|
25 | <script src="{% static 'js/jquery.min.js' %}"></script> | |
22 | {% block extra-head %} |
|
26 | {% block extra-head %} | |
23 | {% endblock %} |
|
27 | {% endblock %} | |
24 | </head> |
|
28 | </head> | |
25 |
|
29 | |||
26 | <body> |
|
30 | <body> | |
27 |
|
31 | |||
28 | {% block main_menu %} |
|
32 | {% block main_menu %} | |
29 | <nav class="navbar navbar-default navbar-fixed-top" role="banner"> |
|
33 | <nav class="navbar navbar-default navbar-fixed-top" role="banner"> | |
30 | <div class="container-fluid"> |
|
34 | <div class="container-fluid"> | |
31 | <div class="navbar-header"> |
|
35 | <div class="navbar-header"> | |
32 | <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navigationbar"> |
|
36 | <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navigationbar"> | |
33 | <span class="sr-only">Toggle navigation</span> |
|
37 | <span class="sr-only">Toggle navigation</span> | |
34 | <span class="icon-bar"></span> |
|
38 | <span class="icon-bar"></span> | |
35 | <span class="icon-bar"></span> |
|
39 | <span class="icon-bar"></span> | |
36 | <span class="icon-bar"></span> |
|
40 | <span class="icon-bar"></span> | |
37 | </button> |
|
41 | </button> | |
38 | <a class="navbar-brand" href="{% url 'index' %}" style="padding-top:1px"><img class="logo" alt="JRO" src="{% static "images/logo-jro-white-trans.png" %}"></a> |
|
42 | <a class="navbar-brand" href="{% url 'index' %}" style="padding-top:1px"><img class="logo" alt="JRO" src="{% static "images/logo-jro-white-trans.png" %}"></a> | |
39 | </div> |
|
43 | </div> | |
40 | <div class="collapse navbar-collapse" id="navigationbar"> |
|
44 | <div class="collapse navbar-collapse" id="navigationbar"> | |
41 | <ul class="nav navbar-nav"> |
|
45 | <ul class="nav navbar-nav"> | |
42 | <li class=" dropdown {% block operation-active %}{% endblock %}"><a href="{% url 'url_operation'%}">Operation</a> |
|
46 | <li class=" dropdown {% block operation-active %}{% endblock %}"><a href="{% url 'url_operation'%}">Operation</a> | |
43 | </li> |
|
47 | </li> | |
44 |
<li class=" dropdown {% block |
|
48 | <li class=" dropdown {% block new-active %}{% endblock %}"> | |
45 | <a href="#" class="dropdown-toggle" data-toggle="dropdown">New<span class="caret"></span></a> |
|
49 | <a href="#" class="dropdown-toggle" data-toggle="dropdown">New<span class="caret"></span></a> | |
46 | <ul class="dropdown-menu" role="menu"> |
|
50 | <ul class="dropdown-menu" role="menu"> | |
47 | <li><a href="{% url 'url_add_campaign' %}">Campaign</a></li> |
|
51 | <li><a href="{% url 'url_add_campaign' %}">Campaign</a></li> | |
48 |
<li><a href="{% url 'url_add_experiment' |
|
52 | <li><a href="{% url 'url_add_experiment' %}">Experiment</a></li> | |
49 | <li><a href="{% url 'url_add_dev_conf' 0%}">Device Configuration</a></li> |
|
53 | <li><a href="{% url 'url_add_dev_conf' 0%}">Device Configuration</a></li> | |
50 |
<li><a href="{% url 'url_add_device'%}"> |
|
54 | <li><a href="{% url 'url_add_device'%}">Device</a></li> | |
51 |
|
||||
52 | </ul> |
|
55 | </ul> | |
53 | </li> |
|
56 | </li> | |
54 | <li class=" dropdown {% block test-active %}{% endblock %}"> |
|
|||
55 | <a href="#" class="dropdown-toggle" data-toggle="dropdown">Test<span class="caret"></span></a> |
|
|||
56 | <ul class="dropdown-menu" role="menu"> |
|
|||
57 | <li><a href="{% url 'url_experiments' %}">Experiments</a></li> |
|
|||
58 | <li><a href="{% url 'url_devices' %}">Devices</a></li> |
|
|||
59 | </ul> |
|
|||
60 | </li> |
|
|||
61 | <li class=" dropdown {% block search-active %}{% endblock %}"> |
|
57 | <li class=" dropdown {% block search-active %}{% endblock %}"> | |
62 | <a href="#" class="dropdown-toggle" data-toggle="dropdown">Search<span class="caret"></span></a> |
|
58 | <a href="#" class="dropdown-toggle" data-toggle="dropdown">Search<span class="caret"></span></a> | |
63 | <ul class="dropdown-menu" role="menu"> |
|
59 | <ul class="dropdown-menu" role="menu"> | |
64 | <li><a href="{% url 'url_campaigns' %}">Campaigns</a></li> |
|
60 | <li><a href="{% url 'url_campaigns' %}">Campaigns</a></li> | |
65 | <li><a href="{% url 'url_experiments' %}">Experiments</a></li> |
|
61 | <li><a href="{% url 'url_experiments' %}">Experiments</a></li> | |
66 | <li><a href="{% url 'url_dev_confs' %}">Configurations</a></li> |
|
62 | <li><a href="{% url 'url_dev_confs' %}">Configurations</a></li> | |
|
63 | <li><a href="{% url 'url_devices' %}">Devices</a></li> | |||
67 | </ul> |
|
64 | </ul> | |
68 | </li> |
|
65 | </li> | |
69 | </ul> |
|
66 | </ul> | |
70 | <ul class="nav navbar-nav navbar-right"> |
|
67 | <ul class="nav navbar-nav navbar-right"> | |
71 | <li class="nav-divider"></li> |
|
68 | <li class="nav-divider"></li> | |
72 | {% if user.is_authenticated %} |
|
69 | {% if user.is_authenticated %} | |
73 | <li class="dropdown"> |
|
70 | <li class="dropdown"> | |
74 | <a href="#" class="dropdown-toggle" data-toggle="dropdown">Hi {{ user.username }}<span class="caret"></span></a> |
|
71 | <a href="#" class="dropdown-toggle" data-toggle="dropdown">Hi {{ user.username }}<span class="caret"></span></a> | |
75 | <ul class="dropdown-menu" role="menu"> |
|
72 | <ul class="dropdown-menu" role="menu"> | |
76 | <li><a href="#">Control Panel</a></li> |
|
73 | <li><a href="#">Control Panel</a></li> | |
77 | <li><a href="{% url 'django.contrib.auth.views.logout' %}">Logout</a></li> |
|
74 | <li><a href="{% url 'django.contrib.auth.views.logout' %}">Logout</a></li> | |
78 | </ul> |
|
75 | </ul> | |
79 | </li> |
|
76 | </li> | |
80 | {% else %} |
|
77 | {% else %} | |
81 | <li><a href="{% url 'django.contrib.auth.views.login' %}?next={{request.get_full_path}}">Login</a></li> |
|
78 | <li><a href="{% url 'django.contrib.auth.views.login' %}?next={{request.get_full_path}}">Login</a></li> | |
82 | {% endif %} |
|
79 | {% endif %} | |
83 | </ul> |
|
80 | </ul> | |
84 | </div> |
|
81 | </div> | |
85 | </div> |
|
82 | </div> | |
86 | </nav> |
|
83 | </nav> | |
87 | <div style="clear: both;"></div> |
|
84 | <div style="clear: both;"></div> | |
88 | {% endblock %} |
|
85 | {% endblock %} | |
89 |
|
86 | |||
90 | <div class="container"> |
|
87 | <div class="container"> | |
91 | <div id="page" class="row" style="min-height:600px"> |
|
88 | <div id="page" class="row" style="min-height:600px"> | |
92 |
|
89 | |||
93 | <div class="col-md-3 hidden-xs hidden-sm" role="complementary"> |
|
90 | <div class="col-md-3 hidden-xs hidden-sm" role="complementary"> | |
94 | <br><br> |
|
91 | <br><br> | |
95 | <div id="sidebar"> |
|
92 | <div id="sidebar"> | |
96 | {% block sidebar%} |
|
93 | {% block sidebar%} | |
97 | {% endblock %} |
|
94 | {% endblock %} | |
98 | </div> |
|
95 | </div> | |
99 | </div> |
|
96 | </div> | |
100 |
|
97 | |||
101 | <div class="col-md-9 col-xs-12" role="main"> |
|
98 | <div class="col-md-9 col-xs-12" role="main"> | |
102 | <div class="page-header"> |
|
99 | <div class="page-header"> | |
103 | <h1>{% block content-title %}{% endblock %} <small>{% block content-suptitle %}{% endblock %}</small></h1> |
|
100 | <h1>{% block content-title %}{% endblock %} <small>{% block content-suptitle %}{% endblock %}</small></h1> | |
104 | </div> |
|
101 | </div> | |
105 | {% block messages %} |
|
102 | {% block messages %} | |
106 | {% if messages %} |
|
103 | {% if messages %} | |
107 | {% for message in messages %} |
|
104 | {% for message in messages %} | |
108 | <div class="alert alert-{% if message.tags %}{% if 'error' in message.tags %}danger{% else %}{{ message.tags }}{% endif %}{% else %}info{% endif %} alert-dismissible" role="alert"> |
|
105 | <div class="alert alert-{% if message.tags %}{% if 'error' in message.tags %}danger{% else %}{{ message.tags }}{% endif %}{% else %}info{% endif %} alert-dismissible" role="alert"> | |
109 | <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button> |
|
106 | <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button> | |
110 | <strong>{{message.tags|title}}!</strong> {{ message }} |
|
107 | <strong>{{message.tags|title}}!</strong> {{ message }} | |
111 | </div> |
|
108 | </div> | |
112 | {% endfor %} |
|
109 | {% endfor %} | |
113 | {% endif %} |
|
110 | {% endif %} | |
114 | {% endblock %} |
|
111 | {% endblock %} | |
115 |
|
112 | |||
116 | {% block content %} |
|
113 | {% block content %} | |
117 | {% endblock %} |
|
114 | {% endblock %} | |
118 |
|
115 | |||
119 | </div> |
|
116 | </div> | |
120 |
|
117 | |||
121 | </div><!--/row--> |
|
118 | </div><!--/row--> | |
122 | </div> <!-- container --> |
|
119 | </div> <!-- container --> | |
123 |
|
120 | |||
124 | <div id="debug">{{debug}}</div> |
|
121 | <div id="debug">{{debug}}</div> | |
125 |
|
122 | |||
126 | {% block footer %} |
|
123 | {% block footer %} | |
127 | <footer class="footer"> |
|
124 | <footer class="footer"> | |
128 | <div class="container"> |
|
125 | <div class="container"> | |
129 | <p><hr></p> |
|
126 | <p><hr></p> | |
130 | <p> |
|
127 | <p> | |
131 | © <a href="http://jro.igp.gob.pe">Jicamarca Radio Observatory</a> - {% now "Y" %} |
|
128 | © <a href="http://jro.igp.gob.pe">Jicamarca Radio Observatory</a> - {% now "Y" %} | |
132 | </p> |
|
129 | </p> | |
133 | </div> |
|
130 | </div> | |
134 | </footer> |
|
131 | </footer> | |
135 | {% endblock %} |
|
132 | {% endblock %} | |
136 |
|
133 | |||
137 | {# bootstrap_javascript jquery=True #} |
|
134 | {# bootstrap_javascript jquery=True #} | |
138 |
|
135 | |||
139 | <script src="{% static 'js/bootstrap.min.js' %}"></script> |
|
136 | <script src="{% static 'js/bootstrap.min.js' %}"></script> | |
140 | {% block extra-js %} |
|
137 | {% block extra-js %} | |
141 | {% endblock%} |
|
138 | {% endblock%} | |
142 | </body> |
|
139 | </body> | |
143 | </html> |
|
140 | </html> | |
144 |
|
141 |
@@ -1,83 +1,78 | |||||
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 | <table class="table table-bordered"> |
|
15 | <table class="table table-bordered"> | |
16 | {% for key in campaign_keys %} |
|
16 | {% for key in campaign_keys %} | |
17 | <tr><th>{{key|title}}</th><td>{{campaign|attr:key}}</td></tr> |
|
17 | <tr><th>{{key|title}}</th><td>{{campaign|attr:key}}</td></tr> | |
18 | {% endfor %} |
|
18 | {% endfor %} | |
19 | </table> |
|
19 | </table> | |
20 |
|
20 | |||
21 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_export">Export</button> |
|
21 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_export">Export</button> | |
22 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_edit">Edit</button> |
|
22 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_edit">Edit</button> | |
23 |
|
23 | |||
24 | <br></br> |
|
24 | <br></br> | |
25 | <br></br> |
|
25 | <br></br> | |
26 |
|
26 | |||
27 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> |
|
27 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> | |
28 |
|
28 | |||
29 | <div class="panel panel-default"> |
|
29 | <div class="panel panel-default"> | |
30 | <div class="panel-heading" role="tab" id="headingTwo"> |
|
30 | <div class="panel-heading" role="tab" id="headingTwo"> | |
31 | <h4 class="panel-title"> |
|
31 | <h4 class="panel-title"> | |
32 | <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo"> |
|
32 | <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo"> | |
33 | Experiment List |
|
33 | Experiment List | |
34 | </a> |
|
34 | </a> | |
35 | </h4> |
|
35 | </h4> | |
36 | </div> |
|
36 | </div> | |
37 |
|
37 | |||
38 | <div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> |
|
38 | <div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> | |
39 | <div class="panel-body"> |
|
39 | <div class="panel-body"> | |
40 | <table class="table table-hover"> |
|
40 | <table class="table table-hover"> | |
41 | <tr> |
|
41 | <tr> | |
42 | <th>#</th> |
|
42 | <th>#</th> | |
43 | {% for header in experiment_keys %} |
|
43 | {% for header in experiment_keys %} | |
44 | <th>{{ header|title }}</th> |
|
44 | <th>{{ header|title }}</th> | |
45 | {% endfor%} |
|
45 | {% endfor%} | |
46 | </tr> |
|
46 | </tr> | |
47 | {% for item in experiments %} |
|
47 | {% for item in experiments %} | |
48 | <tr class="clickable-row" data-href="{% url 'url_experiment' item.id %}"> |
|
48 | <tr class="clickable-row" data-href="{% url 'url_experiment' item.id %}"> | |
49 | <td>{{ forloop.counter }}</td> |
|
49 | <td>{{ forloop.counter }}</td> | |
50 | {% for key in experiment_keys %} |
|
50 | {% for key in experiment_keys %} | |
51 | <td>{{ item|attr:key }}</td> |
|
51 | <td>{{ item|attr:key }}</td> | |
52 | {% endfor %} |
|
52 | {% endfor %} | |
53 | </tr> |
|
53 | </tr> | |
54 | {% endfor %} |
|
54 | {% endfor %} | |
55 | </table> |
|
55 | </table> | |
56 | <button class="btn btn-primary pull-right" id="bt_add">{{button}}</button> |
|
|||
57 | </div> |
|
56 | </div> | |
58 | </div> |
|
57 | </div> | |
59 | </div> |
|
58 | </div> | |
60 | </div> |
|
59 | </div> | |
61 | {% endblock %} |
|
60 | {% endblock %} | |
62 |
|
61 | |||
63 | {% block sidebar%} |
|
62 | {% block sidebar%} | |
64 | {% include "sidebar_devices.html" %} |
|
63 | {% include "sidebar_devices.html" %} | |
65 | {% endblock %} |
|
64 | {% endblock %} | |
66 |
|
65 | |||
67 | {% block extra-js%} |
|
66 | {% block extra-js%} | |
68 | <script type="text/javascript"> |
|
67 | <script type="text/javascript"> | |
69 |
|
68 | |||
70 | $(".clickable-row").click(function() { |
|
69 | $(".clickable-row").click(function() { | |
71 | document.location = $(this).data("href"); |
|
70 | document.location = $(this).data("href"); | |
72 | }); |
|
71 | }); | |
73 |
|
72 | |||
74 | $("#bt_edit").click(function() { |
|
73 | $("#bt_edit").click(function() { | |
75 | document.location = "{% url 'url_edit_campaign' campaign.id%}"; |
|
74 | document.location = "{% url 'url_edit_campaign' campaign.id %}"; | |
76 | }); |
|
75 | }); | |
77 |
|
76 | |||
78 | $("#bt_add").click(function() { |
|
|||
79 | document.location = "{% url 'url_add_experiment' campaign.id%}"; |
|
|||
80 | }); |
|
|||
81 |
|
||||
82 | </script> |
|
77 | </script> | |
83 | {% endblock %} No newline at end of file |
|
78 | {% endblock %} |
@@ -1,36 +1,54 | |||||
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 | <form class="form" method="post" action=""> |
|
15 | <form class="form" method="post" action=""> | |
16 | {% csrf_token %} |
|
16 | {% csrf_token %} | |
17 | {% bootstrap_form form layout='horizontal' size='medium' %} |
|
17 | {% bootstrap_form form layout='horizontal' size='medium' %} | |
18 | <div style="clear: both;"></div> |
|
18 | <div style="clear: both;"></div> | |
19 | <br> |
|
19 | {% if button %} | |
20 | <button type="submit" class="btn btn-primary pull-right">{{button}}</button> |
|
20 | <br> | |
|
21 | <button type="submit" class="btn btn-primary pull-right">{{button}}</button> | |||
|
22 | {% endif %} | |||
21 | </form> |
|
23 | </form> | |
22 | {% endblock %} |
|
24 | {% endblock %} | |
23 |
|
25 | |||
24 | {% block sidebar%} |
|
26 | {% block sidebar%} | |
25 | {% include "sidebar_devices.html" %} |
|
27 | {% include "sidebar_devices.html" %} | |
26 | {% endblock %} |
|
28 | {% endblock %} | |
27 |
|
29 | |||
28 | {% block extra-js%} |
|
30 | {% block extra-js%} | |
29 | <script src="{% static 'js/moment.min.js' %}"></script> |
|
31 | <script src="{% static 'js/moment.min.js' %}"></script> | |
30 | <script src="{% static 'js/bootstrap-datetimepicker.min.js' %}"></script> |
|
32 | <script src="{% static 'js/bootstrap-datetimepicker.min.js' %}"></script> | |
31 | <script type="text/javascript"> |
|
33 | <script type="text/javascript"> | |
32 |
|
34 | |||
33 | $('.input-group.date').datetimepicker({"format": "YYYY-MM-DD HH:mm"}); |
|
35 | $('.input-group.date').datetimepicker({"format": "YYYY-MM-DD HH:mm"}); | |
34 |
|
36 | |||
|
37 | $('#id_create_from').change(function() { | |||
|
38 | var url = "{% url 'url_add_campaign' %}"; | |||
|
39 | if ($(this).val()=="2"){ | |||
|
40 | document.location = url+"?template=0"; | |||
|
41 | }else if ($(this).val()=="1"){ | |||
|
42 | document.location = url+"?blank=0"; | |||
|
43 | }else{ | |||
|
44 | document.location = url; | |||
|
45 | } | |||
|
46 | }); | |||
|
47 | ||||
|
48 | $('#id_choose_template').change(function() { | |||
|
49 | var url = "{% url 'url_add_campaign' %}"; | |||
|
50 | document.location = url+"?template="+$(this).val(); | |||
|
51 | }); | |||
|
52 | ||||
35 | </script> |
|
53 | </script> | |
36 | {% endblock %} No newline at end of file |
|
54 | {% endblock %} |
@@ -1,50 +1,46 | |||||
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 | <table class="table table-hover"> |
|
15 | <table class="table table-hover"> | |
16 | <tr> |
|
16 | <tr> | |
17 | <th>#</th> |
|
17 | <th>#</th> | |
18 | {% for key in campaign_keys %} |
|
18 | {% for key in campaign_keys %} | |
19 | <th>{{ key|title }}</th> |
|
19 | <th>{{ key|title }}</th> | |
20 | {% endfor%} |
|
20 | {% endfor%} | |
21 | </tr> |
|
21 | </tr> | |
22 | {% for campaign in campaigns %} |
|
22 | {% for campaign in campaigns %} | |
23 | <tr class="clickable-row" data-href="{% url 'url_campaign' campaign.id %}"> |
|
23 | <tr class="clickable-row" data-href="{% url 'url_campaign' campaign.id %}"> | |
24 | <td>{{ forloop.counter }}</td> |
|
24 | <td>{{ forloop.counter }}</td> | |
25 | {% for key in campaign_keys %} |
|
25 | {% for key in campaign_keys %} | |
26 | <td>{{ campaign|attr:key }}</td> |
|
26 | <td>{{ campaign|attr:key }}</td> | |
27 | {% endfor %} |
|
27 | {% endfor %} | |
28 | </tr> |
|
28 | </tr> | |
29 | {% endfor %} |
|
29 | {% endfor %} | |
30 | </table> |
|
30 | </table> | |
31 | <button class="btn btn-primary pull-right" id="bt_add">{{button}}</button> |
|
31 | ||
32 | {% endblock %} |
|
32 | {% endblock %} | |
33 |
|
33 | |||
34 | {% block sidebar%} |
|
34 | {% block sidebar%} | |
35 | {% include "sidebar_devices.html" %} |
|
35 | {% include "sidebar_devices.html" %} | |
36 | {% endblock %} |
|
36 | {% endblock %} | |
37 |
|
37 | |||
38 | {% block extra-js%} |
|
38 | {% block extra-js%} | |
39 | <script type="text/javascript"> |
|
39 | <script type="text/javascript"> | |
40 |
|
||||
41 | $("#bt_add").click(function() { |
|
|||
42 | document.location = "{% url 'url_add_campaign' %}"; |
|
|||
43 | }); |
|
|||
44 |
|
40 | |||
45 | $(".clickable-row").click(function() { |
|
41 | $(".clickable-row").click(function() { | |
46 | document.location = $(this).data("href"); |
|
42 | document.location = $(this).data("href"); | |
47 |
|
|
43 | }); | |
48 |
|
44 | |||
49 | </script> |
|
45 | </script> | |
50 | {% endblock %} No newline at end of file |
|
46 | {% endblock %} |
@@ -1,81 +1,81 | |||||
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 |
|
5 | |||
6 |
{% block |
|
6 | {% block search-active %}active{% endblock %} | |
7 |
|
7 | |||
8 | {% block content-title %}{{title}}{% endblock %} |
|
8 | {% block content-title %}{{title}}{% endblock %} | |
9 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
9 | {% block content-suptitle %}{{suptitle}}{% endblock %} | |
10 |
|
10 | |||
11 | {% block content %} |
|
11 | {% block content %} | |
12 |
|
12 | |||
13 | {% block menu-actions %} |
|
13 | {% block menu-actions %} | |
14 | <span class=" dropdown pull-right"> |
|
14 | <span class=" dropdown pull-right"> | |
15 |
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-menu-hamburger" aria-hidden="true"></span></a> |
|
15 | <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-menu-hamburger gi-2x" aria-hidden="true"></span></a> | |
16 | <ul class="dropdown-menu" role="menu"> |
|
16 | <ul class="dropdown-menu" role="menu"> | |
17 | <li><a href="{{ dev_conf.get_absolute_url_edit }}"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a></li> |
|
17 | <li><a href="{{ dev_conf.get_absolute_url_edit }}"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a></li> | |
18 | <li><a href="{{ dev_conf.get_absolute_url_import }}"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Import </a></li> |
|
18 | <li><a href="{{ dev_conf.get_absolute_url_import }}"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Import </a></li> | |
19 | <li><a href="{{ dev_conf.get_absolute_url_export }}"><span class="glyphicon glyphicon-export" aria-hidden="true"></span> Export </a></li> |
|
19 | <li><a href="{{ dev_conf.get_absolute_url_export }}"><span class="glyphicon glyphicon-export" aria-hidden="true"></span> Export </a></li> | |
20 | {% block extra-menu-actions %} |
|
20 | {% block extra-menu-actions %} | |
21 | {% endblock %} |
|
21 | {% endblock %} | |
22 | <li><a>----------------</a></li> |
|
22 | <li><a>----------------</a></li> | |
23 | <li><a href="{{ dev_conf.get_absolute_url_status }}"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Status</a></li> |
|
23 | <li><a href="{{ dev_conf.get_absolute_url_status }}"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Status</a></li> | |
24 | {% if not no_play %} |
|
24 | {% if not no_play %} | |
25 | <li><a href="{{ dev_conf.get_absolute_url_start}}"><span class="glyphicon glyphicon-play" aria-hidden="true"></span> Start</a></li> |
|
25 | <li><a href="{{ dev_conf.get_absolute_url_start}}"><span class="glyphicon glyphicon-play" aria-hidden="true"></span> Start</a></li> | |
26 | <li><a href="{{ dev_conf.get_absolute_url_stop }}"><span class="glyphicon glyphicon-stop" aria-hidden="true"></span> Stop</a></li> |
|
26 | <li><a href="{{ dev_conf.get_absolute_url_stop }}"><span class="glyphicon glyphicon-stop" aria-hidden="true"></span> Stop</a></li> | |
27 | {% endif %} |
|
27 | {% endif %} | |
28 | <li><a href="{{ dev_conf.get_absolute_url_write }}"><span class="glyphicon glyphicon-download" aria-hidden="true"></span> Write</a></li> |
|
28 | <li><a href="{{ dev_conf.get_absolute_url_write }}"><span class="glyphicon glyphicon-download" aria-hidden="true"></span> Write</a></li> | |
29 | <li><a href="{{ dev_conf.get_absolute_url_read }}"><span class="glyphicon glyphicon-upload" aria-hidden="true"></span> Read</a></li> |
|
29 | <li><a href="{{ dev_conf.get_absolute_url_read }}"><span class="glyphicon glyphicon-upload" aria-hidden="true"></span> Read</a></li> | |
30 | </ul> |
|
30 | </ul> | |
31 | </span> |
|
31 | </span> | |
32 | {% endblock %} |
|
32 | {% endblock %} | |
33 |
|
33 | |||
34 | <table class="table table-bordered"> |
|
34 | <table class="table table-bordered"> | |
35 | <tr> |
|
35 | <tr> | |
36 | <th>Status</th> |
|
36 | <th>Status</th> | |
37 | <td>{%if status != "No connected" %} <span class="glyphicon glyphicon-ok-circle text-success" aria-hidden="true"></span> {{status}} {% else %} <span class="glyphicon glyphicon-remove-circle text-danger" aria-hidden="true"></span> {{status}} {% endif %}</td> |
|
37 | <td>{%if status != "No connected" %} <span class="glyphicon glyphicon-ok-circle text-success" aria-hidden="true"></span> {{status}} {% else %} <span class="glyphicon glyphicon-remove-circle text-danger" aria-hidden="true"></span> {{status}} {% endif %}</td> | |
38 | </tr> |
|
38 | </tr> | |
39 |
|
39 | |||
40 | {% for key in dev_conf_keys %} |
|
40 | {% for key in dev_conf_keys %} | |
41 | <tr> |
|
41 | <tr> | |
42 | <th>{% get_verbose_field_name dev_conf key %}</th> |
|
42 | <th>{% get_verbose_field_name dev_conf key %}</th> | |
43 | <td>{{dev_conf|attr:key}}</td> |
|
43 | <td>{{dev_conf|attr:key}}</td> | |
44 | </tr> |
|
44 | </tr> | |
45 | {% endfor %} |
|
45 | {% endfor %} | |
46 | </table> |
|
46 | </table> | |
47 |
|
47 | |||
48 | {% block extra-content %} |
|
48 | {% block extra-content %} | |
49 | {% endblock %} |
|
49 | {% endblock %} | |
50 |
|
50 | |||
51 | {% endblock %} |
|
51 | {% endblock %} | |
52 |
|
52 | |||
53 | {% block sidebar%} |
|
53 | {% block sidebar%} | |
54 | {% include "sidebar_devices.html" %} |
|
54 | {% include "sidebar_devices.html" %} | |
55 | {% endblock %} |
|
55 | {% endblock %} | |
56 |
|
56 | |||
57 | {% block extra-js%} |
|
57 | {% block extra-js%} | |
58 | <script type="text/javascript"> |
|
58 | <script type="text/javascript"> | |
59 |
|
59 | |||
60 | $("#bt_edit").click(function() { |
|
60 | $("#bt_edit").click(function() { | |
61 | document.location = "{{ dev_conf.get_absolute_url_edit }}"; |
|
61 | document.location = "{{ dev_conf.get_absolute_url_edit }}"; | |
62 | }); |
|
62 | }); | |
63 |
|
63 | |||
64 | $("#bt_read").click(function() { |
|
64 | $("#bt_read").click(function() { | |
65 | document.location = "{{ dev_conf.get_absolute_url_read }}"; |
|
65 | document.location = "{{ dev_conf.get_absolute_url_read }}"; | |
66 | }); |
|
66 | }); | |
67 |
|
67 | |||
68 | $("#bt_write").click(function() { |
|
68 | $("#bt_write").click(function() { | |
69 | document.location = "{{ dev_conf.get_absolute_url_write }}"; |
|
69 | document.location = "{{ dev_conf.get_absolute_url_write }}"; | |
70 | }); |
|
70 | }); | |
71 |
|
71 | |||
72 | $("#bt_import").click(function() { |
|
72 | $("#bt_import").click(function() { | |
73 | document.location = "{{ dev_conf.get_absolute_url_import }}"; |
|
73 | document.location = "{{ dev_conf.get_absolute_url_import }}"; | |
74 | }); |
|
74 | }); | |
75 |
|
75 | |||
76 | $("#bt_export").click(function() { |
|
76 | $("#bt_export").click(function() { | |
77 | document.location = "{{ dev_conf.get_absolute_url_export }}"; |
|
77 | document.location = "{{ dev_conf.get_absolute_url_export }}"; | |
78 | }); |
|
78 | }); | |
79 |
|
79 | |||
80 | </script> |
|
80 | </script> | |
81 | {% endblock %} No newline at end of file |
|
81 | {% endblock %} |
@@ -1,46 +1,48 | |||||
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 |
|
5 | |||
6 | {% block conf-active %}active{% endblock %} |
|
6 | {% block conf-active %}active{% endblock %} | |
7 |
|
7 | |||
8 | {% block content-title %}{{title}}{% endblock %} |
|
8 | {% block content-title %}{{title}}{% endblock %} | |
9 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
9 | {% block content-suptitle %}{{suptitle}}{% endblock %} | |
10 |
|
10 | |||
11 | {% block content %} |
|
11 | {% block content %} | |
12 |
|
12 | |||
13 | {% if form.is_multipart %} |
|
13 | {% if form.is_multipart %} | |
14 | <form class="form" enctype="multipart/form-data" method="post" action="{{action}}"> |
|
14 | <form class="form" enctype="multipart/form-data" method="post" action="{{action}}"> | |
15 | {% else %} |
|
15 | {% else %} | |
16 | <form class="form" method="post" action="{{action}}"> |
|
16 | <form class="form" method="post" action="{{action}}"> | |
17 | {% endif %} |
|
17 | {% endif %} | |
18 |
|
18 | |||
19 | {% csrf_token %} |
|
19 | {% csrf_token %} | |
20 | {% bootstrap_form form layout='horizontal' size='medium' %} |
|
20 | {% bootstrap_form form layout='horizontal' size='medium' %} | |
21 | <div style="clear: both;"></div> |
|
21 | <div style="clear: both;"></div> | |
22 | <br> |
|
22 | <br> | |
23 | {% if extra_button %} |
|
23 | {% if extra_button %} | |
24 | <div class="pull-left"> |
|
24 | <div class="pull-left"> | |
25 | <button type="button" class="btn btn-primary" id="bt_{{extra_button}}">{{extra_button}}</button> |
|
25 | <button type="button" class="btn btn-primary" id="bt_{{extra_button}}">{{extra_button}}</button> | |
26 | </div> |
|
26 | </div> | |
27 | {% endif %} |
|
27 | {% endif %} | |
28 | <div class="pull-right"> |
|
28 | <div class="pull-right"> | |
29 | <button type="button" class="btn btn-primary" onclick="{% if previous %}window.location.replace('{{ previous }}');{% else %}history.go(-1);{% endif %}">Cancel</button> |
|
29 | <button type="button" class="btn btn-primary" onclick="{% if previous %}window.location.replace('{{ previous }}');{% else %}history.go(-1);{% endif %}">Cancel</button> | |
30 | <button type="submit" class="btn btn-primary">{{button}}</button> |
|
30 | <button type="submit" class="btn btn-primary">{{button}}</button> | |
31 | </div> |
|
31 | </div> | |
32 | </form> |
|
32 | </form> | |
33 | {% endblock %} |
|
33 | {% endblock %} | |
34 |
|
34 | |||
35 | {% block sidebar%} |
|
35 | {% block sidebar%} | |
36 | {% include "sidebar_devices.html" %} |
|
36 | {% include "sidebar_devices.html" %} | |
37 | {% endblock %} |
|
37 | {% endblock %} | |
38 |
|
38 | |||
39 | {% block extra-js%} |
|
39 | {% block extra-js%} | |
|
40 | {% if id_exp %} | |||
40 | <script type="text/javascript"> |
|
41 | <script type="text/javascript"> | |
41 | $("#id_device").change(function() { |
|
42 | $("#id_device").change(function() { | |
42 | var url = "{% url 'url_add_dev_conf' id_exp %}"; |
|
43 | var url = "{% url 'url_add_dev_conf' id_exp %}"; | |
43 | document.location = url+ $(this).val() + "/"; |
|
44 | document.location = url+ $(this).val() + "/"; | |
44 | }); |
|
45 | }); | |
45 |
|
|
46 | </script> | |
|
47 | {% endif %} | |||
46 | {% endblock %} No newline at end of file |
|
48 | {% endblock %} |
@@ -1,50 +1,45 | |||||
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 conf-active %}active{% endblock %} |
|
9 | {% block conf-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 | <table class="table table-hover"> |
|
15 | <table class="table table-hover"> | |
16 | <tr> |
|
16 | <tr> | |
17 | <th>#</th> |
|
17 | <th>#</th> | |
18 | {% for key in configuration_keys %} |
|
18 | {% for key in configuration_keys %} | |
19 | <th>{{ key|title }}</th> |
|
19 | <th>{{ key|title }}</th> | |
20 | {% endfor%} |
|
20 | {% endfor%} | |
21 | </tr> |
|
21 | </tr> | |
22 | {% for item in configurations %} |
|
22 | {% for item in configurations %} | |
23 | <tr class="clickable-row" data-href="{{item.get_absolute_url}}"> |
|
23 | <tr class="clickable-row" data-href="{{item.get_absolute_url}}"> | |
24 | <td>{{ forloop.counter }}</td> |
|
24 | <td>{{ forloop.counter }}</td> | |
25 | {% for key in configuration_keys %} |
|
25 | {% for key in configuration_keys %} | |
26 | <td>{{ item|attr:key }}</td> |
|
26 | <td>{{ item|attr:key }}</td> | |
27 | {% endfor %} |
|
27 | {% endfor %} | |
28 | </tr> |
|
28 | </tr> | |
29 | {% endfor %} |
|
29 | {% endfor %} | |
30 | </table> |
|
30 | </table> | |
31 | <button class="btn btn-primary pull-right" id="bt_add">{{button}}</button> |
|
|||
32 | {% endblock %} |
|
31 | {% endblock %} | |
33 |
|
32 | |||
34 | {% block sidebar%} |
|
33 | {% block sidebar%} | |
35 | {% include "sidebar_devices.html" %} |
|
34 | {% include "sidebar_devices.html" %} | |
36 | {% endblock %} |
|
35 | {% endblock %} | |
37 |
|
36 | |||
38 | {% block extra-js%} |
|
37 | {% block extra-js%} | |
39 | <script type="text/javascript"> |
|
38 | <script type="text/javascript"> | |
40 |
|
||||
41 | $("#bt_add").click(function() { |
|
|||
42 | document.location = "{% url 'url_add_dev_conf' 0%}"; |
|
|||
43 | }); |
|
|||
44 |
|
39 | |||
45 | $(".clickable-row").click(function() { |
|
40 | $(".clickable-row").click(function() { | |
46 | document.location = $(this).data("href"); |
|
41 | document.location = $(this).data("href"); | |
47 |
|
|
42 | }); | |
48 |
|
43 | |||
49 | </script> |
|
44 | </script> | |
50 | {% endblock %} No newline at end of file |
|
45 | {% endblock %} |
@@ -1,47 +1,43 | |||||
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 |
|
5 | |||
6 | {% block dev-active %}active{% endblock %} |
|
6 | {% block dev-active %}active{% endblock %} | |
7 |
|
7 | |||
8 | {% block content-title %}{{title}}{% endblock %} |
|
8 | {% block content-title %}{{title}}{% endblock %} | |
9 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
9 | {% block content-suptitle %}{{suptitle}}{% endblock %} | |
10 |
|
10 | |||
11 | {% block content %} |
|
11 | {% block content %} | |
12 | <table class="table table-hover"> |
|
12 | <table class="table table-hover"> | |
13 | <tr> |
|
13 | <tr> | |
14 | <th>#</th> |
|
14 | <th>#</th> | |
15 | {% for key in device_keys %} |
|
15 | {% for key in device_keys %} | |
16 | <th>{{ key|title }}</th> |
|
16 | <th>{{ key|title }}</th> | |
17 | {% endfor%} |
|
17 | {% endfor%} | |
18 | </tr> |
|
18 | </tr> | |
19 | {% for device in devices %} |
|
19 | {% for device in devices %} | |
20 | <tr class="clickable-row" data-href="{% url 'url_device' device.id %}"> |
|
20 | <tr class="clickable-row" data-href="{% url 'url_device' device.id %}"> | |
21 | <td>{{ forloop.counter }}</td> |
|
21 | <td>{{ forloop.counter }}</td> | |
22 | {% for key in device_keys %} |
|
22 | {% for key in device_keys %} | |
23 | <td>{{ device|attr:key }}</td> |
|
23 | <td>{{ device|attr:key }}</td> | |
24 | {% endfor %} |
|
24 | {% endfor %} | |
25 | </tr> |
|
25 | </tr> | |
26 | {% endfor %} |
|
26 | {% endfor %} | |
27 | </table> |
|
27 | </table> | |
28 | <button class="btn btn-primary pull-right" id="bt_add">{{button}}</button> |
|
28 | ||
29 | {% endblock %} |
|
29 | {% endblock %} | |
30 |
|
30 | |||
31 | {% block sidebar%} |
|
31 | {% block sidebar%} | |
32 | {% include "sidebar_devices.html" %} |
|
32 | {% include "sidebar_devices.html" %} | |
33 | {% endblock %} |
|
33 | {% endblock %} | |
34 |
|
34 | |||
35 | {% block extra-js%} |
|
35 | {% block extra-js%} | |
36 | <script type="text/javascript"> |
|
36 | <script type="text/javascript"> | |
37 |
|
||||
38 | $("#bt_add").click(function() { |
|
|||
39 | document.location = "{% url 'url_add_device' %}"; |
|
|||
40 | }); |
|
|||
41 |
|
37 | |||
42 | $(".clickable-row").click(function() { |
|
38 | $(".clickable-row").click(function() { | |
43 | document.location = $(this).data("href"); |
|
39 | document.location = $(this).data("href"); | |
44 |
|
|
40 | }); | |
45 |
|
41 | |||
46 | </script> |
|
42 | </script> | |
47 | {% endblock %} No newline at end of file |
|
43 | {% endblock %} |
@@ -1,80 +1,80 | |||||
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 | <table class="table table-bordered"> |
|
15 | <table class="table table-bordered"> | |
16 | {% for key in experiment_keys %} |
|
16 | {% for key in experiment_keys %} | |
17 | <tr><th>{{key|title}}</th><td>{{experiment|attr:key}}</td></tr> |
|
17 | <tr><th>{{key|title}}</th><td>{{experiment|attr:key}}</td></tr> | |
18 | {% endfor %} |
|
18 | {% endfor %} | |
19 | </table> |
|
19 | </table> | |
20 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_export">Export</button> |
|
20 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_export">Export</button> | |
21 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_edit">Edit</button> |
|
21 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_edit">Edit</button> | |
22 | <br></br> |
|
22 | <br></br> | |
23 | <br></br> |
|
23 | <br></br> | |
24 |
|
24 | |||
25 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> |
|
25 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> | |
26 |
|
26 | |||
27 | <div class="panel panel-default"> |
|
27 | <div class="panel panel-default"> | |
28 | <div class="panel-heading" role="tab" id="headingTwo"> |
|
28 | <div class="panel-heading" role="tab" id="headingTwo"> | |
29 | <h4 class="panel-title"> |
|
29 | <h4 class="panel-title"> | |
30 | <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseThree"> |
|
30 | <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseThree"> | |
31 | Device Configurations |
|
31 | Device Configurations | |
32 | </a> |
|
32 | </a> | |
33 | </h4> |
|
33 | </h4> | |
34 | </div> |
|
34 | </div> | |
35 | <div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> |
|
35 | <div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> | |
36 | <div class="panel-body"> |
|
36 | <div class="panel-body"> | |
37 | <table class="table table-hover"> |
|
37 | <table class="table table-hover"> | |
38 | <tr> |
|
38 | <tr> | |
39 | <th>#</th> |
|
39 | <th>#</th> | |
40 | {% for key in configuration_labels %} |
|
40 | {% for key in configuration_labels %} | |
41 | <th>{{ key|title }}</th> |
|
41 | <th>{{ key|title }}</th> | |
42 | {% endfor%} |
|
42 | {% endfor%} | |
43 | </tr> |
|
43 | </tr> | |
44 | {% for item in configurations %} |
|
44 | {% for item in configurations %} | |
45 | <tr class="clickable-row" data-href="{{item.get_absolute_url}}"> |
|
45 | <tr class="clickable-row" data-href="{{item.get_absolute_url}}"> | |
46 | <td>{{ forloop.counter }}</td> |
|
46 | <td>{{ forloop.counter }}</td> | |
47 | {% for key in configuration_keys %} |
|
47 | {% for key in configuration_keys %} | |
48 | <td>{{ item|value:key }}</td> |
|
48 | <td>{{ item|value:key }}</td> | |
49 | {% endfor %} |
|
49 | {% endfor %} | |
50 | </tr> |
|
50 | </tr> | |
51 | {% endfor %} |
|
51 | {% endfor %} | |
52 | </table> |
|
52 | </table> | |
53 | <button class="btn btn-primary pull-right" id="bt_add_conf">{{button}}</button> |
|
53 | <button class="btn btn-primary pull-right" id="bt_add_conf">{{button}}</button> | |
54 | </div> |
|
54 | </div> | |
55 | </div> |
|
55 | </div> | |
56 | </div> |
|
56 | </div> | |
57 | </div> |
|
57 | </div> | |
58 | {% endblock %} |
|
58 | {% endblock %} | |
59 |
|
59 | |||
60 | {% block sidebar%} |
|
60 | {% block sidebar%} | |
61 | {% include "sidebar_devices.html" %} |
|
61 | {% include "sidebar_devices.html" %} | |
62 | {% endblock %} |
|
62 | {% endblock %} | |
63 |
|
63 | |||
64 | {% block extra-js%} |
|
64 | {% block extra-js%} | |
65 | <script type="text/javascript"> |
|
65 | <script type="text/javascript"> | |
66 |
|
66 | |||
67 | $(".clickable-row").click(function() { |
|
67 | $(".clickable-row").click(function() { | |
68 | document.location = $(this).data("href"); |
|
68 | document.location = $(this).data("href"); | |
69 | }); |
|
69 | }); | |
70 |
|
70 | |||
71 | $("#bt_edit").click(function() { |
|
71 | $("#bt_edit").click(function() { | |
72 | document.location = "{% url 'url_edit_experiment' experiment.id%}"; |
|
72 | document.location = "{% url 'url_edit_experiment' experiment.id%}"; | |
73 | }); |
|
73 | }); | |
74 |
|
74 | |||
75 | $("#bt_add_conf").click(function() { |
|
75 | $("#bt_add_conf").click(function() { | |
76 | document.location = "{% url 'url_add_dev_conf' experiment.id%}"; |
|
76 | document.location = "{% url 'url_add_dev_conf' experiment.id %}"; | |
77 | }); |
|
77 | }); | |
78 |
|
78 | |||
79 | </script> |
|
79 | </script> | |
80 | {% endblock %} No newline at end of file |
|
80 | {% endblock %} |
@@ -1,38 +1,93 | |||||
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 | <form class="form" method="post" action=""> |
|
15 | <form class="form" method="post" action=""> | |
16 | {% csrf_token %} |
|
16 | {% csrf_token %} | |
17 | {% bootstrap_form form layout='horizontal' size='medium' %} |
|
17 | {% bootstrap_form form layout='horizontal' size='medium' %} | |
18 | <div style="clear: both;"></div> |
|
18 | <div style="clear: both;"></div> | |
19 | <br> |
|
19 | <br> | |
20 | <button type="submit" class="btn btn-primary pull-right">{{button}}</button> |
|
20 | {% if configurations %} | |
|
21 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> | |||
|
22 | <div class="panel panel-default"> | |||
|
23 | <div class="panel-heading" role="tab" id="headingTwo"> | |||
|
24 | <h4 class="panel-title"> | |||
|
25 | <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseThree"> | |||
|
26 | Device Configurations | |||
|
27 | </a> | |||
|
28 | </h4> | |||
|
29 | </div> | |||
|
30 | <div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> | |||
|
31 | <div class="panel-body"> | |||
|
32 | <table class="table table-hover"> | |||
|
33 | <tr> | |||
|
34 | <th>#</th> | |||
|
35 | {% for key in configuration_keys %} | |||
|
36 | <th>{{ key|title }}</th> | |||
|
37 | {% endfor%} | |||
|
38 | </tr> | |||
|
39 | {% for item in configurations %} | |||
|
40 | <tr class="clickable-row" data-href="{{item.get_absolute_url}}"> | |||
|
41 | <td>{{ forloop.counter }}</td> | |||
|
42 | {% for key in configuration_keys %} | |||
|
43 | <td>{{ item|value:key }}</td> | |||
|
44 | {% endfor %} | |||
|
45 | </tr> | |||
|
46 | {% endfor %} | |||
|
47 | </table> | |||
|
48 | </div> | |||
|
49 | </div> | |||
|
50 | </div> | |||
|
51 | </div> | |||
|
52 | {% endif %} | |||
|
53 | ||||
|
54 | {% if button %} | |||
|
55 | <br> | |||
|
56 | <button type="submit" class="btn btn-primary pull-right">{{button}}</button> | |||
|
57 | {% endif %} | |||
21 | </form> |
|
58 | </form> | |
22 | {% endblock %} |
|
59 | {% endblock %} | |
23 |
|
60 | |||
24 | {% block sidebar%} |
|
61 | {% block sidebar%} | |
25 | {% include "sidebar_devices.html" %} |
|
62 | {% include "sidebar_devices.html" %} | |
26 | {% endblock %} |
|
63 | {% endblock %} | |
27 |
|
64 | |||
28 | {% block extra-js%} |
|
65 | {% block extra-js%} | |
29 | <script src="{% static 'js/moment.min.js' %}"></script> |
|
66 | <script src="{% static 'js/moment.min.js' %}"></script> | |
30 | <script src="{% static 'js/bootstrap-datetimepicker.min.js' %}"></script> |
|
67 | <script src="{% static 'js/bootstrap-datetimepicker.min.js' %}"></script> | |
31 | <script type="text/javascript"> |
|
68 | <script type="text/javascript"> | |
|
69 | ||||
32 | $('.input-group.time').datetimepicker({ |
|
70 | $('.input-group.time').datetimepicker({ | |
33 | format: 'HH:mm:ss', |
|
71 | format: 'HH:mm:ss', | |
34 | pickDate: false, |
|
72 | pickDate: false, | |
35 | pickSeconds: true |
|
73 | pickSeconds: true | |
36 | }); |
|
74 | }); | |
|
75 | ||||
|
76 | $('#id_create_from').change(function() { | |||
|
77 | var url = "{% url 'url_add_experiment' %}"; | |||
|
78 | if ($(this).val()=="2"){ | |||
|
79 | document.location = url+"?template=0"; | |||
|
80 | }else if ($(this).val()=="1"){ | |||
|
81 | document.location = url+"?blank=0"; | |||
|
82 | }else{ | |||
|
83 | document.location = url; | |||
|
84 | } | |||
|
85 | }); | |||
|
86 | ||||
|
87 | $('#id_choose_template').change(function() { | |||
|
88 | var url = "{% url 'url_add_experiment' %}"; | |||
|
89 | document.location = url+"?template="+$(this).val(); | |||
|
90 | }); | |||
|
91 | ||||
37 | </script> |
|
92 | </script> | |
38 | {% endblock %} No newline at end of file |
|
93 | {% endblock %} |
@@ -1,50 +1,45 | |||||
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 | <table class="table table-hover"> |
|
15 | <table class="table table-hover"> | |
16 | <tr> |
|
16 | <tr> | |
17 | <th>#</th> |
|
17 | <th>#</th> | |
18 | {% for key in experiment_keys %} |
|
18 | {% for key in experiment_keys %} | |
19 | <th>{{ key|title }}</th> |
|
19 | <th>{{ key|title }}</th> | |
20 | {% endfor%} |
|
20 | {% endfor%} | |
21 | </tr> |
|
21 | </tr> | |
22 | {% for experiment in experiments %} |
|
22 | {% for experiment in experiments %} | |
23 | <tr class="clickable-row" data-href="{% url 'url_experiment' experiment.id %}"> |
|
23 | <tr class="clickable-row" data-href="{% url 'url_experiment' experiment.id %}"> | |
24 | <td>{{ forloop.counter }}</td> |
|
24 | <td>{{ forloop.counter }}</td> | |
25 | {% for key in experiment_keys %} |
|
25 | {% for key in experiment_keys %} | |
26 | <td>{{ experiment|attr:key }}</td> |
|
26 | <td>{{ experiment|attr:key }}</td> | |
27 | {% endfor %} |
|
27 | {% endfor %} | |
28 | </tr> |
|
28 | </tr> | |
29 | {% endfor %} |
|
29 | {% endfor %} | |
30 | </table> |
|
30 | </table> | |
31 | <button class="btn btn-primary pull-right" id="bt_add">{{button}}</button> |
|
|||
32 | {% endblock %} |
|
31 | {% endblock %} | |
33 |
|
32 | |||
34 | {% block sidebar%} |
|
33 | {% block sidebar%} | |
35 | {% include "sidebar_devices.html" %} |
|
34 | {% include "sidebar_devices.html" %} | |
36 | {% endblock %} |
|
35 | {% endblock %} | |
37 |
|
36 | |||
38 | {% block extra-js%} |
|
37 | {% block extra-js%} | |
39 | <script type="text/javascript"> |
|
38 | <script type="text/javascript"> | |
40 |
|
39 | |||
41 | $(".clickable-row").click(function() { |
|
40 | $(".clickable-row").click(function() { | |
42 | document.location = $(this).data("href"); |
|
41 | document.location = $(this).data("href"); | |
43 | }); |
|
42 | }); | |
44 |
|
43 | |||
45 | $("#bt_add").click(function() { |
|
|||
46 | document.location = "{% url 'url_add_experiment' 0 %}"; |
|
|||
47 | }); |
|
|||
48 |
|
||||
49 | </script> |
|
44 | </script> | |
50 | {% endblock %} No newline at end of file |
|
45 | {% endblock %} |
@@ -1,103 +1,37 | |||||
1 | {% if campaign %} |
|
|||
2 | <div class="panel panel-default"> |
|
|||
3 | <div class="panel-heading"> |
|
|||
4 | <h4>Campaign</h4> |
|
|||
5 | </div> |
|
|||
6 | <div class="list-group"> |
|
|||
7 | <a href="{% url 'url_campaign' campaign.id %}" class="list-group-item active" >{{ campaign.name }}</a> |
|
|||
8 | </div> |
|
|||
9 | </div> |
|
|||
10 |
|
||||
11 | {% if experiments %} |
|
|||
12 | <div class="panel panel-default"> |
|
|||
13 | <div class="panel-heading"> |
|
|||
14 | <h4>Experiments</h4> |
|
|||
15 | </div> |
|
|||
16 | <div class="list-group"> |
|
|||
17 | {% for item in experiments %} |
|
|||
18 | <a href="{% url 'url_experiment' item.id %}" class="list-group-item {{item.active}}">{{item.name}}</a> |
|
|||
19 | {% endfor %} |
|
|||
20 | </div> |
|
|||
21 | </div> |
|
|||
22 | {% endif %} |
|
|||
23 | {% endif %} |
|
|||
24 |
|
||||
25 | {% if experiment %} |
|
|||
26 | <div class="panel panel-default"> |
|
|||
27 | <div class="panel-heading"> |
|
|||
28 | <h4>Campaign</h4> |
|
|||
29 | </div> |
|
|||
30 | <div class="list-group"> |
|
|||
31 | <a href="{% url 'url_campaign' experiment.campaign.id %}" class="list-group-item active" >{{ experiment.campaign.name }}</a> |
|
|||
32 | </div> |
|
|||
33 | </div> |
|
|||
34 |
|
||||
35 | {% if experiments %} |
|
|||
36 | <div class="panel panel-default"> |
|
|||
37 | <div class="panel-heading"> |
|
|||
38 | <h4>Experiments</h4> |
|
|||
39 | </div> |
|
|||
40 | <div class="list-group"> |
|
|||
41 | {% for item in experiments %} |
|
|||
42 | <a href="{% url 'url_experiment' item.id %}" class="list-group-item {%if item.id == experiment.id%}active{%endif%}">{{item.name}}</a> |
|
|||
43 | {% endfor %} |
|
|||
44 | </div> |
|
|||
45 | </div> |
|
|||
46 | {% endif %} |
|
|||
47 |
|
||||
48 | {% if configurations %} |
|
|||
49 | <div class="panel panel-default"> |
|
|||
50 | <div class="panel-heading"> |
|
|||
51 | <h4>Device Configurations</h4> |
|
|||
52 | </div> |
|
|||
53 | <div class="list-group"> |
|
|||
54 | {% for item in configurations %} |
|
|||
55 | <a href="{{item.get_absolute_url}}" class="list-group-item {{item.active}}">{{item.device.name}}</a> |
|
|||
56 | {% endfor %} |
|
|||
57 | </div> |
|
|||
58 | </div> |
|
|||
59 | {% endif %} |
|
|||
60 |
|
||||
61 | {% endif %} |
|
|||
62 |
|
||||
63 | {% if dev_conf %} |
|
|||
64 |
|
1 | |||
65 | {% if campaign %} |
|
2 | {% if campaign %} | |
66 | <div class="panel panel-default"> |
|
3 | <div class="panel panel-default"> | |
67 | <div class="panel-heading"> |
|
4 | <div class="panel-heading"> | |
68 | <h4>Campaign</h4> |
|
5 | <h4>Campaign</h4> | |
69 | </div> |
|
6 | </div> | |
70 | <div class="list-group"> |
|
7 | <div class="list-group"> | |
71 |
<a href="{% url 'url_campaign' |
|
8 | <a href="{% url 'url_campaign' campaign.id %}" class="list-group-item active" >{{ campaign.name }}</a> | |
72 | </div> |
|
9 | </div> | |
73 | </div> |
|
10 | </div> | |
74 | {% endif %} |
|
11 | {% endif %} | |
75 |
|
12 | |||
76 |
{% if experiment |
|
13 | {% if experiment %} | |
77 | <div class="panel panel-default"> |
|
14 | <div class="panel panel-default"> | |
78 | <div class="panel-heading"> |
|
15 | <div class="panel-heading"> | |
79 | <h4>Experiments</h4> |
|
16 | <h4>Experiments</h4> | |
80 | </div> |
|
17 | </div> | |
81 | <div class="list-group"> |
|
18 | <div class="list-group"> | |
82 | {% for item in experiments %} |
|
19 | {% for item in side_experiments %} | |
83 |
<a href="{% url 'url_experiment' item.id %}" class="list-group-item {%if item.id == |
|
20 | <a href="{% url 'url_experiment' item.id %}" class="list-group-item {%if item.id == experiment.id%}active{%endif%}">{{item.name}}</a> | |
84 | {% endfor %} |
|
21 | {% endfor %} | |
85 | </div> |
|
22 | </div> | |
86 | </div> |
|
23 | </div> | |
87 | {% endif %} |
|
24 | {% endif %} | |
88 |
|
25 | |||
89 |
{% if conf |
|
26 | {% if dev_conf %} | |
90 | <div class="panel panel-default"> |
|
27 | <div class="panel panel-default"> | |
91 | <div class="panel-heading"> |
|
28 | <div class="panel-heading"> | |
92 | <h4>Device Configurations</h4> |
|
29 | <h4>Device Configurations</h4> | |
93 | </div> |
|
30 | </div> | |
94 | <div class="list-group"> |
|
31 | <div class="list-group"> | |
95 | {% for item in configurations %} |
|
32 | {% for item in side_configurations %} | |
96 | <a href="{{item.get_absolute_url}}" class="list-group-item {%if item.id == dev_conf.id%}active{%endif%}">{{item.device.name}}</a> |
|
33 | <a href="{{item.get_absolute_url}}" class="list-group-item {%if item.id == dev_conf.id%}active{%endif%}">{{item.device.name}}</a> | |
97 | {% endfor %} |
|
34 | {% endfor %} | |
98 | </div> |
|
35 | </div> | |
99 | </div> |
|
36 | </div> | |
100 | {% endif %} |
|
37 | {% endif %} | |
101 |
|
||||
102 |
|
||||
103 | {% endif %} |
|
@@ -1,37 +1,36 | |||||
1 | from django.template.defaulttags import register |
|
1 | from django.template.defaulttags import register | |
2 | from django.utils.safestring import mark_safe |
|
2 | from django.utils.safestring import mark_safe | |
3 |
|
3 | |||
4 | @register.filter |
|
4 | @register.filter | |
5 | def attr(instance, key): |
|
5 | def attr(instance, key): | |
6 |
|
6 | |||
7 | display_key = "get_" + key + "_display" |
|
7 | display_key = "get_" + key + "_display" | |
8 |
|
8 | |||
9 | if hasattr(instance, display_key): |
|
9 | if hasattr(instance, display_key): | |
10 | return getattr(instance, display_key)() |
|
10 | return getattr(instance, display_key)() | |
11 |
|
11 | |||
12 | if hasattr(instance, key): |
|
12 | if hasattr(instance, key): | |
13 | return getattr(instance, key) |
|
13 | return getattr(instance, key) | |
14 |
|
14 | |||
15 | return instance.get(key) |
|
15 | return instance.get(key) | |
16 |
|
16 | |||
17 | @register.filter |
|
17 | @register.filter | |
18 | def title(s): |
|
18 | def title(s): | |
19 | return s.replace('_', ' ').title() |
|
19 | return s.replace('_', ' ').title() | |
20 |
|
20 | |||
21 | @register.filter |
|
21 | @register.filter | |
22 | def value(instance, key): |
|
22 | def value(instance, key): | |
23 |
|
23 | |||
24 | item = instance |
|
24 | item = instance | |
25 | for my_key in key.split("__"): |
|
25 | for my_key in key.split("__"): | |
26 | item = attr(item, my_key) |
|
26 | item = attr(item, my_key) | |
27 |
|
27 | |||
28 | print item |
|
|||
29 | return item |
|
28 | return item | |
30 |
|
29 | |||
31 | @register.simple_tag |
|
30 | @register.simple_tag | |
32 | def get_verbose_field_name(instance, field_name): |
|
31 | def get_verbose_field_name(instance, field_name): | |
33 | """ |
|
32 | """ | |
34 | Returns verbose_name for a field. |
|
33 | Returns verbose_name for a field. | |
35 | """ |
|
34 | """ | |
36 |
|
35 | |||
37 | return mark_safe(instance._meta.get_field(field_name).verbose_name) No newline at end of file |
|
36 | return mark_safe(instance._meta.get_field(field_name).verbose_name) |
@@ -1,50 +1,50 | |||||
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 |
|
21 | |||
22 |
url(r'^ |
|
22 | url(r'^experiment/new/$', 'apps.main.views.experiment_new', name='url_add_experiment'), | |
23 | url(r'^experiment/$', 'apps.main.views.experiments', name='url_experiments'), |
|
23 | url(r'^experiment/$', 'apps.main.views.experiments', name='url_experiments'), | |
24 | url(r'^experiment/(?P<id_exp>-?\d+)/$', 'apps.main.views.experiment', name='url_experiment'), |
|
24 | url(r'^experiment/(?P<id_exp>-?\d+)/$', 'apps.main.views.experiment', name='url_experiment'), | |
25 | url(r'^experiment/(?P<id_exp>-?\d+)/edit/$', 'apps.main.views.experiment_edit', name='url_edit_experiment'), |
|
25 | url(r'^experiment/(?P<id_exp>-?\d+)/edit/$', 'apps.main.views.experiment_edit', name='url_edit_experiment'), | |
26 | url(r'^experiment/(?P<id_exp>-?\d+)/delete/$', 'apps.main.views.experiment_delete', name='url_delete_experiment'), |
|
26 | url(r'^experiment/(?P<id_exp>-?\d+)/delete/$', 'apps.main.views.experiment_delete', name='url_delete_experiment'), | |
27 |
|
27 | |||
28 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), |
|
28 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), | |
29 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/(?P<id_dev>-?\d+)/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), |
|
29 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/(?P<id_dev>-?\d+)/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), | |
30 | url(r'^dev_conf/$', 'apps.main.views.dev_confs', name='url_dev_confs'), |
|
30 | url(r'^dev_conf/$', 'apps.main.views.dev_confs', name='url_dev_confs'), | |
31 | url(r'^dev_conf/(?P<id_conf>-?\d+)/$', 'apps.main.views.dev_conf', name='url_dev_conf'), |
|
31 | url(r'^dev_conf/(?P<id_conf>-?\d+)/$', 'apps.main.views.dev_conf', name='url_dev_conf'), | |
32 | url(r'^dev_conf/(?P<id_conf>-?\d+)/edit/$', 'apps.main.views.dev_conf_edit', name='url_edit_dev_conf'), |
|
32 | url(r'^dev_conf/(?P<id_conf>-?\d+)/edit/$', 'apps.main.views.dev_conf_edit', name='url_edit_dev_conf'), | |
33 | url(r'^dev_conf/(?P<id_conf>-?\d+)/delete/$', 'apps.main.views.dev_conf_delete', name='url_delete_dev_conf'), |
|
33 | url(r'^dev_conf/(?P<id_conf>-?\d+)/delete/$', 'apps.main.views.dev_conf_delete', name='url_delete_dev_conf'), | |
34 |
|
34 | |||
35 | url(r'^dev_conf/(?P<id_conf>-?\d+)/write/$', 'apps.main.views.dev_conf_write', name='url_write_dev_conf'), |
|
35 | url(r'^dev_conf/(?P<id_conf>-?\d+)/write/$', 'apps.main.views.dev_conf_write', name='url_write_dev_conf'), | |
36 | url(r'^dev_conf/(?P<id_conf>-?\d+)/read/$', 'apps.main.views.dev_conf_read', name='url_read_dev_conf'), |
|
36 | url(r'^dev_conf/(?P<id_conf>-?\d+)/read/$', 'apps.main.views.dev_conf_read', name='url_read_dev_conf'), | |
37 | url(r'^dev_conf/(?P<id_conf>-?\d+)/import/$', 'apps.main.views.dev_conf_import', name='url_import_dev_conf'), |
|
37 | url(r'^dev_conf/(?P<id_conf>-?\d+)/import/$', 'apps.main.views.dev_conf_import', name='url_import_dev_conf'), | |
38 | url(r'^dev_conf/(?P<id_conf>-?\d+)/export/$', 'apps.main.views.dev_conf_export', name='url_export_dev_conf'), |
|
38 | url(r'^dev_conf/(?P<id_conf>-?\d+)/export/$', 'apps.main.views.dev_conf_export', name='url_export_dev_conf'), | |
39 | url(r'^dev_conf/(?P<id_conf>-?\d+)/start/$', 'apps.main.views.dev_conf_start', name='url_start_dev_conf'), |
|
39 | url(r'^dev_conf/(?P<id_conf>-?\d+)/start/$', 'apps.main.views.dev_conf_start', name='url_start_dev_conf'), | |
40 | url(r'^dev_conf/(?P<id_conf>-?\d+)/stop/$', 'apps.main.views.dev_conf_stop', name='url_stop_dev_conf'), |
|
40 | url(r'^dev_conf/(?P<id_conf>-?\d+)/stop/$', 'apps.main.views.dev_conf_stop', name='url_stop_dev_conf'), | |
41 | url(r'^dev_conf/(?P<id_conf>-?\d+)/status/$', 'apps.main.views.dev_conf_status', name='url_status_dev_conf'), |
|
41 | url(r'^dev_conf/(?P<id_conf>-?\d+)/status/$', 'apps.main.views.dev_conf_status', name='url_status_dev_conf'), | |
42 |
|
42 | |||
43 | url(r'^operation/$', 'apps.main.views.operation', name='url_operation'), |
|
43 | url(r'^operation/$', 'apps.main.views.operation', name='url_operation'), | |
44 | url(r'^operation/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation', name='url_operation'), |
|
44 | url(r'^operation/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation', name='url_operation'), | |
45 | url(r'^operation/search/$', 'apps.main.views.operation_search', name='url_operation_search'), |
|
45 | url(r'^operation/search/$', 'apps.main.views.operation_search', name='url_operation_search'), | |
46 | url(r'^operation/search/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation_search', name='url_operation_search'), |
|
46 | url(r'^operation/search/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation_search', name='url_operation_search'), | |
47 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/play/$', 'apps.main.views.radar_play', name='url_radar_play'), |
|
47 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/play/$', 'apps.main.views.radar_play', name='url_radar_play'), | |
48 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/stop/$', 'apps.main.views.radar_stop', name='url_radar_stop'), |
|
48 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/stop/$', 'apps.main.views.radar_stop', name='url_radar_stop'), | |
49 |
|
49 | |||
50 | ) |
|
50 | ) |
@@ -1,906 +1,961 | |||||
1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse |
|
1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse | |
2 | from django.http import HttpResponseRedirect |
|
2 | from django.http import HttpResponseRedirect | |
3 | from django.core.urlresolvers import reverse |
|
3 | from django.core.urlresolvers import reverse | |
4 | from django.contrib import messages |
|
4 | from django.contrib import messages | |
5 |
|
5 | |||
6 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm |
|
6 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm, NewForm | |
7 | from .forms import OperationSearchForm |
|
7 | from .forms import OperationSearchForm | |
8 | from apps.cgs.forms import CGSConfigurationForm |
|
8 | from apps.cgs.forms import CGSConfigurationForm | |
9 | from apps.jars.forms import JARSConfigurationForm |
|
9 | from apps.jars.forms import JARSConfigurationForm | |
10 | from apps.usrp.forms import USRPConfigurationForm |
|
10 | from apps.usrp.forms import USRPConfigurationForm | |
11 | from apps.abs.forms import ABSConfigurationForm |
|
11 | from apps.abs.forms import ABSConfigurationForm | |
12 | from apps.rc.forms import RCConfigurationForm |
|
12 | from apps.rc.forms import RCConfigurationForm | |
13 | from apps.dds.forms import DDSConfigurationForm |
|
13 | from apps.dds.forms import DDSConfigurationForm | |
14 |
|
14 | |||
15 | from .models import Campaign, Experiment, Device, Configuration, Location, RunningExperiment |
|
15 | from .models import Campaign, Experiment, Device, Configuration, Location, RunningExperiment | |
16 | from apps.cgs.models import CGSConfiguration |
|
16 | from apps.cgs.models import CGSConfiguration | |
17 | from apps.jars.models import JARSConfiguration |
|
17 | from apps.jars.models import JARSConfiguration | |
18 | from apps.usrp.models import USRPConfiguration |
|
18 | from apps.usrp.models import USRPConfiguration | |
19 | from apps.abs.models import ABSConfiguration |
|
19 | from apps.abs.models import ABSConfiguration | |
20 | from apps.rc.models import RCConfiguration |
|
20 | from apps.rc.models import RCConfiguration | |
21 | from apps.dds.models import DDSConfiguration |
|
21 | from apps.dds.models import DDSConfiguration | |
22 |
|
22 | |||
23 | # Create your views here. |
|
23 | # Create your views here. | |
24 |
|
24 | |||
25 | CONF_FORMS = { |
|
25 | CONF_FORMS = { | |
26 | 'rc': RCConfigurationForm, |
|
26 | 'rc': RCConfigurationForm, | |
27 | 'dds': DDSConfigurationForm, |
|
27 | 'dds': DDSConfigurationForm, | |
28 | 'jars': JARSConfigurationForm, |
|
28 | 'jars': JARSConfigurationForm, | |
29 | 'cgs': CGSConfigurationForm, |
|
29 | 'cgs': CGSConfigurationForm, | |
30 | 'abs': ABSConfigurationForm, |
|
30 | 'abs': ABSConfigurationForm, | |
31 | 'usrp': USRPConfigurationForm, |
|
31 | 'usrp': USRPConfigurationForm, | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | CONF_MODELS = { |
|
34 | CONF_MODELS = { | |
35 | 'rc': RCConfiguration, |
|
35 | 'rc': RCConfiguration, | |
36 | 'dds': DDSConfiguration, |
|
36 | 'dds': DDSConfiguration, | |
37 | 'jars': JARSConfiguration, |
|
37 | 'jars': JARSConfiguration, | |
38 | 'cgs': CGSConfiguration, |
|
38 | 'cgs': CGSConfiguration, | |
39 | 'abs': ABSConfiguration, |
|
39 | 'abs': ABSConfiguration, | |
40 | 'usrp': USRPConfiguration, |
|
40 | 'usrp': USRPConfiguration, | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | def index(request): |
|
43 | def index(request): | |
44 | kwargs = {} |
|
44 | kwargs = {} | |
45 |
|
45 | |||
46 | return render(request, 'index.html', kwargs) |
|
46 | return render(request, 'index.html', kwargs) | |
47 |
|
47 | |||
48 | def locations(request): |
|
48 | def locations(request): | |
49 |
|
49 | |||
50 | locations = Location.objects.all().order_by('name') |
|
50 | locations = Location.objects.all().order_by('name') | |
51 |
|
51 | |||
52 | keys = ['id', 'name', 'description'] |
|
52 | keys = ['id', 'name', 'description'] | |
53 |
|
53 | |||
54 | kwargs = {} |
|
54 | kwargs = {} | |
55 | kwargs['location_keys'] = keys[1:] |
|
55 | kwargs['location_keys'] = keys[1:] | |
56 | kwargs['locations'] = locations |
|
56 | kwargs['locations'] = locations | |
57 | kwargs['title'] = 'Location' |
|
57 | kwargs['title'] = 'Location' | |
58 | kwargs['suptitle'] = 'List' |
|
58 | kwargs['suptitle'] = 'List' | |
59 | kwargs['button'] = 'New Location' |
|
59 | kwargs['button'] = 'New Location' | |
60 |
|
60 | |||
61 | return render(request, 'locations.html', kwargs) |
|
61 | return render(request, 'locations.html', kwargs) | |
62 |
|
62 | |||
63 | def location(request, id_loc): |
|
63 | def location(request, id_loc): | |
64 |
|
64 | |||
65 | location = get_object_or_404(Location, pk=id_loc) |
|
65 | location = get_object_or_404(Location, pk=id_loc) | |
66 |
|
66 | |||
67 | kwargs = {} |
|
67 | kwargs = {} | |
68 | kwargs['location'] = location |
|
68 | kwargs['location'] = location | |
69 | kwargs['location_keys'] = ['name', 'description'] |
|
69 | kwargs['location_keys'] = ['name', 'description'] | |
70 |
|
70 | |||
71 | kwargs['title'] = 'Location' |
|
71 | kwargs['title'] = 'Location' | |
72 | kwargs['suptitle'] = 'Details' |
|
72 | kwargs['suptitle'] = 'Details' | |
73 |
|
73 | |||
74 | return render(request, 'location.html', kwargs) |
|
74 | return render(request, 'location.html', kwargs) | |
75 |
|
75 | |||
76 | #def location_play(request, id_camp, id_loc): |
|
76 | #def location_play(request, id_camp, id_loc): | |
77 |
|
77 | |||
78 | # campaign = get_object_or_404(Campaign, pk=id_camp) |
|
78 | # campaign = get_object_or_404(Campaign, pk=id_camp) | |
79 | # print campaign |
|
79 | # print campaign | |
80 | # location = get_object_or_404(Location, pk=id_loc) |
|
80 | # location = get_object_or_404(Location, pk=id_loc) | |
81 | # experiments = Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) |
|
81 | # experiments = Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) | |
82 | # locations = Location.objects.filter(pk=id_loc) |
|
82 | # locations = Location.objects.filter(pk=id_loc) | |
83 |
|
83 | |||
84 | # if request.method=='GET': |
|
84 | # if request.method=='GET': | |
85 | # form = OperationForm(initial={'campaign': campaign.id}) |
|
85 | # form = OperationForm(initial={'campaign': campaign.id}) | |
86 |
|
86 | |||
87 | # kwargs = {} |
|
87 | # kwargs = {} | |
88 | #---Campaign |
|
88 | #---Campaign | |
89 | # kwargs['campaign'] = campaign |
|
89 | # kwargs['campaign'] = campaign | |
90 | # kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
90 | # kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
91 | #---Experiment |
|
91 | #---Experiment | |
92 | # keys = ['id', 'name', 'start_time', 'end_time'] |
|
92 | # keys = ['id', 'name', 'start_time', 'end_time'] | |
93 | # kwargs['experiment_keys'] = keys[1:] |
|
93 | # kwargs['experiment_keys'] = keys[1:] | |
94 | # kwargs['experiments'] = experiments |
|
94 | # kwargs['experiments'] = experiments | |
95 | #---Radar |
|
95 | #---Radar | |
96 | # kwargs['location'] = location |
|
96 | # kwargs['location'] = location | |
97 | #---Else |
|
97 | #---Else | |
98 | # kwargs['title'] = 'Campaign' |
|
98 | # kwargs['title'] = 'Campaign' | |
99 | # kwargs['suptitle'] = campaign.name |
|
99 | # kwargs['suptitle'] = campaign.name | |
100 | # kwargs['form'] = form |
|
100 | # kwargs['form'] = form | |
101 | # kwargs['button'] = 'Search' |
|
101 | # kwargs['button'] = 'Search' | |
102 |
|
102 | |||
103 | # return render(request, 'operation_play.html', kwargs) |
|
103 | # return render(request, 'operation_play.html', kwargs) | |
104 |
|
104 | |||
105 | def location_new(request): |
|
105 | def location_new(request): | |
106 |
|
106 | |||
107 | if request.method == 'GET': |
|
107 | if request.method == 'GET': | |
108 | form = LocationForm() |
|
108 | form = LocationForm() | |
109 |
|
109 | |||
110 | if request.method == 'POST': |
|
110 | if request.method == 'POST': | |
111 | form = LocationForm(request.POST) |
|
111 | form = LocationForm(request.POST) | |
112 |
|
112 | |||
113 | if form.is_valid(): |
|
113 | if form.is_valid(): | |
114 | form.save() |
|
114 | form.save() | |
115 | return redirect('url_locations') |
|
115 | return redirect('url_locations') | |
116 |
|
116 | |||
117 | kwargs = {} |
|
117 | kwargs = {} | |
118 | kwargs['form'] = form |
|
118 | kwargs['form'] = form | |
119 | kwargs['title'] = 'Location' |
|
119 | kwargs['title'] = 'Location' | |
120 | kwargs['suptitle'] = 'New' |
|
120 | kwargs['suptitle'] = 'New' | |
121 | kwargs['button'] = 'Create' |
|
121 | kwargs['button'] = 'Create' | |
122 |
|
122 | |||
123 | return render(request, 'location_edit.html', kwargs) |
|
123 | return render(request, 'location_edit.html', kwargs) | |
124 |
|
124 | |||
125 | def location_edit(request, id_loc): |
|
125 | def location_edit(request, id_loc): | |
126 |
|
126 | |||
127 | location = get_object_or_404(Location, pk=id_loc) |
|
127 | location = get_object_or_404(Location, pk=id_loc) | |
128 |
|
128 | |||
129 | if request.method=='GET': |
|
129 | if request.method=='GET': | |
130 | form = LocationForm(instance=location) |
|
130 | form = LocationForm(instance=location) | |
131 |
|
131 | |||
132 | if request.method=='POST': |
|
132 | if request.method=='POST': | |
133 | form = LocationForm(request.POST, instance=location) |
|
133 | form = LocationForm(request.POST, instance=location) | |
134 |
|
134 | |||
135 | if form.is_valid(): |
|
135 | if form.is_valid(): | |
136 | form.save() |
|
136 | form.save() | |
137 | return redirect('url_locations') |
|
137 | return redirect('url_locations') | |
138 |
|
138 | |||
139 | kwargs = {} |
|
139 | kwargs = {} | |
140 | kwargs['form'] = form |
|
140 | kwargs['form'] = form | |
141 | kwargs['title'] = 'Location' |
|
141 | kwargs['title'] = 'Location' | |
142 | kwargs['suptitle'] = 'Edit' |
|
142 | kwargs['suptitle'] = 'Edit' | |
143 | kwargs['button'] = 'Update' |
|
143 | kwargs['button'] = 'Update' | |
144 |
|
144 | |||
145 | return render(request, 'location_edit.html', kwargs) |
|
145 | return render(request, 'location_edit.html', kwargs) | |
146 |
|
146 | |||
147 | def location_delete(request, id_loc): |
|
147 | def location_delete(request, id_loc): | |
148 |
|
148 | |||
149 | location = get_object_or_404(Location, pk=id_loc) |
|
149 | location = get_object_or_404(Location, pk=id_loc) | |
150 |
|
150 | |||
151 | if request.method=='POST': |
|
151 | if request.method=='POST': | |
152 |
|
152 | |||
153 | if request.user.is_staff: |
|
153 | if request.user.is_staff: | |
154 | location.delete() |
|
154 | location.delete() | |
155 | return redirect('url_locations') |
|
155 | return redirect('url_locations') | |
156 |
|
156 | |||
157 | return HttpResponse("Not enough permission to delete this object") |
|
157 | return HttpResponse("Not enough permission to delete this object") | |
158 |
|
158 | |||
159 | kwargs = {'object':location, 'loc_active':'active', |
|
159 | kwargs = {'object':location, 'loc_active':'active', | |
160 | 'url_cancel':'url_location', 'id_item':id_loc} |
|
160 | 'url_cancel':'url_location', 'id_item':id_loc} | |
161 |
|
161 | |||
162 | return render(request, 'item_delete.html', kwargs) |
|
162 | return render(request, 'item_delete.html', kwargs) | |
163 |
|
163 | |||
164 | def devices(request): |
|
164 | def devices(request): | |
165 |
|
165 | |||
166 | devices = Device.objects.all().order_by('device_type__name') |
|
166 | devices = Device.objects.all().order_by('device_type__name') | |
167 |
|
167 | |||
168 | # keys = ['id', 'device_type__name', 'name', 'ip_address'] |
|
168 | # keys = ['id', 'device_type__name', 'name', 'ip_address'] | |
169 | keys = ['id', 'name', 'ip_address', 'port_address', 'device_type'] |
|
169 | keys = ['id', 'name', 'ip_address', 'port_address', 'device_type'] | |
170 |
|
170 | |||
171 | kwargs = {} |
|
171 | kwargs = {} | |
172 | kwargs['device_keys'] = keys[1:] |
|
172 | kwargs['device_keys'] = keys[1:] | |
173 | kwargs['devices'] = devices#.values(*keys) |
|
173 | kwargs['devices'] = devices#.values(*keys) | |
174 | kwargs['title'] = 'Device' |
|
174 | kwargs['title'] = 'Device' | |
175 | kwargs['suptitle'] = 'List' |
|
175 | kwargs['suptitle'] = 'List' | |
176 | kwargs['button'] = 'New Device' |
|
176 | kwargs['button'] = 'New Device' | |
177 |
|
177 | |||
178 | return render(request, 'devices.html', kwargs) |
|
178 | return render(request, 'devices.html', kwargs) | |
179 |
|
179 | |||
180 | def device(request, id_dev): |
|
180 | def device(request, id_dev): | |
181 |
|
181 | |||
182 | device = get_object_or_404(Device, pk=id_dev) |
|
182 | device = get_object_or_404(Device, pk=id_dev) | |
183 |
|
183 | |||
184 | kwargs = {} |
|
184 | kwargs = {} | |
185 | kwargs['device'] = device |
|
185 | kwargs['device'] = device | |
186 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] |
|
186 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] | |
187 |
|
187 | |||
188 | kwargs['title'] = 'Device' |
|
188 | kwargs['title'] = 'Device' | |
189 | kwargs['suptitle'] = 'Details' |
|
189 | kwargs['suptitle'] = 'Details' | |
190 |
|
190 | |||
191 | return render(request, 'device.html', kwargs) |
|
191 | return render(request, 'device.html', kwargs) | |
192 |
|
192 | |||
193 | def device_new(request): |
|
193 | def device_new(request): | |
194 |
|
194 | |||
195 | if request.method == 'GET': |
|
195 | if request.method == 'GET': | |
196 | form = DeviceForm() |
|
196 | form = DeviceForm() | |
197 |
|
197 | |||
198 | if request.method == 'POST': |
|
198 | if request.method == 'POST': | |
199 | form = DeviceForm(request.POST) |
|
199 | form = DeviceForm(request.POST) | |
200 |
|
200 | |||
201 | if form.is_valid(): |
|
201 | if form.is_valid(): | |
202 | form.save() |
|
202 | form.save() | |
203 | return redirect('url_devices') |
|
203 | return redirect('url_devices') | |
204 |
|
204 | |||
205 | kwargs = {} |
|
205 | kwargs = {} | |
206 | kwargs['form'] = form |
|
206 | kwargs['form'] = form | |
207 | kwargs['title'] = 'Device' |
|
207 | kwargs['title'] = 'Device' | |
208 | kwargs['suptitle'] = 'New' |
|
208 | kwargs['suptitle'] = 'New' | |
209 | kwargs['button'] = 'Create' |
|
209 | kwargs['button'] = 'Create' | |
210 |
|
210 | |||
211 | return render(request, 'device_edit.html', kwargs) |
|
211 | return render(request, 'device_edit.html', kwargs) | |
212 |
|
212 | |||
213 | def device_edit(request, id_dev): |
|
213 | def device_edit(request, id_dev): | |
214 |
|
214 | |||
215 | device = get_object_or_404(Device, pk=id_dev) |
|
215 | device = get_object_or_404(Device, pk=id_dev) | |
216 |
|
216 | |||
217 | if request.method=='GET': |
|
217 | if request.method=='GET': | |
218 | form = DeviceForm(instance=device) |
|
218 | form = DeviceForm(instance=device) | |
219 |
|
219 | |||
220 | if request.method=='POST': |
|
220 | if request.method=='POST': | |
221 | form = DeviceForm(request.POST, instance=device) |
|
221 | form = DeviceForm(request.POST, instance=device) | |
222 |
|
222 | |||
223 | if form.is_valid(): |
|
223 | if form.is_valid(): | |
224 | form.save() |
|
224 | form.save() | |
225 | return redirect('url_devices') |
|
225 | return redirect('url_devices') | |
226 |
|
226 | |||
227 | kwargs = {} |
|
227 | kwargs = {} | |
228 | kwargs['form'] = form |
|
228 | kwargs['form'] = form | |
229 | kwargs['title'] = 'Device' |
|
229 | kwargs['title'] = 'Device' | |
230 | kwargs['suptitle'] = 'Edit' |
|
230 | kwargs['suptitle'] = 'Edit' | |
231 | kwargs['button'] = 'Update' |
|
231 | kwargs['button'] = 'Update' | |
232 |
|
232 | |||
233 | return render(request, 'device_edit.html', kwargs) |
|
233 | return render(request, 'device_edit.html', kwargs) | |
234 |
|
234 | |||
235 | def device_delete(request, id_dev): |
|
235 | def device_delete(request, id_dev): | |
236 |
|
236 | |||
237 | device = get_object_or_404(Device, pk=id_dev) |
|
237 | device = get_object_or_404(Device, pk=id_dev) | |
238 |
|
238 | |||
239 | if request.method=='POST': |
|
239 | if request.method=='POST': | |
240 |
|
240 | |||
241 | if request.user.is_staff: |
|
241 | if request.user.is_staff: | |
242 | device.delete() |
|
242 | device.delete() | |
243 | return redirect('url_devices') |
|
243 | return redirect('url_devices') | |
244 |
|
244 | |||
245 | return HttpResponse("Not enough permission to delete this object") |
|
245 | return HttpResponse("Not enough permission to delete this object") | |
246 |
|
246 | |||
247 | kwargs = {'object':device, 'dev_active':'active', |
|
247 | kwargs = {'object':device, 'dev_active':'active', | |
248 | 'url_cancel':'url_device', 'id_item':id_dev} |
|
248 | 'url_cancel':'url_device', 'id_item':id_dev} | |
249 |
|
249 | |||
250 | return render(request, 'item_delete.html', kwargs) |
|
250 | return render(request, 'item_delete.html', kwargs) | |
251 |
|
251 | |||
252 | def campaigns(request): |
|
252 | def campaigns(request): | |
253 |
|
253 | |||
254 | campaigns = Campaign.objects.all().order_by('start_date') |
|
254 | campaigns = Campaign.objects.all().order_by('start_date') | |
255 |
|
255 | |||
256 | keys = ['id', 'name', 'start_date', 'end_date'] |
|
256 | keys = ['id', 'name', 'start_date', 'end_date'] | |
257 |
|
257 | |||
258 | kwargs = {} |
|
258 | kwargs = {} | |
259 | kwargs['campaign_keys'] = keys[1:] |
|
259 | kwargs['campaign_keys'] = keys[1:] | |
260 | kwargs['campaigns'] = campaigns#.values(*keys) |
|
260 | kwargs['campaigns'] = campaigns#.values(*keys) | |
261 | kwargs['title'] = 'Campaign' |
|
261 | kwargs['title'] = 'Campaign' | |
262 | kwargs['suptitle'] = 'List' |
|
262 | kwargs['suptitle'] = 'List' | |
263 | kwargs['button'] = 'New Campaign' |
|
263 | kwargs['button'] = 'New Campaign' | |
264 |
|
264 | |||
265 | return render(request, 'campaigns.html', kwargs) |
|
265 | return render(request, 'campaigns.html', kwargs) | |
266 |
|
266 | |||
267 | def campaign(request, id_camp): |
|
267 | def campaign(request, id_camp): | |
268 |
|
268 | |||
269 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
269 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
270 | experiments = Experiment.objects.filter(campaign=campaign) |
|
270 | experiments = Experiment.objects.filter(campaign=campaign) | |
271 |
|
271 | |||
272 | form = CampaignForm(instance=campaign) |
|
272 | form = CampaignForm(instance=campaign) | |
273 |
|
273 | |||
274 | kwargs = {} |
|
274 | kwargs = {} | |
275 | kwargs['campaign'] = campaign |
|
275 | kwargs['campaign'] = campaign | |
276 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
276 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
277 |
|
277 | |||
278 | keys = ['id', 'name', 'start_time', 'end_time'] |
|
278 | keys = ['id', 'name', 'start_time', 'end_time'] | |
279 |
|
279 | |||
280 | kwargs['experiment_keys'] = keys[1:] |
|
280 | kwargs['experiment_keys'] = keys[1:] | |
281 | kwargs['experiments'] = experiments.values(*keys) |
|
281 | kwargs['experiments'] = experiments.values(*keys) | |
282 |
|
282 | |||
283 | kwargs['title'] = 'Campaign' |
|
283 | kwargs['title'] = 'Campaign' | |
284 | kwargs['suptitle'] = 'Details' |
|
284 | kwargs['suptitle'] = 'Details' | |
285 |
|
285 | |||
286 | kwargs['form'] = form |
|
286 | kwargs['form'] = form | |
287 | kwargs['button'] = 'Add Experiment' |
|
287 | kwargs['button'] = 'Add Experiment' | |
288 |
|
288 | |||
289 | return render(request, 'campaign.html', kwargs) |
|
289 | return render(request, 'campaign.html', kwargs) | |
290 |
|
290 | |||
291 | def campaign_new(request): |
|
291 | def campaign_new(request): | |
292 |
|
292 | |||
|
293 | kwargs = {} | |||
|
294 | ||||
293 | if request.method == 'GET': |
|
295 | if request.method == 'GET': | |
294 | form = CampaignForm() |
|
296 | ||
|
297 | if 'template' in request.GET: | |||
|
298 | if request.GET['template']=='0': | |||
|
299 | form = NewForm(initial={'create_from':2}, | |||
|
300 | template_choices=Campaign.objects.filter(template=True).values_list('id', 'name')) | |||
|
301 | else: | |||
|
302 | kwargs['button'] = 'Create' | |||
|
303 | kwargs['experiments'] = Configuration.objects.filter(experiment=request.GET['template']) | |||
|
304 | kwargs['experiment_keys'] = ['name', 'start_time', 'end_time'] | |||
|
305 | form = CampaignForm(instance=Campaign.objects.get(pk=request.GET['template']), | |||
|
306 | initial={'template':False}) | |||
|
307 | elif 'blank' in request.GET: | |||
|
308 | kwargs['button'] = 'Create' | |||
|
309 | form = CampaignForm() | |||
|
310 | else: | |||
|
311 | form = NewForm() | |||
295 |
|
312 | |||
296 | if request.method == 'POST': |
|
313 | if request.method == 'POST': | |
297 | form = CampaignForm(request.POST) |
|
314 | kwargs['button'] = 'Create' | |
|
315 | post = request.POST.copy() | |||
|
316 | experiments = [] | |||
|
317 | ||||
|
318 | for id_exp in post.getlist('experiments'): | |||
|
319 | exp = Experiment.objects.get(pk=id_exp) | |||
|
320 | new_exp = exp.clone(template=False) | |||
|
321 | experiments.append(new_exp) | |||
|
322 | ||||
|
323 | post.setlist('experiments', []) | |||
|
324 | ||||
|
325 | form = CampaignForm(post) | |||
298 |
|
326 | |||
299 | if form.is_valid(): |
|
327 | if form.is_valid(): | |
300 | campaign = form.save() |
|
328 | campaign = form.save() | |
|
329 | for exp in experiments: | |||
|
330 | campaign.experiments.add(exp) | |||
|
331 | campaign.save() | |||
301 | return redirect('url_campaign', id_camp=campaign.id) |
|
332 | return redirect('url_campaign', id_camp=campaign.id) | |
302 |
|
333 | |||
303 | kwargs = {} |
|
|||
304 | kwargs['form'] = form |
|
334 | kwargs['form'] = form | |
305 | kwargs['title'] = 'Campaign' |
|
335 | kwargs['title'] = 'Campaign' | |
306 | kwargs['suptitle'] = 'New' |
|
336 | kwargs['suptitle'] = 'New' | |
307 | kwargs['button'] = 'Create' |
|
|||
308 |
|
337 | |||
309 | return render(request, 'campaign_edit.html', kwargs) |
|
338 | return render(request, 'campaign_edit.html', kwargs) | |
310 |
|
339 | |||
311 | def campaign_edit(request, id_camp): |
|
340 | def campaign_edit(request, id_camp): | |
312 |
|
341 | |||
313 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
342 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
314 |
|
343 | |||
315 | if request.method=='GET': |
|
344 | if request.method=='GET': | |
316 | form = CampaignForm(instance=campaign) |
|
345 | form = CampaignForm(instance=campaign) | |
317 |
|
346 | |||
318 | if request.method=='POST': |
|
347 | if request.method=='POST': | |
319 | form = CampaignForm(request.POST, instance=campaign) |
|
348 | form = CampaignForm(request.POST, instance=campaign) | |
320 |
|
349 | |||
321 | if form.is_valid(): |
|
350 | if form.is_valid(): | |
322 | form.save() |
|
351 | form.save() | |
323 | return redirect('url_campaign', id_camp=id_camp) |
|
352 | return redirect('url_campaign', id_camp=id_camp) | |
324 |
|
353 | |||
325 | kwargs = {} |
|
354 | kwargs = {} | |
326 | kwargs['form'] = form |
|
355 | kwargs['form'] = form | |
327 | kwargs['title'] = 'Campaign' |
|
356 | kwargs['title'] = 'Campaign' | |
328 | kwargs['suptitle'] = 'Edit' |
|
357 | kwargs['suptitle'] = 'Edit' | |
329 | kwargs['button'] = 'Update' |
|
358 | kwargs['button'] = 'Update' | |
330 |
|
359 | |||
331 | return render(request, 'campaign_edit.html', kwargs) |
|
360 | return render(request, 'campaign_edit.html', kwargs) | |
332 |
|
361 | |||
333 | def campaign_delete(request, id_camp): |
|
362 | def campaign_delete(request, id_camp): | |
334 |
|
363 | |||
335 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
364 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
336 |
|
365 | |||
337 | if request.method=='POST': |
|
366 | if request.method=='POST': | |
338 | if request.user.is_staff: |
|
367 | if request.user.is_staff: | |
|
368 | ||||
|
369 | for exp in campaign.experiments.all(): | |||
|
370 | for conf in Configuration.objects.filter(experiment=exp): | |||
|
371 | conf.delete() | |||
|
372 | exp.delete() | |||
339 | campaign.delete() |
|
373 | campaign.delete() | |
|
374 | ||||
340 | return redirect('url_campaigns') |
|
375 | return redirect('url_campaigns') | |
341 |
|
376 | |||
342 | return HttpResponse("Not enough permission to delete this object") |
|
377 | return HttpResponse("Not enough permission to delete this object") | |
343 |
|
378 | |||
344 | kwargs = {'object':campaign, 'camp_active':'active', |
|
379 | kwargs = {'object':campaign, 'camp_active':'active', | |
345 | 'url_cancel':'url_campaign', 'id_item':id_camp} |
|
380 | 'url_cancel':'url_campaign', 'id_item':id_camp} | |
346 |
|
381 | |||
347 | return render(request, 'item_delete.html', kwargs) |
|
382 | return render(request, 'item_delete.html', kwargs) | |
348 |
|
383 | |||
349 | def experiments(request): |
|
384 | def experiments(request): | |
350 |
|
385 | |||
351 |
experiment_list = Experiment.objects.all() |
|
386 | experiment_list = Experiment.objects.all() | |
352 |
|
387 | |||
353 |
keys = ['id', 'name', 'start_time', 'end_time' |
|
388 | keys = ['id', 'name', 'start_time', 'end_time'] | |
354 |
|
389 | |||
355 | kwargs = {} |
|
390 | kwargs = {} | |
356 |
|
391 | |||
357 | kwargs['experiment_keys'] = keys[1:] |
|
392 | kwargs['experiment_keys'] = keys[1:] | |
358 |
kwargs['experiments'] = experiment_list |
|
393 | kwargs['experiments'] = experiment_list | |
359 |
|
394 | |||
360 | kwargs['title'] = 'Experiment' |
|
395 | kwargs['title'] = 'Experiment' | |
361 | kwargs['suptitle'] = 'List' |
|
396 | kwargs['suptitle'] = 'List' | |
362 | kwargs['button'] = 'New Experiment' |
|
397 | kwargs['button'] = 'New Experiment' | |
363 |
|
398 | |||
364 | return render(request, 'experiments.html', kwargs) |
|
399 | return render(request, 'experiments.html', kwargs) | |
365 |
|
400 | |||
366 | def experiment(request, id_exp): |
|
401 | def experiment(request, id_exp): | |
367 |
|
402 | |||
368 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
403 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
369 |
|
404 | |||
370 | experiments = Experiment.objects.filter(campaign=experiment.campaign) |
|
|||
371 | configurations = Configuration.objects.filter(experiment=experiment, type=0) |
|
405 | configurations = Configuration.objects.filter(experiment=experiment, type=0) | |
372 |
|
406 | |||
373 | kwargs = {} |
|
407 | kwargs = {} | |
374 |
|
408 | |||
375 |
exp_keys = ['id |
|
409 | exp_keys = ['id', 'location', 'name', 'start_time', 'end_time'] | |
376 | conf_keys = ['id', 'device__name', 'device__device_type', 'device__ip_address', 'device__port_address'] |
|
410 | conf_keys = ['id', 'device__name', 'device__device_type', 'device__ip_address', 'device__port_address'] | |
377 |
|
411 | |||
378 | conf_labels = ['id', 'device__name', 'device_type', 'ip_address', 'port_address'] |
|
412 | conf_labels = ['id', 'device__name', 'device_type', 'ip_address', 'port_address'] | |
379 |
|
413 | |||
380 | kwargs['experiment_keys'] = exp_keys[1:] |
|
414 | kwargs['experiment_keys'] = exp_keys[1:] | |
381 | kwargs['experiment'] = experiment |
|
415 | kwargs['experiment'] = experiment | |
382 |
|
416 | |||
383 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
|||
384 |
|
||||
385 | kwargs['configuration_labels'] = conf_labels[1:] |
|
417 | kwargs['configuration_labels'] = conf_labels[1:] | |
386 | kwargs['configuration_keys'] = conf_keys[1:] |
|
418 | kwargs['configuration_keys'] = conf_keys[1:] | |
387 | kwargs['configurations'] = configurations #.values(*conf_keys) |
|
419 | kwargs['configurations'] = configurations #.values(*conf_keys) | |
388 |
|
420 | |||
389 | kwargs['title'] = 'Experiment' |
|
421 | kwargs['title'] = 'Experiment' | |
390 | kwargs['suptitle'] = 'Details' |
|
422 | kwargs['suptitle'] = 'Details' | |
391 |
|
423 | |||
392 | kwargs['button'] = 'Add Configuration' |
|
424 | kwargs['button'] = 'Add Configuration' | |
393 |
|
425 | |||
|
426 | ###### SIDEBAR ###### | |||
|
427 | kwargs.update(sidebar(experiment=experiment)) | |||
|
428 | ||||
394 | return render(request, 'experiment.html', kwargs) |
|
429 | return render(request, 'experiment.html', kwargs) | |
395 |
|
430 | |||
|
431 | ||||
396 | def experiment_new(request, id_camp=None): |
|
432 | def experiment_new(request, id_camp=None): | |
397 |
|
433 | |||
|
434 | kwargs = {} | |||
|
435 | ||||
398 | if request.method == 'GET': |
|
436 | if request.method == 'GET': | |
399 | form = ExperimentForm(initial={'campaign':id_camp}) |
|
437 | if 'template' in request.GET: | |
|
438 | if request.GET['template']=='0': | |||
|
439 | form = NewForm(initial={'create_from':2}, | |||
|
440 | template_choices=Experiment.objects.filter(template=True).values_list('id', 'name')) | |||
|
441 | else: | |||
|
442 | kwargs['button'] = 'Create' | |||
|
443 | kwargs['configurations'] = Configuration.objects.filter(experiment=request.GET['template']) | |||
|
444 | kwargs['configuration_keys'] = ['name', 'device__name', 'device__ip_address', 'device__port_address'] | |||
|
445 | form = ExperimentForm(instance=Experiment.objects.get(pk=request.GET['template']), | |||
|
446 | initial={'template':False}) | |||
|
447 | elif 'blank' in request.GET: | |||
|
448 | kwargs['button'] = 'Create' | |||
|
449 | form = ExperimentForm() | |||
|
450 | else: | |||
|
451 | form = NewForm() | |||
400 |
|
452 | |||
401 | if request.method == 'POST': |
|
453 | if request.method == 'POST': | |
402 |
form = ExperimentForm(request.POST |
|
454 | form = ExperimentForm(request.POST) | |
403 |
|
||||
404 | if form.is_valid(): |
|
455 | if form.is_valid(): | |
405 | experiment = form.save() |
|
456 | experiment = form.save() | |
|
457 | ||||
|
458 | if 'template' in request.GET: | |||
|
459 | configurations = Configuration.objects.filter(experiment=request.GET['template'], type=0) | |||
|
460 | for conf in configurations: | |||
|
461 | conf.clone(experiment=experiment, template=False) | |||
|
462 | ||||
406 | return redirect('url_experiment', id_exp=experiment.id) |
|
463 | return redirect('url_experiment', id_exp=experiment.id) | |
407 |
|
464 | |||
408 | kwargs = {} |
|
|||
409 | kwargs['form'] = form |
|
465 | kwargs['form'] = form | |
410 | kwargs['title'] = 'Experiment' |
|
466 | kwargs['title'] = 'Experiment' | |
411 | kwargs['suptitle'] = 'New' |
|
467 | kwargs['suptitle'] = 'New' | |
412 | kwargs['button'] = 'Create' |
|
|||
413 |
|
468 | |||
414 | return render(request, 'experiment_edit.html', kwargs) |
|
469 | return render(request, 'experiment_edit.html', kwargs) | |
415 |
|
470 | |||
416 | def experiment_edit(request, id_exp): |
|
471 | def experiment_edit(request, id_exp): | |
417 |
|
472 | |||
418 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
473 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
419 |
|
474 | |||
420 | if request.method == 'GET': |
|
475 | if request.method == 'GET': | |
421 | form = ExperimentForm(instance=experiment) |
|
476 | form = ExperimentForm(instance=experiment) | |
422 |
|
477 | |||
423 | if request.method=='POST': |
|
478 | if request.method=='POST': | |
424 | form = ExperimentForm(request.POST, instance=experiment) |
|
479 | form = ExperimentForm(request.POST, instance=experiment) | |
425 |
|
480 | |||
426 | if form.is_valid(): |
|
481 | if form.is_valid(): | |
427 | experiment = form.save() |
|
482 | experiment = form.save() | |
428 | return redirect('url_experiment', id_exp=experiment.id) |
|
483 | return redirect('url_experiment', id_exp=experiment.id) | |
429 |
|
484 | |||
430 | kwargs = {} |
|
485 | kwargs = {} | |
431 | kwargs['form'] = form |
|
486 | kwargs['form'] = form | |
432 | kwargs['title'] = 'Experiment' |
|
487 | kwargs['title'] = 'Experiment' | |
433 | kwargs['suptitle'] = 'Edit' |
|
488 | kwargs['suptitle'] = 'Edit' | |
434 | kwargs['button'] = 'Update' |
|
489 | kwargs['button'] = 'Update' | |
435 |
|
490 | |||
436 | return render(request, 'experiment_edit.html', kwargs) |
|
491 | return render(request, 'experiment_edit.html', kwargs) | |
437 |
|
492 | |||
438 | def experiment_delete(request, id_exp): |
|
493 | def experiment_delete(request, id_exp): | |
439 |
|
494 | |||
440 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
495 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
441 |
|
496 | |||
442 | if request.method=='POST': |
|
497 | if request.method=='POST': | |
443 | if request.user.is_staff: |
|
498 | if request.user.is_staff: | |
444 | id_camp = experiment.campaign.id |
|
|||
445 | experiment.delete() |
|
499 | experiment.delete() | |
446 |
return redirect('url_ |
|
500 | return redirect('url_experiments') | |
447 |
|
501 | |||
448 | return HttpResponse("Not enough permission to delete this object") |
|
502 | return HttpResponse("Not enough permission to delete this object") | |
449 |
|
503 | |||
450 | kwargs = {'object':experiment, 'exp_active':'active', |
|
504 | kwargs = {'object':experiment, 'exp_active':'active', | |
451 | 'url_cancel':'url_experiment', 'id_item':id_exp} |
|
505 | 'url_cancel':'url_experiment', 'id_item':id_exp} | |
452 |
|
506 | |||
453 | return render(request, 'item_delete.html', kwargs) |
|
507 | return render(request, 'item_delete.html', kwargs) | |
454 |
|
508 | |||
455 | def dev_confs(request): |
|
509 | def dev_confs(request): | |
456 |
|
510 | |||
457 | configurations = Configuration.objects.all().order_by('type', 'device__device_type', 'experiment') |
|
511 | configurations = Configuration.objects.all().order_by('type', 'device__device_type', 'experiment') | |
458 |
|
512 | |||
459 | # keys = ['id', 'device__device_type__name', 'device__name', 'experiment__campaign__name', 'experiment__name'] |
|
513 | # keys = ['id', 'device__device_type__name', 'device__name', 'experiment__campaign__name', 'experiment__name'] | |
460 |
|
514 | |||
461 | keys = ['id', 'device', 'experiment', 'type', 'programmed_date'] |
|
515 | keys = ['id', 'device', 'experiment', 'type', 'programmed_date'] | |
462 |
|
516 | |||
463 | kwargs = {} |
|
517 | kwargs = {} | |
464 |
|
518 | |||
465 | kwargs['configuration_keys'] = keys[1:] |
|
519 | kwargs['configuration_keys'] = keys[1:] | |
466 | kwargs['configurations'] = configurations#.values(*keys) |
|
520 | kwargs['configurations'] = configurations#.values(*keys) | |
467 |
|
521 | |||
468 | kwargs['title'] = 'Configuration' |
|
522 | kwargs['title'] = 'Configuration' | |
469 | kwargs['suptitle'] = 'List' |
|
523 | kwargs['suptitle'] = 'List' | |
470 | kwargs['button'] = 'New Configuration' |
|
524 | kwargs['button'] = 'New Configuration' | |
471 |
|
525 | |||
472 | return render(request, 'dev_confs.html', kwargs) |
|
526 | return render(request, 'dev_confs.html', kwargs) | |
473 |
|
527 | |||
474 | def dev_conf(request, id_conf): |
|
528 | def dev_conf(request, id_conf): | |
475 |
|
529 | |||
476 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
530 | conf = get_object_or_404(Configuration, pk=id_conf) | |
477 |
|
531 | |||
478 | return redirect(conf.get_absolute_url()) |
|
532 | return redirect(conf.get_absolute_url()) | |
479 |
|
533 | |||
480 |
|
534 | |||
481 | def dev_conf_new(request, id_exp=0, id_dev=0): |
|
535 | def dev_conf_new(request, id_exp=0, id_dev=0): | |
482 |
|
536 | |||
483 | initial = {} |
|
537 | initial = {} | |
484 |
|
538 | |||
485 |
if id_exp |
|
539 | if id_exp<>0: | |
486 | initial['experiment'] = id_exp |
|
540 | initial['experiment'] = id_exp | |
487 |
|
541 | |||
488 | if id_dev<>0: |
|
542 | if id_dev<>0: | |
489 | initial['device'] = id_dev |
|
543 | initial['device'] = id_dev | |
490 |
|
544 | |||
491 | if request.method == 'GET': |
|
545 | if request.method == 'GET': | |
492 | if id_dev==0: |
|
546 | if id_dev==0: | |
493 | form = ConfigurationForm(initial=initial) |
|
547 | form = ConfigurationForm(initial=initial) | |
494 | else: |
|
548 | else: | |
495 | device = Device.objects.get(pk=id_dev) |
|
549 | device = Device.objects.get(pk=id_dev) | |
496 | DevConfForm = CONF_FORMS[device.device_type.name] |
|
550 | DevConfForm = CONF_FORMS[device.device_type.name] | |
497 |
|
551 | |||
498 | form = DevConfForm(initial=initial) |
|
552 | form = DevConfForm(initial=initial) | |
499 |
|
553 | |||
500 | if request.method == 'POST': |
|
554 | if request.method == 'POST': | |
501 |
|
555 | |||
502 | device = Device.objects.get(pk=request.POST['device']) |
|
556 | device = Device.objects.get(pk=request.POST['device']) | |
503 | DevConfForm = CONF_FORMS[device.device_type.name] |
|
557 | DevConfForm = CONF_FORMS[device.device_type.name] | |
504 |
|
558 | |||
505 | form = DevConfForm(request.POST) |
|
559 | form = DevConfForm(request.POST) | |
506 |
|
560 | |||
507 | if form.is_valid(): |
|
561 | if form.is_valid(): | |
508 | dev_conf = form.save() |
|
562 | dev_conf = form.save() | |
509 |
|
563 | |||
510 | return redirect('url_dev_confs') |
|
564 | return redirect('url_dev_confs') | |
511 |
|
565 | |||
512 | kwargs = {} |
|
566 | kwargs = {} | |
513 | kwargs['id_exp'] = id_exp |
|
567 | kwargs['id_exp'] = id_exp | |
514 | kwargs['form'] = form |
|
568 | kwargs['form'] = form | |
515 | kwargs['title'] = 'Configuration' |
|
569 | kwargs['title'] = 'Configuration' | |
516 | kwargs['suptitle'] = 'New' |
|
570 | kwargs['suptitle'] = 'New' | |
517 | kwargs['button'] = 'Create' |
|
571 | kwargs['button'] = 'Create' | |
518 |
|
572 | |||
519 | return render(request, 'dev_conf_edit.html', kwargs) |
|
573 | return render(request, 'dev_conf_edit.html', kwargs) | |
520 |
|
574 | |||
521 | def dev_conf_edit(request, id_conf): |
|
575 | def dev_conf_edit(request, id_conf): | |
522 |
|
576 | |||
523 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
577 | conf = get_object_or_404(Configuration, pk=id_conf) | |
524 |
|
578 | |||
525 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
579 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
526 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
580 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
527 |
|
581 | |||
528 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
582 | dev_conf = DevConfModel.objects.get(pk=id_conf) | |
529 |
|
583 | |||
530 | if request.method=='GET': |
|
584 | if request.method=='GET': | |
531 | form = DevConfForm(instance=dev_conf) |
|
585 | form = DevConfForm(instance=dev_conf) | |
532 |
|
586 | |||
533 | if request.method=='POST': |
|
587 | if request.method=='POST': | |
534 | form = DevConfForm(request.POST, instance=dev_conf) |
|
588 | form = DevConfForm(request.POST, instance=dev_conf) | |
535 |
|
589 | |||
536 | if form.is_valid(): |
|
590 | if form.is_valid(): | |
537 | form.save() |
|
591 | form.save() | |
538 | return redirect('url_dev_conf', id_conf=id_conf) |
|
592 | return redirect('url_dev_conf', id_conf=id_conf) | |
539 |
|
593 | |||
540 | kwargs = {} |
|
594 | kwargs = {} | |
541 | kwargs['form'] = form |
|
595 | kwargs['form'] = form | |
542 | kwargs['title'] = 'Device Configuration' |
|
596 | kwargs['title'] = 'Device Configuration' | |
543 | kwargs['suptitle'] = 'Edit' |
|
597 | kwargs['suptitle'] = 'Edit' | |
544 | kwargs['button'] = 'Update' |
|
598 | kwargs['button'] = 'Update' | |
545 |
|
599 | |||
546 | ###### SIDEBAR ###### |
|
600 | ###### SIDEBAR ###### | |
547 | kwargs.update(sidebar(conf)) |
|
601 | kwargs.update(sidebar(conf=conf)) | |
548 |
|
602 | |||
549 | return render(request, '%s_conf_edit.html' %conf.device.device_type.name, kwargs) |
|
603 | return render(request, '%s_conf_edit.html' %conf.device.device_type.name, kwargs) | |
550 |
|
604 | |||
551 | def dev_conf_start(request, id_conf): |
|
605 | def dev_conf_start(request, id_conf): | |
552 |
|
606 | |||
553 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
607 | conf = get_object_or_404(Configuration, pk=id_conf) | |
554 |
|
608 | |||
555 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
609 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
556 |
|
610 | |||
557 | conf = DevConfModel.objects.get(pk=id_conf) |
|
611 | conf = DevConfModel.objects.get(pk=id_conf) | |
558 |
|
612 | |||
559 | if conf.start_device(): |
|
613 | if conf.start_device(): | |
560 | messages.success(request, conf.message) |
|
614 | messages.success(request, conf.message) | |
561 | else: |
|
615 | else: | |
562 | messages.error(request, conf.message) |
|
616 | messages.error(request, conf.message) | |
563 |
|
617 | |||
564 | conf.status_device() |
|
618 | conf.status_device() | |
565 |
|
619 | |||
566 | return redirect(conf.get_absolute_url()) |
|
620 | return redirect(conf.get_absolute_url()) | |
567 |
|
621 | |||
568 | def dev_conf_stop(request, id_conf): |
|
622 | def dev_conf_stop(request, id_conf): | |
569 |
|
623 | |||
570 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
624 | conf = get_object_or_404(Configuration, pk=id_conf) | |
571 |
|
625 | |||
572 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
626 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
573 |
|
627 | |||
574 | conf = DevConfModel.objects.get(pk=id_conf) |
|
628 | conf = DevConfModel.objects.get(pk=id_conf) | |
575 |
|
629 | |||
576 | if conf.stop_device(): |
|
630 | if conf.stop_device(): | |
577 | messages.success(request, conf.message) |
|
631 | messages.success(request, conf.message) | |
578 | else: |
|
632 | else: | |
579 | messages.error(request, conf.message) |
|
633 | messages.error(request, conf.message) | |
580 |
|
634 | |||
581 | conf.status_device() |
|
635 | conf.status_device() | |
582 |
|
636 | |||
583 | return redirect(conf.get_absolute_url()) |
|
637 | return redirect(conf.get_absolute_url()) | |
584 |
|
638 | |||
585 | def dev_conf_status(request, id_conf): |
|
639 | def dev_conf_status(request, id_conf): | |
586 |
|
640 | |||
587 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
641 | conf = get_object_or_404(Configuration, pk=id_conf) | |
588 |
|
642 | |||
589 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
643 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
590 |
|
644 | |||
591 | conf = DevConfModel.objects.get(pk=id_conf) |
|
645 | conf = DevConfModel.objects.get(pk=id_conf) | |
592 |
|
646 | |||
593 | if conf.status_device(): |
|
647 | if conf.status_device(): | |
594 | messages.success(request, conf.message) |
|
648 | messages.success(request, conf.message) | |
595 | else: |
|
649 | else: | |
596 | messages.error(request, conf.message) |
|
650 | messages.error(request, conf.message) | |
597 |
|
651 | |||
598 | return redirect(conf.get_absolute_url()) |
|
652 | return redirect(conf.get_absolute_url()) | |
599 |
|
653 | |||
600 |
|
654 | |||
601 | def dev_conf_write(request, id_conf): |
|
655 | def dev_conf_write(request, id_conf): | |
602 |
|
656 | |||
603 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
657 | conf = get_object_or_404(Configuration, pk=id_conf) | |
604 |
|
658 | |||
605 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
659 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
606 |
|
660 | |||
607 | conf = DevConfModel.objects.get(pk=id_conf) |
|
661 | conf = DevConfModel.objects.get(pk=id_conf) | |
608 |
|
662 | |||
609 | answer = conf.write_device() |
|
663 | answer = conf.write_device() | |
610 | conf.status_device() |
|
664 | conf.status_device() | |
611 |
|
665 | |||
612 | if answer: |
|
666 | if answer: | |
613 | messages.success(request, conf.message) |
|
667 | messages.success(request, conf.message) | |
614 |
|
668 | |||
615 | #Creating a historical configuration |
|
669 | #Creating a historical configuration | |
616 | conf.pk = None |
|
670 | conf.clone(type=0, template=False) | |
617 | conf.id = None |
|
|||
618 | conf.type = 1 |
|
|||
619 | conf.template = 0 |
|
|||
620 | conf.save() |
|
|||
621 |
|
671 | |||
622 | #Original configuration |
|
672 | #Original configuration | |
623 | conf = DevConfModel.objects.get(pk=id_conf) |
|
673 | conf = DevConfModel.objects.get(pk=id_conf) | |
624 | else: |
|
674 | else: | |
625 | messages.error(request, conf.message) |
|
675 | messages.error(request, conf.message) | |
626 |
|
676 | |||
627 | return redirect(conf.get_absolute_url()) |
|
677 | return redirect(conf.get_absolute_url()) | |
628 |
|
678 | |||
629 | def dev_conf_read(request, id_conf): |
|
679 | def dev_conf_read(request, id_conf): | |
630 |
|
680 | |||
631 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
681 | conf = get_object_or_404(Configuration, pk=id_conf) | |
632 |
|
682 | |||
633 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
683 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
634 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
684 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
635 |
|
685 | |||
636 | conf = DevConfModel.objects.get(pk=id_conf) |
|
686 | conf = DevConfModel.objects.get(pk=id_conf) | |
637 |
|
687 | |||
638 | if request.method=='GET': |
|
688 | if request.method=='GET': | |
639 |
|
689 | |||
640 | parms = conf.read_device() |
|
690 | parms = conf.read_device() | |
641 | conf.status_device() |
|
691 | conf.status_device() | |
642 |
|
692 | |||
643 | if not parms: |
|
693 | if not parms: | |
644 | messages.error(request, conf.message) |
|
694 | messages.error(request, conf.message) | |
645 | return redirect(conf.get_absolute_url()) |
|
695 | return redirect(conf.get_absolute_url()) | |
646 |
|
696 | |||
647 | form = DevConfForm(initial=parms, instance=conf) |
|
697 | form = DevConfForm(initial=parms, instance=conf) | |
648 |
|
698 | |||
649 | if request.method=='POST': |
|
699 | if request.method=='POST': | |
650 | form = DevConfForm(request.POST, instance=conf) |
|
700 | form = DevConfForm(request.POST, instance=conf) | |
651 |
|
701 | |||
652 | if form.is_valid(): |
|
702 | if form.is_valid(): | |
653 | form.save() |
|
703 | form.save() | |
654 | return redirect(conf.get_absolute_url()) |
|
704 | return redirect(conf.get_absolute_url()) | |
655 |
|
705 | |||
656 | messages.error(request, "Parameters could not be saved") |
|
706 | messages.error(request, "Parameters could not be saved") | |
657 |
|
707 | |||
658 | kwargs = {} |
|
708 | kwargs = {} | |
659 | kwargs['id_dev'] = conf.id |
|
709 | kwargs['id_dev'] = conf.id | |
660 | kwargs['form'] = form |
|
710 | kwargs['form'] = form | |
661 | kwargs['title'] = 'Device Configuration' |
|
711 | kwargs['title'] = 'Device Configuration' | |
662 | kwargs['suptitle'] = 'Parameters read from device' |
|
712 | kwargs['suptitle'] = 'Parameters read from device' | |
663 | kwargs['button'] = 'Save' |
|
713 | kwargs['button'] = 'Save' | |
664 |
|
714 | |||
665 | ###### SIDEBAR ###### |
|
715 | ###### SIDEBAR ###### | |
666 | kwargs.update(sidebar(conf)) |
|
716 | kwargs.update(sidebar(conf=conf)) | |
667 |
|
717 | |||
668 | return render(request, '%s_conf_edit.html' %conf.device.device_type.name, kwargs) |
|
718 | return render(request, '%s_conf_edit.html' %conf.device.device_type.name, kwargs) | |
669 |
|
719 | |||
670 | def dev_conf_import(request, id_conf): |
|
720 | def dev_conf_import(request, id_conf): | |
671 |
|
721 | |||
672 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
722 | conf = get_object_or_404(Configuration, pk=id_conf) | |
673 |
|
723 | |||
674 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
724 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
675 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
725 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
676 |
|
||||
677 | conf = DevConfModel.objects.get(pk=id_conf) |
|
726 | conf = DevConfModel.objects.get(pk=id_conf) | |
678 |
|
727 | |||
679 | if request.method == 'GET': |
|
728 | if request.method == 'GET': | |
680 | file_form = UploadFileForm() |
|
729 | file_form = UploadFileForm() | |
681 |
|
730 | |||
682 | if request.method == 'POST': |
|
731 | if request.method == 'POST': | |
683 | file_form = UploadFileForm(request.POST, request.FILES) |
|
732 | file_form = UploadFileForm(request.POST, request.FILES) | |
684 |
|
733 | |||
685 | if file_form.is_valid(): |
|
734 | if file_form.is_valid(): | |
686 |
|
735 | |||
687 | parms = conf.import_from_file(request.FILES['file']) |
|
736 | parms = conf.import_from_file(request.FILES['file']) | |
688 |
|
737 | |||
689 | if parms: |
|
738 | if parms: | |
690 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) |
|
739 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) | |
691 | print parms |
|
|||
692 | form = DevConfForm(initial=parms, instance=conf) |
|
740 | form = DevConfForm(initial=parms, instance=conf) | |
693 |
|
741 | |||
694 | kwargs = {} |
|
742 | kwargs = {} | |
695 | kwargs['id_dev'] = conf.id |
|
743 | kwargs['id_dev'] = conf.id | |
696 | kwargs['form'] = form |
|
744 | kwargs['form'] = form | |
697 | kwargs['title'] = 'Device Configuration' |
|
745 | kwargs['title'] = 'Device Configuration' | |
698 | kwargs['suptitle'] = 'Parameters imported' |
|
746 | kwargs['suptitle'] = 'Parameters imported' | |
699 | kwargs['button'] = 'Save' |
|
747 | kwargs['button'] = 'Save' | |
700 | kwargs['action'] = conf.get_absolute_url_edit() |
|
748 | kwargs['action'] = conf.get_absolute_url_edit() | |
701 | kwargs['previous'] = conf.get_absolute_url() |
|
749 | kwargs['previous'] = conf.get_absolute_url() | |
702 |
|
750 | |||
703 | ###### SIDEBAR ###### |
|
751 | ###### SIDEBAR ###### | |
704 | kwargs.update(sidebar(conf)) |
|
752 | kwargs.update(sidebar(conf=conf)) | |
705 |
|
753 | |||
706 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) |
|
754 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) | |
707 |
|
755 | |||
708 | messages.error(request, "Could not import parameters from file") |
|
756 | messages.error(request, "Could not import parameters from file") | |
709 |
|
757 | |||
710 | kwargs = {} |
|
758 | kwargs = {} | |
711 | kwargs['id_dev'] = conf.id |
|
759 | kwargs['id_dev'] = conf.id | |
712 | kwargs['title'] = 'Device Configuration' |
|
760 | kwargs['title'] = 'Device Configuration' | |
713 | kwargs['form'] = file_form |
|
761 | kwargs['form'] = file_form | |
714 | kwargs['suptitle'] = 'Importing file' |
|
762 | kwargs['suptitle'] = 'Importing file' | |
715 | kwargs['button'] = 'Import' |
|
763 | kwargs['button'] = 'Import' | |
716 |
|
764 | |||
717 | kwargs.update(sidebar(conf)) |
|
765 | kwargs.update(sidebar(conf=conf)) | |
718 |
|
766 | |||
719 | return render(request, 'dev_conf_import.html', kwargs) |
|
767 | return render(request, 'dev_conf_import.html', kwargs) | |
720 |
|
768 | |||
721 | def dev_conf_export(request, id_conf): |
|
769 | def dev_conf_export(request, id_conf): | |
722 |
|
770 | |||
723 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
771 | conf = get_object_or_404(Configuration, pk=id_conf) | |
724 |
|
772 | |||
725 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
773 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
726 |
|
774 | |||
727 | conf = DevConfModel.objects.get(pk=id_conf) |
|
775 | conf = DevConfModel.objects.get(pk=id_conf) | |
728 |
|
776 | |||
729 | if request.method == 'GET': |
|
777 | if request.method == 'GET': | |
730 | file_form = DownloadFileForm(conf.device.device_type.name) |
|
778 | file_form = DownloadFileForm(conf.device.device_type.name) | |
731 |
|
779 | |||
732 | if request.method == 'POST': |
|
780 | if request.method == 'POST': | |
733 | file_form = DownloadFileForm(conf.device.device_type.name, request.POST) |
|
781 | file_form = DownloadFileForm(conf.device.device_type.name, request.POST) | |
734 |
|
782 | |||
735 | if file_form.is_valid(): |
|
783 | if file_form.is_valid(): | |
736 | fields = conf.export_to_file(format = file_form.cleaned_data['format']) |
|
784 | fields = conf.export_to_file(format = file_form.cleaned_data['format']) | |
737 |
|
785 | |||
738 | response = HttpResponse(content_type=fields['content_type']) |
|
786 | response = HttpResponse(content_type=fields['content_type']) | |
739 | response['Content-Disposition'] = 'attachment; filename="%s"' %fields['filename'] |
|
787 | response['Content-Disposition'] = 'attachment; filename="%s"' %fields['filename'] | |
740 | response.write(fields['content']) |
|
788 | response.write(fields['content']) | |
741 |
|
789 | |||
742 | return response |
|
790 | return response | |
743 |
|
791 | |||
744 | messages.error(request, "Could not export parameters") |
|
792 | messages.error(request, "Could not export parameters") | |
745 |
|
793 | |||
746 | kwargs = {} |
|
794 | kwargs = {} | |
747 | kwargs['id_dev'] = conf.id |
|
795 | kwargs['id_dev'] = conf.id | |
748 | kwargs['title'] = 'Device Configuration' |
|
796 | kwargs['title'] = 'Device Configuration' | |
749 | kwargs['form'] = file_form |
|
797 | kwargs['form'] = file_form | |
750 | kwargs['suptitle'] = 'Exporting file' |
|
798 | kwargs['suptitle'] = 'Exporting file' | |
751 | kwargs['button'] = 'Export' |
|
799 | kwargs['button'] = 'Export' | |
752 |
|
800 | |||
753 | return render(request, 'dev_conf_export.html', kwargs) |
|
801 | return render(request, 'dev_conf_export.html', kwargs) | |
754 |
|
802 | |||
755 | def dev_conf_delete(request, id_conf): |
|
803 | def dev_conf_delete(request, id_conf): | |
756 |
|
804 | |||
757 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
805 | conf = get_object_or_404(Configuration, pk=id_conf) | |
758 |
|
806 | |||
759 | if request.method=='POST': |
|
807 | if request.method=='POST': | |
760 | if request.user.is_staff: |
|
808 | if request.user.is_staff: | |
761 | id_exp = conf.experiment.id |
|
809 | id_exp = conf.experiment.id | |
762 | conf.delete() |
|
810 | conf.delete() | |
763 | return redirect('url_experiment', id_exp=id_exp) |
|
811 | return redirect('url_experiment', id_exp=id_exp) | |
764 |
|
812 | |||
765 | return HttpResponse("Not enough permission to delete this object") |
|
813 | return HttpResponse("Not enough permission to delete this object") | |
766 |
|
814 | |||
767 | kwargs = {'object':conf, 'conf_active':'active', |
|
815 | kwargs = {'object':conf, 'conf_active':'active', | |
768 | 'url_cancel':'url_dev_conf', 'id_item':id_conf} |
|
816 | 'url_cancel':'url_dev_conf', 'id_item':id_conf} | |
769 |
|
817 | |||
770 | ###### SIDEBAR ###### |
|
|||
771 | kwargs.update(sidebar(conf)) |
|
|||
772 |
|
||||
773 | return render(request, 'item_delete.html', kwargs) |
|
818 | return render(request, 'item_delete.html', kwargs) | |
774 |
|
819 | |||
775 | def sidebar(conf): |
|
820 | ||
|
821 | def sidebar(**kwargs): | |||
776 |
|
822 | |||
777 |
|
|
823 | side_data = {} | |
|
824 | ||||
|
825 | conf = kwargs.get('conf', None) | |||
|
826 | experiment = kwargs.get('experiment', None) | |||
778 |
|
827 | |||
779 |
if |
|
828 | if not experiment: | |
780 |
experiment |
|
829 | experiment = conf.experiment | |
781 | configurations = Configuration.objects.filter(experiment=conf.experiment, type=0) |
|
830 | ||
782 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] |
|
831 | if experiment: | |
783 |
|
|
832 | side_data['experiment'] = experiment | |
784 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
833 | campaign = experiment.campaign_set.all() | |
785 | conf_keys = ['id', 'device'] |
|
834 | if campaign: | |
786 | kwargs['configuration_keys'] = conf_keys[1:] |
|
835 | side_data['campaign'] = campaign[0] | |
787 | kwargs['configurations'] = configurations #.values(*conf_keys) |
|
836 | experiments = campaign[0].experiments.all() | |
|
837 | else: | |||
|
838 | experiments = [experiment] | |||
|
839 | configurations = experiment.configuration_set.filter(type=0) | |||
|
840 | side_data['side_experiments'] = experiments | |||
|
841 | side_data['side_configurations'] = configurations | |||
788 |
|
842 | |||
789 |
return |
|
843 | return side_data | |
790 |
|
844 | |||
791 |
|
845 | |||
792 | def operation(request, id_camp=None): |
|
846 | def operation(request, id_camp=None): | |
793 |
|
847 | |||
794 | if not id_camp: |
|
848 | if not id_camp: | |
795 | campaigns = Campaign.objects.all().order_by('-start_date') |
|
849 | campaigns = Campaign.objects.all().order_by('-start_date') | |
796 |
|
850 | |||
797 | if not campaigns: |
|
851 | if not campaigns: | |
798 | kwargs = {} |
|
852 | kwargs = {} | |
799 | kwargs['title'] = 'No Campaigns' |
|
853 | kwargs['title'] = 'No Campaigns' | |
800 | kwargs['suptitle'] = 'Empty' |
|
854 | kwargs['suptitle'] = 'Empty' | |
801 | return render(request, 'operation.html', kwargs) |
|
855 | return render(request, 'operation.html', kwargs) | |
802 |
|
856 | |||
803 | id_camp = campaigns[0].id |
|
857 | id_camp = campaigns[0].id | |
804 |
|
858 | |||
805 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
859 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
806 |
|
860 | |||
807 | if request.method=='GET': |
|
861 | if request.method=='GET': | |
808 | form = OperationForm(initial={'campaign': campaign.id}, length = 5) |
|
862 | form = OperationForm(initial={'campaign': campaign.id}, length = 5) | |
809 |
|
863 | |||
810 | if request.method=='POST': |
|
864 | if request.method=='POST': | |
811 | form = OperationForm(request.POST, initial={'campaign':campaign.id}, length = 5) |
|
865 | form = OperationForm(request.POST, initial={'campaign':campaign.id}, length = 5) | |
812 |
|
866 | |||
813 | if form.is_valid(): |
|
867 | if form.is_valid(): | |
814 | return redirect('url_operation', id_camp=campaign.id) |
|
868 | return redirect('url_operation', id_camp=campaign.id) | |
815 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() |
|
869 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() | |
816 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) |
|
870 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) | |
817 | for exs in experiments: |
|
871 | for exs in experiments: | |
818 | exs.get_status() |
|
872 | exs.get_status() | |
819 | locations= Location.objects.filter(experiment=experiments).distinct() |
|
873 | locations= Location.objects.filter(experiment=experiments).distinct() | |
820 | #experiments = [Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) for location in locations] |
|
874 | #experiments = [Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) for location in locations] | |
821 | kwargs = {} |
|
875 | kwargs = {} | |
822 | #---Campaign |
|
876 | #---Campaign | |
823 | kwargs['campaign'] = campaign |
|
877 | kwargs['campaign'] = campaign | |
824 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
878 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
825 | #---Experiment |
|
879 | #---Experiment | |
826 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] |
|
880 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] | |
827 | kwargs['experiment_keys'] = keys[1:] |
|
881 | kwargs['experiment_keys'] = keys[1:] | |
828 | kwargs['experiments'] = experiments |
|
882 | kwargs['experiments'] = experiments | |
829 | #---Radar |
|
883 | #---Radar | |
830 | kwargs['locations'] = locations |
|
884 | kwargs['locations'] = locations | |
831 | #---Else |
|
885 | #---Else | |
832 | kwargs['title'] = 'Campaign' |
|
886 | kwargs['title'] = 'Campaign' | |
833 | kwargs['suptitle'] = campaign.name |
|
887 | kwargs['suptitle'] = campaign.name | |
834 | kwargs['form'] = form |
|
888 | kwargs['form'] = form | |
835 | kwargs['button'] = 'Search' |
|
889 | kwargs['button'] = 'Search' | |
836 | kwargs['details'] = True |
|
890 | kwargs['details'] = True | |
837 | kwargs['search_button'] = True |
|
891 | kwargs['search_button'] = True | |
838 |
|
892 | |||
839 | return render(request, 'operation.html', kwargs) |
|
893 | return render(request, 'operation.html', kwargs) | |
840 |
|
894 | |||
841 | def operation_search(request, id_camp=None): |
|
895 | def operation_search(request, id_camp=None): | |
842 |
|
896 | |||
843 |
|
897 | |||
844 | if not id_camp: |
|
898 | if not id_camp: | |
845 | campaigns = Campaign.objects.all().order_by('-start_date') |
|
899 | campaigns = Campaign.objects.all().order_by('-start_date') | |
846 |
|
900 | |||
847 | if not campaigns: |
|
901 | if not campaigns: | |
848 | return render(request, 'operation.html', {}) |
|
902 | return render(request, 'operation.html', {}) | |
849 |
|
903 | |||
850 | id_camp = campaigns[0].id |
|
904 | id_camp = campaigns[0].id | |
851 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
905 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
852 |
|
906 | |||
853 | if request.method=='GET': |
|
907 | if request.method=='GET': | |
854 | form = OperationSearchForm(initial={'campaign': campaign.id}) |
|
908 | form = OperationSearchForm(initial={'campaign': campaign.id}) | |
855 |
|
909 | |||
856 | if request.method=='POST': |
|
910 | if request.method=='POST': | |
857 | form = OperationSearchForm(request.POST, initial={'campaign':campaign.id}) |
|
911 | form = OperationSearchForm(request.POST, initial={'campaign':campaign.id}) | |
858 |
|
912 | |||
859 | if form.is_valid(): |
|
913 | if form.is_valid(): | |
860 | return redirect('url_operation', id_camp=campaign.id) |
|
914 | return redirect('url_operation', id_camp=campaign.id) | |
861 |
|
915 | |||
862 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() |
|
916 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() | |
863 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) |
|
917 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) | |
864 | for exs in experiments: |
|
918 | for exs in experiments: | |
865 | exs.get_status() |
|
919 | exs.get_status() | |
866 | locations= Location.objects.filter(experiment=experiments).distinct() |
|
920 | locations= Location.objects.filter(experiment=experiments).distinct() | |
867 | form = OperationSearchForm(initial={'campaign': campaign.id}) |
|
921 | form = OperationSearchForm(initial={'campaign': campaign.id}) | |
868 |
|
922 | |||
869 | kwargs = {} |
|
923 | kwargs = {} | |
870 | #---Campaign |
|
924 | #---Campaign | |
871 | kwargs['campaign'] = campaign |
|
925 | kwargs['campaign'] = campaign | |
872 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
926 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
873 | #---Experiment |
|
927 | #---Experiment | |
874 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] |
|
928 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] | |
875 | kwargs['experiment_keys'] = keys[1:] |
|
929 | kwargs['experiment_keys'] = keys[1:] | |
876 | kwargs['experiments'] = experiments |
|
930 | kwargs['experiments'] = experiments | |
877 | #---Radar |
|
931 | #---Radar | |
878 | kwargs['locations'] = locations |
|
932 | kwargs['locations'] = locations | |
879 | #---Else |
|
933 | #---Else | |
880 | kwargs['title'] = 'Campaign' |
|
934 | kwargs['title'] = 'Campaign' | |
881 | kwargs['suptitle'] = campaign.name |
|
935 | kwargs['suptitle'] = campaign.name | |
882 | kwargs['form'] = form |
|
936 | kwargs['form'] = form | |
883 | kwargs['button'] = 'Select' |
|
937 | kwargs['button'] = 'Select' | |
884 | kwargs['details'] = True |
|
938 | kwargs['details'] = True | |
885 | kwargs['search_button'] = False |
|
939 | kwargs['search_button'] = False | |
886 |
|
940 | |||
887 | return render(request, 'operation.html', kwargs) |
|
941 | return render(request, 'operation.html', kwargs) | |
888 |
|
942 | |||
889 |
|
943 | |||
890 | def radar_play(request, id_camp, id_radar): |
|
944 | def radar_play(request, id_camp, id_radar): | |
891 |
|
945 | |||
892 | route = request.META['HTTP_REFERER'] |
|
946 | route = request.META['HTTP_REFERER'] | |
893 | route = str(route) |
|
947 | route = str(route) | |
894 | if 'search' in route: |
|
948 | if 'search' in route: | |
895 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) |
|
949 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) | |
896 | else: |
|
950 | else: | |
897 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
951 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) | |
898 |
|
952 | |||
899 | def radar_stop(request, id_camp, id_radar): |
|
953 | def radar_stop(request, id_camp, id_radar): | |
900 |
|
954 | |||
901 | route = request.META['HTTP_REFERER'] |
|
955 | route = request.META['HTTP_REFERER'] | |
902 | route = str(route) |
|
956 | route = str(route) | |
903 | if 'search' in route: |
|
957 | if 'search' in route: | |
904 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) |
|
958 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) | |
905 | else: |
|
959 | else: | |
906 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) No newline at end of file |
|
960 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) | |
|
961 |
@@ -1,336 +1,338 | |||||
1 | import os |
|
1 | import os | |
2 | import ast |
|
2 | import ast | |
3 | import json |
|
3 | import json | |
4 |
|
4 | |||
5 | from django import forms |
|
5 | from django import forms | |
6 | from django.utils.safestring import mark_safe |
|
6 | from django.utils.safestring import mark_safe | |
7 | from apps.main.models import Device |
|
7 | from apps.main.models import Device | |
8 | from apps.main.forms import add_empty_choice |
|
8 | from apps.main.forms import add_empty_choice | |
9 | from .models import RCConfiguration, RCLine, RCLineType, RCLineCode |
|
9 | from .models import RCConfiguration, RCLine, RCLineType, RCLineCode | |
10 | from .widgets import KmUnitWidget, KmUnitHzWidget, KmUnitDcWidget, UnitKmWidget, DefaultWidget, CodesWidget, HiddenWidget |
|
10 | from .widgets import KmUnitWidget, KmUnitHzWidget, KmUnitDcWidget, UnitKmWidget, DefaultWidget, CodesWidget, HiddenWidget | |
11 |
|
11 | |||
12 | def create_choices_from_model(model, conf_id, all=False): |
|
12 | def create_choices_from_model(model, conf_id, all=False): | |
13 |
|
13 | |||
14 | if model=='RCLine': |
|
14 | if model=='RCLine': | |
15 | instance = RCConfiguration.objects.get(pk=conf_id) |
|
15 | instance = RCConfiguration.objects.get(pk=conf_id) | |
16 | choices = [(line.pk, line.get_name()) for line in instance.get_lines(type='tx')] |
|
16 | choices = [(line.pk, line.get_name()) for line in instance.get_lines(type='tx')] | |
17 | choices = add_empty_choice(choices, label='All') |
|
17 | choices = add_empty_choice(choices, label='All') | |
18 | else: |
|
18 | else: | |
19 | instance = globals()[model] |
|
19 | instance = globals()[model] | |
20 | choices = instance.objects.all().values_list('pk', 'name') |
|
20 | choices = instance.objects.all().values_list('pk', 'name') | |
21 |
|
21 | |||
22 | return choices |
|
22 | return choices | |
23 |
|
23 | |||
24 |
|
24 | |||
25 | class ExtFileField(forms.FileField): |
|
25 | class ExtFileField(forms.FileField): | |
26 | """ |
|
26 | """ | |
27 | Same as forms.FileField, but you can specify a file extension whitelist. |
|
27 | Same as forms.FileField, but you can specify a file extension whitelist. | |
28 |
|
28 | |||
29 | >>> from django.core.files.uploadedfile import SimpleUploadedFile |
|
29 | >>> from django.core.files.uploadedfile import SimpleUploadedFile | |
30 | >>> |
|
30 | >>> | |
31 | >>> t = ExtFileField(ext_whitelist=(".pdf", ".txt")) |
|
31 | >>> t = ExtFileField(ext_whitelist=(".pdf", ".txt")) | |
32 | >>> |
|
32 | >>> | |
33 | >>> t.clean(SimpleUploadedFile('filename.pdf', 'Some File Content')) |
|
33 | >>> t.clean(SimpleUploadedFile('filename.pdf', 'Some File Content')) | |
34 | >>> t.clean(SimpleUploadedFile('filename.txt', 'Some File Content')) |
|
34 | >>> t.clean(SimpleUploadedFile('filename.txt', 'Some File Content')) | |
35 | >>> |
|
35 | >>> | |
36 | >>> t.clean(SimpleUploadedFile('filename.exe', 'Some File Content')) |
|
36 | >>> t.clean(SimpleUploadedFile('filename.exe', 'Some File Content')) | |
37 | Traceback (most recent call last): |
|
37 | Traceback (most recent call last): | |
38 | ... |
|
38 | ... | |
39 | ValidationError: [u'Not allowed filetype!'] |
|
39 | ValidationError: [u'Not allowed filetype!'] | |
40 | """ |
|
40 | """ | |
41 | def __init__(self, *args, **kwargs): |
|
41 | def __init__(self, *args, **kwargs): | |
42 | extensions = kwargs.pop("extensions") |
|
42 | extensions = kwargs.pop("extensions") | |
43 | self.extensions = [i.lower() for i in extensions] |
|
43 | self.extensions = [i.lower() for i in extensions] | |
44 |
|
44 | |||
45 | super(ExtFileField, self).__init__(*args, **kwargs) |
|
45 | super(ExtFileField, self).__init__(*args, **kwargs) | |
46 |
|
46 | |||
47 | def clean(self, *args, **kwargs): |
|
47 | def clean(self, *args, **kwargs): | |
48 | data = super(ExtFileField, self).clean(*args, **kwargs) |
|
48 | data = super(ExtFileField, self).clean(*args, **kwargs) | |
49 | filename = data.name |
|
49 | filename = data.name | |
50 | ext = os.path.splitext(filename)[1] |
|
50 | ext = os.path.splitext(filename)[1] | |
51 | ext = ext.lower() |
|
51 | ext = ext.lower() | |
52 | if ext not in self.extensions: |
|
52 | if ext not in self.extensions: | |
53 | raise forms.ValidationError('Not allowed file type: %s' % ext) |
|
53 | raise forms.ValidationError('Not allowed file type: %s' % ext) | |
54 |
|
54 | |||
55 |
|
55 | |||
56 | class RCConfigurationForm(forms.ModelForm): |
|
56 | class RCConfigurationForm(forms.ModelForm): | |
57 |
|
57 | |||
58 | def __init__(self, *args, **kwargs): |
|
58 | def __init__(self, *args, **kwargs): | |
59 | super(RCConfigurationForm, self).__init__(*args, **kwargs) |
|
59 | super(RCConfigurationForm, self).__init__(*args, **kwargs) | |
60 |
|
60 | |||
61 | instance = getattr(self, 'instance', None) |
|
61 | instance = getattr(self, 'instance', None) | |
62 |
|
62 | |||
63 | if instance and instance.pk: |
|
63 | if instance and instance.pk: | |
64 |
|
64 | |||
65 | devices = Device.objects.filter(device_type__name='rc') |
|
65 | devices = Device.objects.filter(device_type__name='rc') | |
66 | if instance.experiment: |
|
66 | if instance.experiment: | |
67 |
self.fields['experiment'].widget.attrs[' |
|
67 | self.fields['experiment'].widget.attrs['disabled'] = 'disabled' | |
68 | self.fields['experiment'].widget.choices = [(instance.experiment.id, instance.experiment)] |
|
68 | #self.fields['experiment'].widget.choices = [(instance.experiment.id, instance.experiment)] | |
69 | self.fields['device'].widget.choices = [(device.id, device) for device in devices] |
|
69 | self.fields['device'].widget.choices = [(device.id, device) for device in devices] | |
70 | self.fields['ipp'].widget = KmUnitHzWidget(attrs={'km2unit':instance.km2unit}) |
|
70 | self.fields['ipp'].widget = KmUnitHzWidget(attrs={'km2unit':instance.km2unit}) | |
71 | self.fields['clock'].widget.attrs['readonly'] = True |
|
71 | self.fields['clock'].widget.attrs['readonly'] = True | |
72 |
|
72 | |||
73 | self.fields['time_before'].label = mark_safe(self.fields['time_before'].label) |
|
73 | self.fields['time_before'].label = mark_safe(self.fields['time_before'].label) | |
74 | self.fields['time_after'].label = mark_safe(self.fields['time_after'].label) |
|
74 | self.fields['time_after'].label = mark_safe(self.fields['time_after'].label) | |
75 |
|
75 | |||
|
76 | if 'initial' in kwargs and 'experiment' in kwargs['initial'] and kwargs['initial']['experiment'] not in (0, '0'): | |||
|
77 | self.fields['experiment'].widget.attrs['disabled'] = 'disabled' | |||
76 |
|
78 | |||
77 | class Meta: |
|
79 | class Meta: | |
78 | model = RCConfiguration |
|
80 | model = RCConfiguration | |
79 | exclude = ('type', 'parameters', 'status') |
|
81 | exclude = ('type', 'parameters', 'status') | |
80 |
|
82 | |||
81 | def clean(self): |
|
83 | def clean(self): | |
82 | form_data = super(RCConfigurationForm, self).clean() |
|
84 | form_data = super(RCConfigurationForm, self).clean() | |
83 |
|
85 | |||
84 | if 'clock_divider' in form_data: |
|
86 | if 'clock_divider' in form_data: | |
85 | if form_data['clock_divider']<1: |
|
87 | if form_data['clock_divider']<1: | |
86 | self.add_error('clock_divider', 'Invalid Value') |
|
88 | self.add_error('clock_divider', 'Invalid Value') | |
87 | else: |
|
89 | else: | |
88 | if form_data['ipp']*(20./3*(form_data['clock_in']/form_data['clock_divider']))%10<>0: |
|
90 | if form_data['ipp']*(20./3*(form_data['clock_in']/form_data['clock_divider']))%10<>0: | |
89 | self.add_error('ipp', 'Invalid IPP units={}'.format(form_data['ipp']*(20./3*(form_data['clock_in']/form_data['clock_divider'])))) |
|
91 | self.add_error('ipp', 'Invalid IPP units={}'.format(form_data['ipp']*(20./3*(form_data['clock_in']/form_data['clock_divider'])))) | |
90 |
|
92 | |||
91 | return form_data |
|
93 | return form_data | |
92 |
|
94 | |||
93 | class RCLineForm(forms.ModelForm): |
|
95 | class RCLineForm(forms.ModelForm): | |
94 |
|
96 | |||
95 | def __init__(self, *args, **kwargs): |
|
97 | def __init__(self, *args, **kwargs): | |
96 | self.extra_fields = kwargs.pop('extra_fields', []) |
|
98 | self.extra_fields = kwargs.pop('extra_fields', []) | |
97 | super(RCLineForm, self).__init__(*args, **kwargs) |
|
99 | super(RCLineForm, self).__init__(*args, **kwargs) | |
98 |
|
100 | |||
99 | if 'initial' in kwargs and 'line_type' in kwargs['initial']: |
|
101 | if 'initial' in kwargs and 'line_type' in kwargs['initial']: | |
100 | line_type = RCLineType.objects.get(pk=kwargs['initial']['line_type']) |
|
102 | line_type = RCLineType.objects.get(pk=kwargs['initial']['line_type']) | |
101 |
|
103 | |||
102 | if 'code_id' in kwargs['initial']: |
|
104 | if 'code_id' in kwargs['initial']: | |
103 | model_initial = kwargs['initial']['code_id'] |
|
105 | model_initial = kwargs['initial']['code_id'] | |
104 | else: |
|
106 | else: | |
105 | model_initial = 0 |
|
107 | model_initial = 0 | |
106 |
|
108 | |||
107 | params = json.loads(line_type.params) |
|
109 | params = json.loads(line_type.params) | |
108 |
|
110 | |||
109 | for label, value in self.extra_fields.items(): |
|
111 | for label, value in self.extra_fields.items(): | |
110 | if label=='params': |
|
112 | if label=='params': | |
111 | continue |
|
113 | continue | |
112 |
|
114 | |||
113 | if 'model' in params[label]: |
|
115 | if 'model' in params[label]: | |
114 | self.fields[label] = forms.ChoiceField(choices=create_choices_from_model(params[label]['model'], |
|
116 | self.fields[label] = forms.ChoiceField(choices=create_choices_from_model(params[label]['model'], | |
115 | kwargs['initial']['rc_configuration']), |
|
117 | kwargs['initial']['rc_configuration']), | |
116 | initial=model_initial) |
|
118 | initial=model_initial) | |
117 |
|
119 | |||
118 |
|
120 | |||
119 | else: |
|
121 | else: | |
120 | if label=='codes' and 'code_id' in kwargs['initial']: |
|
122 | if label=='codes' and 'code_id' in kwargs['initial']: | |
121 | self.fields[label] = forms.CharField(initial=RCLineCode.objects.get(pk=kwargs['initial']['code_id']).codes) |
|
123 | self.fields[label] = forms.CharField(initial=RCLineCode.objects.get(pk=kwargs['initial']['code_id']).codes) | |
122 | else: |
|
124 | else: | |
123 | self.fields[label] = forms.CharField(initial=value['value']) |
|
125 | self.fields[label] = forms.CharField(initial=value['value']) | |
124 |
|
126 | |||
125 | if label=='codes': |
|
127 | if label=='codes': | |
126 | self.fields[label].widget = CodesWidget() |
|
128 | self.fields[label].widget = CodesWidget() | |
127 |
|
129 | |||
128 | if self.data: |
|
130 | if self.data: | |
129 | line_type = RCLineType.objects.get(pk=self.data['line_type']) |
|
131 | line_type = RCLineType.objects.get(pk=self.data['line_type']) | |
130 |
|
132 | |||
131 | if 'code_id' in self.data: |
|
133 | if 'code_id' in self.data: | |
132 | model_initial = self.data['code_id'] |
|
134 | model_initial = self.data['code_id'] | |
133 | else: |
|
135 | else: | |
134 | model_initial = 0 |
|
136 | model_initial = 0 | |
135 |
|
137 | |||
136 | params = json.loads(line_type.params) |
|
138 | params = json.loads(line_type.params) | |
137 |
|
139 | |||
138 | for label, value in self.extra_fields.items(): |
|
140 | for label, value in self.extra_fields.items(): | |
139 | if label=='params': |
|
141 | if label=='params': | |
140 | continue |
|
142 | continue | |
141 |
|
143 | |||
142 | if 'model' in params[label]: |
|
144 | if 'model' in params[label]: | |
143 | self.fields[label] = forms.ChoiceField(choices=create_choices_from_model(params[label]['model'], |
|
145 | self.fields[label] = forms.ChoiceField(choices=create_choices_from_model(params[label]['model'], | |
144 | self.data['rc_configuration']), |
|
146 | self.data['rc_configuration']), | |
145 | initial=model_initial) |
|
147 | initial=model_initial) | |
146 |
|
148 | |||
147 |
|
149 | |||
148 | else: |
|
150 | else: | |
149 | if label=='codes' and 'code' in self.data: |
|
151 | if label=='codes' and 'code' in self.data: | |
150 | self.fields[label] = forms.CharField(initial=self.data['codes']) |
|
152 | self.fields[label] = forms.CharField(initial=self.data['codes']) | |
151 | else: |
|
153 | else: | |
152 | self.fields[label] = forms.CharField(initial=self.data[label]) |
|
154 | self.fields[label] = forms.CharField(initial=self.data[label]) | |
153 |
|
155 | |||
154 | if label=='codes': |
|
156 | if label=='codes': | |
155 | self.fields[label].widget = CodesWidget() |
|
157 | self.fields[label].widget = CodesWidget() | |
156 |
|
158 | |||
157 |
|
159 | |||
158 | class Meta: |
|
160 | class Meta: | |
159 | model = RCLine |
|
161 | model = RCLine | |
160 | fields = ('rc_configuration', 'line_type', 'channel') |
|
162 | fields = ('rc_configuration', 'line_type', 'channel') | |
161 | widgets = { |
|
163 | widgets = { | |
162 | 'channel': forms.HiddenInput(), |
|
164 | 'channel': forms.HiddenInput(), | |
163 | } |
|
165 | } | |
164 |
|
166 | |||
165 |
|
167 | |||
166 | def clean(self): |
|
168 | def clean(self): | |
167 |
|
169 | |||
168 | form_data = self.cleaned_data |
|
170 | form_data = self.cleaned_data | |
169 | if 'code' in self.data and self.data['TX_ref']=="0": |
|
171 | if 'code' in self.data and self.data['TX_ref']=="0": | |
170 | self.add_error('TX_ref', 'Choose a valid TX reference') |
|
172 | self.add_error('TX_ref', 'Choose a valid TX reference') | |
171 |
|
173 | |||
172 | return form_data |
|
174 | return form_data | |
173 |
|
175 | |||
174 |
|
176 | |||
175 | def save(self): |
|
177 | def save(self): | |
176 | line = super(RCLineForm, self).save() |
|
178 | line = super(RCLineForm, self).save() | |
177 |
|
179 | |||
178 | #auto add channel |
|
180 | #auto add channel | |
179 | line.channel = RCLine.objects.filter(rc_configuration=line.rc_configuration).count()-1 |
|
181 | line.channel = RCLine.objects.filter(rc_configuration=line.rc_configuration).count()-1 | |
180 |
|
182 | |||
181 | #auto add position for TX, TR & CODE |
|
183 | #auto add position for TX, TR & CODE | |
182 | if line.line_type.name in ('tx', ): |
|
184 | if line.line_type.name in ('tx', ): | |
183 | line.position = RCLine.objects.filter(rc_configuration=line.rc_configuration, line_type=line.line_type).count()-1 |
|
185 | line.position = RCLine.objects.filter(rc_configuration=line.rc_configuration, line_type=line.line_type).count()-1 | |
184 |
|
186 | |||
185 | #save extra fields in params |
|
187 | #save extra fields in params | |
186 | params = {} |
|
188 | params = {} | |
187 | for label, value in self.extra_fields.items(): |
|
189 | for label, value in self.extra_fields.items(): | |
188 | if label=='params': |
|
190 | if label=='params': | |
189 | params['params'] = [] |
|
191 | params['params'] = [] | |
190 | elif label=='codes': |
|
192 | elif label=='codes': | |
191 | params[label] = [s for s in self.data[label].split('\r\n') if s] |
|
193 | params[label] = [s for s in self.data[label].split('\r\n') if s] | |
192 | else: |
|
194 | else: | |
193 | params[label] = self.data[label] |
|
195 | params[label] = self.data[label] | |
194 | line.params = json.dumps(params) |
|
196 | line.params = json.dumps(params) | |
195 | line.save() |
|
197 | line.save() | |
196 | return |
|
198 | return | |
197 |
|
199 | |||
198 |
|
200 | |||
199 | class RCLineViewForm(forms.Form): |
|
201 | class RCLineViewForm(forms.Form): | |
200 |
|
202 | |||
201 | def __init__(self, *args, **kwargs): |
|
203 | def __init__(self, *args, **kwargs): | |
202 |
|
204 | |||
203 | extra_fields = kwargs.pop('extra_fields') |
|
205 | extra_fields = kwargs.pop('extra_fields') | |
204 | line = kwargs.pop('line') |
|
206 | line = kwargs.pop('line') | |
205 | subform = kwargs.pop('subform', False) |
|
207 | subform = kwargs.pop('subform', False) | |
206 | super(RCLineViewForm, self).__init__(*args, **kwargs) |
|
208 | super(RCLineViewForm, self).__init__(*args, **kwargs) | |
207 |
|
209 | |||
208 | if subform: |
|
210 | if subform: | |
209 | params = json.loads(line.line_type.params)['params'] |
|
211 | params = json.loads(line.line_type.params)['params'] | |
210 | else: |
|
212 | else: | |
211 | params = json.loads(line.line_type.params) |
|
213 | params = json.loads(line.line_type.params) | |
212 |
|
214 | |||
213 | for label, value in extra_fields.items(): |
|
215 | for label, value in extra_fields.items(): | |
214 |
|
216 | |||
215 | if label=='params': |
|
217 | if label=='params': | |
216 | continue |
|
218 | continue | |
217 | if 'ref' in label: |
|
219 | if 'ref' in label: | |
218 | if value in (0, '0'): |
|
220 | if value in (0, '0'): | |
219 | value = 'All' |
|
221 | value = 'All' | |
220 | else: |
|
222 | else: | |
221 | value = RCLine.objects.get(pk=value).get_name() |
|
223 | value = RCLine.objects.get(pk=value).get_name() | |
222 | elif label=='code': |
|
224 | elif label=='code': | |
223 | value = RCLineCode.objects.get(pk=value).name |
|
225 | value = RCLineCode.objects.get(pk=value).name | |
224 |
|
226 | |||
225 | self.fields[label] = forms.CharField(initial=value) |
|
227 | self.fields[label] = forms.CharField(initial=value) | |
226 |
|
228 | |||
227 | if 'widget' in params[label]: |
|
229 | if 'widget' in params[label]: | |
228 | km2unit = line.rc_configuration.km2unit |
|
230 | km2unit = line.rc_configuration.km2unit | |
229 | if params[label]['widget']=='km': |
|
231 | if params[label]['widget']=='km': | |
230 | self.fields[label].widget = KmUnitWidget(attrs={'line':line, 'km2unit':km2unit, 'disabled':True}) |
|
232 | self.fields[label].widget = KmUnitWidget(attrs={'line':line, 'km2unit':km2unit, 'disabled':True}) | |
231 | elif params[label]['widget']=='unit': |
|
233 | elif params[label]['widget']=='unit': | |
232 | self.fields[label].widget = UnitKmWidget(attrs={'line':line, 'km2unit':km2unit, 'disabled':True}) |
|
234 | self.fields[label].widget = UnitKmWidget(attrs={'line':line, 'km2unit':km2unit, 'disabled':True}) | |
233 | elif params[label]['widget']=='dc': |
|
235 | elif params[label]['widget']=='dc': | |
234 | self.fields[label].widget = KmUnitDcWidget(attrs={'line':line, 'km2unit':km2unit, 'disabled':True}) |
|
236 | self.fields[label].widget = KmUnitDcWidget(attrs={'line':line, 'km2unit':km2unit, 'disabled':True}) | |
235 | elif params[label]['widget']=='codes': |
|
237 | elif params[label]['widget']=='codes': | |
236 | self.fields[label].widget = CodesWidget(attrs={'line':line, 'km2unit':km2unit, 'disabled':True}) |
|
238 | self.fields[label].widget = CodesWidget(attrs={'line':line, 'km2unit':km2unit, 'disabled':True}) | |
237 | else: |
|
239 | else: | |
238 | self.fields[label].widget = DefaultWidget(attrs={'disabled':True}) |
|
240 | self.fields[label].widget = DefaultWidget(attrs={'disabled':True}) | |
239 |
|
241 | |||
240 |
|
242 | |||
241 | class RCLineEditForm(forms.ModelForm): |
|
243 | class RCLineEditForm(forms.ModelForm): | |
242 |
|
244 | |||
243 | def __init__(self, *args, **kwargs): |
|
245 | def __init__(self, *args, **kwargs): | |
244 |
|
246 | |||
245 | extra_fields = kwargs.pop('extra_fields', []) |
|
247 | extra_fields = kwargs.pop('extra_fields', []) | |
246 | conf = kwargs.pop('conf', False) |
|
248 | conf = kwargs.pop('conf', False) | |
247 | line = kwargs.pop('line') |
|
249 | line = kwargs.pop('line') | |
248 | subform = kwargs.pop('subform', False) |
|
250 | subform = kwargs.pop('subform', False) | |
249 |
|
251 | |||
250 | super(RCLineEditForm, self).__init__(*args, **kwargs) |
|
252 | super(RCLineEditForm, self).__init__(*args, **kwargs) | |
251 |
|
253 | |||
252 | if subform is not False: |
|
254 | if subform is not False: | |
253 | params = json.loads(line.line_type.params)['params'] |
|
255 | params = json.loads(line.line_type.params)['params'] | |
254 | count = subform |
|
256 | count = subform | |
255 | else: |
|
257 | else: | |
256 | params = json.loads(line.line_type.params) |
|
258 | params = json.loads(line.line_type.params) | |
257 | count = -1 |
|
259 | count = -1 | |
258 |
|
260 | |||
259 | for label, value in extra_fields.items(): |
|
261 | for label, value in extra_fields.items(): | |
260 |
|
262 | |||
261 | if label in ('params',): |
|
263 | if label in ('params',): | |
262 | continue |
|
264 | continue | |
263 | if 'help' in params[label]: |
|
265 | if 'help' in params[label]: | |
264 | help_text = params[label]['help'] |
|
266 | help_text = params[label]['help'] | |
265 | else: |
|
267 | else: | |
266 | help_text = '' |
|
268 | help_text = '' | |
267 |
|
269 | |||
268 | if 'model' in params[label]: |
|
270 | if 'model' in params[label]: | |
269 | self.fields[label] = forms.ChoiceField(choices=create_choices_from_model(params[label]['model'], conf.id), |
|
271 | self.fields[label] = forms.ChoiceField(choices=create_choices_from_model(params[label]['model'], conf.id), | |
270 | initial=value, |
|
272 | initial=value, | |
271 | widget=forms.Select(attrs={'name':'%s|%s|%s' % (count, line.id, label)}), |
|
273 | widget=forms.Select(attrs={'name':'%s|%s|%s' % (count, line.id, label)}), | |
272 | help_text=help_text) |
|
274 | help_text=help_text) | |
273 |
|
275 | |||
274 | else: |
|
276 | else: | |
275 |
|
277 | |||
276 | self.fields[label] = forms.CharField(initial=value, help_text=help_text) |
|
278 | self.fields[label] = forms.CharField(initial=value, help_text=help_text) | |
277 |
|
279 | |||
278 | if label in ('code', ): |
|
280 | if label in ('code', ): | |
279 | self.fields[label].widget = HiddenWidget(attrs={'name':'%s|%s|%s' % (count, line.id, label)}) |
|
281 | self.fields[label].widget = HiddenWidget(attrs={'name':'%s|%s|%s' % (count, line.id, label)}) | |
280 |
|
282 | |||
281 | elif 'widget' in params[label]: |
|
283 | elif 'widget' in params[label]: | |
282 | km2unit = line.rc_configuration.km2unit |
|
284 | km2unit = line.rc_configuration.km2unit | |
283 | if params[label]['widget']=='km': |
|
285 | if params[label]['widget']=='km': | |
284 | self.fields[label].widget = KmUnitWidget(attrs={'line':line, 'km2unit':km2unit, 'name':'%s|%s|%s' % (count, line.id, label)}) |
|
286 | self.fields[label].widget = KmUnitWidget(attrs={'line':line, 'km2unit':km2unit, 'name':'%s|%s|%s' % (count, line.id, label)}) | |
285 | elif params[label]['widget']=='unit': |
|
287 | elif params[label]['widget']=='unit': | |
286 | self.fields[label].widget = UnitKmWidget(attrs={'line':line, 'km2unit':km2unit, 'name':'%s|%s|%s' % (count, line.id, label)}) |
|
288 | self.fields[label].widget = UnitKmWidget(attrs={'line':line, 'km2unit':km2unit, 'name':'%s|%s|%s' % (count, line.id, label)}) | |
287 | elif params[label]['widget']=='dc': |
|
289 | elif params[label]['widget']=='dc': | |
288 | self.fields[label].widget = KmUnitDcWidget(attrs={'line':line, 'km2unit':km2unit, 'name':'%s|%s|%s' % (count, line.id, label)}) |
|
290 | self.fields[label].widget = KmUnitDcWidget(attrs={'line':line, 'km2unit':km2unit, 'name':'%s|%s|%s' % (count, line.id, label)}) | |
289 | elif params[label]['widget']=='codes': |
|
291 | elif params[label]['widget']=='codes': | |
290 | self.fields[label].widget = CodesWidget(attrs={'line':line, 'km2unit':km2unit, 'name':'%s|%s|%s' % (count, line.id, label)}) |
|
292 | self.fields[label].widget = CodesWidget(attrs={'line':line, 'km2unit':km2unit, 'name':'%s|%s|%s' % (count, line.id, label)}) | |
291 | else: |
|
293 | else: | |
292 | self.fields[label].widget = DefaultWidget(attrs={'name':'%s|%s|%s' % (count, line.id, label)}) |
|
294 | self.fields[label].widget = DefaultWidget(attrs={'name':'%s|%s|%s' % (count, line.id, label)}) | |
293 |
|
295 | |||
294 |
|
296 | |||
295 | class Meta: |
|
297 | class Meta: | |
296 | model = RCLine |
|
298 | model = RCLine | |
297 | exclude = ('rc_configuration', 'line_type', 'channel', 'position', 'params', 'pulses') |
|
299 | exclude = ('rc_configuration', 'line_type', 'channel', 'position', 'params', 'pulses') | |
298 |
|
300 | |||
299 |
|
301 | |||
300 | class RCSubLineEditForm(forms.Form): |
|
302 | class RCSubLineEditForm(forms.Form): | |
301 |
|
303 | |||
302 | def __init__(self, *args, **kwargs): |
|
304 | def __init__(self, *args, **kwargs): | |
303 | extra_fields = kwargs.pop('extra_fields') |
|
305 | extra_fields = kwargs.pop('extra_fields') | |
304 | count = kwargs.pop('count') |
|
306 | count = kwargs.pop('count') | |
305 | line = kwargs.pop('line') |
|
307 | line = kwargs.pop('line') | |
306 | super(RCSubLineEditForm, self).__init__(*args, **kwargs) |
|
308 | super(RCSubLineEditForm, self).__init__(*args, **kwargs) | |
307 | for label, value in extra_fields.items(): |
|
309 | for label, value in extra_fields.items(): | |
308 | self.fields[label] = forms.CharField(initial=value, |
|
310 | self.fields[label] = forms.CharField(initial=value, | |
309 | widget=forms.TextInput(attrs={'name':'%s|%s|%s' % (count, line, label)})) |
|
311 | widget=forms.TextInput(attrs={'name':'%s|%s|%s' % (count, line, label)})) | |
310 |
|
312 | |||
311 |
|
313 | |||
312 | class RCImportForm(forms.Form): |
|
314 | class RCImportForm(forms.Form): | |
313 |
|
315 | |||
314 | file_name = ExtFileField(extensions=['.racp', '.json', '.dat']) |
|
316 | file_name = ExtFileField(extensions=['.racp', '.json', '.dat']) | |
315 |
|
317 | |||
316 |
|
318 | |||
317 | class RCLineCodesForm(forms.ModelForm): |
|
319 | class RCLineCodesForm(forms.ModelForm): | |
318 |
|
320 | |||
319 | def __init__(self, *args, **kwargs): |
|
321 | def __init__(self, *args, **kwargs): | |
320 | super(RCLineCodesForm, self).__init__(*args, **kwargs) |
|
322 | super(RCLineCodesForm, self).__init__(*args, **kwargs) | |
321 |
|
323 | |||
322 | if 'initial' in kwargs: |
|
324 | if 'initial' in kwargs: | |
323 | self.fields['code'] = forms.ChoiceField(choices=RCLineCode.objects.all().values_list('pk', 'name'), |
|
325 | self.fields['code'] = forms.ChoiceField(choices=RCLineCode.objects.all().values_list('pk', 'name'), | |
324 | initial=kwargs['initial']['code']) |
|
326 | initial=kwargs['initial']['code']) | |
325 | if 'instance' in kwargs: |
|
327 | if 'instance' in kwargs: | |
326 | self.fields['code'] = forms.ChoiceField(choices=RCLineCode.objects.all().values_list('pk', 'name'), |
|
328 | self.fields['code'] = forms.ChoiceField(choices=RCLineCode.objects.all().values_list('pk', 'name'), | |
327 | initial=kwargs['instance'].pk) |
|
329 | initial=kwargs['instance'].pk) | |
328 |
|
330 | |||
329 | self.fields['codes'].widget = CodesWidget() |
|
331 | self.fields['codes'].widget = CodesWidget() | |
330 |
|
332 | |||
331 |
|
333 | |||
332 | class Meta: |
|
334 | class Meta: | |
333 | model = RCLineCode |
|
335 | model = RCLineCode | |
334 | exclude = ('name',) |
|
336 | exclude = ('name',) | |
335 |
|
337 | |||
336 | No newline at end of file |
|
338 |
@@ -1,530 +1,559 | |||||
1 |
|
1 | |||
2 | import ast |
|
2 | import ast | |
3 | import json |
|
3 | import json | |
4 | import numpy as np |
|
4 | import numpy as np | |
5 |
|
5 | |||
6 | from polymorphic import PolymorphicModel |
|
6 | from polymorphic import PolymorphicModel | |
7 |
|
7 | |||
8 | from django.db import models |
|
8 | from django.db import models | |
9 | from django.core.urlresolvers import reverse |
|
9 | from django.core.urlresolvers import reverse | |
10 | from django.core.validators import MinValueValidator, MaxValueValidator |
|
10 | from django.core.validators import MinValueValidator, MaxValueValidator | |
11 |
|
11 | |||
12 | from apps.main.models import Configuration |
|
12 | from apps.main.models import Configuration | |
13 | from .utils import RCFile, pulses, pulses_from_code, create_mask, pulses_to_points |
|
13 | from .utils import RCFile, pulses, pulses_from_code, create_mask, pulses_to_points | |
14 |
|
14 | |||
15 | # Create your models here. |
|
15 | # Create your models here. | |
16 |
|
16 | |||
17 | LINE_TYPES = ( |
|
17 | LINE_TYPES = ( | |
18 | ('none', 'Not used'), |
|
18 | ('none', 'Not used'), | |
19 | ('tr', 'Transmission/reception selector signal'), |
|
19 | ('tr', 'Transmission/reception selector signal'), | |
20 | ('tx', 'A modulating signal (Transmission pulse)'), |
|
20 | ('tx', 'A modulating signal (Transmission pulse)'), | |
21 | ('codes', 'BPSK modulating signal'), |
|
21 | ('codes', 'BPSK modulating signal'), | |
22 | ('windows', 'Sample window signal'), |
|
22 | ('windows', 'Sample window signal'), | |
23 | ('sync', 'Synchronizing signal'), |
|
23 | ('sync', 'Synchronizing signal'), | |
24 | ('flip', 'IPP related periodic signal'), |
|
24 | ('flip', 'IPP related periodic signal'), | |
25 | ('prog_pulses', 'Programmable pulse'), |
|
25 | ('prog_pulses', 'Programmable pulse'), | |
26 | ) |
|
26 | ) | |
27 |
|
27 | |||
28 |
|
28 | |||
29 | SAMPLING_REFS = ( |
|
29 | SAMPLING_REFS = ( | |
30 | ('none', 'No Reference'), |
|
30 | ('none', 'No Reference'), | |
31 | ('first_baud', 'Middle of the first baud'), |
|
31 | ('first_baud', 'Middle of the first baud'), | |
32 | ('sub_baud', 'Middle of the sub-baud') |
|
32 | ('sub_baud', 'Middle of the sub-baud') | |
33 | ) |
|
33 | ) | |
34 |
|
34 | |||
35 | DAT_CMDS = { |
|
35 | DAT_CMDS = { | |
36 | # Pulse Design commands |
|
36 | # Pulse Design commands | |
37 | 'DISABLE' : 0, # Disables pulse generation |
|
37 | 'DISABLE' : 0, # Disables pulse generation | |
38 | 'ENABLE' : 24, # Enables pulse generation |
|
38 | 'ENABLE' : 24, # Enables pulse generation | |
39 | 'DELAY_START' : 40, # Write delay status to memory |
|
39 | 'DELAY_START' : 40, # Write delay status to memory | |
40 | 'FLIP_START' : 48, # Write flip status to memory |
|
40 | 'FLIP_START' : 48, # Write flip status to memory | |
41 | 'SAMPLING_PERIOD' : 64, # Establish Sampling Period |
|
41 | 'SAMPLING_PERIOD' : 64, # Establish Sampling Period | |
42 | 'TX_ONE' : 72, # Output '0' in line TX |
|
42 | 'TX_ONE' : 72, # Output '0' in line TX | |
43 | 'TX_ZERO' : 88, # Output '0' in line TX |
|
43 | 'TX_ZERO' : 88, # Output '0' in line TX | |
44 | 'SW_ONE' : 104, # Output '0' in line SW |
|
44 | 'SW_ONE' : 104, # Output '0' in line SW | |
45 | 'SW_ZERO' : 112, # Output '1' in line SW |
|
45 | 'SW_ZERO' : 112, # Output '1' in line SW | |
46 | 'RESTART': 120, # Restarts CR8 Firmware |
|
46 | 'RESTART': 120, # Restarts CR8 Firmware | |
47 | 'CONTINUE' : 253, # Function Unknown |
|
47 | 'CONTINUE' : 253, # Function Unknown | |
48 | # Commands available to new controllers |
|
48 | # Commands available to new controllers | |
49 | # In Pulse Design Executable, the clock divisor code is written as 12 at the start, but it should be written as code 22(below) just before the final enable. |
|
49 | # In Pulse Design Executable, the clock divisor code is written as 12 at the start, but it should be written as code 22(below) just before the final enable. | |
50 | 'CLOCK_DIVISOR_INIT' : 12, # Specifies Clock Divisor. Legacy command, ignored in the actual .dat conversion |
|
50 | 'CLOCK_DIVISOR_INIT' : 12, # Specifies Clock Divisor. Legacy command, ignored in the actual .dat conversion | |
51 | 'CLOCK_DIVISOR_LAST' : 22, # Specifies Clock Divisor (default 60 if not included) syntax: 255,22 254,N-1. |
|
51 | 'CLOCK_DIVISOR_LAST' : 22, # Specifies Clock Divisor (default 60 if not included) syntax: 255,22 254,N-1. | |
52 | 'CLOCK_DIVIDER' : 8, |
|
52 | 'CLOCK_DIVIDER' : 8, | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 |
|
55 | |||
56 | class RCConfiguration(Configuration): |
|
56 | class RCConfiguration(Configuration): | |
57 |
|
57 | |||
58 | ipp = models.FloatField(verbose_name='Inter pulse period (Km)', validators=[MinValueValidator(1), MaxValueValidator(1000)], default=10) |
|
58 | ipp = models.FloatField(verbose_name='Inter pulse period (Km)', validators=[MinValueValidator(1), MaxValueValidator(1000)], default=10) | |
59 | ntx = models.PositiveIntegerField(verbose_name='Number of TX', validators=[MinValueValidator(1), MaxValueValidator(256)], default=1) |
|
59 | ntx = models.PositiveIntegerField(verbose_name='Number of TX', validators=[MinValueValidator(1), MaxValueValidator(256)], default=1) | |
60 | clock_in = models.FloatField(verbose_name='Clock in (MHz)', validators=[MinValueValidator(1), MaxValueValidator(80)], default=1) |
|
60 | clock_in = models.FloatField(verbose_name='Clock in (MHz)', validators=[MinValueValidator(1), MaxValueValidator(80)], default=1) | |
61 | clock_divider = models.PositiveIntegerField(verbose_name='Clock divider', validators=[MinValueValidator(1), MaxValueValidator(256)], default=1) |
|
61 | clock_divider = models.PositiveIntegerField(verbose_name='Clock divider', validators=[MinValueValidator(1), MaxValueValidator(256)], default=1) | |
62 | clock = models.FloatField(verbose_name='Clock Master (MHz)', blank=True, default=1) |
|
62 | clock = models.FloatField(verbose_name='Clock Master (MHz)', blank=True, default=1) | |
63 | time_before = models.PositiveIntegerField(verbose_name='Time before (μS)', default=0) |
|
63 | time_before = models.PositiveIntegerField(verbose_name='Time before (μS)', default=0) | |
64 | time_after = models.PositiveIntegerField(verbose_name='Time after (μS)', default=0) |
|
64 | time_after = models.PositiveIntegerField(verbose_name='Time after (μS)', default=0) | |
65 | sync = models.PositiveIntegerField(verbose_name='Synchro delay', default=0) |
|
65 | sync = models.PositiveIntegerField(verbose_name='Synchro delay', default=0) | |
66 | sampling_reference = models.CharField(verbose_name='Sampling Reference', choices=SAMPLING_REFS, default='none', max_length=40) |
|
66 | sampling_reference = models.CharField(verbose_name='Sampling Reference', choices=SAMPLING_REFS, default='none', max_length=40) | |
67 | control_tx = models.BooleanField(verbose_name='Control Switch TX', default=False) |
|
67 | control_tx = models.BooleanField(verbose_name='Control Switch TX', default=False) | |
68 | control_sw = models.BooleanField(verbose_name='Control Switch SW', default=False) |
|
68 | control_sw = models.BooleanField(verbose_name='Control Switch SW', default=False) | |
69 |
|
69 | |||
70 |
|
70 | |||
71 | class Meta: |
|
71 | class Meta: | |
72 | db_table = 'rc_configurations' |
|
72 | db_table = 'rc_configurations' | |
73 |
|
73 | |||
74 |
|
74 | |||
75 | def get_absolute_url_plot(self): |
|
75 | def get_absolute_url_plot(self): | |
76 | return reverse('url_plot_rc_pulses', args=[str(self.id)]) |
|
76 | return reverse('url_plot_rc_pulses', args=[str(self.id)]) | |
77 |
|
77 | |||
78 | def get_absolute_url_import(self): |
|
78 | def get_absolute_url_import(self): | |
79 | return reverse('url_import_rc_conf', args=[str(self.id)]) |
|
79 | return reverse('url_import_rc_conf', args=[str(self.id)]) | |
80 |
|
80 | |||
81 | @property |
|
81 | @property | |
82 | def us2unit(self): |
|
82 | def us2unit(self): | |
83 |
|
83 | |||
84 | return self.clock_in/self.clock_divider |
|
84 | return self.clock_in/self.clock_divider | |
85 |
|
85 | |||
86 |
|
86 | |||
87 | @property |
|
87 | @property | |
88 | def km2unit(self): |
|
88 | def km2unit(self): | |
89 |
|
89 | |||
90 | return 20./3*(self.clock_in/self.clock_divider) |
|
90 | return 20./3*(self.clock_in/self.clock_divider) | |
91 |
|
91 | |||
92 |
|
92 | |||
|
93 | def clone(self, **kwargs): | |||
|
94 | ||||
|
95 | lines = self.get_lines() | |||
|
96 | self.pk = None | |||
|
97 | self.id = None | |||
|
98 | for attr, value in kwargs.items(): | |||
|
99 | setattr(self, attr, value) | |||
|
100 | self.save() | |||
|
101 | ||||
|
102 | for line in lines: | |||
|
103 | line.clone(rc_configuration=self) | |||
|
104 | ||||
|
105 | return self | |||
|
106 | ||||
93 | def get_lines(self, type=None): |
|
107 | def get_lines(self, type=None): | |
94 | ''' |
|
108 | ''' | |
95 | Retrieve configuration lines |
|
109 | Retrieve configuration lines | |
96 | ''' |
|
110 | ''' | |
97 |
|
111 | |||
98 | if type is not None: |
|
112 | if type is not None: | |
99 | return RCLine.objects.filter(rc_configuration=self.pk, line_type__name=type) |
|
113 | return RCLine.objects.filter(rc_configuration=self.pk, line_type__name=type) | |
100 | else: |
|
114 | else: | |
101 | return RCLine.objects.filter(rc_configuration=self.pk) |
|
115 | return RCLine.objects.filter(rc_configuration=self.pk) | |
102 |
|
116 | |||
103 | def clean_lines(self): |
|
117 | def clean_lines(self): | |
104 | ''' |
|
118 | ''' | |
105 | ''' |
|
119 | ''' | |
106 |
|
120 | |||
107 | empty_line = RCLineType.objects.get(pk=8) |
|
121 | empty_line = RCLineType.objects.get(pk=8) | |
108 |
|
122 | |||
109 | for line in self.get_lines(): |
|
123 | for line in self.get_lines(): | |
110 | line.line_type = empty_line |
|
124 | line.line_type = empty_line | |
111 | line.params = '{}' |
|
125 | line.params = '{}' | |
112 | line.save() |
|
126 | line.save() | |
113 |
|
127 | |||
114 | def parms_to_dict(self): |
|
128 | def parms_to_dict(self): | |
115 | ''' |
|
129 | ''' | |
116 | ''' |
|
130 | ''' | |
117 |
|
131 | |||
118 | data = {} |
|
132 | data = {} | |
119 | for field in self._meta.fields: |
|
133 | for field in self._meta.fields: | |
120 |
|
134 | |||
121 | data[field.name] = '{}'.format(field.value_from_object(self)) |
|
135 | data[field.name] = '{}'.format(field.value_from_object(self)) | |
122 |
|
136 | |||
123 | data.pop('parameters') |
|
137 | data.pop('parameters') | |
124 | data['lines'] = [] |
|
138 | data['lines'] = [] | |
125 |
|
139 | |||
126 | for line in self.get_lines(): |
|
140 | for line in self.get_lines(): | |
127 | line_data = json.loads(line.params) |
|
141 | line_data = json.loads(line.params) | |
128 | if 'TX_ref' in line_data and line_data['TX_ref'] not in (0, '0'): |
|
142 | if 'TX_ref' in line_data and line_data['TX_ref'] not in (0, '0'): | |
129 | line_data['TX_ref'] = RCLine.objects.get(pk=line_data['TX_ref']).get_name() |
|
143 | line_data['TX_ref'] = RCLine.objects.get(pk=line_data['TX_ref']).get_name() | |
130 | if 'code' in line_data: |
|
144 | if 'code' in line_data: | |
131 | line_data['code'] = RCLineCode.objects.get(pk=line_data['code']).name |
|
145 | line_data['code'] = RCLineCode.objects.get(pk=line_data['code']).name | |
132 | line_data['type'] = line.line_type.name |
|
146 | line_data['type'] = line.line_type.name | |
133 | data['lines'].append(line_data) |
|
147 | data['lines'].append(line_data) | |
134 |
|
148 | |||
135 |
|
149 | |||
136 | return data |
|
150 | return data | |
137 |
|
151 | |||
138 | def get_delays(self): |
|
152 | def get_delays(self): | |
139 |
|
153 | |||
140 | pulses = [line.get_pulses() for line in self.get_lines()] |
|
154 | pulses = [line.get_pulses() for line in self.get_lines()] | |
141 | points = [tup for tups in pulses for tup in tups] |
|
155 | points = [tup for tups in pulses for tup in tups] | |
142 | points = set([x for tup in points for x in tup]) |
|
156 | points = set([x for tup in points for x in tup]) | |
143 | points = list(points) |
|
157 | points = list(points) | |
144 | points.sort() |
|
158 | points.sort() | |
145 |
|
159 | |||
146 | if points[0]<>0: |
|
160 | if points[0]<>0: | |
147 | points.insert(0, 0) |
|
161 | points.insert(0, 0) | |
148 |
|
162 | |||
149 | return [points[i+1]-points[i] for i in range(len(points)-1)] |
|
163 | return [points[i+1]-points[i] for i in range(len(points)-1)] | |
150 |
|
164 | |||
151 |
|
165 | |||
152 | def get_flips(self): |
|
166 | def get_flips(self): | |
153 |
|
167 | |||
154 | line_points = [pulses_to_points(line.pulses_as_array()) for line in self.get_lines()] |
|
168 | line_points = [pulses_to_points(line.pulses_as_array()) for line in self.get_lines()] | |
155 | line_points = [[(x, x+y) for x,y in tups] for tups in line_points] |
|
169 | line_points = [[(x, x+y) for x,y in tups] for tups in line_points] | |
156 | line_points = [[t for x in tups for t in x] for tups in line_points] |
|
170 | line_points = [[t for x in tups for t in x] for tups in line_points] | |
157 | states = [[1 if x in tups else 0 for tups in line_points] for x in points] |
|
171 | states = [[1 if x in tups else 0 for tups in line_points] for x in points] | |
158 |
|
172 | |||
159 | return states |
|
173 | return states | |
160 |
|
174 | |||
161 | def add_cmd(self, cmd): |
|
175 | def add_cmd(self, cmd): | |
162 |
|
176 | |||
163 | if cmd in DAT_CMDS: |
|
177 | if cmd in DAT_CMDS: | |
164 | return (255, DAT_CMDS[cmd]) |
|
178 | return (255, DAT_CMDS[cmd]) | |
165 |
|
179 | |||
166 | def add_data(self, value): |
|
180 | def add_data(self, value): | |
167 |
|
181 | |||
168 | return (254, value-1) |
|
182 | return (254, value-1) | |
169 |
|
183 | |||
170 | def parms_to_binary(self): |
|
184 | def parms_to_binary(self): | |
171 | ''' |
|
185 | ''' | |
172 | Create "dat" stream to be send to CR |
|
186 | Create "dat" stream to be send to CR | |
173 | ''' |
|
187 | ''' | |
174 |
|
188 | |||
175 | data = [] |
|
189 | data = [] | |
176 | # create header |
|
190 | # create header | |
177 | data.append(self.add_cmd('DISABLE')) |
|
191 | data.append(self.add_cmd('DISABLE')) | |
178 | data.append(self.add_cmd('CONTINUE')) |
|
192 | data.append(self.add_cmd('CONTINUE')) | |
179 | data.append(self.add_cmd('RESTART')) |
|
193 | data.append(self.add_cmd('RESTART')) | |
180 |
|
194 | |||
181 | if self.control_sw: |
|
195 | if self.control_sw: | |
182 | data.append(self.add_cmd('SW_ONE')) |
|
196 | data.append(self.add_cmd('SW_ONE')) | |
183 | else: |
|
197 | else: | |
184 | data.append(self.add_cmd('SW_ZERO')) |
|
198 | data.append(self.add_cmd('SW_ZERO')) | |
185 |
|
199 | |||
186 | if self.control_tx: |
|
200 | if self.control_tx: | |
187 | data.append(self.add_cmd('TX_ONE')) |
|
201 | data.append(self.add_cmd('TX_ONE')) | |
188 | else: |
|
202 | else: | |
189 | data.append(self.add_cmd('TX_ZERO')) |
|
203 | data.append(self.add_cmd('TX_ZERO')) | |
190 |
|
204 | |||
191 | # write divider |
|
205 | # write divider | |
192 | data.append(self.add_cmd('CLOCK_DIVIDER')) |
|
206 | data.append(self.add_cmd('CLOCK_DIVIDER')) | |
193 | data.append(self.add_data(self.clock_divider)) |
|
207 | data.append(self.add_data(self.clock_divider)) | |
194 |
|
208 | |||
195 | # write delays |
|
209 | # write delays | |
196 | data.append(self.add_cmd('DELAY_START')) |
|
210 | data.append(self.add_cmd('DELAY_START')) | |
197 | # first delay is always zero |
|
211 | # first delay is always zero | |
198 | data.append(self.add_data(1)) |
|
212 | data.append(self.add_data(1)) | |
199 | line_points = [pulses_to_points(line.pulses_as_array()) for line in self.get_lines()] |
|
213 | line_points = [pulses_to_points(line.pulses_as_array()) for line in self.get_lines()] | |
200 | points = [tup for tups in line_points for tup in tups] |
|
214 | points = [tup for tups in line_points for tup in tups] | |
201 | points = [(x, x+y) for x,y in points] |
|
215 | points = [(x, x+y) for x,y in points] | |
202 | points = set([x for tup in points for x in tup]) |
|
216 | points = set([x for tup in points for x in tup]) | |
203 | points = list(points) |
|
217 | points = list(points) | |
204 | points.sort() |
|
218 | points.sort() | |
205 |
|
219 | |||
206 | if points[0]<>0: |
|
220 | if points[0]<>0: | |
207 | points.insert(0, 0) |
|
221 | points.insert(0, 0) | |
208 |
|
222 | |||
209 | delays = [points[i+1]-points[i] for i in range(len(points)-1)] |
|
223 | delays = [points[i+1]-points[i] for i in range(len(points)-1)] | |
210 |
|
224 | |||
211 | for delay in delays: |
|
225 | for delay in delays: | |
212 | while delay>252: |
|
226 | while delay>252: | |
213 | data.append(self.add_data(253)) |
|
227 | data.append(self.add_data(253)) | |
214 | delay -= 253 |
|
228 | delay -= 253 | |
215 | data.append(self.add_data(delay)) |
|
229 | data.append(self.add_data(delay)) | |
216 |
|
230 | |||
217 | # write flips |
|
231 | # write flips | |
218 | data.append(self.add_cmd('FLIP_START')) |
|
232 | data.append(self.add_cmd('FLIP_START')) | |
219 | line_points = [[(x, x+y) for x,y in tups] for tups in line_points] |
|
233 | line_points = [[(x, x+y) for x,y in tups] for tups in line_points] | |
220 | line_points = [[t for x in tups for t in x] for tups in line_points] |
|
234 | line_points = [[t for x in tups for t in x] for tups in line_points] | |
221 | states = [[1 if x in tups else 0 for tups in line_points] for x in points] |
|
235 | states = [[1 if x in tups else 0 for tups in line_points] for x in points] | |
222 | for flips, delay in zip(states[:-1], delays): |
|
236 | for flips, delay in zip(states[:-1], delays): | |
223 | flips.reverse() |
|
237 | flips.reverse() | |
224 | flip = int(''.join([str(x) for x in flips]), 2) |
|
238 | flip = int(''.join([str(x) for x in flips]), 2) | |
225 | data.append(self.add_data(flip+1)) |
|
239 | data.append(self.add_data(flip+1)) | |
226 | while delay>252: |
|
240 | while delay>252: | |
227 | data.append(self.add_data(1)) |
|
241 | data.append(self.add_data(1)) | |
228 | delay -= 253 |
|
242 | delay -= 253 | |
229 |
|
243 | |||
230 | # write sampling period |
|
244 | # write sampling period | |
231 | data.append(self.add_cmd('SAMPLING_PERIOD')) |
|
245 | data.append(self.add_cmd('SAMPLING_PERIOD')) | |
232 | wins = self.get_lines(type='windows') |
|
246 | wins = self.get_lines(type='windows') | |
233 | if wins: |
|
247 | if wins: | |
234 | win_params = json.loads(wins[0].params)['params'] |
|
248 | win_params = json.loads(wins[0].params)['params'] | |
235 | if win_params: |
|
249 | if win_params: | |
236 | dh = int(win_params[0]['resolution']*self.km2unit) |
|
250 | dh = int(win_params[0]['resolution']*self.km2unit) | |
237 | else: |
|
251 | else: | |
238 | dh = 1 |
|
252 | dh = 1 | |
239 | else: |
|
253 | else: | |
240 | dh = 1 |
|
254 | dh = 1 | |
241 | data.append(self.add_data(dh)) |
|
255 | data.append(self.add_data(dh)) | |
242 |
|
256 | |||
243 | # write enable |
|
257 | # write enable | |
244 | data.append(self.add_cmd('ENABLE')) |
|
258 | data.append(self.add_cmd('ENABLE')) | |
245 |
|
259 | |||
246 | return '\n'.join(['{}'.format(x) for tup in data for x in tup]) |
|
260 | return '\n'.join(['{}'.format(x) for tup in data for x in tup]) | |
247 |
|
261 | |||
248 | def update_from_file(self, filename): |
|
262 | def update_from_file(self, filename): | |
249 | ''' |
|
263 | ''' | |
250 | Update instance from file |
|
264 | Update instance from file | |
251 | ''' |
|
265 | ''' | |
252 |
|
266 | |||
253 | f = RCFile(filename) |
|
267 | f = RCFile(filename) | |
254 | data = f.data |
|
268 | data = f.data | |
255 | self.name = data['name'] |
|
269 | self.name = data['name'] | |
256 | self.ipp = data['ipp'] |
|
270 | self.ipp = data['ipp'] | |
257 | self.ntx = data['ntx'] |
|
271 | self.ntx = data['ntx'] | |
258 | self.clock_in = data['clock_in'] |
|
272 | self.clock_in = data['clock_in'] | |
259 | self.clock_divider = data['clock_divider'] |
|
273 | self.clock_divider = data['clock_divider'] | |
260 | self.clock = data['clock'] |
|
274 | self.clock = data['clock'] | |
261 | self.time_before = data['time_before'] |
|
275 | self.time_before = data['time_before'] | |
262 | self.time_after = data['time_after'] |
|
276 | self.time_after = data['time_after'] | |
263 | self.sync = data['sync'] |
|
277 | self.sync = data['sync'] | |
264 | self.sampling_reference = data['sampling_reference'] |
|
278 | self.sampling_reference = data['sampling_reference'] | |
265 | self.clean_lines() |
|
279 | self.clean_lines() | |
266 |
|
280 | |||
267 | lines = [] |
|
281 | lines = [] | |
268 | positions = {'tx':0, 'tr':0} |
|
282 | positions = {'tx':0, 'tr':0} | |
269 |
|
283 | |||
270 | for i, line_data in enumerate(data['lines']): |
|
284 | for i, line_data in enumerate(data['lines']): | |
271 | line_type = RCLineType.objects.get(name=line_data.pop('type')) |
|
285 | line_type = RCLineType.objects.get(name=line_data.pop('type')) | |
272 | if line_type.name=='codes': |
|
286 | if line_type.name=='codes': | |
273 | code = RCLineCode.objects.get(name=line_data['code']) |
|
287 | code = RCLineCode.objects.get(name=line_data['code']) | |
274 | line_data['code'] = code.pk |
|
288 | line_data['code'] = code.pk | |
275 | line = RCLine.objects.filter(rc_configuration=self, channel=i) |
|
289 | line = RCLine.objects.filter(rc_configuration=self, channel=i) | |
276 | if line: |
|
290 | if line: | |
277 | line = line[0] |
|
291 | line = line[0] | |
278 | line.line_type = line_type |
|
292 | line.line_type = line_type | |
279 | line.params = json.dumps(line_data) |
|
293 | line.params = json.dumps(line_data) | |
280 | else: |
|
294 | else: | |
281 | line = RCLine(rc_configuration=self, line_type=line_type, |
|
295 | line = RCLine(rc_configuration=self, line_type=line_type, | |
282 | params=json.dumps(line_data), |
|
296 | params=json.dumps(line_data), | |
283 | channel=i) |
|
297 | channel=i) | |
284 |
|
298 | |||
285 | if line_type.name=='tx': |
|
299 | if line_type.name=='tx': | |
286 | line.position = positions['tx'] |
|
300 | line.position = positions['tx'] | |
287 | positions['tx'] += 1 |
|
301 | positions['tx'] += 1 | |
288 |
|
302 | |||
289 | if line_type.name=='tr': |
|
303 | if line_type.name=='tr': | |
290 | line.position = positions['tr'] |
|
304 | line.position = positions['tr'] | |
291 | positions['tr'] += 1 |
|
305 | positions['tr'] += 1 | |
292 |
|
306 | |||
293 | line.save() |
|
307 | line.save() | |
294 | lines.append(line) |
|
308 | lines.append(line) | |
295 |
|
309 | |||
296 | for line, line_data in zip(lines, data['lines']): |
|
310 | for line, line_data in zip(lines, data['lines']): | |
297 | if 'TX_ref' in line_data: |
|
311 | if 'TX_ref' in line_data: | |
298 | params = json.loads(line.params) |
|
312 | params = json.loads(line.params) | |
299 | if line_data['TX_ref'] in (0, '0'): |
|
313 | if line_data['TX_ref'] in (0, '0'): | |
300 | params['TX_ref'] = '0' |
|
314 | params['TX_ref'] = '0' | |
301 | else: |
|
315 | else: | |
302 | params['TX_ref'] = [l.pk for l in lines if l.line_type.name=='tx' and l.get_name()==line_data['TX_ref']][0] |
|
316 | params['TX_ref'] = [l.pk for l in lines if l.line_type.name=='tx' and l.get_name()==line_data['TX_ref']][0] | |
303 | line.params = json.dumps(params) |
|
317 | line.params = json.dumps(params) | |
304 | line.save() |
|
318 | line.save() | |
305 |
|
319 | |||
306 |
|
320 | |||
|
321 | def status_device(self): | |||
|
322 | ||||
|
323 | return 0 | |||
|
324 | ||||
307 | class RCLineCode(models.Model): |
|
325 | class RCLineCode(models.Model): | |
308 |
|
326 | |||
309 | name = models.CharField(max_length=40) |
|
327 | name = models.CharField(max_length=40) | |
310 | bits_per_code = models.PositiveIntegerField(default=0) |
|
328 | bits_per_code = models.PositiveIntegerField(default=0) | |
311 | number_of_codes = models.PositiveIntegerField(default=0) |
|
329 | number_of_codes = models.PositiveIntegerField(default=0) | |
312 | codes = models.TextField(blank=True, null=True) |
|
330 | codes = models.TextField(blank=True, null=True) | |
313 |
|
331 | |||
314 | class Meta: |
|
332 | class Meta: | |
315 | db_table = 'rc_line_codes' |
|
333 | db_table = 'rc_line_codes' | |
316 | ordering = ('name',) |
|
334 | ordering = ('name',) | |
317 |
|
335 | |||
318 | def __unicode__(self): |
|
336 | def __unicode__(self): | |
319 | return u'%s' % self.name |
|
337 | return u'%s' % self.name | |
320 |
|
338 | |||
321 | class RCLineType(models.Model): |
|
339 | class RCLineType(models.Model): | |
322 |
|
340 | |||
323 | name = models.CharField(choices=LINE_TYPES, max_length=40) |
|
341 | name = models.CharField(choices=LINE_TYPES, max_length=40) | |
324 | description = models.TextField(blank=True, null=True) |
|
342 | description = models.TextField(blank=True, null=True) | |
325 | params = models.TextField(default='[]') |
|
343 | params = models.TextField(default='[]') | |
326 |
|
344 | |||
327 | class Meta: |
|
345 | class Meta: | |
328 | db_table = 'rc_line_types' |
|
346 | db_table = 'rc_line_types' | |
329 |
|
347 | |||
330 | def __unicode__(self): |
|
348 | def __unicode__(self): | |
331 | return u'%s - %s' % (self.name.upper(), self.get_name_display()) |
|
349 | return u'%s - %s' % (self.name.upper(), self.get_name_display()) | |
332 |
|
350 | |||
333 |
|
351 | |||
334 | class RCLine(models.Model): |
|
352 | class RCLine(models.Model): | |
335 |
|
353 | |||
336 | rc_configuration = models.ForeignKey(RCConfiguration) |
|
354 | rc_configuration = models.ForeignKey(RCConfiguration, on_delete=models.CASCADE) | |
337 | line_type = models.ForeignKey(RCLineType) |
|
355 | line_type = models.ForeignKey(RCLineType) | |
338 | channel = models.PositiveIntegerField(default=0) |
|
356 | channel = models.PositiveIntegerField(default=0) | |
339 | position = models.PositiveIntegerField(default=0) |
|
357 | position = models.PositiveIntegerField(default=0) | |
340 | params = models.TextField(default='{}') |
|
358 | params = models.TextField(default='{}') | |
341 | pulses = models.TextField(default='') |
|
359 | pulses = models.TextField(default='') | |
342 |
|
360 | |||
343 | class Meta: |
|
361 | class Meta: | |
344 | db_table = 'rc_lines' |
|
362 | db_table = 'rc_lines' | |
345 | ordering = ['channel'] |
|
363 | ordering = ['channel'] | |
346 |
|
364 | |||
347 | def __unicode__(self): |
|
365 | def __unicode__(self): | |
348 | if self.rc_configuration: |
|
366 | if self.rc_configuration: | |
349 | return u'%s - %s' % (self.rc_configuration, self.get_name()) |
|
367 | return u'%s - %s' % (self.rc_configuration, self.get_name()) | |
350 |
|
368 | |||
|
369 | def clone(self, **kwargs): | |||
|
370 | ||||
|
371 | self.pk = None | |||
|
372 | ||||
|
373 | for attr, value in kwargs.items(): | |||
|
374 | setattr(self, attr, value) | |||
|
375 | ||||
|
376 | self.save() | |||
|
377 | ||||
|
378 | return self | |||
|
379 | ||||
351 | def get_name(self): |
|
380 | def get_name(self): | |
352 |
|
381 | |||
353 | chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
|
382 | chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | |
354 |
|
383 | |||
355 | if self.line_type.name in ('tx',): |
|
384 | if self.line_type.name in ('tx',): | |
356 | return '%s%s' % (self.line_type.name.upper(), chars[self.position]) |
|
385 | return '%s%s' % (self.line_type.name.upper(), chars[self.position]) | |
357 | elif self.line_type.name in ('codes', 'windows', 'tr'): |
|
386 | elif self.line_type.name in ('codes', 'windows', 'tr'): | |
358 | if 'TX_ref' not in json.loads(self.params): |
|
387 | if 'TX_ref' not in json.loads(self.params): | |
359 | return self.line_type.name.upper() |
|
388 | return self.line_type.name.upper() | |
360 | pk = json.loads(self.params)['TX_ref'] |
|
389 | pk = json.loads(self.params)['TX_ref'] | |
361 | if pk in (0, '0'): |
|
390 | if pk in (0, '0'): | |
362 | refs = ','.join(chars[l.position] for l in self.rc_configuration.get_lines('tx')) |
|
391 | refs = ','.join(chars[l.position] for l in self.rc_configuration.get_lines('tx')) | |
363 | return '%s (%s)' % (self.line_type.name.upper(), refs) |
|
392 | return '%s (%s)' % (self.line_type.name.upper(), refs) | |
364 | else: |
|
393 | else: | |
365 | ref = RCLine.objects.get(pk=pk) |
|
394 | ref = RCLine.objects.get(pk=pk) | |
366 | return '%s (%s)' % (self.line_type.name.upper(), chars[ref.position]) |
|
395 | return '%s (%s)' % (self.line_type.name.upper(), chars[ref.position]) | |
367 | elif self.line_type.name in ('flip', 'prog_pulses', 'sync', 'none'): |
|
396 | elif self.line_type.name in ('flip', 'prog_pulses', 'sync', 'none'): | |
368 | return '%s %s' % (self.line_type.name.upper(), self.channel) |
|
397 | return '%s %s' % (self.line_type.name.upper(), self.channel) | |
369 | else: |
|
398 | else: | |
370 | return self.line_type.name.upper() |
|
399 | return self.line_type.name.upper() | |
371 |
|
400 | |||
372 | def get_lines(self, type=None): |
|
401 | def get_lines(self, type=None): | |
373 |
|
402 | |||
374 | if type is not None: |
|
403 | if type is not None: | |
375 | return RCLine.objects.filter(rc_configuration=self.rc_configuration, line_type__name=type) |
|
404 | return RCLine.objects.filter(rc_configuration=self.rc_configuration, line_type__name=type) | |
376 | else: |
|
405 | else: | |
377 | return RCLine.objects.filter(rc_configuration=self.rc_configuration) |
|
406 | return RCLine.objects.filter(rc_configuration=self.rc_configuration) | |
378 |
|
407 | |||
379 |
|
408 | |||
380 | def pulses_as_array(self): |
|
409 | def pulses_as_array(self): | |
381 |
|
410 | |||
382 | return (np.fromstring(self.pulses, dtype=np.uint8)-48).astype(np.int8) |
|
411 | return (np.fromstring(self.pulses, dtype=np.uint8)-48).astype(np.int8) | |
383 |
|
412 | |||
384 |
|
413 | |||
385 | def get_pulses(self): |
|
414 | def get_pulses(self): | |
386 |
|
415 | |||
387 | X = self.pulses_as_array() |
|
416 | X = self.pulses_as_array() | |
388 |
|
417 | |||
389 | d = X[1:]-X[:-1] |
|
418 | d = X[1:]-X[:-1] | |
390 |
|
419 | |||
391 | up = np.where(d==1)[0] |
|
420 | up = np.where(d==1)[0] | |
392 | if X[0]==1: |
|
421 | if X[0]==1: | |
393 | up = np.concatenate((np.array([-1]), up)) |
|
422 | up = np.concatenate((np.array([-1]), up)) | |
394 | up += 1 |
|
423 | up += 1 | |
395 |
|
424 | |||
396 | dw = np.where(d==-1)[0] |
|
425 | dw = np.where(d==-1)[0] | |
397 | if X[-1]==1: |
|
426 | if X[-1]==1: | |
398 | dw = np.concatenate((dw, np.array([len(X)-1]))) |
|
427 | dw = np.concatenate((dw, np.array([len(X)-1]))) | |
399 | dw += 1 |
|
428 | dw += 1 | |
400 |
|
429 | |||
401 | return [(tup[0], tup[1]) for tup in zip(up, dw)] |
|
430 | return [(tup[0], tup[1]) for tup in zip(up, dw)] | |
402 |
|
431 | |||
403 | def get_win_ref(self, params, tx_id, km2unit): |
|
432 | def get_win_ref(self, params, tx_id, km2unit): | |
404 |
|
433 | |||
405 | ref = self.rc_configuration.sampling_reference |
|
434 | ref = self.rc_configuration.sampling_reference | |
406 |
|
435 | |||
407 | codes = [line for line in self.get_lines(type='code') if int(json.loads(line.params)['TX_ref'])==int(tx_id)] |
|
436 | codes = [line for line in self.get_lines(type='code') if int(json.loads(line.params)['TX_ref'])==int(tx_id)] | |
408 |
|
437 | |||
409 | if codes: |
|
438 | if codes: | |
410 | code_line = RCLineCode.objects.get(pk=json.loads(codes[0].params)['code']) |
|
439 | code_line = RCLineCode.objects.get(pk=json.loads(codes[0].params)['code']) | |
411 | tx_width = float(json.loads(RCLine.objects.get(pk=tx_id).params)['pulse_width'])*km2unit/code_line.bits_per_code |
|
440 | tx_width = float(json.loads(RCLine.objects.get(pk=tx_id).params)['pulse_width'])*km2unit/code_line.bits_per_code | |
412 | else: |
|
441 | else: | |
413 | tx_width = float(json.loads(RCLine.objects.get(pk=tx_id).params)['pulse_width'])*km2unit |
|
442 | tx_width = float(json.loads(RCLine.objects.get(pk=tx_id).params)['pulse_width'])*km2unit | |
414 |
|
443 | |||
415 | if ref=='first_baud': |
|
444 | if ref=='first_baud': | |
416 | return int(1 + (tx_width + 1)/2 + params['first_height']*km2unit - params['resolution']*km2unit) |
|
445 | return int(1 + (tx_width + 1)/2 + params['first_height']*km2unit - params['resolution']*km2unit) | |
417 | elif ref=='sub_baud': |
|
446 | elif ref=='sub_baud': | |
418 | return int(1 + params['first_height']*km2unit - params['resolution']*km2unit/2) |
|
447 | return int(1 + params['first_height']*km2unit - params['resolution']*km2unit/2) | |
419 | else: |
|
448 | else: | |
420 | return 0 |
|
449 | return 0 | |
421 |
|
450 | |||
422 | def update_pulses(self, save=True, tr=False): |
|
451 | def update_pulses(self, save=True, tr=False): | |
423 | ''' |
|
452 | ''' | |
424 | Update pulses field |
|
453 | Update pulses field | |
425 | ''' |
|
454 | ''' | |
426 |
|
455 | |||
427 | km2unit = self.rc_configuration.km2unit |
|
456 | km2unit = self.rc_configuration.km2unit | |
428 | us2unit = self.rc_configuration.us2unit |
|
457 | us2unit = self.rc_configuration.us2unit | |
429 | ipp = self.rc_configuration.ipp |
|
458 | ipp = self.rc_configuration.ipp | |
430 | ntx = self.rc_configuration.ntx |
|
459 | ntx = self.rc_configuration.ntx | |
431 | ipp_u = int(ipp*km2unit) |
|
460 | ipp_u = int(ipp*km2unit) | |
432 |
|
461 | |||
433 | x = np.arange(0, ipp_u*ntx) |
|
462 | x = np.arange(0, ipp_u*ntx) | |
434 |
|
463 | |||
435 | if self.line_type.name=='tr': |
|
464 | if self.line_type.name=='tr': | |
436 | params = json.loads(self.params) |
|
465 | params = json.loads(self.params) | |
437 | if params['TX_ref'] in ('0', 0): |
|
466 | if params['TX_ref'] in ('0', 0): | |
438 | txs = [tx.update_pulses(save=False, tr=True) for tx in self.get_lines('tx')] |
|
467 | txs = [tx.update_pulses(save=False, tr=True) for tx in self.get_lines('tx')] | |
439 | else: |
|
468 | else: | |
440 | txs = [tx.update_pulses(save=False, tr=True) for tx in RCLine.objects.filter(pk=params['TX_ref'])] |
|
469 | txs = [tx.update_pulses(save=False, tr=True) for tx in RCLine.objects.filter(pk=params['TX_ref'])] | |
441 | if len(txs)==0 or 0 in [len(tx) for tx in txs]: |
|
470 | if len(txs)==0 or 0 in [len(tx) for tx in txs]: | |
442 | return |
|
471 | return | |
443 |
|
472 | |||
444 | y = np.any(txs, axis=0, out=np.ones(ipp_u*ntx)) |
|
473 | y = np.any(txs, axis=0, out=np.ones(ipp_u*ntx)) | |
445 |
|
474 | |||
446 | ranges = params['range'].split(',') |
|
475 | ranges = params['range'].split(',') | |
447 | if len(ranges)>0 and ranges[0]<>'0': |
|
476 | if len(ranges)>0 and ranges[0]<>'0': | |
448 | mask = create_mask(ranges, ipp_u, ntx, self.rc_configuration.sync) |
|
477 | mask = create_mask(ranges, ipp_u, ntx, self.rc_configuration.sync) | |
449 | y = y.astype(np.int8) & mask |
|
478 | y = y.astype(np.int8) & mask | |
450 |
|
479 | |||
451 | elif self.line_type.name=='tx': |
|
480 | elif self.line_type.name=='tx': | |
452 | params = json.loads(self.params) |
|
481 | params = json.loads(self.params) | |
453 | delays = [float(d)*km2unit for d in params['delays'].split(',') if d] |
|
482 | delays = [float(d)*km2unit for d in params['delays'].split(',') if d] | |
454 | y = pulses(x, ipp_u, float(params['pulse_width'])*km2unit, |
|
483 | y = pulses(x, ipp_u, float(params['pulse_width'])*km2unit, | |
455 | delay=delays, |
|
484 | delay=delays, | |
456 | before=int(self.rc_configuration.time_before*us2unit), |
|
485 | before=int(self.rc_configuration.time_before*us2unit), | |
457 | after=int(self.rc_configuration.time_after*us2unit) if tr else 0, |
|
486 | after=int(self.rc_configuration.time_after*us2unit) if tr else 0, | |
458 | sync=self.rc_configuration.sync) |
|
487 | sync=self.rc_configuration.sync) | |
459 |
|
488 | |||
460 | ranges = params['range'].split(',') |
|
489 | ranges = params['range'].split(',') | |
461 |
|
490 | |||
462 | if len(ranges)>0 and ranges[0]<>'0': |
|
491 | if len(ranges)>0 and ranges[0]<>'0': | |
463 | mask = create_mask(ranges, ipp_u, ntx, self.rc_configuration.sync) |
|
492 | mask = create_mask(ranges, ipp_u, ntx, self.rc_configuration.sync) | |
464 | y = y & mask |
|
493 | y = y & mask | |
465 |
|
494 | |||
466 | elif self.line_type.name=='flip': |
|
495 | elif self.line_type.name=='flip': | |
467 | width = float(json.loads(self.params)['number_of_flips'])*ipp*km2unit |
|
496 | width = float(json.loads(self.params)['number_of_flips'])*ipp*km2unit | |
468 | y = pulses(x, 2*width, width) |
|
497 | y = pulses(x, 2*width, width) | |
469 |
|
498 | |||
470 | elif self.line_type.name=='codes': |
|
499 | elif self.line_type.name=='codes': | |
471 | params = json.loads(self.params) |
|
500 | params = json.loads(self.params) | |
472 | #codes = ast.literal_eval(RCLineCode.objects.get(pk=json.loads(self.params)['code']).codes) |
|
501 | #codes = ast.literal_eval(RCLineCode.objects.get(pk=json.loads(self.params)['code']).codes) | |
473 | tx = RCLine.objects.get(pk=params['TX_ref']) |
|
502 | tx = RCLine.objects.get(pk=params['TX_ref']) | |
474 | tx_params = json.loads(tx.params) |
|
503 | tx_params = json.loads(tx.params) | |
475 |
|
504 | |||
476 | y = pulses_from_code(ipp_u, ntx, params['codes'], |
|
505 | y = pulses_from_code(ipp_u, ntx, params['codes'], | |
477 | int(float(tx_params['pulse_width'])*km2unit), |
|
506 | int(float(tx_params['pulse_width'])*km2unit), | |
478 | before=int(self.rc_configuration.time_before*us2unit)+self.rc_configuration.sync) |
|
507 | before=int(self.rc_configuration.time_before*us2unit)+self.rc_configuration.sync) | |
479 |
|
508 | |||
480 | ranges = tx_params['range'].split(',') |
|
509 | ranges = tx_params['range'].split(',') | |
481 | if len(ranges)>0 and ranges[0]<>'0': |
|
510 | if len(ranges)>0 and ranges[0]<>'0': | |
482 | mask = create_mask(ranges, ipp_u, ntx, self.rc_configuration.sync) |
|
511 | mask = create_mask(ranges, ipp_u, ntx, self.rc_configuration.sync) | |
483 | y = y.astype(np.int8) & mask |
|
512 | y = y.astype(np.int8) & mask | |
484 |
|
513 | |||
485 | elif self.line_type.name=='sync': |
|
514 | elif self.line_type.name=='sync': | |
486 | params = json.loads(self.params) |
|
515 | params = json.loads(self.params) | |
487 | y = np.zeros(ipp_u*ntx) |
|
516 | y = np.zeros(ipp_u*ntx) | |
488 | if params['invert'] in ('1', 1): |
|
517 | if params['invert'] in ('1', 1): | |
489 | y[-1] = 1 |
|
518 | y[-1] = 1 | |
490 | else: |
|
519 | else: | |
491 | y[0] = 1 |
|
520 | y[0] = 1 | |
492 |
|
521 | |||
493 | elif self.line_type.name=='prog_pulses': |
|
522 | elif self.line_type.name=='prog_pulses': | |
494 | params = json.loads(self.params) |
|
523 | params = json.loads(self.params) | |
495 | if int(params['periodic'])==0: |
|
524 | if int(params['periodic'])==0: | |
496 | nntx = ntx |
|
525 | nntx = ntx | |
497 | else: |
|
526 | else: | |
498 | nntx = 1 |
|
527 | nntx = 1 | |
499 |
|
528 | |||
500 | if 'params' in params and len(params['params'])>0: |
|
529 | if 'params' in params and len(params['params'])>0: | |
501 | y = sum([pulses(x, ipp_u*nntx, (pp['end']-pp['begin']), shift=pp['begin']) for pp in params['params']]) |
|
530 | y = sum([pulses(x, ipp_u*nntx, (pp['end']-pp['begin']), shift=pp['begin']) for pp in params['params']]) | |
502 | else: |
|
531 | else: | |
503 | y = np.zeros(ipp_u*ntx) |
|
532 | y = np.zeros(ipp_u*ntx) | |
504 |
|
533 | |||
505 | elif self.line_type.name=='windows': |
|
534 | elif self.line_type.name=='windows': | |
506 | params = json.loads(self.params) |
|
535 | params = json.loads(self.params) | |
507 | if 'params' in params and len(params['params'])>0: |
|
536 | if 'params' in params and len(params['params'])>0: | |
508 | print 'REFS' |
|
537 | print 'REFS' | |
509 | print [self.get_win_ref(pp, params['TX_ref'],km2unit) for pp in params['params']] |
|
538 | print [self.get_win_ref(pp, params['TX_ref'],km2unit) for pp in params['params']] | |
510 | y = sum([pulses(x, ipp_u, pp['resolution']*pp['number_of_samples']*km2unit, |
|
539 | y = sum([pulses(x, ipp_u, pp['resolution']*pp['number_of_samples']*km2unit, | |
511 | shift=0, |
|
540 | shift=0, | |
512 | before=int(self.rc_configuration.time_before*us2unit)+self.get_win_ref(pp, params['TX_ref'],km2unit), |
|
541 | before=int(self.rc_configuration.time_before*us2unit)+self.get_win_ref(pp, params['TX_ref'],km2unit), | |
513 | sync=self.rc_configuration.sync) for pp in params['params']]) |
|
542 | sync=self.rc_configuration.sync) for pp in params['params']]) | |
514 | tr = self.get_lines('tr')[0] |
|
543 | tr = self.get_lines('tr')[0] | |
515 | ranges = json.loads(tr.params)['range'].split(',') |
|
544 | ranges = json.loads(tr.params)['range'].split(',') | |
516 | if len(ranges)>0 and ranges[0]<>'0': |
|
545 | if len(ranges)>0 and ranges[0]<>'0': | |
517 | mask = create_mask(ranges, ipp_u, ntx, self.rc_configuration.sync) |
|
546 | mask = create_mask(ranges, ipp_u, ntx, self.rc_configuration.sync) | |
518 | y = y & mask |
|
547 | y = y & mask | |
519 | else: |
|
548 | else: | |
520 | y = np.zeros(ipp_u*ntx) |
|
549 | y = np.zeros(ipp_u*ntx) | |
521 | else: |
|
550 | else: | |
522 | y = np.zeros(ipp_u*ntx) |
|
551 | y = np.zeros(ipp_u*ntx) | |
523 |
|
552 | |||
524 | if save: |
|
553 | if save: | |
525 | self.pulses = (y+48).astype(np.uint8).tostring() |
|
554 | self.pulses = (y+48).astype(np.uint8).tostring() | |
526 | self.save() |
|
555 | self.save() | |
527 | else: |
|
556 | else: | |
528 | return y |
|
557 | return y | |
529 |
|
558 | |||
530 | No newline at end of file |
|
559 |
@@ -1,395 +1,391 | |||||
1 |
|
1 | |||
2 | import json |
|
2 | import json | |
3 |
|
3 | |||
4 | from django.contrib import messages |
|
4 | from django.contrib import messages | |
5 | from django.utils.safestring import mark_safe |
|
5 | from django.utils.safestring import mark_safe | |
6 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse |
|
6 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse | |
7 |
|
7 | |||
8 | from apps.main.models import Configuration, Experiment, Device |
|
8 | from apps.main.models import Configuration, Experiment, Device | |
9 | from apps.main.views import sidebar |
|
9 | from apps.main.views import sidebar | |
10 |
|
10 | |||
11 | from .models import RCConfiguration, RCLine, RCLineType, RCLineCode |
|
11 | from .models import RCConfiguration, RCLine, RCLineType, RCLineCode | |
12 | from .forms import RCConfigurationForm, RCLineForm, RCLineViewForm, RCLineEditForm, RCImportForm, RCLineCodesForm |
|
12 | from .forms import RCConfigurationForm, RCLineForm, RCLineViewForm, RCLineEditForm, RCImportForm, RCLineCodesForm | |
13 | from .utils import plot_pulses |
|
13 | from .utils import plot_pulses | |
14 |
|
14 | |||
15 |
|
15 | |||
16 | def conf(request, conf_id): |
|
16 | def conf(request, conf_id): | |
17 |
|
17 | |||
18 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
18 | conf = get_object_or_404(RCConfiguration, pk=conf_id) | |
19 |
|
19 | |||
20 | lines = RCLine.objects.filter(rc_configuration=conf).order_by('channel') |
|
20 | lines = RCLine.objects.filter(rc_configuration=conf).order_by('channel') | |
21 |
|
21 | |||
22 | for line in lines: |
|
22 | for line in lines: | |
23 | params = json.loads(line.params) |
|
23 | params = json.loads(line.params) | |
24 | line.form = RCLineViewForm(extra_fields=params, line=line) |
|
24 | line.form = RCLineViewForm(extra_fields=params, line=line) | |
25 | if 'params' in params: |
|
25 | if 'params' in params: | |
26 | line.subforms = [RCLineViewForm(extra_fields=fields, line=line, subform=True) for fields in params['params']] |
|
26 | line.subforms = [RCLineViewForm(extra_fields=fields, line=line, subform=True) for fields in params['params']] | |
27 |
|
27 | |||
28 | kwargs = {} |
|
28 | kwargs = {} | |
29 | kwargs['dev_conf'] = conf |
|
29 | kwargs['dev_conf'] = conf | |
30 | kwargs['rc_lines'] = lines |
|
30 | kwargs['rc_lines'] = lines | |
31 | kwargs['dev_conf_keys'] = ['name', 'ipp', 'ntx', 'clock_in', 'clock_divider', 'clock', |
|
31 | kwargs['dev_conf_keys'] = ['name', 'ipp', 'ntx', 'clock_in', 'clock_divider', 'clock', | |
32 | 'time_before', 'time_after', 'sync', 'sampling_reference', 'control_tx', 'control_sw'] |
|
32 | 'time_before', 'time_after', 'sync', 'sampling_reference', 'control_tx', 'control_sw'] | |
33 |
|
33 | |||
34 | kwargs['title'] = 'RC Configuration' |
|
34 | kwargs['title'] = 'RC Configuration' | |
35 | kwargs['suptitle'] = 'Details' |
|
35 | kwargs['suptitle'] = 'Details' | |
36 |
|
36 | |||
37 | kwargs['button'] = 'Edit Configuration' |
|
37 | kwargs['button'] = 'Edit Configuration' | |
38 | ###### SIDEBAR ###### |
|
38 | ###### SIDEBAR ###### | |
39 | kwargs.update(sidebar(conf)) |
|
39 | kwargs.update(sidebar(conf=conf)) | |
40 |
|
40 | |||
41 | return render(request, 'rc_conf.html', kwargs) |
|
41 | return render(request, 'rc_conf.html', kwargs) | |
42 |
|
42 | |||
43 |
|
43 | |||
44 | def conf_edit(request, conf_id): |
|
44 | def conf_edit(request, conf_id): | |
45 |
|
45 | |||
46 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
46 | conf = get_object_or_404(RCConfiguration, pk=conf_id) | |
47 |
|
47 | |||
48 | lines = RCLine.objects.filter(rc_configuration=conf).order_by('channel') |
|
48 | lines = RCLine.objects.filter(rc_configuration=conf).order_by('channel') | |
49 |
|
49 | |||
50 | for line in lines: |
|
50 | for line in lines: | |
51 | params = json.loads(line.params) |
|
51 | params = json.loads(line.params) | |
52 | line.form = RCLineEditForm(conf=conf, line=line, extra_fields=params) |
|
52 | line.form = RCLineEditForm(conf=conf, line=line, extra_fields=params) | |
53 | line.subform = False |
|
53 | line.subform = False | |
54 |
|
54 | |||
55 | if 'params' in params: |
|
55 | if 'params' in params: | |
56 | line.subforms = [RCLineEditForm(extra_fields=fields, line=line, subform=i) for i, fields in enumerate(params['params'])] |
|
56 | line.subforms = [RCLineEditForm(extra_fields=fields, line=line, subform=i) for i, fields in enumerate(params['params'])] | |
57 | line.subform = True |
|
57 | line.subform = True | |
58 |
|
58 | |||
59 | if request.method=='GET': |
|
59 | if request.method=='GET': | |
60 |
|
60 | |||
61 | form = RCConfigurationForm(instance=conf) |
|
61 | form = RCConfigurationForm(instance=conf) | |
62 |
|
62 | |||
63 | elif request.method=='POST': |
|
63 | elif request.method=='POST': | |
64 |
|
64 | |||
65 | line_data = {} |
|
65 | line_data = {} | |
66 | conf_data = {} |
|
66 | conf_data = {} | |
67 | extras = [] |
|
67 | extras = [] | |
68 |
|
68 | |||
69 | #classified post fields |
|
69 | #classified post fields | |
70 | for label,value in request.POST.items(): |
|
70 | for label,value in request.POST.items(): | |
71 | if label=='csrfmiddlewaretoken': |
|
71 | if label=='csrfmiddlewaretoken': | |
72 | continue |
|
72 | continue | |
73 |
|
73 | |||
74 | if label.count('|')==0: |
|
74 | if label.count('|')==0: | |
75 | conf_data[label] = value |
|
75 | conf_data[label] = value | |
76 | continue |
|
76 | continue | |
77 |
|
77 | |||
78 | elif label.split('|')[0]<>'-1': |
|
78 | elif label.split('|')[0]<>'-1': | |
79 | extras.append(label) |
|
79 | extras.append(label) | |
80 | continue |
|
80 | continue | |
81 |
|
81 | |||
82 | x, pk, name = label.split('|') |
|
82 | x, pk, name = label.split('|') | |
83 |
|
83 | |||
84 | if name=='codes': |
|
84 | if name=='codes': | |
85 | value = [s for s in value.split('\r\n') if s] |
|
85 | value = [s for s in value.split('\r\n') if s] | |
86 |
|
86 | |||
87 | if pk in line_data: |
|
87 | if pk in line_data: | |
88 | line_data[pk][name] = value |
|
88 | line_data[pk][name] = value | |
89 | else: |
|
89 | else: | |
90 | line_data[pk] = {name:value} |
|
90 | line_data[pk] = {name:value} | |
91 |
|
91 | |||
92 | #update conf |
|
92 | #update conf | |
93 | form = RCConfigurationForm(conf_data, instance=conf) |
|
93 | form = RCConfigurationForm(conf_data, instance=conf) | |
94 |
|
94 | |||
95 | if form.is_valid(): |
|
95 | if form.is_valid(): | |
96 |
|
96 | |||
97 | form.save() |
|
97 | form.save() | |
98 |
|
98 | |||
99 | #update lines fields |
|
99 | #update lines fields | |
100 | extras.sort() |
|
100 | extras.sort() | |
101 | for label in extras: |
|
101 | for label in extras: | |
102 | x, pk, name = label.split('|') |
|
102 | x, pk, name = label.split('|') | |
103 | if pk not in line_data: |
|
103 | if pk not in line_data: | |
104 | line_data[pk] = {} |
|
104 | line_data[pk] = {} | |
105 | if 'params' not in line_data[pk]: |
|
105 | if 'params' not in line_data[pk]: | |
106 | line_data[pk]['params'] = [] |
|
106 | line_data[pk]['params'] = [] | |
107 | if len(line_data[pk]['params'])<int(x)+1: |
|
107 | if len(line_data[pk]['params'])<int(x)+1: | |
108 | line_data[pk]['params'].append({}) |
|
108 | line_data[pk]['params'].append({}) | |
109 | line_data[pk]['params'][int(x)][name] = float(request.POST[label]) |
|
109 | line_data[pk]['params'][int(x)][name] = float(request.POST[label]) | |
110 |
|
110 | |||
111 | for pk, params in line_data.items(): |
|
111 | for pk, params in line_data.items(): | |
112 | line = RCLine.objects.get(pk=pk) |
|
112 | line = RCLine.objects.get(pk=pk) | |
113 | if line.line_type.name in ('windows', 'prog_pulses'): |
|
113 | if line.line_type.name in ('windows', 'prog_pulses'): | |
114 | if 'params' not in params: |
|
114 | if 'params' not in params: | |
115 | params['params'] = [] |
|
115 | params['params'] = [] | |
116 | line.params = json.dumps(params) |
|
116 | line.params = json.dumps(params) | |
117 | line.save() |
|
117 | line.save() | |
118 |
|
118 | |||
119 | #update pulses field |
|
119 | #update pulses field | |
120 | for line in conf.get_lines(): |
|
120 | for line in conf.get_lines(): | |
121 | if line.line_type.name=='tr': |
|
121 | if line.line_type.name=='tr': | |
122 | continue |
|
122 | continue | |
123 | line.update_pulses() |
|
123 | line.update_pulses() | |
124 |
|
124 | |||
125 | for tr in conf.get_lines('tr'): |
|
125 | for tr in conf.get_lines('tr'): | |
126 | tr.update_pulses() |
|
126 | tr.update_pulses() | |
127 |
|
127 | |||
128 | messages.success(request, 'RC Configuration successfully updated') |
|
128 | messages.success(request, 'RC Configuration successfully updated') | |
129 |
|
129 | |||
130 | return redirect(conf.get_absolute_url()) |
|
130 | return redirect(conf.get_absolute_url()) | |
131 |
|
131 | |||
132 | kwargs = {} |
|
132 | kwargs = {} | |
133 | kwargs['dev_conf'] = conf |
|
133 | kwargs['dev_conf'] = conf | |
134 | kwargs['form'] = form |
|
134 | kwargs['form'] = form | |
135 | kwargs['rc_lines'] = lines |
|
135 | kwargs['rc_lines'] = lines | |
136 | kwargs['edit'] = True |
|
136 | kwargs['edit'] = True | |
137 |
|
137 | |||
138 | kwargs['title'] = 'RC Configuration' |
|
138 | kwargs['title'] = 'RC Configuration' | |
139 | kwargs['suptitle'] = 'Edit' |
|
139 | kwargs['suptitle'] = 'Edit' | |
140 | kwargs['button'] = 'Update' |
|
140 | kwargs['button'] = 'Update' | |
141 | kwargs['previous'] = conf.get_absolute_url() |
|
141 | kwargs['previous'] = conf.get_absolute_url() | |
142 |
|
||||
143 | kwargs.update(sidebar(conf)) |
|
|||
144 |
|
142 | |||
145 | return render(request, 'rc_conf_edit.html', kwargs) |
|
143 | return render(request, 'rc_conf_edit.html', kwargs) | |
146 |
|
144 | |||
147 |
|
145 | |||
148 | def add_line(request, conf_id, line_type_id=None, code_id=None): |
|
146 | def add_line(request, conf_id, line_type_id=None, code_id=None): | |
149 |
|
147 | |||
150 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
148 | conf = get_object_or_404(RCConfiguration, pk=conf_id) | |
151 |
|
149 | |||
152 | if request.method=='GET': |
|
150 | if request.method=='GET': | |
153 | if line_type_id: |
|
151 | if line_type_id: | |
154 | line_type = get_object_or_404(RCLineType, pk=line_type_id) |
|
152 | line_type = get_object_or_404(RCLineType, pk=line_type_id) | |
155 |
|
153 | |||
156 | if code_id: |
|
154 | if code_id: | |
157 | form = RCLineForm(initial={'rc_configuration':conf_id, 'line_type': line_type_id, 'code_id': code_id}, |
|
155 | form = RCLineForm(initial={'rc_configuration':conf_id, 'line_type': line_type_id, 'code_id': code_id}, | |
158 | extra_fields=json.loads(line_type.params)) |
|
156 | extra_fields=json.loads(line_type.params)) | |
159 | else: |
|
157 | else: | |
160 | form = RCLineForm(initial={'rc_configuration':conf_id, 'line_type': line_type_id}, |
|
158 | form = RCLineForm(initial={'rc_configuration':conf_id, 'line_type': line_type_id}, | |
161 | extra_fields=json.loads(line_type.params)) |
|
159 | extra_fields=json.loads(line_type.params)) | |
162 | else: |
|
160 | else: | |
163 | line_type = {'id':0} |
|
161 | line_type = {'id':0} | |
164 | form = RCLineForm(initial={'rc_configuration':conf_id}) |
|
162 | form = RCLineForm(initial={'rc_configuration':conf_id}) | |
165 |
|
163 | |||
166 | if request.method=='POST': |
|
164 | if request.method=='POST': | |
167 |
|
165 | |||
168 | line_type = get_object_or_404(RCLineType, pk=line_type_id) |
|
166 | line_type = get_object_or_404(RCLineType, pk=line_type_id) | |
169 | form = RCLineForm(request.POST, |
|
167 | form = RCLineForm(request.POST, | |
170 | extra_fields=json.loads(line_type.params)) |
|
168 | extra_fields=json.loads(line_type.params)) | |
171 |
|
169 | |||
172 | if form.is_valid(): |
|
170 | if form.is_valid(): | |
173 | form.save() |
|
171 | form.save() | |
174 | form.instance.update_pulses() |
|
172 | form.instance.update_pulses() | |
175 | return redirect('url_edit_rc_conf', conf.id) |
|
173 | return redirect('url_edit_rc_conf', conf.id) | |
176 |
|
174 | |||
177 | kwargs = {} |
|
175 | kwargs = {} | |
178 | kwargs['form'] = form |
|
176 | kwargs['form'] = form | |
179 | kwargs['title'] = 'RC Configuration' |
|
177 | kwargs['title'] = 'RC Configuration' | |
180 | kwargs['suptitle'] = 'Add Line' |
|
178 | kwargs['suptitle'] = 'Add Line' | |
181 | kwargs['button'] = 'Add' |
|
179 | kwargs['button'] = 'Add' | |
182 | kwargs['previous'] = conf.get_absolute_url_edit() |
|
180 | kwargs['previous'] = conf.get_absolute_url_edit() | |
183 | kwargs['dev_conf'] = conf |
|
181 | kwargs['dev_conf'] = conf | |
184 | kwargs['line_type'] = line_type |
|
182 | kwargs['line_type'] = line_type | |
185 |
|
183 | |||
186 | kwargs.update(sidebar(conf)) |
|
|||
187 |
|
||||
188 | return render(request, 'rc_add_line.html', kwargs) |
|
184 | return render(request, 'rc_add_line.html', kwargs) | |
189 |
|
185 | |||
190 | def edit_codes(request, conf_id, line_id, code_id=None): |
|
186 | def edit_codes(request, conf_id, line_id, code_id=None): | |
191 |
|
187 | |||
192 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
188 | conf = get_object_or_404(RCConfiguration, pk=conf_id) | |
193 | line = get_object_or_404(RCLine, pk=line_id) |
|
189 | line = get_object_or_404(RCLine, pk=line_id) | |
194 | params = json.loads(line.params) |
|
190 | params = json.loads(line.params) | |
195 |
|
191 | |||
196 | if request.method=='GET': |
|
192 | if request.method=='GET': | |
197 | if code_id: |
|
193 | if code_id: | |
198 | code = get_object_or_404(RCLineCode, pk=code_id) |
|
194 | code = get_object_or_404(RCLineCode, pk=code_id) | |
199 | form = RCLineCodesForm(instance=code) |
|
195 | form = RCLineCodesForm(instance=code) | |
200 | else: |
|
196 | else: | |
201 | initial = {'code': params['code'], |
|
197 | initial = {'code': params['code'], | |
202 | 'codes': params['codes'] if 'codes' in params else [], |
|
198 | 'codes': params['codes'] if 'codes' in params else [], | |
203 | 'number_of_codes': len(params['codes']) if 'codes' in params else 0, |
|
199 | 'number_of_codes': len(params['codes']) if 'codes' in params else 0, | |
204 | 'bits_per_code': len(params['codes'][0]) if 'codes' in params else 0, |
|
200 | 'bits_per_code': len(params['codes'][0]) if 'codes' in params else 0, | |
205 | } |
|
201 | } | |
206 | form = RCLineCodesForm(initial=initial) |
|
202 | form = RCLineCodesForm(initial=initial) | |
207 |
|
203 | |||
208 | if request.method=='POST': |
|
204 | if request.method=='POST': | |
209 | form = RCLineCodesForm(request.POST) |
|
205 | form = RCLineCodesForm(request.POST) | |
210 | if form.is_valid(): |
|
206 | if form.is_valid(): | |
211 | params['code'] = request.POST['code'] |
|
207 | params['code'] = request.POST['code'] | |
212 | params['codes'] = [s for s in request.POST['codes'].split('\r\n') if s] |
|
208 | params['codes'] = [s for s in request.POST['codes'].split('\r\n') if s] | |
213 | line.params = json.dumps(params) |
|
209 | line.params = json.dumps(params) | |
214 | line.save() |
|
210 | line.save() | |
215 | messages.success(request, 'Line: "%s" has been updated.' % line) |
|
211 | messages.success(request, 'Line: "%s" has been updated.' % line) | |
216 | return redirect('url_edit_rc_conf', conf.id) |
|
212 | return redirect('url_edit_rc_conf', conf.id) | |
217 |
|
213 | |||
218 | kwargs = {} |
|
214 | kwargs = {} | |
219 | kwargs['form'] = form |
|
215 | kwargs['form'] = form | |
220 | kwargs['title'] = line |
|
216 | kwargs['title'] = line | |
221 | kwargs['suptitle'] = 'Edit' |
|
217 | kwargs['suptitle'] = 'Edit' | |
222 | kwargs['button'] = 'Update' |
|
218 | kwargs['button'] = 'Update' | |
223 | kwargs['dev_conf'] = conf |
|
219 | kwargs['dev_conf'] = conf | |
224 | kwargs['previous'] = conf.get_absolute_url_edit() |
|
220 | kwargs['previous'] = conf.get_absolute_url_edit() | |
225 | kwargs['line'] = line |
|
221 | kwargs['line'] = line | |
226 |
|
222 | |||
227 | return render(request, 'rc_edit_codes.html', kwargs) |
|
223 | return render(request, 'rc_edit_codes.html', kwargs) | |
228 |
|
224 | |||
229 | def add_subline(request, conf_id, line_id): |
|
225 | def add_subline(request, conf_id, line_id): | |
230 |
|
226 | |||
231 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
227 | conf = get_object_or_404(RCConfiguration, pk=conf_id) | |
232 | line = get_object_or_404(RCLine, pk=line_id) |
|
228 | line = get_object_or_404(RCLine, pk=line_id) | |
233 |
|
229 | |||
234 | if request.method == 'POST': |
|
230 | if request.method == 'POST': | |
235 | if line: |
|
231 | if line: | |
236 | params = json.loads(line.params) |
|
232 | params = json.loads(line.params) | |
237 | subparams = json.loads(line.line_type.params) |
|
233 | subparams = json.loads(line.line_type.params) | |
238 | if 'params' in subparams: |
|
234 | if 'params' in subparams: | |
239 | dum = {} |
|
235 | dum = {} | |
240 | for key, value in subparams['params'].items(): |
|
236 | for key, value in subparams['params'].items(): | |
241 | dum[key] = value['value'] |
|
237 | dum[key] = value['value'] | |
242 | params['params'].append(dum) |
|
238 | params['params'].append(dum) | |
243 | line.params = json.dumps(params) |
|
239 | line.params = json.dumps(params) | |
244 | line.save() |
|
240 | line.save() | |
245 | return redirect('url_edit_rc_conf', conf.id) |
|
241 | return redirect('url_edit_rc_conf', conf.id) | |
246 |
|
242 | |||
247 | kwargs = {} |
|
243 | kwargs = {} | |
248 |
|
244 | |||
249 | kwargs['title'] = 'Add new' |
|
245 | kwargs['title'] = 'Add new' | |
250 | kwargs['suptitle'] = '%s to %s' % (line.line_type.name, line) |
|
246 | kwargs['suptitle'] = '%s to %s' % (line.line_type.name, line) | |
251 |
|
247 | |||
252 | return render(request, 'confirm.html', kwargs) |
|
248 | return render(request, 'confirm.html', kwargs) | |
253 |
|
249 | |||
254 | def remove_line(request, conf_id, line_id): |
|
250 | def remove_line(request, conf_id, line_id): | |
255 |
|
251 | |||
256 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
252 | conf = get_object_or_404(RCConfiguration, pk=conf_id) | |
257 | line = get_object_or_404(RCLine, pk=line_id) |
|
253 | line = get_object_or_404(RCLine, pk=line_id) | |
258 |
|
254 | |||
259 | if request.method == 'POST': |
|
255 | if request.method == 'POST': | |
260 | if line: |
|
256 | if line: | |
261 | try: |
|
257 | try: | |
262 | channel = line.channel |
|
258 | channel = line.channel | |
263 | line.delete() |
|
259 | line.delete() | |
264 | for ch in range(channel+1, RCLine.objects.filter(rc_configuration=conf).count()+1): |
|
260 | for ch in range(channel+1, RCLine.objects.filter(rc_configuration=conf).count()+1): | |
265 | l = RCLine.objects.get(rc_configuration=conf, channel=ch) |
|
261 | l = RCLine.objects.get(rc_configuration=conf, channel=ch) | |
266 | l.channel = l.channel-1 |
|
262 | l.channel = l.channel-1 | |
267 | l.save() |
|
263 | l.save() | |
268 | messages.success(request, 'Line: "%s" has been deleted.' % line) |
|
264 | messages.success(request, 'Line: "%s" has been deleted.' % line) | |
269 | except: |
|
265 | except: | |
270 | messages.error(request, 'Unable to delete line: "%s".' % line) |
|
266 | messages.error(request, 'Unable to delete line: "%s".' % line) | |
271 |
|
267 | |||
272 | return redirect('url_edit_rc_conf', conf.id) |
|
268 | return redirect('url_edit_rc_conf', conf.id) | |
273 |
|
269 | |||
274 | kwargs = {} |
|
270 | kwargs = {} | |
275 |
|
271 | |||
276 | kwargs['object'] = line |
|
272 | kwargs['object'] = line | |
277 | kwargs['delete_view'] = True |
|
273 | kwargs['delete_view'] = True | |
278 | kwargs['title'] = 'Confirm delete' |
|
274 | kwargs['title'] = 'Confirm delete' | |
279 | kwargs['previous'] = conf.get_absolute_url_edit() |
|
275 | kwargs['previous'] = conf.get_absolute_url_edit() | |
280 | return render(request, 'confirm.html', kwargs) |
|
276 | return render(request, 'confirm.html', kwargs) | |
281 |
|
277 | |||
282 |
|
278 | |||
283 | def remove_subline(request, conf_id, line_id, subline_id): |
|
279 | def remove_subline(request, conf_id, line_id, subline_id): | |
284 |
|
280 | |||
285 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
281 | conf = get_object_or_404(RCConfiguration, pk=conf_id) | |
286 | line = get_object_or_404(RCLine, pk=line_id) |
|
282 | line = get_object_or_404(RCLine, pk=line_id) | |
287 |
|
283 | |||
288 | if request.method == 'POST': |
|
284 | if request.method == 'POST': | |
289 | if line: |
|
285 | if line: | |
290 | params = json.loads(line.params) |
|
286 | params = json.loads(line.params) | |
291 | params['params'].remove(params['params'][int(subline_id)-1]) |
|
287 | params['params'].remove(params['params'][int(subline_id)-1]) | |
292 | line.params = json.dumps(params) |
|
288 | line.params = json.dumps(params) | |
293 | line.save() |
|
289 | line.save() | |
294 |
|
290 | |||
295 | return redirect('url_edit_rc_conf', conf.id) |
|
291 | return redirect('url_edit_rc_conf', conf.id) | |
296 |
|
292 | |||
297 | kwargs = {} |
|
293 | kwargs = {} | |
298 |
|
294 | |||
299 | kwargs['object'] = line |
|
295 | kwargs['object'] = line | |
300 | kwargs['object_name'] = line.line_type.name |
|
296 | kwargs['object_name'] = line.line_type.name | |
301 | kwargs['delete_view'] = True |
|
297 | kwargs['delete_view'] = True | |
302 | kwargs['title'] = 'Confirm delete' |
|
298 | kwargs['title'] = 'Confirm delete' | |
303 |
|
299 | |||
304 | return render(request, 'confirm.html', kwargs) |
|
300 | return render(request, 'confirm.html', kwargs) | |
305 |
|
301 | |||
306 |
|
302 | |||
307 | def update_lines_position(request, conf_id): |
|
303 | def update_lines_position(request, conf_id): | |
308 |
|
304 | |||
309 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
305 | conf = get_object_or_404(RCConfiguration, pk=conf_id) | |
310 |
|
306 | |||
311 | if request.method=='POST': |
|
307 | if request.method=='POST': | |
312 | ch = 0 |
|
308 | ch = 0 | |
313 | for item in request.POST['items'].split('&'): |
|
309 | for item in request.POST['items'].split('&'): | |
314 | line = RCLine.objects.get(pk=item.split('=')[-1]) |
|
310 | line = RCLine.objects.get(pk=item.split('=')[-1]) | |
315 | line.channel = ch |
|
311 | line.channel = ch | |
316 | line.save() |
|
312 | line.save() | |
317 | ch += 1 |
|
313 | ch += 1 | |
318 |
|
314 | |||
319 | lines = RCLine.objects.filter(rc_configuration=conf).order_by('channel') |
|
315 | lines = RCLine.objects.filter(rc_configuration=conf).order_by('channel') | |
320 |
|
316 | |||
321 | for line in lines: |
|
317 | for line in lines: | |
322 | params = json.loads(line.params) |
|
318 | params = json.loads(line.params) | |
323 | line.form = RCLineEditForm(conf=conf, line=line, extra_fields=params) |
|
319 | line.form = RCLineEditForm(conf=conf, line=line, extra_fields=params) | |
324 |
|
320 | |||
325 | if 'params' in params: |
|
321 | if 'params' in params: | |
326 | line.subform = True |
|
322 | line.subform = True | |
327 | line.subforms = [RCLineEditForm(extra_fields=fields, line=line, subform=i) for i, fields in enumerate(params['params'])] |
|
323 | line.subforms = [RCLineEditForm(extra_fields=fields, line=line, subform=i) for i, fields in enumerate(params['params'])] | |
328 |
|
324 | |||
329 | html = render(request, 'rc_lines.html', {'dev_conf':conf, 'rc_lines':lines, 'edit':True}) |
|
325 | html = render(request, 'rc_lines.html', {'dev_conf':conf, 'rc_lines':lines, 'edit':True}) | |
330 | data = {'html': html.content} |
|
326 | data = {'html': html.content} | |
331 |
|
327 | |||
332 | return HttpResponse(json.dumps(data), content_type="application/json") |
|
328 | return HttpResponse(json.dumps(data), content_type="application/json") | |
333 | return redirect('url_edit_rc_conf', conf.id) |
|
329 | return redirect('url_edit_rc_conf', conf.id) | |
334 |
|
330 | |||
335 |
|
331 | |||
336 | def import_file(request, conf_id): |
|
332 | def import_file(request, conf_id): | |
337 |
|
333 | |||
338 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
334 | conf = get_object_or_404(RCConfiguration, pk=conf_id) | |
339 | if request.method=='POST': |
|
335 | if request.method=='POST': | |
340 | form = RCImportForm(request.POST, request.FILES) |
|
336 | form = RCImportForm(request.POST, request.FILES) | |
341 | if form.is_valid(): |
|
337 | if form.is_valid(): | |
342 | #try: |
|
338 | #try: | |
343 | if True: |
|
339 | if True: | |
344 |
|
340 | |||
345 | conf.update_from_file(request.FILES['file_name']) |
|
341 | conf.update_from_file(request.FILES['file_name']) | |
346 | conf.save() |
|
342 | conf.save() | |
347 |
|
343 | |||
348 | for line in conf.get_lines(): |
|
344 | for line in conf.get_lines(): | |
349 | if line.line_type.name=='tr': |
|
345 | if line.line_type.name=='tr': | |
350 | continue |
|
346 | continue | |
351 | line.update_pulses() |
|
347 | line.update_pulses() | |
352 |
|
348 | |||
353 | for tr in conf.get_lines('tr'): |
|
349 | for tr in conf.get_lines('tr'): | |
354 | tr.update_pulses() |
|
350 | tr.update_pulses() | |
355 |
|
351 | |||
356 | messages.success(request, 'Configuration "%s" loaded succesfully' % request.FILES['file_name']) |
|
352 | messages.success(request, 'Configuration "%s" loaded succesfully' % request.FILES['file_name']) | |
357 | return redirect(conf.get_absolute_url()) |
|
353 | return redirect(conf.get_absolute_url()) | |
358 |
|
354 | |||
359 | #except Exception as e: |
|
355 | #except Exception as e: | |
360 | # messages.error(request, 'Error parsing file: "%s" - %s' % (request.FILES['file_name'], e)) |
|
356 | # messages.error(request, 'Error parsing file: "%s" - %s' % (request.FILES['file_name'], e)) | |
361 |
|
357 | |||
362 | else: |
|
358 | else: | |
363 | messages.warning(request, 'Your current configuration will be replaced') |
|
359 | messages.warning(request, 'Your current configuration will be replaced') | |
364 | form = RCImportForm() |
|
360 | form = RCImportForm() | |
365 |
|
361 | |||
366 | kwargs = {} |
|
362 | kwargs = {} | |
367 | kwargs['form'] = form |
|
363 | kwargs['form'] = form | |
368 | kwargs['title'] = 'RC Configuration' |
|
364 | kwargs['title'] = 'RC Configuration' | |
369 | kwargs['suptitle'] = 'Import file' |
|
365 | kwargs['suptitle'] = 'Import file' | |
370 | kwargs['button'] = 'Upload' |
|
366 | kwargs['button'] = 'Upload' | |
371 | kwargs['previous'] = conf.get_absolute_url() |
|
367 | kwargs['previous'] = conf.get_absolute_url() | |
372 |
|
368 | |||
373 | return render(request, 'rc_import.html', kwargs) |
|
369 | return render(request, 'rc_import.html', kwargs) | |
374 |
|
370 | |||
375 |
|
371 | |||
376 | def view_pulses(request, conf_id): |
|
372 | def view_pulses(request, conf_id): | |
377 |
|
373 | |||
378 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
374 | conf = get_object_or_404(RCConfiguration, pk=conf_id) | |
379 | lines = RCLine.objects.filter(rc_configuration=conf) |
|
375 | lines = RCLine.objects.filter(rc_configuration=conf) | |
380 |
|
376 | |||
381 | unit = (conf.clock/conf.clock_divider)*3./20 |
|
377 | unit = (conf.clock/conf.clock_divider)*3./20 | |
382 |
|
378 | |||
383 | N = int(conf.ipp*(conf.clock/conf.clock_divider)*20./3)*conf.ntx |
|
379 | N = int(conf.ipp*(conf.clock/conf.clock_divider)*20./3)*conf.ntx | |
384 |
|
380 | |||
385 | script, div = plot_pulses(unit, N, lines) |
|
381 | script, div = plot_pulses(unit, N, lines) | |
386 |
|
382 | |||
387 | kwargs = {} |
|
383 | kwargs = {} | |
388 |
|
384 | |||
389 | kwargs['title'] = 'RC Pulses' |
|
385 | kwargs['title'] = 'RC Pulses' | |
390 | kwargs['suptitle'] = conf.name |
|
386 | kwargs['suptitle'] = conf.name | |
391 | kwargs['div'] = mark_safe(div) |
|
387 | kwargs['div'] = mark_safe(div) | |
392 | kwargs['script'] = mark_safe(script) |
|
388 | kwargs['script'] = mark_safe(script) | |
393 |
|
389 | |||
394 | return render(request, 'rc_pulses.html', kwargs) |
|
390 | return render(request, 'rc_pulses.html', kwargs) | |
395 |
|
391 |
General Comments 0
You need to be logged in to leave comments.
Login now