@@ -1,143 +1,147 | |||||
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 | <!-- Not Empty--> |
|
16 | <!-- Not Empty--> | |
17 | {% if details %} |
|
17 | {% if details %} | |
18 |
|
18 | |||
19 | <form class="form" method="post" action=""> |
|
19 | <form class="form" method="post" action=""> | |
20 | {% csrf_token %} |
|
20 | {% csrf_token %} | |
21 |
|
21 | |||
22 | {% bootstrap_form form layout='horizontal' size='medium' %} |
|
22 | {% bootstrap_form form layout='horizontal' size='medium' %} | |
23 | <div style="clear: both;"></div> |
|
23 | <div style="clear: both;"></div> | |
24 | <br> |
|
24 | <br> | |
25 | <!-- For deep search --> |
|
25 | <!-- For deep search --> | |
26 | {% if search_button == True %} |
|
26 | {% if search_button == True %} | |
27 | <button id="button-1" type="button" class="btn btn-primary pull-right">{{button}}</button> |
|
27 | <button id="button-1" type="button" class="btn btn-primary pull-right">{{button}}</button> | |
28 | {% endif %} |
|
28 | {% endif %} | |
29 | <br> |
|
29 | <br> | |
30 | <br> |
|
30 | <br> | |
31 | </form> |
|
31 | </form> | |
32 | <br> |
|
32 | <br> | |
33 | <br> |
|
33 | <br> | |
34 |
|
34 | |||
35 | {% endif %} |
|
35 | {% endif %} | |
36 |
|
36 | |||
37 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true" > |
|
37 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true" > | |
38 |
|
38 | |||
39 | {% for location in locations %} |
|
39 | {% for location in locations %} | |
40 |
|
40 | |||
41 | <div class="panel panel-default"> |
|
41 | <div class="panel panel-default"> | |
42 | <div class="panel-heading" role="tab" id="headingTwo"> |
|
42 | <div class="panel-heading" role="tab" id="headingTwo"> | |
43 | <h4 class="panel-title"> |
|
43 | <h4 class="panel-title"> | |
44 | <a class="collapsed" role="button" data-toggle="collapse" href="#collapseTwo-{{ location.id }}" aria-expanded="false" aria-controls="collapseTwo"> |
|
44 | <a class="collapsed" role="button" data-toggle="collapse" href="#collapseTwo-{{ location.id }}" aria-expanded="false" aria-controls="collapseTwo"> | |
45 | {{location.name}}: Experiment List |
|
45 | {{location.name}}: Experiment List | |
46 | <span> |
|
46 | <span> | |
47 | </span> |
|
47 | </span> | |
48 | </a> |
|
48 | </a> | |
49 | <button id="play-{{ location.id }}" type="button" class="btn btn-primary pull-right btn-xs" aria-label="Left Align" style="margin-left: 10px"> |
|
49 | <button id="play-{{ location.id }}" type="button" class="btn btn-primary pull-right btn-xs" aria-label="Left Align" style="margin-left: 10px"> | |
50 | <span class="glyphicon glyphicon-play" aria-hidden="true"></span> |
|
50 | <span class="glyphicon glyphicon-play" aria-hidden="true"></span> | |
51 | </button> |
|
51 | </button> | |
52 | <button id="stop-{{ location.id }}" type="button" class="btn btn-primary pull-right btn-xs" aria-label="Left Align" style="margin-left: 10px"> |
|
52 | <button id="stop-{{ location.id }}" type="button" class="btn btn-primary pull-right btn-xs" aria-label="Left Align" style="margin-left: 10px"> | |
53 | <span class="glyphicon glyphicon-stop" aria-hidden="true"></span> |
|
53 | <span class="glyphicon glyphicon-stop" aria-hidden="true"></span> | |
54 | </button> |
|
54 | </button> | |
55 |
|
55 | |||
56 | </h4> |
|
56 | </h4> | |
57 | </div> |
|
57 | </div> | |
58 |
|
58 | |||
59 | <div id="collapseTwo-{{ location.id }}" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> |
|
59 | <div id="collapseTwo-{{ location.id }}" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> | |
60 | <div class="panel-body"> |
|
60 | <div class="panel-body"> | |
61 | <table class="table table-hover"> |
|
61 | <table class="table table-hover"> | |
62 | <tr> |
|
62 | <tr> | |
63 | <th>#</th> |
|
63 | <th>#</th> | |
64 | {% for header in experiment_keys %} |
|
64 | {% for header in experiment_keys %} | |
65 | <th>{{ header|title }}</th> |
|
65 | <th>{{ header|title }}</th> | |
66 | {% endfor%} |
|
66 | {% endfor%} | |
67 | </tr> |
|
67 | </tr> | |
68 |
|
68 | |||
69 | {% for item in experiments %} |
|
69 | {% for item in experiments %} | |
70 | {% if location.name in item.location.name %} |
|
70 | {% if location.name in item.location.name %} | |
71 |
|
71 | |||
72 | <tr class="clickable-row" data-href="{% url 'url_experiment' item.id %}" > |
|
72 | <tr class="clickable-row" data-href="{% url 'url_experiment' item.id %}" > | |
73 | <td>{{ forloop.counter }}</td> |
|
73 | <td>{{ forloop.counter }}</td> | |
74 | {% for key in experiment_keys %} |
|
74 | {% for key in experiment_keys %} | |
|
75 | {% if 'status' in key %} | |||
|
76 | <td></td> | |||
|
77 | {% else %} | |||
75 | <td>{{ item|value:key }}</td> |
|
78 | <td>{{ item|value:key }}</td> | |
|
79 | {% endif %} | |||
76 | {% endfor %} |
|
80 | {% endfor %} | |
77 | </tr> |
|
81 | </tr> | |
78 | {% endif %} |
|
82 | {% endif %} | |
79 | {% endfor %} |
|
83 | {% endfor %} | |
80 | </table> |
|
84 | </table> | |
81 | </div> |
|
85 | </div> | |
82 | </div> |
|
86 | </div> | |
83 | </div> |
|
87 | </div> | |
84 | {% endfor %} |
|
88 | {% endfor %} | |
85 | </div> |
|
89 | </div> | |
86 |
|
90 | |||
87 |
|
91 | |||
88 |
|
92 | |||
89 | {% endblock %} |
|
93 | {% endblock %} | |
90 |
|
94 | |||
91 |
|
95 | |||
92 |
|
96 | |||
93 | {% block extra-js%} |
|
97 | {% block extra-js%} | |
94 | <script type="text/javascript"> |
|
98 | <script type="text/javascript"> | |
95 | //for (i = 0; i < locations.length; i++) { |
|
99 | //for (i = 0; i < locations.length; i++) { | |
96 | // text += cars[i] + "<br>"; |
|
100 | // text += cars[i] + "<br>"; | |
97 | //} |
|
101 | //} | |
98 | //------For PLAY Button------- |
|
102 | //------For PLAY Button------- | |
99 | {% for location in locations %} |
|
103 | {% for location in locations %} | |
100 | $("#play-{{ location.id }}").click(function() { |
|
104 | $("#play-{{ location.id }}").click(function() { | |
101 | //alert("Play-{{location}}"); |
|
105 | //alert("Play-{{location}}"); | |
102 | var id_loc = {{location.id}} |
|
106 | var id_loc = {{location.id}} | |
103 | //document.location = |
|
107 | //document.location = | |
104 | }); |
|
108 | }); | |
105 | {% endfor %} |
|
109 | {% endfor %} | |
106 |
|
110 | |||
107 | //--------For STOP Button------- |
|
111 | //--------For STOP Button------- | |
108 | {% for location in locations %} |
|
112 | {% for location in locations %} | |
109 | $("#stop-{{ location.id }}").click(function() { |
|
113 | $("#stop-{{ location.id }}").click(function() { | |
110 | alert("Stop-{{location}}"); |
|
114 | alert("Stop-{{location}}"); | |
111 | // document.location = "{% url 'url_operation' campaign.id %}"; |
|
115 | // document.location = "{% url 'url_operation' campaign.id %}"; | |
112 | }); |
|
116 | }); | |
113 | {% endfor %} |
|
117 | {% endfor %} | |
114 |
|
118 | |||
115 | $(".clickable-row").click(function() { |
|
119 | $(".clickable-row").click(function() { | |
116 | document.location = $(this).data("href"); |
|
120 | document.location = $(this).data("href"); | |
117 | }); |
|
121 | }); | |
118 |
|
122 | |||
119 | {% if search_button == True %} |
|
123 | {% if search_button == True %} | |
120 | $(document).ready(function() { |
|
124 | $(document).ready(function() { | |
121 | $("#id_campaign").change(function() { |
|
125 | $("#id_campaign").change(function() { | |
122 | var id_camp = document.getElementById("id_campaign").value; |
|
126 | var id_camp = document.getElementById("id_campaign").value; | |
123 | //alert(id_camp); |
|
127 | //alert(id_camp); | |
124 | document.location = "{% url 'url_operation'%}"+String(id_camp); |
|
128 | document.location = "{% url 'url_operation'%}"+String(id_camp); | |
125 | }); |
|
129 | }); | |
126 | }); |
|
130 | }); | |
127 | {% else %} |
|
131 | {% else %} | |
128 | $(document).ready(function() { |
|
132 | $(document).ready(function() { | |
129 | $("#id_campaign").change(function() { |
|
133 | $("#id_campaign").change(function() { | |
130 | var id_camp = document.getElementById("id_campaign").value; |
|
134 | var id_camp = document.getElementById("id_campaign").value; | |
131 | //alert(id_camp); |
|
135 | //alert(id_camp); | |
132 | document.location = "{% url 'url_operation_search'%}"+String(id_camp); |
|
136 | document.location = "{% url 'url_operation_search'%}"+String(id_camp); | |
133 | }); |
|
137 | }); | |
134 | }); |
|
138 | }); | |
135 | {% endif %} |
|
139 | {% endif %} | |
136 |
|
140 | |||
137 | $("#button-1").click(function() { |
|
141 | $("#button-1").click(function() { | |
138 | document.location = "{% url 'url_operation_search' %}"; |
|
142 | document.location = "{% url 'url_operation_search' %}"; | |
139 | }); |
|
143 | }); | |
140 |
|
144 | |||
141 |
|
145 | |||
142 | </script> |
|
146 | </script> | |
143 | {% endblock %} No newline at end of file |
|
147 | {% endblock %} |
@@ -1,888 +1,892 | |||||
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 .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm |
|
4 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm | |
5 | from .forms import OperationSearchForm |
|
5 | from .forms import OperationSearchForm | |
6 | from apps.cgs.forms import CGSConfigurationForm |
|
6 | from apps.cgs.forms import CGSConfigurationForm | |
7 | from apps.jars.forms import JARSConfigurationForm |
|
7 | from apps.jars.forms import JARSConfigurationForm | |
8 | from apps.usrp.forms import USRPConfigurationForm |
|
8 | from apps.usrp.forms import USRPConfigurationForm | |
9 | from apps.abs.forms import ABSConfigurationForm |
|
9 | from apps.abs.forms import ABSConfigurationForm | |
10 | from apps.rc.forms import RCConfigurationForm |
|
10 | from apps.rc.forms import RCConfigurationForm | |
11 | from apps.dds.forms import DDSConfigurationForm |
|
11 | from apps.dds.forms import DDSConfigurationForm | |
12 |
|
12 | |||
13 | from .models import Campaign, Experiment, Device, Configuration, Location#, RunningExperiment |
|
13 | from .models import Campaign, Experiment, Device, Configuration, Location#, RunningExperiment | |
14 | from apps.cgs.models import CGSConfiguration |
|
14 | from apps.cgs.models import CGSConfiguration | |
15 | from apps.jars.models import JARSConfiguration |
|
15 | from apps.jars.models import JARSConfiguration | |
16 | from apps.usrp.models import USRPConfiguration |
|
16 | from apps.usrp.models import USRPConfiguration | |
17 | from apps.abs.models import ABSConfiguration |
|
17 | from apps.abs.models import ABSConfiguration | |
18 | from apps.rc.models import RCConfiguration |
|
18 | from apps.rc.models import RCConfiguration | |
19 | from apps.dds.models import DDSConfiguration |
|
19 | from apps.dds.models import DDSConfiguration | |
20 |
|
20 | |||
21 | # Create your views here. |
|
21 | # Create your views here. | |
22 |
|
22 | |||
23 | CONF_FORMS = { |
|
23 | CONF_FORMS = { | |
24 | 'rc': RCConfigurationForm, |
|
24 | 'rc': RCConfigurationForm, | |
25 | 'dds': DDSConfigurationForm, |
|
25 | 'dds': DDSConfigurationForm, | |
26 | 'jars': JARSConfigurationForm, |
|
26 | 'jars': JARSConfigurationForm, | |
27 | 'cgs': CGSConfigurationForm, |
|
27 | 'cgs': CGSConfigurationForm, | |
28 | 'abs': ABSConfigurationForm, |
|
28 | 'abs': ABSConfigurationForm, | |
29 | 'usrp': USRPConfigurationForm, |
|
29 | 'usrp': USRPConfigurationForm, | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | CONF_MODELS = { |
|
32 | CONF_MODELS = { | |
33 | 'rc': RCConfiguration, |
|
33 | 'rc': RCConfiguration, | |
34 | 'dds': DDSConfiguration, |
|
34 | 'dds': DDSConfiguration, | |
35 | 'jars': JARSConfiguration, |
|
35 | 'jars': JARSConfiguration, | |
36 | 'cgs': CGSConfiguration, |
|
36 | 'cgs': CGSConfiguration, | |
37 | 'abs': ABSConfiguration, |
|
37 | 'abs': ABSConfiguration, | |
38 | 'usrp': USRPConfiguration, |
|
38 | 'usrp': USRPConfiguration, | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | def index(request): |
|
41 | def index(request): | |
42 | kwargs = {} |
|
42 | kwargs = {} | |
43 |
|
43 | |||
44 | return render(request, 'index.html', kwargs) |
|
44 | return render(request, 'index.html', kwargs) | |
45 |
|
45 | |||
46 | def locations(request): |
|
46 | def locations(request): | |
47 |
|
47 | |||
48 | locations = Location.objects.all().order_by('name') |
|
48 | locations = Location.objects.all().order_by('name') | |
49 |
|
49 | |||
50 | keys = ['id', 'name', 'description'] |
|
50 | keys = ['id', 'name', 'description'] | |
51 |
|
51 | |||
52 | kwargs = {} |
|
52 | kwargs = {} | |
53 | kwargs['location_keys'] = keys[1:] |
|
53 | kwargs['location_keys'] = keys[1:] | |
54 | kwargs['locations'] = locations |
|
54 | kwargs['locations'] = locations | |
55 | kwargs['title'] = 'Location' |
|
55 | kwargs['title'] = 'Location' | |
56 | kwargs['suptitle'] = 'List' |
|
56 | kwargs['suptitle'] = 'List' | |
57 | kwargs['button'] = 'New Location' |
|
57 | kwargs['button'] = 'New Location' | |
58 |
|
58 | |||
59 | return render(request, 'locations.html', kwargs) |
|
59 | return render(request, 'locations.html', kwargs) | |
60 |
|
60 | |||
61 | def location(request, id_loc): |
|
61 | def location(request, id_loc): | |
62 |
|
62 | |||
63 | location = get_object_or_404(Location, pk=id_loc) |
|
63 | location = get_object_or_404(Location, pk=id_loc) | |
64 |
|
64 | |||
65 | kwargs = {} |
|
65 | kwargs = {} | |
66 | kwargs['location'] = location |
|
66 | kwargs['location'] = location | |
67 | kwargs['location_keys'] = ['name', 'description'] |
|
67 | kwargs['location_keys'] = ['name', 'description'] | |
68 |
|
68 | |||
69 | kwargs['title'] = 'Location' |
|
69 | kwargs['title'] = 'Location' | |
70 | kwargs['suptitle'] = 'Details' |
|
70 | kwargs['suptitle'] = 'Details' | |
71 |
|
71 | |||
72 | return render(request, 'location.html', kwargs) |
|
72 | return render(request, 'location.html', kwargs) | |
73 |
|
73 | |||
74 | #def location_play(request, id_camp, id_loc): |
|
74 | #def location_play(request, id_camp, id_loc): | |
75 |
|
75 | |||
76 | # campaign = get_object_or_404(Campaign, pk=id_camp) |
|
76 | # campaign = get_object_or_404(Campaign, pk=id_camp) | |
77 | # print campaign |
|
77 | # print campaign | |
78 | # location = get_object_or_404(Location, pk=id_loc) |
|
78 | # location = get_object_or_404(Location, pk=id_loc) | |
79 | # experiments = Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) |
|
79 | # experiments = Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) | |
80 | # locations = Location.objects.filter(pk=id_loc) |
|
80 | # locations = Location.objects.filter(pk=id_loc) | |
81 |
|
81 | |||
82 | # if request.method=='GET': |
|
82 | # if request.method=='GET': | |
83 | # form = OperationForm(initial={'campaign': campaign.id}) |
|
83 | # form = OperationForm(initial={'campaign': campaign.id}) | |
84 |
|
84 | |||
85 | # kwargs = {} |
|
85 | # kwargs = {} | |
86 | #---Campaign |
|
86 | #---Campaign | |
87 | # kwargs['campaign'] = campaign |
|
87 | # kwargs['campaign'] = campaign | |
88 | # kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
88 | # kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
89 | #---Experiment |
|
89 | #---Experiment | |
90 | # keys = ['id', 'name', 'start_time', 'end_time'] |
|
90 | # keys = ['id', 'name', 'start_time', 'end_time'] | |
91 | # kwargs['experiment_keys'] = keys[1:] |
|
91 | # kwargs['experiment_keys'] = keys[1:] | |
92 | # kwargs['experiments'] = experiments |
|
92 | # kwargs['experiments'] = experiments | |
93 | #---Radar |
|
93 | #---Radar | |
94 | # kwargs['location'] = location |
|
94 | # kwargs['location'] = location | |
95 | #---Else |
|
95 | #---Else | |
96 | # kwargs['title'] = 'Campaign' |
|
96 | # kwargs['title'] = 'Campaign' | |
97 | # kwargs['suptitle'] = campaign.name |
|
97 | # kwargs['suptitle'] = campaign.name | |
98 | # kwargs['form'] = form |
|
98 | # kwargs['form'] = form | |
99 | # kwargs['button'] = 'Search' |
|
99 | # kwargs['button'] = 'Search' | |
100 |
|
100 | |||
101 | # return render(request, 'operation_play.html', kwargs) |
|
101 | # return render(request, 'operation_play.html', kwargs) | |
102 |
|
102 | |||
103 | def location_new(request): |
|
103 | def location_new(request): | |
104 |
|
104 | |||
105 | if request.method == 'GET': |
|
105 | if request.method == 'GET': | |
106 | form = LocationForm() |
|
106 | form = LocationForm() | |
107 |
|
107 | |||
108 | if request.method == 'POST': |
|
108 | if request.method == 'POST': | |
109 | form = LocationForm(request.POST) |
|
109 | form = LocationForm(request.POST) | |
110 |
|
110 | |||
111 | if form.is_valid(): |
|
111 | if form.is_valid(): | |
112 | form.save() |
|
112 | form.save() | |
113 | return redirect('url_locations') |
|
113 | return redirect('url_locations') | |
114 |
|
114 | |||
115 | kwargs = {} |
|
115 | kwargs = {} | |
116 | kwargs['form'] = form |
|
116 | kwargs['form'] = form | |
117 | kwargs['title'] = 'Location' |
|
117 | kwargs['title'] = 'Location' | |
118 | kwargs['suptitle'] = 'New' |
|
118 | kwargs['suptitle'] = 'New' | |
119 | kwargs['button'] = 'Create' |
|
119 | kwargs['button'] = 'Create' | |
120 |
|
120 | |||
121 | return render(request, 'location_edit.html', kwargs) |
|
121 | return render(request, 'location_edit.html', kwargs) | |
122 |
|
122 | |||
123 | def location_edit(request, id_loc): |
|
123 | def location_edit(request, id_loc): | |
124 |
|
124 | |||
125 | location = get_object_or_404(Location, pk=id_loc) |
|
125 | location = get_object_or_404(Location, pk=id_loc) | |
126 |
|
126 | |||
127 | if request.method=='GET': |
|
127 | if request.method=='GET': | |
128 | form = LocationForm(instance=location) |
|
128 | form = LocationForm(instance=location) | |
129 |
|
129 | |||
130 | if request.method=='POST': |
|
130 | if request.method=='POST': | |
131 | form = LocationForm(request.POST, instance=location) |
|
131 | form = LocationForm(request.POST, instance=location) | |
132 |
|
132 | |||
133 | if form.is_valid(): |
|
133 | if form.is_valid(): | |
134 | form.save() |
|
134 | form.save() | |
135 | return redirect('url_locations') |
|
135 | return redirect('url_locations') | |
136 |
|
136 | |||
137 | kwargs = {} |
|
137 | kwargs = {} | |
138 | kwargs['form'] = form |
|
138 | kwargs['form'] = form | |
139 | kwargs['title'] = 'Location' |
|
139 | kwargs['title'] = 'Location' | |
140 | kwargs['suptitle'] = 'Edit' |
|
140 | kwargs['suptitle'] = 'Edit' | |
141 | kwargs['button'] = 'Update' |
|
141 | kwargs['button'] = 'Update' | |
142 |
|
142 | |||
143 | return render(request, 'location_edit.html', kwargs) |
|
143 | return render(request, 'location_edit.html', kwargs) | |
144 |
|
144 | |||
145 | def location_delete(request, id_loc): |
|
145 | def location_delete(request, id_loc): | |
146 |
|
146 | |||
147 | location = get_object_or_404(Location, pk=id_loc) |
|
147 | location = get_object_or_404(Location, pk=id_loc) | |
148 |
|
148 | |||
149 | if request.method=='POST': |
|
149 | if request.method=='POST': | |
150 |
|
150 | |||
151 | if request.user.is_staff: |
|
151 | if request.user.is_staff: | |
152 | location.delete() |
|
152 | location.delete() | |
153 | return redirect('url_locations') |
|
153 | return redirect('url_locations') | |
154 |
|
154 | |||
155 | return HttpResponse("Not enough permission to delete this object") |
|
155 | return HttpResponse("Not enough permission to delete this object") | |
156 |
|
156 | |||
157 | kwargs = {'object':location, 'loc_active':'active', |
|
157 | kwargs = {'object':location, 'loc_active':'active', | |
158 | 'url_cancel':'url_location', 'id_item':id_loc} |
|
158 | 'url_cancel':'url_location', 'id_item':id_loc} | |
159 |
|
159 | |||
160 | return render(request, 'item_delete.html', kwargs) |
|
160 | return render(request, 'item_delete.html', kwargs) | |
161 |
|
161 | |||
162 | def devices(request): |
|
162 | def devices(request): | |
163 |
|
163 | |||
164 | devices = Device.objects.all().order_by('device_type__name') |
|
164 | devices = Device.objects.all().order_by('device_type__name') | |
165 |
|
165 | |||
166 | # keys = ['id', 'device_type__name', 'name', 'ip_address'] |
|
166 | # keys = ['id', 'device_type__name', 'name', 'ip_address'] | |
167 | keys = ['id', 'name', 'ip_address', 'port_address', 'device_type'] |
|
167 | keys = ['id', 'name', 'ip_address', 'port_address', 'device_type'] | |
168 |
|
168 | |||
169 | kwargs = {} |
|
169 | kwargs = {} | |
170 | kwargs['device_keys'] = keys[1:] |
|
170 | kwargs['device_keys'] = keys[1:] | |
171 | kwargs['devices'] = devices#.values(*keys) |
|
171 | kwargs['devices'] = devices#.values(*keys) | |
172 | kwargs['title'] = 'Device' |
|
172 | kwargs['title'] = 'Device' | |
173 | kwargs['suptitle'] = 'List' |
|
173 | kwargs['suptitle'] = 'List' | |
174 | kwargs['button'] = 'New Device' |
|
174 | kwargs['button'] = 'New Device' | |
175 |
|
175 | |||
176 | return render(request, 'devices.html', kwargs) |
|
176 | return render(request, 'devices.html', kwargs) | |
177 |
|
177 | |||
178 | def device(request, id_dev): |
|
178 | def device(request, id_dev): | |
179 |
|
179 | |||
180 | device = get_object_or_404(Device, pk=id_dev) |
|
180 | device = get_object_or_404(Device, pk=id_dev) | |
181 |
|
181 | |||
182 | kwargs = {} |
|
182 | kwargs = {} | |
183 | kwargs['device'] = device |
|
183 | kwargs['device'] = device | |
184 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] |
|
184 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] | |
185 |
|
185 | |||
186 | kwargs['title'] = 'Device' |
|
186 | kwargs['title'] = 'Device' | |
187 | kwargs['suptitle'] = 'Details' |
|
187 | kwargs['suptitle'] = 'Details' | |
188 |
|
188 | |||
189 | return render(request, 'device.html', kwargs) |
|
189 | return render(request, 'device.html', kwargs) | |
190 |
|
190 | |||
191 | def device_new(request): |
|
191 | def device_new(request): | |
192 |
|
192 | |||
193 | if request.method == 'GET': |
|
193 | if request.method == 'GET': | |
194 | form = DeviceForm() |
|
194 | form = DeviceForm() | |
195 |
|
195 | |||
196 | if request.method == 'POST': |
|
196 | if request.method == 'POST': | |
197 | form = DeviceForm(request.POST) |
|
197 | form = DeviceForm(request.POST) | |
198 |
|
198 | |||
199 | if form.is_valid(): |
|
199 | if form.is_valid(): | |
200 | form.save() |
|
200 | form.save() | |
201 | return redirect('url_devices') |
|
201 | return redirect('url_devices') | |
202 |
|
202 | |||
203 | kwargs = {} |
|
203 | kwargs = {} | |
204 | kwargs['form'] = form |
|
204 | kwargs['form'] = form | |
205 | kwargs['title'] = 'Device' |
|
205 | kwargs['title'] = 'Device' | |
206 | kwargs['suptitle'] = 'New' |
|
206 | kwargs['suptitle'] = 'New' | |
207 | kwargs['button'] = 'Create' |
|
207 | kwargs['button'] = 'Create' | |
208 |
|
208 | |||
209 | return render(request, 'device_edit.html', kwargs) |
|
209 | return render(request, 'device_edit.html', kwargs) | |
210 |
|
210 | |||
211 | def device_edit(request, id_dev): |
|
211 | def device_edit(request, id_dev): | |
212 |
|
212 | |||
213 | device = get_object_or_404(Device, pk=id_dev) |
|
213 | device = get_object_or_404(Device, pk=id_dev) | |
214 |
|
214 | |||
215 | if request.method=='GET': |
|
215 | if request.method=='GET': | |
216 | form = DeviceForm(instance=device) |
|
216 | form = DeviceForm(instance=device) | |
217 |
|
217 | |||
218 | if request.method=='POST': |
|
218 | if request.method=='POST': | |
219 | form = DeviceForm(request.POST, instance=device) |
|
219 | form = DeviceForm(request.POST, instance=device) | |
220 |
|
220 | |||
221 | if form.is_valid(): |
|
221 | if form.is_valid(): | |
222 | form.save() |
|
222 | form.save() | |
223 | return redirect('url_devices') |
|
223 | return redirect('url_devices') | |
224 |
|
224 | |||
225 | kwargs = {} |
|
225 | kwargs = {} | |
226 | kwargs['form'] = form |
|
226 | kwargs['form'] = form | |
227 | kwargs['title'] = 'Device' |
|
227 | kwargs['title'] = 'Device' | |
228 | kwargs['suptitle'] = 'Edit' |
|
228 | kwargs['suptitle'] = 'Edit' | |
229 | kwargs['button'] = 'Update' |
|
229 | kwargs['button'] = 'Update' | |
230 |
|
230 | |||
231 | return render(request, 'device_edit.html', kwargs) |
|
231 | return render(request, 'device_edit.html', kwargs) | |
232 |
|
232 | |||
233 | def device_delete(request, id_dev): |
|
233 | def device_delete(request, id_dev): | |
234 |
|
234 | |||
235 | device = get_object_or_404(Device, pk=id_dev) |
|
235 | device = get_object_or_404(Device, pk=id_dev) | |
236 |
|
236 | |||
237 | if request.method=='POST': |
|
237 | if request.method=='POST': | |
238 |
|
238 | |||
239 | if request.user.is_staff: |
|
239 | if request.user.is_staff: | |
240 | device.delete() |
|
240 | device.delete() | |
241 | return redirect('url_devices') |
|
241 | return redirect('url_devices') | |
242 |
|
242 | |||
243 | return HttpResponse("Not enough permission to delete this object") |
|
243 | return HttpResponse("Not enough permission to delete this object") | |
244 |
|
244 | |||
245 | kwargs = {'object':device, 'dev_active':'active', |
|
245 | kwargs = {'object':device, 'dev_active':'active', | |
246 | 'url_cancel':'url_device', 'id_item':id_dev} |
|
246 | 'url_cancel':'url_device', 'id_item':id_dev} | |
247 |
|
247 | |||
248 | return render(request, 'item_delete.html', kwargs) |
|
248 | return render(request, 'item_delete.html', kwargs) | |
249 |
|
249 | |||
250 | def campaigns(request): |
|
250 | def campaigns(request): | |
251 |
|
251 | |||
252 | campaigns = Campaign.objects.all().order_by('start_date') |
|
252 | campaigns = Campaign.objects.all().order_by('start_date') | |
253 |
|
253 | |||
254 | keys = ['id', 'name', 'start_date', 'end_date'] |
|
254 | keys = ['id', 'name', 'start_date', 'end_date'] | |
255 |
|
255 | |||
256 | kwargs = {} |
|
256 | kwargs = {} | |
257 | kwargs['campaign_keys'] = keys[1:] |
|
257 | kwargs['campaign_keys'] = keys[1:] | |
258 | kwargs['campaigns'] = campaigns#.values(*keys) |
|
258 | kwargs['campaigns'] = campaigns#.values(*keys) | |
259 | kwargs['title'] = 'Campaign' |
|
259 | kwargs['title'] = 'Campaign' | |
260 | kwargs['suptitle'] = 'List' |
|
260 | kwargs['suptitle'] = 'List' | |
261 | kwargs['button'] = 'New Campaign' |
|
261 | kwargs['button'] = 'New Campaign' | |
262 |
|
262 | |||
263 | return render(request, 'campaigns.html', kwargs) |
|
263 | return render(request, 'campaigns.html', kwargs) | |
264 |
|
264 | |||
265 | def campaign(request, id_camp): |
|
265 | def campaign(request, id_camp): | |
266 |
|
266 | |||
267 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
267 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
268 | experiments = Experiment.objects.filter(campaign=campaign) |
|
268 | experiments = Experiment.objects.filter(campaign=campaign) | |
269 |
|
269 | |||
270 | form = CampaignForm(instance=campaign) |
|
270 | form = CampaignForm(instance=campaign) | |
271 |
|
271 | |||
272 | kwargs = {} |
|
272 | kwargs = {} | |
273 | kwargs['campaign'] = campaign |
|
273 | kwargs['campaign'] = campaign | |
274 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
274 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
275 |
|
275 | |||
276 | keys = ['id', 'name', 'start_time', 'end_time'] |
|
276 | keys = ['id', 'name', 'start_time', 'end_time'] | |
277 |
|
277 | |||
278 | kwargs['experiment_keys'] = keys[1:] |
|
278 | kwargs['experiment_keys'] = keys[1:] | |
279 | kwargs['experiments'] = experiments.values(*keys) |
|
279 | kwargs['experiments'] = experiments.values(*keys) | |
280 |
|
280 | |||
281 | kwargs['title'] = 'Campaign' |
|
281 | kwargs['title'] = 'Campaign' | |
282 | kwargs['suptitle'] = 'Details' |
|
282 | kwargs['suptitle'] = 'Details' | |
283 |
|
283 | |||
284 | kwargs['form'] = form |
|
284 | kwargs['form'] = form | |
285 | kwargs['button'] = 'Add Experiment' |
|
285 | kwargs['button'] = 'Add Experiment' | |
286 |
|
286 | |||
287 | return render(request, 'campaign.html', kwargs) |
|
287 | return render(request, 'campaign.html', kwargs) | |
288 |
|
288 | |||
289 | def campaign_new(request): |
|
289 | def campaign_new(request): | |
290 |
|
290 | |||
291 | if request.method == 'GET': |
|
291 | if request.method == 'GET': | |
292 | form = CampaignForm() |
|
292 | form = CampaignForm() | |
293 |
|
293 | |||
294 | if request.method == 'POST': |
|
294 | if request.method == 'POST': | |
295 | form = CampaignForm(request.POST) |
|
295 | form = CampaignForm(request.POST) | |
296 |
|
296 | |||
297 | if form.is_valid(): |
|
297 | if form.is_valid(): | |
298 | campaign = form.save() |
|
298 | campaign = form.save() | |
299 | return redirect('url_campaign', id_camp=campaign.id) |
|
299 | return redirect('url_campaign', id_camp=campaign.id) | |
300 |
|
300 | |||
301 | kwargs = {} |
|
301 | kwargs = {} | |
302 | kwargs['form'] = form |
|
302 | kwargs['form'] = form | |
303 | kwargs['title'] = 'Campaign' |
|
303 | kwargs['title'] = 'Campaign' | |
304 | kwargs['suptitle'] = 'New' |
|
304 | kwargs['suptitle'] = 'New' | |
305 | kwargs['button'] = 'Create' |
|
305 | kwargs['button'] = 'Create' | |
306 |
|
306 | |||
307 | return render(request, 'campaign_edit.html', kwargs) |
|
307 | return render(request, 'campaign_edit.html', kwargs) | |
308 |
|
308 | |||
309 | def campaign_edit(request, id_camp): |
|
309 | def campaign_edit(request, id_camp): | |
310 |
|
310 | |||
311 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
311 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
312 |
|
312 | |||
313 | if request.method=='GET': |
|
313 | if request.method=='GET': | |
314 | form = CampaignForm(instance=campaign) |
|
314 | form = CampaignForm(instance=campaign) | |
315 |
|
315 | |||
316 | if request.method=='POST': |
|
316 | if request.method=='POST': | |
317 | form = CampaignForm(request.POST, instance=campaign) |
|
317 | form = CampaignForm(request.POST, instance=campaign) | |
318 |
|
318 | |||
319 | if form.is_valid(): |
|
319 | if form.is_valid(): | |
320 | form.save() |
|
320 | form.save() | |
321 | return redirect('url_campaign', id_camp=id_camp) |
|
321 | return redirect('url_campaign', id_camp=id_camp) | |
322 |
|
322 | |||
323 | kwargs = {} |
|
323 | kwargs = {} | |
324 | kwargs['form'] = form |
|
324 | kwargs['form'] = form | |
325 | kwargs['title'] = 'Campaign' |
|
325 | kwargs['title'] = 'Campaign' | |
326 | kwargs['suptitle'] = 'Edit' |
|
326 | kwargs['suptitle'] = 'Edit' | |
327 | kwargs['button'] = 'Update' |
|
327 | kwargs['button'] = 'Update' | |
328 |
|
328 | |||
329 | return render(request, 'campaign_edit.html', kwargs) |
|
329 | return render(request, 'campaign_edit.html', kwargs) | |
330 |
|
330 | |||
331 | def campaign_delete(request, id_camp): |
|
331 | def campaign_delete(request, id_camp): | |
332 |
|
332 | |||
333 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
333 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
334 |
|
334 | |||
335 | if request.method=='POST': |
|
335 | if request.method=='POST': | |
336 | if request.user.is_staff: |
|
336 | if request.user.is_staff: | |
337 | campaign.delete() |
|
337 | campaign.delete() | |
338 | return redirect('url_campaigns') |
|
338 | return redirect('url_campaigns') | |
339 |
|
339 | |||
340 | return HttpResponse("Not enough permission to delete this object") |
|
340 | return HttpResponse("Not enough permission to delete this object") | |
341 |
|
341 | |||
342 | kwargs = {'object':campaign, 'camp_active':'active', |
|
342 | kwargs = {'object':campaign, 'camp_active':'active', | |
343 | 'url_cancel':'url_campaign', 'id_item':id_camp} |
|
343 | 'url_cancel':'url_campaign', 'id_item':id_camp} | |
344 |
|
344 | |||
345 | return render(request, 'item_delete.html', kwargs) |
|
345 | return render(request, 'item_delete.html', kwargs) | |
346 |
|
346 | |||
347 | def experiments(request): |
|
347 | def experiments(request): | |
348 |
|
348 | |||
349 | experiment_list = Experiment.objects.all().order_by('campaign') |
|
349 | experiment_list = Experiment.objects.all().order_by('campaign') | |
350 |
|
350 | |||
351 | keys = ['id', 'name', 'start_time', 'end_time', 'campaign'] |
|
351 | keys = ['id', 'name', 'start_time', 'end_time', 'campaign'] | |
352 |
|
352 | |||
353 | kwargs = {} |
|
353 | kwargs = {} | |
354 |
|
354 | |||
355 | kwargs['experiment_keys'] = keys[1:] |
|
355 | kwargs['experiment_keys'] = keys[1:] | |
356 | kwargs['experiments'] = experiment_list#.values(*keys) |
|
356 | kwargs['experiments'] = experiment_list#.values(*keys) | |
357 |
|
357 | |||
358 | kwargs['title'] = 'Experiment' |
|
358 | kwargs['title'] = 'Experiment' | |
359 | kwargs['suptitle'] = 'List' |
|
359 | kwargs['suptitle'] = 'List' | |
360 | kwargs['button'] = 'New Experiment' |
|
360 | kwargs['button'] = 'New Experiment' | |
361 |
|
361 | |||
362 | return render(request, 'experiments.html', kwargs) |
|
362 | return render(request, 'experiments.html', kwargs) | |
363 |
|
363 | |||
364 | def experiment(request, id_exp): |
|
364 | def experiment(request, id_exp): | |
365 |
|
365 | |||
366 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
366 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
367 |
|
367 | |||
368 | experiments = Experiment.objects.filter(campaign=experiment.campaign) |
|
368 | experiments = Experiment.objects.filter(campaign=experiment.campaign) | |
369 | configurations = Configuration.objects.filter(experiment=experiment, type=0) |
|
369 | configurations = Configuration.objects.filter(experiment=experiment, type=0) | |
370 |
|
370 | |||
371 | kwargs = {} |
|
371 | kwargs = {} | |
372 |
|
372 | |||
373 | exp_keys = ['id', 'campaign', 'location', 'name', 'start_time', 'end_time'] |
|
373 | exp_keys = ['id', 'campaign', 'location', 'name', 'start_time', 'end_time'] | |
374 | conf_keys = ['id', 'device__name', 'device__device_type', 'device__ip_address', 'device__port_address'] |
|
374 | conf_keys = ['id', 'device__name', 'device__device_type', 'device__ip_address', 'device__port_address'] | |
375 |
|
375 | |||
376 | conf_labels = ['id', 'device__name', 'device_type', 'ip_address', 'port_address'] |
|
376 | conf_labels = ['id', 'device__name', 'device_type', 'ip_address', 'port_address'] | |
377 |
|
377 | |||
378 | kwargs['experiment_keys'] = exp_keys[1:] |
|
378 | kwargs['experiment_keys'] = exp_keys[1:] | |
379 | kwargs['experiment'] = experiment |
|
379 | kwargs['experiment'] = experiment | |
380 |
|
380 | |||
381 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
381 | kwargs['experiments'] = experiments.values(*exp_keys) | |
382 |
|
382 | |||
383 | kwargs['configuration_labels'] = conf_labels[1:] |
|
383 | kwargs['configuration_labels'] = conf_labels[1:] | |
384 | kwargs['configuration_keys'] = conf_keys[1:] |
|
384 | kwargs['configuration_keys'] = conf_keys[1:] | |
385 | kwargs['configurations'] = configurations #.values(*conf_keys) |
|
385 | kwargs['configurations'] = configurations #.values(*conf_keys) | |
386 |
|
386 | |||
387 | kwargs['title'] = 'Experiment' |
|
387 | kwargs['title'] = 'Experiment' | |
388 | kwargs['suptitle'] = 'Details' |
|
388 | kwargs['suptitle'] = 'Details' | |
389 |
|
389 | |||
390 | kwargs['button'] = 'Add Configuration' |
|
390 | kwargs['button'] = 'Add Configuration' | |
391 |
|
391 | |||
392 | return render(request, 'experiment.html', kwargs) |
|
392 | return render(request, 'experiment.html', kwargs) | |
393 |
|
393 | |||
394 | def experiment_new(request, id_camp=None): |
|
394 | def experiment_new(request, id_camp=None): | |
395 |
|
395 | |||
396 | if request.method == 'GET': |
|
396 | if request.method == 'GET': | |
397 | form = ExperimentForm(initial={'campaign':id_camp}) |
|
397 | form = ExperimentForm(initial={'campaign':id_camp}) | |
398 |
|
398 | |||
399 | if request.method == 'POST': |
|
399 | if request.method == 'POST': | |
400 | form = ExperimentForm(request.POST, initial={'campaign':id_camp}) |
|
400 | form = ExperimentForm(request.POST, initial={'campaign':id_camp}) | |
401 |
|
401 | |||
402 | if form.is_valid(): |
|
402 | if form.is_valid(): | |
403 | experiment = form.save() |
|
403 | experiment = form.save() | |
|
404 | ##AGREGAR! | |||
404 | return redirect('url_experiment', id_exp=experiment.id) |
|
405 | return redirect('url_experiment', id_exp=experiment.id) | |
405 |
|
406 | |||
406 | kwargs = {} |
|
407 | kwargs = {} | |
407 | kwargs['form'] = form |
|
408 | kwargs['form'] = form | |
408 | kwargs['title'] = 'Experiment' |
|
409 | kwargs['title'] = 'Experiment' | |
409 | kwargs['suptitle'] = 'New' |
|
410 | kwargs['suptitle'] = 'New' | |
410 | kwargs['button'] = 'Create' |
|
411 | kwargs['button'] = 'Create' | |
411 |
|
412 | |||
412 | return render(request, 'experiment_edit.html', kwargs) |
|
413 | return render(request, 'experiment_edit.html', kwargs) | |
413 |
|
414 | |||
414 | def experiment_edit(request, id_exp): |
|
415 | def experiment_edit(request, id_exp): | |
415 |
|
416 | |||
416 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
417 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
417 |
|
418 | |||
418 | if request.method == 'GET': |
|
419 | if request.method == 'GET': | |
419 | form = ExperimentForm(instance=experiment) |
|
420 | form = ExperimentForm(instance=experiment) | |
420 |
|
421 | |||
421 | if request.method=='POST': |
|
422 | if request.method=='POST': | |
422 | form = ExperimentForm(request.POST, instance=experiment) |
|
423 | form = ExperimentForm(request.POST, instance=experiment) | |
423 |
|
424 | |||
424 | if form.is_valid(): |
|
425 | if form.is_valid(): | |
425 | experiment = form.save() |
|
426 | experiment = form.save() | |
426 | return redirect('url_experiment', id_exp=experiment.id) |
|
427 | return redirect('url_experiment', id_exp=experiment.id) | |
427 |
|
428 | |||
428 | kwargs = {} |
|
429 | kwargs = {} | |
429 | kwargs['form'] = form |
|
430 | kwargs['form'] = form | |
430 | kwargs['title'] = 'Experiment' |
|
431 | kwargs['title'] = 'Experiment' | |
431 | kwargs['suptitle'] = 'Edit' |
|
432 | kwargs['suptitle'] = 'Edit' | |
432 | kwargs['button'] = 'Update' |
|
433 | kwargs['button'] = 'Update' | |
433 |
|
434 | |||
434 | return render(request, 'experiment_edit.html', kwargs) |
|
435 | return render(request, 'experiment_edit.html', kwargs) | |
435 |
|
436 | |||
436 | def experiment_delete(request, id_exp): |
|
437 | def experiment_delete(request, id_exp): | |
437 |
|
438 | |||
438 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
439 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
439 |
|
440 | |||
440 | if request.method=='POST': |
|
441 | if request.method=='POST': | |
441 | if request.user.is_staff: |
|
442 | if request.user.is_staff: | |
442 | id_camp = experiment.campaign.id |
|
443 | id_camp = experiment.campaign.id | |
443 | experiment.delete() |
|
444 | experiment.delete() | |
444 | return redirect('url_campaign', id_camp=id_camp) |
|
445 | return redirect('url_campaign', id_camp=id_camp) | |
445 |
|
446 | |||
446 | return HttpResponse("Not enough permission to delete this object") |
|
447 | return HttpResponse("Not enough permission to delete this object") | |
447 |
|
448 | |||
448 | kwargs = {'object':experiment, 'exp_active':'active', |
|
449 | kwargs = {'object':experiment, 'exp_active':'active', | |
449 | 'url_cancel':'url_experiment', 'id_item':id_exp} |
|
450 | 'url_cancel':'url_experiment', 'id_item':id_exp} | |
450 |
|
451 | |||
451 | return render(request, 'item_delete.html', kwargs) |
|
452 | return render(request, 'item_delete.html', kwargs) | |
452 |
|
453 | |||
453 | def dev_confs(request): |
|
454 | def dev_confs(request): | |
454 |
|
455 | |||
455 | configurations = Configuration.objects.all().order_by('type', 'device__device_type', 'experiment') |
|
456 | configurations = Configuration.objects.all().order_by('type', 'device__device_type', 'experiment') | |
456 |
|
457 | |||
457 | # keys = ['id', 'device__device_type__name', 'device__name', 'experiment__campaign__name', 'experiment__name'] |
|
458 | # keys = ['id', 'device__device_type__name', 'device__name', 'experiment__campaign__name', 'experiment__name'] | |
458 |
|
459 | |||
459 | keys = ['id', 'device', 'experiment', 'type', 'programmed_date'] |
|
460 | keys = ['id', 'device', 'experiment', 'type', 'programmed_date'] | |
460 |
|
461 | |||
461 | kwargs = {} |
|
462 | kwargs = {} | |
462 |
|
463 | |||
463 | kwargs['configuration_keys'] = keys[1:] |
|
464 | kwargs['configuration_keys'] = keys[1:] | |
464 | kwargs['configurations'] = configurations#.values(*keys) |
|
465 | kwargs['configurations'] = configurations#.values(*keys) | |
465 |
|
466 | |||
466 | kwargs['title'] = 'Configuration' |
|
467 | kwargs['title'] = 'Configuration' | |
467 | kwargs['suptitle'] = 'List' |
|
468 | kwargs['suptitle'] = 'List' | |
468 | kwargs['button'] = 'New Configuration' |
|
469 | kwargs['button'] = 'New Configuration' | |
469 |
|
470 | |||
470 | return render(request, 'dev_confs.html', kwargs) |
|
471 | return render(request, 'dev_confs.html', kwargs) | |
471 |
|
472 | |||
472 | def dev_conf(request, id_conf): |
|
473 | def dev_conf(request, id_conf): | |
473 |
|
474 | |||
474 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
475 | conf = get_object_or_404(Configuration, pk=id_conf) | |
475 |
|
476 | |||
476 | return redirect(conf.get_absolute_url()) |
|
477 | return redirect(conf.get_absolute_url()) | |
477 |
|
478 | |||
478 |
|
479 | |||
479 | def dev_conf_new(request, id_exp=0, id_dev=0): |
|
480 | def dev_conf_new(request, id_exp=0, id_dev=0): | |
480 |
|
481 | |||
481 | initial = {} |
|
482 | initial = {} | |
482 |
|
483 | |||
483 | if id_exp==0: |
|
484 | if id_exp==0: | |
484 | initial['experiment'] = id_exp |
|
485 | initial['experiment'] = id_exp | |
485 |
|
486 | |||
486 | if id_dev<>0: |
|
487 | if id_dev<>0: | |
487 | initial['device'] = id_dev |
|
488 | initial['device'] = id_dev | |
488 |
|
489 | |||
489 | if request.method == 'GET': |
|
490 | if request.method == 'GET': | |
490 | if id_dev==0: |
|
491 | if id_dev==0: | |
491 | form = ConfigurationForm(initial=initial) |
|
492 | form = ConfigurationForm(initial=initial) | |
492 | else: |
|
493 | else: | |
493 | device = Device.objects.get(pk=id_dev) |
|
494 | device = Device.objects.get(pk=id_dev) | |
494 | DevConfForm = CONF_FORMS[device.device_type.name] |
|
495 | DevConfForm = CONF_FORMS[device.device_type.name] | |
495 |
|
496 | |||
496 | form = DevConfForm(initial=initial) |
|
497 | form = DevConfForm(initial=initial) | |
497 |
|
498 | |||
498 | if request.method == 'POST': |
|
499 | if request.method == 'POST': | |
499 |
|
500 | |||
500 | device = Device.objects.get(pk=request.POST['device']) |
|
501 | device = Device.objects.get(pk=request.POST['device']) | |
501 | DevConfForm = CONF_FORMS[device.device_type.name] |
|
502 | DevConfForm = CONF_FORMS[device.device_type.name] | |
502 |
|
503 | |||
503 | form = DevConfForm(request.POST) |
|
504 | form = DevConfForm(request.POST) | |
504 |
|
505 | |||
505 | if form.is_valid(): |
|
506 | if form.is_valid(): | |
506 | dev_conf = form.save() |
|
507 | dev_conf = form.save() | |
507 |
|
508 | |||
508 | return redirect('url_dev_confs') |
|
509 | return redirect('url_dev_confs') | |
509 |
|
510 | |||
510 | kwargs = {} |
|
511 | kwargs = {} | |
511 | kwargs['id_exp'] = id_exp |
|
512 | kwargs['id_exp'] = id_exp | |
512 | kwargs['form'] = form |
|
513 | kwargs['form'] = form | |
513 | kwargs['title'] = 'Configuration' |
|
514 | kwargs['title'] = 'Configuration' | |
514 | kwargs['suptitle'] = 'New' |
|
515 | kwargs['suptitle'] = 'New' | |
515 | kwargs['button'] = 'Create' |
|
516 | kwargs['button'] = 'Create' | |
516 |
|
517 | |||
517 | return render(request, 'dev_conf_edit.html', kwargs) |
|
518 | return render(request, 'dev_conf_edit.html', kwargs) | |
518 |
|
519 | |||
519 | def dev_conf_edit(request, id_conf): |
|
520 | def dev_conf_edit(request, id_conf): | |
520 |
|
521 | |||
521 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
522 | conf = get_object_or_404(Configuration, pk=id_conf) | |
522 |
|
523 | |||
523 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
524 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
524 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
525 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
525 |
|
526 | |||
526 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
527 | dev_conf = DevConfModel.objects.get(pk=id_conf) | |
527 |
|
528 | |||
528 | if request.method=='GET': |
|
529 | if request.method=='GET': | |
529 | form = DevConfForm(instance=dev_conf) |
|
530 | form = DevConfForm(instance=dev_conf) | |
530 |
|
531 | |||
531 | if request.method=='POST': |
|
532 | if request.method=='POST': | |
532 | form = DevConfForm(request.POST, instance=dev_conf) |
|
533 | form = DevConfForm(request.POST, instance=dev_conf) | |
533 |
|
534 | |||
534 | if form.is_valid(): |
|
535 | if form.is_valid(): | |
535 | form.save() |
|
536 | form.save() | |
536 | return redirect('url_dev_conf', id_conf=id_conf) |
|
537 | return redirect('url_dev_conf', id_conf=id_conf) | |
537 |
|
538 | |||
538 | kwargs = {} |
|
539 | kwargs = {} | |
539 | kwargs['form'] = form |
|
540 | kwargs['form'] = form | |
540 | kwargs['title'] = 'Device Configuration' |
|
541 | kwargs['title'] = 'Device Configuration' | |
541 | kwargs['suptitle'] = 'Edit' |
|
542 | kwargs['suptitle'] = 'Edit' | |
542 | kwargs['button'] = 'Update' |
|
543 | kwargs['button'] = 'Update' | |
543 |
|
544 | |||
544 | ###### SIDEBAR ###### |
|
545 | ###### SIDEBAR ###### | |
545 | kwargs.update(sidebar(conf)) |
|
546 | kwargs.update(sidebar(conf)) | |
546 |
|
547 | |||
547 | return render(request, '%s_conf_edit.html' %conf.device.device_type.name, kwargs) |
|
548 | return render(request, '%s_conf_edit.html' %conf.device.device_type.name, kwargs) | |
548 |
|
549 | |||
549 | def dev_conf_start(request, id_conf): |
|
550 | def dev_conf_start(request, id_conf): | |
550 |
|
551 | |||
551 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
552 | conf = get_object_or_404(Configuration, pk=id_conf) | |
552 |
|
553 | |||
553 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
554 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
554 |
|
555 | |||
555 | conf = DevConfModel.objects.get(pk=id_conf) |
|
556 | conf = DevConfModel.objects.get(pk=id_conf) | |
556 |
|
557 | |||
557 | if conf.start_device(): |
|
558 | if conf.start_device(): | |
558 | messages.success(request, conf.message) |
|
559 | messages.success(request, conf.message) | |
559 | else: |
|
560 | else: | |
560 | messages.error(request, conf.message) |
|
561 | messages.error(request, conf.message) | |
561 |
|
562 | |||
562 | conf.status_device() |
|
563 | conf.status_device() | |
563 |
|
564 | |||
564 | return redirect(conf.get_absolute_url()) |
|
565 | return redirect(conf.get_absolute_url()) | |
565 |
|
566 | |||
566 | def dev_conf_stop(request, id_conf): |
|
567 | def dev_conf_stop(request, id_conf): | |
567 |
|
568 | |||
568 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
569 | conf = get_object_or_404(Configuration, pk=id_conf) | |
569 |
|
570 | |||
570 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
571 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
571 |
|
572 | |||
572 | conf = DevConfModel.objects.get(pk=id_conf) |
|
573 | conf = DevConfModel.objects.get(pk=id_conf) | |
573 |
|
574 | |||
574 | if conf.stop_device(): |
|
575 | if conf.stop_device(): | |
575 | messages.success(request, conf.message) |
|
576 | messages.success(request, conf.message) | |
576 | else: |
|
577 | else: | |
577 | messages.error(request, conf.message) |
|
578 | messages.error(request, conf.message) | |
578 |
|
579 | |||
579 | conf.status_device() |
|
580 | conf.status_device() | |
580 |
|
581 | |||
581 | return redirect(conf.get_absolute_url()) |
|
582 | return redirect(conf.get_absolute_url()) | |
582 |
|
583 | |||
583 | def dev_conf_status(request, id_conf): |
|
584 | def dev_conf_status(request, id_conf): | |
584 |
|
585 | |||
585 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
586 | conf = get_object_or_404(Configuration, pk=id_conf) | |
586 |
|
587 | |||
587 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
588 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
588 |
|
589 | |||
589 | conf = DevConfModel.objects.get(pk=id_conf) |
|
590 | conf = DevConfModel.objects.get(pk=id_conf) | |
590 |
|
591 | |||
591 | if conf.status_device(): |
|
592 | if conf.status_device(): | |
592 | messages.success(request, conf.message) |
|
593 | messages.success(request, conf.message) | |
593 | else: |
|
594 | else: | |
594 | messages.error(request, conf.message) |
|
595 | messages.error(request, conf.message) | |
595 |
|
596 | |||
596 | return redirect(conf.get_absolute_url()) |
|
597 | return redirect(conf.get_absolute_url()) | |
597 |
|
598 | |||
598 |
|
599 | |||
599 | def dev_conf_write(request, id_conf): |
|
600 | def dev_conf_write(request, id_conf): | |
600 |
|
601 | |||
601 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
602 | conf = get_object_or_404(Configuration, pk=id_conf) | |
602 |
|
603 | |||
603 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
604 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
604 |
|
605 | |||
605 | conf = DevConfModel.objects.get(pk=id_conf) |
|
606 | conf = DevConfModel.objects.get(pk=id_conf) | |
606 |
|
607 | |||
607 | answer = conf.write_device() |
|
608 | answer = conf.write_device() | |
608 | conf.status_device() |
|
609 | conf.status_device() | |
609 |
|
610 | |||
610 | if answer: |
|
611 | if answer: | |
611 | messages.success(request, conf.message) |
|
612 | messages.success(request, conf.message) | |
612 |
|
613 | |||
613 | #Creating a historical configuration |
|
614 | #Creating a historical configuration | |
614 | conf.pk = None |
|
615 | conf.pk = None | |
615 | conf.id = None |
|
616 | conf.id = None | |
616 | conf.type = 1 |
|
617 | conf.type = 1 | |
617 | conf.template = 0 |
|
618 | conf.template = 0 | |
618 | conf.save() |
|
619 | conf.save() | |
619 |
|
620 | |||
620 | #Original configuration |
|
621 | #Original configuration | |
621 | conf = DevConfModel.objects.get(pk=id_conf) |
|
622 | conf = DevConfModel.objects.get(pk=id_conf) | |
622 | else: |
|
623 | else: | |
623 | messages.error(request, conf.message) |
|
624 | messages.error(request, conf.message) | |
624 |
|
625 | |||
625 | return redirect(conf.get_absolute_url()) |
|
626 | return redirect(conf.get_absolute_url()) | |
626 |
|
627 | |||
627 | def dev_conf_read(request, id_conf): |
|
628 | def dev_conf_read(request, id_conf): | |
628 |
|
629 | |||
629 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
630 | conf = get_object_or_404(Configuration, pk=id_conf) | |
630 |
|
631 | |||
631 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
632 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
632 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
633 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
633 |
|
634 | |||
634 | conf = DevConfModel.objects.get(pk=id_conf) |
|
635 | conf = DevConfModel.objects.get(pk=id_conf) | |
635 |
|
636 | |||
636 | if request.method=='GET': |
|
637 | if request.method=='GET': | |
637 |
|
638 | |||
638 | parms = conf.read_device() |
|
639 | parms = conf.read_device() | |
639 | conf.status_device() |
|
640 | conf.status_device() | |
640 |
|
641 | |||
641 | if not parms: |
|
642 | if not parms: | |
642 | messages.error(request, conf.message) |
|
643 | messages.error(request, conf.message) | |
643 | return redirect(conf.get_absolute_url()) |
|
644 | return redirect(conf.get_absolute_url()) | |
644 |
|
645 | |||
645 | form = DevConfForm(initial=parms, instance=conf) |
|
646 | form = DevConfForm(initial=parms, instance=conf) | |
646 |
|
647 | |||
647 | if request.method=='POST': |
|
648 | if request.method=='POST': | |
648 | form = DevConfForm(request.POST, instance=conf) |
|
649 | form = DevConfForm(request.POST, instance=conf) | |
649 |
|
650 | |||
650 | if form.is_valid(): |
|
651 | if form.is_valid(): | |
651 | form.save() |
|
652 | form.save() | |
652 | return redirect(conf.get_absolute_url()) |
|
653 | return redirect(conf.get_absolute_url()) | |
653 |
|
654 | |||
654 | messages.error(request, "Parameters could not be saved") |
|
655 | messages.error(request, "Parameters could not be saved") | |
655 |
|
656 | |||
656 | kwargs = {} |
|
657 | kwargs = {} | |
657 | kwargs['id_dev'] = conf.id |
|
658 | kwargs['id_dev'] = conf.id | |
658 | kwargs['form'] = form |
|
659 | kwargs['form'] = form | |
659 | kwargs['title'] = 'Device Configuration' |
|
660 | kwargs['title'] = 'Device Configuration' | |
660 | kwargs['suptitle'] = 'Parameters read from device' |
|
661 | kwargs['suptitle'] = 'Parameters read from device' | |
661 | kwargs['button'] = 'Save' |
|
662 | kwargs['button'] = 'Save' | |
662 |
|
663 | |||
663 | ###### SIDEBAR ###### |
|
664 | ###### SIDEBAR ###### | |
664 | kwargs.update(sidebar(conf)) |
|
665 | kwargs.update(sidebar(conf)) | |
665 |
|
666 | |||
666 | return render(request, '%s_conf_edit.html' %conf.device.device_type.name, kwargs) |
|
667 | return render(request, '%s_conf_edit.html' %conf.device.device_type.name, kwargs) | |
667 |
|
668 | |||
668 | def dev_conf_import(request, id_conf): |
|
669 | def dev_conf_import(request, id_conf): | |
669 |
|
670 | |||
670 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
671 | conf = get_object_or_404(Configuration, pk=id_conf) | |
671 |
|
672 | |||
672 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
673 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
673 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
674 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
674 |
|
675 | |||
675 | conf = DevConfModel.objects.get(pk=id_conf) |
|
676 | conf = DevConfModel.objects.get(pk=id_conf) | |
676 |
|
677 | |||
677 | if request.method == 'GET': |
|
678 | if request.method == 'GET': | |
678 | file_form = UploadFileForm() |
|
679 | file_form = UploadFileForm() | |
679 |
|
680 | |||
680 | if request.method == 'POST': |
|
681 | if request.method == 'POST': | |
681 | file_form = UploadFileForm(request.POST, request.FILES) |
|
682 | file_form = UploadFileForm(request.POST, request.FILES) | |
682 |
|
683 | |||
683 | if file_form.is_valid(): |
|
684 | if file_form.is_valid(): | |
684 |
|
685 | |||
685 | parms = conf.import_from_file(request.FILES['file']) |
|
686 | parms = conf.import_from_file(request.FILES['file']) | |
686 |
|
687 | |||
687 | if parms: |
|
688 | if parms: | |
688 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) |
|
689 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) | |
689 | print parms |
|
690 | print parms | |
690 | form = DevConfForm(initial=parms, instance=conf) |
|
691 | form = DevConfForm(initial=parms, instance=conf) | |
691 |
|
692 | |||
692 | kwargs = {} |
|
693 | kwargs = {} | |
693 | kwargs['id_dev'] = conf.id |
|
694 | kwargs['id_dev'] = conf.id | |
694 | kwargs['form'] = form |
|
695 | kwargs['form'] = form | |
695 | kwargs['title'] = 'Device Configuration' |
|
696 | kwargs['title'] = 'Device Configuration' | |
696 | kwargs['suptitle'] = 'Parameters imported' |
|
697 | kwargs['suptitle'] = 'Parameters imported' | |
697 | kwargs['button'] = 'Save' |
|
698 | kwargs['button'] = 'Save' | |
698 | kwargs['action'] = conf.get_absolute_url_edit() |
|
699 | kwargs['action'] = conf.get_absolute_url_edit() | |
699 | kwargs['previous'] = conf.get_absolute_url() |
|
700 | kwargs['previous'] = conf.get_absolute_url() | |
700 |
|
701 | |||
701 | ###### SIDEBAR ###### |
|
702 | ###### SIDEBAR ###### | |
702 | kwargs.update(sidebar(conf)) |
|
703 | kwargs.update(sidebar(conf)) | |
703 |
|
704 | |||
704 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) |
|
705 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) | |
705 |
|
706 | |||
706 | messages.error(request, "Could not import parameters from file") |
|
707 | messages.error(request, "Could not import parameters from file") | |
707 |
|
708 | |||
708 | kwargs = {} |
|
709 | kwargs = {} | |
709 | kwargs['id_dev'] = conf.id |
|
710 | kwargs['id_dev'] = conf.id | |
710 | kwargs['title'] = 'Device Configuration' |
|
711 | kwargs['title'] = 'Device Configuration' | |
711 | kwargs['form'] = file_form |
|
712 | kwargs['form'] = file_form | |
712 | kwargs['suptitle'] = 'Importing file' |
|
713 | kwargs['suptitle'] = 'Importing file' | |
713 | kwargs['button'] = 'Import' |
|
714 | kwargs['button'] = 'Import' | |
714 |
|
715 | |||
715 | kwargs.update(sidebar(conf)) |
|
716 | kwargs.update(sidebar(conf)) | |
716 |
|
717 | |||
717 | return render(request, 'dev_conf_import.html', kwargs) |
|
718 | return render(request, 'dev_conf_import.html', kwargs) | |
718 |
|
719 | |||
719 | def dev_conf_export(request, id_conf): |
|
720 | def dev_conf_export(request, id_conf): | |
720 |
|
721 | |||
721 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
722 | conf = get_object_or_404(Configuration, pk=id_conf) | |
722 |
|
723 | |||
723 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
724 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
724 |
|
725 | |||
725 | conf = DevConfModel.objects.get(pk=id_conf) |
|
726 | conf = DevConfModel.objects.get(pk=id_conf) | |
726 |
|
727 | |||
727 | if request.method == 'GET': |
|
728 | if request.method == 'GET': | |
728 | file_form = DownloadFileForm(conf.device.device_type.name) |
|
729 | file_form = DownloadFileForm(conf.device.device_type.name) | |
729 |
|
730 | |||
730 | if request.method == 'POST': |
|
731 | if request.method == 'POST': | |
731 | file_form = DownloadFileForm(conf.device.device_type.name, request.POST) |
|
732 | file_form = DownloadFileForm(conf.device.device_type.name, request.POST) | |
732 |
|
733 | |||
733 | if file_form.is_valid(): |
|
734 | if file_form.is_valid(): | |
734 | fields = conf.export_to_file(format = file_form.cleaned_data['format']) |
|
735 | fields = conf.export_to_file(format = file_form.cleaned_data['format']) | |
735 |
|
736 | |||
736 | response = HttpResponse(content_type=fields['content_type']) |
|
737 | response = HttpResponse(content_type=fields['content_type']) | |
737 | response['Content-Disposition'] = 'attachment; filename="%s"' %fields['filename'] |
|
738 | response['Content-Disposition'] = 'attachment; filename="%s"' %fields['filename'] | |
738 | response.write(fields['content']) |
|
739 | response.write(fields['content']) | |
739 |
|
740 | |||
740 | return response |
|
741 | return response | |
741 |
|
742 | |||
742 | messages.error(request, "Could not export parameters") |
|
743 | messages.error(request, "Could not export parameters") | |
743 |
|
744 | |||
744 | kwargs = {} |
|
745 | kwargs = {} | |
745 | kwargs['id_dev'] = conf.id |
|
746 | kwargs['id_dev'] = conf.id | |
746 | kwargs['title'] = 'Device Configuration' |
|
747 | kwargs['title'] = 'Device Configuration' | |
747 | kwargs['form'] = file_form |
|
748 | kwargs['form'] = file_form | |
748 | kwargs['suptitle'] = 'Exporting file' |
|
749 | kwargs['suptitle'] = 'Exporting file' | |
749 | kwargs['button'] = 'Export' |
|
750 | kwargs['button'] = 'Export' | |
750 |
|
751 | |||
751 | return render(request, 'dev_conf_export.html', kwargs) |
|
752 | return render(request, 'dev_conf_export.html', kwargs) | |
752 |
|
753 | |||
753 | def dev_conf_delete(request, id_conf): |
|
754 | def dev_conf_delete(request, id_conf): | |
754 |
|
755 | |||
755 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
756 | conf = get_object_or_404(Configuration, pk=id_conf) | |
756 |
|
757 | |||
757 | if request.method=='POST': |
|
758 | if request.method=='POST': | |
758 | if request.user.is_staff: |
|
759 | if request.user.is_staff: | |
759 | id_exp = conf.experiment.id |
|
760 | id_exp = conf.experiment.id | |
760 | conf.delete() |
|
761 | conf.delete() | |
761 | return redirect('url_experiment', id_exp=id_exp) |
|
762 | return redirect('url_experiment', id_exp=id_exp) | |
762 |
|
763 | |||
763 | return HttpResponse("Not enough permission to delete this object") |
|
764 | return HttpResponse("Not enough permission to delete this object") | |
764 |
|
765 | |||
765 | kwargs = {'object':conf, 'conf_active':'active', |
|
766 | kwargs = {'object':conf, 'conf_active':'active', | |
766 | 'url_cancel':'url_dev_conf', 'id_item':id_conf} |
|
767 | 'url_cancel':'url_dev_conf', 'id_item':id_conf} | |
767 |
|
768 | |||
768 | ###### SIDEBAR ###### |
|
769 | ###### SIDEBAR ###### | |
769 | kwargs.update(sidebar(conf)) |
|
770 | kwargs.update(sidebar(conf)) | |
770 |
|
771 | |||
771 | return render(request, 'item_delete.html', kwargs) |
|
772 | return render(request, 'item_delete.html', kwargs) | |
772 |
|
773 | |||
773 | def sidebar(conf): |
|
774 | def sidebar(conf): | |
774 |
|
775 | |||
775 | kwargs = {} |
|
776 | kwargs = {} | |
776 |
|
777 | |||
777 | if conf.experiment: |
|
778 | if conf.experiment: | |
778 | experiments = Experiment.objects.filter(campaign=conf.experiment.campaign) |
|
779 | experiments = Experiment.objects.filter(campaign=conf.experiment.campaign) | |
779 | configurations = Configuration.objects.filter(experiment=conf.experiment, type=0) |
|
780 | configurations = Configuration.objects.filter(experiment=conf.experiment, type=0) | |
780 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] |
|
781 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] | |
781 | kwargs['experiment_keys'] = exp_keys[1:] |
|
782 | kwargs['experiment_keys'] = exp_keys[1:] | |
782 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
783 | kwargs['experiments'] = experiments.values(*exp_keys) | |
783 | conf_keys = ['id', 'device'] |
|
784 | conf_keys = ['id', 'device'] | |
784 | kwargs['configuration_keys'] = conf_keys[1:] |
|
785 | kwargs['configuration_keys'] = conf_keys[1:] | |
785 | kwargs['configurations'] = configurations #.values(*conf_keys) |
|
786 | kwargs['configurations'] = configurations #.values(*conf_keys) | |
786 |
|
787 | |||
787 | return kwargs |
|
788 | return kwargs | |
788 |
|
789 | |||
789 |
|
790 | |||
790 | def operation(request, id_camp=None): |
|
791 | def operation(request, id_camp=None): | |
791 |
|
792 | |||
792 | if not id_camp: |
|
793 | if not id_camp: | |
793 | campaigns = Campaign.objects.all().order_by('-start_date') |
|
794 | campaigns = Campaign.objects.all().order_by('-start_date') | |
794 |
|
795 | |||
795 | if not campaigns: |
|
796 | if not campaigns: | |
796 | kwargs = {} |
|
797 | kwargs = {} | |
797 | kwargs['title'] = 'No Campaigns' |
|
798 | kwargs['title'] = 'No Campaigns' | |
798 | kwargs['suptitle'] = 'Empty' |
|
799 | kwargs['suptitle'] = 'Empty' | |
799 | return render(request, 'operation.html', kwargs) |
|
800 | return render(request, 'operation.html', kwargs) | |
800 |
|
801 | |||
801 | id_camp = campaigns[0].id |
|
802 | id_camp = campaigns[0].id | |
802 |
|
803 | |||
803 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
804 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
804 |
|
805 | |||
805 | if request.method=='GET': |
|
806 | if request.method=='GET': | |
806 | form = OperationForm(initial={'campaign': campaign.id}, length = 5) |
|
807 | form = OperationForm(initial={'campaign': campaign.id}, length = 5) | |
807 |
|
808 | |||
808 | if request.method=='POST': |
|
809 | if request.method=='POST': | |
809 | form = OperationForm(request.POST, initial={'campaign':campaign.id}, length = 5) |
|
810 | form = OperationForm(request.POST, initial={'campaign':campaign.id}, length = 5) | |
810 |
|
811 | |||
811 | if form.is_valid(): |
|
812 | if form.is_valid(): | |
812 | return redirect('url_operation', id_camp=campaign.id) |
|
813 | return redirect('url_operation', id_camp=campaign.id) | |
813 | locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() |
|
814 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() | |
814 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) |
|
815 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) | |
|
816 | locations= Location.objects.filter(experiment=experiments).distinct() | |||
815 | #experiments = [Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) for location in locations] |
|
817 | #experiments = [Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) for location in locations] | |
816 | kwargs = {} |
|
818 | kwargs = {} | |
817 | #---Campaign |
|
819 | #---Campaign | |
818 | kwargs['campaign'] = campaign |
|
820 | kwargs['campaign'] = campaign | |
819 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
821 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
820 | #---Experiment |
|
822 | #---Experiment | |
821 | keys = ['id', 'name', 'start_time', 'end_time'] |
|
823 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] | |
822 | kwargs['experiment_keys'] = keys[1:] |
|
824 | kwargs['experiment_keys'] = keys[1:] | |
823 | kwargs['experiments'] = experiments |
|
825 | kwargs['experiments'] = experiments | |
824 | #---Radar |
|
826 | #---Radar | |
825 | kwargs['locations'] = locations |
|
827 | kwargs['locations'] = locations | |
826 | #---Else |
|
828 | #---Else | |
827 | kwargs['title'] = 'Campaign' |
|
829 | kwargs['title'] = 'Campaign' | |
828 | kwargs['suptitle'] = campaign.name |
|
830 | kwargs['suptitle'] = campaign.name | |
829 | kwargs['form'] = form |
|
831 | kwargs['form'] = form | |
830 | kwargs['button'] = 'Search' |
|
832 | kwargs['button'] = 'Search' | |
831 | kwargs['details'] = True |
|
833 | kwargs['details'] = True | |
832 | kwargs['search_button'] = True |
|
834 | kwargs['search_button'] = True | |
833 |
|
835 | |||
834 | return render(request, 'operation.html', kwargs) |
|
836 | return render(request, 'operation.html', kwargs) | |
835 |
|
837 | |||
836 | def operation_search(request, id_camp=None, location_play = None): |
|
838 | def operation_search(request, id_camp=None, location_play = None): | |
837 |
|
839 | |||
838 |
|
840 | |||
839 | if not id_camp: |
|
841 | if not id_camp: | |
840 | campaigns = Campaign.objects.all().order_by('-start_date') |
|
842 | campaigns = Campaign.objects.all().order_by('-start_date') | |
841 | form = OperationSearchForm() |
|
843 | form = OperationSearchForm() | |
842 |
|
844 | |||
843 | if not campaigns: |
|
845 | if not campaigns: | |
844 | return render(request, 'operation.html', {}) |
|
846 | return render(request, 'operation.html', {}) | |
845 |
|
847 | |||
846 | id_camp = campaigns[0].id |
|
848 | id_camp = campaigns[0].id | |
847 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
849 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
848 |
|
850 | |||
849 | kwargs = {} |
|
851 | kwargs = {} | |
850 | kwargs['title'] = 'All Campaigns' |
|
852 | kwargs['title'] = 'All Campaigns' | |
851 | kwargs['form'] = form |
|
853 | kwargs['form'] = form | |
852 | kwargs['details'] = True |
|
854 | kwargs['details'] = True | |
853 | return render(request, 'operation.html', kwargs) |
|
855 | return render(request, 'operation.html', kwargs) | |
854 |
|
856 | |||
855 | else: |
|
857 | else: | |
856 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
858 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
857 | locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() |
|
859 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() | |
|
860 | #experiments = Experiment.objects.filter(campaign__pk=campaign.id) | |||
858 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) |
|
861 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) | |
|
862 | locations= Location.objects.filter(experiment=experiments).distinct() | |||
859 | #experiments = [Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) for location in locations] |
|
863 | #experiments = [Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) for location in locations] | |
860 | form = OperationSearchForm(initial={'campaign': campaign.id}) |
|
864 | form = OperationSearchForm(initial={'campaign': campaign.id}) | |
861 |
|
865 | |||
862 | kwargs = {} |
|
866 | kwargs = {} | |
863 | #---Campaign |
|
867 | #---Campaign | |
864 | kwargs['campaign'] = campaign |
|
868 | kwargs['campaign'] = campaign | |
865 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
869 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
866 | #---Experiment |
|
870 | #---Experiment | |
867 | keys = ['id', 'name', 'start_time', 'end_time'] |
|
871 | keys = ['id', 'name', 'start_time', 'end_time'] | |
868 | kwargs['experiment_keys'] = keys[1:] |
|
872 | kwargs['experiment_keys'] = keys[1:] | |
869 | kwargs['experiments'] = experiments |
|
873 | kwargs['experiments'] = experiments | |
870 | #---Radar |
|
874 | #---Radar | |
871 | kwargs['locations'] = locations |
|
875 | kwargs['locations'] = locations | |
872 | #---Else |
|
876 | #---Else | |
873 | kwargs['title'] = 'Campaign' |
|
877 | kwargs['title'] = 'Campaign' | |
874 | kwargs['suptitle'] = campaign.name |
|
878 | kwargs['suptitle'] = campaign.name | |
875 | kwargs['form'] = form |
|
879 | kwargs['form'] = form | |
876 | kwargs['button'] = 'Select' |
|
880 | kwargs['button'] = 'Select' | |
877 | kwargs['details'] = True |
|
881 | kwargs['details'] = True | |
878 | kwargs['search_button'] = False |
|
882 | kwargs['search_button'] = False | |
879 |
|
883 | |||
880 |
|
884 | |||
881 | if request.method=='POST': |
|
885 | if request.method=='POST': | |
882 | form = OperationSearchForm(request.POST, initial={'campaign':campaign.id}) |
|
886 | form = OperationSearchForm(request.POST, initial={'campaign':campaign.id}) | |
883 |
|
887 | |||
884 | if form.is_valid(): |
|
888 | if form.is_valid(): | |
885 | return redirect('operation.html', id_camp=campaign.id) |
|
889 | return redirect('operation.html', id_camp=campaign.id) | |
886 |
|
890 | |||
887 |
|
891 | |||
888 | return render(request, 'operation.html', kwargs) No newline at end of file |
|
892 | return render(request, 'operation.html', kwargs) |
General Comments 0
You need to be logged in to leave comments.
Login now