|
@@
-1,1429
+1,1482
|
|
1
|
from django.shortcuts import render, redirect, get_object_or_404, HttpResponse
|
|
1
|
from django.shortcuts import render, redirect, get_object_or_404, HttpResponse
|
|
2
|
from django.utils.safestring import mark_safe
|
|
2
|
from django.utils.safestring import mark_safe
|
|
3
|
from django.http import HttpResponseRedirect
|
|
3
|
from django.http import HttpResponseRedirect
|
|
4
|
from django.core.urlresolvers import reverse
|
|
4
|
from django.core.urlresolvers import reverse
|
|
5
|
from django.db.models import Q
|
|
5
|
from django.db.models import Q
|
|
6
|
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
|
6
|
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
|
7
|
from django.contrib import messages
|
|
7
|
from django.contrib import messages
|
|
8
|
from datetime import datetime
|
|
8
|
from datetime import datetime
|
|
9
|
import urllib
|
|
9
|
import urllib
|
|
10
|
|
|
10
|
|
|
11
|
from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm, NewForm
|
|
11
|
from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm, NewForm
|
|
12
|
from .forms import OperationSearchForm, FilterForm
|
|
12
|
from .forms import OperationSearchForm, FilterForm
|
|
13
|
from apps.cgs.forms import CGSConfigurationForm
|
|
13
|
from apps.cgs.forms import CGSConfigurationForm
|
|
14
|
from apps.jars.forms import JARSConfigurationForm
|
|
14
|
from apps.jars.forms import JARSConfigurationForm
|
|
15
|
from apps.usrp.forms import USRPConfigurationForm
|
|
15
|
from apps.usrp.forms import USRPConfigurationForm
|
|
16
|
from apps.abs.forms import ABSConfigurationForm
|
|
16
|
from apps.abs.forms import ABSConfigurationForm
|
|
17
|
from apps.rc.forms import RCConfigurationForm, RCMixConfigurationForm
|
|
17
|
from apps.rc.forms import RCConfigurationForm, RCMixConfigurationForm
|
|
18
|
from apps.dds.forms import DDSConfigurationForm
|
|
18
|
from apps.dds.forms import DDSConfigurationForm
|
|
19
|
|
|
19
|
|
|
20
|
from .models import Campaign, Experiment, Device, Configuration, Location, RunningExperiment
|
|
20
|
from .models import Campaign, Experiment, Device, Configuration, Location, RunningExperiment
|
|
21
|
from apps.cgs.models import CGSConfiguration
|
|
21
|
from apps.cgs.models import CGSConfiguration
|
|
22
|
from apps.jars.models import JARSConfiguration
|
|
22
|
from apps.jars.models import JARSConfiguration, EXPERIMENT_TYPE
|
|
23
|
from apps.usrp.models import USRPConfiguration
|
|
23
|
from apps.usrp.models import USRPConfiguration
|
|
24
|
from apps.abs.models import ABSConfiguration
|
|
24
|
from apps.abs.models import ABSConfiguration
|
|
25
|
from apps.rc.models import RCConfiguration, RCLine, RCLineType
|
|
25
|
from apps.rc.models import RCConfiguration, RCLine, RCLineType
|
|
26
|
from apps.dds.models import DDSConfiguration
|
|
26
|
from apps.dds.models import DDSConfiguration
|
|
27
|
from django.http.request import QueryDict
|
|
27
|
from django.http.request import QueryDict
|
|
28
|
|
|
28
|
|
|
29
|
# Create your views here.
|
|
29
|
# Create your views here.
|
|
30
|
|
|
30
|
|
|
31
|
CONF_FORMS = {
|
|
31
|
CONF_FORMS = {
|
|
32
|
'rc': RCConfigurationForm,
|
|
32
|
'rc': RCConfigurationForm,
|
|
33
|
'dds': DDSConfigurationForm,
|
|
33
|
'dds': DDSConfigurationForm,
|
|
34
|
'jars': JARSConfigurationForm,
|
|
34
|
'jars': JARSConfigurationForm,
|
|
35
|
'cgs': CGSConfigurationForm,
|
|
35
|
'cgs': CGSConfigurationForm,
|
|
36
|
'abs': ABSConfigurationForm,
|
|
36
|
'abs': ABSConfigurationForm,
|
|
37
|
'usrp': USRPConfigurationForm,
|
|
37
|
'usrp': USRPConfigurationForm,
|
|
38
|
}
|
|
38
|
}
|
|
39
|
|
|
39
|
|
|
40
|
CONF_MODELS = {
|
|
40
|
CONF_MODELS = {
|
|
41
|
'rc': RCConfiguration,
|
|
41
|
'rc': RCConfiguration,
|
|
42
|
'dds': DDSConfiguration,
|
|
42
|
'dds': DDSConfiguration,
|
|
43
|
'jars': JARSConfiguration,
|
|
43
|
'jars': JARSConfiguration,
|
|
44
|
'cgs': CGSConfiguration,
|
|
44
|
'cgs': CGSConfiguration,
|
|
45
|
'abs': ABSConfiguration,
|
|
45
|
'abs': ABSConfiguration,
|
|
46
|
'usrp': USRPConfiguration,
|
|
46
|
'usrp': USRPConfiguration,
|
|
47
|
}
|
|
47
|
}
|
|
48
|
|
|
48
|
|
|
49
|
MIX_MODES = {
|
|
49
|
MIX_MODES = {
|
|
50
|
'0': 'P',
|
|
50
|
'0': 'P',
|
|
51
|
'1': 'S',
|
|
51
|
'1': 'S',
|
|
52
|
}
|
|
52
|
}
|
|
53
|
|
|
53
|
|
|
54
|
MIX_OPERATIONS = {
|
|
54
|
MIX_OPERATIONS = {
|
|
55
|
'0': 'OR',
|
|
55
|
'0': 'OR',
|
|
56
|
'1': 'XOR',
|
|
56
|
'1': 'XOR',
|
|
57
|
'2': 'AND',
|
|
57
|
'2': 'AND',
|
|
58
|
'3': 'NAND',
|
|
58
|
'3': 'NAND',
|
|
59
|
}
|
|
59
|
}
|
|
60
|
|
|
60
|
|
|
61
|
|
|
61
|
|
|
62
|
def index(request):
|
|
62
|
def index(request):
|
|
63
|
kwargs = {}
|
|
63
|
kwargs = {}
|
|
64
|
|
|
64
|
|
|
65
|
return render(request, 'index.html', kwargs)
|
|
65
|
return render(request, 'index.html', kwargs)
|
|
66
|
|
|
66
|
|
|
67
|
|
|
67
|
|
|
68
|
def locations(request):
|
|
68
|
def locations(request):
|
|
69
|
|
|
69
|
|
|
70
|
page = request.GET.get('page')
|
|
70
|
page = request.GET.get('page')
|
|
71
|
order = ('name',)
|
|
71
|
order = ('name',)
|
|
72
|
|
|
72
|
|
|
73
|
kwargs = get_paginator(Location, page, order)
|
|
73
|
kwargs = get_paginator(Location, page, order)
|
|
74
|
|
|
74
|
|
|
75
|
kwargs['keys'] = ['name', 'description']
|
|
75
|
kwargs['keys'] = ['name', 'description']
|
|
76
|
kwargs['title'] = 'Radar System'
|
|
76
|
kwargs['title'] = 'Radar System'
|
|
77
|
kwargs['suptitle'] = 'List'
|
|
77
|
kwargs['suptitle'] = 'List'
|
|
78
|
|
|
78
|
|
|
79
|
return render(request, 'base_list.html', kwargs)
|
|
79
|
return render(request, 'base_list.html', kwargs)
|
|
80
|
|
|
80
|
|
|
81
|
|
|
81
|
|
|
82
|
def location(request, id_loc):
|
|
82
|
def location(request, id_loc):
|
|
83
|
|
|
83
|
|
|
84
|
location = get_object_or_404(Location, pk=id_loc)
|
|
84
|
location = get_object_or_404(Location, pk=id_loc)
|
|
85
|
|
|
85
|
|
|
86
|
kwargs = {}
|
|
86
|
kwargs = {}
|
|
87
|
kwargs['location'] = location
|
|
87
|
kwargs['location'] = location
|
|
88
|
kwargs['location_keys'] = ['name', 'description']
|
|
88
|
kwargs['location_keys'] = ['name', 'description']
|
|
89
|
|
|
89
|
|
|
90
|
kwargs['title'] = 'Location'
|
|
90
|
kwargs['title'] = 'Location'
|
|
91
|
kwargs['suptitle'] = 'Details'
|
|
91
|
kwargs['suptitle'] = 'Details'
|
|
92
|
|
|
92
|
|
|
93
|
return render(request, 'location.html', kwargs)
|
|
93
|
return render(request, 'location.html', kwargs)
|
|
94
|
|
|
94
|
|
|
95
|
|
|
95
|
|
|
96
|
def location_new(request):
|
|
96
|
def location_new(request):
|
|
97
|
|
|
97
|
|
|
98
|
if request.method == 'GET':
|
|
98
|
if request.method == 'GET':
|
|
99
|
form = LocationForm()
|
|
99
|
form = LocationForm()
|
|
100
|
|
|
100
|
|
|
101
|
if request.method == 'POST':
|
|
101
|
if request.method == 'POST':
|
|
102
|
form = LocationForm(request.POST)
|
|
102
|
form = LocationForm(request.POST)
|
|
103
|
|
|
103
|
|
|
104
|
if form.is_valid():
|
|
104
|
if form.is_valid():
|
|
105
|
form.save()
|
|
105
|
form.save()
|
|
106
|
return redirect('url_locations')
|
|
106
|
return redirect('url_locations')
|
|
107
|
|
|
107
|
|
|
108
|
kwargs = {}
|
|
108
|
kwargs = {}
|
|
109
|
kwargs['form'] = form
|
|
109
|
kwargs['form'] = form
|
|
110
|
kwargs['title'] = 'Radar System'
|
|
110
|
kwargs['title'] = 'Radar System'
|
|
111
|
kwargs['suptitle'] = 'New'
|
|
111
|
kwargs['suptitle'] = 'New'
|
|
112
|
kwargs['button'] = 'Create'
|
|
112
|
kwargs['button'] = 'Create'
|
|
113
|
|
|
113
|
|
|
114
|
return render(request, 'base_edit.html', kwargs)
|
|
114
|
return render(request, 'base_edit.html', kwargs)
|
|
115
|
|
|
115
|
|
|
116
|
|
|
116
|
|
|
117
|
def location_edit(request, id_loc):
|
|
117
|
def location_edit(request, id_loc):
|
|
118
|
|
|
118
|
|
|
119
|
location = get_object_or_404(Location, pk=id_loc)
|
|
119
|
location = get_object_or_404(Location, pk=id_loc)
|
|
120
|
|
|
120
|
|
|
121
|
if request.method=='GET':
|
|
121
|
if request.method=='GET':
|
|
122
|
form = LocationForm(instance=location)
|
|
122
|
form = LocationForm(instance=location)
|
|
123
|
|
|
123
|
|
|
124
|
if request.method=='POST':
|
|
124
|
if request.method=='POST':
|
|
125
|
form = LocationForm(request.POST, instance=location)
|
|
125
|
form = LocationForm(request.POST, instance=location)
|
|
126
|
|
|
126
|
|
|
127
|
if form.is_valid():
|
|
127
|
if form.is_valid():
|
|
128
|
form.save()
|
|
128
|
form.save()
|
|
129
|
return redirect('url_locations')
|
|
129
|
return redirect('url_locations')
|
|
130
|
|
|
130
|
|
|
131
|
kwargs = {}
|
|
131
|
kwargs = {}
|
|
132
|
kwargs['form'] = form
|
|
132
|
kwargs['form'] = form
|
|
133
|
kwargs['title'] = 'Location'
|
|
133
|
kwargs['title'] = 'Location'
|
|
134
|
kwargs['suptitle'] = 'Edit'
|
|
134
|
kwargs['suptitle'] = 'Edit'
|
|
135
|
kwargs['button'] = 'Update'
|
|
135
|
kwargs['button'] = 'Update'
|
|
136
|
|
|
136
|
|
|
137
|
return render(request, 'base_edit.html', kwargs)
|
|
137
|
return render(request, 'base_edit.html', kwargs)
|
|
138
|
|
|
138
|
|
|
139
|
|
|
139
|
|
|
140
|
def location_delete(request, id_loc):
|
|
140
|
def location_delete(request, id_loc):
|
|
141
|
|
|
141
|
|
|
142
|
location = get_object_or_404(Location, pk=id_loc)
|
|
142
|
location = get_object_or_404(Location, pk=id_loc)
|
|
143
|
|
|
143
|
|
|
144
|
if request.method=='POST':
|
|
144
|
if request.method=='POST':
|
|
145
|
|
|
145
|
|
|
146
|
if request.user.is_staff:
|
|
146
|
if request.user.is_staff:
|
|
147
|
location.delete()
|
|
147
|
location.delete()
|
|
148
|
return redirect('url_locations')
|
|
148
|
return redirect('url_locations')
|
|
149
|
|
|
149
|
|
|
150
|
messages.error(request, 'Not enough permission to delete this object')
|
|
150
|
messages.error(request, 'Not enough permission to delete this object')
|
|
151
|
return redirect(location.get_absolute_url())
|
|
151
|
return redirect(location.get_absolute_url())
|
|
152
|
|
|
152
|
|
|
153
|
kwargs = {
|
|
153
|
kwargs = {
|
|
154
|
'title': 'Delete',
|
|
154
|
'title': 'Delete',
|
|
155
|
'suptitle': 'Location',
|
|
155
|
'suptitle': 'Location',
|
|
156
|
'object': location,
|
|
156
|
'object': location,
|
|
157
|
'previous': location.get_absolute_url(),
|
|
157
|
'previous': location.get_absolute_url(),
|
|
158
|
'delete': True
|
|
158
|
'delete': True
|
|
159
|
}
|
|
159
|
}
|
|
160
|
|
|
160
|
|
|
161
|
return render(request, 'confirm.html', kwargs)
|
|
161
|
return render(request, 'confirm.html', kwargs)
|
|
162
|
|
|
162
|
|
|
163
|
|
|
163
|
|
|
164
|
def devices(request):
|
|
164
|
def devices(request):
|
|
165
|
|
|
165
|
|
|
166
|
page = request.GET.get('page')
|
|
166
|
page = request.GET.get('page')
|
|
167
|
order = ('device_type', 'name')
|
|
167
|
order = ('device_type', 'name')
|
|
168
|
|
|
168
|
|
|
169
|
kwargs = get_paginator(Device, page, order)
|
|
169
|
kwargs = get_paginator(Device, page, order)
|
|
170
|
kwargs['keys'] = ['name', 'ip_address', 'port_address', 'device_type']
|
|
170
|
kwargs['keys'] = ['name', 'ip_address', 'port_address', 'device_type']
|
|
171
|
kwargs['title'] = 'Device'
|
|
171
|
kwargs['title'] = 'Device'
|
|
172
|
kwargs['suptitle'] = 'List'
|
|
172
|
kwargs['suptitle'] = 'List'
|
|
173
|
|
|
173
|
|
|
174
|
return render(request, 'base_list.html', kwargs)
|
|
174
|
return render(request, 'base_list.html', kwargs)
|
|
175
|
|
|
175
|
|
|
176
|
|
|
176
|
|
|
177
|
def device(request, id_dev):
|
|
177
|
def device(request, id_dev):
|
|
178
|
|
|
178
|
|
|
179
|
device = get_object_or_404(Device, pk=id_dev)
|
|
179
|
device = get_object_or_404(Device, pk=id_dev)
|
|
180
|
|
|
180
|
|
|
181
|
kwargs = {}
|
|
181
|
kwargs = {}
|
|
182
|
kwargs['device'] = device
|
|
182
|
kwargs['device'] = device
|
|
183
|
kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description']
|
|
183
|
kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description']
|
|
184
|
|
|
184
|
|
|
185
|
kwargs['title'] = 'Device'
|
|
185
|
kwargs['title'] = 'Device'
|
|
186
|
kwargs['suptitle'] = 'Details'
|
|
186
|
kwargs['suptitle'] = 'Details'
|
|
187
|
|
|
187
|
|
|
188
|
return render(request, 'device.html', kwargs)
|
|
188
|
return render(request, 'device.html', kwargs)
|
|
189
|
|
|
189
|
|
|
190
|
|
|
190
|
|
|
191
|
def device_new(request):
|
|
191
|
def device_new(request):
|
|
192
|
|
|
192
|
|
|
193
|
if request.method == 'GET':
|
|
193
|
if request.method == 'GET':
|
|
194
|
form = DeviceForm()
|
|
194
|
form = DeviceForm()
|
|
195
|
|
|
195
|
|
|
196
|
if request.method == 'POST':
|
|
196
|
if request.method == 'POST':
|
|
197
|
form = DeviceForm(request.POST)
|
|
197
|
form = DeviceForm(request.POST)
|
|
198
|
|
|
198
|
|
|
199
|
if form.is_valid():
|
|
199
|
if form.is_valid():
|
|
200
|
form.save()
|
|
200
|
form.save()
|
|
201
|
return redirect('url_devices')
|
|
201
|
return redirect('url_devices')
|
|
202
|
|
|
202
|
|
|
203
|
kwargs = {}
|
|
203
|
kwargs = {}
|
|
204
|
kwargs['form'] = form
|
|
204
|
kwargs['form'] = form
|
|
205
|
kwargs['title'] = 'Device'
|
|
205
|
kwargs['title'] = 'Device'
|
|
206
|
kwargs['suptitle'] = 'New'
|
|
206
|
kwargs['suptitle'] = 'New'
|
|
207
|
kwargs['button'] = 'Create'
|
|
207
|
kwargs['button'] = 'Create'
|
|
208
|
|
|
208
|
|
|
209
|
return render(request, 'base_edit.html', kwargs)
|
|
209
|
return render(request, 'base_edit.html', kwargs)
|
|
210
|
|
|
210
|
|
|
211
|
|
|
211
|
|
|
212
|
def device_edit(request, id_dev):
|
|
212
|
def device_edit(request, id_dev):
|
|
213
|
|
|
213
|
|
|
214
|
device = get_object_or_404(Device, pk=id_dev)
|
|
214
|
device = get_object_or_404(Device, pk=id_dev)
|
|
215
|
|
|
215
|
|
|
216
|
if request.method=='GET':
|
|
216
|
if request.method=='GET':
|
|
217
|
form = DeviceForm(instance=device)
|
|
217
|
form = DeviceForm(instance=device)
|
|
218
|
|
|
218
|
|
|
219
|
if request.method=='POST':
|
|
219
|
if request.method=='POST':
|
|
220
|
form = DeviceForm(request.POST, instance=device)
|
|
220
|
form = DeviceForm(request.POST, instance=device)
|
|
221
|
|
|
221
|
|
|
222
|
if form.is_valid():
|
|
222
|
if form.is_valid():
|
|
223
|
form.save()
|
|
223
|
form.save()
|
|
224
|
return redirect(device.get_absolute_url())
|
|
224
|
return redirect(device.get_absolute_url())
|
|
225
|
|
|
225
|
|
|
226
|
kwargs = {}
|
|
226
|
kwargs = {}
|
|
227
|
kwargs['form'] = form
|
|
227
|
kwargs['form'] = form
|
|
228
|
kwargs['title'] = 'Device'
|
|
228
|
kwargs['title'] = 'Device'
|
|
229
|
kwargs['suptitle'] = 'Edit'
|
|
229
|
kwargs['suptitle'] = 'Edit'
|
|
230
|
kwargs['button'] = 'Update'
|
|
230
|
kwargs['button'] = 'Update'
|
|
231
|
|
|
231
|
|
|
232
|
return render(request, 'base_edit.html', kwargs)
|
|
232
|
return render(request, 'base_edit.html', kwargs)
|
|
233
|
|
|
233
|
|
|
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
|
messages.error(request, 'Not enough permission to delete this object')
|
|
245
|
messages.error(request, 'Not enough permission to delete this object')
|
|
246
|
return redirect(device.get_absolute_url())
|
|
246
|
return redirect(device.get_absolute_url())
|
|
247
|
|
|
247
|
|
|
248
|
kwargs = {
|
|
248
|
kwargs = {
|
|
249
|
'title': 'Delete',
|
|
249
|
'title': 'Delete',
|
|
250
|
'suptitle': 'Device',
|
|
250
|
'suptitle': 'Device',
|
|
251
|
'object': device,
|
|
251
|
'object': device,
|
|
252
|
'previous': device.get_absolute_url(),
|
|
252
|
'previous': device.get_absolute_url(),
|
|
253
|
'delete': True
|
|
253
|
'delete': True
|
|
254
|
}
|
|
254
|
}
|
|
255
|
|
|
255
|
|
|
256
|
return render(request, 'confirm.html', kwargs)
|
|
256
|
return render(request, 'confirm.html', kwargs)
|
|
257
|
|
|
257
|
|
|
258
|
|
|
258
|
|
|
259
|
def campaigns(request):
|
|
259
|
def campaigns(request):
|
|
260
|
|
|
260
|
|
|
261
|
page = request.GET.get('page')
|
|
261
|
page = request.GET.get('page')
|
|
262
|
order = ('start_date',)
|
|
262
|
order = ('start_date',)
|
|
263
|
filters = request.GET.copy()
|
|
263
|
filters = request.GET.copy()
|
|
264
|
|
|
264
|
|
|
265
|
kwargs = get_paginator(Campaign, page, order, filters)
|
|
265
|
kwargs = get_paginator(Campaign, page, order, filters)
|
|
266
|
|
|
266
|
|
|
267
|
form = FilterForm(initial=request.GET, extra_fields=['range_date', 'tags','template'])
|
|
267
|
form = FilterForm(initial=request.GET, extra_fields=['range_date', 'tags','template'])
|
|
268
|
kwargs['keys'] = ['name', 'start_date', 'end_date']
|
|
268
|
kwargs['keys'] = ['name', 'start_date', 'end_date']
|
|
269
|
kwargs['title'] = 'Campaign'
|
|
269
|
kwargs['title'] = 'Campaign'
|
|
270
|
kwargs['suptitle'] = 'List'
|
|
270
|
kwargs['suptitle'] = 'List'
|
|
271
|
kwargs['form'] = form
|
|
271
|
kwargs['form'] = form
|
|
272
|
filters.pop('page', None)
|
|
272
|
filters.pop('page', None)
|
|
273
|
kwargs['q'] = urllib.urlencode(filters)
|
|
273
|
kwargs['q'] = urllib.urlencode(filters)
|
|
274
|
|
|
274
|
|
|
275
|
return render(request, 'base_list.html', kwargs)
|
|
275
|
return render(request, 'base_list.html', kwargs)
|
|
276
|
|
|
276
|
|
|
277
|
|
|
277
|
|
|
278
|
def campaign(request, id_camp):
|
|
278
|
def campaign(request, id_camp):
|
|
279
|
|
|
279
|
|
|
280
|
campaign = get_object_or_404(Campaign, pk=id_camp)
|
|
280
|
campaign = get_object_or_404(Campaign, pk=id_camp)
|
|
281
|
experiments = Experiment.objects.filter(campaign=campaign)
|
|
281
|
experiments = Experiment.objects.filter(campaign=campaign)
|
|
282
|
|
|
282
|
|
|
283
|
form = CampaignForm(instance=campaign)
|
|
283
|
form = CampaignForm(instance=campaign)
|
|
284
|
|
|
284
|
|
|
285
|
kwargs = {}
|
|
285
|
kwargs = {}
|
|
286
|
kwargs['campaign'] = campaign
|
|
286
|
kwargs['campaign'] = campaign
|
|
287
|
kwargs['campaign_keys'] = ['template', 'name', 'start_date', 'end_date', 'tags', 'description']
|
|
287
|
kwargs['campaign_keys'] = ['template', 'name', 'start_date', 'end_date', 'tags', 'description']
|
|
288
|
|
|
288
|
|
|
289
|
kwargs['experiments'] = experiments
|
|
289
|
kwargs['experiments'] = experiments
|
|
290
|
kwargs['experiment_keys'] = ['name', 'radar_system', 'start_time', 'end_time']
|
|
290
|
kwargs['experiment_keys'] = ['name', 'radar_system', 'start_time', 'end_time']
|
|
291
|
|
|
291
|
|
|
292
|
kwargs['title'] = 'Campaign'
|
|
292
|
kwargs['title'] = 'Campaign'
|
|
293
|
kwargs['suptitle'] = 'Details'
|
|
293
|
kwargs['suptitle'] = 'Details'
|
|
294
|
|
|
294
|
|
|
295
|
kwargs['form'] = form
|
|
295
|
kwargs['form'] = form
|
|
296
|
kwargs['button'] = 'Add Experiment'
|
|
296
|
kwargs['button'] = 'Add Experiment'
|
|
297
|
|
|
297
|
|
|
298
|
return render(request, 'campaign.html', kwargs)
|
|
298
|
return render(request, 'campaign.html', kwargs)
|
|
299
|
|
|
299
|
|
|
300
|
|
|
300
|
|
|
301
|
def campaign_new(request):
|
|
301
|
def campaign_new(request):
|
|
302
|
|
|
302
|
|
|
303
|
kwargs = {}
|
|
303
|
kwargs = {}
|
|
304
|
|
|
304
|
|
|
305
|
if request.method == 'GET':
|
|
305
|
if request.method == 'GET':
|
|
306
|
|
|
306
|
|
|
307
|
if 'template' in request.GET:
|
|
307
|
if 'template' in request.GET:
|
|
308
|
if request.GET['template']=='0':
|
|
308
|
if request.GET['template']=='0':
|
|
309
|
form = NewForm(initial={'create_from':2},
|
|
309
|
form = NewForm(initial={'create_from':2},
|
|
310
|
template_choices=Campaign.objects.filter(template=True).values_list('id', 'name'))
|
|
310
|
template_choices=Campaign.objects.filter(template=True).values_list('id', 'name'))
|
|
311
|
else:
|
|
311
|
else:
|
|
312
|
kwargs['button'] = 'Create'
|
|
312
|
kwargs['button'] = 'Create'
|
|
313
|
kwargs['experiments'] = Configuration.objects.filter(experiment=request.GET['template'])
|
|
313
|
kwargs['experiments'] = Configuration.objects.filter(experiment=request.GET['template'])
|
|
314
|
kwargs['experiment_keys'] = ['name', 'start_time', 'end_time']
|
|
314
|
kwargs['experiment_keys'] = ['name', 'start_time', 'end_time']
|
|
315
|
camp = Campaign.objects.get(pk=request.GET['template'])
|
|
315
|
camp = Campaign.objects.get(pk=request.GET['template'])
|
|
316
|
form = CampaignForm(instance=camp,
|
|
316
|
form = CampaignForm(instance=camp,
|
|
317
|
initial={'name':'{} [{:%Y/%m/%d}]'.format(camp.name, datetime.now()),
|
|
317
|
initial={'name':'{} [{:%Y/%m/%d}]'.format(camp.name, datetime.now()),
|
|
318
|
'template':False})
|
|
318
|
'template':False})
|
|
319
|
elif 'blank' in request.GET:
|
|
319
|
elif 'blank' in request.GET:
|
|
320
|
kwargs['button'] = 'Create'
|
|
320
|
kwargs['button'] = 'Create'
|
|
321
|
form = CampaignForm()
|
|
321
|
form = CampaignForm()
|
|
322
|
else:
|
|
322
|
else:
|
|
323
|
form = NewForm()
|
|
323
|
form = NewForm()
|
|
324
|
|
|
324
|
|
|
325
|
if request.method == 'POST':
|
|
325
|
if request.method == 'POST':
|
|
326
|
kwargs['button'] = 'Create'
|
|
326
|
kwargs['button'] = 'Create'
|
|
327
|
post = request.POST.copy()
|
|
327
|
post = request.POST.copy()
|
|
328
|
experiments = []
|
|
328
|
experiments = []
|
|
329
|
|
|
329
|
|
|
330
|
for id_exp in post.getlist('experiments'):
|
|
330
|
for id_exp in post.getlist('experiments'):
|
|
331
|
exp = Experiment.objects.get(pk=id_exp)
|
|
331
|
exp = Experiment.objects.get(pk=id_exp)
|
|
332
|
new_exp = exp.clone(template=False)
|
|
332
|
new_exp = exp.clone(template=False)
|
|
333
|
experiments.append(new_exp)
|
|
333
|
experiments.append(new_exp)
|
|
334
|
|
|
334
|
|
|
335
|
post.setlist('experiments', [])
|
|
335
|
post.setlist('experiments', [])
|
|
336
|
|
|
336
|
|
|
337
|
form = CampaignForm(post)
|
|
337
|
form = CampaignForm(post)
|
|
338
|
|
|
338
|
|
|
339
|
if form.is_valid():
|
|
339
|
if form.is_valid():
|
|
340
|
campaign = form.save()
|
|
340
|
campaign = form.save()
|
|
341
|
for exp in experiments:
|
|
341
|
for exp in experiments:
|
|
342
|
campaign.experiments.add(exp)
|
|
342
|
campaign.experiments.add(exp)
|
|
343
|
campaign.save()
|
|
343
|
campaign.save()
|
|
344
|
return redirect('url_campaign', id_camp=campaign.id)
|
|
344
|
return redirect('url_campaign', id_camp=campaign.id)
|
|
345
|
|
|
345
|
|
|
346
|
kwargs['form'] = form
|
|
346
|
kwargs['form'] = form
|
|
347
|
kwargs['title'] = 'Campaign'
|
|
347
|
kwargs['title'] = 'Campaign'
|
|
348
|
kwargs['suptitle'] = 'New'
|
|
348
|
kwargs['suptitle'] = 'New'
|
|
349
|
|
|
349
|
|
|
350
|
return render(request, 'campaign_edit.html', kwargs)
|
|
350
|
return render(request, 'campaign_edit.html', kwargs)
|
|
351
|
|
|
351
|
|
|
352
|
|
|
352
|
|
|
353
|
def campaign_edit(request, id_camp):
|
|
353
|
def campaign_edit(request, id_camp):
|
|
354
|
|
|
354
|
|
|
355
|
campaign = get_object_or_404(Campaign, pk=id_camp)
|
|
355
|
campaign = get_object_or_404(Campaign, pk=id_camp)
|
|
356
|
|
|
356
|
|
|
357
|
if request.method=='GET':
|
|
357
|
if request.method=='GET':
|
|
358
|
form = CampaignForm(instance=campaign)
|
|
358
|
form = CampaignForm(instance=campaign)
|
|
359
|
|
|
359
|
|
|
360
|
if request.method=='POST':
|
|
360
|
if request.method=='POST':
|
|
361
|
exps = campaign.experiments.all().values_list('pk', flat=True)
|
|
361
|
exps = campaign.experiments.all().values_list('pk', flat=True)
|
|
362
|
post = request.POST.copy()
|
|
362
|
post = request.POST.copy()
|
|
363
|
new_exps = post.getlist('experiments')
|
|
363
|
new_exps = post.getlist('experiments')
|
|
364
|
post.setlist('experiments', [])
|
|
364
|
post.setlist('experiments', [])
|
|
365
|
form = CampaignForm(post, instance=campaign)
|
|
365
|
form = CampaignForm(post, instance=campaign)
|
|
366
|
|
|
366
|
|
|
367
|
if form.is_valid():
|
|
367
|
if form.is_valid():
|
|
368
|
camp = form.save()
|
|
368
|
camp = form.save()
|
|
369
|
for id_exp in new_exps:
|
|
369
|
for id_exp in new_exps:
|
|
370
|
if int(id_exp) in exps:
|
|
370
|
if int(id_exp) in exps:
|
|
371
|
exps.pop(id_exp)
|
|
371
|
exps.pop(id_exp)
|
|
372
|
else:
|
|
372
|
else:
|
|
373
|
exp = Experiment.objects.get(pk=id_exp)
|
|
373
|
exp = Experiment.objects.get(pk=id_exp)
|
|
374
|
if exp.template:
|
|
374
|
if exp.template:
|
|
375
|
camp.experiments.add(exp.clone(template=False))
|
|
375
|
camp.experiments.add(exp.clone(template=False))
|
|
376
|
else:
|
|
376
|
else:
|
|
377
|
camp.experiments.add(exp)
|
|
377
|
camp.experiments.add(exp)
|
|
378
|
|
|
378
|
|
|
379
|
for id_exp in exps:
|
|
379
|
for id_exp in exps:
|
|
380
|
camp.experiments.remove(Experiment.objects.get(pk=id_exp))
|
|
380
|
camp.experiments.remove(Experiment.objects.get(pk=id_exp))
|
|
381
|
|
|
381
|
|
|
382
|
return redirect('url_campaign', id_camp=id_camp)
|
|
382
|
return redirect('url_campaign', id_camp=id_camp)
|
|
383
|
|
|
383
|
|
|
384
|
kwargs = {}
|
|
384
|
kwargs = {}
|
|
385
|
kwargs['form'] = form
|
|
385
|
kwargs['form'] = form
|
|
386
|
kwargs['title'] = 'Campaign'
|
|
386
|
kwargs['title'] = 'Campaign'
|
|
387
|
kwargs['suptitle'] = 'Edit'
|
|
387
|
kwargs['suptitle'] = 'Edit'
|
|
388
|
kwargs['button'] = 'Update'
|
|
388
|
kwargs['button'] = 'Update'
|
|
389
|
|
|
389
|
|
|
390
|
return render(request, 'campaign_edit.html', kwargs)
|
|
390
|
return render(request, 'campaign_edit.html', kwargs)
|
|
391
|
|
|
391
|
|
|
392
|
|
|
392
|
|
|
393
|
def campaign_delete(request, id_camp):
|
|
393
|
def campaign_delete(request, id_camp):
|
|
394
|
|
|
394
|
|
|
395
|
campaign = get_object_or_404(Campaign, pk=id_camp)
|
|
395
|
campaign = get_object_or_404(Campaign, pk=id_camp)
|
|
396
|
|
|
396
|
|
|
397
|
if request.method=='POST':
|
|
397
|
if request.method=='POST':
|
|
398
|
if request.user.is_staff:
|
|
398
|
if request.user.is_staff:
|
|
399
|
|
|
399
|
|
|
400
|
for exp in campaign.experiments.all():
|
|
400
|
for exp in campaign.experiments.all():
|
|
401
|
for conf in Configuration.objects.filter(experiment=exp):
|
|
401
|
for conf in Configuration.objects.filter(experiment=exp):
|
|
402
|
conf.delete()
|
|
402
|
conf.delete()
|
|
403
|
exp.delete()
|
|
403
|
exp.delete()
|
|
404
|
campaign.delete()
|
|
404
|
campaign.delete()
|
|
405
|
|
|
405
|
|
|
406
|
return redirect('url_campaigns')
|
|
406
|
return redirect('url_campaigns')
|
|
407
|
|
|
407
|
|
|
408
|
messages.error(request, 'Not enough permission to delete this object')
|
|
408
|
messages.error(request, 'Not enough permission to delete this object')
|
|
409
|
return redirect(campaign.get_absolute_url())
|
|
409
|
return redirect(campaign.get_absolute_url())
|
|
410
|
|
|
410
|
|
|
411
|
kwargs = {
|
|
411
|
kwargs = {
|
|
412
|
'title': 'Delete',
|
|
412
|
'title': 'Delete',
|
|
413
|
'suptitle': 'Campaign',
|
|
413
|
'suptitle': 'Campaign',
|
|
414
|
'object': campaign,
|
|
414
|
'object': campaign,
|
|
415
|
'previous': campaign.get_absolute_url(),
|
|
415
|
'previous': campaign.get_absolute_url(),
|
|
416
|
'delete': True
|
|
416
|
'delete': True
|
|
417
|
}
|
|
417
|
}
|
|
418
|
|
|
418
|
|
|
419
|
return render(request, 'confirm.html', kwargs)
|
|
419
|
return render(request, 'confirm.html', kwargs)
|
|
420
|
|
|
420
|
|
|
421
|
def campaign_export(request, id_camp):
|
|
421
|
def campaign_export(request, id_camp):
|
|
422
|
|
|
422
|
|
|
423
|
campaign = get_object_or_404(Campaign, pk=id_camp)
|
|
423
|
campaign = get_object_or_404(Campaign, pk=id_camp)
|
|
424
|
content = campaign.parms_to_dict()
|
|
424
|
content = campaign.parms_to_dict()
|
|
425
|
content_type = 'application/json'
|
|
425
|
content_type = 'application/json'
|
|
426
|
filename = '%s_%s.json' %(campaign.name, campaign.id)
|
|
426
|
filename = '%s_%s.json' %(campaign.name, campaign.id)
|
|
427
|
|
|
427
|
|
|
428
|
response = HttpResponse(content_type=content_type)
|
|
428
|
response = HttpResponse(content_type=content_type)
|
|
429
|
response['Content-Disposition'] = 'attachment; filename="%s"' %filename
|
|
429
|
response['Content-Disposition'] = 'attachment; filename="%s"' %filename
|
|
430
|
response.write(content)
|
|
430
|
response.write(content)
|
|
431
|
|
|
431
|
|
|
432
|
return response
|
|
432
|
return response
|
|
433
|
|
|
433
|
|
|
434
|
|
|
434
|
|
|
435
|
def campaign_import(request, id_camp):
|
|
435
|
def campaign_import(request, id_camp):
|
|
436
|
|
|
436
|
|
|
437
|
campaign = get_object_or_404(Campaign, pk=id_camp)
|
|
437
|
campaign = get_object_or_404(Campaign, pk=id_camp)
|
|
438
|
|
|
438
|
|
|
439
|
if request.method == 'GET':
|
|
439
|
if request.method == 'GET':
|
|
440
|
file_form = UploadFileForm()
|
|
440
|
file_form = UploadFileForm()
|
|
441
|
|
|
441
|
|
|
442
|
if request.method == 'POST':
|
|
442
|
if request.method == 'POST':
|
|
443
|
file_form = UploadFileForm(request.POST, request.FILES)
|
|
443
|
file_form = UploadFileForm(request.POST, request.FILES)
|
|
444
|
|
|
444
|
|
|
445
|
if file_form.is_valid():
|
|
445
|
if file_form.is_valid():
|
|
446
|
|
|
446
|
|
|
447
|
parms = campaign.import_from_file(request.FILES['file'])
|
|
447
|
parms = campaign.import_from_file(request.FILES['file'])
|
|
448
|
|
|
448
|
|
|
449
|
if parms:
|
|
449
|
if parms:
|
|
450
|
parms['name'] = parms['campaign']
|
|
450
|
parms['name'] = parms['campaign']
|
|
451
|
|
|
451
|
|
|
452
|
new_camp = campaign.dict_to_parms(parms, CONF_MODELS)
|
|
452
|
new_camp = campaign.dict_to_parms(parms, CONF_MODELS)
|
|
453
|
|
|
453
|
|
|
454
|
messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name)
|
|
454
|
messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name)
|
|
455
|
|
|
455
|
|
|
456
|
return redirect(new_camp.get_absolute_url_edit())
|
|
456
|
return redirect(new_camp.get_absolute_url_edit())
|
|
457
|
|
|
457
|
|
|
458
|
messages.error(request, "Could not import parameters from file")
|
|
458
|
messages.error(request, "Could not import parameters from file")
|
|
459
|
|
|
459
|
|
|
460
|
kwargs = {}
|
|
460
|
kwargs = {}
|
|
461
|
kwargs['title'] = 'Campaign'
|
|
461
|
kwargs['title'] = 'Campaign'
|
|
462
|
kwargs['form'] = file_form
|
|
462
|
kwargs['form'] = file_form
|
|
463
|
kwargs['suptitle'] = 'Importing file'
|
|
463
|
kwargs['suptitle'] = 'Importing file'
|
|
464
|
kwargs['button'] = 'Import'
|
|
464
|
kwargs['button'] = 'Import'
|
|
465
|
|
|
465
|
|
|
466
|
return render(request, 'campaign_import.html', kwargs)
|
|
466
|
return render(request, 'campaign_import.html', kwargs)
|
|
467
|
|
|
467
|
|
|
468
|
|
|
468
|
|
|
469
|
def experiments(request):
|
|
469
|
def experiments(request):
|
|
470
|
|
|
470
|
|
|
471
|
page = request.GET.get('page')
|
|
471
|
page = request.GET.get('page')
|
|
472
|
order = ('location',)
|
|
472
|
order = ('location',)
|
|
473
|
filters = request.GET.copy()
|
|
473
|
filters = request.GET.copy()
|
|
474
|
|
|
474
|
|
|
475
|
kwargs = get_paginator(Experiment, page, order, filters)
|
|
475
|
kwargs = get_paginator(Experiment, page, order, filters)
|
|
476
|
|
|
476
|
|
|
477
|
form = FilterForm(initial=request.GET, extra_fields=['tags','template'])
|
|
477
|
form = FilterForm(initial=request.GET, extra_fields=['tags','template'])
|
|
478
|
|
|
478
|
|
|
479
|
kwargs['keys'] = ['name', 'radar_system', 'start_time', 'end_time']
|
|
479
|
kwargs['keys'] = ['name', 'radar_system', 'start_time', 'end_time']
|
|
480
|
kwargs['title'] = 'Experiment'
|
|
480
|
kwargs['title'] = 'Experiment'
|
|
481
|
kwargs['suptitle'] = 'List'
|
|
481
|
kwargs['suptitle'] = 'List'
|
|
482
|
kwargs['form'] = form
|
|
482
|
kwargs['form'] = form
|
|
483
|
filters.pop('page', None)
|
|
483
|
filters.pop('page', None)
|
|
484
|
kwargs['q'] = urllib.urlencode(filters)
|
|
484
|
kwargs['q'] = urllib.urlencode(filters)
|
|
485
|
|
|
485
|
|
|
486
|
return render(request, 'base_list.html', kwargs)
|
|
486
|
return render(request, 'base_list.html', kwargs)
|
|
487
|
|
|
487
|
|
|
488
|
|
|
488
|
|
|
489
|
def experiment(request, id_exp):
|
|
489
|
def experiment(request, id_exp):
|
|
490
|
|
|
490
|
|
|
491
|
experiment = get_object_or_404(Experiment, pk=id_exp)
|
|
491
|
experiment = get_object_or_404(Experiment, pk=id_exp)
|
|
492
|
|
|
492
|
|
|
493
|
configurations = Configuration.objects.filter(experiment=experiment, type=0)
|
|
493
|
configurations = Configuration.objects.filter(experiment=experiment, type=0)
|
|
494
|
|
|
494
|
|
|
495
|
kwargs = {}
|
|
495
|
kwargs = {}
|
|
496
|
|
|
496
|
|
|
497
|
kwargs['experiment_keys'] = ['template', 'radar_system', 'name', 'start_time', 'end_time']
|
|
497
|
kwargs['experiment_keys'] = ['template', 'radar_system', 'name', 'start_time', 'end_time']
|
|
498
|
kwargs['experiment'] = experiment
|
|
498
|
kwargs['experiment'] = experiment
|
|
499
|
|
|
499
|
|
|
500
|
kwargs['configuration_keys'] = ['name', 'device__ip_address', 'device__port_address', 'device__status']
|
|
500
|
kwargs['configuration_keys'] = ['name', 'device__ip_address', 'device__port_address', 'device__status']
|
|
501
|
kwargs['configurations'] = configurations
|
|
501
|
kwargs['configurations'] = configurations
|
|
502
|
|
|
502
|
|
|
503
|
kwargs['title'] = 'Experiment'
|
|
503
|
kwargs['title'] = 'Experiment'
|
|
504
|
kwargs['suptitle'] = 'Details'
|
|
504
|
kwargs['suptitle'] = 'Details'
|
|
505
|
|
|
505
|
|
|
506
|
kwargs['button'] = 'Add Configuration'
|
|
506
|
kwargs['button'] = 'Add Configuration'
|
|
507
|
|
|
507
|
|
|
508
|
###### SIDEBAR ######
|
|
508
|
###### SIDEBAR ######
|
|
509
|
kwargs.update(sidebar(experiment=experiment))
|
|
509
|
kwargs.update(sidebar(experiment=experiment))
|
|
510
|
|
|
510
|
|
|
511
|
return render(request, 'experiment.html', kwargs)
|
|
511
|
return render(request, 'experiment.html', kwargs)
|
|
512
|
|
|
512
|
|
|
513
|
|
|
513
|
|
|
514
|
def experiment_new(request, id_camp=None):
|
|
514
|
def experiment_new(request, id_camp=None):
|
|
515
|
|
|
515
|
|
|
516
|
kwargs = {}
|
|
516
|
kwargs = {}
|
|
517
|
|
|
517
|
|
|
518
|
if request.method == 'GET':
|
|
518
|
if request.method == 'GET':
|
|
519
|
if 'template' in request.GET:
|
|
519
|
if 'template' in request.GET:
|
|
520
|
if request.GET['template']=='0':
|
|
520
|
if request.GET['template']=='0':
|
|
521
|
form = NewForm(initial={'create_from':2},
|
|
521
|
form = NewForm(initial={'create_from':2},
|
|
522
|
template_choices=Experiment.objects.filter(template=True).values_list('id', 'name'))
|
|
522
|
template_choices=Experiment.objects.filter(template=True).values_list('id', 'name'))
|
|
523
|
else:
|
|
523
|
else:
|
|
524
|
kwargs['button'] = 'Create'
|
|
524
|
kwargs['button'] = 'Create'
|
|
525
|
kwargs['configurations'] = Configuration.objects.filter(experiment=request.GET['template'])
|
|
525
|
kwargs['configurations'] = Configuration.objects.filter(experiment=request.GET['template'])
|
|
526
|
kwargs['configuration_keys'] = ['name', 'device__name', 'device__ip_address', 'device__port_address']
|
|
526
|
kwargs['configuration_keys'] = ['name', 'device__name', 'device__ip_address', 'device__port_address']
|
|
527
|
exp=Experiment.objects.get(pk=request.GET['template'])
|
|
527
|
exp=Experiment.objects.get(pk=request.GET['template'])
|
|
528
|
form = ExperimentForm(instance=exp,
|
|
528
|
form = ExperimentForm(instance=exp,
|
|
529
|
initial={'name': '{} [{:%Y/%m/%d}]'.format(exp.name, datetime.now()),
|
|
529
|
initial={'name': '{} [{:%Y/%m/%d}]'.format(exp.name, datetime.now()),
|
|
530
|
'template': False})
|
|
530
|
'template': False})
|
|
531
|
elif 'blank' in request.GET:
|
|
531
|
elif 'blank' in request.GET:
|
|
532
|
kwargs['button'] = 'Create'
|
|
532
|
kwargs['button'] = 'Create'
|
|
533
|
form = ExperimentForm()
|
|
533
|
form = ExperimentForm()
|
|
534
|
else:
|
|
534
|
else:
|
|
535
|
form = NewForm()
|
|
535
|
form = NewForm()
|
|
536
|
|
|
536
|
|
|
537
|
if request.method == 'POST':
|
|
537
|
if request.method == 'POST':
|
|
538
|
form = ExperimentForm(request.POST)
|
|
538
|
form = ExperimentForm(request.POST)
|
|
539
|
print form.data
|
|
539
|
print form.data
|
|
540
|
if form.is_valid():
|
|
540
|
if form.is_valid():
|
|
541
|
experiment = form.save()
|
|
541
|
experiment = form.save()
|
|
542
|
|
|
542
|
|
|
543
|
if 'template' in request.GET:
|
|
543
|
if 'template' in request.GET:
|
|
544
|
configurations = Configuration.objects.filter(experiment=request.GET['template'], type=0)
|
|
544
|
configurations = Configuration.objects.filter(experiment=request.GET['template'], type=0)
|
|
545
|
for conf in configurations:
|
|
545
|
for conf in configurations:
|
|
546
|
conf.clone(experiment=experiment, template=False)
|
|
546
|
conf.clone(experiment=experiment, template=False)
|
|
547
|
|
|
547
|
|
|
548
|
return redirect('url_experiment', id_exp=experiment.id)
|
|
548
|
return redirect('url_experiment', id_exp=experiment.id)
|
|
549
|
|
|
549
|
|
|
550
|
kwargs['form'] = form
|
|
550
|
kwargs['form'] = form
|
|
551
|
kwargs['title'] = 'Experiment'
|
|
551
|
kwargs['title'] = 'Experiment'
|
|
552
|
kwargs['suptitle'] = 'New'
|
|
552
|
kwargs['suptitle'] = 'New'
|
|
553
|
|
|
553
|
|
|
554
|
return render(request, 'experiment_edit.html', kwargs)
|
|
554
|
return render(request, 'experiment_edit.html', kwargs)
|
|
555
|
|
|
555
|
|
|
556
|
|
|
556
|
|
|
557
|
def experiment_edit(request, id_exp):
|
|
557
|
def experiment_edit(request, id_exp):
|
|
558
|
|
|
558
|
|
|
559
|
experiment = get_object_or_404(Experiment, pk=id_exp)
|
|
559
|
experiment = get_object_or_404(Experiment, pk=id_exp)
|
|
560
|
|
|
560
|
|
|
561
|
if request.method == 'GET':
|
|
561
|
if request.method == 'GET':
|
|
562
|
form = ExperimentForm(instance=experiment)
|
|
562
|
form = ExperimentForm(instance=experiment)
|
|
563
|
|
|
563
|
|
|
564
|
if request.method=='POST':
|
|
564
|
if request.method=='POST':
|
|
565
|
form = ExperimentForm(request.POST, instance=experiment)
|
|
565
|
form = ExperimentForm(request.POST, instance=experiment)
|
|
566
|
|
|
566
|
|
|
567
|
if form.is_valid():
|
|
567
|
if form.is_valid():
|
|
568
|
experiment = form.save()
|
|
568
|
experiment = form.save()
|
|
569
|
return redirect('url_experiment', id_exp=experiment.id)
|
|
569
|
return redirect('url_experiment', id_exp=experiment.id)
|
|
570
|
|
|
570
|
|
|
571
|
kwargs = {}
|
|
571
|
kwargs = {}
|
|
572
|
kwargs['form'] = form
|
|
572
|
kwargs['form'] = form
|
|
573
|
kwargs['title'] = 'Experiment'
|
|
573
|
kwargs['title'] = 'Experiment'
|
|
574
|
kwargs['suptitle'] = 'Edit'
|
|
574
|
kwargs['suptitle'] = 'Edit'
|
|
575
|
kwargs['button'] = 'Update'
|
|
575
|
kwargs['button'] = 'Update'
|
|
576
|
|
|
576
|
|
|
577
|
return render(request, 'experiment_edit.html', kwargs)
|
|
577
|
return render(request, 'experiment_edit.html', kwargs)
|
|
578
|
|
|
578
|
|
|
579
|
|
|
579
|
|
|
580
|
def experiment_delete(request, id_exp):
|
|
580
|
def experiment_delete(request, id_exp):
|
|
581
|
|
|
581
|
|
|
582
|
experiment = get_object_or_404(Experiment, pk=id_exp)
|
|
582
|
experiment = get_object_or_404(Experiment, pk=id_exp)
|
|
583
|
|
|
583
|
|
|
584
|
if request.method=='POST':
|
|
584
|
if request.method=='POST':
|
|
585
|
if request.user.is_staff:
|
|
585
|
if request.user.is_staff:
|
|
586
|
for conf in Configuration.objects.filter(experiment=experiment):
|
|
586
|
for conf in Configuration.objects.filter(experiment=experiment):
|
|
587
|
conf.delete()
|
|
587
|
conf.delete()
|
|
588
|
experiment.delete()
|
|
588
|
experiment.delete()
|
|
589
|
return redirect('url_experiments')
|
|
589
|
return redirect('url_experiments')
|
|
590
|
|
|
590
|
|
|
591
|
messages.error(request, 'Not enough permission to delete this object')
|
|
591
|
messages.error(request, 'Not enough permission to delete this object')
|
|
592
|
return redirect(experiment.get_absolute_url())
|
|
592
|
return redirect(experiment.get_absolute_url())
|
|
593
|
|
|
593
|
|
|
594
|
kwargs = {
|
|
594
|
kwargs = {
|
|
595
|
'title': 'Delete',
|
|
595
|
'title': 'Delete',
|
|
596
|
'suptitle': 'Experiment',
|
|
596
|
'suptitle': 'Experiment',
|
|
597
|
'object': experiment,
|
|
597
|
'object': experiment,
|
|
598
|
'previous': experiment.get_absolute_url(),
|
|
598
|
'previous': experiment.get_absolute_url(),
|
|
599
|
'delete': True
|
|
599
|
'delete': True
|
|
600
|
}
|
|
600
|
}
|
|
601
|
|
|
601
|
|
|
602
|
return render(request, 'confirm.html', kwargs)
|
|
602
|
return render(request, 'confirm.html', kwargs)
|
|
603
|
|
|
603
|
|
|
604
|
|
|
604
|
|
|
605
|
def experiment_export(request, id_exp):
|
|
605
|
def experiment_export(request, id_exp):
|
|
606
|
|
|
606
|
|
|
607
|
experiment = get_object_or_404(Experiment, pk=id_exp)
|
|
607
|
experiment = get_object_or_404(Experiment, pk=id_exp)
|
|
608
|
content = experiment.parms_to_dict()
|
|
608
|
content = experiment.parms_to_dict()
|
|
609
|
content_type = 'application/json'
|
|
609
|
content_type = 'application/json'
|
|
610
|
filename = '%s_%s.json' %(experiment.name, experiment.id)
|
|
610
|
filename = '%s_%s.json' %(experiment.name, experiment.id)
|
|
611
|
|
|
611
|
|
|
612
|
response = HttpResponse(content_type=content_type)
|
|
612
|
response = HttpResponse(content_type=content_type)
|
|
613
|
response['Content-Disposition'] = 'attachment; filename="%s"' %filename
|
|
613
|
response['Content-Disposition'] = 'attachment; filename="%s"' %filename
|
|
614
|
response.write(content)
|
|
614
|
response.write(content)
|
|
615
|
|
|
615
|
|
|
616
|
return response
|
|
616
|
return response
|
|
617
|
|
|
617
|
|
|
618
|
def experiment_import(request, id_exp):
|
|
618
|
def experiment_import(request, id_exp):
|
|
619
|
|
|
619
|
|
|
620
|
experiment = get_object_or_404(Experiment, pk=id_exp)
|
|
620
|
experiment = get_object_or_404(Experiment, pk=id_exp)
|
|
621
|
configurations = Configuration.objects.filter(experiment=experiment)
|
|
621
|
configurations = Configuration.objects.filter(experiment=experiment)
|
|
622
|
|
|
622
|
|
|
623
|
if request.method == 'GET':
|
|
623
|
if request.method == 'GET':
|
|
624
|
file_form = UploadFileForm()
|
|
624
|
file_form = UploadFileForm()
|
|
625
|
|
|
625
|
|
|
626
|
if request.method == 'POST':
|
|
626
|
if request.method == 'POST':
|
|
627
|
file_form = UploadFileForm(request.POST, request.FILES)
|
|
627
|
file_form = UploadFileForm(request.POST, request.FILES)
|
|
628
|
|
|
628
|
|
|
629
|
if file_form.is_valid():
|
|
629
|
if file_form.is_valid():
|
|
630
|
|
|
630
|
|
|
631
|
parms = experiment.import_from_file(request.FILES['file'])
|
|
631
|
parms = experiment.import_from_file(request.FILES['file'])
|
|
632
|
|
|
632
|
|
|
633
|
if parms:
|
|
633
|
if parms:
|
|
634
|
|
|
634
|
|
|
635
|
new_exp = experiment.dict_to_parms(parms, CONF_MODELS)
|
|
635
|
new_exp = experiment.dict_to_parms(parms, CONF_MODELS)
|
|
636
|
|
|
636
|
|
|
637
|
messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name)
|
|
637
|
messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name)
|
|
638
|
|
|
638
|
|
|
639
|
return redirect(new_exp.get_absolute_url_edit())
|
|
639
|
return redirect(new_exp.get_absolute_url_edit())
|
|
640
|
|
|
640
|
|
|
641
|
messages.error(request, "Could not import parameters from file")
|
|
641
|
messages.error(request, "Could not import parameters from file")
|
|
642
|
|
|
642
|
|
|
643
|
kwargs = {}
|
|
643
|
kwargs = {}
|
|
644
|
kwargs['title'] = 'Experiment'
|
|
644
|
kwargs['title'] = 'Experiment'
|
|
645
|
kwargs['form'] = file_form
|
|
645
|
kwargs['form'] = file_form
|
|
646
|
kwargs['suptitle'] = 'Importing file'
|
|
646
|
kwargs['suptitle'] = 'Importing file'
|
|
647
|
kwargs['button'] = 'Import'
|
|
647
|
kwargs['button'] = 'Import'
|
|
648
|
|
|
648
|
|
|
649
|
kwargs.update(sidebar(experiment=experiment))
|
|
649
|
kwargs.update(sidebar(experiment=experiment))
|
|
650
|
|
|
650
|
|
|
651
|
return render(request, 'experiment_import.html', kwargs)
|
|
651
|
return render(request, 'experiment_import.html', kwargs)
|
|
652
|
|
|
652
|
|
|
653
|
def experiment_mix(request, id_exp):
|
|
653
|
def experiment_mix(request, id_exp):
|
|
654
|
|
|
654
|
|
|
655
|
experiment = get_object_or_404(Experiment, pk=id_exp)
|
|
655
|
experiment = get_object_or_404(Experiment, pk=id_exp)
|
|
656
|
rc_confs = [conf for conf in RCConfiguration.objects.filter(experiment=id_exp,
|
|
656
|
rc_confs = [conf for conf in RCConfiguration.objects.filter(experiment=id_exp,
|
|
657
|
mix=False)]
|
|
657
|
mix=False)]
|
|
658
|
|
|
658
|
|
|
659
|
if len(rc_confs)<2:
|
|
659
|
if len(rc_confs)<2:
|
|
660
|
messages.warning(request, 'You need at least two RC Configurations to make a mix')
|
|
660
|
messages.warning(request, 'You need at least two RC Configurations to make a mix')
|
|
661
|
return redirect(experiment.get_absolute_url())
|
|
661
|
return redirect(experiment.get_absolute_url())
|
|
662
|
|
|
662
|
|
|
663
|
mix_confs = RCConfiguration.objects.filter(experiment=id_exp, mix=True)
|
|
663
|
mix_confs = RCConfiguration.objects.filter(experiment=id_exp, mix=True)
|
|
664
|
|
|
664
|
|
|
665
|
if mix_confs:
|
|
665
|
if mix_confs:
|
|
666
|
mix = mix_confs[0]
|
|
666
|
mix = mix_confs[0]
|
|
667
|
else:
|
|
667
|
else:
|
|
668
|
mix = RCConfiguration(experiment=experiment,
|
|
668
|
mix = RCConfiguration(experiment=experiment,
|
|
669
|
device=rc_confs[0].device,
|
|
669
|
device=rc_confs[0].device,
|
|
670
|
ipp=rc_confs[0].ipp,
|
|
670
|
ipp=rc_confs[0].ipp,
|
|
671
|
clock_in=rc_confs[0].clock_in,
|
|
671
|
clock_in=rc_confs[0].clock_in,
|
|
672
|
clock_divider=rc_confs[0].clock_divider,
|
|
672
|
clock_divider=rc_confs[0].clock_divider,
|
|
673
|
mix=True,
|
|
673
|
mix=True,
|
|
674
|
parameters='')
|
|
674
|
parameters='')
|
|
675
|
mix.save()
|
|
675
|
mix.save()
|
|
676
|
|
|
676
|
|
|
677
|
line_type = RCLineType.objects.get(name='mix')
|
|
677
|
line_type = RCLineType.objects.get(name='mix')
|
|
678
|
for i in range(len(rc_confs[0].get_lines())):
|
|
678
|
for i in range(len(rc_confs[0].get_lines())):
|
|
679
|
line = RCLine(rc_configuration=mix, line_type=line_type, channel=i)
|
|
679
|
line = RCLine(rc_configuration=mix, line_type=line_type, channel=i)
|
|
680
|
line.save()
|
|
680
|
line.save()
|
|
681
|
|
|
681
|
|
|
682
|
initial = {'name': mix.name,
|
|
682
|
initial = {'name': mix.name,
|
|
683
|
'result': parse_mix_result(mix.parameters),
|
|
683
|
'result': parse_mix_result(mix.parameters),
|
|
684
|
'delay': 0,
|
|
684
|
'delay': 0,
|
|
685
|
'mask': [0,1,2,3,4,5,6,7]
|
|
685
|
'mask': [0,1,2,3,4,5,6,7]
|
|
686
|
}
|
|
686
|
}
|
|
687
|
|
|
687
|
|
|
688
|
if request.method=='GET':
|
|
688
|
if request.method=='GET':
|
|
689
|
form = RCMixConfigurationForm(confs=rc_confs, initial=initial)
|
|
689
|
form = RCMixConfigurationForm(confs=rc_confs, initial=initial)
|
|
690
|
|
|
690
|
|
|
691
|
if request.method=='POST':
|
|
691
|
if request.method=='POST':
|
|
692
|
result = mix.parameters
|
|
692
|
result = mix.parameters
|
|
693
|
|
|
693
|
|
|
694
|
if '{}|'.format(request.POST['experiment']) in result:
|
|
694
|
if '{}|'.format(request.POST['experiment']) in result:
|
|
695
|
messages.error(request, 'Configuration already added')
|
|
695
|
messages.error(request, 'Configuration already added')
|
|
696
|
else:
|
|
696
|
else:
|
|
697
|
if 'operation' in request.POST:
|
|
697
|
if 'operation' in request.POST:
|
|
698
|
operation = MIX_OPERATIONS[request.POST['operation']]
|
|
698
|
operation = MIX_OPERATIONS[request.POST['operation']]
|
|
699
|
else:
|
|
699
|
else:
|
|
700
|
operation = ' '
|
|
700
|
operation = ' '
|
|
701
|
|
|
701
|
|
|
702
|
mode = MIX_MODES[request.POST['mode']]
|
|
702
|
mode = MIX_MODES[request.POST['mode']]
|
|
703
|
|
|
703
|
|
|
704
|
if result:
|
|
704
|
if result:
|
|
705
|
result = '{}-{}|{}|{}|{}|{}'.format(mix.parameters,
|
|
705
|
result = '{}-{}|{}|{}|{}|{}'.format(mix.parameters,
|
|
706
|
request.POST['experiment'],
|
|
706
|
request.POST['experiment'],
|
|
707
|
mode,
|
|
707
|
mode,
|
|
708
|
operation,
|
|
708
|
operation,
|
|
709
|
float(request.POST['delay']),
|
|
709
|
float(request.POST['delay']),
|
|
710
|
parse_mask(request.POST.getlist('mask'))
|
|
710
|
parse_mask(request.POST.getlist('mask'))
|
|
711
|
)
|
|
711
|
)
|
|
712
|
else:
|
|
712
|
else:
|
|
713
|
result = '{}|{}|{}|{}|{}'.format(request.POST['experiment'],
|
|
713
|
result = '{}|{}|{}|{}|{}'.format(request.POST['experiment'],
|
|
714
|
mode,
|
|
714
|
mode,
|
|
715
|
operation,
|
|
715
|
operation,
|
|
716
|
float(request.POST['delay']),
|
|
716
|
float(request.POST['delay']),
|
|
717
|
parse_mask(request.POST.getlist('mask'))
|
|
717
|
parse_mask(request.POST.getlist('mask'))
|
|
718
|
)
|
|
718
|
)
|
|
719
|
|
|
719
|
|
|
720
|
mix.parameters = result
|
|
720
|
mix.parameters = result
|
|
721
|
mix.name = request.POST['name']
|
|
721
|
mix.name = request.POST['name']
|
|
722
|
mix.save()
|
|
722
|
mix.save()
|
|
723
|
mix.update_pulses()
|
|
723
|
mix.update_pulses()
|
|
724
|
|
|
724
|
|
|
725
|
initial['result'] = parse_mix_result(result)
|
|
725
|
initial['result'] = parse_mix_result(result)
|
|
726
|
initial['name'] = mix.name
|
|
726
|
initial['name'] = mix.name
|
|
727
|
|
|
727
|
|
|
728
|
form = RCMixConfigurationForm(initial=initial, confs=rc_confs)
|
|
728
|
form = RCMixConfigurationForm(initial=initial, confs=rc_confs)
|
|
729
|
|
|
729
|
|
|
730
|
|
|
730
|
|
|
731
|
kwargs = {
|
|
731
|
kwargs = {
|
|
732
|
'title': 'Experiment',
|
|
732
|
'title': 'Experiment',
|
|
733
|
'suptitle': 'Mix Configurations',
|
|
733
|
'suptitle': 'Mix Configurations',
|
|
734
|
'form' : form,
|
|
734
|
'form' : form,
|
|
735
|
'extra_button': 'Delete',
|
|
735
|
'extra_button': 'Delete',
|
|
736
|
'button': 'Add',
|
|
736
|
'button': 'Add',
|
|
737
|
'cancel': 'Back',
|
|
737
|
'cancel': 'Back',
|
|
738
|
'previous': experiment.get_absolute_url(),
|
|
738
|
'previous': experiment.get_absolute_url(),
|
|
739
|
'id_exp':id_exp,
|
|
739
|
'id_exp':id_exp,
|
|
740
|
|
|
740
|
|
|
741
|
}
|
|
741
|
}
|
|
742
|
|
|
742
|
|
|
743
|
return render(request, 'experiment_mix.html', kwargs)
|
|
743
|
return render(request, 'experiment_mix.html', kwargs)
|
|
744
|
|
|
744
|
|
|
745
|
|
|
745
|
|
|
746
|
def experiment_mix_delete(request, id_exp):
|
|
746
|
def experiment_mix_delete(request, id_exp):
|
|
747
|
|
|
747
|
|
|
748
|
conf = RCConfiguration.objects.get(experiment=id_exp, mix=True)
|
|
748
|
conf = RCConfiguration.objects.get(experiment=id_exp, mix=True)
|
|
749
|
values = conf.parameters.split('-')
|
|
749
|
values = conf.parameters.split('-')
|
|
750
|
conf.parameters = '-'.join(values[:-1])
|
|
750
|
conf.parameters = '-'.join(values[:-1])
|
|
751
|
conf.save()
|
|
751
|
conf.save()
|
|
752
|
|
|
752
|
|
|
753
|
return redirect('url_mix_experiment', id_exp=id_exp)
|
|
753
|
return redirect('url_mix_experiment', id_exp=id_exp)
|
|
754
|
|
|
754
|
|
|
755
|
|
|
755
|
|
|
|
|
|
756
|
def experiment_summary(request, id_exp):
|
|
|
|
|
757
|
|
|
|
|
|
758
|
import json
|
|
|
|
|
759
|
|
|
|
|
|
760
|
experiment = get_object_or_404(Experiment, pk=id_exp)
|
|
|
|
|
761
|
experiment_data = json.loads(experiment.parms_to_dict())
|
|
|
|
|
762
|
configurations = Configuration.objects.filter(experiment=experiment, type=0)
|
|
|
|
|
763
|
|
|
|
|
|
764
|
kwargs = {}
|
|
|
|
|
765
|
|
|
|
|
|
766
|
kwargs['experiment_keys'] = ['template', 'radar_system', 'name', 'start_time', 'end_time']
|
|
|
|
|
767
|
kwargs['experiment'] = experiment
|
|
|
|
|
768
|
|
|
|
|
|
769
|
kwargs['configuration_keys'] = ['name', 'device__ip_address', 'device__port_address', 'device__status']
|
|
|
|
|
770
|
kwargs['configurations'] = configurations
|
|
|
|
|
771
|
kwargs['experiment_data'] = experiment_data
|
|
|
|
|
772
|
|
|
|
|
|
773
|
kwargs['title'] = 'Experiment Summary'
|
|
|
|
|
774
|
kwargs['suptitle'] = 'Details'
|
|
|
|
|
775
|
|
|
|
|
|
776
|
kwargs['button'] = 'Verify Parameters'
|
|
|
|
|
777
|
|
|
|
|
|
778
|
for configuration in configurations:
|
|
|
|
|
779
|
if configuration.device.device_type.name == 'jars':
|
|
|
|
|
780
|
kwargs['exp_type'] = EXPERIMENT_TYPE[configuration.exp_type][1]
|
|
|
|
|
781
|
|
|
|
|
|
782
|
if configuration.device.device_type.name == 'rc':
|
|
|
|
|
783
|
rc_lines = experiment_data['configurations']['rc']['lines']
|
|
|
|
|
784
|
code = rc_lines[3]['code']
|
|
|
|
|
785
|
|
|
|
|
|
786
|
window_data = rc_lines[6]['params'][0]
|
|
|
|
|
787
|
h0 = str(window_data['first_height'])
|
|
|
|
|
788
|
dh = str(window_data['resolution'])
|
|
|
|
|
789
|
nsa = str(window_data['number_of_samples'])
|
|
|
|
|
790
|
window = 'Ho='+h0+'km\nDH='+dh+'km\nNSA='+nsa
|
|
|
|
|
791
|
|
|
|
|
|
792
|
tx = ''
|
|
|
|
|
793
|
if float(rc_lines[1]['delays']) == 0:
|
|
|
|
|
794
|
tx = rc_lines[2]['pulse_width']
|
|
|
|
|
795
|
elif float(rc_lines[2]['delays']) == 0:
|
|
|
|
|
796
|
tx = rc_lines[1]['pulse_width']
|
|
|
|
|
797
|
else:
|
|
|
|
|
798
|
tx = rc_lines[1]['pulse_width']+' | '+rc_lines[2]['pulse_width']
|
|
|
|
|
799
|
|
|
|
|
|
800
|
kwargs['tx'] = tx
|
|
|
|
|
801
|
kwargs['code'] = code
|
|
|
|
|
802
|
kwargs['window'] = window
|
|
|
|
|
803
|
|
|
|
|
|
804
|
###### SIDEBAR ######
|
|
|
|
|
805
|
kwargs.update(sidebar(experiment=experiment))
|
|
|
|
|
806
|
|
|
|
|
|
807
|
return render(request, 'experiment_summary.html', kwargs)
|
|
|
|
|
808
|
|
|
|
|
|
809
|
|
|
756
|
def parse_mix_result(s):
|
|
810
|
def parse_mix_result(s):
|
|
757
|
|
|
811
|
|
|
758
|
values = s.split('-')
|
|
812
|
values = s.split('-')
|
|
759
|
html = 'EXP MOD OPE DELAY MASK\r\n'
|
|
813
|
html = 'EXP MOD OPE DELAY MASK\r\n'
|
|
760
|
|
|
814
|
|
|
761
|
if not values or values[0] in ('', ' '):
|
|
815
|
if not values or values[0] in ('', ' '):
|
|
762
|
return mark_safe(html)
|
|
816
|
return mark_safe(html)
|
|
763
|
|
|
817
|
|
|
764
|
for i, value in enumerate(values):
|
|
818
|
for i, value in enumerate(values):
|
|
765
|
if not value:
|
|
819
|
if not value:
|
|
766
|
continue
|
|
820
|
continue
|
|
767
|
pk, mode, operation, delay, mask = value.split('|')
|
|
821
|
pk, mode, operation, delay, mask = value.split('|')
|
|
768
|
conf = RCConfiguration.objects.get(pk=pk)
|
|
822
|
conf = RCConfiguration.objects.get(pk=pk)
|
|
769
|
if i==0:
|
|
823
|
if i==0:
|
|
770
|
html += '{:20.18}{:3}{:4}{:9}km{:>6}\r\n'.format(
|
|
824
|
html += '{:20.18}{:3}{:4}{:9}km{:>6}\r\n'.format(
|
|
771
|
conf.name,
|
|
825
|
conf.name,
|
|
772
|
mode,
|
|
826
|
mode,
|
|
773
|
' ',
|
|
827
|
' ',
|
|
774
|
delay,
|
|
828
|
delay,
|
|
775
|
mask)
|
|
829
|
mask)
|
|
776
|
else:
|
|
830
|
else:
|
|
777
|
html += '{:20.18}{:3}{:4}{:9}km{:>6}\r\n'.format(
|
|
831
|
html += '{:20.18}{:3}{:4}{:9}km{:>6}\r\n'.format(
|
|
778
|
conf.name,
|
|
832
|
conf.name,
|
|
779
|
mode,
|
|
833
|
mode,
|
|
780
|
operation,
|
|
834
|
operation,
|
|
781
|
delay,
|
|
835
|
delay,
|
|
782
|
mask)
|
|
836
|
mask)
|
|
783
|
|
|
837
|
|
|
784
|
return mark_safe(html)
|
|
838
|
return mark_safe(html)
|
|
785
|
|
|
839
|
|
|
786
|
def parse_mask(l):
|
|
840
|
def parse_mask(l):
|
|
787
|
|
|
841
|
|
|
788
|
values = []
|
|
842
|
values = []
|
|
789
|
|
|
843
|
|
|
790
|
for x in range(8):
|
|
844
|
for x in range(8):
|
|
791
|
if '{}'.format(x) in l:
|
|
845
|
if '{}'.format(x) in l:
|
|
792
|
values.append(1)
|
|
846
|
values.append(1)
|
|
793
|
else:
|
|
847
|
else:
|
|
794
|
values.append(0)
|
|
848
|
values.append(0)
|
|
795
|
|
|
849
|
|
|
796
|
values.reverse()
|
|
850
|
values.reverse()
|
|
797
|
|
|
851
|
|
|
798
|
return int(''.join([str(x) for x in values]), 2)
|
|
852
|
return int(''.join([str(x) for x in values]), 2)
|
|
799
|
|
|
853
|
|
|
800
|
|
|
854
|
|
|
801
|
def dev_confs(request):
|
|
855
|
def dev_confs(request):
|
|
802
|
|
|
856
|
|
|
803
|
|
|
857
|
|
|
804
|
page = request.GET.get('page')
|
|
858
|
page = request.GET.get('page')
|
|
805
|
order = ('type', 'device__device_type', 'experiment')
|
|
859
|
order = ('type', 'device__device_type', 'experiment')
|
|
806
|
filters = request.GET.copy()
|
|
860
|
filters = request.GET.copy()
|
|
807
|
|
|
861
|
|
|
808
|
kwargs = get_paginator(Configuration, page, order, filters)
|
|
862
|
kwargs = get_paginator(Configuration, page, order, filters)
|
|
809
|
|
|
863
|
|
|
810
|
form = FilterForm(initial=request.GET, extra_fields=['tags','template'])
|
|
864
|
form = FilterForm(initial=request.GET, extra_fields=['tags','template'])
|
|
811
|
kwargs['keys'] = ['name', 'experiment', 'type', 'programmed_date']
|
|
865
|
kwargs['keys'] = ['name', 'experiment', 'type', 'programmed_date']
|
|
812
|
kwargs['title'] = 'Configuration'
|
|
866
|
kwargs['title'] = 'Configuration'
|
|
813
|
kwargs['suptitle'] = 'List'
|
|
867
|
kwargs['suptitle'] = 'List'
|
|
814
|
kwargs['form'] = form
|
|
868
|
kwargs['form'] = form
|
|
815
|
filters.pop('page', None)
|
|
869
|
filters.pop('page', None)
|
|
816
|
kwargs['q'] = urllib.urlencode(filters)
|
|
870
|
kwargs['q'] = urllib.urlencode(filters)
|
|
817
|
|
|
871
|
|
|
818
|
return render(request, 'base_list.html', kwargs)
|
|
872
|
return render(request, 'base_list.html', kwargs)
|
|
819
|
|
|
873
|
|
|
820
|
|
|
874
|
|
|
821
|
def dev_conf(request, id_conf):
|
|
875
|
def dev_conf(request, id_conf):
|
|
822
|
|
|
876
|
|
|
823
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
877
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
824
|
|
|
878
|
|
|
825
|
return redirect(conf.get_absolute_url())
|
|
879
|
return redirect(conf.get_absolute_url())
|
|
826
|
|
|
880
|
|
|
827
|
|
|
881
|
|
|
828
|
def dev_conf_new(request, id_exp=0, id_dev=0):
|
|
882
|
def dev_conf_new(request, id_exp=0, id_dev=0):
|
|
829
|
|
|
883
|
|
|
830
|
initial = {}
|
|
884
|
initial = {}
|
|
831
|
kwargs = {}
|
|
885
|
kwargs = {}
|
|
832
|
|
|
886
|
|
|
833
|
if id_exp<>0:
|
|
887
|
if id_exp<>0:
|
|
834
|
initial['experiment'] = id_exp
|
|
888
|
initial['experiment'] = id_exp
|
|
835
|
|
|
889
|
|
|
836
|
if id_dev<>0:
|
|
890
|
if id_dev<>0:
|
|
837
|
initial['device'] = id_dev
|
|
891
|
initial['device'] = id_dev
|
|
838
|
|
|
892
|
|
|
839
|
if request.method == 'GET':
|
|
893
|
if request.method == 'GET':
|
|
840
|
|
|
894
|
|
|
841
|
if id_dev:
|
|
895
|
if id_dev:
|
|
842
|
kwargs['button'] = 'Create'
|
|
896
|
kwargs['button'] = 'Create'
|
|
843
|
device = Device.objects.get(pk=id_dev)
|
|
897
|
device = Device.objects.get(pk=id_dev)
|
|
844
|
DevConfForm = CONF_FORMS[device.device_type.name]
|
|
898
|
DevConfForm = CONF_FORMS[device.device_type.name]
|
|
845
|
initial['name'] = request.GET['name']
|
|
899
|
initial['name'] = request.GET['name']
|
|
846
|
form = DevConfForm(initial=initial)
|
|
900
|
form = DevConfForm(initial=initial)
|
|
847
|
else:
|
|
901
|
else:
|
|
848
|
if 'template' in request.GET:
|
|
902
|
if 'template' in request.GET:
|
|
849
|
if request.GET['template']=='0':
|
|
903
|
if request.GET['template']=='0':
|
|
850
|
choices = [(conf.pk, '{}'.format(conf)) for conf in Configuration.objects.filter(template=True)]
|
|
904
|
choices = [(conf.pk, '{}'.format(conf)) for conf in Configuration.objects.filter(template=True)]
|
|
851
|
form = NewForm(initial={'create_from':2},
|
|
905
|
form = NewForm(initial={'create_from':2},
|
|
852
|
template_choices=choices)
|
|
906
|
template_choices=choices)
|
|
853
|
else:
|
|
907
|
else:
|
|
854
|
kwargs['button'] = 'Create'
|
|
908
|
kwargs['button'] = 'Create'
|
|
855
|
conf = Configuration.objects.get(pk=request.GET['template'])
|
|
909
|
conf = Configuration.objects.get(pk=request.GET['template'])
|
|
856
|
id_dev = conf.device.pk
|
|
910
|
id_dev = conf.device.pk
|
|
857
|
DevConfForm = CONF_FORMS[conf.device.device_type.name]
|
|
911
|
DevConfForm = CONF_FORMS[conf.device.device_type.name]
|
|
858
|
form = DevConfForm(instance=conf,
|
|
912
|
form = DevConfForm(instance=conf,
|
|
859
|
initial={'name': '{} [{:%Y/%m/%d}]'.format(conf.name, datetime.now()),
|
|
913
|
initial={'name': '{} [{:%Y/%m/%d}]'.format(conf.name, datetime.now()),
|
|
860
|
'template': False,
|
|
914
|
'template': False,
|
|
861
|
'experiment':id_exp})
|
|
915
|
'experiment':id_exp})
|
|
862
|
elif 'blank' in request.GET:
|
|
916
|
elif 'blank' in request.GET:
|
|
863
|
kwargs['button'] = 'Create'
|
|
917
|
kwargs['button'] = 'Create'
|
|
864
|
form = ConfigurationForm(initial=initial)
|
|
918
|
form = ConfigurationForm(initial=initial)
|
|
865
|
else:
|
|
919
|
else:
|
|
866
|
form = NewForm()
|
|
920
|
form = NewForm()
|
|
867
|
|
|
921
|
|
|
868
|
if request.method == 'POST':
|
|
922
|
if request.method == 'POST':
|
|
869
|
|
|
923
|
|
|
870
|
device = Device.objects.get(pk=request.POST['device'])
|
|
924
|
device = Device.objects.get(pk=request.POST['device'])
|
|
871
|
DevConfForm = CONF_FORMS[device.device_type.name]
|
|
925
|
DevConfForm = CONF_FORMS[device.device_type.name]
|
|
872
|
|
|
926
|
|
|
873
|
form = DevConfForm(request.POST)
|
|
927
|
form = DevConfForm(request.POST)
|
|
874
|
kwargs['button'] = 'Create'
|
|
928
|
kwargs['button'] = 'Create'
|
|
875
|
if form.is_valid():
|
|
929
|
if form.is_valid():
|
|
876
|
conf = form.save()
|
|
930
|
conf = form.save()
|
|
877
|
|
|
931
|
|
|
878
|
if 'template' in request.GET and conf.device.device_type.name=='rc':
|
|
932
|
if 'template' in request.GET and conf.device.device_type.name=='rc':
|
|
879
|
lines = RCLine.objects.filter(rc_configuration=request.GET['template'])
|
|
933
|
lines = RCLine.objects.filter(rc_configuration=request.GET['template'])
|
|
880
|
for line in lines:
|
|
934
|
for line in lines:
|
|
881
|
line.clone(rc_configuration=conf)
|
|
935
|
line.clone(rc_configuration=conf)
|
|
882
|
|
|
936
|
|
|
883
|
if conf.device.device_type.name=='jars':
|
|
937
|
if conf.device.device_type.name=='jars':
|
|
884
|
conf.add_parms_to_filter()
|
|
938
|
conf.add_parms_to_filter()
|
|
885
|
|
|
939
|
|
|
886
|
return redirect('url_dev_conf', id_conf=conf.pk)
|
|
940
|
return redirect('url_dev_conf', id_conf=conf.pk)
|
|
887
|
|
|
941
|
|
|
888
|
kwargs['id_exp'] = id_exp
|
|
942
|
kwargs['id_exp'] = id_exp
|
|
889
|
kwargs['form'] = form
|
|
943
|
kwargs['form'] = form
|
|
890
|
kwargs['title'] = 'Configuration'
|
|
944
|
kwargs['title'] = 'Configuration'
|
|
891
|
kwargs['suptitle'] = 'New'
|
|
945
|
kwargs['suptitle'] = 'New'
|
|
892
|
|
|
946
|
|
|
893
|
|
|
947
|
|
|
894
|
if id_dev != 0:
|
|
948
|
if id_dev != 0:
|
|
895
|
device = Device.objects.get(pk=id_dev)
|
|
949
|
device = Device.objects.get(pk=id_dev)
|
|
896
|
kwargs['device'] = device.device_type.name
|
|
950
|
kwargs['device'] = device.device_type.name
|
|
897
|
|
|
951
|
|
|
898
|
return render(request, 'dev_conf_edit.html', kwargs)
|
|
952
|
return render(request, 'dev_conf_edit.html', kwargs)
|
|
899
|
|
|
953
|
|
|
900
|
|
|
954
|
|
|
901
|
def dev_conf_edit(request, id_conf):
|
|
955
|
def dev_conf_edit(request, id_conf):
|
|
902
|
|
|
956
|
|
|
903
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
957
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
904
|
|
|
958
|
|
|
905
|
DevConfModel = CONF_MODELS[conf.device.device_type.name]
|
|
959
|
DevConfModel = CONF_MODELS[conf.device.device_type.name]
|
|
906
|
DevConfForm = CONF_FORMS[conf.device.device_type.name]
|
|
960
|
DevConfForm = CONF_FORMS[conf.device.device_type.name]
|
|
907
|
|
|
961
|
|
|
908
|
dev_conf = DevConfModel.objects.get(pk=id_conf)
|
|
962
|
dev_conf = DevConfModel.objects.get(pk=id_conf)
|
|
909
|
|
|
963
|
|
|
910
|
if request.method=='GET':
|
|
964
|
if request.method=='GET':
|
|
911
|
form = DevConfForm(instance=dev_conf)
|
|
965
|
form = DevConfForm(instance=dev_conf)
|
|
912
|
|
|
966
|
|
|
913
|
if request.method=='POST':
|
|
967
|
if request.method=='POST':
|
|
914
|
form = DevConfForm(request.POST, instance=dev_conf)
|
|
968
|
form = DevConfForm(request.POST, instance=dev_conf)
|
|
915
|
|
|
969
|
|
|
916
|
if form.is_valid():
|
|
970
|
if form.is_valid():
|
|
917
|
form.save()
|
|
971
|
form.save()
|
|
918
|
return redirect('url_dev_conf', id_conf=id_conf)
|
|
972
|
return redirect('url_dev_conf', id_conf=id_conf)
|
|
919
|
|
|
973
|
|
|
920
|
kwargs = {}
|
|
974
|
kwargs = {}
|
|
921
|
kwargs['form'] = form
|
|
975
|
kwargs['form'] = form
|
|
922
|
kwargs['title'] = 'Device Configuration'
|
|
976
|
kwargs['title'] = 'Device Configuration'
|
|
923
|
kwargs['suptitle'] = 'Edit'
|
|
977
|
kwargs['suptitle'] = 'Edit'
|
|
924
|
kwargs['button'] = 'Update'
|
|
978
|
kwargs['button'] = 'Update'
|
|
925
|
|
|
979
|
|
|
926
|
###### SIDEBAR ######
|
|
980
|
###### SIDEBAR ######
|
|
927
|
kwargs.update(sidebar(conf=conf))
|
|
981
|
kwargs.update(sidebar(conf=conf))
|
|
928
|
|
|
982
|
|
|
929
|
return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs)
|
|
983
|
return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs)
|
|
930
|
|
|
984
|
|
|
931
|
|
|
985
|
|
|
932
|
def dev_conf_start(request, id_conf):
|
|
986
|
def dev_conf_start(request, id_conf):
|
|
933
|
|
|
987
|
|
|
934
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
988
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
935
|
|
|
989
|
|
|
936
|
DevConfModel = CONF_MODELS[conf.device.device_type.name]
|
|
990
|
DevConfModel = CONF_MODELS[conf.device.device_type.name]
|
|
937
|
|
|
991
|
|
|
938
|
conf = DevConfModel.objects.get(pk=id_conf)
|
|
992
|
conf = DevConfModel.objects.get(pk=id_conf)
|
|
939
|
|
|
993
|
|
|
940
|
if conf.start_device():
|
|
994
|
if conf.start_device():
|
|
941
|
messages.success(request, conf.message)
|
|
995
|
messages.success(request, conf.message)
|
|
942
|
else:
|
|
996
|
else:
|
|
943
|
messages.error(request, conf.message)
|
|
997
|
messages.error(request, conf.message)
|
|
944
|
|
|
998
|
|
|
945
|
conf.status_device()
|
|
999
|
conf.status_device()
|
|
946
|
|
|
1000
|
|
|
947
|
return redirect(conf.get_absolute_url())
|
|
1001
|
return redirect(conf.get_absolute_url())
|
|
948
|
|
|
1002
|
|
|
949
|
|
|
1003
|
|
|
950
|
def dev_conf_stop(request, id_conf):
|
|
1004
|
def dev_conf_stop(request, id_conf):
|
|
951
|
|
|
1005
|
|
|
952
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
1006
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
953
|
|
|
1007
|
|
|
954
|
DevConfModel = CONF_MODELS[conf.device.device_type.name]
|
|
1008
|
DevConfModel = CONF_MODELS[conf.device.device_type.name]
|
|
955
|
|
|
1009
|
|
|
956
|
conf = DevConfModel.objects.get(pk=id_conf)
|
|
1010
|
conf = DevConfModel.objects.get(pk=id_conf)
|
|
957
|
|
|
1011
|
|
|
958
|
if conf.stop_device():
|
|
1012
|
if conf.stop_device():
|
|
959
|
messages.success(request, conf.message)
|
|
1013
|
messages.success(request, conf.message)
|
|
960
|
else:
|
|
1014
|
else:
|
|
961
|
messages.error(request, conf.message)
|
|
1015
|
messages.error(request, conf.message)
|
|
962
|
|
|
1016
|
|
|
963
|
conf.status_device()
|
|
1017
|
conf.status_device()
|
|
964
|
|
|
1018
|
|
|
965
|
return redirect(conf.get_absolute_url())
|
|
1019
|
return redirect(conf.get_absolute_url())
|
|
966
|
|
|
1020
|
|
|
967
|
|
|
1021
|
|
|
968
|
def dev_conf_status(request, id_conf):
|
|
1022
|
def dev_conf_status(request, id_conf):
|
|
969
|
|
|
1023
|
|
|
970
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
1024
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
971
|
|
|
1025
|
|
|
972
|
DevConfModel = CONF_MODELS[conf.device.device_type.name]
|
|
1026
|
DevConfModel = CONF_MODELS[conf.device.device_type.name]
|
|
973
|
|
|
1027
|
|
|
974
|
conf = DevConfModel.objects.get(pk=id_conf)
|
|
1028
|
conf = DevConfModel.objects.get(pk=id_conf)
|
|
975
|
|
|
1029
|
|
|
976
|
if conf.status_device():
|
|
1030
|
if conf.status_device():
|
|
977
|
messages.success(request, conf.message)
|
|
1031
|
messages.success(request, conf.message)
|
|
978
|
else:
|
|
1032
|
else:
|
|
979
|
messages.error(request, conf.message)
|
|
1033
|
messages.error(request, conf.message)
|
|
980
|
|
|
1034
|
|
|
981
|
return redirect(conf.get_absolute_url())
|
|
1035
|
return redirect(conf.get_absolute_url())
|
|
982
|
|
|
1036
|
|
|
983
|
|
|
1037
|
|
|
984
|
def dev_conf_write(request, id_conf):
|
|
1038
|
def dev_conf_write(request, id_conf):
|
|
985
|
|
|
1039
|
|
|
986
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
1040
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
987
|
|
|
1041
|
|
|
988
|
DevConfModel = CONF_MODELS[conf.device.device_type.name]
|
|
1042
|
DevConfModel = CONF_MODELS[conf.device.device_type.name]
|
|
989
|
|
|
1043
|
|
|
990
|
conf = DevConfModel.objects.get(pk=id_conf)
|
|
1044
|
conf = DevConfModel.objects.get(pk=id_conf)
|
|
991
|
|
|
1045
|
|
|
992
|
answer = conf.write_device()
|
|
1046
|
answer = conf.write_device()
|
|
993
|
conf.status_device()
|
|
1047
|
conf.status_device()
|
|
994
|
|
|
1048
|
|
|
995
|
if answer:
|
|
1049
|
if answer:
|
|
996
|
messages.success(request, conf.message)
|
|
1050
|
messages.success(request, conf.message)
|
|
997
|
|
|
1051
|
|
|
998
|
#Creating a historical configuration
|
|
1052
|
#Creating a historical configuration
|
|
999
|
conf.clone(type=0, template=False)
|
|
1053
|
conf.clone(type=0, template=False)
|
|
1000
|
|
|
1054
|
|
|
1001
|
#Original configuration
|
|
1055
|
#Original configuration
|
|
1002
|
conf = DevConfModel.objects.get(pk=id_conf)
|
|
1056
|
conf = DevConfModel.objects.get(pk=id_conf)
|
|
1003
|
else:
|
|
1057
|
else:
|
|
1004
|
messages.error(request, conf.message)
|
|
1058
|
messages.error(request, conf.message)
|
|
1005
|
|
|
1059
|
|
|
1006
|
return redirect(conf.get_absolute_url())
|
|
1060
|
return redirect(conf.get_absolute_url())
|
|
1007
|
|
|
1061
|
|
|
1008
|
|
|
1062
|
|
|
1009
|
def dev_conf_read(request, id_conf):
|
|
1063
|
def dev_conf_read(request, id_conf):
|
|
1010
|
|
|
1064
|
|
|
1011
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
1065
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
1012
|
|
|
1066
|
|
|
1013
|
DevConfModel = CONF_MODELS[conf.device.device_type.name]
|
|
1067
|
DevConfModel = CONF_MODELS[conf.device.device_type.name]
|
|
1014
|
DevConfForm = CONF_FORMS[conf.device.device_type.name]
|
|
1068
|
DevConfForm = CONF_FORMS[conf.device.device_type.name]
|
|
1015
|
|
|
1069
|
|
|
1016
|
conf = DevConfModel.objects.get(pk=id_conf)
|
|
1070
|
conf = DevConfModel.objects.get(pk=id_conf)
|
|
1017
|
|
|
1071
|
|
|
1018
|
if request.method=='GET':
|
|
1072
|
if request.method=='GET':
|
|
1019
|
|
|
1073
|
|
|
1020
|
parms = conf.read_device()
|
|
1074
|
parms = conf.read_device()
|
|
1021
|
conf.status_device()
|
|
1075
|
conf.status_device()
|
|
1022
|
|
|
1076
|
|
|
1023
|
if not parms:
|
|
1077
|
if not parms:
|
|
1024
|
messages.error(request, conf.message)
|
|
1078
|
messages.error(request, conf.message)
|
|
1025
|
return redirect(conf.get_absolute_url())
|
|
1079
|
return redirect(conf.get_absolute_url())
|
|
1026
|
|
|
1080
|
|
|
1027
|
form = DevConfForm(initial=parms, instance=conf)
|
|
1081
|
form = DevConfForm(initial=parms, instance=conf)
|
|
1028
|
|
|
1082
|
|
|
1029
|
if request.method=='POST':
|
|
1083
|
if request.method=='POST':
|
|
1030
|
form = DevConfForm(request.POST, instance=conf)
|
|
1084
|
form = DevConfForm(request.POST, instance=conf)
|
|
1031
|
|
|
1085
|
|
|
1032
|
if form.is_valid():
|
|
1086
|
if form.is_valid():
|
|
1033
|
form.save()
|
|
1087
|
form.save()
|
|
1034
|
return redirect(conf.get_absolute_url())
|
|
1088
|
return redirect(conf.get_absolute_url())
|
|
1035
|
|
|
1089
|
|
|
1036
|
messages.error(request, "Parameters could not be saved")
|
|
1090
|
messages.error(request, "Parameters could not be saved")
|
|
1037
|
|
|
1091
|
|
|
1038
|
kwargs = {}
|
|
1092
|
kwargs = {}
|
|
1039
|
kwargs['id_dev'] = conf.id
|
|
1093
|
kwargs['id_dev'] = conf.id
|
|
1040
|
kwargs['form'] = form
|
|
1094
|
kwargs['form'] = form
|
|
1041
|
kwargs['title'] = 'Device Configuration'
|
|
1095
|
kwargs['title'] = 'Device Configuration'
|
|
1042
|
kwargs['suptitle'] = 'Parameters read from device'
|
|
1096
|
kwargs['suptitle'] = 'Parameters read from device'
|
|
1043
|
kwargs['button'] = 'Save'
|
|
1097
|
kwargs['button'] = 'Save'
|
|
1044
|
|
|
1098
|
|
|
1045
|
###### SIDEBAR ######
|
|
1099
|
###### SIDEBAR ######
|
|
1046
|
kwargs.update(sidebar(conf=conf))
|
|
1100
|
kwargs.update(sidebar(conf=conf))
|
|
1047
|
|
|
1101
|
|
|
1048
|
return render(request, '%s_conf_edit.html' %conf.device.device_type.name, kwargs)
|
|
1102
|
return render(request, '%s_conf_edit.html' %conf.device.device_type.name, kwargs)
|
|
1049
|
|
|
1103
|
|
|
1050
|
|
|
1104
|
|
|
1051
|
def dev_conf_import(request, id_conf):
|
|
1105
|
def dev_conf_import(request, id_conf):
|
|
1052
|
|
|
1106
|
|
|
1053
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
1107
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
1054
|
|
|
1108
|
|
|
1055
|
DevConfModel = CONF_MODELS[conf.device.device_type.name]
|
|
1109
|
DevConfModel = CONF_MODELS[conf.device.device_type.name]
|
|
1056
|
DevConfForm = CONF_FORMS[conf.device.device_type.name]
|
|
1110
|
DevConfForm = CONF_FORMS[conf.device.device_type.name]
|
|
1057
|
conf = DevConfModel.objects.get(pk=id_conf)
|
|
1111
|
conf = DevConfModel.objects.get(pk=id_conf)
|
|
1058
|
|
|
1112
|
|
|
1059
|
if request.method == 'GET':
|
|
1113
|
if request.method == 'GET':
|
|
1060
|
file_form = UploadFileForm()
|
|
1114
|
file_form = UploadFileForm()
|
|
1061
|
|
|
1115
|
|
|
1062
|
if request.method == 'POST':
|
|
1116
|
if request.method == 'POST':
|
|
1063
|
file_form = UploadFileForm(request.POST, request.FILES)
|
|
1117
|
file_form = UploadFileForm(request.POST, request.FILES)
|
|
1064
|
|
|
1118
|
|
|
1065
|
if file_form.is_valid():
|
|
1119
|
if file_form.is_valid():
|
|
1066
|
|
|
1120
|
|
|
1067
|
parms = conf.import_from_file(request.FILES['file'])
|
|
1121
|
parms = conf.import_from_file(request.FILES['file'])
|
|
1068
|
|
|
1122
|
|
|
1069
|
if parms:
|
|
1123
|
if parms:
|
|
1070
|
messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name)
|
|
1124
|
messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name)
|
|
1071
|
form = DevConfForm(initial=parms, instance=conf)
|
|
1125
|
form = DevConfForm(initial=parms, instance=conf)
|
|
1072
|
|
|
1126
|
|
|
1073
|
kwargs = {}
|
|
1127
|
kwargs = {}
|
|
1074
|
kwargs['id_dev'] = conf.id
|
|
1128
|
kwargs['id_dev'] = conf.id
|
|
1075
|
kwargs['form'] = form
|
|
1129
|
kwargs['form'] = form
|
|
1076
|
kwargs['title'] = 'Device Configuration'
|
|
1130
|
kwargs['title'] = 'Device Configuration'
|
|
1077
|
kwargs['suptitle'] = 'Parameters imported'
|
|
1131
|
kwargs['suptitle'] = 'Parameters imported'
|
|
1078
|
kwargs['button'] = 'Save'
|
|
1132
|
kwargs['button'] = 'Save'
|
|
1079
|
kwargs['action'] = conf.get_absolute_url_edit()
|
|
1133
|
kwargs['action'] = conf.get_absolute_url_edit()
|
|
1080
|
kwargs['previous'] = conf.get_absolute_url()
|
|
1134
|
kwargs['previous'] = conf.get_absolute_url()
|
|
1081
|
|
|
1135
|
|
|
1082
|
###### SIDEBAR ######
|
|
1136
|
###### SIDEBAR ######
|
|
1083
|
kwargs.update(sidebar(conf=conf))
|
|
1137
|
kwargs.update(sidebar(conf=conf))
|
|
1084
|
|
|
1138
|
|
|
1085
|
return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs)
|
|
1139
|
return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs)
|
|
1086
|
|
|
1140
|
|
|
1087
|
messages.error(request, "Could not import parameters from file")
|
|
1141
|
messages.error(request, "Could not import parameters from file")
|
|
1088
|
|
|
1142
|
|
|
1089
|
kwargs = {}
|
|
1143
|
kwargs = {}
|
|
1090
|
kwargs['id_dev'] = conf.id
|
|
1144
|
kwargs['id_dev'] = conf.id
|
|
1091
|
kwargs['title'] = 'Device Configuration'
|
|
1145
|
kwargs['title'] = 'Device Configuration'
|
|
1092
|
kwargs['form'] = file_form
|
|
1146
|
kwargs['form'] = file_form
|
|
1093
|
kwargs['suptitle'] = 'Importing file'
|
|
1147
|
kwargs['suptitle'] = 'Importing file'
|
|
1094
|
kwargs['button'] = 'Import'
|
|
1148
|
kwargs['button'] = 'Import'
|
|
1095
|
|
|
1149
|
|
|
1096
|
kwargs.update(sidebar(conf=conf))
|
|
1150
|
kwargs.update(sidebar(conf=conf))
|
|
1097
|
|
|
1151
|
|
|
1098
|
return render(request, 'dev_conf_import.html', kwargs)
|
|
1152
|
return render(request, 'dev_conf_import.html', kwargs)
|
|
1099
|
|
|
1153
|
|
|
1100
|
|
|
1154
|
|
|
1101
|
def dev_conf_export(request, id_conf):
|
|
1155
|
def dev_conf_export(request, id_conf):
|
|
1102
|
|
|
1156
|
|
|
1103
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
1157
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
1104
|
|
|
1158
|
|
|
1105
|
DevConfModel = CONF_MODELS[conf.device.device_type.name]
|
|
1159
|
DevConfModel = CONF_MODELS[conf.device.device_type.name]
|
|
1106
|
|
|
1160
|
|
|
1107
|
conf = DevConfModel.objects.get(pk=id_conf)
|
|
1161
|
conf = DevConfModel.objects.get(pk=id_conf)
|
|
1108
|
|
|
1162
|
|
|
1109
|
if request.method == 'GET':
|
|
1163
|
if request.method == 'GET':
|
|
1110
|
file_form = DownloadFileForm(conf.device.device_type.name)
|
|
1164
|
file_form = DownloadFileForm(conf.device.device_type.name)
|
|
1111
|
|
|
1165
|
|
|
1112
|
if request.method == 'POST':
|
|
1166
|
if request.method == 'POST':
|
|
1113
|
file_form = DownloadFileForm(conf.device.device_type.name, request.POST)
|
|
1167
|
file_form = DownloadFileForm(conf.device.device_type.name, request.POST)
|
|
1114
|
|
|
1168
|
|
|
1115
|
if file_form.is_valid():
|
|
1169
|
if file_form.is_valid():
|
|
1116
|
fields = conf.export_to_file(format = file_form.cleaned_data['format'])
|
|
1170
|
fields = conf.export_to_file(format = file_form.cleaned_data['format'])
|
|
1117
|
|
|
1171
|
|
|
1118
|
response = HttpResponse(content_type=fields['content_type'])
|
|
1172
|
response = HttpResponse(content_type=fields['content_type'])
|
|
1119
|
response['Content-Disposition'] = 'attachment; filename="%s"' %fields['filename']
|
|
1173
|
response['Content-Disposition'] = 'attachment; filename="%s"' %fields['filename']
|
|
1120
|
response.write(fields['content'])
|
|
1174
|
response.write(fields['content'])
|
|
1121
|
|
|
1175
|
|
|
1122
|
return response
|
|
1176
|
return response
|
|
1123
|
|
|
1177
|
|
|
1124
|
messages.error(request, "Could not export parameters")
|
|
1178
|
messages.error(request, "Could not export parameters")
|
|
1125
|
|
|
1179
|
|
|
1126
|
kwargs = {}
|
|
1180
|
kwargs = {}
|
|
1127
|
kwargs['id_dev'] = conf.id
|
|
1181
|
kwargs['id_dev'] = conf.id
|
|
1128
|
kwargs['title'] = 'Device Configuration'
|
|
1182
|
kwargs['title'] = 'Device Configuration'
|
|
1129
|
kwargs['form'] = file_form
|
|
1183
|
kwargs['form'] = file_form
|
|
1130
|
kwargs['suptitle'] = 'Exporting file'
|
|
1184
|
kwargs['suptitle'] = 'Exporting file'
|
|
1131
|
kwargs['button'] = 'Export'
|
|
1185
|
kwargs['button'] = 'Export'
|
|
1132
|
|
|
1186
|
|
|
1133
|
return render(request, 'dev_conf_export.html', kwargs)
|
|
1187
|
return render(request, 'dev_conf_export.html', kwargs)
|
|
1134
|
|
|
1188
|
|
|
1135
|
|
|
1189
|
|
|
1136
|
def dev_conf_delete(request, id_conf):
|
|
1190
|
def dev_conf_delete(request, id_conf):
|
|
1137
|
|
|
1191
|
|
|
1138
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
1192
|
conf = get_object_or_404(Configuration, pk=id_conf)
|
|
1139
|
|
|
1193
|
|
|
1140
|
if request.method=='POST':
|
|
1194
|
if request.method=='POST':
|
|
1141
|
if request.user.is_staff:
|
|
1195
|
if request.user.is_staff:
|
|
1142
|
conf.delete()
|
|
1196
|
conf.delete()
|
|
1143
|
return redirect('url_dev_confs')
|
|
1197
|
return redirect('url_dev_confs')
|
|
1144
|
|
|
1198
|
|
|
1145
|
messages.error(request, 'Not enough permission to delete this object')
|
|
1199
|
messages.error(request, 'Not enough permission to delete this object')
|
|
1146
|
return redirect(conf.get_absolute_url())
|
|
1200
|
return redirect(conf.get_absolute_url())
|
|
1147
|
|
|
1201
|
|
|
1148
|
kwargs = {
|
|
1202
|
kwargs = {
|
|
1149
|
'title': 'Delete',
|
|
1203
|
'title': 'Delete',
|
|
1150
|
'suptitle': 'Experiment',
|
|
1204
|
'suptitle': 'Experiment',
|
|
1151
|
'object': conf,
|
|
1205
|
'object': conf,
|
|
1152
|
'previous': conf.get_absolute_url(),
|
|
1206
|
'previous': conf.get_absolute_url(),
|
|
1153
|
'delete': True
|
|
1207
|
'delete': True
|
|
1154
|
}
|
|
1208
|
}
|
|
1155
|
|
|
1209
|
|
|
1156
|
return render(request, 'confirm.html', kwargs)
|
|
1210
|
return render(request, 'confirm.html', kwargs)
|
|
1157
|
|
|
1211
|
|
|
1158
|
|
|
1212
|
|
|
1159
|
def sidebar(**kwargs):
|
|
1213
|
def sidebar(**kwargs):
|
|
1160
|
|
|
1214
|
|
|
1161
|
side_data = {}
|
|
1215
|
side_data = {}
|
|
1162
|
|
|
1216
|
|
|
1163
|
conf = kwargs.get('conf', None)
|
|
1217
|
conf = kwargs.get('conf', None)
|
|
1164
|
experiment = kwargs.get('experiment', None)
|
|
1218
|
experiment = kwargs.get('experiment', None)
|
|
1165
|
|
|
1219
|
|
|
1166
|
if not experiment:
|
|
1220
|
if not experiment:
|
|
1167
|
experiment = conf.experiment
|
|
1221
|
experiment = conf.experiment
|
|
1168
|
|
|
1222
|
|
|
1169
|
if experiment:
|
|
1223
|
if experiment:
|
|
1170
|
side_data['experiment'] = experiment
|
|
1224
|
side_data['experiment'] = experiment
|
|
1171
|
campaign = experiment.campaign_set.all()
|
|
1225
|
campaign = experiment.campaign_set.all()
|
|
1172
|
if campaign:
|
|
1226
|
if campaign:
|
|
1173
|
side_data['campaign'] = campaign[0]
|
|
1227
|
side_data['campaign'] = campaign[0]
|
|
1174
|
experiments = campaign[0].experiments.all()
|
|
1228
|
experiments = campaign[0].experiments.all()
|
|
1175
|
else:
|
|
1229
|
else:
|
|
1176
|
experiments = [experiment]
|
|
1230
|
experiments = [experiment]
|
|
1177
|
configurations = experiment.configuration_set.filter(type=0)
|
|
1231
|
configurations = experiment.configuration_set.filter(type=0)
|
|
1178
|
side_data['side_experiments'] = experiments
|
|
1232
|
side_data['side_experiments'] = experiments
|
|
1179
|
side_data['side_configurations'] = configurations
|
|
1233
|
side_data['side_configurations'] = configurations
|
|
1180
|
|
|
1234
|
|
|
1181
|
return side_data
|
|
1235
|
return side_data
|
|
1182
|
|
|
1236
|
|
|
1183
|
def get_paginator(model, page, order, filters={}, n=10):
|
|
1237
|
def get_paginator(model, page, order, filters={}, n=10):
|
|
1184
|
|
|
1238
|
|
|
1185
|
kwargs = {}
|
|
1239
|
kwargs = {}
|
|
1186
|
query = Q()
|
|
1240
|
query = Q()
|
|
1187
|
if isinstance(filters, QueryDict):
|
|
1241
|
if isinstance(filters, QueryDict):
|
|
1188
|
filters = filters.dict()
|
|
1242
|
filters = filters.dict()
|
|
1189
|
[filters.pop(key) for key in filters.keys() if filters[key] in ('', ' ')]
|
|
1243
|
[filters.pop(key) for key in filters.keys() if filters[key] in ('', ' ')]
|
|
1190
|
filters.pop('page', None)
|
|
1244
|
filters.pop('page', None)
|
|
1191
|
|
|
1245
|
|
|
1192
|
if 'start_date' in filters:
|
|
1246
|
if 'start_date' in filters:
|
|
1193
|
filters['start_date__gte'] = filters.pop('start_date')
|
|
1247
|
filters['start_date__gte'] = filters.pop('start_date')
|
|
1194
|
if 'end_date' in filters:
|
|
1248
|
if 'end_date' in filters:
|
|
1195
|
filters['start_date__lte'] = filters.pop('end_date')
|
|
1249
|
filters['start_date__lte'] = filters.pop('end_date')
|
|
1196
|
if 'tags' in filters:
|
|
1250
|
if 'tags' in filters:
|
|
1197
|
tags = filters.pop('tags')
|
|
1251
|
tags = filters.pop('tags')
|
|
1198
|
if 'tags' in model._meta.get_all_field_names():
|
|
1252
|
if 'tags' in model._meta.get_all_field_names():
|
|
1199
|
query = query | Q(tags__icontains=tags)
|
|
1253
|
query = query | Q(tags__icontains=tags)
|
|
1200
|
if 'name' in model._meta.get_all_field_names():
|
|
1254
|
if 'name' in model._meta.get_all_field_names():
|
|
1201
|
query = query | Q(name__icontains=tags)
|
|
1255
|
query = query | Q(name__icontains=tags)
|
|
1202
|
if 'location' in model._meta.get_all_field_names():
|
|
1256
|
if 'location' in model._meta.get_all_field_names():
|
|
1203
|
query = query | Q(location__name__icontains=tags)
|
|
1257
|
query = query | Q(location__name__icontains=tags)
|
|
1204
|
if 'device' in model._meta.get_all_field_names():
|
|
1258
|
if 'device' in model._meta.get_all_field_names():
|
|
1205
|
query = query | Q(device__name__icontains=tags)
|
|
1259
|
query = query | Q(device__name__icontains=tags)
|
|
1206
|
|
|
1260
|
|
|
1207
|
object_list = model.objects.filter(query, **filters).order_by(*order)
|
|
1261
|
object_list = model.objects.filter(query, **filters).order_by(*order)
|
|
1208
|
paginator = Paginator(object_list, n)
|
|
1262
|
paginator = Paginator(object_list, n)
|
|
1209
|
|
|
1263
|
|
|
1210
|
try:
|
|
1264
|
try:
|
|
1211
|
objects = paginator.page(page)
|
|
1265
|
objects = paginator.page(page)
|
|
1212
|
except PageNotAnInteger:
|
|
1266
|
except PageNotAnInteger:
|
|
1213
|
objects = paginator.page(1)
|
|
1267
|
objects = paginator.page(1)
|
|
1214
|
except EmptyPage:
|
|
1268
|
except EmptyPage:
|
|
1215
|
objects = paginator.page(paginator.num_pages)
|
|
1269
|
objects = paginator.page(paginator.num_pages)
|
|
1216
|
|
|
1270
|
|
|
1217
|
kwargs['objects'] = objects
|
|
1271
|
kwargs['objects'] = objects
|
|
1218
|
kwargs['offset'] = (int(page)-1)*n if page else 0
|
|
1272
|
kwargs['offset'] = (int(page)-1)*n if page else 0
|
|
1219
|
|
|
1273
|
|
|
1220
|
return kwargs
|
|
1274
|
return kwargs
|
|
1221
|
|
|
1275
|
|
|
1222
|
def operation(request, id_camp=None):
|
|
1276
|
def operation(request, id_camp=None):
|
|
1223
|
|
|
1277
|
|
|
1224
|
if not id_camp:
|
|
1278
|
if not id_camp:
|
|
1225
|
campaigns = Campaign.objects.all().order_by('-start_date')
|
|
1279
|
campaigns = Campaign.objects.all().order_by('-start_date')
|
|
1226
|
|
|
1280
|
|
|
1227
|
if not campaigns:
|
|
1281
|
if not campaigns:
|
|
1228
|
kwargs = {}
|
|
1282
|
kwargs = {}
|
|
1229
|
kwargs['title'] = 'No Campaigns'
|
|
1283
|
kwargs['title'] = 'No Campaigns'
|
|
1230
|
kwargs['suptitle'] = 'Empty'
|
|
1284
|
kwargs['suptitle'] = 'Empty'
|
|
1231
|
return render(request, 'operation.html', kwargs)
|
|
1285
|
return render(request, 'operation.html', kwargs)
|
|
1232
|
|
|
1286
|
|
|
1233
|
id_camp = campaigns[0].id
|
|
1287
|
id_camp = campaigns[0].id
|
|
1234
|
|
|
1288
|
|
|
1235
|
campaign = get_object_or_404(Campaign, pk = id_camp)
|
|
1289
|
campaign = get_object_or_404(Campaign, pk = id_camp)
|
|
1236
|
|
|
1290
|
|
|
1237
|
if request.method=='GET':
|
|
1291
|
if request.method=='GET':
|
|
1238
|
form = OperationForm(initial={'campaign': campaign.id}, length = 5)
|
|
1292
|
form = OperationForm(initial={'campaign': campaign.id}, length = 5)
|
|
1239
|
|
|
1293
|
|
|
1240
|
if request.method=='POST':
|
|
1294
|
if request.method=='POST':
|
|
1241
|
form = OperationForm(request.POST, initial={'campaign':campaign.id}, length = 5)
|
|
1295
|
form = OperationForm(request.POST, initial={'campaign':campaign.id}, length = 5)
|
|
1242
|
|
|
1296
|
|
|
1243
|
if form.is_valid():
|
|
1297
|
if form.is_valid():
|
|
1244
|
return redirect('url_operation', id_camp=campaign.id)
|
|
1298
|
return redirect('url_operation', id_camp=campaign.id)
|
|
1245
|
#locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct()
|
|
1299
|
#locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct()
|
|
1246
|
experiments = Experiment.objects.filter(campaign__pk=campaign.id)
|
|
1300
|
experiments = Experiment.objects.filter(campaign__pk=campaign.id)
|
|
1247
|
#for exs in experiments:
|
|
1301
|
#for exs in experiments:
|
|
1248
|
# exs.get_status()
|
|
1302
|
# exs.get_status()
|
|
1249
|
locations= Location.objects.filter(experiment=experiments).distinct()
|
|
1303
|
locations= Location.objects.filter(experiment=experiments).distinct()
|
|
1250
|
#experiments = [Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) for location in locations]
|
|
1304
|
#experiments = [Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) for location in locations]
|
|
1251
|
kwargs = {}
|
|
1305
|
kwargs = {}
|
|
1252
|
#---Campaign
|
|
1306
|
#---Campaign
|
|
1253
|
kwargs['campaign'] = campaign
|
|
1307
|
kwargs['campaign'] = campaign
|
|
1254
|
kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description']
|
|
1308
|
kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description']
|
|
1255
|
#---Experiment
|
|
1309
|
#---Experiment
|
|
1256
|
keys = ['id', 'name', 'start_time', 'end_time', 'status']
|
|
1310
|
keys = ['id', 'name', 'start_time', 'end_time', 'status']
|
|
1257
|
kwargs['experiment_keys'] = keys[1:]
|
|
1311
|
kwargs['experiment_keys'] = keys[1:]
|
|
1258
|
kwargs['experiments'] = experiments
|
|
1312
|
kwargs['experiments'] = experiments
|
|
1259
|
#---Radar
|
|
1313
|
#---Radar
|
|
1260
|
kwargs['locations'] = locations
|
|
1314
|
kwargs['locations'] = locations
|
|
1261
|
#---Else
|
|
1315
|
#---Else
|
|
1262
|
kwargs['title'] = 'Campaign'
|
|
1316
|
kwargs['title'] = 'Campaign'
|
|
1263
|
kwargs['suptitle'] = campaign.name
|
|
1317
|
kwargs['suptitle'] = campaign.name
|
|
1264
|
kwargs['form'] = form
|
|
1318
|
kwargs['form'] = form
|
|
1265
|
kwargs['button'] = 'Search'
|
|
1319
|
kwargs['button'] = 'Search'
|
|
1266
|
kwargs['details'] = True
|
|
1320
|
kwargs['details'] = True
|
|
1267
|
kwargs['search_button'] = True
|
|
1321
|
kwargs['search_button'] = True
|
|
1268
|
|
|
1322
|
|
|
1269
|
return render(request, 'operation.html', kwargs)
|
|
1323
|
return render(request, 'operation.html', kwargs)
|
|
1270
|
|
|
1324
|
|
|
1271
|
|
|
1325
|
|
|
1272
|
def operation_search(request, id_camp=None):
|
|
1326
|
def operation_search(request, id_camp=None):
|
|
1273
|
|
|
1327
|
|
|
1274
|
|
|
1328
|
|
|
1275
|
if not id_camp:
|
|
1329
|
if not id_camp:
|
|
1276
|
campaigns = Campaign.objects.all().order_by('-start_date')
|
|
1330
|
campaigns = Campaign.objects.all().order_by('-start_date')
|
|
1277
|
|
|
1331
|
|
|
1278
|
if not campaigns:
|
|
1332
|
if not campaigns:
|
|
1279
|
return render(request, 'operation.html', {})
|
|
1333
|
return render(request, 'operation.html', {})
|
|
1280
|
|
|
1334
|
|
|
1281
|
id_camp = campaigns[0].id
|
|
1335
|
id_camp = campaigns[0].id
|
|
1282
|
campaign = get_object_or_404(Campaign, pk = id_camp)
|
|
1336
|
campaign = get_object_or_404(Campaign, pk = id_camp)
|
|
1283
|
|
|
1337
|
|
|
1284
|
if request.method=='GET':
|
|
1338
|
if request.method=='GET':
|
|
1285
|
form = OperationSearchForm(initial={'campaign': campaign.id})
|
|
1339
|
form = OperationSearchForm(initial={'campaign': campaign.id})
|
|
1286
|
|
|
1340
|
|
|
1287
|
if request.method=='POST':
|
|
1341
|
if request.method=='POST':
|
|
1288
|
form = OperationSearchForm(request.POST, initial={'campaign':campaign.id})
|
|
1342
|
form = OperationSearchForm(request.POST, initial={'campaign':campaign.id})
|
|
1289
|
|
|
1343
|
|
|
1290
|
if form.is_valid():
|
|
1344
|
if form.is_valid():
|
|
1291
|
return redirect('url_operation', id_camp=campaign.id)
|
|
1345
|
return redirect('url_operation', id_camp=campaign.id)
|
|
1292
|
|
|
1346
|
|
|
1293
|
#locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct()
|
|
1347
|
#locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct()
|
|
1294
|
experiments = Experiment.objects.filter(campaign__pk=campaign.id)
|
|
1348
|
experiments = Experiment.objects.filter(campaign__pk=campaign.id)
|
|
1295
|
#for exs in experiments:
|
|
1349
|
#for exs in experiments:
|
|
1296
|
# exs.get_status()
|
|
1350
|
# exs.get_status()
|
|
1297
|
locations= Location.objects.filter(experiment=experiments).distinct()
|
|
1351
|
locations= Location.objects.filter(experiment=experiments).distinct()
|
|
1298
|
form = OperationSearchForm(initial={'campaign': campaign.id})
|
|
1352
|
form = OperationSearchForm(initial={'campaign': campaign.id})
|
|
1299
|
|
|
1353
|
|
|
1300
|
kwargs = {}
|
|
1354
|
kwargs = {}
|
|
1301
|
#---Campaign
|
|
1355
|
#---Campaign
|
|
1302
|
kwargs['campaign'] = campaign
|
|
1356
|
kwargs['campaign'] = campaign
|
|
1303
|
kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description']
|
|
1357
|
kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description']
|
|
1304
|
#---Experiment
|
|
1358
|
#---Experiment
|
|
1305
|
keys = ['id', 'name', 'start_time', 'end_time', 'status']
|
|
1359
|
keys = ['id', 'name', 'start_time', 'end_time', 'status']
|
|
1306
|
kwargs['experiment_keys'] = keys[1:]
|
|
1360
|
kwargs['experiment_keys'] = keys[1:]
|
|
1307
|
kwargs['experiments'] = experiments
|
|
1361
|
kwargs['experiments'] = experiments
|
|
1308
|
#---Radar
|
|
1362
|
#---Radar
|
|
1309
|
kwargs['locations'] = locations
|
|
1363
|
kwargs['locations'] = locations
|
|
1310
|
#---Else
|
|
1364
|
#---Else
|
|
1311
|
kwargs['title'] = 'Campaign'
|
|
1365
|
kwargs['title'] = 'Campaign'
|
|
1312
|
kwargs['suptitle'] = campaign.name
|
|
1366
|
kwargs['suptitle'] = campaign.name
|
|
1313
|
kwargs['form'] = form
|
|
1367
|
kwargs['form'] = form
|
|
1314
|
kwargs['button'] = 'Select'
|
|
1368
|
kwargs['button'] = 'Select'
|
|
1315
|
kwargs['details'] = True
|
|
1369
|
kwargs['details'] = True
|
|
1316
|
kwargs['search_button'] = False
|
|
1370
|
kwargs['search_button'] = False
|
|
1317
|
|
|
1371
|
|
|
1318
|
return render(request, 'operation.html', kwargs)
|
|
1372
|
return render(request, 'operation.html', kwargs)
|
|
1319
|
|
|
1373
|
|
|
1320
|
|
|
1374
|
|
|
1321
|
def radar_play(request, id_camp, id_radar):
|
|
1375
|
def radar_play(request, id_camp, id_radar):
|
|
1322
|
campaign = get_object_or_404(Campaign, pk = id_camp)
|
|
1376
|
campaign = get_object_or_404(Campaign, pk = id_camp)
|
|
1323
|
radar = get_object_or_404(Location, pk = id_radar)
|
|
1377
|
radar = get_object_or_404(Location, pk = id_radar)
|
|
1324
|
today = datetime.today()
|
|
1378
|
today = datetime.today()
|
|
1325
|
now = today.time()
|
|
1379
|
now = today.time()
|
|
1326
|
|
|
1380
|
|
|
1327
|
#--Clear Old Experiments From RunningExperiment Object
|
|
1381
|
#--Clear Old Experiments From RunningExperiment Object
|
|
1328
|
running_experiment = RunningExperiment.objects.filter(radar=radar)
|
|
1382
|
running_experiment = RunningExperiment.objects.filter(radar=radar)
|
|
1329
|
if running_experiment:
|
|
1383
|
if running_experiment:
|
|
1330
|
running_experiment = running_experiment[0]
|
|
1384
|
running_experiment = running_experiment[0]
|
|
1331
|
running_experiment.running_experiment.clear()
|
|
1385
|
running_experiment.running_experiment.clear()
|
|
1332
|
running_experiment.save()
|
|
1386
|
running_experiment.save()
|
|
1333
|
|
|
1387
|
|
|
1334
|
#--If campaign datetime is ok:
|
|
1388
|
#--If campaign datetime is ok:
|
|
1335
|
if today >= campaign.start_date and today <= campaign.end_date:
|
|
1389
|
if today >= campaign.start_date and today <= campaign.end_date:
|
|
1336
|
experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar)
|
|
1390
|
experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar)
|
|
1337
|
for exp in experiments:
|
|
1391
|
for exp in experiments:
|
|
1338
|
#--If experiment time is ok:
|
|
1392
|
#--If experiment time is ok:
|
|
1339
|
if now >= exp.start_time and now <= exp.end_time:
|
|
1393
|
if now >= exp.start_time and now <= exp.end_time:
|
|
1340
|
configurations = Configuration.objects.filter(experiment = exp)
|
|
1394
|
configurations = Configuration.objects.filter(experiment = exp)
|
|
1341
|
for conf in configurations:
|
|
1395
|
for conf in configurations:
|
|
1342
|
if 'cgs' in conf.device.device_type.name:
|
|
1396
|
if 'cgs' in conf.device.device_type.name:
|
|
1343
|
conf.status_device()
|
|
1397
|
conf.status_device()
|
|
1344
|
else:
|
|
1398
|
else:
|
|
1345
|
answer = conf.start_device()
|
|
1399
|
answer = conf.start_device()
|
|
1346
|
conf.status_device()
|
|
1400
|
conf.status_device()
|
|
1347
|
#--Running Experiment
|
|
1401
|
#--Running Experiment
|
|
1348
|
old_running_experiment = RunningExperiment.objects.filter(radar=radar)
|
|
1402
|
old_running_experiment = RunningExperiment.objects.filter(radar=radar)
|
|
1349
|
#--If RunningExperiment element exists
|
|
1403
|
#--If RunningExperiment element exists
|
|
1350
|
if old_running_experiment:
|
|
1404
|
if old_running_experiment:
|
|
1351
|
old_running_experiment = old_running_experiment[0]
|
|
1405
|
old_running_experiment = old_running_experiment[0]
|
|
1352
|
old_running_experiment.running_experiment.add(exp)
|
|
1406
|
old_running_experiment.running_experiment.add(exp)
|
|
1353
|
old_running_experiment.status = 3
|
|
1407
|
old_running_experiment.status = 3
|
|
1354
|
old_running_experiment.save()
|
|
1408
|
old_running_experiment.save()
|
|
1355
|
#--Create a new Running_Experiment Object
|
|
1409
|
#--Create a new Running_Experiment Object
|
|
1356
|
else:
|
|
1410
|
else:
|
|
1357
|
new_running_experiment = RunningExperiment(
|
|
1411
|
new_running_experiment = RunningExperiment(
|
|
1358
|
radar = radar,
|
|
1412
|
radar = radar,
|
|
1359
|
status = 3,
|
|
1413
|
status = 3,
|
|
1360
|
)
|
|
1414
|
)
|
|
1361
|
new_running_experiment.save()
|
|
1415
|
new_running_experiment.save()
|
|
1362
|
new_running_experiment.running_experiment.add(exp)
|
|
1416
|
new_running_experiment.running_experiment.add(exp)
|
|
1363
|
new_running_experiment.save()
|
|
1417
|
new_running_experiment.save()
|
|
1364
|
|
|
1418
|
|
|
1365
|
if answer:
|
|
1419
|
if answer:
|
|
1366
|
messages.success(request, conf.message)
|
|
1420
|
messages.success(request, conf.message)
|
|
1367
|
exp.status=2
|
|
1421
|
exp.status=2
|
|
1368
|
exp.save()
|
|
1422
|
exp.save()
|
|
1369
|
else:
|
|
1423
|
else:
|
|
1370
|
messages.error(request, conf.message)
|
|
1424
|
messages.error(request, conf.message)
|
|
1371
|
else:
|
|
1425
|
else:
|
|
1372
|
if exp.status == 1 or exp.status == 3:
|
|
1426
|
if exp.status == 1 or exp.status == 3:
|
|
1373
|
exp.status=3
|
|
1427
|
exp.status=3
|
|
1374
|
exp.save()
|
|
1428
|
exp.save()
|
|
1375
|
|
|
1429
|
|
|
1376
|
|
|
1430
|
|
|
1377
|
route = request.META['HTTP_REFERER']
|
|
1431
|
route = request.META['HTTP_REFERER']
|
|
1378
|
route = str(route)
|
|
1432
|
route = str(route)
|
|
1379
|
if 'search' in route:
|
|
1433
|
if 'search' in route:
|
|
1380
|
return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp]))
|
|
1434
|
return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp]))
|
|
1381
|
else:
|
|
1435
|
else:
|
|
1382
|
return HttpResponseRedirect(reverse('url_operation', args=[id_camp]))
|
|
1436
|
return HttpResponseRedirect(reverse('url_operation', args=[id_camp]))
|
|
1383
|
|
|
1437
|
|
|
1384
|
|
|
1438
|
|
|
1385
|
def radar_stop(request, id_camp, id_radar):
|
|
1439
|
def radar_stop(request, id_camp, id_radar):
|
|
1386
|
campaign = get_object_or_404(Campaign, pk = id_camp)
|
|
1440
|
campaign = get_object_or_404(Campaign, pk = id_camp)
|
|
1387
|
radar = get_object_or_404(Location, pk = id_radar)
|
|
1441
|
radar = get_object_or_404(Location, pk = id_radar)
|
|
1388
|
experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar)
|
|
1442
|
experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar)
|
|
1389
|
|
|
1443
|
|
|
1390
|
for exp in experiments:
|
|
1444
|
for exp in experiments:
|
|
1391
|
configurations = Configuration.objects.filter(experiment = exp)
|
|
1445
|
configurations = Configuration.objects.filter(experiment = exp)
|
|
1392
|
for conf in configurations:
|
|
1446
|
for conf in configurations:
|
|
1393
|
if 'cgs' in conf.device.device_type.name:
|
|
1447
|
if 'cgs' in conf.device.device_type.name:
|
|
1394
|
conf.status_device()
|
|
1448
|
conf.status_device()
|
|
1395
|
else:
|
|
1449
|
else:
|
|
1396
|
answer = conf.stop_device()
|
|
1450
|
answer = conf.stop_device()
|
|
1397
|
conf.status_device()
|
|
1451
|
conf.status_device()
|
|
1398
|
|
|
1452
|
|
|
1399
|
if answer:
|
|
1453
|
if answer:
|
|
1400
|
messages.success(request, conf.message)
|
|
1454
|
messages.success(request, conf.message)
|
|
1401
|
exp.status=1
|
|
1455
|
exp.status=1
|
|
1402
|
exp.save()
|
|
1456
|
exp.save()
|
|
1403
|
else:
|
|
1457
|
else:
|
|
1404
|
messages.error(request, conf.message)
|
|
1458
|
messages.error(request, conf.message)
|
|
1405
|
|
|
1459
|
|
|
1406
|
|
|
1460
|
|
|
1407
|
route = request.META['HTTP_REFERER']
|
|
1461
|
route = request.META['HTTP_REFERER']
|
|
1408
|
route = str(route)
|
|
1462
|
route = str(route)
|
|
1409
|
if 'search' in route:
|
|
1463
|
if 'search' in route:
|
|
1410
|
return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp]))
|
|
1464
|
return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp]))
|
|
1411
|
else:
|
|
1465
|
else:
|
|
1412
|
return HttpResponseRedirect(reverse('url_operation', args=[id_camp]))
|
|
1466
|
return HttpResponseRedirect(reverse('url_operation', args=[id_camp]))
|
|
1413
|
|
|
1467
|
|
|
1414
|
|
|
1468
|
|
|
1415
|
def radar_refresh(request, id_camp, id_radar):
|
|
1469
|
def radar_refresh(request, id_camp, id_radar):
|
|
1416
|
|
|
1470
|
|
|
1417
|
campaign = get_object_or_404(Campaign, pk = id_camp)
|
|
1471
|
campaign = get_object_or_404(Campaign, pk = id_camp)
|
|
1418
|
radar = get_object_or_404(Location, pk = id_radar)
|
|
1472
|
radar = get_object_or_404(Location, pk = id_radar)
|
|
1419
|
experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar)
|
|
1473
|
experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar)
|
|
1420
|
for exs in experiments:
|
|
1474
|
for exs in experiments:
|
|
1421
|
exs.get_status()
|
|
1475
|
exs.get_status()
|
|
1422
|
|
|
1476
|
|
|
1423
|
route = request.META['HTTP_REFERER']
|
|
1477
|
route = request.META['HTTP_REFERER']
|
|
1424
|
route = str(route)
|
|
1478
|
route = str(route)
|
|
1425
|
if 'search' in route:
|
|
1479
|
if 'search' in route:
|
|
1426
|
return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp]))
|
|
1480
|
return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp]))
|
|
1427
|
else:
|
|
1481
|
else:
|
|
1428
|
return HttpResponseRedirect(reverse('url_operation', args=[id_camp]))
|
|
1482
|
return HttpResponseRedirect(reverse('url_operation', args=[id_camp]))
|
|
1429
|
|
|
|
|