@@ -1,7 +1,9 | |||
|
1 | 1 | from django.conf.urls import url |
|
2 | 2 | |
|
3 | 3 | urlpatterns = ( |
|
4 | 4 | #url(r'^configuration/$', 'apps.cgs.views.configurate_frequencies', name='new_device'), |
|
5 | url(r'^(?P<id>-?\d+)/$', 'apps.cgs.views.configurate_frequencies', name='new_device'), | |
|
5 | # url(r'^(?P<id>-?\d+)/$', 'apps.cgs.views.configurate_frequencies', name='new_device'), | |
|
6 | url(r'^(?P<id_conf>-?\d+)/$', 'apps.main.views.dev_conf', name='url_cgs_conf'), | |
|
7 | url(r'^(?P<id_conf>-?\d+)/edit/$', 'apps.main.views.edit_dev_conf', name='url_edit_cgs_conf'), | |
|
6 | 8 | ) |
|
7 | 9 |
@@ -1,49 +1,63 | |||
|
1 | 1 | # Create your views here. |
|
2 | 2 | |
|
3 | 3 | from django.shortcuts import redirect, render |
|
4 | 4 | |
|
5 | from apps.main.models import Experiment, Configuration | |
|
5 | 6 | from .models import DDSConfiguration |
|
6 | 7 | from .forms import DDSConfigurationForm |
|
7 | 8 | # Create your views here. |
|
8 | 9 | |
|
9 | 10 | def dds_conf(request, id_conf): |
|
10 | 11 | |
|
11 |
|
|
|
12 | conf = DDSConfiguration.objects.get(pk=id_conf) | |
|
12 | 13 | |
|
13 | 14 | kwargs = {} |
|
14 |
kwargs['dev_conf'] = |
|
|
15 | kwargs['dev_conf'] = conf | |
|
15 | 16 | kwargs['dev_conf_keys'] = ['experiment', 'device', |
|
16 | 17 | 'clock', 'multiplier', |
|
17 | 18 | 'freq_reg', 'phase_reg', |
|
18 | 19 | 'amplitude_chA', 'amplitude_chB', |
|
19 | 20 | 'modulation', |
|
20 | 21 | 'freq_reg_mod', 'phase_reg_mod'] |
|
21 | 22 | |
|
22 | 23 | kwargs['title'] = 'DDS Configuration' |
|
23 | 24 | kwargs['suptitle'] = 'Details' |
|
24 | 25 | |
|
25 | 26 | kwargs['button'] = 'Edit Configuration' |
|
26 | 27 | |
|
28 | ###### SIDEBAR ###### | |
|
29 | experiments = Experiment.objects.filter(campaign=conf.experiment.campaign) | |
|
30 | configurations = Configuration.objects.filter(experiment=conf.experiment) | |
|
31 | ||
|
32 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] | |
|
33 | conf_keys = ['id', 'device__name', 'device__device_type__name', 'device__ip_address'] | |
|
34 | ||
|
35 | kwargs['experiment_keys'] = exp_keys[1:] | |
|
36 | kwargs['experiments'] = experiments.values(*exp_keys) | |
|
37 | ||
|
38 | kwargs['configuration_keys'] = conf_keys[1:] | |
|
39 | kwargs['configurations'] = configurations.values(*conf_keys) | |
|
40 | ||
|
27 | 41 | return render(request, 'dds_conf.html', kwargs) |
|
28 | 42 | |
|
29 | 43 | def edit_dds_conf(request, id_conf): |
|
30 | 44 | |
|
31 |
|
|
|
45 | conf = DDSConfiguration.objects.get(pk=id_conf) | |
|
32 | 46 | |
|
33 | 47 | if request.method=='GET': |
|
34 |
form = DDSConfigurationForm(instance= |
|
|
48 | form = DDSConfigurationForm(instance=conf) | |
|
35 | 49 | |
|
36 | 50 | if request.method=='POST': |
|
37 |
form = DDSConfigurationForm(request.POST, instance= |
|
|
51 | form = DDSConfigurationForm(request.POST, instance=conf) | |
|
38 | 52 | |
|
39 | 53 | if form.is_valid(): |
|
40 | 54 | form.save() |
|
41 | 55 | return redirect('url_dds_conf', id_conf=id_conf) |
|
42 | 56 | |
|
43 | 57 | kwargs = {} |
|
44 | 58 | kwargs['form'] = form |
|
45 | 59 | kwargs['title'] = 'Device Configuration' |
|
46 | 60 | kwargs['suptitle'] = 'Edit' |
|
47 | 61 | kwargs['button'] = 'Update' |
|
48 | 62 | |
|
49 | 63 | return render(request, 'dds_conf_edit.html', kwargs) No newline at end of file |
@@ -1,5 +1,7 | |||
|
1 | 1 | from django.conf.urls import url |
|
2 | 2 | |
|
3 | 3 | urlpatterns = ( |
|
4 | url(r'^(?P<id>-?\d+)/$', 'apps.jars.views.jars_config', name='jars'), | |
|
4 | # url(r'^(?P<id>-?\d+)/$', 'apps.jars.views.jars_config', name='jars'), | |
|
5 | url(r'^(?P<id_conf>-?\d+)/$', 'apps.main.views.dev_conf', name='url_jars_conf'), | |
|
6 | url(r'^(?P<id_conf>-?\d+)/edit/$', 'apps.main.views.edit_dev_conf', name='url_edit_jars_conf'), | |
|
5 | 7 | ) |
@@ -1,62 +1,100 | |||
|
1 |
{% if |
|
|
1 | {% if campaign %} | |
|
2 | 2 | <div class="panel panel-default"> |
|
3 | 3 | <div class="panel-heading"> |
|
4 | 4 | <h4>Campaign</h4> |
|
5 | 5 | </div> |
|
6 | 6 | <div class="list-group"> |
|
7 |
<a href="{% url 'url_campaign' |
|
|
7 | <a href="{% url 'url_campaign' campaign.id %}" class="list-group-item active" >{{ campaign.name }}</a> | |
|
8 | 8 | </div> |
|
9 | 9 | </div> |
|
10 | 10 | |
|
11 | {% if experiments %} | |
|
12 | <div class="panel panel-default"> | |
|
13 | <div class="panel-heading"> | |
|
14 | <h4>Experiments</h4> | |
|
15 | </div> | |
|
16 | <div class="list-group"> | |
|
17 | {% for item in experiments %} | |
|
18 | <a href="{% url 'url_experiment' item.id %}" class="list-group-item {{item.active}}">{{item.name}}</a> | |
|
19 | {% endfor %} | |
|
20 | </div> | |
|
21 | </div> | |
|
22 | {% endif %} | |
|
23 | {% endif %} | |
|
24 | ||
|
25 | {% if experiment %} | |
|
11 | 26 | <div class="panel panel-default"> |
|
12 | 27 | <div class="panel-heading"> |
|
13 |
<h4> |
|
|
28 | <h4>Campaign</h4> | |
|
14 | 29 | </div> |
|
15 | 30 | <div class="list-group"> |
|
16 |
<a href="{% url 'url_ |
|
|
31 | <a href="{% url 'url_campaign' experiment.campaign.id %}" class="list-group-item active" >{{ experiment.campaign.name }}</a> | |
|
17 | 32 | </div> |
|
18 | 33 | </div> |
|
19 | 34 | |
|
35 | {% if experiments %} | |
|
36 | <div class="panel panel-default"> | |
|
37 | <div class="panel-heading"> | |
|
38 | <h4>Experiments</h4> | |
|
39 | </div> | |
|
40 | <div class="list-group"> | |
|
41 | {% for item in experiments %} | |
|
42 | <a href="{% url 'url_experiment' item.id %}" class="list-group-item {%if item.id == experiment.id%}active{%endif%}">{{item.name}}</a> | |
|
43 | {% endfor %} | |
|
44 | </div> | |
|
45 | </div> | |
|
46 | {% endif %} | |
|
47 | ||
|
20 | 48 | {% if configurations %} |
|
21 | 49 | <div class="panel panel-default"> |
|
22 | 50 | <div class="panel-heading"> |
|
23 | 51 | <h4>Device Configurations</h4> |
|
24 | 52 | </div> |
|
25 | 53 | <div class="list-group"> |
|
26 | 54 | {% for item in configurations %} |
|
27 | 55 | <a href="/{{item.device__device_type__name}}/{{item.id}}" class="list-group-item {{item.active}}">{{item.device__name}}</a> |
|
28 | 56 | {% endfor %} |
|
29 | 57 | </div> |
|
30 | 58 | </div> |
|
31 | 59 | {% endif %} |
|
60 | ||
|
32 | 61 | {% endif %} |
|
33 | 62 | |
|
34 | 63 | {% if dev_conf %} |
|
35 | 64 | <div class="panel panel-default"> |
|
36 | 65 | <div class="panel-heading"> |
|
37 | 66 | <h4>Campaign</h4> |
|
38 | 67 | </div> |
|
39 | 68 | <div class="list-group"> |
|
40 | 69 | <a href="{% url 'url_campaign' dev_conf.experiment.campaign.id %}" class="list-group-item active" >{{ dev_conf.experiment.campaign.name }}</a> |
|
41 | 70 | </div> |
|
42 | 71 | </div> |
|
43 | 72 | |
|
44 | <div class="panel panel-default"> | |
|
45 |
|
|
|
46 | <h4>Experiment</h4> | |
|
47 | </div> | |
|
48 | <div class="list-group"> | |
|
49 | <a href="{% url 'url_experiment' dev_conf.experiment.id %}" class="list-group-item active" >{{ dev_conf.experiment.name }}</a> | |
|
50 | </div> | |
|
51 | </div> | |
|
73 | {% if experiments %} | |
|
74 | <div class="panel panel-default"> | |
|
75 | <div class="panel-heading"> | |
|
76 | <h4>Experiments</h4> | |
|
77 | </div> | |
|
78 | <div class="list-group"> | |
|
79 | {% for item in experiments %} | |
|
80 | <a href="{% url 'url_experiment' item.id %}" class="list-group-item {%if item.id == dev_conf.experiment.id%}active{%endif%}">{{item.name}}</a> | |
|
81 | {% endfor %} | |
|
82 | </div> | |
|
83 | </div> | |
|
84 | {% endif %} | |
|
85 | ||
|
86 | {% if configurations %} | |
|
87 | <div class="panel panel-default"> | |
|
88 | <div class="panel-heading"> | |
|
89 | <h4>Device Configurations</h4> | |
|
90 | </div> | |
|
91 | <div class="list-group"> | |
|
92 | {% for item in configurations %} | |
|
93 | <a href="/{{item.device__device_type__name}}/{{item.id}}" class="list-group-item {%if item.id == dev_conf.id%}active{%endif%}">{{item.device__name}}</a> | |
|
94 | {% endfor %} | |
|
95 | </div> | |
|
96 | </div> | |
|
97 | {% endif %} | |
|
52 | 98 | |
|
53 | <div class="panel panel-default"> | |
|
54 | <div class="panel-heading"> | |
|
55 | <h4>Device</h4> | |
|
56 | </div> | |
|
57 | <div class="list-group"> | |
|
58 | <a href="{% url 'url_device' dev_conf.device.id %}" class="list-group-item active" >{{ dev_conf.device.name }}</a> | |
|
59 | </div> | |
|
60 | </div> | |
|
61 | 99 | |
|
62 | 100 | {% endif %} |
@@ -1,494 +1,507 | |||
|
1 | 1 | from django.shortcuts import render, redirect |
|
2 | 2 | |
|
3 | 3 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm |
|
4 | 4 | from apps.cgs.forms import CGSConfigurationForm |
|
5 | 5 | from apps.jars.forms import JARSConfigurationForm |
|
6 | 6 | from apps.usrp.forms import USRPConfigurationForm |
|
7 | 7 | from apps.abs.forms import ABSConfigurationForm |
|
8 | 8 | from apps.rc.forms import RCConfigurationForm |
|
9 | 9 | from apps.dds.forms import DDSConfigurationForm |
|
10 | 10 | |
|
11 | 11 | from .models import Campaign, Experiment, Device, Configuration |
|
12 | 12 | from apps.cgs.models import CGSConfiguration |
|
13 | 13 | from apps.jars.models import JARSConfiguration |
|
14 | 14 | from apps.usrp.models import USRPConfiguration |
|
15 | 15 | from apps.abs.models import ABSConfiguration |
|
16 | 16 | from apps.rc.models import RCConfiguration |
|
17 | 17 | from apps.dds.models import DDSConfiguration |
|
18 | 18 | |
|
19 | 19 | # Create your views here. |
|
20 | 20 | |
|
21 | 21 | CONF_FORMS = { |
|
22 | 22 | 'rc': RCConfigurationForm, |
|
23 | 23 | 'dds': DDSConfigurationForm, |
|
24 | 24 | 'jars': JARSConfigurationForm, |
|
25 | 25 | 'cgs': CGSConfigurationForm, |
|
26 | 26 | 'abs': ABSConfigurationForm, |
|
27 | 27 | 'usrp': USRPConfigurationForm, |
|
28 | 28 | } |
|
29 | 29 | |
|
30 | 30 | CONF_MODELS = { |
|
31 | 31 | 'rc': RCConfiguration, |
|
32 | 32 | 'dds': DDSConfiguration, |
|
33 | 33 | 'jars': JARSConfiguration, |
|
34 | 34 | 'cgs': CGSConfiguration, |
|
35 | 35 | 'abs': ABSConfiguration, |
|
36 | 36 | 'usrp': USRPConfiguration, |
|
37 | 37 | } |
|
38 | 38 | |
|
39 | 39 | def index(request): |
|
40 | 40 | kwargs = {} |
|
41 | 41 | |
|
42 | 42 | return render(request, 'index.html', kwargs) |
|
43 | 43 | |
|
44 | 44 | def devices(request): |
|
45 | 45 | |
|
46 | 46 | devices = Device.objects.all().order_by('device_type__name') |
|
47 | 47 | |
|
48 | 48 | keys = ['id', 'device_type__name', 'name', 'ip_address'] |
|
49 | 49 | |
|
50 | 50 | kwargs = {} |
|
51 | 51 | kwargs['device_keys'] = keys[1:] |
|
52 | 52 | kwargs['devices'] = devices.values(*keys) |
|
53 | 53 | kwargs['title'] = 'Device' |
|
54 | 54 | kwargs['suptitle'] = 'List' |
|
55 | 55 | kwargs['button'] = 'New Device' |
|
56 | 56 | |
|
57 | 57 | return render(request, 'devices.html', kwargs) |
|
58 | 58 | |
|
59 | 59 | def device(request, id_dev): |
|
60 | 60 | |
|
61 | 61 | device = Device.objects.get(pk=id_dev) |
|
62 | 62 | |
|
63 | 63 | # form = DeviceForm(instance=device) |
|
64 | 64 | |
|
65 | 65 | kwargs = {} |
|
66 | 66 | kwargs['device'] = device |
|
67 | 67 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] |
|
68 | 68 | |
|
69 | 69 | kwargs['title'] = 'Device' |
|
70 | 70 | kwargs['suptitle'] = 'Details' |
|
71 | 71 | |
|
72 | 72 | # kwargs['form'] = form |
|
73 | 73 | kwargs['button'] = 'Add Device' |
|
74 | 74 | |
|
75 | 75 | return render(request, 'device.html', kwargs) |
|
76 | 76 | |
|
77 | 77 | def add_device(request): |
|
78 | 78 | |
|
79 | 79 | if request.method == 'GET': |
|
80 | 80 | form = DeviceForm() |
|
81 | 81 | |
|
82 | 82 | if request.method == 'POST': |
|
83 | 83 | form = DeviceForm(request.POST) |
|
84 | 84 | |
|
85 | 85 | if form.is_valid(): |
|
86 | 86 | form.save() |
|
87 | 87 | return redirect('url_devices') |
|
88 | 88 | |
|
89 | 89 | kwargs = {} |
|
90 | 90 | kwargs['form'] = form |
|
91 | 91 | kwargs['title'] = 'Device' |
|
92 | 92 | kwargs['suptitle'] = 'New' |
|
93 | 93 | kwargs['button'] = 'Create' |
|
94 | 94 | |
|
95 | 95 | return render(request, 'device_edit.html', kwargs) |
|
96 | 96 | |
|
97 | 97 | def edit_device(request, id_dev): |
|
98 | 98 | |
|
99 | 99 | device = Device.objects.get(pk=id_dev) |
|
100 | 100 | |
|
101 | 101 | if request.method=='GET': |
|
102 | 102 | form = DeviceForm(instance=device) |
|
103 | 103 | |
|
104 | 104 | if request.method=='POST': |
|
105 | 105 | form = DeviceForm(request.POST, instance=device) |
|
106 | 106 | |
|
107 | 107 | if form.is_valid(): |
|
108 | 108 | form.save() |
|
109 | 109 | return redirect('url_devices') |
|
110 | 110 | |
|
111 | 111 | kwargs = {} |
|
112 | 112 | kwargs['form'] = form |
|
113 | 113 | kwargs['title'] = 'Device' |
|
114 | 114 | kwargs['suptitle'] = 'Edit' |
|
115 | 115 | kwargs['button'] = 'Update' |
|
116 | 116 | |
|
117 | 117 | return render(request, 'device_edit.html', kwargs) |
|
118 | 118 | |
|
119 | 119 | def campaigns(request): |
|
120 | 120 | |
|
121 | 121 | campaigns = Campaign.objects.all().order_by('start_date') |
|
122 | 122 | |
|
123 | 123 | keys = ['id', 'name', 'start_date', 'end_date'] |
|
124 | 124 | |
|
125 | 125 | kwargs = {} |
|
126 | 126 | kwargs['campaign_keys'] = keys[1:] |
|
127 | 127 | kwargs['campaigns'] = campaigns.values(*keys) |
|
128 | 128 | kwargs['title'] = 'Campaign' |
|
129 | 129 | kwargs['suptitle'] = 'List' |
|
130 | 130 | kwargs['button'] = 'New Campaign' |
|
131 | 131 | |
|
132 | 132 | return render(request, 'campaigns.html', kwargs) |
|
133 | 133 | |
|
134 | 134 | def campaign(request, id_camp): |
|
135 | 135 | |
|
136 | 136 | campaign = Campaign.objects.get(pk=id_camp) |
|
137 | 137 | experiments = Experiment.objects.filter(campaign=campaign) |
|
138 | 138 | |
|
139 | 139 | form = CampaignForm(instance=campaign) |
|
140 | 140 | |
|
141 | 141 | kwargs = {} |
|
142 | 142 | kwargs['campaign'] = campaign |
|
143 | 143 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
144 | 144 | |
|
145 | 145 | keys = ['id', 'name', 'start_time', 'end_time'] |
|
146 | 146 | |
|
147 | 147 | kwargs['experiment_keys'] = keys[1:] |
|
148 | 148 | kwargs['experiments'] = experiments.values(*keys) |
|
149 | 149 | |
|
150 | 150 | kwargs['title'] = 'Campaign' |
|
151 | 151 | kwargs['suptitle'] = 'Details' |
|
152 | 152 | |
|
153 | 153 | kwargs['form'] = form |
|
154 | 154 | kwargs['button'] = 'Add Experiment' |
|
155 | 155 | |
|
156 | 156 | return render(request, 'campaign.html', kwargs) |
|
157 | 157 | |
|
158 | 158 | def add_campaign(request): |
|
159 | 159 | |
|
160 | 160 | if request.method == 'GET': |
|
161 | 161 | form = CampaignForm() |
|
162 | 162 | |
|
163 | 163 | if request.method == 'POST': |
|
164 | 164 | form = CampaignForm(request.POST) |
|
165 | 165 | |
|
166 | 166 | if form.is_valid(): |
|
167 | 167 | campaign = form.save() |
|
168 | 168 | return redirect('url_campaign', id_camp=campaign.id) |
|
169 | 169 | |
|
170 | 170 | kwargs = {} |
|
171 | 171 | kwargs['form'] = form |
|
172 | 172 | kwargs['title'] = 'Campaign' |
|
173 | 173 | kwargs['suptitle'] = 'New' |
|
174 | 174 | kwargs['button'] = 'Create' |
|
175 | 175 | |
|
176 | 176 | return render(request, 'campaign_edit.html', kwargs) |
|
177 | 177 | |
|
178 | 178 | def edit_campaign(request, id_camp): |
|
179 | 179 | |
|
180 | 180 | campaign = Campaign.objects.get(pk=id_camp) |
|
181 | 181 | |
|
182 | 182 | if request.method=='GET': |
|
183 | 183 | form = CampaignForm(instance=campaign) |
|
184 | 184 | |
|
185 | 185 | if request.method=='POST': |
|
186 | 186 | form = CampaignForm(request.POST, instance=campaign) |
|
187 | 187 | |
|
188 | 188 | if form.is_valid(): |
|
189 | 189 | form.save() |
|
190 | 190 | return redirect('url_campaign', id_camp=id_camp) |
|
191 | 191 | |
|
192 | 192 | kwargs = {} |
|
193 | 193 | kwargs['form'] = form |
|
194 | 194 | kwargs['title'] = 'Campaign' |
|
195 | 195 | kwargs['suptitle'] = 'Edit' |
|
196 | 196 | kwargs['button'] = 'Update' |
|
197 | 197 | |
|
198 | 198 | return render(request, 'campaign_edit.html', kwargs) |
|
199 | 199 | |
|
200 | 200 | def experiments(request): |
|
201 | 201 | |
|
202 | 202 | campaigns = Experiment.objects.all().order_by('start_time') |
|
203 | 203 | |
|
204 | 204 | keys = ['id', 'campaign__name', 'name', 'start_time', 'end_time'] |
|
205 | 205 | |
|
206 | 206 | kwargs = {} |
|
207 | 207 | |
|
208 | 208 | kwargs['experiment_keys'] = keys[1:] |
|
209 | 209 | kwargs['experiments'] = campaigns.values(*keys) |
|
210 | 210 | |
|
211 | 211 | kwargs['title'] = 'Experiment' |
|
212 | 212 | kwargs['suptitle'] = 'List' |
|
213 | 213 | kwargs['button'] = 'New Experiment' |
|
214 | 214 | |
|
215 | 215 | return render(request, 'experiments.html', kwargs) |
|
216 | 216 | |
|
217 | 217 | def experiment(request, id_exp): |
|
218 | 218 | |
|
219 | 219 | experiment = Experiment.objects.get(pk=id_exp) |
|
220 | # campaign = Campaign.objects.get(pk = experiment.campaign.id) | |
|
221 | configurations = Configuration.objects.filter(experiment=experiment) | |
|
222 | 220 | |
|
223 | # form = ExperimentForm(instance=experiment) | |
|
221 | experiments = Experiment.objects.filter(campaign=experiment.campaign) | |
|
222 | configurations = Configuration.objects.filter(experiment=experiment) | |
|
224 | 223 | |
|
225 | 224 | kwargs = {} |
|
226 | 225 | |
|
227 | # kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
|
228 | # kwargs['campaign'] = campaign | |
|
226 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] | |
|
227 | conf_keys = ['id', 'device__name', 'device__device_type__name', 'device__ip_address'] | |
|
228 | ||
|
229 | 229 | |
|
230 | kwargs['experiment_keys'] = ['campaign', 'name', 'start_time', 'end_time'] | |
|
230 | kwargs['experiment_keys'] = exp_keys[1:] | |
|
231 | 231 | kwargs['experiment'] = experiment |
|
232 | 232 | |
|
233 | keys = ['id', 'device__name', 'device__device_type__name', 'device__ip_address'] | |
|
233 | kwargs['experiments'] = experiments.values(*exp_keys) | |
|
234 | 234 | |
|
235 | kwargs['configuration_keys'] = keys[1:] | |
|
236 | kwargs['configurations'] = configurations.values(*keys) | |
|
235 | kwargs['configuration_keys'] = conf_keys[1:] | |
|
236 | kwargs['configurations'] = configurations.values(*conf_keys) | |
|
237 | 237 | |
|
238 | 238 | kwargs['title'] = 'Experiment' |
|
239 | 239 | kwargs['suptitle'] = 'Details' |
|
240 | 240 | |
|
241 | 241 | # kwargs['form'] = form |
|
242 | 242 | kwargs['button'] = 'Add Device' |
|
243 | 243 | |
|
244 | 244 | return render(request, 'experiment.html', kwargs) |
|
245 | 245 | |
|
246 | 246 | def add_experiment(request, id_camp=0): |
|
247 | 247 | |
|
248 | 248 | if request.method == 'GET': |
|
249 | 249 | form = ExperimentForm(initial={'campaign':id_camp}) |
|
250 | 250 | |
|
251 | 251 | if request.method == 'POST': |
|
252 | 252 | form = ExperimentForm(request.POST, initial={'campaign':id_camp}) |
|
253 | 253 | |
|
254 | 254 | if form.is_valid(): |
|
255 | 255 | experiment = form.save() |
|
256 | 256 | return redirect('url_experiment', id_exp=experiment.id) |
|
257 | 257 | |
|
258 | 258 | kwargs = {} |
|
259 | 259 | kwargs['form'] = form |
|
260 | 260 | kwargs['title'] = 'Experiment' |
|
261 | 261 | kwargs['suptitle'] = 'New' |
|
262 | 262 | kwargs['button'] = 'Create' |
|
263 | 263 | |
|
264 | 264 | return render(request, 'experiment_edit.html', kwargs) |
|
265 | 265 | |
|
266 | 266 | def edit_experiment(request, id_exp): |
|
267 | 267 | |
|
268 | 268 | experiment = Experiment.objects.get(pk=id_exp) |
|
269 | 269 | |
|
270 | 270 | if request.method == 'GET': |
|
271 | 271 | form = ExperimentForm(instance=experiment) |
|
272 | 272 | |
|
273 | 273 | if request.method=='POST': |
|
274 | 274 | form = ExperimentForm(request.POST, instance=experiment) |
|
275 | 275 | |
|
276 | 276 | if form.is_valid(): |
|
277 | 277 | experiment = form.save() |
|
278 | 278 | return redirect('url_experiment', id_exp=experiment.id) |
|
279 | 279 | |
|
280 | 280 | kwargs = {} |
|
281 | 281 | kwargs['form'] = form |
|
282 | 282 | kwargs['title'] = 'Experiment' |
|
283 | 283 | kwargs['suptitle'] = 'Edit' |
|
284 | 284 | kwargs['button'] = 'Update' |
|
285 | 285 | |
|
286 | 286 | return render(request, 'experiment_edit.html', kwargs) |
|
287 | 287 | |
|
288 | 288 | def dev_confs(request): |
|
289 | 289 | |
|
290 | 290 | configurations = Configuration.objects.all().order_by('device__device_type') |
|
291 | 291 | |
|
292 | 292 | keys = ['id', 'device__device_type__name', 'device__name', 'experiment__campaign__name', 'experiment__name'] |
|
293 | 293 | |
|
294 | 294 | kwargs = {} |
|
295 | 295 | |
|
296 | 296 | kwargs['configuration_keys'] = keys[1:] |
|
297 | 297 | kwargs['configurations'] = configurations.values(*keys) |
|
298 | 298 | |
|
299 | 299 | kwargs['title'] = 'Configuration' |
|
300 | 300 | kwargs['suptitle'] = 'List' |
|
301 | 301 | kwargs['button'] = 'New Configuration' |
|
302 | 302 | |
|
303 | 303 | return render(request, 'dev_confs.html', kwargs) |
|
304 | 304 | |
|
305 | 305 | def dev_conf(request, id_conf): |
|
306 | 306 | |
|
307 | 307 | conf = Configuration.objects.get(pk=id_conf) |
|
308 | 308 | |
|
309 | 309 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
310 | 310 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
311 | 311 | |
|
312 | 312 | kwargs = {} |
|
313 | 313 | kwargs['dev_conf'] = dev_conf |
|
314 | 314 | kwargs['dev_conf_keys'] = ['experiment', 'device'] |
|
315 | 315 | |
|
316 | 316 | kwargs['title'] = 'Configuration' |
|
317 | 317 | kwargs['suptitle'] = 'Details' |
|
318 | 318 | |
|
319 | 319 | kwargs['button'] = 'Edit Configuration' |
|
320 | 320 | |
|
321 | ###### SIDEBAR ###### | |
|
322 | experiments = Experiment.objects.filter(campaign=conf.experiment.campaign) | |
|
323 | configurations = Configuration.objects.filter(experiment=conf.experiment) | |
|
324 | ||
|
325 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] | |
|
326 | conf_keys = ['id', 'device__name', 'device__device_type__name', 'device__ip_address'] | |
|
327 | ||
|
328 | kwargs['experiment_keys'] = exp_keys[1:] | |
|
329 | kwargs['experiments'] = experiments.values(*exp_keys) | |
|
330 | ||
|
331 | kwargs['configuration_keys'] = conf_keys[1:] | |
|
332 | kwargs['configurations'] = configurations.values(*conf_keys) | |
|
333 | ||
|
321 | 334 | return render(request, 'dev_conf.html', kwargs) |
|
322 | 335 | |
|
323 | 336 | def add_dev_conf(request, id_exp=0): |
|
324 | 337 | |
|
325 | 338 | if request.method == 'GET': |
|
326 | 339 | form = ConfigurationForm(initial={'experiment':id_exp}) |
|
327 | 340 | |
|
328 | 341 | if request.method == 'POST': |
|
329 | 342 | form = ConfigurationForm(request.POST) |
|
330 | 343 | |
|
331 | 344 | if form.is_valid(): |
|
332 | 345 | experiment = Experiment.objects.get(pk=request.POST['experiment']) |
|
333 | 346 | device = Device.objects.get(pk=request.POST['device']) |
|
334 | 347 | |
|
335 | 348 | exp_devices = Device.objects.filter(configuration__experiment=experiment) |
|
336 | 349 | |
|
337 | 350 | if device.id not in exp_devices.values('id',): |
|
338 | 351 | |
|
339 | 352 | DevConfModel = CONF_MODELS[device.device_type.name] |
|
340 | 353 | conf = DevConfModel(experiment=experiment, device=device) |
|
341 | 354 | conf.save() |
|
342 | 355 | |
|
343 | 356 | return redirect('url_experiment', id_exp=experiment.id) |
|
344 | 357 | |
|
345 | 358 | kwargs = {} |
|
346 | 359 | kwargs['form'] = form |
|
347 | 360 | kwargs['title'] = 'Configuration' |
|
348 | 361 | kwargs['suptitle'] = 'New' |
|
349 | 362 | kwargs['button'] = 'Create' |
|
350 | 363 | |
|
351 | 364 | return render(request, 'dev_conf_edit.html', kwargs) |
|
352 | 365 | |
|
353 | 366 | def edit_dev_conf(request, id_conf): |
|
354 | 367 | |
|
355 | 368 | conf = Configuration.objects.get(pk=id_conf) |
|
356 | 369 | |
|
357 | 370 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
358 | 371 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
359 | 372 | |
|
360 | 373 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
361 | 374 | |
|
362 | 375 | if request.method=='GET': |
|
363 | 376 | form = DevConfForm(instance=dev_conf) |
|
364 | 377 | |
|
365 | 378 | if request.method=='POST': |
|
366 | 379 | form = DevConfForm(request.POST, instance=dev_conf) |
|
367 | 380 | |
|
368 | 381 | if form.is_valid(): |
|
369 | 382 | form.save() |
|
370 | 383 | return redirect('url_dev_conf', id_conf=id_conf) |
|
371 | 384 | |
|
372 | 385 | kwargs = {} |
|
373 | 386 | kwargs['form'] = form |
|
374 | 387 | kwargs['title'] = 'Device Configuration' |
|
375 | 388 | kwargs['suptitle'] = 'Edit' |
|
376 | 389 | kwargs['button'] = 'Update' |
|
377 | 390 | |
|
378 | 391 | return render(request, 'dev_conf_edit.html', kwargs) |
|
379 | 392 | |
|
380 | 393 | |
|
381 | 394 | # def experiment(request, id_exp=0, id_dev_type=0): |
|
382 | 395 | # kwargs = {} |
|
383 | 396 | # if id_exp: |
|
384 | 397 | # experiment = Experiment.objects.get(pk=id_exp) |
|
385 | 398 | # devices = Configuration.objects.filter(configuration__experiment=experiment) |
|
386 | 399 | # kwargs['experiment'] = experiment |
|
387 | 400 | # kwargs['experiment_keys'] = ['campaign', 'name', 'start_time', 'end_time'] |
|
388 | 401 | # |
|
389 | 402 | # form = ExperimentForm(instance=experiment) |
|
390 | 403 | # |
|
391 | 404 | # if id_dev_type: |
|
392 | 405 | # subform = DeviceTypeForm(initial={'device_type':id_dev_type}) |
|
393 | 406 | # kwargs['keys'] = ['ip_address'] |
|
394 | 407 | # keys = ['id']+kwargs['keys'] |
|
395 | 408 | # kwargs['items'] = Device.objects.filter(device_type=id_dev_type).values(*keys) |
|
396 | 409 | # else: |
|
397 | 410 | # subform = DeviceTypeForm() |
|
398 | 411 | # |
|
399 | 412 | # kwargs['form'] = form |
|
400 | 413 | # kwargs['subform'] = subform |
|
401 | 414 | # kwargs['device_keys'] = ['device_type__name', 'ip_address'] |
|
402 | 415 | # kwargs['devices'] = devices.values('device_type__name', 'ip_address', 'configuration__id') |
|
403 | 416 | # kwargs['suptitle'] = 'Detail' |
|
404 | 417 | # else: |
|
405 | 418 | # experiments = Experiment.objects.all().order_by('start_time') |
|
406 | 419 | # kwargs['keys'] = ['name', 'start_time', 'end_time'] |
|
407 | 420 | # keys = ['id']+kwargs['keys'] |
|
408 | 421 | # kwargs['items'] = experiments.values(*keys) |
|
409 | 422 | # kwargs['suptitle'] = 'List' |
|
410 | 423 | # kwargs['button'] = 'Add Experiment' |
|
411 | 424 | # |
|
412 | 425 | # kwargs['id_dev_type'] = id_dev_type |
|
413 | 426 | # kwargs['id_exp'] = id_exp |
|
414 | 427 | # return render_to_response("experiment.html", kwargs, context_instance=RequestContext(request)) |
|
415 | 428 | |
|
416 | 429 | # def edit_experiment(request, id_exp): |
|
417 | 430 | # if request.method=='POST': |
|
418 | 431 | # experiment = Experiment.objects.get(pk=id_exp) |
|
419 | 432 | # form = ExperimentForm(request.POST, instance=experiment) |
|
420 | 433 | # if form.is_valid(): |
|
421 | 434 | # form.save() |
|
422 | 435 | # return redirect('experiment', id_exp=id_exp) |
|
423 | 436 | |
|
424 | 437 | # def experiment_add_device(request, id_exp): |
|
425 | 438 | # if request.method=='POST': |
|
426 | 439 | # experiment = Experiment.objects.get(pk=id_exp) |
|
427 | 440 | # |
|
428 | 441 | # exp_devices = Device.objects.filter(configuration__experiment=experiment) |
|
429 | 442 | # |
|
430 | 443 | # device = Device.objects.get(pk=request.POST['device']) |
|
431 | 444 | # |
|
432 | 445 | # if device.id in exp_devices.values('id',): |
|
433 | 446 | # return redirect('experiment', id_exp=id_exp) |
|
434 | 447 | # |
|
435 | 448 | # model = MODELS[device.device_type.alias] |
|
436 | 449 | # conf = model(experiment=experiment, device=device) |
|
437 | 450 | # conf.save() |
|
438 | 451 | # return redirect('experiment', id_exp=id_exp) |
|
439 | 452 | |
|
440 | 453 | # def add_experiment(request): |
|
441 | 454 | # |
|
442 | 455 | # kwargs = {} |
|
443 | 456 | # if request.method == 'POST': |
|
444 | 457 | # form = ExperimentForm(request.POST) |
|
445 | 458 | # if form.is_valid(): |
|
446 | 459 | # experiment = form.save() |
|
447 | 460 | # return redirect('experiment', id_exp=experiment.id) |
|
448 | 461 | # else: |
|
449 | 462 | # form = ExperimentForm() |
|
450 | 463 | # kwargs['form_new'] = form |
|
451 | 464 | # kwargs['title'] = 'Experiment' |
|
452 | 465 | # kwargs['suptitle'] = 'New' |
|
453 | 466 | # kwargs['id_exp'] = 0 |
|
454 | 467 | # return render_to_response("experiment.html", kwargs, context_instance=RequestContext(request)) |
|
455 | 468 | |
|
456 | 469 | # def device(request, id_dev=0): |
|
457 | 470 | # kwargs = {} |
|
458 | 471 | # if id_dev: |
|
459 | 472 | # device = Device.objects.get(pk=id_dev) |
|
460 | 473 | # kwargs['form'] = DeviceForm(instance=device) |
|
461 | 474 | # kwargs['action'] = 'edit/' |
|
462 | 475 | # kwargs['button'] = 'Update' |
|
463 | 476 | # kwargs['suptitle'] = 'Detail' |
|
464 | 477 | # else: |
|
465 | 478 | # devices = Device.objects.all() |
|
466 | 479 | # kwargs['keys'] = ['device_type__name', 'ip_address'] |
|
467 | 480 | # keys = ['id']+kwargs['keys'] |
|
468 | 481 | # kwargs['items'] = devices.values(*keys) |
|
469 | 482 | # kwargs['suptitle'] = 'List' |
|
470 | 483 | # kwargs['button'] = 'Add Device' |
|
471 | 484 | # return render_to_response("device.html", kwargs, context_instance=RequestContext(request)) |
|
472 | 485 | # |
|
473 | 486 | # def edit_device(request, id_dev): |
|
474 | 487 | # if request.method=='POST': |
|
475 | 488 | # device = Device.objects.get(pk=id_dev) |
|
476 | 489 | # form = DeviceForm(request.POST, instance=device) |
|
477 | 490 | # if form.is_valid(): |
|
478 | 491 | # form.save() |
|
479 | 492 | # return redirect('devices') |
|
480 | 493 | # |
|
481 | 494 | # def add_device(request): |
|
482 | 495 | # kwargs = {} |
|
483 | 496 | # if request.method == 'POST': |
|
484 | 497 | # form = DeviceForm(request.POST) |
|
485 | 498 | # if form.is_valid(): |
|
486 | 499 | # form.save() |
|
487 | 500 | # return redirect('devices') |
|
488 | 501 | # else: |
|
489 | 502 | # form = DeviceForm() |
|
490 | 503 | # kwargs['form'] = form |
|
491 | 504 | # kwargs['button'] = 'Create' |
|
492 | 505 | # kwargs['suptitle'] = 'New' |
|
493 | 506 | # return render_to_response("device.html", kwargs, context_instance=RequestContext(request)) |
|
494 | 507 |
General Comments 0
You need to be logged in to leave comments.
Login now