@@ -50,6 +50,9 class CampaignForm(forms.ModelForm): | |||
|
50 | 50 | self.fields['end_date'].widget = DatepickerWidget(self.fields['end_date'].widget.attrs) |
|
51 | 51 | self.fields['description'].widget.attrs = {'rows': 2} |
|
52 | 52 | |
|
53 | if self.instance: | |
|
54 | self.fields['experiments'].queryset |= self.instance.experiments.all() | |
|
55 | ||
|
53 | 56 | class Meta: |
|
54 | 57 | model = Campaign |
|
55 | 58 | exclude = [''] |
@@ -149,9 +149,12 class Experiment(models.Model): | |||
|
149 | 149 | |
|
150 | 150 | class Meta: |
|
151 | 151 | db_table = 'db_experiments' |
|
152 |
ordering = ('name' |
|
|
152 | ordering = ('template', 'name') | |
|
153 | 153 | |
|
154 | 154 | def __unicode__(self): |
|
155 | if self.template: | |
|
156 | return u'%s (template)' % (self.name) | |
|
157 | else: | |
|
155 | 158 | return u'%s' % (self.name) |
|
156 | 159 | |
|
157 | 160 | @property |
@@ -206,7 +209,7 class Experiment(models.Model): | |||
|
206 | 209 | elif self.status == 1: |
|
207 | 210 | color = "info" |
|
208 | 211 | elif self.status == 2: |
|
209 | color = "succes" | |
|
212 | color = "success" | |
|
210 | 213 | elif self.status == 3: |
|
211 | 214 | color = "warning" |
|
212 | 215 | else: |
@@ -37,7 +37,7 | |||
|
37 | 37 | <table class="table table-hover"> |
|
38 | 38 | <tr> |
|
39 | 39 | <th>#</th> |
|
40 |
{% for key in configuration_ |
|
|
40 | {% for key in configuration_keys %} | |
|
41 | 41 | <th>{{ key|title }}</th> |
|
42 | 42 | {% endfor%} |
|
43 | 43 | </tr> |
@@ -1,4 +1,4 | |||
|
1 | {% extends "base.html" %} | |
|
1 | {% extends "base_edit.html" %} | |
|
2 | 2 | {% load bootstrap3 %} |
|
3 | 3 | {% load static %} |
|
4 | 4 | {% load main_tags %} |
@@ -6,28 +6,6 | |||
|
6 | 6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> |
|
7 | 7 | {% endblock %} |
|
8 | 8 | |
|
9 | {% block exp-active %}active{% endblock %} | |
|
10 | ||
|
11 | {% block content-title %}{{title}}{% endblock %} | |
|
12 | {% block content-suptitle %}{{suptitle}}{% endblock %} | |
|
13 | ||
|
14 | {% block content %} | |
|
15 | <form class="form" method="post" action=""> | |
|
16 | {% csrf_token %} | |
|
17 | {% bootstrap_form form layout='horizontal' size='medium' %} | |
|
18 | <div style="clear: both;"></div> | |
|
19 | <br> | |
|
20 | {% if button %} | |
|
21 | <br> | |
|
22 | <button type="submit" class="btn btn-primary pull-right">{{button}}</button> | |
|
23 | {% endif %} | |
|
24 | </form> | |
|
25 | {% endblock %} | |
|
26 | ||
|
27 | {% block sidebar%} | |
|
28 | {% include "sidebar_devices.html" %} | |
|
29 | {% endblock %} | |
|
30 | ||
|
31 | 9 | {% block extra-js%} |
|
32 | 10 | <script src="{% static 'js/moment.min.js' %}"></script> |
|
33 | 11 | <script src="{% static 'js/bootstrap-datetimepicker.min.js' %}"></script> |
@@ -16,7 +16,7 def attr(instance, key): | |||
|
16 | 16 | |
|
17 | 17 | @register.filter |
|
18 | 18 | def title(s): |
|
19 | return s.replace('_', ' ').title() | |
|
19 | return s.split('__')[-1].replace('_', ' ').title() | |
|
20 | 20 | |
|
21 | 21 | @register.filter |
|
22 | 22 | def value(instance, key): |
@@ -298,8 +298,10 def campaign_new(request): | |||
|
298 | 298 | kwargs['button'] = 'Create' |
|
299 | 299 | kwargs['experiments'] = Configuration.objects.filter(experiment=request.GET['template']) |
|
300 | 300 | kwargs['experiment_keys'] = ['name', 'start_time', 'end_time'] |
|
301 |
|
|
|
302 | initial={'template':False}) | |
|
301 | camp = Campaign.objects.get(pk=request.GET['template']) | |
|
302 | form = CampaignForm(instance=camp, | |
|
303 | initial={'name':'{} [{:%Y/%m/%d}]'.format(camp.name, datetime.now()), | |
|
304 | 'template':False}) | |
|
303 | 305 | elif 'blank' in request.GET: |
|
304 | 306 | kwargs['button'] = 'Create' |
|
305 | 307 | form = CampaignForm() |
@@ -342,10 +344,27 def campaign_edit(request, id_camp): | |||
|
342 | 344 | form = CampaignForm(instance=campaign) |
|
343 | 345 | |
|
344 | 346 | if request.method=='POST': |
|
345 | form = CampaignForm(request.POST, instance=campaign) | |
|
347 | exps = campaign.experiments.all().values_list('pk', flat=True) | |
|
348 | post = request.POST.copy() | |
|
349 | new_exps = post.getlist('experiments') | |
|
350 | post.setlist('experiments', []) | |
|
351 | form = CampaignForm(post, instance=campaign) | |
|
346 | 352 | |
|
347 | 353 | if form.is_valid(): |
|
348 | form.save() | |
|
354 | camp = form.save() | |
|
355 | for id_exp in new_exps: | |
|
356 | if int(id_exp) in exps: | |
|
357 | exps.pop(id_exp) | |
|
358 | else: | |
|
359 | exp = Experiment.objects.get(pk=id_exp) | |
|
360 | if exp.template: | |
|
361 | camp.experiments.add(exp.clone(template=False)) | |
|
362 | else: | |
|
363 | camp.experiments.add(exp) | |
|
364 | ||
|
365 | for id_exp in exps: | |
|
366 | camp.experiments.remove(Experiment.objects.get(pk=id_exp)) | |
|
367 | ||
|
349 | 368 | return redirect('url_campaign', id_camp=id_camp) |
|
350 | 369 | |
|
351 | 370 | kwargs = {} |
@@ -412,17 +431,11 def experiment(request, id_exp): | |||
|
412 | 431 | |
|
413 | 432 | kwargs = {} |
|
414 | 433 | |
|
415 |
exp_keys = [' |
|
|
416 | conf_keys = ['id', 'device__name', 'device__device_type', 'device__ip_address', 'device__port_address'] | |
|
417 | ||
|
418 | conf_labels = ['id', 'device__name', 'device_type', 'ip_address', 'port_address'] | |
|
419 | ||
|
420 | kwargs['experiment_keys'] = exp_keys[1:] | |
|
434 | kwargs['experiment_keys'] = ['template', 'radar', 'name', 'start_time', 'end_time'] | |
|
421 | 435 | kwargs['experiment'] = experiment |
|
422 | 436 | |
|
423 | kwargs['configuration_labels'] = conf_labels[1:] | |
|
424 |
kwargs['configuration |
|
|
425 | kwargs['configurations'] = configurations #.values(*conf_keys) | |
|
437 | kwargs['configuration_keys'] = ['device__name', 'device__device_type', 'device__ip_address', 'device__port_address'] | |
|
438 | kwargs['configurations'] = configurations | |
|
426 | 439 | |
|
427 | 440 | kwargs['title'] = 'Experiment' |
|
428 | 441 | kwargs['suptitle'] = 'Details' |
@@ -448,8 +461,10 def experiment_new(request, id_camp=None): | |||
|
448 | 461 | kwargs['button'] = 'Create' |
|
449 | 462 | kwargs['configurations'] = Configuration.objects.filter(experiment=request.GET['template']) |
|
450 | 463 | kwargs['configuration_keys'] = ['name', 'device__name', 'device__ip_address', 'device__port_address'] |
|
451 |
|
|
|
452 | initial={'template':False}) | |
|
464 | exp=Experiment.objects.get(pk=request.GET['template']) | |
|
465 | form = ExperimentForm(instance=exp, | |
|
466 | initial={'name': '{} [{:%Y/%m/%d}]'.format(exp.name, datetime.now()), | |
|
467 | 'template': False}) | |
|
453 | 468 | elif 'blank' in request.GET: |
|
454 | 469 | kwargs['button'] = 'Create' |
|
455 | 470 | form = ExperimentForm() |
@@ -504,33 +519,36 def experiment_delete(request, id_exp): | |||
|
504 | 519 | |
|
505 | 520 | if request.method=='POST': |
|
506 | 521 | if request.user.is_staff: |
|
522 | for conf in Configuration.objects.filter(experiment=experiment): | |
|
523 | conf.delete() | |
|
507 | 524 | experiment.delete() |
|
508 | 525 | return redirect('url_experiments') |
|
509 | 526 | |
|
510 |
|
|
|
527 | messages.error(request, 'Not enough permission to delete this object') | |
|
528 | return redirect(experiment.get_absolute_url()) | |
|
511 | 529 | |
|
512 | kwargs = {'object':experiment, 'exp_active':'active', | |
|
513 | 'url_cancel':'url_experiment', 'id_item':id_exp} | |
|
530 | kwargs = { | |
|
531 | 'title': 'Delete', | |
|
532 | 'suptitle': 'Experiment', | |
|
533 | 'object': experiment, | |
|
534 | 'previous': experiment.get_absolute_url(), | |
|
535 | 'delete': True | |
|
536 | } | |
|
514 | 537 | |
|
515 |
return render(request, ' |
|
|
538 | return render(request, 'confirm.html', kwargs) | |
|
516 | 539 | |
|
517 | 540 | |
|
518 | 541 | def dev_confs(request): |
|
519 | 542 | |
|
520 | 543 | configurations = Configuration.objects.all().order_by('type', 'device__device_type', 'experiment') |
|
521 | 544 | |
|
522 | # keys = ['id', 'device__device_type__name', 'device__name', 'experiment__campaign__name', 'experiment__name'] | |
|
523 | ||
|
524 | keys = ['id', 'device', 'experiment', 'type', 'programmed_date'] | |
|
525 | ||
|
526 | 545 | kwargs = {} |
|
527 | 546 | |
|
528 | kwargs['configuration_keys'] = keys[1:] | |
|
529 |
kwargs['configurations'] = configurations |
|
|
547 | kwargs['configuration_keys'] = ['device', 'experiment', 'type', 'programmed_date'] | |
|
548 | kwargs['configurations'] = configurations | |
|
530 | 549 | |
|
531 | 550 | kwargs['title'] = 'Configuration' |
|
532 | 551 | kwargs['suptitle'] = 'List' |
|
533 | kwargs['button'] = 'New Configuration' | |
|
534 | 552 | |
|
535 | 553 | return render(request, 'dev_confs.html', kwargs) |
|
536 | 554 | |
@@ -824,16 +842,21 def dev_conf_delete(request, id_conf): | |||
|
824 | 842 | |
|
825 | 843 | if request.method=='POST': |
|
826 | 844 | if request.user.is_staff: |
|
827 | id_exp = conf.experiment.id | |
|
828 | 845 | conf.delete() |
|
829 |
return redirect('url_ |
|
|
846 | return redirect('url_dev_confs') | |
|
830 | 847 | |
|
831 |
|
|
|
848 | messages.error(request, 'Not enough permission to delete this object') | |
|
849 | return redirect(conf.get_absolute_url()) | |
|
832 | 850 | |
|
833 | kwargs = {'object':conf, 'conf_active':'active', | |
|
834 | 'url_cancel':'url_dev_conf', 'id_item':id_conf} | |
|
851 | kwargs = { | |
|
852 | 'title': 'Delete', | |
|
853 | 'suptitle': 'Experiment', | |
|
854 | 'object': conf, | |
|
855 | 'previous': conf.get_absolute_url(), | |
|
856 | 'delete': True | |
|
857 | } | |
|
835 | 858 | |
|
836 |
return render(request, ' |
|
|
859 | return render(request, 'confirm.html', kwargs) | |
|
837 | 860 | |
|
838 | 861 | |
|
839 | 862 | def sidebar(**kwargs): |
General Comments 0
You need to be logged in to leave comments.
Login now