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