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