@@ -1,53 +1,51 | |||
|
1 | 1 | from django.shortcuts import render, render_to_response |
|
2 | 2 | from django.template import RequestContext |
|
3 | 3 | |
|
4 | 4 | from .forms import CGSConfigurationForm |
|
5 | 5 | from .models import CGSConfiguration |
|
6 | 6 | from apps.main.models import Device |
|
7 | 7 | # Create your views here. |
|
8 | 8 | |
|
9 | 9 | def configurate_frequencies(request, id=0): |
|
10 | 10 | |
|
11 | 11 | if id: |
|
12 | 12 | conf = CGSConfiguration.objects.get(pk=id) |
|
13 | 13 | devices = Device.objects.filter(configuration__experiment=conf.experiment) |
|
14 | 14 | devices = devices.values('configuration__id', 'device_type__name') |
|
15 | 15 | for device in devices: |
|
16 | 16 | if device['device_type__name']=='cgs': |
|
17 | 17 | device['active'] = 'active' |
|
18 | 18 | break |
|
19 | 19 | |
|
20 | 20 | device = device |
|
21 | 21 | form = CGSConfigurationForm(instance=conf) |
|
22 | 22 | else: |
|
23 | 23 | form = CGSConfigurationForm() |
|
24 | 24 | |
|
25 | 25 | data = { |
|
26 | 26 | 'form': form, |
|
27 | 27 | 'device': device, |
|
28 | 28 | 'devices':devices, |
|
29 | 29 | 'title': ('YAP'), |
|
30 | 'experiment': conf.experiment, | |
|
31 | ||
|
32 | 30 | } |
|
33 | 31 | |
|
34 | 32 | data['dev_conf'] = conf |
|
35 | 33 | data['dev_conf_keys'] = ['experiment', 'device'] |
|
36 | 34 | |
|
37 | 35 | if request.method == 'POST': |
|
38 | 36 | form = CGSConfigurationForm(request.POST) #, initial={'purchase_request':purchase_request}) |
|
39 | 37 | if form.is_valid(): |
|
40 | 38 | instance = form.save(commit=False) |
|
41 | 39 | #if 'quote' in request.FILES: |
|
42 | 40 | # instance.quoe = request.FILES['quote'] |
|
43 | 41 | instance.save() |
|
44 | 42 | form.save_m2m() |
|
45 | 43 | msg = _(u'The frequencies have been activated successfully.') |
|
46 | 44 | messages.success(request, msg, fail_silently=True) |
|
47 | 45 | #return redirect(purchase_request.get_absolute_url()) |
|
48 | 46 | else: |
|
49 | 47 | form = CGSConfigurationForm() |
|
50 | 48 | |
|
51 | 49 | return render(request, 'cgs_conf.html', data) |
|
52 | 50 | |
|
53 | 51 |
@@ -1,31 +1,32 | |||
|
1 | 1 | from django.shortcuts import render_to_response |
|
2 | 2 | from django.template import RequestContext |
|
3 | 3 | |
|
4 | 4 | from apps.main.models import Device |
|
5 | 5 | from .models import JARSConfiguration |
|
6 | 6 | from .forms import JARSConfigurationForm |
|
7 | 7 | # Create your views here. |
|
8 | 8 | |
|
9 | 9 | def jars_config(request, id): |
|
10 | 10 | |
|
11 | 11 | if id: |
|
12 | 12 | conf = JARSConfiguration.objects.get(pk=id) |
|
13 | 13 | devices = Device.objects.filter(configuration__experiment=conf.experiment) |
|
14 | 14 | devices = devices.values('configuration__id', 'device_type__name') |
|
15 | 15 | for device in devices: |
|
16 | 16 | if device['device_type__name']=='jars': |
|
17 | 17 | device['active'] = 'active' |
|
18 | 18 | form = JARSConfigurationForm(instance=conf) |
|
19 | 19 | else: |
|
20 | 20 | form = JARSConfigurationForm() |
|
21 | 21 | |
|
22 | 22 | kwargs = { |
|
23 | 23 | 'form': form, |
|
24 | 24 | 'devices':devices, |
|
25 | 'dev_conf': conf | |
|
25 | 26 | } |
|
26 | 27 | |
|
27 | 28 | return render_to_response('jars.html', kwargs, context_instance=RequestContext(request)) |
|
28 | 29 | |
|
29 | 30 | |
|
30 | 31 | |
|
31 | 32 |
@@ -1,96 +1,83 | |||
|
1 | 1 | {% extends "base.html" %} |
|
2 | 2 | {% load bootstrap3 %} |
|
3 | 3 | {% load static %} |
|
4 | 4 | {% load main_tags %} |
|
5 | 5 | {% block extra-head %} |
|
6 | 6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> |
|
7 | 7 | {% endblock %} |
|
8 | 8 | |
|
9 | 9 | {% block camp-active %}active{% endblock %} |
|
10 | 10 | |
|
11 | 11 | {% block content-title %}{{title}}{% endblock %} |
|
12 | 12 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
13 | 13 | |
|
14 | 14 | {% block content %} |
|
15 | 15 | <table class="table table-bordered"> |
|
16 | 16 | {% for key in campaign_keys %} |
|
17 | 17 | <tr><th>{{key|title}}</th><td>{{campaign|attr:key}}</td></tr> |
|
18 | 18 | {% endfor %} |
|
19 | 19 | </table> |
|
20 | <hr> | |
|
20 | <button class="btn btn-primary pull-right" id="bt_edit_campaign">Edit Campaign</button> | |
|
21 | <br></br> | |
|
22 | <br></br> | |
|
21 | 23 | |
|
22 | 24 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> |
|
23 | <div class="panel panel-default"> | |
|
24 | <div class="panel-heading" role="tab" id="headingOne"> | |
|
25 | <h4 class="panel-title"> | |
|
26 | <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne"> | |
|
27 | Edit Campaign Details | |
|
28 | </a> | |
|
29 | </h4> | |
|
30 | </div> | |
|
31 | <div id="collapseOne" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne"> | |
|
32 | <div class="panel-body"> | |
|
33 | <form class="form" method="post" action="{% url 'url_edit_campaign' campaign.id %}"> | |
|
34 | {% csrf_token %} | |
|
35 | {% bootstrap_form form layout='horizontal' size='medium' %} | |
|
36 | <div style="clear: both;"></div> | |
|
37 | <br> | |
|
38 | <button type="submit" class="btn btn-primary pull-right" id="bt_update">Update</button> | |
|
39 | </form> | |
|
40 | </div> | |
|
41 | </div> | |
|
42 | </div> | |
|
25 | ||
|
43 | 26 | <div class="panel panel-default"> |
|
44 | 27 | <div class="panel-heading" role="tab" id="headingTwo"> |
|
45 | 28 | <h4 class="panel-title"> |
|
46 | 29 | <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo"> |
|
47 | 30 | Experiment List |
|
48 | 31 | </a> |
|
49 | 32 | </h4> |
|
50 | 33 | </div> |
|
51 | 34 | |
|
52 | 35 | <div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> |
|
53 | 36 | <div class="panel-body"> |
|
54 | 37 | <table class="table table-hover"> |
|
55 | 38 | <tr> |
|
56 | 39 | <th>#</th> |
|
57 | 40 | {% for header in experiment_keys %} |
|
58 | 41 | <th>{{ header|title }}</th> |
|
59 | 42 | {% endfor%} |
|
60 | 43 | </tr> |
|
61 | 44 | {% for item in experiments %} |
|
62 | 45 | <tr class="clickable-row" data-href="{% url 'url_experiment' item.id %}"> |
|
63 | 46 | <td>{{ forloop.counter }}</td> |
|
64 | 47 | {% for key in experiment_keys %} |
|
65 | 48 | <td>{{ item|attr:key }}</td> |
|
66 | 49 | {% endfor %} |
|
67 | 50 | </tr> |
|
68 | 51 | {% endfor %} |
|
69 | 52 | </table> |
|
70 | 53 | <button class="btn btn-primary pull-right" id="bt_add">{{button}}</button> |
|
71 | 54 | </div> |
|
72 | 55 | </div> |
|
73 | 56 | </div> |
|
74 | 57 | </div> |
|
75 | 58 | {% endblock %} |
|
76 | 59 | |
|
77 | 60 | {% block sidebar%} |
|
78 | 61 | {% include "sidebar_devices.html" %} |
|
79 | 62 | {% endblock %} |
|
80 | 63 | |
|
81 | 64 | {% block extra-js%} |
|
82 | 65 | <script src="{% static 'js/moment.min.js' %}"></script> |
|
83 | 66 | <script src="{% static 'js/bootstrap-datetimepicker.min.js' %}"></script> |
|
84 | 67 | <script type="text/javascript"> |
|
85 | 68 | $('.input-group.date').datetimepicker({"format": "YYYY-MM-DD HH:mm"}); |
|
86 | 69 | |
|
87 | $("#bt_add").click(function() { | |
|
88 | document.location = "{% url 'url_add_experiment' campaign.id%}"; | |
|
89 | }); | |
|
90 | ||
|
91 | 70 | $(".clickable-row").click(function() { |
|
92 | 71 | document.location = $(this).data("href"); |
|
93 | 72 | }); |
|
73 | ||
|
74 | $("#bt_edit_campaign").click(function() { | |
|
75 | document.location = "{% url 'url_edit_campaign' campaign.id%}"; | |
|
76 | }); | |
|
77 | ||
|
78 | $("#bt_add").click(function() { | |
|
79 | document.location = "{% url 'url_add_experiment' campaign.id%}"; | |
|
80 | }); | |
|
94 | 81 | |
|
95 | 82 | </script> |
|
96 | 83 | {% endblock %} No newline at end of file |
@@ -1,54 +1,49 | |||
|
1 | 1 | {% extends "base.html" %} |
|
2 | 2 | {% load bootstrap3 %} |
|
3 | 3 | {% load static %} |
|
4 | 4 | {% load main_tags %} |
|
5 | {% block extra-head %} | |
|
6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> | |
|
7 | {% endblock %} | |
|
8 | 5 | |
|
9 | 6 | {% block dev-active %}active{% endblock %} |
|
10 | 7 | |
|
11 | 8 | {% block content-title %}{{title}}{% endblock %} |
|
12 | 9 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
13 | 10 | |
|
14 | 11 | {% block content %} |
|
15 | 12 | <table class="table table-hover"> |
|
16 | 13 | <tr> |
|
17 | 14 | <th>#</th> |
|
18 | 15 | {% for key in device_keys %} |
|
19 | 16 | <th>{{ key|title }}</th> |
|
20 | 17 | {% endfor%} |
|
21 | 18 | </tr> |
|
22 | 19 | {% for device in devices %} |
|
23 | 20 | <tr class="clickable-row" data-href="{% url 'url_device' device.id %}"> |
|
24 | 21 | <td>{{ forloop.counter }}</td> |
|
25 | 22 | {% for key in device_keys %} |
|
26 | 23 | <td>{{ device|attr:key }}</td> |
|
27 | 24 | {% endfor %} |
|
28 | 25 | </tr> |
|
29 | 26 | {% endfor %} |
|
30 | 27 | </table> |
|
31 | 28 | <button class="btn btn-primary pull-right" id="bt_add">{{button}}</button> |
|
32 | 29 | {% endblock %} |
|
33 | 30 | |
|
34 | 31 | {% block sidebar%} |
|
35 | 32 | {% include "sidebar_devices.html" %} |
|
36 | 33 | {% endblock %} |
|
37 | 34 | |
|
38 | 35 | {% block extra-js%} |
|
39 | 36 | <script src="{% static 'js/moment.min.js' %}"></script> |
|
40 | 37 | <script src="{% static 'js/bootstrap-datetimepicker.min.js' %}"></script> |
|
41 | 38 | <script type="text/javascript"> |
|
42 | $('.input-group.date').datetimepicker({"format": "YYYY-MM-DD HH:mm"}); | |
|
43 | $('.input-group.time').datetimepicker({"format": "HH:mm"}); | |
|
44 | 39 | |
|
45 | 40 | $("#bt_add").click(function() { |
|
46 | 41 | document.location = "{% url 'url_add_device' %}"; |
|
47 | 42 | }); |
|
48 | 43 | |
|
49 | 44 | $(".clickable-row").click(function() { |
|
50 | 45 | document.location = $(this).data("href"); |
|
51 | 46 | }); |
|
52 | 47 | |
|
53 | 48 | </script> |
|
54 | 49 | {% endblock %} No newline at end of file |
@@ -1,83 +1,83 | |||
|
1 | 1 | {% extends "base.html" %} |
|
2 | 2 | {% load bootstrap3 %} |
|
3 | 3 | {% load static %} |
|
4 | 4 | {% load main_tags %} |
|
5 | 5 | {% block extra-head %} |
|
6 | 6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> |
|
7 | 7 | {% endblock %} |
|
8 | 8 | |
|
9 | 9 | {% block exp-active %}active{% endblock %} |
|
10 | 10 | |
|
11 | 11 | {% block content-title %}{{title}}{% endblock %} |
|
12 | 12 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
13 | 13 | |
|
14 | 14 | {% block content %} |
|
15 | 15 | <table class="table table-bordered"> |
|
16 | 16 | {% for key in experiment_keys %} |
|
17 | 17 | <tr><th>{{key|title}}</th><td>{{experiment|attr:key}}</td></tr> |
|
18 | 18 | {% endfor %} |
|
19 | 19 | </table> |
|
20 | 20 | <button class="btn btn-primary pull-right" id="bt_edit_experiment">Edit Experiment</button> |
|
21 | 21 | <br></br> |
|
22 | 22 | <br></br> |
|
23 | 23 | |
|
24 | 24 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> |
|
25 | 25 | |
|
26 | 26 | <div class="panel panel-default"> |
|
27 | 27 | <div class="panel-heading" role="tab" id="headingTwo"> |
|
28 | 28 | <h4 class="panel-title"> |
|
29 | 29 | <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseThree"> |
|
30 | Experiment's Devices | |
|
30 | Device Configurations | |
|
31 | 31 | </a> |
|
32 | 32 | </h4> |
|
33 | 33 | </div> |
|
34 | 34 | <div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> |
|
35 | 35 | <div class="panel-body"> |
|
36 | 36 | <table class="table table-hover"> |
|
37 | 37 | <tr> |
|
38 | 38 | <th>#</th> |
|
39 | 39 | {% for key in configuration_keys %} |
|
40 | 40 | <th>{{ key|title }}</th> |
|
41 | 41 | {% endfor%} |
|
42 | 42 | </tr> |
|
43 | 43 | {% for item in configurations %} |
|
44 | 44 | <tr class="clickable-row" data-href="/{{item.device__device_type__name}}/{{item.id}}/"> |
|
45 | 45 | <td>{{ forloop.counter }}</td> |
|
46 | 46 | {% for key in configuration_keys %} |
|
47 | 47 | <td>{{ item|attr:key }}</td> |
|
48 | 48 | {% endfor %} |
|
49 | 49 | </tr> |
|
50 | 50 | {% endfor %} |
|
51 | 51 | </table> |
|
52 | 52 | <button class="btn btn-primary pull-right" id="bt_add_conf">{{button}}</button> |
|
53 | 53 | </div> |
|
54 | 54 | </div> |
|
55 | 55 | </div> |
|
56 | 56 | </div> |
|
57 | 57 | {% endblock %} |
|
58 | 58 | |
|
59 | 59 | {% block sidebar%} |
|
60 | 60 | {% include "sidebar_devices.html" %} |
|
61 | 61 | {% endblock %} |
|
62 | 62 | |
|
63 | 63 | {% block extra-js%} |
|
64 | 64 | |
|
65 | 65 | <script src="{% static 'js/moment.min.js' %}"></script> |
|
66 | 66 | <script src="{% static 'js/bootstrap-datetimepicker.min.js' %}"></script> |
|
67 | 67 | <script type="text/javascript"> |
|
68 | 68 | $('.input-group.date').datetimepicker({"format": "YYYY-MM-DD HH:mm"}); |
|
69 | 69 | |
|
70 | 70 | $(".clickable-row").click(function() { |
|
71 | 71 | document.location = $(this).data("href"); |
|
72 | 72 | }); |
|
73 | 73 | |
|
74 | 74 | $("#bt_edit_experiment").click(function() { |
|
75 | 75 | document.location = "{% url 'url_edit_experiment' experiment.id%}"; |
|
76 | 76 | }); |
|
77 | 77 | |
|
78 | 78 | $("#bt_add_conf").click(function() { |
|
79 | 79 | document.location = "{% url 'url_add_dev_conf' experiment.id%}"; |
|
80 | 80 | }); |
|
81 | 81 | |
|
82 | 82 | </script> |
|
83 | 83 | {% endblock %} No newline at end of file |
@@ -1,23 +1,62 | |||
|
1 | 1 | {% if experiment %} |
|
2 | <div class="panel panel-default"> | |
|
3 | <div class="panel-heading"> | |
|
4 |
<h |
|
|
5 | </div> | |
|
6 | <div class="list-group"> | |
|
7 |
<a href="{% url 'url_ |
|
|
8 | </div> | |
|
9 | </div> | |
|
2 | <div class="panel panel-default"> | |
|
3 | <div class="panel-heading"> | |
|
4 | <h4>Campaign</h4> | |
|
5 | </div> | |
|
6 | <div class="list-group"> | |
|
7 | <a href="{% url 'url_campaign' experiment.campaign.id %}" class="list-group-item active" >{{ experiment.campaign.name }}</a> | |
|
8 | </div> | |
|
9 | </div> | |
|
10 | ||
|
11 | <div class="panel panel-default"> | |
|
12 | <div class="panel-heading"> | |
|
13 | <h4>Experiment</h4> | |
|
14 | </div> | |
|
15 | <div class="list-group"> | |
|
16 | <a href="{% url 'url_experiment' experiment.id %}" class="list-group-item active" >{{ experiment.name }}</a> | |
|
17 | </div> | |
|
18 | </div> | |
|
19 | ||
|
20 | {% if configurations %} | |
|
21 | <div class="panel panel-default"> | |
|
22 | <div class="panel-heading"> | |
|
23 | <h4>Device Configurations</h4> | |
|
24 | </div> | |
|
25 | <div class="list-group"> | |
|
26 | {% for item in configurations %} | |
|
27 | <a href="/{{item.device__device_type__name}}/{{item.id}}" class="list-group-item {{item.active}}">{{item.device__name}}</a> | |
|
28 | {% endfor %} | |
|
29 | </div> | |
|
30 | </div> | |
|
31 | {% endif %} | |
|
10 | 32 | {% endif %} |
|
11 | 33 | |
|
12 |
{% if dev |
|
|
13 | <div class="panel panel-default"> | |
|
14 | <div class="panel-heading"> | |
|
15 | <h3>Devices</h3> | |
|
16 | </div> | |
|
17 | <div class="list-group"> | |
|
18 | {% for item in devices %} | |
|
19 | <a href="/{{item.device_type__name}}/{{item.configuration__id}}/" class="list-group-item {{item.active}}">{{item.device_type__alias}}</a> | |
|
20 | {% endfor %} | |
|
21 | </div> | |
|
22 | </div> | |
|
23 | {% endif %} No newline at end of file | |
|
34 | {% if dev_conf %} | |
|
35 | <div class="panel panel-default"> | |
|
36 | <div class="panel-heading"> | |
|
37 | <h4>Campaign</h4> | |
|
38 | </div> | |
|
39 | <div class="list-group"> | |
|
40 | <a href="{% url 'url_campaign' dev_conf.experiment.campaign.id %}" class="list-group-item active" >{{ dev_conf.experiment.campaign.name }}</a> | |
|
41 | </div> | |
|
42 | </div> | |
|
43 | ||
|
44 | <div class="panel panel-default"> | |
|
45 | <div class="panel-heading"> | |
|
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> | |
|
52 | ||
|
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 | ||
|
62 | {% endif %} |
@@ -1,494 +1,494 | |||
|
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) | |
|
220 | # campaign = Campaign.objects.get(pk = experiment.campaign.id) | |
|
221 | 221 | configurations = Configuration.objects.filter(experiment=experiment) |
|
222 | 222 | |
|
223 | 223 | # form = ExperimentForm(instance=experiment) |
|
224 | 224 | |
|
225 | 225 | kwargs = {} |
|
226 | 226 | |
|
227 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
|
228 | kwargs['campaign'] = campaign | |
|
227 | # kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
|
228 | # kwargs['campaign'] = campaign | |
|
229 | 229 | |
|
230 | 230 | kwargs['experiment_keys'] = ['campaign', 'name', 'start_time', 'end_time'] |
|
231 | 231 | kwargs['experiment'] = experiment |
|
232 | 232 | |
|
233 | 233 | keys = ['id', 'device__name', 'device__device_type__name', 'device__ip_address'] |
|
234 | 234 | |
|
235 | 235 | kwargs['configuration_keys'] = keys[1:] |
|
236 | 236 | kwargs['configurations'] = configurations.values(*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 |
kwargs['title'] = 'Configuration |
|
|
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 | 321 | return render(request, 'dev_conf.html', kwargs) |
|
322 | 322 | |
|
323 | 323 | def add_dev_conf(request, id_exp=0): |
|
324 | 324 | |
|
325 | 325 | if request.method == 'GET': |
|
326 | 326 | form = ConfigurationForm(initial={'experiment':id_exp}) |
|
327 | 327 | |
|
328 | 328 | if request.method == 'POST': |
|
329 | 329 | form = ConfigurationForm(request.POST) |
|
330 | 330 | |
|
331 | 331 | if form.is_valid(): |
|
332 | 332 | experiment = Experiment.objects.get(pk=request.POST['experiment']) |
|
333 | 333 | device = Device.objects.get(pk=request.POST['device']) |
|
334 | 334 | |
|
335 | 335 | exp_devices = Device.objects.filter(configuration__experiment=experiment) |
|
336 | 336 | |
|
337 | 337 | if device.id not in exp_devices.values('id',): |
|
338 | 338 | |
|
339 | 339 | DevConfModel = CONF_MODELS[device.device_type.name] |
|
340 | 340 | conf = DevConfModel(experiment=experiment, device=device) |
|
341 | 341 | conf.save() |
|
342 | 342 | |
|
343 | 343 | return redirect('url_experiment', id_exp=experiment.id) |
|
344 | 344 | |
|
345 | 345 | kwargs = {} |
|
346 | 346 | kwargs['form'] = form |
|
347 | 347 | kwargs['title'] = 'Configuration' |
|
348 | 348 | kwargs['suptitle'] = 'New' |
|
349 | 349 | kwargs['button'] = 'Create' |
|
350 | 350 | |
|
351 | 351 | return render(request, 'dev_conf_edit.html', kwargs) |
|
352 | 352 | |
|
353 | 353 | def edit_dev_conf(request, id_conf): |
|
354 | 354 | |
|
355 | 355 | conf = Configuration.objects.get(pk=id_conf) |
|
356 | 356 | |
|
357 | 357 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
358 | 358 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
359 | 359 | |
|
360 | 360 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
361 | 361 | |
|
362 | 362 | if request.method=='GET': |
|
363 | 363 | form = DevConfForm(instance=dev_conf) |
|
364 | 364 | |
|
365 | 365 | if request.method=='POST': |
|
366 | 366 | form = DevConfForm(request.POST, instance=dev_conf) |
|
367 | 367 | |
|
368 | 368 | if form.is_valid(): |
|
369 | 369 | form.save() |
|
370 | 370 | return redirect('url_dev_conf', id_conf=id_conf) |
|
371 | 371 | |
|
372 | 372 | kwargs = {} |
|
373 | 373 | kwargs['form'] = form |
|
374 | 374 | kwargs['title'] = 'Device Configuration' |
|
375 | 375 | kwargs['suptitle'] = 'Edit' |
|
376 | 376 | kwargs['button'] = 'Update' |
|
377 | 377 | |
|
378 | 378 | return render(request, 'dev_conf_edit.html', kwargs) |
|
379 | 379 | |
|
380 | 380 | |
|
381 | 381 | # def experiment(request, id_exp=0, id_dev_type=0): |
|
382 | 382 | # kwargs = {} |
|
383 | 383 | # if id_exp: |
|
384 | 384 | # experiment = Experiment.objects.get(pk=id_exp) |
|
385 | 385 | # devices = Configuration.objects.filter(configuration__experiment=experiment) |
|
386 | 386 | # kwargs['experiment'] = experiment |
|
387 | 387 | # kwargs['experiment_keys'] = ['campaign', 'name', 'start_time', 'end_time'] |
|
388 | 388 | # |
|
389 | 389 | # form = ExperimentForm(instance=experiment) |
|
390 | 390 | # |
|
391 | 391 | # if id_dev_type: |
|
392 | 392 | # subform = DeviceTypeForm(initial={'device_type':id_dev_type}) |
|
393 | 393 | # kwargs['keys'] = ['ip_address'] |
|
394 | 394 | # keys = ['id']+kwargs['keys'] |
|
395 | 395 | # kwargs['items'] = Device.objects.filter(device_type=id_dev_type).values(*keys) |
|
396 | 396 | # else: |
|
397 | 397 | # subform = DeviceTypeForm() |
|
398 | 398 | # |
|
399 | 399 | # kwargs['form'] = form |
|
400 | 400 | # kwargs['subform'] = subform |
|
401 | 401 | # kwargs['device_keys'] = ['device_type__name', 'ip_address'] |
|
402 | 402 | # kwargs['devices'] = devices.values('device_type__name', 'ip_address', 'configuration__id') |
|
403 | 403 | # kwargs['suptitle'] = 'Detail' |
|
404 | 404 | # else: |
|
405 | 405 | # experiments = Experiment.objects.all().order_by('start_time') |
|
406 | 406 | # kwargs['keys'] = ['name', 'start_time', 'end_time'] |
|
407 | 407 | # keys = ['id']+kwargs['keys'] |
|
408 | 408 | # kwargs['items'] = experiments.values(*keys) |
|
409 | 409 | # kwargs['suptitle'] = 'List' |
|
410 | 410 | # kwargs['button'] = 'Add Experiment' |
|
411 | 411 | # |
|
412 | 412 | # kwargs['id_dev_type'] = id_dev_type |
|
413 | 413 | # kwargs['id_exp'] = id_exp |
|
414 | 414 | # return render_to_response("experiment.html", kwargs, context_instance=RequestContext(request)) |
|
415 | 415 | |
|
416 | 416 | # def edit_experiment(request, id_exp): |
|
417 | 417 | # if request.method=='POST': |
|
418 | 418 | # experiment = Experiment.objects.get(pk=id_exp) |
|
419 | 419 | # form = ExperimentForm(request.POST, instance=experiment) |
|
420 | 420 | # if form.is_valid(): |
|
421 | 421 | # form.save() |
|
422 | 422 | # return redirect('experiment', id_exp=id_exp) |
|
423 | 423 | |
|
424 | 424 | # def experiment_add_device(request, id_exp): |
|
425 | 425 | # if request.method=='POST': |
|
426 | 426 | # experiment = Experiment.objects.get(pk=id_exp) |
|
427 | 427 | # |
|
428 | 428 | # exp_devices = Device.objects.filter(configuration__experiment=experiment) |
|
429 | 429 | # |
|
430 | 430 | # device = Device.objects.get(pk=request.POST['device']) |
|
431 | 431 | # |
|
432 | 432 | # if device.id in exp_devices.values('id',): |
|
433 | 433 | # return redirect('experiment', id_exp=id_exp) |
|
434 | 434 | # |
|
435 | 435 | # model = MODELS[device.device_type.alias] |
|
436 | 436 | # conf = model(experiment=experiment, device=device) |
|
437 | 437 | # conf.save() |
|
438 | 438 | # return redirect('experiment', id_exp=id_exp) |
|
439 | 439 | |
|
440 | 440 | # def add_experiment(request): |
|
441 | 441 | # |
|
442 | 442 | # kwargs = {} |
|
443 | 443 | # if request.method == 'POST': |
|
444 | 444 | # form = ExperimentForm(request.POST) |
|
445 | 445 | # if form.is_valid(): |
|
446 | 446 | # experiment = form.save() |
|
447 | 447 | # return redirect('experiment', id_exp=experiment.id) |
|
448 | 448 | # else: |
|
449 | 449 | # form = ExperimentForm() |
|
450 | 450 | # kwargs['form_new'] = form |
|
451 | 451 | # kwargs['title'] = 'Experiment' |
|
452 | 452 | # kwargs['suptitle'] = 'New' |
|
453 | 453 | # kwargs['id_exp'] = 0 |
|
454 | 454 | # return render_to_response("experiment.html", kwargs, context_instance=RequestContext(request)) |
|
455 | 455 | |
|
456 | 456 | # def device(request, id_dev=0): |
|
457 | 457 | # kwargs = {} |
|
458 | 458 | # if id_dev: |
|
459 | 459 | # device = Device.objects.get(pk=id_dev) |
|
460 | 460 | # kwargs['form'] = DeviceForm(instance=device) |
|
461 | 461 | # kwargs['action'] = 'edit/' |
|
462 | 462 | # kwargs['button'] = 'Update' |
|
463 | 463 | # kwargs['suptitle'] = 'Detail' |
|
464 | 464 | # else: |
|
465 | 465 | # devices = Device.objects.all() |
|
466 | 466 | # kwargs['keys'] = ['device_type__name', 'ip_address'] |
|
467 | 467 | # keys = ['id']+kwargs['keys'] |
|
468 | 468 | # kwargs['items'] = devices.values(*keys) |
|
469 | 469 | # kwargs['suptitle'] = 'List' |
|
470 | 470 | # kwargs['button'] = 'Add Device' |
|
471 | 471 | # return render_to_response("device.html", kwargs, context_instance=RequestContext(request)) |
|
472 | 472 | # |
|
473 | 473 | # def edit_device(request, id_dev): |
|
474 | 474 | # if request.method=='POST': |
|
475 | 475 | # device = Device.objects.get(pk=id_dev) |
|
476 | 476 | # form = DeviceForm(request.POST, instance=device) |
|
477 | 477 | # if form.is_valid(): |
|
478 | 478 | # form.save() |
|
479 | 479 | # return redirect('devices') |
|
480 | 480 | # |
|
481 | 481 | # def add_device(request): |
|
482 | 482 | # kwargs = {} |
|
483 | 483 | # if request.method == 'POST': |
|
484 | 484 | # form = DeviceForm(request.POST) |
|
485 | 485 | # if form.is_valid(): |
|
486 | 486 | # form.save() |
|
487 | 487 | # return redirect('devices') |
|
488 | 488 | # else: |
|
489 | 489 | # form = DeviceForm() |
|
490 | 490 | # kwargs['form'] = form |
|
491 | 491 | # kwargs['button'] = 'Create' |
|
492 | 492 | # kwargs['suptitle'] = 'New' |
|
493 | 493 | # return render_to_response("device.html", kwargs, context_instance=RequestContext(request)) |
|
494 | 494 |
General Comments 0
You need to be logged in to leave comments.
Login now