@@ -1,4 +1,4 | |||
|
1 | ||
|
1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse | |
|
2 | 2 | from datetime import datetime |
|
3 | 3 | |
|
4 | 4 | from django.db import models |
@@ -130,6 +130,24 class Campaign(models.Model): | |||
|
130 | 130 | def get_absolute_url(self): |
|
131 | 131 | return reverse('url_campaign', args=[str(self.id)]) |
|
132 | 132 | |
|
133 | def parms_to_dict(self): | |
|
134 | ||
|
135 | import json | |
|
136 | ||
|
137 | parameters = {} | |
|
138 | experiments = Experiment.objects.filter(campaign = campaign) | |
|
139 | ||
|
140 | ||
|
141 | parameters['campaign'] = self.name | |
|
142 | ||
|
143 | #parameters = json.dumps(parameters, indent=2) | |
|
144 | parameters = json.dumps(parameters) | |
|
145 | return parameters | |
|
146 | ||
|
147 | def get_absolute_url_export(self): | |
|
148 | return reverse('url_export_campaign', args=[str(self.id)]) | |
|
149 | ||
|
150 | ||
|
133 | 151 | |
|
134 | 152 | class RunningExperiment(models.Model): |
|
135 | 153 | radar = models.OneToOneField('Location', on_delete=models.CASCADE) |
@@ -220,6 +238,41 class Experiment(models.Model): | |||
|
220 | 238 | def get_absolute_url(self): |
|
221 | 239 | return reverse('url_experiment', args=[str(self.id)]) |
|
222 | 240 | |
|
241 | def parms_to_dict(self): | |
|
242 | ||
|
243 | import json | |
|
244 | ||
|
245 | configurations = Configuration.objects.filter(experiment=self) | |
|
246 | conf_parameters = {} | |
|
247 | parameters={} | |
|
248 | ||
|
249 | for configuration in configurations: | |
|
250 | if 'cgs' in configuration.device.device_type.name: | |
|
251 | conf_parameters['cgs'] = configuration.parms_to_dict() | |
|
252 | if 'dds' in configuration.device.device_type.name: | |
|
253 | conf_parameters['dds'] = configuration.parms_to_dict() | |
|
254 | if 'rc' in configuration.device.device_type.name: | |
|
255 | conf_parameters['rc'] = configuration.parms_to_dict() | |
|
256 | if 'jars' in configuration.device.device_type.name: | |
|
257 | conf_parameters['jars'] = configuration.parms_to_dict() | |
|
258 | if 'usrp' in configuration.device.device_type.name: | |
|
259 | conf_parameters['usrp'] = configuration.parms_to_dict() | |
|
260 | if 'abs' in configuration.device.device_type.name: | |
|
261 | conf_parameters['abs'] = configuration.parms_to_dict() | |
|
262 | ||
|
263 | parameters['configurations'] = conf_parameters | |
|
264 | parameters['end_time'] = self.end_time.strftime("%Y-%m-%d") | |
|
265 | parameters['start_time'] = self.start_time.strftime("%Y-%m-%d") | |
|
266 | parameters['radar'] = self.radar.name | |
|
267 | parameters['experiment'] = self.name | |
|
268 | parameters = json.dumps(parameters, indent=2) | |
|
269 | #parameters = json.dumps(parameters) | |
|
270 | ||
|
271 | return parameters | |
|
272 | ||
|
273 | def get_absolute_url_export(self): | |
|
274 | return reverse('url_export_experiment', args=[str(self.id)]) | |
|
275 | ||
|
223 | 276 | |
|
224 | 277 | class Configuration(PolymorphicModel): |
|
225 | 278 |
@@ -12,14 +12,38 | |||
|
12 | 12 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
13 | 13 | |
|
14 | 14 | {% block content %} |
|
15 | ||
|
16 | {% block menu-actions %} | |
|
17 | <span class=" dropdown pull-right"> | |
|
18 | <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-menu-hamburger gi-2x" aria-hidden="true"></span></a> | |
|
19 | <ul class="dropdown-menu" role="menu"> | |
|
20 | <li><a href="{% url 'url_edit_campaign' campaign.id %}"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a></li> | |
|
21 | <li><a href="{% url 'url_delete_campaign' campaign.id %}"><span class="glyphicon glyphicon-remove-sign" aria-hidden="true"></span> Delete</a></li> | |
|
22 | <li><a href="{{ dev_conf.get_absolute_url_import }}"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Import </a></li> | |
|
23 | <li><a href="{{ campaign.get_absolute_url_export }}"><span class="glyphicon glyphicon-export" aria-hidden="true"></span> Export </a></li> | |
|
24 | {% block extra-menu-actions %} | |
|
25 | {% endblock %} | |
|
26 | <li><a>----------------</a></li> | |
|
27 | <li><a href="#"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Mix Experiments</a></li> | |
|
28 | <!--<li><a href="{{ dev_conf.get_absolute_url_status }}"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Status</a></li> | |
|
29 | {% if not no_play %} | |
|
30 | <li><a href="{{ dev_conf.get_absolute_url_start}}"><span class="glyphicon glyphicon-play" aria-hidden="true"></span> Start</a></li> | |
|
31 | <li><a href="{{ dev_conf.get_absolute_url_stop }}"><span class="glyphicon glyphicon-stop" aria-hidden="true"></span> Stop</a></li> | |
|
32 | {% endif %} | |
|
33 | <li><a href="{{ dev_conf.get_absolute_url_write }}"><span class="glyphicon glyphicon-download" aria-hidden="true"></span> Write</a></li> | |
|
34 | <li><a href="{{ dev_conf.get_absolute_url_read }}"><span class="glyphicon glyphicon-upload" aria-hidden="true"></span> Read</a></li>--> | |
|
35 | </ul> | |
|
36 | </span> | |
|
37 | {% endblock %} | |
|
38 | ||
|
15 | 39 | <table class="table table-bordered"> |
|
16 | 40 | {% for key in campaign_keys %} |
|
17 | 41 | <tr><th>{{key|title}}</th><td>{{campaign|attr:key}}</td></tr> |
|
18 | 42 | {% endfor %} |
|
19 | 43 | </table> |
|
20 | 44 | |
|
21 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_export">Export</button> | |
|
22 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_edit">Edit</button> | |
|
45 | <!--<button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_export">Export</button>--> | |
|
46 | <!--<button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_edit">Edit</button>--> | |
|
23 | 47 | |
|
24 | 48 | <br></br> |
|
25 | 49 | <br></br> |
@@ -72,12 +96,12 | |||
|
72 | 96 | document.location = $(this).data("href"); |
|
73 | 97 | }); |
|
74 | 98 | |
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
|
99 | // $("#bt_edit").click(function() { | |
|
100 | // document.location = "{% url 'url_edit_campaign' campaign.id %}"; | |
|
101 | // }); | |
|
78 | 102 | |
|
79 | 103 | $("#bt_mix").click(function() { |
|
80 | document.location = "{% url 'url_mix_campaign' campaign.id %}"; | |
|
104 | ||
|
81 | 105 | }); |
|
82 | 106 | |
|
83 | 107 | </script> |
@@ -12,13 +12,28 | |||
|
12 | 12 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
13 | 13 | |
|
14 | 14 | {% block content %} |
|
15 | ||
|
16 | {% block menu-actions %} | |
|
17 | <span class=" dropdown pull-right"> | |
|
18 | <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-menu-hamburger gi-2x" aria-hidden="true"></span></a> | |
|
19 | <ul class="dropdown-menu" role="menu"> | |
|
20 | <li><a href="{% url 'url_edit_experiment' experiment.id %}"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a></li> | |
|
21 | <li><a href="{% url 'url_delete_experiment' experiment.id %}"><span class="glyphicon glyphicon-remove-sign" aria-hidden="true"></span> Delete</a></li> | |
|
22 | <li><a href="{{ dev_conf.get_absolute_url_import }}"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Import </a></li> | |
|
23 | <li><a href="{{ experiment.get_absolute_url_export }}"><span class="glyphicon glyphicon-export" aria-hidden="true"></span> Export </a></li> | |
|
24 | {% block extra-menu-actions %} | |
|
25 | {% endblock %} | |
|
26 | <li><a>----------------</a></li> | |
|
27 | <li><a href="#"><span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span> Add Configuration</a></li> | |
|
28 | </ul> | |
|
29 | </span> | |
|
30 | {% endblock %} | |
|
31 | ||
|
15 | 32 | <table class="table table-bordered"> |
|
16 | 33 | {% for key in experiment_keys %} |
|
17 | 34 | <tr><th>{{key|title}}</th><td>{{experiment|attr:key}}</td></tr> |
|
18 | 35 | {% endfor %} |
|
19 | 36 | </table> |
|
20 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_export">Export</button> | |
|
21 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_edit">Edit</button> | |
|
22 | 37 | <br></br> |
|
23 | 38 | <br></br> |
|
24 | 39 |
@@ -18,12 +18,14 urlpatterns = ( | |||
|
18 | 18 | url(r'^campaign/(?P<id_camp>-?\d+)/$', 'apps.main.views.campaign', name='url_campaign'), |
|
19 | 19 | url(r'^campaign/(?P<id_camp>-?\d+)/edit/$', 'apps.main.views.campaign_edit', name='url_edit_campaign'), |
|
20 | 20 | url(r'^campaign/(?P<id_camp>-?\d+)/delete/$', 'apps.main.views.campaign_delete', name='url_delete_campaign'), |
|
21 | url(r'^campaign/(?P<id_camp>-?\d+)/export/$', 'apps.main.views.campaign_export', name='url_export_campaign'), | |
|
21 | 22 | |
|
22 | 23 | url(r'^experiment/new/$', 'apps.main.views.experiment_new', name='url_add_experiment'), |
|
23 | 24 | url(r'^experiment/$', 'apps.main.views.experiments', name='url_experiments'), |
|
24 | 25 | url(r'^experiment/(?P<id_exp>-?\d+)/$', 'apps.main.views.experiment', name='url_experiment'), |
|
25 | 26 | url(r'^experiment/(?P<id_exp>-?\d+)/edit/$', 'apps.main.views.experiment_edit', name='url_edit_experiment'), |
|
26 | 27 | url(r'^experiment/(?P<id_exp>-?\d+)/delete/$', 'apps.main.views.experiment_delete', name='url_delete_experiment'), |
|
28 | url(r'^experiment/(?P<id_exp>-?\d+)/export/$', 'apps.main.views.experiment_export', name='url_export_experiment'), | |
|
27 | 29 | |
|
28 | 30 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), |
|
29 | 31 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/(?P<id_dev>-?\d+)/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), |
@@ -404,6 +404,18 def campaign_delete(request, id_camp): | |||
|
404 | 404 | |
|
405 | 405 | return render(request, 'confirm.html', kwargs) |
|
406 | 406 | |
|
407 | def campaign_export(request, id_camp): | |
|
408 | ||
|
409 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
|
410 | content = campaign.parms_to_dict() | |
|
411 | content_type = 'application/json' | |
|
412 | filename = '%s_%s.json' %(campaign.name, campaign.id) | |
|
413 | ||
|
414 | response = HttpResponse(content_type=content_type) | |
|
415 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename | |
|
416 | response.write(content) | |
|
417 | ||
|
418 | return response | |
|
407 | 419 | |
|
408 | 420 | def experiments(request): |
|
409 | 421 | |
@@ -538,6 +550,20 def experiment_delete(request, id_exp): | |||
|
538 | 550 | return render(request, 'confirm.html', kwargs) |
|
539 | 551 | |
|
540 | 552 | |
|
553 | def experiment_export(request, id_exp): | |
|
554 | ||
|
555 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
|
556 | content = experiment.parms_to_dict() | |
|
557 | content_type = 'application/json' | |
|
558 | filename = '%s_%s.json' %(experiment.name, experiment.id) | |
|
559 | ||
|
560 | response = HttpResponse(content_type=content_type) | |
|
561 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename | |
|
562 | response.write(content) | |
|
563 | ||
|
564 | return response | |
|
565 | ||
|
566 | ||
|
541 | 567 | def dev_confs(request): |
|
542 | 568 | |
|
543 | 569 | configurations = Configuration.objects.all().order_by('type', 'device__device_type', 'experiment') |
General Comments 0
You need to be logged in to leave comments.
Login now