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