@@ -1,95 +1,104 | |||
|
1 | 1 | {% extends "base.html" %} |
|
2 | 2 | {% load bootstrap3 %} |
|
3 | 3 | {% load static %} |
|
4 | 4 | {% load main_tags %} |
|
5 | 5 | {% block extra-head %} |
|
6 | 6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> |
|
7 | 7 | {% endblock %} |
|
8 | 8 | |
|
9 | 9 | {% block camp-active %}active{% endblock %} |
|
10 | 10 | |
|
11 | 11 | {% block content-title %}{{title}}{% endblock %} |
|
12 | 12 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
13 | 13 | |
|
14 | 14 | {% block content %} |
|
15 | 15 | |
|
16 | 16 | <form class="form" method="post" action=""> |
|
17 | 17 | {% csrf_token %} |
|
18 | 18 | {% bootstrap_form form layout='horizontal' size='medium' %} |
|
19 | 19 | <div style="clear: both;"></div> |
|
20 | 20 | <br> |
|
21 | 21 | <button type="submit" class="btn btn-primary pull-right">{{button}}</button> |
|
22 | 22 | <br> |
|
23 | 23 | <br> |
|
24 | 24 | </form> |
|
25 | 25 | <br> |
|
26 | <br> | |
|
27 | 26 | |
|
28 | 27 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true" > |
|
29 | 28 | |
|
30 | 29 | {% for radar in radars %} |
|
31 | 30 | |
|
32 | 31 | <div class="panel panel-default"> |
|
33 | 32 | <div class="panel-heading" role="tab" id="headingTwo"> |
|
34 | 33 | <h4 class="panel-title"> |
|
34 | ||
|
35 | 35 | <a class="collapsed" role="button" data-toggle="collapse" href="#collapseTwo-{{ radar.id }}" aria-expanded="false" aria-controls="collapseTwo"> |
|
36 | 36 | {{radar.name}}: Experiment List |
|
37 | <span> | |
|
38 | </span> | |
|
37 | 39 | </a> |
|
40 | <button type="button" class="btn btn-primary pull-right btn-xs" aria-label="Left Align" style="margin-left: 10px"> | |
|
41 | <span class="glyphicon glyphicon-play" aria-hidden="true"></span> | |
|
42 | </button> | |
|
43 | <button type="button" class="btn btn-primary pull-right btn-xs" aria-label="Left Align" style="margin-left: 10px"> | |
|
44 | <span class="glyphicon glyphicon-stop" aria-hidden="true"></span> | |
|
45 | </button> | |
|
46 | ||
|
38 | 47 | </h4> |
|
39 | 48 | </div> |
|
40 | 49 | |
|
41 | 50 | <div id="collapseTwo-{{ radar.id }}" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> |
|
42 | 51 | <div class="panel-body"> |
|
43 | 52 | <table class="table table-hover"> |
|
44 | 53 | <tr> |
|
45 | 54 | |
|
46 | 55 | {% for header in experiment_keys %} |
|
47 | 56 | <th>{{ header|title }}</th> |
|
48 | 57 | {% endfor%} |
|
49 | 58 | </tr> |
|
50 | 59 | {% for item in experiments %} |
|
51 | 60 | {% for exs in item %} |
|
52 | 61 | <tr class="clickable-row" data-href="{% url 'url_experiment' exs.id %}" > |
|
53 | 62 | |
|
54 | 63 | {% for key in experiment_keys %} |
|
55 | 64 | {% if radar.name in exs.radar.name %} |
|
56 | 65 | <td>{{ exs|attr:key }}</td> |
|
57 | 66 | {% endif %} |
|
58 | 67 | {% endfor %} |
|
59 | 68 | {% endfor %} |
|
60 | 69 | </tr> |
|
61 | 70 | {% endfor %} |
|
62 | 71 | </table> |
|
63 | 72 | </div> |
|
64 | 73 | </div> |
|
65 | 74 | </div> |
|
66 | 75 | {% endfor %} |
|
67 | 76 | </div> |
|
68 | 77 | |
|
69 | 78 | {% endblock %} |
|
70 | 79 | |
|
71 | 80 | |
|
72 | 81 | |
|
73 | 82 | {% block extra-js%} |
|
74 | 83 | <script type="text/javascript"> |
|
75 | 84 | |
|
76 | 85 | //$("#bt_add").click(function() { |
|
77 | 86 | //alert("sometext"); |
|
78 | 87 | // document.location = "{% url 'url_operation' campaign.id %}"; |
|
79 | 88 | //}); |
|
80 | 89 | |
|
81 | 90 | $(".clickable-row").click(function() { |
|
82 | 91 | document.location = $(this).data("href"); |
|
83 | 92 | }); |
|
84 | 93 | |
|
85 | 94 | $(document).ready(function() { |
|
86 | 95 | $("#id_campaign").change(function() { |
|
87 | 96 | var id_camp = document.getElementById("id_campaign").value; |
|
88 | 97 | //alert(id_camp); |
|
89 | 98 | document.location = "{% url 'url_operation'%}"+String(id_camp); |
|
90 | 99 | }); |
|
91 | 100 | }); |
|
92 | 101 | |
|
93 | 102 | |
|
94 | 103 | </script> |
|
95 | 104 | {% endblock %} No newline at end of file |
@@ -1,631 +1,631 | |||
|
1 | 1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse |
|
2 | 2 | from django.contrib import messages |
|
3 | 3 | |
|
4 | 4 | from datetime import datetime |
|
5 | 5 | |
|
6 | 6 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, OperationForm |
|
7 | 7 | from apps.cgs.forms import CGSConfigurationForm |
|
8 | 8 | from apps.jars.forms import JARSConfigurationForm |
|
9 | 9 | from apps.usrp.forms import USRPConfigurationForm |
|
10 | 10 | from apps.abs.forms import ABSConfigurationForm |
|
11 | 11 | from apps.rc.forms import RCConfigurationForm |
|
12 | 12 | from apps.dds.forms import DDSConfigurationForm |
|
13 | 13 | |
|
14 | 14 | from .models import Campaign, Experiment, Device, Configuration, Location, Radar |
|
15 | 15 | from apps.cgs.models import CGSConfiguration |
|
16 | 16 | from apps.jars.models import JARSConfiguration |
|
17 | 17 | from apps.usrp.models import USRPConfiguration |
|
18 | 18 | from apps.abs.models import ABSConfiguration |
|
19 | 19 | from apps.rc.models import RCConfiguration |
|
20 | 20 | from apps.dds.models import DDSConfiguration |
|
21 | 21 | |
|
22 | 22 | # Create your views here. |
|
23 | 23 | |
|
24 | 24 | CONF_FORMS = { |
|
25 | 25 | 'rc': RCConfigurationForm, |
|
26 | 26 | 'dds': DDSConfigurationForm, |
|
27 | 27 | 'jars': JARSConfigurationForm, |
|
28 | 28 | 'cgs': CGSConfigurationForm, |
|
29 | 29 | 'abs': ABSConfigurationForm, |
|
30 | 30 | 'usrp': USRPConfigurationForm, |
|
31 | 31 | } |
|
32 | 32 | |
|
33 | 33 | CONF_MODELS = { |
|
34 | 34 | 'rc': RCConfiguration, |
|
35 | 35 | 'dds': DDSConfiguration, |
|
36 | 36 | 'jars': JARSConfiguration, |
|
37 | 37 | 'cgs': CGSConfiguration, |
|
38 | 38 | 'abs': ABSConfiguration, |
|
39 | 39 | 'usrp': USRPConfiguration, |
|
40 | 40 | } |
|
41 | 41 | |
|
42 | 42 | def index(request): |
|
43 | 43 | kwargs = {} |
|
44 | 44 | |
|
45 | 45 | return render(request, 'index.html', kwargs) |
|
46 | 46 | |
|
47 | 47 | def locations(request): |
|
48 | 48 | |
|
49 | 49 | locations = Location.objects.all().order_by('name') |
|
50 | 50 | |
|
51 | 51 | keys = ['id', 'name', 'description'] |
|
52 | 52 | |
|
53 | 53 | kwargs = {} |
|
54 | 54 | kwargs['location_keys'] = keys[1:] |
|
55 | 55 | kwargs['locations'] = locations |
|
56 | 56 | kwargs['title'] = 'Location' |
|
57 | 57 | kwargs['suptitle'] = 'List' |
|
58 | 58 | kwargs['button'] = 'New Location' |
|
59 | 59 | |
|
60 | 60 | return render(request, 'locations.html', kwargs) |
|
61 | 61 | |
|
62 | 62 | def location(request, id_loc): |
|
63 | 63 | |
|
64 | 64 | location = get_object_or_404(Location, pk=id_loc) |
|
65 | 65 | |
|
66 | 66 | kwargs = {} |
|
67 | 67 | kwargs['location'] = location |
|
68 | 68 | kwargs['location_keys'] = ['name', 'description'] |
|
69 | 69 | |
|
70 | 70 | kwargs['title'] = 'Location' |
|
71 | 71 | kwargs['suptitle'] = 'Details' |
|
72 | 72 | |
|
73 | 73 | return render(request, 'location.html', kwargs) |
|
74 | 74 | |
|
75 | 75 | def location_new(request): |
|
76 | 76 | |
|
77 | 77 | if request.method == 'GET': |
|
78 | 78 | form = LocationForm() |
|
79 | 79 | |
|
80 | 80 | if request.method == 'POST': |
|
81 | 81 | form = LocationForm(request.POST) |
|
82 | 82 | |
|
83 | 83 | if form.is_valid(): |
|
84 | 84 | form.save() |
|
85 | 85 | return redirect('url_locations') |
|
86 | 86 | |
|
87 | 87 | kwargs = {} |
|
88 | 88 | kwargs['form'] = form |
|
89 | 89 | kwargs['title'] = 'Location' |
|
90 | 90 | kwargs['suptitle'] = 'New' |
|
91 | 91 | kwargs['button'] = 'Create' |
|
92 | 92 | |
|
93 | 93 | return render(request, 'location_edit.html', kwargs) |
|
94 | 94 | |
|
95 | 95 | def location_edit(request, id_loc): |
|
96 | 96 | |
|
97 | 97 | location = get_object_or_404(Location, pk=id_loc) |
|
98 | 98 | |
|
99 | 99 | if request.method=='GET': |
|
100 | 100 | form = LocationForm(instance=location) |
|
101 | 101 | |
|
102 | 102 | if request.method=='POST': |
|
103 | 103 | form = LocationForm(request.POST, instance=location) |
|
104 | 104 | |
|
105 | 105 | if form.is_valid(): |
|
106 | 106 | form.save() |
|
107 | 107 | return redirect('url_locations') |
|
108 | 108 | |
|
109 | 109 | kwargs = {} |
|
110 | 110 | kwargs['form'] = form |
|
111 | 111 | kwargs['title'] = 'Location' |
|
112 | 112 | kwargs['suptitle'] = 'Edit' |
|
113 | 113 | kwargs['button'] = 'Update' |
|
114 | 114 | |
|
115 | 115 | return render(request, 'location_edit.html', kwargs) |
|
116 | 116 | |
|
117 | 117 | def location_delete(request, id_loc): |
|
118 | 118 | |
|
119 | 119 | location = get_object_or_404(Location, pk=id_loc) |
|
120 | 120 | |
|
121 | 121 | if request.method=='POST': |
|
122 | 122 | |
|
123 | 123 | if request.user.is_staff: |
|
124 | 124 | location.delete() |
|
125 | 125 | return redirect('url_locations') |
|
126 | 126 | |
|
127 | 127 | return HttpResponse("Not enough permission to delete this object") |
|
128 | 128 | |
|
129 | 129 | kwargs = {'object':location, 'loc_active':'active', |
|
130 | 130 | 'url_cancel':'url_location', 'id_item':id_loc} |
|
131 | 131 | |
|
132 | 132 | return render(request, 'item_delete.html', kwargs) |
|
133 | 133 | |
|
134 | 134 | def devices(request): |
|
135 | 135 | |
|
136 | 136 | devices = Device.objects.all().order_by('device_type__name') |
|
137 | 137 | |
|
138 | 138 | # keys = ['id', 'device_type__name', 'name', 'ip_address'] |
|
139 | 139 | keys = ['id', 'name', 'ip_address', 'port_address', 'device_type'] |
|
140 | 140 | |
|
141 | 141 | kwargs = {} |
|
142 | 142 | kwargs['device_keys'] = keys[1:] |
|
143 | 143 | kwargs['devices'] = devices#.values(*keys) |
|
144 | 144 | kwargs['title'] = 'Device' |
|
145 | 145 | kwargs['suptitle'] = 'List' |
|
146 | 146 | kwargs['button'] = 'New Device' |
|
147 | 147 | |
|
148 | 148 | return render(request, 'devices.html', kwargs) |
|
149 | 149 | |
|
150 | 150 | def device(request, id_dev): |
|
151 | 151 | |
|
152 | 152 | device = get_object_or_404(Device, pk=id_dev) |
|
153 | 153 | |
|
154 | 154 | kwargs = {} |
|
155 | 155 | kwargs['device'] = device |
|
156 | 156 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] |
|
157 | 157 | |
|
158 | 158 | kwargs['title'] = 'Device' |
|
159 | 159 | kwargs['suptitle'] = 'Details' |
|
160 | 160 | |
|
161 | 161 | return render(request, 'device.html', kwargs) |
|
162 | 162 | |
|
163 | 163 | def device_new(request): |
|
164 | 164 | |
|
165 | 165 | if request.method == 'GET': |
|
166 | 166 | form = DeviceForm() |
|
167 | 167 | |
|
168 | 168 | if request.method == 'POST': |
|
169 | 169 | form = DeviceForm(request.POST) |
|
170 | 170 | |
|
171 | 171 | if form.is_valid(): |
|
172 | 172 | form.save() |
|
173 | 173 | return redirect('url_devices') |
|
174 | 174 | |
|
175 | 175 | kwargs = {} |
|
176 | 176 | kwargs['form'] = form |
|
177 | 177 | kwargs['title'] = 'Device' |
|
178 | 178 | kwargs['suptitle'] = 'New' |
|
179 | 179 | kwargs['button'] = 'Create' |
|
180 | 180 | |
|
181 | 181 | return render(request, 'device_edit.html', kwargs) |
|
182 | 182 | |
|
183 | 183 | def device_edit(request, id_dev): |
|
184 | 184 | |
|
185 | 185 | device = get_object_or_404(Device, pk=id_dev) |
|
186 | 186 | |
|
187 | 187 | if request.method=='GET': |
|
188 | 188 | form = DeviceForm(instance=device) |
|
189 | 189 | |
|
190 | 190 | if request.method=='POST': |
|
191 | 191 | form = DeviceForm(request.POST, instance=device) |
|
192 | 192 | |
|
193 | 193 | if form.is_valid(): |
|
194 | 194 | form.save() |
|
195 | 195 | return redirect('url_devices') |
|
196 | 196 | |
|
197 | 197 | kwargs = {} |
|
198 | 198 | kwargs['form'] = form |
|
199 | 199 | kwargs['title'] = 'Device' |
|
200 | 200 | kwargs['suptitle'] = 'Edit' |
|
201 | 201 | kwargs['button'] = 'Update' |
|
202 | 202 | |
|
203 | 203 | return render(request, 'device_edit.html', kwargs) |
|
204 | 204 | |
|
205 | 205 | def device_delete(request, id_dev): |
|
206 | 206 | |
|
207 | 207 | device = get_object_or_404(Device, pk=id_dev) |
|
208 | 208 | |
|
209 | 209 | if request.method=='POST': |
|
210 | 210 | |
|
211 | 211 | if request.user.is_staff: |
|
212 | 212 | device.delete() |
|
213 | 213 | return redirect('url_devices') |
|
214 | 214 | |
|
215 | 215 | return HttpResponse("Not enough permission to delete this object") |
|
216 | 216 | |
|
217 | 217 | kwargs = {'object':device, 'dev_active':'active', |
|
218 | 218 | 'url_cancel':'url_device', 'id_item':id_dev} |
|
219 | 219 | |
|
220 | 220 | return render(request, 'item_delete.html', kwargs) |
|
221 | 221 | |
|
222 | 222 | def campaigns(request): |
|
223 | 223 | |
|
224 | 224 | campaigns = Campaign.objects.all().order_by('start_date') |
|
225 | 225 | |
|
226 | 226 | keys = ['id', 'name', 'start_date', 'end_date'] |
|
227 | 227 | |
|
228 | 228 | kwargs = {} |
|
229 | 229 | kwargs['campaign_keys'] = keys[1:] |
|
230 | 230 | kwargs['campaigns'] = campaigns#.values(*keys) |
|
231 | 231 | kwargs['title'] = 'Campaign' |
|
232 | 232 | kwargs['suptitle'] = 'List' |
|
233 | 233 | kwargs['button'] = 'New Campaign' |
|
234 | 234 | |
|
235 | 235 | return render(request, 'campaigns.html', kwargs) |
|
236 | 236 | |
|
237 | 237 | def campaign(request, id_camp): |
|
238 | 238 | |
|
239 | 239 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
240 | 240 | #experiments = Experiment.objects.filter(campaign=campaign) |
|
241 | 241 | form = CampaignForm(instance=campaign) |
|
242 | 242 | |
|
243 | 243 | kwargs = {} |
|
244 | 244 | kwargs['campaign'] = campaign |
|
245 | 245 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
246 | 246 | |
|
247 | 247 | keys = ['id', 'name', 'start_time', 'end_time'] |
|
248 | 248 | |
|
249 | 249 | kwargs['experiment_keys'] = keys[1:] |
|
250 | 250 | #kwargs['experiments'] = experiments.values(*keys) |
|
251 | 251 | |
|
252 | 252 | kwargs['title'] = 'Campaign' |
|
253 | 253 | kwargs['suptitle'] = 'Details' |
|
254 | 254 | |
|
255 | 255 | kwargs['form'] = form |
|
256 | 256 | kwargs['button'] = 'Add Experiment' |
|
257 | 257 | |
|
258 | 258 | return render(request, 'campaign.html', kwargs) |
|
259 | 259 | |
|
260 | 260 | def campaign_new(request): |
|
261 | 261 | |
|
262 | 262 | if request.method == 'GET': |
|
263 | 263 | form = CampaignForm() |
|
264 | 264 | |
|
265 | 265 | if request.method == 'POST': |
|
266 | 266 | form = CampaignForm(request.POST) |
|
267 | 267 | |
|
268 | 268 | if form.is_valid(): |
|
269 | 269 | campaign = form.save() |
|
270 | 270 | return redirect('url_campaign', id_camp=campaign.id) |
|
271 | 271 | |
|
272 | 272 | kwargs = {} |
|
273 | 273 | kwargs['form'] = form |
|
274 | 274 | kwargs['title'] = 'Campaign' |
|
275 | 275 | kwargs['suptitle'] = 'New' |
|
276 | 276 | kwargs['button'] = 'Create' |
|
277 | 277 | |
|
278 | 278 | return render(request, 'campaign_edit.html', kwargs) |
|
279 | 279 | |
|
280 | 280 | def campaign_edit(request, id_camp): |
|
281 | 281 | |
|
282 | 282 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
283 | 283 | |
|
284 | 284 | if request.method=='GET': |
|
285 | 285 | form = CampaignForm(instance=campaign) |
|
286 | 286 | |
|
287 | 287 | if request.method=='POST': |
|
288 | 288 | form = CampaignForm(request.POST, instance=campaign) |
|
289 | 289 | |
|
290 | 290 | if form.is_valid(): |
|
291 | 291 | form.save() |
|
292 | 292 | return redirect('url_campaign', id_camp=id_camp) |
|
293 | 293 | |
|
294 | 294 | kwargs = {} |
|
295 | 295 | kwargs['form'] = form |
|
296 | 296 | kwargs['title'] = 'Campaign' |
|
297 | 297 | kwargs['suptitle'] = 'Edit' |
|
298 | 298 | kwargs['button'] = 'Update' |
|
299 | 299 | |
|
300 | 300 | return render(request, 'campaign_edit.html', kwargs) |
|
301 | 301 | |
|
302 | 302 | def campaign_delete(request, id_camp): |
|
303 | 303 | |
|
304 | 304 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
305 | 305 | |
|
306 | 306 | if request.method=='POST': |
|
307 | 307 | if request.user.is_staff: |
|
308 | 308 | campaign.delete() |
|
309 | 309 | return redirect('url_campaigns') |
|
310 | 310 | |
|
311 | 311 | return HttpResponse("Not enough permission to delete this object") |
|
312 | 312 | |
|
313 | 313 | kwargs = {'object':campaign, 'camp_active':'active', |
|
314 | 314 | 'url_cancel':'url_campaign', 'id_item':id_camp} |
|
315 | 315 | |
|
316 | 316 | return render(request, 'item_delete.html', kwargs) |
|
317 | 317 | |
|
318 | 318 | def experiments(request): |
|
319 | 319 | |
|
320 | 320 | experiment_list = Experiment.objects.all().order_by('campaign') |
|
321 | 321 | |
|
322 | 322 | keys = ['id', 'name', 'start_time', 'end_time', 'campaign'] |
|
323 | 323 | |
|
324 | 324 | kwargs = {} |
|
325 | 325 | |
|
326 | 326 | kwargs['experiment_keys'] = keys[1:] |
|
327 | 327 | kwargs['experiments'] = experiment_list#.values(*keys) |
|
328 | 328 | |
|
329 | 329 | kwargs['title'] = 'Experiment' |
|
330 | 330 | kwargs['suptitle'] = 'List' |
|
331 | 331 | kwargs['button'] = 'New Experiment' |
|
332 | 332 | |
|
333 | 333 | return render(request, 'experiments.html', kwargs) |
|
334 | 334 | |
|
335 | 335 | def experiment(request, id_exp): |
|
336 | 336 | |
|
337 | 337 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
338 | 338 | |
|
339 | 339 | experiments = Experiment.objects.filter(campaign=experiment.campaign) |
|
340 | 340 | configurations = Configuration.objects.filter(experiment=experiment, type=0) |
|
341 | 341 | |
|
342 | 342 | kwargs = {} |
|
343 | 343 | |
|
344 | 344 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] |
|
345 | 345 | conf_keys = ['id', 'device__name', 'device__device_type', 'device__ip_address', 'device__port_address'] |
|
346 | 346 | |
|
347 | 347 | conf_labels = ['id', 'device__name', 'device_type', 'ip_address', 'port_address'] |
|
348 | 348 | |
|
349 | 349 | kwargs['experiment_keys'] = exp_keys[1:] |
|
350 | 350 | kwargs['experiment'] = experiment |
|
351 | 351 | |
|
352 | 352 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
353 | 353 | |
|
354 | 354 | kwargs['configuration_labels'] = conf_labels[1:] |
|
355 | 355 | kwargs['configuration_keys'] = conf_keys[1:] |
|
356 | 356 | kwargs['configurations'] = configurations #.values(*conf_keys) |
|
357 | 357 | |
|
358 | 358 | kwargs['title'] = 'Experiment' |
|
359 | 359 | kwargs['suptitle'] = 'Details' |
|
360 | 360 | |
|
361 | 361 | kwargs['button'] = 'Add Configuration' |
|
362 | 362 | |
|
363 | 363 | return render(request, 'experiment.html', kwargs) |
|
364 | 364 | |
|
365 | 365 | def experiment_new(request, id_camp=0): |
|
366 | 366 | |
|
367 | 367 | if request.method == 'GET': |
|
368 | 368 | form = ExperimentForm(initial={'campaign':id_camp}) |
|
369 | 369 | |
|
370 | 370 | if request.method == 'POST': |
|
371 | 371 | form = ExperimentForm(request.POST, initial={'campaign':id_camp}) |
|
372 | 372 | |
|
373 | 373 | if form.is_valid(): |
|
374 | 374 | experiment = form.save() |
|
375 | 375 | return redirect('url_experiment', id_exp=experiment.id) |
|
376 | 376 | |
|
377 | 377 | kwargs = {} |
|
378 | 378 | kwargs['form'] = form |
|
379 | 379 | kwargs['title'] = 'Experiment' |
|
380 | 380 | kwargs['suptitle'] = 'New' |
|
381 | 381 | kwargs['button'] = 'Create' |
|
382 | 382 | |
|
383 | 383 | return render(request, 'experiment_edit.html', kwargs) |
|
384 | 384 | |
|
385 | 385 | def experiment_edit(request, id_exp): |
|
386 | 386 | |
|
387 | 387 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
388 | 388 | |
|
389 | 389 | if request.method == 'GET': |
|
390 | 390 | form = ExperimentForm(instance=experiment) |
|
391 | 391 | |
|
392 | 392 | if request.method=='POST': |
|
393 | 393 | form = ExperimentForm(request.POST, instance=experiment) |
|
394 | 394 | |
|
395 | 395 | if form.is_valid(): |
|
396 | 396 | experiment = form.save() |
|
397 | 397 | return redirect('url_experiment', id_exp=experiment.id) |
|
398 | 398 | |
|
399 | 399 | kwargs = {} |
|
400 | 400 | kwargs['form'] = form |
|
401 | 401 | kwargs['title'] = 'Experiment' |
|
402 | 402 | kwargs['suptitle'] = 'Edit' |
|
403 | 403 | kwargs['button'] = 'Update' |
|
404 | 404 | |
|
405 | 405 | return render(request, 'experiment_edit.html', kwargs) |
|
406 | 406 | |
|
407 | 407 | def experiment_delete(request, id_exp): |
|
408 | 408 | |
|
409 | 409 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
410 | 410 | |
|
411 | 411 | if request.method=='POST': |
|
412 | 412 | if request.user.is_staff: |
|
413 | 413 | id_camp = experiment.campaign.id |
|
414 | 414 | experiment.delete() |
|
415 | 415 | return redirect('url_campaign', id_camp=id_camp) |
|
416 | 416 | |
|
417 | 417 | return HttpResponse("Not enough permission to delete this object") |
|
418 | 418 | |
|
419 | 419 | kwargs = {'object':experiment, 'exp_active':'active', |
|
420 | 420 | 'url_cancel':'url_experiment', 'id_item':id_exp} |
|
421 | 421 | |
|
422 | 422 | return render(request, 'item_delete.html', kwargs) |
|
423 | 423 | |
|
424 | 424 | def dev_confs(request): |
|
425 | 425 | |
|
426 | 426 | configurations = Configuration.objects.all().order_by('type', 'device__device_type', 'experiment') |
|
427 | 427 | |
|
428 | 428 | # keys = ['id', 'device__device_type__name', 'device__name', 'experiment__campaign__name', 'experiment__name'] |
|
429 | 429 | |
|
430 | 430 | keys = ['id', 'device', 'experiment', 'type', 'programmed_date'] |
|
431 | 431 | |
|
432 | 432 | kwargs = {} |
|
433 | 433 | |
|
434 | 434 | kwargs['configuration_keys'] = keys[1:] |
|
435 | 435 | kwargs['configurations'] = configurations#.values(*keys) |
|
436 | 436 | |
|
437 | 437 | kwargs['title'] = 'Configuration' |
|
438 | 438 | kwargs['suptitle'] = 'List' |
|
439 | 439 | kwargs['button'] = 'New Configuration' |
|
440 | 440 | |
|
441 | 441 | return render(request, 'dev_confs.html', kwargs) |
|
442 | 442 | |
|
443 | 443 | def dev_conf(request, id_conf): |
|
444 | 444 | |
|
445 | 445 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
446 | 446 | |
|
447 | 447 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
448 | 448 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
449 | 449 | |
|
450 | 450 | kwargs = {} |
|
451 | 451 | kwargs['dev_conf'] = dev_conf |
|
452 | 452 | kwargs['dev_conf_keys'] = ['name', 'experiment', 'device'] |
|
453 | 453 | |
|
454 | 454 | kwargs['title'] = 'Configuration' |
|
455 | 455 | kwargs['suptitle'] = 'Details' |
|
456 | 456 | |
|
457 | 457 | kwargs['button'] = 'Edit Configuration' |
|
458 | 458 | |
|
459 | 459 | ###### SIDEBAR ###### |
|
460 | 460 | kwargs.update(sidebar(conf)) |
|
461 | 461 | |
|
462 | 462 | return render(request, 'dev_conf.html', kwargs) |
|
463 | 463 | |
|
464 | 464 | def dev_conf_new(request, id_exp=0): |
|
465 | 465 | |
|
466 | 466 | if request.method == 'GET': |
|
467 | 467 | form = ConfigurationForm(initial={'experiment':id_exp}) |
|
468 | 468 | |
|
469 | 469 | if request.method == 'POST': |
|
470 | 470 | experiment = Experiment.objects.get(pk=request.POST['experiment']) |
|
471 | 471 | device = Device.objects.get(pk=request.POST['device']) |
|
472 | 472 | |
|
473 | 473 | DevConfForm = CONF_FORMS[device.device_type.name] |
|
474 | 474 | |
|
475 | 475 | form = DevConfForm(request.POST, initial={'experiment':experiment.id}) |
|
476 | 476 | |
|
477 | 477 | if form.is_valid(): |
|
478 | 478 | dev_conf = form.save() |
|
479 | 479 | |
|
480 | 480 | return redirect('url_experiment', id_exp=experiment.id) |
|
481 | 481 | |
|
482 | 482 | kwargs = {} |
|
483 | 483 | kwargs['form'] = form |
|
484 | 484 | kwargs['title'] = 'Configuration' |
|
485 | 485 | kwargs['suptitle'] = 'New' |
|
486 | 486 | kwargs['button'] = 'Create' |
|
487 | 487 | |
|
488 | 488 | return render(request, 'dev_conf_edit.html', kwargs) |
|
489 | 489 | |
|
490 | 490 | def dev_conf_edit(request, id_conf): |
|
491 | 491 | |
|
492 | 492 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
493 | 493 | |
|
494 | 494 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
495 | 495 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
496 | 496 | |
|
497 | 497 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
498 | 498 | |
|
499 | 499 | if request.method=='GET': |
|
500 | 500 | form = DevConfForm(instance=dev_conf) |
|
501 | 501 | |
|
502 | 502 | if request.method=='POST': |
|
503 | 503 | form = DevConfForm(request.POST, instance=dev_conf) |
|
504 | 504 | |
|
505 | 505 | if form.is_valid(): |
|
506 | 506 | form.save() |
|
507 | 507 | return redirect('url_dev_conf', id_conf=id_conf) |
|
508 | 508 | |
|
509 | 509 | kwargs = {} |
|
510 | 510 | kwargs['form'] = form |
|
511 | 511 | kwargs['title'] = 'Device Configuration' |
|
512 | 512 | kwargs['suptitle'] = 'Edit' |
|
513 | 513 | kwargs['button'] = 'Update' |
|
514 | 514 | |
|
515 | 515 | ###### SIDEBAR ###### |
|
516 | 516 | kwargs.update(sidebar(conf)) |
|
517 | 517 | |
|
518 | 518 | return render(request, 'dev_conf_edit.html', kwargs) |
|
519 | 519 | |
|
520 | 520 | def dev_conf_read(request, id_conf): |
|
521 | 521 | |
|
522 | 522 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
523 | 523 | |
|
524 | 524 | messages.error(request, "Read View not implemented yet") |
|
525 | 525 | |
|
526 | 526 | return redirect('url_dev_conf', id_conf=conf.id) |
|
527 | 527 | |
|
528 | 528 | def dev_conf_write(request, id_conf): |
|
529 | 529 | |
|
530 | 530 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
531 | 531 | |
|
532 | 532 | messages.error(request, "Write View not implemented yet") |
|
533 | 533 | |
|
534 | 534 | return redirect('url_dev_conf', id_conf=conf.id) |
|
535 | 535 | |
|
536 | 536 | def dev_conf_import(request, id_conf): |
|
537 | 537 | |
|
538 | 538 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
539 | 539 | |
|
540 | 540 | messages.error(request, "Import View not implemented yet") |
|
541 | 541 | |
|
542 | 542 | return redirect('url_dev_conf', id_conf=conf.id) |
|
543 | 543 | |
|
544 | 544 | def dev_conf_export(request, id_conf): |
|
545 | 545 | |
|
546 | 546 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
547 | 547 | |
|
548 | 548 | messages.error(request, "Export View not implemented yet") |
|
549 | 549 | |
|
550 | 550 | return redirect('url_dev_conf', id_conf=conf.id) |
|
551 | 551 | |
|
552 | 552 | def dev_conf_delete(request, id_conf): |
|
553 | 553 | |
|
554 | 554 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
555 | 555 | |
|
556 | 556 | if request.method=='POST': |
|
557 | 557 | if request.user.is_staff: |
|
558 | 558 | id_exp = conf.experiment.id |
|
559 | 559 | conf.delete() |
|
560 | 560 | return redirect('url_experiment', id_exp=id_exp) |
|
561 | 561 | |
|
562 | 562 | return HttpResponse("Not enough permission to delete this object") |
|
563 | 563 | |
|
564 | 564 | kwargs = {'object':conf, 'conf_active':'active', |
|
565 | 565 | 'url_cancel':'url_dev_conf', 'id_item':id_conf} |
|
566 | 566 | |
|
567 | 567 | ###### SIDEBAR ###### |
|
568 | 568 | kwargs.update(sidebar(conf)) |
|
569 | 569 | |
|
570 | 570 | return render(request, 'item_delete.html', kwargs) |
|
571 | 571 | |
|
572 | 572 | def sidebar(conf): |
|
573 | 573 | |
|
574 | 574 | experiments = Experiment.objects.filter(campaign=conf.experiment.campaign) |
|
575 | 575 | configurations = Configuration.objects.filter(experiment=conf.experiment, type=0) |
|
576 | 576 | |
|
577 | 577 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] |
|
578 | 578 | conf_keys = ['id', 'device'] |
|
579 | 579 | |
|
580 | 580 | kwargs = {} |
|
581 | 581 | |
|
582 | 582 | kwargs['dev_conf'] = conf |
|
583 | 583 | |
|
584 | 584 | kwargs['experiment_keys'] = exp_keys[1:] |
|
585 | 585 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
586 | 586 | |
|
587 | 587 | kwargs['configuration_keys'] = conf_keys[1:] |
|
588 | 588 | kwargs['configurations'] = configurations #.values(*conf_keys) |
|
589 | 589 | |
|
590 | 590 | return kwargs |
|
591 | 591 | |
|
592 | 592 | |
|
593 | 593 | def operation(request, id_camp=None): |
|
594 | 594 | |
|
595 | 595 | today = datetime.today() |
|
596 | 596 | |
|
597 | 597 | if id_camp==None: |
|
598 | 598 | id_camp = Campaign.objects.filter(start_date__month=today.month).filter(start_date__year=today.year).order_by('-start_date')[0].id |
|
599 | 599 | |
|
600 | 600 | if request.method=='GET': |
|
601 | 601 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
602 | 602 | campaigns = Campaign.objects.filter(start_date__month=today.month).filter(start_date__year=today.year).order_by('-start_date') |
|
603 | 603 | form = OperationForm(initial={'campaign': id_camp}) |
|
604 | 604 | |
|
605 | 605 | if request.method=='POST': |
|
606 | 606 | campaign = get_object_or_404(Campaign, pk=request.POST['campaign']) |
|
607 | 607 | #id_camp = Campaign.objects.filter(start_date__month=today.month).filter(start_date__year=today.year).order_by('-start_date')[1].id |
|
608 | 608 | form = OperationForm(request.POST, initial={'campaign':campaign.name}) |
|
609 | 609 | if form.is_valid(): |
|
610 | 610 | return redirect('url_operation', id_camp=campaign.id) |
|
611 | 611 | |
|
612 | 612 | radars = Radar.objects.filter(campaign = campaign) |
|
613 | 613 | experiments = [Experiment.objects.filter(radar=radar) for radar in radars] #zip(radars, [Experiment.objects.filter(radar=radar) for radar in radars]) |
|
614 | 614 | |
|
615 | 615 | kwargs = {} |
|
616 | 616 | #---Campaign |
|
617 | 617 | kwargs['campaign'] = campaign |
|
618 | 618 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
619 | 619 | #---Experimet |
|
620 |
keys = ['id', 'name', 'start_time', 'end_time' |
|
|
620 | keys = ['id', 'name', 'start_time', 'end_time'] | |
|
621 | 621 | kwargs['experiment_keys'] = keys[1:] |
|
622 | 622 | kwargs['experiments'] = experiments |
|
623 | 623 | #---Radar |
|
624 | 624 | kwargs['radars'] = radars |
|
625 | 625 | #---Else |
|
626 | 626 | kwargs['title'] = 'Operation' |
|
627 | 627 | kwargs['suptitle'] = campaign.name |
|
628 | 628 | kwargs['form'] = form |
|
629 | 629 | kwargs['button'] = '...' |
|
630 | 630 | |
|
631 | 631 | return render(request, 'operation.html', kwargs) No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now