@@ -0,0 +1,34 | |||
|
1 | {% extends "base.html" %} | |
|
2 | {% load bootstrap3 %} | |
|
3 | {% load static %} | |
|
4 | {% load main_tags %} | |
|
5 | ||
|
6 | {% block loc-active %}active{% endblock %} | |
|
7 | ||
|
8 | {% block content-title %}{{title}}{% endblock %} | |
|
9 | {% block content-suptitle %}{{suptitle}}{% endblock %} | |
|
10 | ||
|
11 | {% block content %} | |
|
12 | <table class="table table-bordered"> | |
|
13 | {% for key in location_keys %} | |
|
14 | <tr><th>{{key|title}}</th><td>{{location|attr:key}}</td></tr> | |
|
15 | {% endfor %} | |
|
16 | </table> | |
|
17 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_edit">Edit</button> | |
|
18 | <br></br> | |
|
19 | <br></br> | |
|
20 | {% endblock %} | |
|
21 | ||
|
22 | {% block sidebar%} | |
|
23 | {% include "sidebar_devices.html" %} | |
|
24 | {% endblock %} | |
|
25 | ||
|
26 | {% block extra-js%} | |
|
27 | <script type="text/javascript"> | |
|
28 | ||
|
29 | $("#bt_edit").click(function() { | |
|
30 | document.location = "{% url 'url_edit_location' location.id%}"; | |
|
31 | }); | |
|
32 | ||
|
33 | </script> | |
|
34 | {% endblock %} No newline at end of file |
@@ -0,0 +1,29 | |||
|
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 loc-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 | <button type="submit" class="btn btn-primary pull-right">{{button}}</button> | |
|
21 | </form> | |
|
22 | {% endblock %} | |
|
23 | ||
|
24 | {% block sidebar%} | |
|
25 | {% include "sidebar_devices.html" %} | |
|
26 | {% endblock %} | |
|
27 | ||
|
28 | {% block extra-js%} | |
|
29 | {% endblock %} No newline at end of file |
@@ -0,0 +1,47 | |||
|
1 | {% extends "base.html" %} | |
|
2 | {% load bootstrap3 %} | |
|
3 | {% load static %} | |
|
4 | {% load main_tags %} | |
|
5 | ||
|
6 | {% block loc-active %}active{% endblock %} | |
|
7 | ||
|
8 | {% block content-title %}{{title}}{% endblock %} | |
|
9 | {% block content-suptitle %}{{suptitle}}{% endblock %} | |
|
10 | ||
|
11 | {% block content %} | |
|
12 | <table class="table table-hover"> | |
|
13 | <tr> | |
|
14 | <th>#</th> | |
|
15 | {% for key in location_keys %} | |
|
16 | <th>{{ key|title }}</th> | |
|
17 | {% endfor%} | |
|
18 | </tr> | |
|
19 | {% for location in locations %} | |
|
20 | <tr class="clickable-row" data-href="{% url 'url_location' location.id %}"> | |
|
21 | <td>{{ forloop.counter }}</td> | |
|
22 | {% for key in location_keys %} | |
|
23 | <td>{{ location|attr:key }}</td> | |
|
24 | {% endfor %} | |
|
25 | </tr> | |
|
26 | {% endfor %} | |
|
27 | </table> | |
|
28 | <button class="btn btn-primary pull-right" id="bt_add">{{button}}</button> | |
|
29 | {% endblock %} | |
|
30 | ||
|
31 | {% block sidebar%} | |
|
32 | {% include "sidebar_devices.html" %} | |
|
33 | {% endblock %} | |
|
34 | ||
|
35 | {% block extra-js%} | |
|
36 | <script type="text/javascript"> | |
|
37 | ||
|
38 | $("#bt_add").click(function() { | |
|
39 | document.location = "{% url 'url_add_location' %}"; | |
|
40 | }); | |
|
41 | ||
|
42 | $(".clickable-row").click(function() { | |
|
43 | document.location = $(this).data("href"); | |
|
44 | }); | |
|
45 | ||
|
46 | </script> | |
|
47 | {% endblock %} No newline at end of file |
@@ -1,7 +1,7 | |||
|
1 | 1 | from django import forms |
|
2 | 2 | from django.utils.safestring import mark_safe |
|
3 | 3 | |
|
4 | from .models import DeviceType, Device, Experiment, Campaign, Configuration | |
|
4 | from .models import DeviceType, Device, Experiment, Campaign, Configuration, Location | |
|
5 | 5 | |
|
6 | 6 | def add_empty_choice(choices, pos=0, label='-----'): |
|
7 | 7 | if len(choices)>0: |
@@ -45,6 +45,11 class ExperimentForm(forms.ModelForm): | |||
|
45 | 45 | model = Experiment |
|
46 | 46 | fields = ['campaign', 'name', 'start_time', 'end_time'] |
|
47 | 47 | |
|
48 | class LocationForm(forms.ModelForm): | |
|
49 | class Meta: | |
|
50 | model = Location | |
|
51 | exclude = [''] | |
|
52 | ||
|
48 | 53 | class DeviceForm(forms.ModelForm): |
|
49 | 54 | class Meta: |
|
50 | 55 | model = Device |
@@ -57,4 +62,3 class ConfigurationForm(forms.ModelForm): | |||
|
57 | 62 | |
|
58 | 63 | class DeviceTypeForm(forms.Form): |
|
59 | 64 | device_type = forms.ChoiceField(choices=add_empty_choice(DeviceType.objects.all().order_by('name').values_list('id', 'name'))) |
|
60 |
@@ -1,9 +1,14 | |||
|
1 | from itertools import chain | |
|
2 | 1 |
|
|
3 | 2 | from polymorphic import PolymorphicModel |
|
4 | 3 | |
|
5 | 4 | from django.core.urlresolvers import reverse |
|
6 | 5 | |
|
6 | CONF_STATES = ( | |
|
7 | (0, 'Disconnected'), | |
|
8 | (1, 'Connected'), | |
|
9 | (1, 'Running'), | |
|
10 | ) | |
|
11 | ||
|
7 | 12 | CONF_TYPES = ( |
|
8 | 13 | (0, 'Active'), |
|
9 | 14 | (1, 'Historical'), |
@@ -27,15 +32,22 DEV_TYPES = ( | |||
|
27 | 32 | ) |
|
28 | 33 | |
|
29 | 34 | # Create your models here. |
|
35 | ||
|
36 | class Location(models.Model): | |
|
37 | ||
|
38 | name = models.CharField(max_length = 30) | |
|
39 | description = models.TextField(blank=True, null=True) | |
|
40 | ||
|
41 | class Meta: | |
|
42 | db_table = 'db_location' | |
|
43 | ||
|
44 | def __unicode__(self): | |
|
45 | return u'%s' % self.name | |
|
30 | 46 | |
|
31 | 47 | class DeviceType(models.Model): |
|
32 | 48 | |
|
33 | 49 | name = models.CharField(max_length = 10, choices = DEV_TYPES, default = 'rc') |
|
34 | ||
|
35 | 50 | description = models.TextField(blank=True, null=True) |
|
36 | ||
|
37 | # info = models.TextField(blank=True, null=True) | |
|
38 | # status = models.PositiveSmallIntegerField(default=1, choices=STATES) | |
|
39 | 51 | |
|
40 | 52 | class Meta: |
|
41 | 53 | db_table = 'db_device_types' |
@@ -46,15 +58,13 class DeviceType(models.Model): | |||
|
46 | 58 | class Device(models.Model): |
|
47 | 59 | |
|
48 | 60 | device_type = models.ForeignKey(DeviceType) |
|
61 | # location = models.ForeignKey(Location) | |
|
62 | ||
|
49 | 63 | name = models.CharField(max_length=40, default='') |
|
50 | 64 | ip_address = models.GenericIPAddressField(protocol='IPv4', default='0.0.0.0') |
|
51 | 65 | port_address = models.PositiveSmallIntegerField(default=2000) |
|
52 | 66 | description = models.TextField(blank=True, null=True) |
|
53 | 67 | status = models.PositiveSmallIntegerField(default=0, choices=DEV_STATES) |
|
54 | ||
|
55 | # serial_number = models.CharField(max_length=40, default='') | |
|
56 | # mac_address = models.CharField(max_length = 20, null=True, blank=True) | |
|
57 | ||
|
58 | 68 | |
|
59 | 69 | class Meta: |
|
60 | 70 | db_table = 'db_devices' |
@@ -94,8 +104,12 class Configuration(PolymorphicModel): | |||
|
94 | 104 | |
|
95 | 105 | experiment = models.ForeignKey(Experiment) |
|
96 | 106 | device = models.ForeignKey(Device) |
|
107 | ||
|
108 | status = models.PositiveSmallIntegerField(default=0, choices=CONF_STATES) | |
|
97 | 109 | type = models.PositiveSmallIntegerField(default=0, choices=CONF_TYPES) |
|
98 | 110 | |
|
111 | name = models.CharField(max_length=40, default='') | |
|
112 | ||
|
99 | 113 | created_date = models.DateTimeField(auto_now_add=True) |
|
100 | 114 | programmed_date = models.DateTimeField(auto_now=True) |
|
101 | 115 |
@@ -37,13 +37,15 | |||
|
37 | 37 | </div> |
|
38 | 38 | <div class="collapse navbar-collapse" id="navigationbar"> |
|
39 | 39 | <ul class="nav navbar-nav"> |
|
40 | <li class=" dropdown {% block dev-active %}{% endblock %}"><a href="{% url 'url_devices'%}">Devices</a> | |
|
41 | </li> | |
|
42 | 40 | <li class=" dropdown {% block camp-active %}{% endblock %}"><a href="{% url 'url_campaigns'%}">Campaigns</a> |
|
43 | 41 | </li> |
|
44 | 42 | <li class=" dropdown {% block exp-active %}{% endblock %}"><a href="{% url 'url_experiments'%}">Experiments</a> |
|
45 | 43 | </li> |
|
46 |
<li class=" dropdown {% block conf-active %}{% endblock %}"><a href="{% url 'url_dev_confs'%}"> |
|
|
44 | <li class=" dropdown {% block conf-active %}{% endblock %}"><a href="{% url 'url_dev_confs'%}">Configurations</a> | |
|
45 | </li> | |
|
46 | <li class=" dropdown {% block dev-active %}{% endblock %}"><a href="{% url 'url_devices'%}">Devices</a> | |
|
47 | </li> | |
|
48 | <li class=" dropdown {% block loc-active %}{% endblock %}"><a href="{% url 'url_locations'%}">Locations</a> | |
|
47 | 49 | </li> |
|
48 | 50 | </ul> |
|
49 | 51 | <ul class="nav navbar-nav navbar-right"> |
@@ -11,9 +11,9 | |||
|
11 | 11 | {% block content %} |
|
12 | 12 | |
|
13 | 13 | {% if form.is_multipart %} |
|
14 | <form class="form" enctype="multipart/form-data" method="post" action=""> | |
|
14 | <form class="form" enctype="multipart/form-data" method="post" action="{{action}}"> | |
|
15 | 15 | {% else %} |
|
16 | <form class="form" method="post" action=""> | |
|
16 | <form class="form" method="post" action="{{action}}"> | |
|
17 | 17 | {% endif %} |
|
18 | 18 | |
|
19 | 19 | {% csrf_token %} |
@@ -37,15 +37,15 | |||
|
37 | 37 | <table class="table table-hover"> |
|
38 | 38 | <tr> |
|
39 | 39 | <th>#</th> |
|
40 |
{% for key in configuration_ |
|
|
40 | {% for key in configuration_labels %} | |
|
41 | 41 | <th>{{ key|title }}</th> |
|
42 | 42 | {% endfor%} |
|
43 | 43 | </tr> |
|
44 | 44 | {% for item in configurations %} |
|
45 |
<tr class="clickable-row" data-href=" |
|
|
45 | <tr class="clickable-row" data-href="{{item.get_absolute_url}}"> | |
|
46 | 46 | <td>{{ forloop.counter }}</td> |
|
47 | 47 | {% for key in configuration_keys %} |
|
48 |
<td>{{ item| |
|
|
48 | <td>{{ item|value:key }}</td> | |
|
49 | 49 | {% endfor %} |
|
50 | 50 | </tr> |
|
51 | 51 | {% endfor %} |
@@ -52,7 +52,7 | |||
|
52 | 52 | </div> |
|
53 | 53 | <div class="list-group"> |
|
54 | 54 | {% for item in configurations %} |
|
55 |
<a href=" |
|
|
55 | <a href="{{item.get_absolute_url}}" class="list-group-item {{item.active}}">{{item.device.name}}</a> | |
|
56 | 56 | {% endfor %} |
|
57 | 57 | </div> |
|
58 | 58 | </div> |
@@ -90,7 +90,7 | |||
|
90 | 90 | </div> |
|
91 | 91 | <div class="list-group"> |
|
92 | 92 | {% for item in configurations %} |
|
93 |
<a href=" |
|
|
93 | <a href="{{item.get_absolute_url}}" class="list-group-item {%if item.id == dev_conf.id%}active{%endif%}">{{item.device.name}}</a> | |
|
94 | 94 | {% endfor %} |
|
95 | 95 | </div> |
|
96 | 96 | </div> |
@@ -17,6 +17,17 def attr(instance, key): | |||
|
17 | 17 | def title(s): |
|
18 | 18 | return s.replace('_', ' ').title() |
|
19 | 19 | |
|
20 | @register.filter | |
|
21 | def value(instance, key): | |
|
22 | ||
|
23 | item = instance | |
|
24 | for my_key in key.split("__"): | |
|
25 | print "TP Value", item, my_key | |
|
26 | item = attr(item, my_key) | |
|
27 | ||
|
28 | print item | |
|
29 | return item | |
|
30 | ||
|
20 | 31 | @register.simple_tag |
|
21 | 32 | def get_verbose_field_name(instance, field_name): |
|
22 | 33 | """ |
@@ -1,6 +1,12 | |||
|
1 | 1 | from django.conf.urls import url |
|
2 | 2 | |
|
3 | 3 | urlpatterns = ( |
|
4 | url(r'^location/new/$', 'apps.main.views.location_new', name='url_add_location'), | |
|
5 | url(r'^location/$', 'apps.main.views.locations', name='url_locations'), | |
|
6 | url(r'^location/(?P<id_loc>-?\d+)/$', 'apps.main.views.location', name='url_location'), | |
|
7 | url(r'^location/(?P<id_loc>-?\d+)/edit/$', 'apps.main.views.location_edit', name='url_edit_location'), | |
|
8 | url(r'^location/(?P<id_loc>-?\d+)/delete/$', 'apps.main.views.location_delete', name='url_delete_location'), | |
|
9 | ||
|
4 | 10 | url(r'^device/new/$', 'apps.main.views.device_new', name='url_add_device'), |
|
5 | 11 | url(r'^device/$', 'apps.main.views.devices', name='url_devices'), |
|
6 | 12 | url(r'^device/(?P<id_dev>-?\d+)/$', 'apps.main.views.device', name='url_device'), |
@@ -24,4 +30,5 urlpatterns = ( | |||
|
24 | 30 | url(r'^dev_conf/(?P<id_conf>-?\d+)/$', 'apps.main.views.dev_conf', name='url_dev_conf'), |
|
25 | 31 | url(r'^dev_conf/(?P<id_conf>-?\d+)/edit/$', 'apps.main.views.dev_conf_edit', name='url_edit_dev_conf'), |
|
26 | 32 | url(r'^dev_conf/(?P<id_conf>-?\d+)/delete/$', 'apps.main.views.dev_conf_delete', name='url_delete_dev_conf'), |
|
33 | ||
|
27 | 34 | ) |
@@ -1,7 +1,7 | |||
|
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 | |
|
4 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm | |
|
5 | 5 | from apps.cgs.forms import CGSConfigurationForm |
|
6 | 6 | from apps.jars.forms import JARSConfigurationForm |
|
7 | 7 | from apps.usrp.forms import USRPConfigurationForm |
@@ -9,7 +9,7 from apps.abs.forms import ABSConfigurationForm | |||
|
9 | 9 | from apps.rc.forms import RCConfigurationForm |
|
10 | 10 | from apps.dds.forms import DDSConfigurationForm |
|
11 | 11 | |
|
12 | from .models import Campaign, Experiment, Device, Configuration | |
|
12 | from .models import Campaign, Experiment, Device, Configuration, Location | |
|
13 | 13 | from apps.cgs.models import CGSConfiguration |
|
14 | 14 | from apps.jars.models import JARSConfiguration |
|
15 | 15 | from apps.usrp.models import USRPConfiguration |
@@ -42,12 +42,99 def index(request): | |||
|
42 | 42 | |
|
43 | 43 | return render(request, 'index.html', kwargs) |
|
44 | 44 | |
|
45 | def locations(request): | |
|
46 | ||
|
47 | locations = Location.objects.all().order_by('name') | |
|
48 | ||
|
49 | keys = ['id', 'name', 'description'] | |
|
50 | ||
|
51 | kwargs = {} | |
|
52 | kwargs['location_keys'] = keys[1:] | |
|
53 | kwargs['locations'] = locations | |
|
54 | kwargs['title'] = 'Location' | |
|
55 | kwargs['suptitle'] = 'List' | |
|
56 | kwargs['button'] = 'New Location' | |
|
57 | ||
|
58 | return render(request, 'locations.html', kwargs) | |
|
59 | ||
|
60 | def location(request, id_loc): | |
|
61 | ||
|
62 | location = get_object_or_404(Location, pk=id_loc) | |
|
63 | ||
|
64 | kwargs = {} | |
|
65 | kwargs['location'] = location | |
|
66 | kwargs['location_keys'] = ['name', 'description'] | |
|
67 | ||
|
68 | kwargs['title'] = 'Location' | |
|
69 | kwargs['suptitle'] = 'Details' | |
|
70 | ||
|
71 | return render(request, 'location.html', kwargs) | |
|
72 | ||
|
73 | def location_new(request): | |
|
74 | ||
|
75 | if request.method == 'GET': | |
|
76 | form = LocationForm() | |
|
77 | ||
|
78 | if request.method == 'POST': | |
|
79 | form = LocationForm(request.POST) | |
|
80 | ||
|
81 | if form.is_valid(): | |
|
82 | form.save() | |
|
83 | return redirect('url_locations') | |
|
84 | ||
|
85 | kwargs = {} | |
|
86 | kwargs['form'] = form | |
|
87 | kwargs['title'] = 'Location' | |
|
88 | kwargs['suptitle'] = 'New' | |
|
89 | kwargs['button'] = 'Create' | |
|
90 | ||
|
91 | return render(request, 'location_edit.html', kwargs) | |
|
92 | ||
|
93 | def location_edit(request, id_loc): | |
|
94 | ||
|
95 | location = get_object_or_404(Location, pk=id_loc) | |
|
96 | ||
|
97 | if request.method=='GET': | |
|
98 | form = LocationForm(instance=location) | |
|
99 | ||
|
100 | if request.method=='POST': | |
|
101 | form = LocationForm(request.POST, instance=location) | |
|
102 | ||
|
103 | if form.is_valid(): | |
|
104 | form.save() | |
|
105 | return redirect('url_locations') | |
|
106 | ||
|
107 | kwargs = {} | |
|
108 | kwargs['form'] = form | |
|
109 | kwargs['title'] = 'Location' | |
|
110 | kwargs['suptitle'] = 'Edit' | |
|
111 | kwargs['button'] = 'Update' | |
|
112 | ||
|
113 | return render(request, 'location_edit.html', kwargs) | |
|
114 | ||
|
115 | def location_delete(request, id_loc): | |
|
116 | ||
|
117 | location = get_object_or_404(Location, pk=id_loc) | |
|
118 | ||
|
119 | if request.method=='POST': | |
|
120 | ||
|
121 | if request.user.is_staff: | |
|
122 | location.delete() | |
|
123 | return redirect('url_locations') | |
|
124 | ||
|
125 | return HttpResponse("Not enough permission to delete this object") | |
|
126 | ||
|
127 | kwargs = {'object':location, 'loc_active':'active', | |
|
128 | 'url_cancel':'url_location', 'id_item':id_loc} | |
|
129 | ||
|
130 | return render(request, 'item_delete.html', kwargs) | |
|
131 | ||
|
45 | 132 | def devices(request): |
|
46 | 133 | |
|
47 | 134 | devices = Device.objects.all().order_by('device_type__name') |
|
48 | 135 | |
|
49 | 136 | # keys = ['id', 'device_type__name', 'name', 'ip_address'] |
|
50 | keys = ['id', 'name', 'ip_address', 'device_type'] | |
|
137 | keys = ['id', 'name', 'ip_address', 'port_address', 'device_type'] | |
|
51 | 138 | |
|
52 | 139 | kwargs = {} |
|
53 | 140 | kwargs['device_keys'] = keys[1:] |
@@ -69,8 +156,6 def device(request, id_dev): | |||
|
69 | 156 | kwargs['title'] = 'Device' |
|
70 | 157 | kwargs['suptitle'] = 'Details' |
|
71 | 158 | |
|
72 | kwargs['button'] = 'Add Device' | |
|
73 | ||
|
74 | 159 | return render(request, 'device.html', kwargs) |
|
75 | 160 | |
|
76 | 161 | def device_new(request): |
@@ -251,21 +336,23 def experiment(request, id_exp): | |||
|
251 | 336 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
252 | 337 | |
|
253 | 338 | experiments = Experiment.objects.filter(campaign=experiment.campaign) |
|
254 | configurations = Configuration.objects.filter(experiment=experiment) | |
|
339 | configurations = Configuration.objects.filter(experiment=experiment, type=0) | |
|
255 | 340 | |
|
256 | 341 | kwargs = {} |
|
257 | 342 | |
|
258 | 343 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] |
|
259 |
conf_keys = ['id', 'device__name', 'device__device_type |
|
|
344 | conf_keys = ['id', 'device__name', 'device__device_type', 'device__ip_address', 'device__port_address'] | |
|
260 | 345 | |
|
346 | conf_labels = ['id', 'device__name', 'device_type', 'ip_address', 'port_address'] | |
|
261 | 347 | |
|
262 | 348 | kwargs['experiment_keys'] = exp_keys[1:] |
|
263 | 349 | kwargs['experiment'] = experiment |
|
264 | 350 | |
|
265 | 351 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
266 | 352 | |
|
353 | kwargs['configuration_labels'] = conf_labels[1:] | |
|
267 | 354 | kwargs['configuration_keys'] = conf_keys[1:] |
|
268 | kwargs['configurations'] = configurations.values(*conf_keys) | |
|
355 | kwargs['configurations'] = configurations #.values(*conf_keys) | |
|
269 | 356 | |
|
270 | 357 | kwargs['title'] = 'Experiment' |
|
271 | 358 | kwargs['suptitle'] = 'Details' |
@@ -335,7 +422,7 def experiment_delete(request, id_exp): | |||
|
335 | 422 | |
|
336 | 423 | def dev_confs(request): |
|
337 | 424 | |
|
338 | configurations = Configuration.objects.all().order_by('experiment') | |
|
425 | configurations = Configuration.objects.all().order_by('type', 'device__device_type', 'experiment') | |
|
339 | 426 | |
|
340 | 427 | # keys = ['id', 'device__device_type__name', 'device__name', 'experiment__campaign__name', 'experiment__name'] |
|
341 | 428 | |
@@ -385,14 +472,15 def dev_conf_new(request, id_exp=0): | |||
|
385 | 472 | experiment = Experiment.objects.get(pk=request.POST['experiment']) |
|
386 | 473 | device = Device.objects.get(pk=request.POST['device']) |
|
387 | 474 | |
|
388 |
exp_devices = Device.objects.filter(configuration__experiment=experiment |
|
|
475 | exp_devices = Device.objects.filter(configuration__experiment=experiment, | |
|
476 | configuration__type=0) | |
|
389 | 477 | |
|
390 | 478 | if device.id not in exp_devices.values('id',): |
|
391 | 479 | |
|
392 | 480 | DevConfModel = CONF_MODELS[device.device_type.name] |
|
393 | 481 | conf = DevConfModel(experiment=experiment, device=device) |
|
394 | 482 | conf.save() |
|
395 | ||
|
483 | ||
|
396 | 484 | return redirect('url_experiment', id_exp=experiment.id) |
|
397 | 485 | |
|
398 | 486 | kwargs = {} |
@@ -401,9 +489,6 def dev_conf_new(request, id_exp=0): | |||
|
401 | 489 | kwargs['suptitle'] = 'New' |
|
402 | 490 | kwargs['button'] = 'Create' |
|
403 | 491 | |
|
404 | ###### SIDEBAR ###### | |
|
405 | kwargs.update(sidebar(conf)) | |
|
406 | ||
|
407 | 492 | return render(request, 'dev_conf_edit.html', kwargs) |
|
408 | 493 | |
|
409 | 494 | def dev_conf_edit(request, id_conf): |
@@ -494,7 +579,7 def sidebar(conf): | |||
|
494 | 579 | configurations = Configuration.objects.filter(experiment=conf.experiment, type=0) |
|
495 | 580 | |
|
496 | 581 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] |
|
497 | conf_keys = ['id', 'device__name', 'device__device_type__name', 'device__ip_address'] | |
|
582 | conf_keys = ['id', 'device'] | |
|
498 | 583 | |
|
499 | 584 | kwargs = {} |
|
500 | 585 | |
@@ -504,6 +589,6 def sidebar(conf): | |||
|
504 | 589 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
505 | 590 | |
|
506 | 591 | kwargs['configuration_keys'] = conf_keys[1:] |
|
507 | kwargs['configurations'] = configurations.values(*conf_keys) | |
|
592 | kwargs['configurations'] = configurations #.values(*conf_keys) | |
|
508 | 593 | |
|
509 | 594 | return kwargs No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now