##// END OF EJS Templates
Task #487: Vista de Operacion...
Fiorella Quino -
r50:28cae6c7c559
parent child
Show More
@@ -0,0 +1,95
1 {% extends "base.html" %}
2 {% load bootstrap3 %}
3 {% load static %}
4 {% load main_tags %}
5 {% block extra-head %}
6 <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet">
7 {% endblock %}
8
9 {% block camp-active %}active{% endblock %}
10
11 {% block content-title %}{{title}}{% endblock %}
12 {% block content-suptitle %}{{suptitle}}{% endblock %}
13
14 {% block content %}
15
16 <form class="form" method="post" action="">
17 {% csrf_token %}
18 {% bootstrap_form form layout='horizontal' size='medium' %}
19 <div style="clear: both;"></div>
20 <br>
21 <button type="submit" class="btn btn-primary pull-right">{{button}}</button>
22 <br>
23 <br>
24 </form>
25 <br>
26 <br>
27
28 <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true" >
29
30 {% for radar in radars %}
31
32 <div class="panel panel-default">
33 <div class="panel-heading" role="tab" id="headingTwo">
34 <h4 class="panel-title">
35 <a class="collapsed" role="button" data-toggle="collapse" href="#collapseTwo-{{ radar.id }}" aria-expanded="false" aria-controls="collapseTwo">
36 {{radar.name}}: Experiment List
37 </a>
38 </h4>
39 </div>
40
41 <div id="collapseTwo-{{ radar.id }}" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo">
42 <div class="panel-body">
43 <table class="table table-hover">
44 <tr>
45
46 {% for header in experiment_keys %}
47 <th>{{ header|title }}</th>
48 {% endfor%}
49 </tr>
50 {% for item in experiments %}
51 {% for exs in item %}
52 <tr class="clickable-row" data-href="{% url 'url_experiment' exs.id %}" >
53
54 {% for key in experiment_keys %}
55 {% if radar.name in exs.radar.name %}
56 <td>{{ exs|attr:key }}</td>
57 {% endif %}
58 {% endfor %}
59 {% endfor %}
60 </tr>
61 {% endfor %}
62 </table>
63 </div>
64 </div>
65 </div>
66 {% endfor %}
67 </div>
68
69 {% endblock %}
70
71
72
73 {% block extra-js%}
74 <script type="text/javascript">
75
76 //$("#bt_add").click(function() {
77 //alert("sometext");
78 // document.location = "{% url 'url_operation' campaign.id %}";
79 //});
80
81 $(".clickable-row").click(function() {
82 document.location = $(this).data("href");
83 });
84
85 $(document).ready(function() {
86 $("#id_campaign").change(function() {
87 var id_camp = document.getElementById("id_campaign").value;
88 //alert(id_camp);
89 document.location = "{% url 'url_operation'%}"+String(id_camp);
90 });
91 });
92
93
94 </script>
95 {% endblock %} No newline at end of file
@@ -1,8 +1,10
1 1 from django.contrib import admin
2 from .models import Device, DeviceType, Experiment, Campaign
2 from .models import Device, DeviceType, Experiment, Campaign, Location, Radar
3 3
4 4 # Register your models here.
5 5 admin.site.register(Campaign)
6 6 admin.site.register(Experiment)
7 7 admin.site.register(Device)
8 admin.site.register(DeviceType) No newline at end of file
8 admin.site.register(DeviceType)
9 admin.site.register(Location)
10 admin.site.register(Radar) No newline at end of file
@@ -1,64 +1,74
1 1 from django import forms
2 2 from django.utils.safestring import mark_safe
3 from datetime import datetime
4
5 from apps.main.widgets import Filtering_ComboBox_Widget, Datepicker, HTMLrender,Filtering_ComboBox_Widget2
6
3 7
4 8 from .models import DeviceType, Device, Experiment, Campaign, Configuration, Location
5 9
6 10 def add_empty_choice(choices, pos=0, label='-----'):
7 11 if len(choices)>0:
8 12 choices = list(choices)
9 13 choices.insert(0, (0, label))
10 14 return choices
11 15 else:
12 16 return [(0, label)]
13 17
14 18 class DatepickerWidget(forms.widgets.TextInput):
15 19 def render(self, name, value, attrs=None):
16 20 input_html = super(DatepickerWidget, self).render(name, value, attrs)
17 21 html = '<div class="input-group date">'+input_html+'<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span></div>'
18 22 return mark_safe(html)
19 23
20 24 class TimepickerWidget(forms.widgets.TextInput):
21 25 def render(self, name, value, attrs=None):
22 26 input_html = super(TimepickerWidget, self).render(name, value, attrs)
23 27 html = '<div class="input-group time">'+input_html+'<span class="input-group-addon"><i class="glyphicon glyphicon-time"></i></span></div>'
24 28 return mark_safe(html)
25 29
26 30 class CampaignForm(forms.ModelForm):
27 31 def __init__(self, *args, **kwargs):
28 32 super(CampaignForm, self).__init__(*args, **kwargs)
29 33 self.fields['start_date'].widget = DatepickerWidget(self.fields['start_date'].widget.attrs)
30 34 self.fields['end_date'].widget = DatepickerWidget(self.fields['end_date'].widget.attrs)
31 35
32 36 class Meta:
33 37 model = Campaign
34 38 exclude = ['']
35 39
36 40 class ExperimentForm(forms.ModelForm):
37 41 def __init__(self, *args, **kwargs):
38 42 super(ExperimentForm, self).__init__(*args, **kwargs)
39 43 self.fields['start_time'].widget = TimepickerWidget(self.fields['start_time'].widget.attrs)
40 44 self.fields['end_time'].widget = TimepickerWidget(self.fields['end_time'].widget.attrs)
41 45
42 46 self.fields['campaign'].widget.attrs['readonly'] = True
43 47
44 48 class Meta:
45 49 model = Experiment
46 50 exclude = ['']
47 51
48 52 class LocationForm(forms.ModelForm):
49 53 class Meta:
50 54 model = Location
51 55 exclude = ['']
52 56
53 57 class DeviceForm(forms.ModelForm):
54 58 class Meta:
55 59 model = Device
56 60 exclude = ['status']
57 61
58 62 class ConfigurationForm(forms.ModelForm):
59 63 class Meta:
60 64 model = Configuration
61 65 exclude = ['type', 'created_date', 'programmed_date', 'parameters']
62 66
63 67 class DeviceTypeForm(forms.Form):
64 68 device_type = forms.ChoiceField(choices=add_empty_choice(DeviceType.objects.all().order_by('name').values_list('id', 'name')))
69
70 class OperationForm(forms.Form):
71 today = datetime.today()
72 # -----Campaigns from this month------
73 campaign = forms.ChoiceField(choices=Campaign.objects.filter(start_date__month=today.month).filter(start_date__year=today.year).order_by('-start_date').values_list('id', 'name'), label="Campaign")
74 No newline at end of file
@@ -1,34 +1,37
1 1 from django.conf.urls import url
2 2
3 3 urlpatterns = (
4 4 url(r'^location/new/$', 'apps.main.views.location_new', name='url_add_location'),
5 5 url(r'^location/$', 'apps.main.views.locations', name='url_locations'),
6 6 url(r'^location/(?P<id_loc>-?\d+)/$', 'apps.main.views.location', name='url_location'),
7 7 url(r'^location/(?P<id_loc>-?\d+)/edit/$', 'apps.main.views.location_edit', name='url_edit_location'),
8 8 url(r'^location/(?P<id_loc>-?\d+)/delete/$', 'apps.main.views.location_delete', name='url_delete_location'),
9 9
10 10 url(r'^device/new/$', 'apps.main.views.device_new', name='url_add_device'),
11 11 url(r'^device/$', 'apps.main.views.devices', name='url_devices'),
12 12 url(r'^device/(?P<id_dev>-?\d+)/$', 'apps.main.views.device', name='url_device'),
13 13 url(r'^device/(?P<id_dev>-?\d+)/edit/$', 'apps.main.views.device_edit', name='url_edit_device'),
14 14 url(r'^device/(?P<id_dev>-?\d+)/delete/$', 'apps.main.views.device_delete', name='url_delete_device'),
15 15
16 16 url(r'^campaign/new/$', 'apps.main.views.campaign_new', name='url_add_campaign'),
17 17 url(r'^campaign/$', 'apps.main.views.campaigns', name='url_campaigns'),
18 18 url(r'^campaign/(?P<id_camp>-?\d+)/$', 'apps.main.views.campaign', name='url_campaign'),
19 19 url(r'^campaign/(?P<id_camp>-?\d+)/edit/$', 'apps.main.views.campaign_edit', name='url_edit_campaign'),
20 20 url(r'^campaign/(?P<id_camp>-?\d+)/delete/$', 'apps.main.views.campaign_delete', name='url_delete_campaign'),
21 21
22 22 url(r'^campaign/(?P<id_camp>-?\d+)/new_experiment/$', 'apps.main.views.experiment_new', name='url_add_experiment'),
23 23 url(r'^experiment/$', 'apps.main.views.experiments', name='url_experiments'),
24 24 url(r'^experiment/(?P<id_exp>-?\d+)/$', 'apps.main.views.experiment', name='url_experiment'),
25 25 url(r'^experiment/(?P<id_exp>-?\d+)/edit/$', 'apps.main.views.experiment_edit', name='url_edit_experiment'),
26 26 url(r'^experiment/(?P<id_exp>-?\d+)/delete/$', 'apps.main.views.experiment_delete', name='url_delete_experiment'),
27 27
28 28 url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'),
29 29 url(r'^dev_conf/$', 'apps.main.views.dev_confs', name='url_dev_confs'),
30 30 url(r'^dev_conf/(?P<id_conf>-?\d+)/$', 'apps.main.views.dev_conf', name='url_dev_conf'),
31 31 url(r'^dev_conf/(?P<id_conf>-?\d+)/edit/$', 'apps.main.views.dev_conf_edit', name='url_edit_dev_conf'),
32 32 url(r'^dev_conf/(?P<id_conf>-?\d+)/delete/$', 'apps.main.views.dev_conf_delete', name='url_delete_dev_conf'),
33 33
34 url(r'^operation/$', 'apps.main.views.operation', name='url_operation'),
35 url(r'^operation/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation', name='url_operation'),
36
34 37 )
@@ -1,595 +1,631
1 1 from django.shortcuts import render, redirect, get_object_or_404, HttpResponse
2 2 from django.contrib import messages
3 3
4 from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm
4 from datetime import datetime
5
6 from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, OperationForm
5 7 from apps.cgs.forms import CGSConfigurationForm
6 8 from apps.jars.forms import JARSConfigurationForm
7 9 from apps.usrp.forms import USRPConfigurationForm
8 10 from apps.abs.forms import ABSConfigurationForm
9 11 from apps.rc.forms import RCConfigurationForm
10 12 from apps.dds.forms import DDSConfigurationForm
11 13
12 from .models import Campaign, Experiment, Device, Configuration, Location
14 from .models import Campaign, Experiment, Device, Configuration, Location, Radar
13 15 from apps.cgs.models import CGSConfiguration
14 16 from apps.jars.models import JARSConfiguration
15 17 from apps.usrp.models import USRPConfiguration
16 18 from apps.abs.models import ABSConfiguration
17 19 from apps.rc.models import RCConfiguration
18 20 from apps.dds.models import DDSConfiguration
19 21
20 22 # Create your views here.
21 23
22 24 CONF_FORMS = {
23 25 'rc': RCConfigurationForm,
24 26 'dds': DDSConfigurationForm,
25 27 'jars': JARSConfigurationForm,
26 28 'cgs': CGSConfigurationForm,
27 29 'abs': ABSConfigurationForm,
28 30 'usrp': USRPConfigurationForm,
29 31 }
30 32
31 33 CONF_MODELS = {
32 34 'rc': RCConfiguration,
33 35 'dds': DDSConfiguration,
34 36 'jars': JARSConfiguration,
35 37 'cgs': CGSConfiguration,
36 38 'abs': ABSConfiguration,
37 39 'usrp': USRPConfiguration,
38 40 }
39 41
40 42 def index(request):
41 43 kwargs = {}
42 44
43 45 return render(request, 'index.html', kwargs)
44 46
45 47 def locations(request):
46 48
47 49 locations = Location.objects.all().order_by('name')
48 50
49 51 keys = ['id', 'name', 'description']
50 52
51 53 kwargs = {}
52 54 kwargs['location_keys'] = keys[1:]
53 55 kwargs['locations'] = locations
54 56 kwargs['title'] = 'Location'
55 57 kwargs['suptitle'] = 'List'
56 58 kwargs['button'] = 'New Location'
57 59
58 60 return render(request, 'locations.html', kwargs)
59 61
60 62 def location(request, id_loc):
61 63
62 64 location = get_object_or_404(Location, pk=id_loc)
63 65
64 66 kwargs = {}
65 67 kwargs['location'] = location
66 68 kwargs['location_keys'] = ['name', 'description']
67 69
68 70 kwargs['title'] = 'Location'
69 71 kwargs['suptitle'] = 'Details'
70 72
71 73 return render(request, 'location.html', kwargs)
72 74
73 75 def location_new(request):
74 76
75 77 if request.method == 'GET':
76 78 form = LocationForm()
77 79
78 80 if request.method == 'POST':
79 81 form = LocationForm(request.POST)
80 82
81 83 if form.is_valid():
82 84 form.save()
83 85 return redirect('url_locations')
84 86
85 87 kwargs = {}
86 88 kwargs['form'] = form
87 89 kwargs['title'] = 'Location'
88 90 kwargs['suptitle'] = 'New'
89 91 kwargs['button'] = 'Create'
90 92
91 93 return render(request, 'location_edit.html', kwargs)
92 94
93 95 def location_edit(request, id_loc):
94 96
95 97 location = get_object_or_404(Location, pk=id_loc)
96 98
97 99 if request.method=='GET':
98 100 form = LocationForm(instance=location)
99 101
100 102 if request.method=='POST':
101 103 form = LocationForm(request.POST, instance=location)
102 104
103 105 if form.is_valid():
104 106 form.save()
105 107 return redirect('url_locations')
106 108
107 109 kwargs = {}
108 110 kwargs['form'] = form
109 111 kwargs['title'] = 'Location'
110 112 kwargs['suptitle'] = 'Edit'
111 113 kwargs['button'] = 'Update'
112 114
113 115 return render(request, 'location_edit.html', kwargs)
114 116
115 117 def location_delete(request, id_loc):
116 118
117 119 location = get_object_or_404(Location, pk=id_loc)
118 120
119 121 if request.method=='POST':
120 122
121 123 if request.user.is_staff:
122 124 location.delete()
123 125 return redirect('url_locations')
124 126
125 127 return HttpResponse("Not enough permission to delete this object")
126 128
127 129 kwargs = {'object':location, 'loc_active':'active',
128 130 'url_cancel':'url_location', 'id_item':id_loc}
129 131
130 132 return render(request, 'item_delete.html', kwargs)
131 133
132 134 def devices(request):
133 135
134 136 devices = Device.objects.all().order_by('device_type__name')
135 137
136 138 # keys = ['id', 'device_type__name', 'name', 'ip_address']
137 139 keys = ['id', 'name', 'ip_address', 'port_address', 'device_type']
138 140
139 141 kwargs = {}
140 142 kwargs['device_keys'] = keys[1:]
141 143 kwargs['devices'] = devices#.values(*keys)
142 144 kwargs['title'] = 'Device'
143 145 kwargs['suptitle'] = 'List'
144 146 kwargs['button'] = 'New Device'
145 147
146 148 return render(request, 'devices.html', kwargs)
147 149
148 150 def device(request, id_dev):
149 151
150 152 device = get_object_or_404(Device, pk=id_dev)
151 153
152 154 kwargs = {}
153 155 kwargs['device'] = device
154 156 kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description']
155 157
156 158 kwargs['title'] = 'Device'
157 159 kwargs['suptitle'] = 'Details'
158 160
159 161 return render(request, 'device.html', kwargs)
160 162
161 163 def device_new(request):
162 164
163 165 if request.method == 'GET':
164 166 form = DeviceForm()
165 167
166 168 if request.method == 'POST':
167 169 form = DeviceForm(request.POST)
168 170
169 171 if form.is_valid():
170 172 form.save()
171 173 return redirect('url_devices')
172 174
173 175 kwargs = {}
174 176 kwargs['form'] = form
175 177 kwargs['title'] = 'Device'
176 178 kwargs['suptitle'] = 'New'
177 179 kwargs['button'] = 'Create'
178 180
179 181 return render(request, 'device_edit.html', kwargs)
180 182
181 183 def device_edit(request, id_dev):
182 184
183 185 device = get_object_or_404(Device, pk=id_dev)
184 186
185 187 if request.method=='GET':
186 188 form = DeviceForm(instance=device)
187 189
188 190 if request.method=='POST':
189 191 form = DeviceForm(request.POST, instance=device)
190 192
191 193 if form.is_valid():
192 194 form.save()
193 195 return redirect('url_devices')
194 196
195 197 kwargs = {}
196 198 kwargs['form'] = form
197 199 kwargs['title'] = 'Device'
198 200 kwargs['suptitle'] = 'Edit'
199 201 kwargs['button'] = 'Update'
200 202
201 203 return render(request, 'device_edit.html', kwargs)
202 204
203 205 def device_delete(request, id_dev):
204 206
205 207 device = get_object_or_404(Device, pk=id_dev)
206 208
207 209 if request.method=='POST':
208 210
209 211 if request.user.is_staff:
210 212 device.delete()
211 213 return redirect('url_devices')
212 214
213 215 return HttpResponse("Not enough permission to delete this object")
214 216
215 217 kwargs = {'object':device, 'dev_active':'active',
216 218 'url_cancel':'url_device', 'id_item':id_dev}
217 219
218 220 return render(request, 'item_delete.html', kwargs)
219 221
220 222 def campaigns(request):
221 223
222 224 campaigns = Campaign.objects.all().order_by('start_date')
223 225
224 226 keys = ['id', 'name', 'start_date', 'end_date']
225 227
226 228 kwargs = {}
227 229 kwargs['campaign_keys'] = keys[1:]
228 230 kwargs['campaigns'] = campaigns#.values(*keys)
229 231 kwargs['title'] = 'Campaign'
230 232 kwargs['suptitle'] = 'List'
231 233 kwargs['button'] = 'New Campaign'
232 234
233 235 return render(request, 'campaigns.html', kwargs)
234 236
235 237 def campaign(request, id_camp):
236 238
237 239 campaign = get_object_or_404(Campaign, pk=id_camp)
238 experiments = Experiment.objects.filter(campaign=campaign)
239
240 #experiments = Experiment.objects.filter(campaign=campaign)
240 241 form = CampaignForm(instance=campaign)
241 242
242 243 kwargs = {}
243 244 kwargs['campaign'] = campaign
244 245 kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description']
245 246
246 247 keys = ['id', 'name', 'start_time', 'end_time']
247 248
248 249 kwargs['experiment_keys'] = keys[1:]
249 kwargs['experiments'] = experiments.values(*keys)
250 #kwargs['experiments'] = experiments.values(*keys)
250 251
251 252 kwargs['title'] = 'Campaign'
252 253 kwargs['suptitle'] = 'Details'
253 254
254 255 kwargs['form'] = form
255 256 kwargs['button'] = 'Add Experiment'
256 257
257 258 return render(request, 'campaign.html', kwargs)
258 259
259 260 def campaign_new(request):
260 261
261 262 if request.method == 'GET':
262 263 form = CampaignForm()
263 264
264 265 if request.method == 'POST':
265 266 form = CampaignForm(request.POST)
266 267
267 268 if form.is_valid():
268 269 campaign = form.save()
269 270 return redirect('url_campaign', id_camp=campaign.id)
270 271
271 272 kwargs = {}
272 273 kwargs['form'] = form
273 274 kwargs['title'] = 'Campaign'
274 275 kwargs['suptitle'] = 'New'
275 276 kwargs['button'] = 'Create'
276 277
277 278 return render(request, 'campaign_edit.html', kwargs)
278 279
279 280 def campaign_edit(request, id_camp):
280 281
281 282 campaign = get_object_or_404(Campaign, pk=id_camp)
282 283
283 284 if request.method=='GET':
284 285 form = CampaignForm(instance=campaign)
285 286
286 287 if request.method=='POST':
287 288 form = CampaignForm(request.POST, instance=campaign)
288 289
289 290 if form.is_valid():
290 291 form.save()
291 292 return redirect('url_campaign', id_camp=id_camp)
292 293
293 294 kwargs = {}
294 295 kwargs['form'] = form
295 296 kwargs['title'] = 'Campaign'
296 297 kwargs['suptitle'] = 'Edit'
297 298 kwargs['button'] = 'Update'
298 299
299 300 return render(request, 'campaign_edit.html', kwargs)
300 301
301 302 def campaign_delete(request, id_camp):
302 303
303 304 campaign = get_object_or_404(Campaign, pk=id_camp)
304 305
305 306 if request.method=='POST':
306 307 if request.user.is_staff:
307 308 campaign.delete()
308 309 return redirect('url_campaigns')
309 310
310 311 return HttpResponse("Not enough permission to delete this object")
311 312
312 313 kwargs = {'object':campaign, 'camp_active':'active',
313 314 'url_cancel':'url_campaign', 'id_item':id_camp}
314 315
315 316 return render(request, 'item_delete.html', kwargs)
316 317
317 318 def experiments(request):
318 319
319 320 experiment_list = Experiment.objects.all().order_by('campaign')
320 321
321 322 keys = ['id', 'name', 'start_time', 'end_time', 'campaign']
322 323
323 324 kwargs = {}
324 325
325 326 kwargs['experiment_keys'] = keys[1:]
326 327 kwargs['experiments'] = experiment_list#.values(*keys)
327 328
328 329 kwargs['title'] = 'Experiment'
329 330 kwargs['suptitle'] = 'List'
330 331 kwargs['button'] = 'New Experiment'
331 332
332 333 return render(request, 'experiments.html', kwargs)
333 334
334 335 def experiment(request, id_exp):
335 336
336 337 experiment = get_object_or_404(Experiment, pk=id_exp)
337 338
338 339 experiments = Experiment.objects.filter(campaign=experiment.campaign)
339 340 configurations = Configuration.objects.filter(experiment=experiment, type=0)
340 341
341 342 kwargs = {}
342 343
343 344 exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time']
344 345 conf_keys = ['id', 'device__name', 'device__device_type', 'device__ip_address', 'device__port_address']
345 346
346 347 conf_labels = ['id', 'device__name', 'device_type', 'ip_address', 'port_address']
347 348
348 349 kwargs['experiment_keys'] = exp_keys[1:]
349 350 kwargs['experiment'] = experiment
350 351
351 352 kwargs['experiments'] = experiments.values(*exp_keys)
352 353
353 354 kwargs['configuration_labels'] = conf_labels[1:]
354 355 kwargs['configuration_keys'] = conf_keys[1:]
355 356 kwargs['configurations'] = configurations #.values(*conf_keys)
356 357
357 358 kwargs['title'] = 'Experiment'
358 359 kwargs['suptitle'] = 'Details'
359 360
360 361 kwargs['button'] = 'Add Configuration'
361 362
362 363 return render(request, 'experiment.html', kwargs)
363 364
364 365 def experiment_new(request, id_camp=0):
365 366
366 367 if request.method == 'GET':
367 368 form = ExperimentForm(initial={'campaign':id_camp})
368 369
369 370 if request.method == 'POST':
370 371 form = ExperimentForm(request.POST, initial={'campaign':id_camp})
371 372
372 373 if form.is_valid():
373 374 experiment = form.save()
374 375 return redirect('url_experiment', id_exp=experiment.id)
375 376
376 377 kwargs = {}
377 378 kwargs['form'] = form
378 379 kwargs['title'] = 'Experiment'
379 380 kwargs['suptitle'] = 'New'
380 381 kwargs['button'] = 'Create'
381 382
382 383 return render(request, 'experiment_edit.html', kwargs)
383 384
384 385 def experiment_edit(request, id_exp):
385 386
386 387 experiment = get_object_or_404(Experiment, pk=id_exp)
387 388
388 389 if request.method == 'GET':
389 390 form = ExperimentForm(instance=experiment)
390 391
391 392 if request.method=='POST':
392 393 form = ExperimentForm(request.POST, instance=experiment)
393 394
394 395 if form.is_valid():
395 396 experiment = form.save()
396 397 return redirect('url_experiment', id_exp=experiment.id)
397 398
398 399 kwargs = {}
399 400 kwargs['form'] = form
400 401 kwargs['title'] = 'Experiment'
401 402 kwargs['suptitle'] = 'Edit'
402 403 kwargs['button'] = 'Update'
403 404
404 405 return render(request, 'experiment_edit.html', kwargs)
405 406
406 407 def experiment_delete(request, id_exp):
407 408
408 409 experiment = get_object_or_404(Experiment, pk=id_exp)
409 410
410 411 if request.method=='POST':
411 412 if request.user.is_staff:
412 413 id_camp = experiment.campaign.id
413 414 experiment.delete()
414 415 return redirect('url_campaign', id_camp=id_camp)
415 416
416 417 return HttpResponse("Not enough permission to delete this object")
417 418
418 419 kwargs = {'object':experiment, 'exp_active':'active',
419 420 'url_cancel':'url_experiment', 'id_item':id_exp}
420 421
421 422 return render(request, 'item_delete.html', kwargs)
422 423
423 424 def dev_confs(request):
424 425
425 426 configurations = Configuration.objects.all().order_by('type', 'device__device_type', 'experiment')
426 427
427 428 # keys = ['id', 'device__device_type__name', 'device__name', 'experiment__campaign__name', 'experiment__name']
428 429
429 430 keys = ['id', 'device', 'experiment', 'type', 'programmed_date']
430 431
431 432 kwargs = {}
432 433
433 434 kwargs['configuration_keys'] = keys[1:]
434 435 kwargs['configurations'] = configurations#.values(*keys)
435 436
436 437 kwargs['title'] = 'Configuration'
437 438 kwargs['suptitle'] = 'List'
438 439 kwargs['button'] = 'New Configuration'
439 440
440 441 return render(request, 'dev_confs.html', kwargs)
441 442
442 443 def dev_conf(request, id_conf):
443 444
444 445 conf = get_object_or_404(Configuration, pk=id_conf)
445 446
446 447 DevConfModel = CONF_MODELS[conf.device.device_type.name]
447 448 dev_conf = DevConfModel.objects.get(pk=id_conf)
448 449
449 450 kwargs = {}
450 451 kwargs['dev_conf'] = dev_conf
451 452 kwargs['dev_conf_keys'] = ['name', 'experiment', 'device']
452 453
453 454 kwargs['title'] = 'Configuration'
454 455 kwargs['suptitle'] = 'Details'
455 456
456 457 kwargs['button'] = 'Edit Configuration'
457 458
458 459 ###### SIDEBAR ######
459 460 kwargs.update(sidebar(conf))
460 461
461 462 return render(request, 'dev_conf.html', kwargs)
462 463
463 464 def dev_conf_new(request, id_exp=0):
464 465
465 466 if request.method == 'GET':
466 467 form = ConfigurationForm(initial={'experiment':id_exp})
467 468
468 469 if request.method == 'POST':
469 470 experiment = Experiment.objects.get(pk=request.POST['experiment'])
470 471 device = Device.objects.get(pk=request.POST['device'])
471 472
472 473 DevConfForm = CONF_FORMS[device.device_type.name]
473 474
474 475 form = DevConfForm(request.POST, initial={'experiment':experiment.id})
475 476
476 477 if form.is_valid():
477 478 dev_conf = form.save()
478 479
479 480 return redirect('url_experiment', id_exp=experiment.id)
480 481
481 482 kwargs = {}
482 483 kwargs['form'] = form
483 484 kwargs['title'] = 'Configuration'
484 485 kwargs['suptitle'] = 'New'
485 486 kwargs['button'] = 'Create'
486 487
487 488 return render(request, 'dev_conf_edit.html', kwargs)
488 489
489 490 def dev_conf_edit(request, id_conf):
490 491
491 492 conf = get_object_or_404(Configuration, pk=id_conf)
492 493
493 494 DevConfModel = CONF_MODELS[conf.device.device_type.name]
494 495 DevConfForm = CONF_FORMS[conf.device.device_type.name]
495 496
496 497 dev_conf = DevConfModel.objects.get(pk=id_conf)
497 498
498 499 if request.method=='GET':
499 500 form = DevConfForm(instance=dev_conf)
500 501
501 502 if request.method=='POST':
502 503 form = DevConfForm(request.POST, instance=dev_conf)
503 504
504 505 if form.is_valid():
505 506 form.save()
506 507 return redirect('url_dev_conf', id_conf=id_conf)
507 508
508 509 kwargs = {}
509 510 kwargs['form'] = form
510 511 kwargs['title'] = 'Device Configuration'
511 512 kwargs['suptitle'] = 'Edit'
512 513 kwargs['button'] = 'Update'
513 514
514 515 ###### SIDEBAR ######
515 516 kwargs.update(sidebar(conf))
516 517
517 518 return render(request, 'dev_conf_edit.html', kwargs)
518 519
519 520 def dev_conf_read(request, id_conf):
520 521
521 522 conf = get_object_or_404(Configuration, pk=id_conf)
522 523
523 524 messages.error(request, "Read View not implemented yet")
524 525
525 526 return redirect('url_dev_conf', id_conf=conf.id)
526 527
527 528 def dev_conf_write(request, id_conf):
528 529
529 530 conf = get_object_or_404(Configuration, pk=id_conf)
530 531
531 532 messages.error(request, "Write View not implemented yet")
532 533
533 534 return redirect('url_dev_conf', id_conf=conf.id)
534 535
535 536 def dev_conf_import(request, id_conf):
536 537
537 538 conf = get_object_or_404(Configuration, pk=id_conf)
538 539
539 540 messages.error(request, "Import View not implemented yet")
540 541
541 542 return redirect('url_dev_conf', id_conf=conf.id)
542 543
543 544 def dev_conf_export(request, id_conf):
544 545
545 546 conf = get_object_or_404(Configuration, pk=id_conf)
546 547
547 548 messages.error(request, "Export View not implemented yet")
548 549
549 550 return redirect('url_dev_conf', id_conf=conf.id)
550 551
551 552 def dev_conf_delete(request, id_conf):
552 553
553 554 conf = get_object_or_404(Configuration, pk=id_conf)
554 555
555 556 if request.method=='POST':
556 557 if request.user.is_staff:
557 558 id_exp = conf.experiment.id
558 559 conf.delete()
559 560 return redirect('url_experiment', id_exp=id_exp)
560 561
561 562 return HttpResponse("Not enough permission to delete this object")
562 563
563 564 kwargs = {'object':conf, 'conf_active':'active',
564 565 'url_cancel':'url_dev_conf', 'id_item':id_conf}
565 566
566 567 ###### SIDEBAR ######
567 568 kwargs.update(sidebar(conf))
568 569
569 570 return render(request, 'item_delete.html', kwargs)
570 571
571 572 def sidebar(conf):
572 573
573 574 experiments = Experiment.objects.filter(campaign=conf.experiment.campaign)
574 575 configurations = Configuration.objects.filter(experiment=conf.experiment, type=0)
575 576
576 577 exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time']
577 578 conf_keys = ['id', 'device']
578 579
579 580 kwargs = {}
580 581
581 582 kwargs['dev_conf'] = conf
582 583
583 584 kwargs['experiment_keys'] = exp_keys[1:]
584 585 kwargs['experiments'] = experiments.values(*exp_keys)
585 586
586 587 kwargs['configuration_keys'] = conf_keys[1:]
587 588 kwargs['configurations'] = configurations #.values(*conf_keys)
588 589
589 590 return kwargs
590 591
591 592
592 def operation(request):
593 pass
594
595
593 def operation(request, id_camp=None):
594
595 today = datetime.today()
596
597 if id_camp==None:
598 id_camp = Campaign.objects.filter(start_date__month=today.month).filter(start_date__year=today.year).order_by('-start_date')[0].id
599
600 if request.method=='GET':
601 campaign = get_object_or_404(Campaign, pk = id_camp)
602 campaigns = Campaign.objects.filter(start_date__month=today.month).filter(start_date__year=today.year).order_by('-start_date')
603 form = OperationForm(initial={'campaign': id_camp})
604
605 if request.method=='POST':
606 campaign = get_object_or_404(Campaign, pk=request.POST['campaign'])
607 #id_camp = Campaign.objects.filter(start_date__month=today.month).filter(start_date__year=today.year).order_by('-start_date')[1].id
608 form = OperationForm(request.POST, initial={'campaign':campaign.name})
609 if form.is_valid():
610 return redirect('url_operation', id_camp=campaign.id)
611
612 radars = Radar.objects.filter(campaign = campaign)
613 experiments = [Experiment.objects.filter(radar=radar) for radar in radars] #zip(radars, [Experiment.objects.filter(radar=radar) for radar in radars])
614
615 kwargs = {}
616 #---Campaign
617 kwargs['campaign'] = campaign
618 kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description']
619 #---Experimet
620 keys = ['id', 'name', 'start_time', 'end_time', 'radar']
621 kwargs['experiment_keys'] = keys[1:]
622 kwargs['experiments'] = experiments
623 #---Radar
624 kwargs['radars'] = radars
625 #---Else
626 kwargs['title'] = 'Operation'
627 kwargs['suptitle'] = campaign.name
628 kwargs['form'] = form
629 kwargs['button'] = '...'
630
631 return render(request, 'operation.html', kwargs) No newline at end of file
@@ -1,123 +1,123
1 1 """
2 2 Django settings for radarsys project.
3 3
4 4 Generated by 'django-admin startproject' using Django 1.8.6.
5 5
6 6 For more information on this file, see
7 7 https://docs.djangoproject.com/en/1.8/topics/settings/
8 8
9 9 For the full list of settings and their values, see
10 10 https://docs.djangoproject.com/en/1.8/ref/settings/
11 11 """
12 12
13 13 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
14 14 import os
15 15
16 16 BASE_DIR = os.path.dirname(os.path.abspath(__file__))
17 17
18 18 # Quick-start development settings - unsuitable for production
19 19 # See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
20 20
21 21 # SECURITY WARNING: keep the secret key used in production secret!
22 22 SECRET_KEY = 'xshb$k5fc-+j16)cvyffj&9u__0q3$l!hieh#+tbzqg)*f^km0'
23 23
24 24 # SECURITY WARNING: don't run with debug turned on in production!
25 25 DEBUG = True
26 26
27 27 ALLOWED_HOSTS = []
28 28
29 29 # Application definition
30 30
31 31 INSTALLED_APPS = (
32 32 'django.contrib.admin',
33 33 'django.contrib.auth',
34 34 'django.contrib.contenttypes',
35 35 'django.contrib.sessions',
36 36 'django.contrib.messages',
37 37 'django.contrib.staticfiles',
38 38 'bootstrap3',
39 39 'polymorphic',
40 40 'apps.accounts',
41 41 'apps.main',
42 42 'apps.misc',
43 43 'apps.rc',
44 44 'apps.dds',
45 45 'apps.cgs',
46 46 'apps.jars',
47 47 'apps.usrp',
48 48 'apps.abs',
49 49 )
50 50
51 51 MIDDLEWARE_CLASSES = (
52 52 'django.contrib.sessions.middleware.SessionMiddleware',
53 53 'django.middleware.common.CommonMiddleware',
54 54 'django.middleware.csrf.CsrfViewMiddleware',
55 55 'django.contrib.auth.middleware.AuthenticationMiddleware',
56 56 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
57 57 'django.contrib.messages.middleware.MessageMiddleware',
58 58 'django.middleware.clickjacking.XFrameOptionsMiddleware',
59 59 'django.middleware.security.SecurityMiddleware',
60 60 )
61 61
62 62 ROOT_URLCONF = 'radarsys.urls'
63 63
64 64 TEMPLATES = [
65 65 {
66 66 'BACKEND': 'django.template.backends.django.DjangoTemplates',
67 67 'DIRS': [os.path.join(BASE_DIR, "templates").replace('\\', '/'),],
68 68 'APP_DIRS': True,
69 69 'OPTIONS': {
70 70 'context_processors': [
71 71 'django.template.context_processors.debug',
72 72 'django.template.context_processors.request',
73 73 'django.contrib.auth.context_processors.auth',
74 74 'django.contrib.messages.context_processors.messages',
75 75 ],
76 76 },
77 77 },
78 78 ]
79 79
80 80 WSGI_APPLICATION = 'radarsys.wsgi.application'
81 81
82 82
83 83 # Database
84 84 # https://docs.djangoproject.com/en/1.8/ref/settings/#databases
85 85
86 86 DATABASES = {
87 87 'default': {
88 88 'ENGINE': 'django.db.backends.mysql',
89 89 'NAME': 'radarsys',
90 90 'USER': 'developer',
91 91 'PASSWORD': 'idi2015',
92 92 }
93 93 }
94 94
95 95
96 96 # Internationalization
97 97 # https://docs.djangoproject.com/en/1.8/topics/i18n/
98 98
99 99 LANGUAGE_CODE = 'en-us'
100 100
101 TIME_ZONE = 'UTC'
101 TIME_ZONE = None
102 102
103 103 USE_I18N = True
104 104
105 105 USE_L10N = True
106 106
107 USE_TZ = True
107 USE_TZ = False
108 108
109 109 # Static files (CSS, JavaScript, Images)
110 110 # https://docs.djangoproject.com/en/1.8/howto/static-files/
111 111
112 112 STATIC_URL = '/static/'
113 113 STATIC_ROOT = '/var/www/html/static/'
114 114
115 115 STATICFILES_DIRS = (
116 116 os.path.join(BASE_DIR, 'apps', 'main', 'static'),
117 117
118 118 )
119 119
120 120 STATICFILES_FINDERS = (
121 121 'django.contrib.staticfiles.finders.FileSystemFinder',
122 122 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
123 123 )
@@ -1,32 +1,31
1 1 """radarsys URL Configuration
2 2
3 3 The `urlpatterns` list routes URLs to views. For more information please see:
4 4 https://docs.djangoproject.com/en/1.8/topics/http/urls/
5 5 Examples:
6 6 Function views
7 7 1. Add an import: from my_app import views
8 8 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
9 9 Class-based views
10 10 1. Add an import: from other_app.views import Home
11 11 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
12 12 Including another URLconf
13 13 1. Add an import: from blog import urls as blog_urls
14 14 2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls))
15 15 """
16 16 from django.conf.urls import include, url
17 17 from django.contrib import admin
18 18
19 19 urlpatterns = [
20 url(r'^$', 'apps.main.views.index', name='index'),
21 url(r'^operation/', 'apps.main.views.operation', name='url_operation'),
20 url(r'^$', 'apps.main.views.index', name='index'),
22 21 url(r'^admin/', include(admin.site.urls)),
23 22 url(r'^accounts/', include('apps.accounts.urls')),
24 23 url(r'^', include('apps.main.urls')),
25 24 url(r'^rc/', include('apps.rc.urls')),
26 25 url(r'^dds/', include('apps.dds.urls')),
27 26 url(r'^cgs/', include('apps.cgs.urls')),
28 27 url(r'^jars/', include('apps.jars.urls')),
29 28 url(r'^usrp/', include('apps.usrp.urls')),
30 29 url(r'^abs/', include('apps.abs.urls')),
31 30 url(r'^misc/', include('apps.misc.urls')),
32 31 ]
General Comments 0
You need to be logged in to leave comments. Login now