@@ -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 | 454 | kwargs = {'object':conf, 'conf_active':'active', |
|
455 | 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 | 1 | from django.contrib import admin |
|
2 | from .models import RCConfiguration, RCLine, RCLineType | |
|
2 | from .models import RCConfiguration, RCLine, RCLineType, RCLineCode | |
|
3 | 3 | |
|
4 | 4 | # Register your models here. |
|
5 | 5 | |
|
6 | 6 | admin.site.register(RCConfiguration) |
|
7 | 7 | admin.site.register(RCLine) |
|
8 | 8 | admin.site.register(RCLineType) |
|
9 | admin.site.register(RCLineCode) |
@@ -1,7 +1,16 | |||
|
1 | 1 | import json |
|
2 | 2 | |
|
3 | 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 | 15 | class RCConfigurationForm(forms.ModelForm): |
|
7 | 16 | |
@@ -12,6 +21,17 class RCConfigurationForm(forms.ModelForm): | |||
|
12 | 21 | |
|
13 | 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 | 35 | class Meta: |
|
16 | 36 | model = RCLine |
|
17 | 37 | fields = ('rc_configuration', 'line_type', 'channel') |
@@ -21,15 +41,18 class RCLineForm(forms.ModelForm): | |||
|
21 | 41 | |
|
22 | 42 | def save(self): |
|
23 | 43 | line = super(RCLineForm, self).save() |
|
44 | ||
|
24 | 45 | #auto add channel |
|
25 | 46 | line.channel = RCLine.objects.filter(rc_configuration=line.rc_configuration).count()-1 |
|
47 | ||
|
26 | 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 | 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 | 53 | params = {} |
|
31 | for field in json.loads(line.line_type.params): | |
|
32 |
params[ |
|
|
54 | for item in self.extra_fields: | |
|
55 | params[item['name']] = self.data[item['name']] | |
|
33 | 56 | line.params = json.dumps(params) |
|
34 | 57 | line.save() |
|
35 | 58 | return |
@@ -40,4 +63,25 class RCLineViewForm(forms.Form): | |||
|
40 | 63 | extra_fields = kwargs.pop('extra_fields') |
|
41 | 64 | super(RCLineViewForm, self).__init__(*args, **kwargs) |
|
42 | 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 | 4 | from polymorphic import PolymorphicModel |
|
3 | 5 | |
|
4 | 6 | from django.db import models |
@@ -45,16 +47,24 class RCConfiguration(Configuration): | |||
|
45 | 47 | if lines: |
|
46 | 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 | 55 | class RCLineCode(models.Model): |
|
49 | 56 | |
|
50 |
name = models.CharField( |
|
|
57 | name = models.CharField(max_length=40) | |
|
51 | 58 | bits_per_code = models.PositiveIntegerField(default=0) |
|
52 | 59 | number_of_codes = models.PositiveIntegerField(default=0) |
|
53 | 60 | codes = models.TextField(blank=True, null=True) |
|
54 | 61 | |
|
55 | 62 | class Meta: |
|
56 | 63 | db_table = 'rc_line_codes' |
|
57 | ||
|
64 | ordering = ('name',) | |
|
65 | ||
|
66 | def __unicode__(self): | |
|
67 | return u'%s' % self.name | |
|
58 | 68 | |
|
59 | 69 | class RCLineType(models.Model): |
|
60 | 70 | |
@@ -87,9 +97,11 class RCLine(models.Model): | |||
|
87 | 97 | |
|
88 | 98 | chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
|
89 | 99 | |
|
90 |
if self.line_type.name in ('tx', ' |
|
|
91 | return '%s%s' % (self.line_type.name.upper(), chars[self.position]) | |
|
92 | ||
|
93 | return self.line_type.name.upper() | |
|
94 | ||
|
95 | ||
|
100 | if self.line_type.name in ('tx', 'tr',): | |
|
101 | return '%s %s' % (self.line_type.name.upper(), chars[self.position]) | |
|
102 | elif self.line_type.name in ('codes', 'windows',): | |
|
103 | pk = json.loads(self.params)['TX_ref'] | |
|
104 | ref = RCLine.objects.get(pk=pk) | |
|
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 | 1 | {% extends "dev_conf.html" %} |
|
2 | 2 | {% load static %} |
|
3 | 3 | {% load bootstrap3 %} |
|
4 | {% load main_tags %}s | |
|
5 | ||
|
4 | 6 | {% block extra-head %} |
|
5 | 7 | <style type="text/css"> |
|
6 | 8 | /* show the move cursor as the user moves the mouse over the panel header.*/ |
@@ -19,31 +21,14 | |||
|
19 | 21 | <br> |
|
20 | 22 | <h2>RC Lines</h2><hr> |
|
21 | 23 | |
|
22 |
<div class="panel-group" id=" |
|
|
23 |
{% |
|
|
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%} | |
|
24 | <div class="panel-group" id="div_lines" role="tablist" aria-multiselectable="true"> | |
|
25 | {% include "rc_lines.html" %} | |
|
42 | 26 | </div> |
|
27 | ||
|
43 | 28 | <br> |
|
44 | 29 | <div class="pull-right"> |
|
45 | 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 | 32 | <button class="btn btn-primary" id="bt_pulses">Pulses</button> |
|
48 | 33 | </div> |
|
49 | 34 | {% endblock %} |
@@ -52,31 +37,35 | |||
|
52 | 37 | {% block extra-js%} |
|
53 | 38 | |
|
54 | 39 | <script type="text/javascript"> |
|
55 | $(document).ready(function() { | |
|
40 | ||
|
56 | 41 | $("#bt_edit").click(function() { |
|
57 | 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%}"; | |
|
42 | document.location = "{% url 'url_edit_rc_conf' dev_conf.id %}"; | |
|
62 | 43 | }); |
|
63 | 44 | |
|
64 |
$(" |
|
|
45 | $("#div_lines").on("click", "button[name=bt_remove_line]", function(){ | |
|
65 | 46 | document.location = "line/"+$(this).val()+"/delete/"; |
|
66 |
}); |
|
|
67 | ||
|
68 | $("button[name=bt_line_up]").click(function(){ | |
|
69 | document.location = "line/"+$(this).val()+"/up/"; | |
|
70 | }); | |
|
47 | }); | |
|
71 | 48 | |
|
72 | $("button[name=bt_line_down]").click(function(){ | |
|
73 | document.location = "line/"+$(this).val()+"/down/"; | |
|
74 | }); | |
|
49 | $(".panel-group").sortable({ | |
|
50 | //placeholder: "ui-state-highlight", | |
|
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 | 70 | </script> |
|
82 | 71 | {% endblock %} No newline at end of file |
@@ -3,8 +3,9 from django.conf.urls import url | |||
|
3 | 3 | urlpatterns = ( |
|
4 | 4 | url(r'^(?P<id>-?\d+)/$', 'apps.rc.views.conf', name='url_rc_conf'), |
|
5 | 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 | 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 | 1 | import json |
|
2 | 2 | |
|
3 | 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 | 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 .forms import RCConfigurationForm, RCLineForm, RCLineViewForm | |
|
9 | from .models import RCConfiguration, RCLine, RCLineType | |
|
10 | from .forms import RCConfigurationForm, RCLineForm, RCLineViewForm, RCLineEditForm | |
|
10 | 11 | |
|
11 | 12 | |
|
12 | 13 | def conf(request, id): |
@@ -29,17 +30,7 def conf(request, id): | |||
|
29 | 30 | kwargs['button'] = 'Edit Configuration' |
|
30 | 31 | |
|
31 | 32 | ###### SIDEBAR ###### |
|
32 | experiments = Experiment.objects.filter(campaign=conf.experiment.campaign) | |
|
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) | |
|
33 | kwargs.update(sidebar(conf)) | |
|
43 | 34 | |
|
44 | 35 | return render(request, 'rc_conf.html', kwargs) |
|
45 | 36 | |
@@ -56,30 +47,40 def conf_edit(request, id): | |||
|
56 | 47 | |
|
57 | 48 | if form.is_valid(): |
|
58 | 49 | form.save() |
|
59 |
return redirect('url_ |
|
|
50 | return redirect('url_dev_conf', id=id) | |
|
60 | 51 | |
|
61 | 52 | kwargs = {} |
|
53 | kwargs['dev_conf'] = conf | |
|
62 | 54 | kwargs['form'] = form |
|
63 | 55 | kwargs['title'] = 'Device Configuration' |
|
64 | 56 | kwargs['suptitle'] = 'Edit' |
|
65 | 57 | kwargs['button'] = 'Update' |
|
66 | 58 | kwargs['previous'] = conf.get_absolute_url() |
|
59 | ||
|
60 | kwargs.update(sidebar(conf)) | |
|
61 | ||
|
67 | 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 | 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 | 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 | 81 | if form.is_valid(): |
|
81 | 82 | form.save() |
|
82 |
return redirect( |
|
|
83 | return redirect(conf.get_absolute_url()) | |
|
83 | 84 | |
|
84 | 85 | kwargs = {} |
|
85 | 86 | kwargs['form'] = form |
@@ -87,6 +88,10 def add_line(request, id): | |||
|
87 | 88 | kwargs['suptitle'] = 'Add Line' |
|
88 | 89 | kwargs['button'] = 'Add' |
|
89 | 90 | kwargs['previous'] = conf.get_absolute_url() |
|
91 | kwargs['dev_conf'] = conf | |
|
92 | ||
|
93 | kwargs.update(sidebar(conf)) | |
|
94 | ||
|
90 | 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 | 124 | return render(request, 'confirm.html', kwargs) |
|
120 | 125 | |
|
121 | 126 | |
|
122 |
def |
|
|
127 | def edit_lines(request, conf_id): | |
|
123 | 128 | |
|
124 | 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: | |
|
128 | ch = line.channel | |
|
129 | if ch-1>=0: | |
|
130 | line0 = RCLine.objects.get(rc_configuration=conf, channel=ch-1) | |
|
131 | line0.channel = ch | |
|
132 | line0.save() | |
|
133 | line.channel = ch-1 | |
|
134 | line.save() | |
|
131 | if request.method=='GET': | |
|
132 | lines = RCLine.objects.filter(rc_configuration=conf).order_by('channel') | |
|
133 | for line in lines: | |
|
134 | line_type = get_object_or_404(RCLineType, pk=line.line_type.id) | |
|
135 | extra_fields = json.loads(line_type.params) | |
|
136 | for item in extra_fields: | |
|
137 | params = json.loads(line.params) | |
|
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 | 178 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
142 | line = get_object_or_404(RCLine, pk=line_id) | |
|
143 | ||
|
144 | if line: | |
|
145 | ch = line.channel | |
|
146 | if ch+1<RCLine.objects.filter(rc_configuration=conf).count(): | |
|
147 | line1 = RCLine.objects.get(rc_configuration=conf, channel=ch+1) | |
|
148 | line1.channel = ch | |
|
149 | line1.save() | |
|
150 | line.channel = ch+1 | |
|
179 | ||
|
180 | if request.method=='POST': | |
|
181 | ch = 0 | |
|
182 | for item in request.POST['items'].split('&'): | |
|
183 | line = RCLine.objects.get(pk=item.split('=')[-1]) | |
|
184 | line.channel = ch | |
|
151 | 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 | 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