@@ -0,0 +1,18 | |||||
|
1 | {% extends "dev_conf_edit.html" %} | |||
|
2 | ||||
|
3 | {% block content %} | |||
|
4 | <form class="form" method="post" action=""> | |||
|
5 | {% csrf_token %} | |||
|
6 | ||||
|
7 | <div class="panel-group" id="div_lines" role="tablist" aria-multiselectable="true"> | |||
|
8 | {% include "rc_lines.html" %} | |||
|
9 | </div> | |||
|
10 | ||||
|
11 | <div style="clear: both;"></div> | |||
|
12 | <br> | |||
|
13 | <div class="pull-right"> | |||
|
14 | <button type="button" class="btn btn-primary" onclick="{% if previous %}window.location.replace('{{ previous }}');{% else %}history.go(-1);{% endif %}">Cancel</button> | |||
|
15 | <button type="submit" class="btn btn-primary">{{button}}</button> | |||
|
16 | </div> | |||
|
17 | </form> | |||
|
18 | {% endblock %} No newline at end of file |
@@ -0,0 +1,21 | |||||
|
1 | {% load bootstrap3 %} | |||
|
2 | ||||
|
3 | {% for line in rc_lines %} | |||
|
4 | <div class="panel panel-default" id="panel-{{line.id}}"> | |||
|
5 | <div class="panel-heading" role="tab" id="heading{{line.id}}"> | |||
|
6 | <h4 class="panel-title"> | |||
|
7 | <a role="button" data-toggle="collapse" data-parent="#div_lines" href="#collapse{{line.id}}" aria-expanded="true" aria-controls="collapse{{line.id}}"> | |||
|
8 | CH{{line.channel}} - {{line.get_name}} | |||
|
9 | </a> | |||
|
10 | {% if not edit %} | |||
|
11 | <button class="btn-xs btn-default pull-right" name="bt_remove_line" value="{{line.pk}}"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button> | |||
|
12 | {% endif %} | |||
|
13 | </h4> | |||
|
14 | </div> | |||
|
15 | <div id="collapse{{line.id}}" class="panel-collapse collapse{% if edit %} in{% endif %}" role="tabpanel" aria-labelledby="heading{{line.id}}"> | |||
|
16 | <div class="panel-body"> | |||
|
17 | {% bootstrap_form line.form layout='horizontal' size='small' %} | |||
|
18 | </div> | |||
|
19 | </div> | |||
|
20 | </div> | |||
|
21 | {% endfor%} |
@@ -1,457 +1,474 | |||||
1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse |
|
1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse | |
2 |
|
2 | |||
3 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm |
|
3 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm | |
4 | from apps.cgs.forms import CGSConfigurationForm |
|
4 | from apps.cgs.forms import CGSConfigurationForm | |
5 | from apps.jars.forms import JARSConfigurationForm |
|
5 | from apps.jars.forms import JARSConfigurationForm | |
6 | from apps.usrp.forms import USRPConfigurationForm |
|
6 | from apps.usrp.forms import USRPConfigurationForm | |
7 | from apps.abs.forms import ABSConfigurationForm |
|
7 | from apps.abs.forms import ABSConfigurationForm | |
8 | from apps.rc.forms import RCConfigurationForm |
|
8 | from apps.rc.forms import RCConfigurationForm | |
9 | from apps.dds.forms import DDSConfigurationForm |
|
9 | from apps.dds.forms import DDSConfigurationForm | |
10 |
|
10 | |||
11 | from .models import Campaign, Experiment, Device, Configuration |
|
11 | from .models import Campaign, Experiment, Device, Configuration | |
12 | from apps.cgs.models import CGSConfiguration |
|
12 | from apps.cgs.models import CGSConfiguration | |
13 | from apps.jars.models import JARSConfiguration |
|
13 | from apps.jars.models import JARSConfiguration | |
14 | from apps.usrp.models import USRPConfiguration |
|
14 | from apps.usrp.models import USRPConfiguration | |
15 | from apps.abs.models import ABSConfiguration |
|
15 | from apps.abs.models import ABSConfiguration | |
16 | from apps.rc.models import RCConfiguration |
|
16 | from apps.rc.models import RCConfiguration | |
17 | from apps.dds.models import DDSConfiguration |
|
17 | from apps.dds.models import DDSConfiguration | |
18 |
|
18 | |||
19 | # Create your views here. |
|
19 | # Create your views here. | |
20 |
|
20 | |||
21 | CONF_FORMS = { |
|
21 | CONF_FORMS = { | |
22 | 'rc': RCConfigurationForm, |
|
22 | 'rc': RCConfigurationForm, | |
23 | 'dds': DDSConfigurationForm, |
|
23 | 'dds': DDSConfigurationForm, | |
24 | 'jars': JARSConfigurationForm, |
|
24 | 'jars': JARSConfigurationForm, | |
25 | 'cgs': CGSConfigurationForm, |
|
25 | 'cgs': CGSConfigurationForm, | |
26 | 'abs': ABSConfigurationForm, |
|
26 | 'abs': ABSConfigurationForm, | |
27 | 'usrp': USRPConfigurationForm, |
|
27 | 'usrp': USRPConfigurationForm, | |
28 | } |
|
28 | } | |
29 |
|
29 | |||
30 | CONF_MODELS = { |
|
30 | CONF_MODELS = { | |
31 | 'rc': RCConfiguration, |
|
31 | 'rc': RCConfiguration, | |
32 | 'dds': DDSConfiguration, |
|
32 | 'dds': DDSConfiguration, | |
33 | 'jars': JARSConfiguration, |
|
33 | 'jars': JARSConfiguration, | |
34 | 'cgs': CGSConfiguration, |
|
34 | 'cgs': CGSConfiguration, | |
35 | 'abs': ABSConfiguration, |
|
35 | 'abs': ABSConfiguration, | |
36 | 'usrp': USRPConfiguration, |
|
36 | 'usrp': USRPConfiguration, | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | def index(request): |
|
39 | def index(request): | |
40 | kwargs = {} |
|
40 | kwargs = {} | |
41 |
|
41 | |||
42 | return render(request, 'index.html', kwargs) |
|
42 | return render(request, 'index.html', kwargs) | |
43 |
|
43 | |||
44 | def devices(request): |
|
44 | def devices(request): | |
45 |
|
45 | |||
46 | devices = Device.objects.all().order_by('device_type__name') |
|
46 | devices = Device.objects.all().order_by('device_type__name') | |
47 |
|
47 | |||
48 | # keys = ['id', 'device_type__name', 'name', 'ip_address'] |
|
48 | # keys = ['id', 'device_type__name', 'name', 'ip_address'] | |
49 | keys = ['id', 'name', 'ip_address', 'device_type'] |
|
49 | keys = ['id', 'name', 'ip_address', 'device_type'] | |
50 |
|
50 | |||
51 | kwargs = {} |
|
51 | kwargs = {} | |
52 | kwargs['device_keys'] = keys[1:] |
|
52 | kwargs['device_keys'] = keys[1:] | |
53 | kwargs['devices'] = devices#.values(*keys) |
|
53 | kwargs['devices'] = devices#.values(*keys) | |
54 | kwargs['title'] = 'Device' |
|
54 | kwargs['title'] = 'Device' | |
55 | kwargs['suptitle'] = 'List' |
|
55 | kwargs['suptitle'] = 'List' | |
56 | kwargs['button'] = 'New Device' |
|
56 | kwargs['button'] = 'New Device' | |
57 |
|
57 | |||
58 | return render(request, 'devices.html', kwargs) |
|
58 | return render(request, 'devices.html', kwargs) | |
59 |
|
59 | |||
60 | def device(request, id_dev): |
|
60 | def device(request, id_dev): | |
61 |
|
61 | |||
62 | device = get_object_or_404(Device, pk=id_dev) |
|
62 | device = get_object_or_404(Device, pk=id_dev) | |
63 |
|
63 | |||
64 | kwargs = {} |
|
64 | kwargs = {} | |
65 | kwargs['device'] = device |
|
65 | kwargs['device'] = device | |
66 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] |
|
66 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] | |
67 |
|
67 | |||
68 | kwargs['title'] = 'Device' |
|
68 | kwargs['title'] = 'Device' | |
69 | kwargs['suptitle'] = 'Details' |
|
69 | kwargs['suptitle'] = 'Details' | |
70 |
|
70 | |||
71 | kwargs['button'] = 'Add Device' |
|
71 | kwargs['button'] = 'Add Device' | |
72 |
|
72 | |||
73 | return render(request, 'device.html', kwargs) |
|
73 | return render(request, 'device.html', kwargs) | |
74 |
|
74 | |||
75 | def device_new(request): |
|
75 | def device_new(request): | |
76 |
|
76 | |||
77 | if request.method == 'GET': |
|
77 | if request.method == 'GET': | |
78 | form = DeviceForm() |
|
78 | form = DeviceForm() | |
79 |
|
79 | |||
80 | if request.method == 'POST': |
|
80 | if request.method == 'POST': | |
81 | form = DeviceForm(request.POST) |
|
81 | form = DeviceForm(request.POST) | |
82 |
|
82 | |||
83 | if form.is_valid(): |
|
83 | if form.is_valid(): | |
84 | form.save() |
|
84 | form.save() | |
85 | return redirect('url_devices') |
|
85 | return redirect('url_devices') | |
86 |
|
86 | |||
87 | kwargs = {} |
|
87 | kwargs = {} | |
88 | kwargs['form'] = form |
|
88 | kwargs['form'] = form | |
89 | kwargs['title'] = 'Device' |
|
89 | kwargs['title'] = 'Device' | |
90 | kwargs['suptitle'] = 'New' |
|
90 | kwargs['suptitle'] = 'New' | |
91 | kwargs['button'] = 'Create' |
|
91 | kwargs['button'] = 'Create' | |
92 |
|
92 | |||
93 | return render(request, 'device_edit.html', kwargs) |
|
93 | return render(request, 'device_edit.html', kwargs) | |
94 |
|
94 | |||
95 | def device_edit(request, id_dev): |
|
95 | def device_edit(request, id_dev): | |
96 |
|
96 | |||
97 | device = get_object_or_404(Device, pk=id_dev) |
|
97 | device = get_object_or_404(Device, pk=id_dev) | |
98 |
|
98 | |||
99 | if request.method=='GET': |
|
99 | if request.method=='GET': | |
100 | form = DeviceForm(instance=device) |
|
100 | form = DeviceForm(instance=device) | |
101 |
|
101 | |||
102 | if request.method=='POST': |
|
102 | if request.method=='POST': | |
103 | form = DeviceForm(request.POST, instance=device) |
|
103 | form = DeviceForm(request.POST, instance=device) | |
104 |
|
104 | |||
105 | if form.is_valid(): |
|
105 | if form.is_valid(): | |
106 | form.save() |
|
106 | form.save() | |
107 | return redirect('url_devices') |
|
107 | return redirect('url_devices') | |
108 |
|
108 | |||
109 | kwargs = {} |
|
109 | kwargs = {} | |
110 | kwargs['form'] = form |
|
110 | kwargs['form'] = form | |
111 | kwargs['title'] = 'Device' |
|
111 | kwargs['title'] = 'Device' | |
112 | kwargs['suptitle'] = 'Edit' |
|
112 | kwargs['suptitle'] = 'Edit' | |
113 | kwargs['button'] = 'Update' |
|
113 | kwargs['button'] = 'Update' | |
114 |
|
114 | |||
115 | return render(request, 'device_edit.html', kwargs) |
|
115 | return render(request, 'device_edit.html', kwargs) | |
116 |
|
116 | |||
117 | def device_delete(request, id_dev): |
|
117 | def device_delete(request, id_dev): | |
118 |
|
118 | |||
119 | device = get_object_or_404(Device, pk=id_dev) |
|
119 | device = get_object_or_404(Device, pk=id_dev) | |
120 |
|
120 | |||
121 | if request.method=='POST': |
|
121 | if request.method=='POST': | |
122 |
|
122 | |||
123 | if request.user.is_staff: |
|
123 | if request.user.is_staff: | |
124 | device.delete() |
|
124 | device.delete() | |
125 | return redirect('url_devices') |
|
125 | return redirect('url_devices') | |
126 |
|
126 | |||
127 | return HttpResponse("Not enough permission to delete this object") |
|
127 | return HttpResponse("Not enough permission to delete this object") | |
128 |
|
128 | |||
129 | kwargs = {'object':device, 'dev_active':'active', |
|
129 | kwargs = {'object':device, 'dev_active':'active', | |
130 | 'url_cancel':'url_device', 'id_item':id_dev} |
|
130 | 'url_cancel':'url_device', 'id_item':id_dev} | |
131 |
|
131 | |||
132 | return render(request, 'item_delete.html', kwargs) |
|
132 | return render(request, 'item_delete.html', kwargs) | |
133 |
|
133 | |||
134 | def campaigns(request): |
|
134 | def campaigns(request): | |
135 |
|
135 | |||
136 | campaigns = Campaign.objects.all().order_by('start_date') |
|
136 | campaigns = Campaign.objects.all().order_by('start_date') | |
137 |
|
137 | |||
138 | keys = ['id', 'name', 'start_date', 'end_date'] |
|
138 | keys = ['id', 'name', 'start_date', 'end_date'] | |
139 |
|
139 | |||
140 | kwargs = {} |
|
140 | kwargs = {} | |
141 | kwargs['campaign_keys'] = keys[1:] |
|
141 | kwargs['campaign_keys'] = keys[1:] | |
142 | kwargs['campaigns'] = campaigns#.values(*keys) |
|
142 | kwargs['campaigns'] = campaigns#.values(*keys) | |
143 | kwargs['title'] = 'Campaign' |
|
143 | kwargs['title'] = 'Campaign' | |
144 | kwargs['suptitle'] = 'List' |
|
144 | kwargs['suptitle'] = 'List' | |
145 | kwargs['button'] = 'New Campaign' |
|
145 | kwargs['button'] = 'New Campaign' | |
146 |
|
146 | |||
147 | return render(request, 'campaigns.html', kwargs) |
|
147 | return render(request, 'campaigns.html', kwargs) | |
148 |
|
148 | |||
149 | def campaign(request, id_camp): |
|
149 | def campaign(request, id_camp): | |
150 |
|
150 | |||
151 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
151 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
152 | experiments = Experiment.objects.filter(campaign=campaign) |
|
152 | experiments = Experiment.objects.filter(campaign=campaign) | |
153 |
|
153 | |||
154 | form = CampaignForm(instance=campaign) |
|
154 | form = CampaignForm(instance=campaign) | |
155 |
|
155 | |||
156 | kwargs = {} |
|
156 | kwargs = {} | |
157 | kwargs['campaign'] = campaign |
|
157 | kwargs['campaign'] = campaign | |
158 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
158 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
159 |
|
159 | |||
160 | keys = ['id', 'name', 'start_time', 'end_time'] |
|
160 | keys = ['id', 'name', 'start_time', 'end_time'] | |
161 |
|
161 | |||
162 | kwargs['experiment_keys'] = keys[1:] |
|
162 | kwargs['experiment_keys'] = keys[1:] | |
163 | kwargs['experiments'] = experiments.values(*keys) |
|
163 | kwargs['experiments'] = experiments.values(*keys) | |
164 |
|
164 | |||
165 | kwargs['title'] = 'Campaign' |
|
165 | kwargs['title'] = 'Campaign' | |
166 | kwargs['suptitle'] = 'Details' |
|
166 | kwargs['suptitle'] = 'Details' | |
167 |
|
167 | |||
168 | kwargs['form'] = form |
|
168 | kwargs['form'] = form | |
169 | kwargs['button'] = 'Add Experiment' |
|
169 | kwargs['button'] = 'Add Experiment' | |
170 |
|
170 | |||
171 | return render(request, 'campaign.html', kwargs) |
|
171 | return render(request, 'campaign.html', kwargs) | |
172 |
|
172 | |||
173 | def campaign_new(request): |
|
173 | def campaign_new(request): | |
174 |
|
174 | |||
175 | if request.method == 'GET': |
|
175 | if request.method == 'GET': | |
176 | form = CampaignForm() |
|
176 | form = CampaignForm() | |
177 |
|
177 | |||
178 | if request.method == 'POST': |
|
178 | if request.method == 'POST': | |
179 | form = CampaignForm(request.POST) |
|
179 | form = CampaignForm(request.POST) | |
180 |
|
180 | |||
181 | if form.is_valid(): |
|
181 | if form.is_valid(): | |
182 | campaign = form.save() |
|
182 | campaign = form.save() | |
183 | return redirect('url_campaign', id_camp=campaign.id) |
|
183 | return redirect('url_campaign', id_camp=campaign.id) | |
184 |
|
184 | |||
185 | kwargs = {} |
|
185 | kwargs = {} | |
186 | kwargs['form'] = form |
|
186 | kwargs['form'] = form | |
187 | kwargs['title'] = 'Campaign' |
|
187 | kwargs['title'] = 'Campaign' | |
188 | kwargs['suptitle'] = 'New' |
|
188 | kwargs['suptitle'] = 'New' | |
189 | kwargs['button'] = 'Create' |
|
189 | kwargs['button'] = 'Create' | |
190 |
|
190 | |||
191 | return render(request, 'campaign_edit.html', kwargs) |
|
191 | return render(request, 'campaign_edit.html', kwargs) | |
192 |
|
192 | |||
193 | def campaign_edit(request, id_camp): |
|
193 | def campaign_edit(request, id_camp): | |
194 |
|
194 | |||
195 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
195 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
196 |
|
196 | |||
197 | if request.method=='GET': |
|
197 | if request.method=='GET': | |
198 | form = CampaignForm(instance=campaign) |
|
198 | form = CampaignForm(instance=campaign) | |
199 |
|
199 | |||
200 | if request.method=='POST': |
|
200 | if request.method=='POST': | |
201 | form = CampaignForm(request.POST, instance=campaign) |
|
201 | form = CampaignForm(request.POST, instance=campaign) | |
202 |
|
202 | |||
203 | if form.is_valid(): |
|
203 | if form.is_valid(): | |
204 | form.save() |
|
204 | form.save() | |
205 | return redirect('url_campaign', id_camp=id_camp) |
|
205 | return redirect('url_campaign', id_camp=id_camp) | |
206 |
|
206 | |||
207 | kwargs = {} |
|
207 | kwargs = {} | |
208 | kwargs['form'] = form |
|
208 | kwargs['form'] = form | |
209 | kwargs['title'] = 'Campaign' |
|
209 | kwargs['title'] = 'Campaign' | |
210 | kwargs['suptitle'] = 'Edit' |
|
210 | kwargs['suptitle'] = 'Edit' | |
211 | kwargs['button'] = 'Update' |
|
211 | kwargs['button'] = 'Update' | |
212 |
|
212 | |||
213 | return render(request, 'campaign_edit.html', kwargs) |
|
213 | return render(request, 'campaign_edit.html', kwargs) | |
214 |
|
214 | |||
215 | def campaign_delete(request, id_camp): |
|
215 | def campaign_delete(request, id_camp): | |
216 |
|
216 | |||
217 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
217 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
218 |
|
218 | |||
219 | if request.method=='POST': |
|
219 | if request.method=='POST': | |
220 | if request.user.is_staff: |
|
220 | if request.user.is_staff: | |
221 | campaign.delete() |
|
221 | campaign.delete() | |
222 | return redirect('url_campaigns') |
|
222 | return redirect('url_campaigns') | |
223 |
|
223 | |||
224 | return HttpResponse("Not enough permission to delete this object") |
|
224 | return HttpResponse("Not enough permission to delete this object") | |
225 |
|
225 | |||
226 | kwargs = {'object':campaign, 'camp_active':'active', |
|
226 | kwargs = {'object':campaign, 'camp_active':'active', | |
227 | 'url_cancel':'url_campaign', 'id_item':id_camp} |
|
227 | 'url_cancel':'url_campaign', 'id_item':id_camp} | |
228 |
|
228 | |||
229 | return render(request, 'item_delete.html', kwargs) |
|
229 | return render(request, 'item_delete.html', kwargs) | |
230 |
|
230 | |||
231 | def experiments(request): |
|
231 | def experiments(request): | |
232 |
|
232 | |||
233 | experiment_list = Experiment.objects.all().order_by('campaign') |
|
233 | experiment_list = Experiment.objects.all().order_by('campaign') | |
234 |
|
234 | |||
235 | keys = ['id', 'name', 'start_time', 'end_time', 'campaign'] |
|
235 | keys = ['id', 'name', 'start_time', 'end_time', 'campaign'] | |
236 |
|
236 | |||
237 | kwargs = {} |
|
237 | kwargs = {} | |
238 |
|
238 | |||
239 | kwargs['experiment_keys'] = keys[1:] |
|
239 | kwargs['experiment_keys'] = keys[1:] | |
240 | kwargs['experiments'] = experiment_list#.values(*keys) |
|
240 | kwargs['experiments'] = experiment_list#.values(*keys) | |
241 |
|
241 | |||
242 | kwargs['title'] = 'Experiment' |
|
242 | kwargs['title'] = 'Experiment' | |
243 | kwargs['suptitle'] = 'List' |
|
243 | kwargs['suptitle'] = 'List' | |
244 | kwargs['button'] = 'New Experiment' |
|
244 | kwargs['button'] = 'New Experiment' | |
245 |
|
245 | |||
246 | return render(request, 'experiments.html', kwargs) |
|
246 | return render(request, 'experiments.html', kwargs) | |
247 |
|
247 | |||
248 | def experiment(request, id_exp): |
|
248 | def experiment(request, id_exp): | |
249 |
|
249 | |||
250 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
250 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
251 |
|
251 | |||
252 | experiments = Experiment.objects.filter(campaign=experiment.campaign) |
|
252 | experiments = Experiment.objects.filter(campaign=experiment.campaign) | |
253 | configurations = Configuration.objects.filter(experiment=experiment) |
|
253 | configurations = Configuration.objects.filter(experiment=experiment) | |
254 |
|
254 | |||
255 | kwargs = {} |
|
255 | kwargs = {} | |
256 |
|
256 | |||
257 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] |
|
257 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] | |
258 | conf_keys = ['id', 'device__name', 'device__device_type__name', 'device__ip_address'] |
|
258 | conf_keys = ['id', 'device__name', 'device__device_type__name', 'device__ip_address'] | |
259 |
|
259 | |||
260 |
|
260 | |||
261 | kwargs['experiment_keys'] = exp_keys[1:] |
|
261 | kwargs['experiment_keys'] = exp_keys[1:] | |
262 | kwargs['experiment'] = experiment |
|
262 | kwargs['experiment'] = experiment | |
263 |
|
263 | |||
264 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
264 | kwargs['experiments'] = experiments.values(*exp_keys) | |
265 |
|
265 | |||
266 | kwargs['configuration_keys'] = conf_keys[1:] |
|
266 | kwargs['configuration_keys'] = conf_keys[1:] | |
267 | kwargs['configurations'] = configurations.values(*conf_keys) |
|
267 | kwargs['configurations'] = configurations.values(*conf_keys) | |
268 |
|
268 | |||
269 | kwargs['title'] = 'Experiment' |
|
269 | kwargs['title'] = 'Experiment' | |
270 | kwargs['suptitle'] = 'Details' |
|
270 | kwargs['suptitle'] = 'Details' | |
271 |
|
271 | |||
272 | kwargs['button'] = 'Add Device' |
|
272 | kwargs['button'] = 'Add Device' | |
273 |
|
273 | |||
274 | return render(request, 'experiment.html', kwargs) |
|
274 | return render(request, 'experiment.html', kwargs) | |
275 |
|
275 | |||
276 | def experiment_new(request, id_camp=0): |
|
276 | def experiment_new(request, id_camp=0): | |
277 |
|
277 | |||
278 | if request.method == 'GET': |
|
278 | if request.method == 'GET': | |
279 | form = ExperimentForm(initial={'campaign':id_camp}) |
|
279 | form = ExperimentForm(initial={'campaign':id_camp}) | |
280 |
|
280 | |||
281 | if request.method == 'POST': |
|
281 | if request.method == 'POST': | |
282 | form = ExperimentForm(request.POST, initial={'campaign':id_camp}) |
|
282 | form = ExperimentForm(request.POST, initial={'campaign':id_camp}) | |
283 |
|
283 | |||
284 | if form.is_valid(): |
|
284 | if form.is_valid(): | |
285 | experiment = form.save() |
|
285 | experiment = form.save() | |
286 | return redirect('url_experiment', id_exp=experiment.id) |
|
286 | return redirect('url_experiment', id_exp=experiment.id) | |
287 |
|
287 | |||
288 | kwargs = {} |
|
288 | kwargs = {} | |
289 | kwargs['form'] = form |
|
289 | kwargs['form'] = form | |
290 | kwargs['title'] = 'Experiment' |
|
290 | kwargs['title'] = 'Experiment' | |
291 | kwargs['suptitle'] = 'New' |
|
291 | kwargs['suptitle'] = 'New' | |
292 | kwargs['button'] = 'Create' |
|
292 | kwargs['button'] = 'Create' | |
293 |
|
293 | |||
294 | return render(request, 'experiment_edit.html', kwargs) |
|
294 | return render(request, 'experiment_edit.html', kwargs) | |
295 |
|
295 | |||
296 | def experiment_edit(request, id_exp): |
|
296 | def experiment_edit(request, id_exp): | |
297 |
|
297 | |||
298 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
298 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
299 |
|
299 | |||
300 | if request.method == 'GET': |
|
300 | if request.method == 'GET': | |
301 | form = ExperimentForm(instance=experiment) |
|
301 | form = ExperimentForm(instance=experiment) | |
302 |
|
302 | |||
303 | if request.method=='POST': |
|
303 | if request.method=='POST': | |
304 | form = ExperimentForm(request.POST, instance=experiment) |
|
304 | form = ExperimentForm(request.POST, instance=experiment) | |
305 |
|
305 | |||
306 | if form.is_valid(): |
|
306 | if form.is_valid(): | |
307 | experiment = form.save() |
|
307 | experiment = form.save() | |
308 | return redirect('url_experiment', id_exp=experiment.id) |
|
308 | return redirect('url_experiment', id_exp=experiment.id) | |
309 |
|
309 | |||
310 | kwargs = {} |
|
310 | kwargs = {} | |
311 | kwargs['form'] = form |
|
311 | kwargs['form'] = form | |
312 | kwargs['title'] = 'Experiment' |
|
312 | kwargs['title'] = 'Experiment' | |
313 | kwargs['suptitle'] = 'Edit' |
|
313 | kwargs['suptitle'] = 'Edit' | |
314 | kwargs['button'] = 'Update' |
|
314 | kwargs['button'] = 'Update' | |
315 |
|
315 | |||
316 | return render(request, 'experiment_edit.html', kwargs) |
|
316 | return render(request, 'experiment_edit.html', kwargs) | |
317 |
|
317 | |||
318 | def experiment_delete(request, id_exp): |
|
318 | def experiment_delete(request, id_exp): | |
319 |
|
319 | |||
320 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
320 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
321 |
|
321 | |||
322 | if request.method=='POST': |
|
322 | if request.method=='POST': | |
323 | if request.user.is_staff: |
|
323 | if request.user.is_staff: | |
324 | id_camp = experiment.campaign.id |
|
324 | id_camp = experiment.campaign.id | |
325 | experiment.delete() |
|
325 | experiment.delete() | |
326 | return redirect('url_campaign', id_camp=id_camp) |
|
326 | return redirect('url_campaign', id_camp=id_camp) | |
327 |
|
327 | |||
328 | return HttpResponse("Not enough permission to delete this object") |
|
328 | return HttpResponse("Not enough permission to delete this object") | |
329 |
|
329 | |||
330 | kwargs = {'object':experiment, 'exp_active':'active', |
|
330 | kwargs = {'object':experiment, 'exp_active':'active', | |
331 | 'url_cancel':'url_experiment', 'id_item':id_exp} |
|
331 | 'url_cancel':'url_experiment', 'id_item':id_exp} | |
332 |
|
332 | |||
333 | return render(request, 'item_delete.html', kwargs) |
|
333 | return render(request, 'item_delete.html', kwargs) | |
334 |
|
334 | |||
335 | def dev_confs(request): |
|
335 | def dev_confs(request): | |
336 |
|
336 | |||
337 | configurations = Configuration.objects.all().order_by('experiment') |
|
337 | configurations = Configuration.objects.all().order_by('experiment') | |
338 |
|
338 | |||
339 | # keys = ['id', 'device__device_type__name', 'device__name', 'experiment__campaign__name', 'experiment__name'] |
|
339 | # keys = ['id', 'device__device_type__name', 'device__name', 'experiment__campaign__name', 'experiment__name'] | |
340 |
|
340 | |||
341 | keys = ['id', 'device', 'experiment'] |
|
341 | keys = ['id', 'device', 'experiment'] | |
342 |
|
342 | |||
343 | kwargs = {} |
|
343 | kwargs = {} | |
344 |
|
344 | |||
345 | kwargs['configuration_keys'] = keys[1:] |
|
345 | kwargs['configuration_keys'] = keys[1:] | |
346 | kwargs['configurations'] = configurations#.values(*keys) |
|
346 | kwargs['configurations'] = configurations#.values(*keys) | |
347 |
|
347 | |||
348 | kwargs['title'] = 'Configuration' |
|
348 | kwargs['title'] = 'Configuration' | |
349 | kwargs['suptitle'] = 'List' |
|
349 | kwargs['suptitle'] = 'List' | |
350 | kwargs['button'] = 'New Configuration' |
|
350 | kwargs['button'] = 'New Configuration' | |
351 |
|
351 | |||
352 | return render(request, 'dev_confs.html', kwargs) |
|
352 | return render(request, 'dev_confs.html', kwargs) | |
353 |
|
353 | |||
354 | def dev_conf(request, id_conf): |
|
354 | def dev_conf(request, id_conf): | |
355 |
|
355 | |||
356 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
356 | conf = get_object_or_404(Configuration, pk=id_conf) | |
357 |
|
357 | |||
358 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
358 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
359 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
359 | dev_conf = DevConfModel.objects.get(pk=id_conf) | |
360 |
|
360 | |||
361 | kwargs = {} |
|
361 | kwargs = {} | |
362 | kwargs['dev_conf'] = dev_conf |
|
362 | kwargs['dev_conf'] = dev_conf | |
363 | kwargs['dev_conf_keys'] = ['experiment', 'device'] |
|
363 | kwargs['dev_conf_keys'] = ['experiment', 'device'] | |
364 |
|
364 | |||
365 | kwargs['title'] = 'Configuration' |
|
365 | kwargs['title'] = 'Configuration' | |
366 | kwargs['suptitle'] = 'Details' |
|
366 | kwargs['suptitle'] = 'Details' | |
367 |
|
367 | |||
368 | kwargs['button'] = 'Edit Configuration' |
|
368 | kwargs['button'] = 'Edit Configuration' | |
369 |
|
369 | |||
370 | ###### SIDEBAR ###### |
|
370 | ###### SIDEBAR ###### | |
371 | experiments = Experiment.objects.filter(campaign=conf.experiment.campaign) |
|
371 | experiments = Experiment.objects.filter(campaign=conf.experiment.campaign) | |
372 | configurations = Configuration.objects.filter(experiment=conf.experiment) |
|
372 | configurations = Configuration.objects.filter(experiment=conf.experiment) | |
373 |
|
373 | |||
374 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] |
|
374 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] | |
375 | conf_keys = ['id', 'device__name', 'device__device_type__name', 'device__ip_address'] |
|
375 | conf_keys = ['id', 'device__name', 'device__device_type__name', 'device__ip_address'] | |
376 |
|
376 | |||
377 | kwargs['experiment_keys'] = exp_keys[1:] |
|
377 | kwargs['experiment_keys'] = exp_keys[1:] | |
378 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
378 | kwargs['experiments'] = experiments.values(*exp_keys) | |
379 |
|
379 | |||
380 | kwargs['configuration_keys'] = conf_keys[1:] |
|
380 | kwargs['configuration_keys'] = conf_keys[1:] | |
381 | kwargs['configurations'] = configurations.values(*conf_keys) |
|
381 | kwargs['configurations'] = configurations.values(*conf_keys) | |
382 |
|
382 | |||
383 | return render(request, 'dev_conf.html', kwargs) |
|
383 | return render(request, 'dev_conf.html', kwargs) | |
384 |
|
384 | |||
385 | def dev_conf_new(request, id_exp=0): |
|
385 | def dev_conf_new(request, id_exp=0): | |
386 |
|
386 | |||
387 | if request.method == 'GET': |
|
387 | if request.method == 'GET': | |
388 | form = ConfigurationForm(initial={'experiment':id_exp}) |
|
388 | form = ConfigurationForm(initial={'experiment':id_exp}) | |
389 |
|
389 | |||
390 | if request.method == 'POST': |
|
390 | if request.method == 'POST': | |
391 | form = ConfigurationForm(request.POST) |
|
391 | form = ConfigurationForm(request.POST) | |
392 |
|
392 | |||
393 | if form.is_valid(): |
|
393 | if form.is_valid(): | |
394 | experiment = Experiment.objects.get(pk=request.POST['experiment']) |
|
394 | experiment = Experiment.objects.get(pk=request.POST['experiment']) | |
395 | device = Device.objects.get(pk=request.POST['device']) |
|
395 | device = Device.objects.get(pk=request.POST['device']) | |
396 |
|
396 | |||
397 | exp_devices = Device.objects.filter(configuration__experiment=experiment) |
|
397 | exp_devices = Device.objects.filter(configuration__experiment=experiment) | |
398 |
|
398 | |||
399 | if device.id not in exp_devices.values('id',): |
|
399 | if device.id not in exp_devices.values('id',): | |
400 |
|
400 | |||
401 | DevConfModel = CONF_MODELS[device.device_type.name] |
|
401 | DevConfModel = CONF_MODELS[device.device_type.name] | |
402 | conf = DevConfModel(experiment=experiment, device=device) |
|
402 | conf = DevConfModel(experiment=experiment, device=device) | |
403 | conf.save() |
|
403 | conf.save() | |
404 |
|
404 | |||
405 | return redirect('url_experiment', id_exp=experiment.id) |
|
405 | return redirect('url_experiment', id_exp=experiment.id) | |
406 |
|
406 | |||
407 | kwargs = {} |
|
407 | kwargs = {} | |
408 | kwargs['form'] = form |
|
408 | kwargs['form'] = form | |
409 | kwargs['title'] = 'Configuration' |
|
409 | kwargs['title'] = 'Configuration' | |
410 | kwargs['suptitle'] = 'New' |
|
410 | kwargs['suptitle'] = 'New' | |
411 | kwargs['button'] = 'Create' |
|
411 | kwargs['button'] = 'Create' | |
412 |
|
412 | |||
413 | return render(request, 'dev_conf_edit.html', kwargs) |
|
413 | return render(request, 'dev_conf_edit.html', kwargs) | |
414 |
|
414 | |||
415 | def dev_conf_edit(request, id_conf): |
|
415 | def dev_conf_edit(request, id_conf): | |
416 |
|
416 | |||
417 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
417 | conf = get_object_or_404(Configuration, pk=id_conf) | |
418 |
|
418 | |||
419 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
419 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
420 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
420 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
421 |
|
421 | |||
422 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
422 | dev_conf = DevConfModel.objects.get(pk=id_conf) | |
423 |
|
423 | |||
424 | if request.method=='GET': |
|
424 | if request.method=='GET': | |
425 | form = DevConfForm(instance=dev_conf) |
|
425 | form = DevConfForm(instance=dev_conf) | |
426 |
|
426 | |||
427 | if request.method=='POST': |
|
427 | if request.method=='POST': | |
428 | form = DevConfForm(request.POST, instance=dev_conf) |
|
428 | form = DevConfForm(request.POST, instance=dev_conf) | |
429 |
|
429 | |||
430 | if form.is_valid(): |
|
430 | if form.is_valid(): | |
431 | form.save() |
|
431 | form.save() | |
432 | return redirect('url_dev_conf', id_conf=id_conf) |
|
432 | return redirect('url_dev_conf', id_conf=id_conf) | |
433 |
|
433 | |||
434 | kwargs = {} |
|
434 | kwargs = {} | |
435 | kwargs['form'] = form |
|
435 | kwargs['form'] = form | |
436 | kwargs['title'] = 'Device Configuration' |
|
436 | kwargs['title'] = 'Device Configuration' | |
437 | kwargs['suptitle'] = 'Edit' |
|
437 | kwargs['suptitle'] = 'Edit' | |
438 | kwargs['button'] = 'Update' |
|
438 | kwargs['button'] = 'Update' | |
439 |
|
439 | |||
440 | return render(request, 'dev_conf_edit.html', kwargs) |
|
440 | return render(request, 'dev_conf_edit.html', kwargs) | |
441 |
|
441 | |||
442 | def dev_conf_delete(request, id_conf): |
|
442 | def dev_conf_delete(request, id_conf): | |
443 |
|
443 | |||
444 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
444 | conf = get_object_or_404(Configuration, pk=id_conf) | |
445 |
|
445 | |||
446 | if request.method=='POST': |
|
446 | if request.method=='POST': | |
447 | if request.user.is_staff: |
|
447 | if request.user.is_staff: | |
448 | id_exp = conf.experiment.id |
|
448 | id_exp = conf.experiment.id | |
449 | conf.delete() |
|
449 | conf.delete() | |
450 | return redirect('url_experiment', id_exp=id_exp) |
|
450 | return redirect('url_experiment', id_exp=id_exp) | |
451 |
|
451 | |||
452 | return HttpResponse("Not enough permission to delete this object") |
|
452 | return HttpResponse("Not enough permission to delete this object") | |
453 |
|
453 | |||
454 | kwargs = {'object':conf, 'conf_active':'active', |
|
454 | kwargs = {'object':conf, 'conf_active':'active', | |
455 | 'url_cancel':'url_dev_conf', 'id_item':id_conf} |
|
455 | 'url_cancel':'url_dev_conf', 'id_item':id_conf} | |
456 |
|
456 | |||
457 | return render(request, 'item_delete.html', kwargs) No newline at end of file |
|
457 | return render(request, 'item_delete.html', kwargs) | |
|
458 | ||||
|
459 | def sidebar(conf): | |||
|
460 | ||||
|
461 | experiments = Experiment.objects.filter(campaign=conf.experiment.campaign) | |||
|
462 | configurations = Configuration.objects.filter(experiment=conf.experiment) | |||
|
463 | ||||
|
464 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] | |||
|
465 | conf_keys = ['id', 'device__name', 'device__device_type__name', 'device__ip_address'] | |||
|
466 | ||||
|
467 | kwargs = {} | |||
|
468 | kwargs['experiment_keys'] = exp_keys[1:] | |||
|
469 | kwargs['experiments'] = experiments.values(*exp_keys) | |||
|
470 | ||||
|
471 | kwargs['configuration_keys'] = conf_keys[1:] | |||
|
472 | kwargs['configurations'] = configurations.values(*conf_keys) | |||
|
473 | ||||
|
474 | return kwargs No newline at end of file |
@@ -1,8 +1,9 | |||||
1 | from django.contrib import admin |
|
1 | from django.contrib import admin | |
2 | from .models import RCConfiguration, RCLine, RCLineType |
|
2 | from .models import RCConfiguration, RCLine, RCLineType, RCLineCode | |
3 |
|
3 | |||
4 | # Register your models here. |
|
4 | # Register your models here. | |
5 |
|
5 | |||
6 | admin.site.register(RCConfiguration) |
|
6 | admin.site.register(RCConfiguration) | |
7 | admin.site.register(RCLine) |
|
7 | admin.site.register(RCLine) | |
8 | admin.site.register(RCLineType) |
|
8 | admin.site.register(RCLineType) | |
|
9 | admin.site.register(RCLineCode) |
@@ -1,43 +1,87 | |||||
1 | import json |
|
1 | import json | |
2 |
|
2 | |||
3 | from django import forms |
|
3 | from django import forms | |
4 | from .models import RCConfiguration, RCLine, RCLineType |
|
4 | from .models import RCConfiguration, RCLine, RCLineType, RCLineCode | |
|
5 | ||||
|
6 | def create_choices_from_model(model, conf_id): | |||
|
7 | ||||
|
8 | if model=='RCLine': | |||
|
9 | instance = RCConfiguration.objects.get(pk=conf_id) | |||
|
10 | return instance.get_refs_lines() | |||
|
11 | else: | |||
|
12 | instance = globals()[model] | |||
|
13 | return instance.objects.all().values_list('pk', 'name') | |||
5 |
|
14 | |||
6 | class RCConfigurationForm(forms.ModelForm): |
|
15 | class RCConfigurationForm(forms.ModelForm): | |
7 |
|
16 | |||
8 | class Meta: |
|
17 | class Meta: | |
9 | model = RCConfiguration |
|
18 | model = RCConfiguration | |
10 | exclude = ('clock', 'ipp', 'ntx', 'clock_divider') |
|
19 | exclude = ('clock', 'ipp', 'ntx', 'clock_divider') | |
11 |
|
20 | |||
12 |
|
21 | |||
13 | class RCLineForm(forms.ModelForm): |
|
22 | class RCLineForm(forms.ModelForm): | |
14 |
|
23 | |||
|
24 | def __init__(self, *args, **kwargs): | |||
|
25 | self.extra_fields = kwargs.pop('extra_fields', []) | |||
|
26 | super(RCLineForm, self).__init__(*args, **kwargs) | |||
|
27 | if 'initial'in kwargs: | |||
|
28 | for item in self.extra_fields: | |||
|
29 | if 'model' in item: | |||
|
30 | self.fields[item['name']] = forms.ChoiceField(choices=create_choices_from_model(item['model'], | |||
|
31 | kwargs['initial']['rc_configuration'])) | |||
|
32 | else: | |||
|
33 | self.fields[item['name']] = forms.CharField(initial=item['value']) | |||
|
34 | ||||
15 | class Meta: |
|
35 | class Meta: | |
16 | model = RCLine |
|
36 | model = RCLine | |
17 | fields = ('rc_configuration', 'line_type', 'channel') |
|
37 | fields = ('rc_configuration', 'line_type', 'channel') | |
18 | widgets = { |
|
38 | widgets = { | |
19 | 'channel': forms.HiddenInput(), |
|
39 | 'channel': forms.HiddenInput(), | |
20 | } |
|
40 | } | |
21 |
|
41 | |||
22 | def save(self): |
|
42 | def save(self): | |
23 | line = super(RCLineForm, self).save() |
|
43 | line = super(RCLineForm, self).save() | |
|
44 | ||||
24 | #auto add channel |
|
45 | #auto add channel | |
25 | line.channel = RCLine.objects.filter(rc_configuration=line.rc_configuration).count()-1 |
|
46 | line.channel = RCLine.objects.filter(rc_configuration=line.rc_configuration).count()-1 | |
|
47 | ||||
26 | #auto add position for TX, TR & CODE |
|
48 | #auto add position for TX, TR & CODE | |
27 | if line.line_type.name in ('tx', 'tr', 'code'): |
|
49 | if line.line_type.name in ('tx', 'tr', 'codes', 'windows'): | |
28 | line.position = RCLine.objects.filter(rc_configuration=line.rc_configuration, line_type=line.line_type).count()-1 |
|
50 | line.position = RCLine.objects.filter(rc_configuration=line.rc_configuration, line_type=line.line_type).count()-1 | |
29 | #add default params |
|
51 | ||
|
52 | #save extra fields in params | |||
30 | params = {} |
|
53 | params = {} | |
31 | for field in json.loads(line.line_type.params): |
|
54 | for item in self.extra_fields: | |
32 |
params[ |
|
55 | params[item['name']] = self.data[item['name']] | |
33 | line.params = json.dumps(params) |
|
56 | line.params = json.dumps(params) | |
34 | line.save() |
|
57 | line.save() | |
35 | return |
|
58 | return | |
36 |
|
59 | |||
37 | class RCLineViewForm(forms.Form): |
|
60 | class RCLineViewForm(forms.Form): | |
38 |
|
61 | |||
39 | def __init__(self, *args, **kwargs): |
|
62 | def __init__(self, *args, **kwargs): | |
40 | extra_fields = kwargs.pop('extra_fields') |
|
63 | extra_fields = kwargs.pop('extra_fields') | |
41 | super(RCLineViewForm, self).__init__(*args, **kwargs) |
|
64 | super(RCLineViewForm, self).__init__(*args, **kwargs) | |
42 | for label, value in extra_fields.items(): |
|
65 | for label, value in extra_fields.items(): | |
43 | self.fields[label] = forms.CharField(initial=value) No newline at end of file |
|
66 | if 'ref' in label: | |
|
67 | value = RCLine.objects.get(pk=value).get_name() | |||
|
68 | elif 'code' in label: | |||
|
69 | value = RCLineCode.objects.get(pk=value).name | |||
|
70 | self.fields[label] = forms.CharField(initial=value) | |||
|
71 | ||||
|
72 | class RCLineEditForm(forms.Form): | |||
|
73 | ||||
|
74 | def __init__(self, *args, **kwargs): | |||
|
75 | self.extra_fields = kwargs.pop('extra_fields', []) | |||
|
76 | super(RCLineEditForm, self).__init__(*args, **kwargs) | |||
|
77 | if 'initial'in kwargs: | |||
|
78 | for item in self.extra_fields: | |||
|
79 | if 'model' in item: | |||
|
80 | self.fields[item['name']] = forms.ChoiceField(choices=create_choices_from_model(item['model'], | |||
|
81 | kwargs['initial']['rc_configuration']), | |||
|
82 | initial=item['value'], | |||
|
83 | widget=forms.Select(attrs={'name':'%s|%s' % (kwargs['initial']['line'], item['name'])})) | |||
|
84 | else: | |||
|
85 | self.fields[item['name']] = forms.CharField(initial=item['value'], | |||
|
86 | widget=forms.TextInput(attrs={'name':'%s|%s' % (kwargs['initial']['line'], item['name'])})) | |||
|
87 | No newline at end of file |
@@ -1,95 +1,107 | |||||
1 |
|
1 | |||
|
2 | import json | |||
|
3 | ||||
2 | from polymorphic import PolymorphicModel |
|
4 | from polymorphic import PolymorphicModel | |
3 |
|
5 | |||
4 | from django.db import models |
|
6 | from django.db import models | |
5 | from django.core.validators import MinValueValidator, MaxValueValidator |
|
7 | from django.core.validators import MinValueValidator, MaxValueValidator | |
6 |
|
8 | |||
7 | from apps.main.models import Configuration |
|
9 | from apps.main.models import Configuration | |
8 | # Create your models here. |
|
10 | # Create your models here. | |
9 |
|
11 | |||
10 | LINE_TYPES = ( |
|
12 | LINE_TYPES = ( | |
11 | ('tr', 'Transmission/reception selector signal'), |
|
13 | ('tr', 'Transmission/reception selector signal'), | |
12 | ('tx', 'A modulating signal (Transmission pulse)'), |
|
14 | ('tx', 'A modulating signal (Transmission pulse)'), | |
13 | ('codes', 'BPSK modulating signal'), |
|
15 | ('codes', 'BPSK modulating signal'), | |
14 | ('windows', 'Sample window signal'), |
|
16 | ('windows', 'Sample window signal'), | |
15 | ('sync', 'Synchronizing signal'), |
|
17 | ('sync', 'Synchronizing signal'), | |
16 | ('flip', 'IPP related periodic signal'), |
|
18 | ('flip', 'IPP related periodic signal'), | |
17 | ('prog_pulses', 'Programmable pulse'), |
|
19 | ('prog_pulses', 'Programmable pulse'), | |
18 | ) |
|
20 | ) | |
19 |
|
21 | |||
20 | LINE_PARAMS = { |
|
22 | LINE_PARAMS = { | |
21 | "tr": [{"name":"time_after", "value": 0}], |
|
23 | "tr": [{"name":"time_after", "value": 0}], | |
22 | "tx": [{"name": "pulse_width", "value": 0},{"name":"delays", "value":""}], |
|
24 | "tx": [{"name": "pulse_width", "value": 0},{"name":"delays", "value":""}], | |
23 | "codes": [{"name":"tx_ref", "value": ""},{"name":"code", "value": "", "choices":"RCLineCode"}], |
|
25 | "codes": [{"name":"tx_ref", "value": ""},{"name":"code", "value": "", "choices":"RCLineCode"}], | |
24 | "windows": [{"name":"tx_ref","value":""}, {"name":"first_height", "value":0}, {"name":"number_of_samples","value":0}, {"name":"resolution","value":0}, {"name":"last_height","value":0}], |
|
26 | "windows": [{"name":"tx_ref","value":""}, {"name":"first_height", "value":0}, {"name":"number_of_samples","value":0}, {"name":"resolution","value":0}, {"name":"last_height","value":0}], | |
25 | "sync": [{"name": "delay", "value": 0}], |
|
27 | "sync": [{"name": "delay", "value": 0}], | |
26 | "flip": [{"name":"number_of_flips", "value": 0}], |
|
28 | "flip": [{"name":"number_of_flips", "value": 0}], | |
27 | "prog_pulses": [{"name": "begin", "value": 0}, {"name": "end","value": 0}], |
|
29 | "prog_pulses": [{"name": "begin", "value": 0}, {"name": "end","value": 0}], | |
28 | } |
|
30 | } | |
29 |
|
31 | |||
30 |
|
32 | |||
31 | class RCConfiguration(Configuration): |
|
33 | class RCConfiguration(Configuration): | |
32 |
|
34 | |||
33 | clock = models.FloatField(verbose_name='Clock Master (MHz)', validators=[MinValueValidator(0), MaxValueValidator(80)], blank=True, null=True) |
|
35 | clock = models.FloatField(verbose_name='Clock Master (MHz)', validators=[MinValueValidator(0), MaxValueValidator(80)], blank=True, null=True) | |
34 | clock_divider = models.PositiveIntegerField(verbose_name='Clock divider', validators=[MinValueValidator(0), MaxValueValidator(256)], blank=True, null=True) |
|
36 | clock_divider = models.PositiveIntegerField(verbose_name='Clock divider', validators=[MinValueValidator(0), MaxValueValidator(256)], blank=True, null=True) | |
35 | ipp = models.PositiveIntegerField(verbose_name='Inter pulse period (Km)', default=10) |
|
37 | ipp = models.PositiveIntegerField(verbose_name='Inter pulse period (Km)', default=10) | |
36 | ntx = models.PositiveIntegerField(verbose_name='Number of pulse of transmit', default=1) |
|
38 | ntx = models.PositiveIntegerField(verbose_name='Number of pulse of transmit', default=1) | |
37 | time_before = models.PositiveIntegerField(verbose_name='Number of pulse of transmit', default=0) |
|
39 | time_before = models.PositiveIntegerField(verbose_name='Number of pulse of transmit', default=0) | |
38 |
|
40 | |||
39 | class Meta: |
|
41 | class Meta: | |
40 | db_table = 'rc_configurations' |
|
42 | db_table = 'rc_configurations' | |
41 |
|
43 | |||
42 | def get_number_position(self): |
|
44 | def get_number_position(self): | |
43 |
|
45 | |||
44 | lines = RCLine.objects.filter(rc_configuration=self.rc_configuration) |
|
46 | lines = RCLine.objects.filter(rc_configuration=self.rc_configuration) | |
45 | if lines: |
|
47 | if lines: | |
46 | return max([line.position for line in lines]) |
|
48 | return max([line.position for line in lines]) | |
47 |
|
49 | |||
|
50 | def get_refs_lines(self): | |||
|
51 | ||||
|
52 | lines = RCLine.objects.filter(rc_configuration=self.pk, line_type__name='tx') | |||
|
53 | return [(line.pk, line.get_name()) for line in lines] | |||
|
54 | ||||
48 | class RCLineCode(models.Model): |
|
55 | class RCLineCode(models.Model): | |
49 |
|
56 | |||
50 |
name = models.CharField( |
|
57 | name = models.CharField(max_length=40) | |
51 | bits_per_code = models.PositiveIntegerField(default=0) |
|
58 | bits_per_code = models.PositiveIntegerField(default=0) | |
52 | number_of_codes = models.PositiveIntegerField(default=0) |
|
59 | number_of_codes = models.PositiveIntegerField(default=0) | |
53 | codes = models.TextField(blank=True, null=True) |
|
60 | codes = models.TextField(blank=True, null=True) | |
54 |
|
61 | |||
55 | class Meta: |
|
62 | class Meta: | |
56 | db_table = 'rc_line_codes' |
|
63 | db_table = 'rc_line_codes' | |
57 |
|
64 | ordering = ('name',) | ||
|
65 | ||||
|
66 | def __unicode__(self): | |||
|
67 | return u'%s' % self.name | |||
58 |
|
68 | |||
59 | class RCLineType(models.Model): |
|
69 | class RCLineType(models.Model): | |
60 |
|
70 | |||
61 | name = models.CharField(choices=LINE_TYPES, max_length=40) |
|
71 | name = models.CharField(choices=LINE_TYPES, max_length=40) | |
62 | description = models.TextField(blank=True, null=True) |
|
72 | description = models.TextField(blank=True, null=True) | |
63 | params = models.TextField(default='[]') |
|
73 | params = models.TextField(default='[]') | |
64 |
|
74 | |||
65 | class Meta: |
|
75 | class Meta: | |
66 | db_table = 'rc_line_types' |
|
76 | db_table = 'rc_line_types' | |
67 |
|
77 | |||
68 | def __unicode__(self): |
|
78 | def __unicode__(self): | |
69 | return u'%s - %s' % (self.name.upper(), self.get_name_display()) |
|
79 | return u'%s - %s' % (self.name.upper(), self.get_name_display()) | |
70 |
|
80 | |||
71 |
|
81 | |||
72 | class RCLine(models.Model): |
|
82 | class RCLine(models.Model): | |
73 |
|
83 | |||
74 | rc_configuration = models.ForeignKey(RCConfiguration) |
|
84 | rc_configuration = models.ForeignKey(RCConfiguration) | |
75 | line_type = models.ForeignKey(RCLineType) |
|
85 | line_type = models.ForeignKey(RCLineType) | |
76 | channel = models.PositiveIntegerField(default=0) |
|
86 | channel = models.PositiveIntegerField(default=0) | |
77 | position = models.PositiveIntegerField(default=0) |
|
87 | position = models.PositiveIntegerField(default=0) | |
78 | params = models.TextField(default='{}') |
|
88 | params = models.TextField(default='{}') | |
79 |
|
89 | |||
80 | class Meta: |
|
90 | class Meta: | |
81 | db_table = 'rc_lines' |
|
91 | db_table = 'rc_lines' | |
82 |
|
92 | |||
83 | def __unicode__(self): |
|
93 | def __unicode__(self): | |
84 | return u'%s - %s' % (self.rc_configuration, self.get_name()) |
|
94 | return u'%s - %s' % (self.rc_configuration, self.get_name()) | |
85 |
|
95 | |||
86 | def get_name(self): |
|
96 | def get_name(self): | |
87 |
|
97 | |||
88 | chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
|
98 | chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | |
89 |
|
99 | |||
90 |
if self.line_type.name in ('tx', ' |
|
100 | if self.line_type.name in ('tx', 'tr',): | |
91 | return '%s%s' % (self.line_type.name.upper(), chars[self.position]) |
|
101 | return '%s %s' % (self.line_type.name.upper(), chars[self.position]) | |
92 |
|
102 | elif self.line_type.name in ('codes', 'windows',): | ||
93 | return self.line_type.name.upper() |
|
103 | pk = json.loads(self.params)['TX_ref'] | |
94 |
|
104 | ref = RCLine.objects.get(pk=pk) | ||
95 |
|
105 | return '%s %s' % (self.line_type.name.upper(), chars[ref.position]) | ||
|
106 | else: | |||
|
107 | return self.line_type.name.upper() |
@@ -1,1 +1,13 | |||||
1 | {% extends "dev_conf_edit.html" %} No newline at end of file |
|
1 | {% extends "dev_conf_edit.html" %} | |
|
2 | ||||
|
3 | {% block extra-js%} | |||
|
4 | ||||
|
5 | <script type="text/javascript"> | |||
|
6 | ||||
|
7 | $("#id_line_type").change(function() { | |||
|
8 | var url = "{% url 'url_add_rc_line' dev_conf.id %}"; | |||
|
9 | document.location = url + $(this).val()+"/"; | |||
|
10 | }); | |||
|
11 | ||||
|
12 | </script> | |||
|
13 | {% endblock %} No newline at end of file |
@@ -1,82 +1,71 | |||||
1 | {% extends "dev_conf.html" %} |
|
1 | {% extends "dev_conf.html" %} | |
2 | {% load static %} |
|
2 | {% load static %} | |
3 | {% load bootstrap3 %} |
|
3 | {% load bootstrap3 %} | |
|
4 | {% load main_tags %}s | |||
|
5 | ||||
4 | {% block extra-head %} |
|
6 | {% block extra-head %} | |
5 | <style type="text/css"> |
|
7 | <style type="text/css"> | |
6 | /* show the move cursor as the user moves the mouse over the panel header.*/ |
|
8 | /* show the move cursor as the user moves the mouse over the panel header.*/ | |
7 | .panel-default { cursor: move; } |
|
9 | .panel-default { cursor: move; } | |
8 | </style> |
|
10 | </style> | |
9 | {% endblock %} |
|
11 | {% endblock %} | |
10 | {% block content %} |
|
12 | {% block content %} | |
11 | <table class="table table-bordered"> |
|
13 | <table class="table table-bordered"> | |
12 | {% for key in dev_conf_keys %} |
|
14 | {% for key in dev_conf_keys %} | |
13 | <tr><th>{{key|title}}</th><td>{{dev_conf|attr:key}}</td></tr> |
|
15 | <tr><th>{{key|title}}</th><td>{{dev_conf|attr:key}}</td></tr> | |
14 | {% endfor %} |
|
16 | {% endfor %} | |
15 | </table> |
|
17 | </table> | |
16 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_send">Send</button> |
|
18 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_send">Send</button> | |
17 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_export">Export</button> |
|
19 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_export">Export</button> | |
18 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_edit">Edit</button> |
|
20 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_edit">Edit</button> | |
19 | <br> |
|
21 | <br> | |
20 | <h2>RC Lines</h2><hr> |
|
22 | <h2>RC Lines</h2><hr> | |
21 |
|
23 | |||
22 |
<div class="panel-group" id=" |
|
24 | <div class="panel-group" id="div_lines" role="tablist" aria-multiselectable="true"> | |
23 |
{% |
|
25 | {% include "rc_lines.html" %} | |
24 | <div class="panel panel-default" > |
|
|||
25 | <div class="panel-heading" role="tab" id="headingOne"> |
|
|||
26 | <h4 class="panel-title"> |
|
|||
27 | <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse{{line.id}}" aria-expanded="true" aria-controls="collapseOne"> |
|
|||
28 | CH{{line.channel}} - {{line.get_name}} |
|
|||
29 | </a> |
|
|||
30 | <button class="btn-xs btn-danger pull-right" name="bt_remove_line" value="{{line.pk}}"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button> |
|
|||
31 | <button class="btn-xs btn-info pull-right" name="bt_line_down" value="{{line.pk}}"><span class="glyphicon glyphicon-arrow-down" aria-hidden="true"></span></button> |
|
|||
32 | <button class="btn-xs btn-info pull-right" name="bt_line_up" value="{{line.pk}}"><span class="glyphicon glyphicon-arrow-up" aria-hidden="true"></span></button> |
|
|||
33 | </h4> |
|
|||
34 | </div> |
|
|||
35 | <div id="collapse{{line.id}}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne"> |
|
|||
36 | <div class="panel-body"> |
|
|||
37 | {% bootstrap_form line.form layout='horizontal' size='small' %} |
|
|||
38 | </div> |
|
|||
39 | </div> |
|
|||
40 | </div> |
|
|||
41 | {% endfor%} |
|
|||
42 | </div> |
|
26 | </div> | |
|
27 | ||||
43 | <br> |
|
28 | <br> | |
44 | <div class="pull-right"> |
|
29 | <div class="pull-right"> | |
45 | <button class="btn btn-primary" id="bt_add_line">Add Line</button> |
|
30 | <button class="btn btn-primary" id="bt_add_line">Add Line</button> | |
46 |
<button class="btn btn-primary" id="bt_ |
|
31 | <button class="btn btn-primary" id="bt_edit_lines"> Edit </button> | |
47 | <button class="btn btn-primary" id="bt_pulses">Pulses</button> |
|
32 | <button class="btn btn-primary" id="bt_pulses">Pulses</button> | |
48 | </div> |
|
33 | </div> | |
49 | {% endblock %} |
|
34 | {% endblock %} | |
50 |
|
35 | |||
51 |
|
36 | |||
52 | {% block extra-js%} |
|
37 | {% block extra-js%} | |
53 |
|
38 | |||
54 | <script type="text/javascript"> |
|
39 | <script type="text/javascript"> | |
55 | $(document).ready(function() { |
|
40 | ||
56 | $("#bt_edit").click(function() { |
|
41 | $("#bt_edit").click(function() { | |
57 | document.location = "{% url 'url_edit_rc_conf' dev_conf.id%}"; |
|
42 | document.location = "{% url 'url_edit_rc_conf' dev_conf.id %}"; | |
58 | }); |
|
|||
59 |
|
||||
60 | $("#bt_add_line").click(function() { |
|
|||
61 | document.location = "{% url 'url_add_rc_line' dev_conf.id%}"; |
|
|||
62 | }); |
|
43 | }); | |
63 |
|
44 | |||
64 |
$(" |
|
45 | $("#div_lines").on("click", "button[name=bt_remove_line]", function(){ | |
65 | document.location = "line/"+$(this).val()+"/delete/"; |
|
46 | document.location = "line/"+$(this).val()+"/delete/"; | |
66 |
}); |
|
47 | }); | |
67 |
|
||||
68 | $("button[name=bt_line_up]").click(function(){ |
|
|||
69 | document.location = "line/"+$(this).val()+"/up/"; |
|
|||
70 | }); |
|
|||
71 |
|
48 | |||
72 | $("button[name=bt_line_down]").click(function(){ |
|
49 | $(".panel-group").sortable({ | |
73 | document.location = "line/"+$(this).val()+"/down/"; |
|
50 | //placeholder: "ui-state-highlight", | |
74 | }); |
|
51 | update: function( event, ui ) { | |
|
52 | var sorted = $( ".panel-group" ).sortable( "serialize", { key: "item" } ); | |||
|
53 | var url = "{% url 'url_update_rc_lines' dev_conf.id %}"; | |||
|
54 | var csrf_token = "{{csrf_token}}"; | |||
|
55 | $.post( url, { 'items': sorted, 'csrfmiddlewaretoken': csrf_token }, function(data){ | |||
|
56 | $("#div_lines").html(data.html); | |||
|
57 | }); | |||
|
58 | } | |||
|
59 | }); | |||
75 |
|
60 | |||
76 |
|
61 | |||
|
62 | $("#bt_add_line").click(function() { | |||
|
63 | document.location = "{% url 'url_add_rc_line' dev_conf.id%}"; | |||
|
64 | }); | |||
77 |
|
65 | |||
78 | $(".panel-group").sortable(); |
|
66 | $("#bt_edit_lines").click(function() { | |
|
67 | document.location = "{% url 'url_edit_rc_lines' dev_conf.id %}"; | |||
|
68 | }); | |||
79 |
|
69 | |||
80 | }); |
|
|||
81 | </script> |
|
70 | </script> | |
82 | {% endblock %} No newline at end of file |
|
71 | {% endblock %} |
@@ -1,10 +1,11 | |||||
1 | from django.conf.urls import url |
|
1 | from django.conf.urls import url | |
2 |
|
2 | |||
3 | urlpatterns = ( |
|
3 | urlpatterns = ( | |
4 | url(r'^(?P<id>-?\d+)/$', 'apps.rc.views.conf', name='url_rc_conf'), |
|
4 | url(r'^(?P<id>-?\d+)/$', 'apps.rc.views.conf', name='url_rc_conf'), | |
5 | url(r'^(?P<id>-?\d+)/edit/$', 'apps.rc.views.conf_edit', name='url_edit_rc_conf'), |
|
5 | url(r'^(?P<id>-?\d+)/edit/$', 'apps.rc.views.conf_edit', name='url_edit_rc_conf'), | |
6 | url(r'^(?P<id>-?\d+)/add_line/$', 'apps.rc.views.add_line', name='url_add_rc_line'), |
|
6 | url(r'^(?P<conf_id>-?\d+)/add_line/$', 'apps.rc.views.add_line', name='url_add_rc_line'), | |
|
7 | url(r'^(?P<conf_id>-?\d+)/update_lines/$', 'apps.rc.views.update_lines', name='url_update_rc_lines'), | |||
|
8 | url(r'^(?P<conf_id>-?\d+)/edit_lines/$', 'apps.rc.views.edit_lines', name='url_edit_rc_lines'), | |||
|
9 | url(r'^(?P<conf_id>-?\d+)/add_line/(?P<line_type_id>-?\d+)/$', 'apps.rc.views.add_line', name='url_add_rc_line'), | |||
7 | url(r'^(?P<conf_id>-?\d+)/line/(?P<line_id>-?\d+)/delete/$', 'apps.rc.views.remove_line', name='url_remove_rc_line'), |
|
10 | url(r'^(?P<conf_id>-?\d+)/line/(?P<line_id>-?\d+)/delete/$', 'apps.rc.views.remove_line', name='url_remove_rc_line'), | |
8 | url(r'^(?P<conf_id>-?\d+)/line/(?P<line_id>-?\d+)/up/$', 'apps.rc.views.line_up', name='url_rc_line_up'), |
|
|||
9 | url(r'^(?P<conf_id>-?\d+)/line/(?P<line_id>-?\d+)/down/$', 'apps.rc.views.line_down', name='url_rc_line_down'), |
|
|||
10 | ) |
|
11 | ) |
@@ -1,154 +1,200 | |||||
1 | import json |
|
1 | import json | |
2 |
|
2 | |||
3 | from django.contrib import messages |
|
3 | from django.contrib import messages | |
4 | from django.shortcuts import render, redirect, get_object_or_404 |
|
4 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse | |
5 |
|
5 | |||
6 | from apps.main.models import Configuration, Experiment |
|
6 | from apps.main.models import Configuration, Experiment | |
|
7 | from apps.main.views import sidebar | |||
7 |
|
8 | |||
8 | from .models import RCConfiguration, RCLine |
|
9 | from .models import RCConfiguration, RCLine, RCLineType | |
9 | from .forms import RCConfigurationForm, RCLineForm, RCLineViewForm |
|
10 | from .forms import RCConfigurationForm, RCLineForm, RCLineViewForm, RCLineEditForm | |
10 |
|
11 | |||
11 |
|
12 | |||
12 | def conf(request, id): |
|
13 | def conf(request, id): | |
13 |
|
14 | |||
14 | conf = get_object_or_404(RCConfiguration, pk=id) |
|
15 | conf = get_object_or_404(RCConfiguration, pk=id) | |
15 |
|
16 | |||
16 | lines = RCLine.objects.filter(rc_configuration=conf).order_by('channel') |
|
17 | lines = RCLine.objects.filter(rc_configuration=conf).order_by('channel') | |
17 |
|
18 | |||
18 | for line in lines: |
|
19 | for line in lines: | |
19 | line.form = RCLineViewForm(extra_fields=json.loads(line.params)) |
|
20 | line.form = RCLineViewForm(extra_fields=json.loads(line.params)) | |
20 |
|
21 | |||
21 | kwargs = {} |
|
22 | kwargs = {} | |
22 | kwargs['dev_conf'] = conf |
|
23 | kwargs['dev_conf'] = conf | |
23 | kwargs['rc_lines'] = lines |
|
24 | kwargs['rc_lines'] = lines | |
24 | kwargs['dev_conf_keys'] = ['clock', 'ipp', 'ntx','clock_divider'] |
|
25 | kwargs['dev_conf_keys'] = ['clock', 'ipp', 'ntx','clock_divider'] | |
25 |
|
26 | |||
26 | kwargs['title'] = 'RC Configuration' |
|
27 | kwargs['title'] = 'RC Configuration' | |
27 | kwargs['suptitle'] = 'Details' |
|
28 | kwargs['suptitle'] = 'Details' | |
28 |
|
29 | |||
29 | kwargs['button'] = 'Edit Configuration' |
|
30 | kwargs['button'] = 'Edit Configuration' | |
30 |
|
31 | |||
31 | ###### SIDEBAR ###### |
|
32 | ###### SIDEBAR ###### | |
32 | experiments = Experiment.objects.filter(campaign=conf.experiment.campaign) |
|
33 | kwargs.update(sidebar(conf)) | |
33 | configurations = Configuration.objects.filter(experiment=conf.experiment) |
|
|||
34 |
|
||||
35 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] |
|
|||
36 | conf_keys = ['id', 'device__name', 'device__device_type__name', 'device__ip_address'] |
|
|||
37 |
|
||||
38 | kwargs['experiment_keys'] = exp_keys[1:] |
|
|||
39 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
|||
40 |
|
||||
41 | kwargs['configuration_keys'] = conf_keys[1:] |
|
|||
42 | kwargs['configurations'] = configurations.values(*conf_keys) |
|
|||
43 |
|
34 | |||
44 | return render(request, 'rc_conf.html', kwargs) |
|
35 | return render(request, 'rc_conf.html', kwargs) | |
45 |
|
36 | |||
46 |
|
37 | |||
47 | def conf_edit(request, id): |
|
38 | def conf_edit(request, id): | |
48 |
|
39 | |||
49 | conf = get_object_or_404(RCConfiguration, pk=id) |
|
40 | conf = get_object_or_404(RCConfiguration, pk=id) | |
50 |
|
41 | |||
51 | if request.method=='GET': |
|
42 | if request.method=='GET': | |
52 | form = RCConfigurationForm(instance=conf) |
|
43 | form = RCConfigurationForm(instance=conf) | |
53 |
|
44 | |||
54 | if request.method=='POST': |
|
45 | if request.method=='POST': | |
55 | form = RCConfigurationForm(request.POST, instance=conf) |
|
46 | form = RCConfigurationForm(request.POST, instance=conf) | |
56 |
|
47 | |||
57 | if form.is_valid(): |
|
48 | if form.is_valid(): | |
58 | form.save() |
|
49 | form.save() | |
59 |
return redirect('url_ |
|
50 | return redirect('url_dev_conf', id=id) | |
60 |
|
51 | |||
61 | kwargs = {} |
|
52 | kwargs = {} | |
|
53 | kwargs['dev_conf'] = conf | |||
62 | kwargs['form'] = form |
|
54 | kwargs['form'] = form | |
63 | kwargs['title'] = 'Device Configuration' |
|
55 | kwargs['title'] = 'Device Configuration' | |
64 | kwargs['suptitle'] = 'Edit' |
|
56 | kwargs['suptitle'] = 'Edit' | |
65 | kwargs['button'] = 'Update' |
|
57 | kwargs['button'] = 'Update' | |
66 | kwargs['previous'] = conf.get_absolute_url() |
|
58 | kwargs['previous'] = conf.get_absolute_url() | |
|
59 | ||||
|
60 | kwargs.update(sidebar(conf)) | |||
|
61 | ||||
67 | return render(request, 'rc_conf_edit.html', kwargs) |
|
62 | return render(request, 'rc_conf_edit.html', kwargs) | |
68 |
|
63 | |||
69 |
|
64 | |||
70 | def add_line(request, id): |
|
65 | def add_line(request, conf_id, line_type_id=None): | |
71 |
|
66 | |||
72 | conf = get_object_or_404(RCConfiguration, pk=id) |
|
67 | conf = get_object_or_404(RCConfiguration, pk=conf_id) | |
73 |
|
68 | |||
74 | if request.method=='GET': |
|
69 | if request.method=='GET': | |
75 | form = RCLineForm(initial={'rc_configuration':conf.id}) |
|
70 | if line_type_id: | |
|
71 | line_type = get_object_or_404(RCLineType, pk=line_type_id) | |||
|
72 | form = RCLineForm(initial={'rc_configuration':conf_id, 'line_type': line_type_id}, | |||
|
73 | extra_fields=json.loads(line_type.params)) | |||
|
74 | else: | |||
|
75 | form = RCLineForm(initial={'rc_configuration':conf_id}) | |||
76 |
|
76 | |||
77 | if request.method=='POST': |
|
77 | if request.method=='POST': | |
78 | form = RCLineForm(request.POST) |
|
78 | line_type = get_object_or_404(RCLineType, pk=line_type_id) | |
|
79 | form = RCLineForm(request.POST, extra_fields=json.loads(line_type.params)) | |||
79 |
|
80 | |||
80 | if form.is_valid(): |
|
81 | if form.is_valid(): | |
81 | form.save() |
|
82 | form.save() | |
82 |
return redirect( |
|
83 | return redirect(conf.get_absolute_url()) | |
83 |
|
84 | |||
84 | kwargs = {} |
|
85 | kwargs = {} | |
85 | kwargs['form'] = form |
|
86 | kwargs['form'] = form | |
86 | kwargs['title'] = 'RC Configuration' |
|
87 | kwargs['title'] = 'RC Configuration' | |
87 | kwargs['suptitle'] = 'Add Line' |
|
88 | kwargs['suptitle'] = 'Add Line' | |
88 | kwargs['button'] = 'Add' |
|
89 | kwargs['button'] = 'Add' | |
89 | kwargs['previous'] = conf.get_absolute_url() |
|
90 | kwargs['previous'] = conf.get_absolute_url() | |
|
91 | kwargs['dev_conf'] = conf | |||
|
92 | ||||
|
93 | kwargs.update(sidebar(conf)) | |||
|
94 | ||||
90 | return render(request, 'rc_add_line.html', kwargs) |
|
95 | return render(request, 'rc_add_line.html', kwargs) | |
91 |
|
96 | |||
92 |
|
97 | |||
93 | def remove_line(request, conf_id, line_id): |
|
98 | def remove_line(request, conf_id, line_id): | |
94 |
|
99 | |||
95 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
100 | conf = get_object_or_404(RCConfiguration, pk=conf_id) | |
96 | line = get_object_or_404(RCLine, pk=line_id) |
|
101 | line = get_object_or_404(RCLine, pk=line_id) | |
97 |
|
102 | |||
98 | if request.method == 'POST': |
|
103 | if request.method == 'POST': | |
99 | if line: |
|
104 | if line: | |
100 | try: |
|
105 | try: | |
101 | channel = line.channel |
|
106 | channel = line.channel | |
102 | line.delete() |
|
107 | line.delete() | |
103 | for ch in range(channel+1, RCLine.objects.filter(rc_configuration=conf).count()+1): |
|
108 | for ch in range(channel+1, RCLine.objects.filter(rc_configuration=conf).count()+1): | |
104 | l = RCLine.objects.get(rc_configuration=conf, channel=ch) |
|
109 | l = RCLine.objects.get(rc_configuration=conf, channel=ch) | |
105 | l.channel = l.channel-1 |
|
110 | l.channel = l.channel-1 | |
106 | l.save() |
|
111 | l.save() | |
107 | messages.success(request, 'Line: "%s" has been deleted.' % line) |
|
112 | messages.success(request, 'Line: "%s" has been deleted.' % line) | |
108 | except: |
|
113 | except: | |
109 | messages.error(request, 'Unable to delete line: "%s".' % line) |
|
114 | messages.error(request, 'Unable to delete line: "%s".' % line) | |
110 |
|
115 | |||
111 | return redirect(conf.get_absolute_url()) |
|
116 | return redirect(conf.get_absolute_url()) | |
112 |
|
117 | |||
113 | kwargs = {} |
|
118 | kwargs = {} | |
114 |
|
119 | |||
115 | kwargs['object'] = line |
|
120 | kwargs['object'] = line | |
116 | kwargs['delete_view'] = True |
|
121 | kwargs['delete_view'] = True | |
117 | kwargs['title'] = 'Confirm delete' |
|
122 | kwargs['title'] = 'Confirm delete' | |
118 | kwargs['previous'] = conf.get_absolute_url() |
|
123 | kwargs['previous'] = conf.get_absolute_url() | |
119 | return render(request, 'confirm.html', kwargs) |
|
124 | return render(request, 'confirm.html', kwargs) | |
120 |
|
125 | |||
121 |
|
126 | |||
122 |
def |
|
127 | def edit_lines(request, conf_id): | |
123 |
|
128 | |||
124 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
129 | conf = get_object_or_404(RCConfiguration, pk=conf_id) | |
125 | line = get_object_or_404(RCLine, pk=line_id) |
|
|||
126 |
|
130 | |||
127 | if line: |
|
131 | if request.method=='GET': | |
128 | ch = line.channel |
|
132 | lines = RCLine.objects.filter(rc_configuration=conf).order_by('channel') | |
129 | if ch-1>=0: |
|
133 | for line in lines: | |
130 | line0 = RCLine.objects.get(rc_configuration=conf, channel=ch-1) |
|
134 | line_type = get_object_or_404(RCLineType, pk=line.line_type.id) | |
131 | line0.channel = ch |
|
135 | extra_fields = json.loads(line_type.params) | |
132 | line0.save() |
|
136 | for item in extra_fields: | |
133 | line.channel = ch-1 |
|
137 | params = json.loads(line.params) | |
134 | line.save() |
|
138 | item['value'] = params[item['name']] | |
|
139 | line.form = RCLineEditForm(initial={'rc_configuration':conf_id, 'line_type': line.line_type.id, 'line': line.id}, | |||
|
140 | extra_fields=extra_fields) | |||
|
141 | ||||
|
142 | elif request.method=='POST': | |||
|
143 | data = {} | |||
|
144 | for label,value in request.POST.items(): | |||
|
145 | if '|' not in label: | |||
|
146 | continue | |||
|
147 | id, name = label.split('|') | |||
|
148 | if id in data: | |||
|
149 | data[id][name]=value | |||
|
150 | else: | |||
|
151 | data[id] = {name:value} | |||
|
152 | ||||
|
153 | for id, params in data.items(): | |||
|
154 | line = RCLine.objects.get(pk=id) | |||
|
155 | line.params = json.dumps(params) | |||
|
156 | line.save() | |||
|
157 | ||||
|
158 | return redirect(conf.get_absolute_url()) | |||
135 |
|
159 | |||
136 | return redirect(conf.get_absolute_url()) |
|
160 | kwargs = {} | |
|
161 | kwargs['dev_conf'] = conf | |||
|
162 | kwargs['rc_lines'] = lines | |||
|
163 | kwargs['edit'] = True | |||
|
164 | ||||
|
165 | kwargs['title'] = 'RC Configuration' | |||
|
166 | kwargs['suptitle'] = 'Edit Lines' | |||
|
167 | kwargs['button'] = 'Update' | |||
|
168 | kwargs['previous'] = conf.get_absolute_url() | |||
137 |
|
169 | |||
|
170 | ||||
|
171 | kwargs.update(sidebar(conf)) | |||
|
172 | ||||
|
173 | return render(request, 'rc_edit_lines.html', kwargs) | |||
|
174 | ||||
138 |
|
175 | |||
139 |
def |
|
176 | def update_lines(request, conf_id): | |
140 |
|
177 | |||
141 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
178 | conf = get_object_or_404(RCConfiguration, pk=conf_id) | |
142 | line = get_object_or_404(RCLine, pk=line_id) |
|
179 | ||
143 |
|
180 | if request.method=='POST': | ||
144 | if line: |
|
181 | ch = 0 | |
145 | ch = line.channel |
|
182 | for item in request.POST['items'].split('&'): | |
146 | if ch+1<RCLine.objects.filter(rc_configuration=conf).count(): |
|
183 | line = RCLine.objects.get(pk=item.split('=')[-1]) | |
147 | line1 = RCLine.objects.get(rc_configuration=conf, channel=ch+1) |
|
184 | line.channel = ch | |
148 | line1.channel = ch |
|
|||
149 | line1.save() |
|
|||
150 | line.channel = ch+1 |
|
|||
151 | line.save() |
|
185 | line.save() | |
152 |
|
186 | ch += 1 | ||
|
187 | ||||
|
188 | lines = RCLine.objects.filter(rc_configuration=conf).order_by('channel') | |||
|
189 | ||||
|
190 | for line in lines: | |||
|
191 | line.form = RCLineViewForm(extra_fields=json.loads(line.params)) | |||
|
192 | ||||
|
193 | html = render(request, 'rc_lines.html', {'rc_lines':lines}) | |||
|
194 | data = {'html': html.content} | |||
|
195 | ||||
|
196 | return HttpResponse(json.dumps(data), content_type="application/json") | |||
153 | return redirect(conf.get_absolute_url()) |
|
197 | return redirect(conf.get_absolute_url()) | |
|
198 | ||||
|
199 | ||||
154 |
|
200 |
General Comments 0
You need to be logged in to leave comments.
Login now