@@ -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%} |
@@ -454,4 +454,21 def dev_conf_delete(request, id_conf): | |||||
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,7 +1,16 | |||||
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 | |||
@@ -12,6 +21,17 class RCConfigurationForm(forms.ModelForm): | |||||
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') | |
@@ -21,15 +41,18 class RCLineForm(forms.ModelForm): | |||||
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 | |
@@ -40,4 +63,25 class RCLineViewForm(forms.Form): | |||||
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,4 +1,6 | |||||
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 | |
@@ -45,16 +47,24 class RCConfiguration(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 | |||
@@ -87,9 +97,11 class RCLine(models.Model): | |||||
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,6 +1,8 | |||||
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.*/ | |
@@ -19,31 +21,14 | |||||
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 %} | |
@@ -52,31 +37,35 | |||||
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 %} |
@@ -3,8 +3,9 from django.conf.urls import url | |||||
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,12 +1,13 | |||||
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): | |
@@ -29,17 +30,7 def conf(request, id): | |||||
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 | |||
@@ -56,30 +47,40 def conf_edit(request, id): | |||||
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 | |
@@ -87,6 +88,10 def add_line(request, id): | |||||
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 | |||
@@ -119,36 +124,77 def remove_line(request, conf_id, line_id): | |||||
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