@@ -1,36 +1,50 | |||||
1 | from django import forms |
|
1 | from django import forms | |
2 | from apps.main.models import Device |
|
2 | from apps.main.models import Device | |
3 | from .models import DDSConfiguration |
|
3 | from .models import DDSConfiguration | |
4 |
|
4 | |||
5 | from django.core.validators import MinValueValidator, MaxValueValidator |
|
5 | # from django.core.validators import MinValueValidator, MaxValueValidator | |
6 |
|
6 | |||
7 | class DDSConfigurationForm(forms.ModelForm): |
|
7 | class DDSConfigurationForm(forms.ModelForm): | |
8 |
|
8 | |||
9 | frequency = forms.FloatField(label='Frequency (MHz)', validators=[MinValueValidator(0), MaxValueValidator(150)]) |
|
9 | # frequency_bin = forms.IntegerField(label='Frequency (Binary)', required=False) | |
10 | phase = forms.FloatField(label='Phase (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)]) |
|
10 | # phase_bin = forms.IntegerField(label='Phase (Binary)', required=False) | |
11 |
|
11 | |||
12 |
frequency_mod = forms. |
|
12 | # frequency_mod_bin = forms.IntegerField(label='Frequency Mod (Binary)', required=False) | |
13 | phase_mod = forms.FloatField(label='Phase (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)], required=False) |
|
13 | # phase_mod_bin = forms.IntegerField(label='Phase Mod (Binary)', required=False) | |
|
14 | ||||
|
15 | field_order = ['experiment', 'device', | |||
|
16 | 'clock', 'multiplier', | |||
|
17 | 'frequency', | |||
|
18 | 'frequency_bin', | |||
|
19 | 'phase', | |||
|
20 | 'phase_bin', | |||
|
21 | 'amplitude_chA', 'amplitude_chB', | |||
|
22 | 'modulation', | |||
|
23 | 'frequency_mod', | |||
|
24 | 'frequency_mod_bin', | |||
|
25 | 'phase_mod', | |||
|
26 | 'phase_mod_bin'] | |||
14 |
|
27 | |||
15 | def __init__(self, *args, **kwargs): |
|
28 | def __init__(self, *args, **kwargs): | |
16 | #request = kwargs.pop('request') |
|
29 | #request = kwargs.pop('request') | |
17 | super(DDSConfigurationForm, self).__init__(*args, **kwargs) |
|
30 | super(DDSConfigurationForm, self).__init__(*args, **kwargs) | |
18 |
|
31 | |||
19 | instance = getattr(self, 'instance', None) |
|
32 | instance = getattr(self, 'instance', None) | |
20 |
|
33 | |||
21 | if instance and instance.pk: |
|
34 | if instance and instance.pk: | |
22 |
|
35 | |||
23 | devices = Device.objects.filter(device_type__name='dds') |
|
36 | devices = Device.objects.filter(device_type__name='dds') | |
24 | items = devices.values('id', 'name', 'device_type__name', 'ip_address') |
|
|||
25 |
|
37 | |||
26 | self.fields['experiment'].widget.attrs['readonly'] = True |
|
38 | self.fields['experiment'].widget.attrs['readonly'] = True | |
27 | self.fields['device'].widget.choices = [(item['id'], '[%s]: %s | %s' % (item['device_type__name'], item['name'], item['ip_address'])) for item in items] |
|
39 | self.fields['experiment'].widget.choices = [(instance.experiment.id, instance.experiment)] | |
|
40 | ||||
|
41 | self.fields['device'].widget.choices = [(device.id, device) for device in devices] | |||
28 |
|
42 | |||
29 |
|
43 | |||
30 | def clean(self): |
|
44 | def clean(self): | |
31 | # Custom validation to force an integer when type of unit = "Unit" |
|
45 | # Custom validation to force an integer when type of unit = "Unit" | |
32 | return |
|
46 | return | |
33 |
|
47 | |||
34 | class Meta: |
|
48 | class Meta: | |
35 | model = DDSConfiguration |
|
49 | model = DDSConfiguration | |
36 | fields = ('experiment', 'device', 'clock', 'multiplier', 'modulation') |
|
50 | exclude = ('type','parameters') |
@@ -1,31 +1,77 | |||||
1 | from django.db import models |
|
1 | from django.db import models | |
2 | from apps.main.models import Configuration |
|
2 | from apps.main.models import Configuration | |
3 | # Create your models here. |
|
3 | # Create your models here. | |
4 |
|
4 | |||
5 | from django.core.validators import MinValueValidator, MaxValueValidator |
|
5 | from django.core.validators import MinValueValidator, MaxValueValidator | |
|
6 | from django.core.exceptions import ValidationError | |||
6 |
|
7 | |||
7 | MOD_TYPES = ( |
|
8 | MOD_TYPES = ( | |
8 | (None, 'Select a modulation type'), |
|
9 | (None, 'Select a modulation type'), | |
9 |
(0, ' |
|
10 | (0, 'Single Tone'), | |
10 |
(1, ' |
|
11 | (1, 'FSK'), | |
11 | (2, 'FSK'), |
|
12 | (2, 'Ramped FSK'), | |
12 |
(3, ' |
|
13 | (3, 'Chirp'), | |
|
14 | (4, 'BPSK'), | |||
13 | ) |
|
15 | ) | |
14 |
|
16 | |||
15 | class DDSConfiguration(Configuration): |
|
17 | class DDSConfiguration(Configuration): | |
16 |
|
18 | |||
17 | clock = models.FloatField(verbose_name='Clock Master (MHz)',validators=[MinValueValidator(5), MaxValueValidator(50)], blank=True, null=True) |
|
19 | DDS_NBITS = 48 | |
|
20 | ||||
|
21 | clock = models.FloatField(verbose_name='Clock Master (MHz)',validators=[MinValueValidator(5), MaxValueValidator(75)]) | |||
18 | multiplier = models.PositiveIntegerField(verbose_name='Multiplier',validators=[MinValueValidator(1), MaxValueValidator(20)], default=4) |
|
22 | multiplier = models.PositiveIntegerField(verbose_name='Multiplier',validators=[MinValueValidator(1), MaxValueValidator(20)], default=4) | |
19 | freq_reg = models.PositiveIntegerField(verbose_name='Frequency (Binary)',validators=[MinValueValidator(0), MaxValueValidator(2**32-1)], blank=True, null=True) |
|
23 | ||
20 |
|
|
24 | frequency = models.DecimalField(verbose_name='Frequency (MHz)', validators=[MinValueValidator(0), MaxValueValidator(150)], max_digits=17, decimal_places=15) | |
|
25 | frequency_bin = models.BigIntegerField(verbose_name='Frequency (Binary)',validators=[MinValueValidator(0), MaxValueValidator(2**DDS_NBITS-1)]) | |||
21 |
|
26 | |||
22 |
|
|
27 | phase = models.FloatField(verbose_name='Phase (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)]) | |
23 |
|
|
28 | # phase_binary = models.PositiveIntegerField(verbose_name='Phase (Binary)',validators=[MinValueValidator(0), MaxValueValidator(2**14-1)]) | |
|
29 | ||||
|
30 | amplitude_ch_A = models.PositiveIntegerField(verbose_name='Amplitude CHA',validators=[MinValueValidator(0), MaxValueValidator(2**10-1)], blank=True, null=True) | |||
|
31 | amplitude_ch_B = models.PositiveIntegerField(verbose_name='Amplitude CHB',validators=[MinValueValidator(0), MaxValueValidator(2**10-1)], blank=True, null=True) | |||
24 |
|
32 | |||
25 | modulation = models.PositiveIntegerField(choices = MOD_TYPES, default = 0) |
|
33 | modulation = models.PositiveIntegerField(choices = MOD_TYPES, default = 0) | |
26 | freq_reg_mod = models.PositiveIntegerField(verbose_name='Frequency Mod (Binary)',validators=[MinValueValidator(0), MaxValueValidator(2**32-1)], blank=True, null=True) |
|
34 | ||
27 |
|
|
35 | frequency_mod = models.DecimalField(verbose_name='Frequency Mod. (MHz)', validators=[MinValueValidator(0), MaxValueValidator(150)], max_digits=17, decimal_places=15, blank=True, null=True) | |
|
36 | frequency_mod_bin = models.BigIntegerField(verbose_name='Frequency Mod. (Binary)',validators=[MinValueValidator(0), MaxValueValidator(2**DDS_NBITS-1)], blank=True, null=True) | |||
|
37 | ||||
|
38 | phase_mod = models.FloatField(verbose_name='Phase Mod. (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)], blank=True, null=True) | |||
|
39 | # phase_binary_mod = models.PositiveIntegerField(verbose_name='Phase Mod (Binary)',validators=[MinValueValidator(0), MaxValueValidator(2**14-1)], blank=True, null=True) | |||
|
40 | ||||
|
41 | def get_nbits(self): | |||
|
42 | ||||
|
43 | return self.DDS_NBITS | |||
|
44 | ||||
|
45 | def clean(self): | |||
|
46 | ||||
|
47 | if self.modulation in [1,2,3]: | |||
|
48 | if self.frequency_mod is None or self.frequency_mod_bin is None: | |||
|
49 | raise ValidationError({ | |||
|
50 | 'frequency_mod': 'Frequency modulation has to be defined when FSK or Chirp modulation is selected' | |||
|
51 | }) | |||
|
52 | ||||
|
53 | if self.modulation in [4,]: | |||
|
54 | if self.phase_mod is None: | |||
|
55 | raise ValidationError({ | |||
|
56 | 'phase_mod': 'Phase modulation has to be defined when BPSK modulation is selected' | |||
|
57 | }) | |||
|
58 | ||||
|
59 | def verify_frequencies(self): | |||
|
60 | ||||
|
61 | return True | |||
|
62 | ||||
|
63 | def freq2binary(self, freq, mclock): | |||
|
64 | ||||
|
65 | binary = (float(freq)/mclock)*(2**self.DDS_NBITS) | |||
|
66 | ||||
|
67 | return binary | |||
|
68 | ||||
|
69 | def binary2freq(self, binary, mclock): | |||
|
70 | ||||
|
71 | freq = (float(binary)/(2**self.DDS_NBITS))*mclock | |||
|
72 | ||||
|
73 | return freq | |||
28 |
|
74 | |||
29 | class Meta: |
|
75 | class Meta: | |
30 | db_table = 'dds_configurations' |
|
76 | db_table = 'dds_configurations' | |
31 | No newline at end of file |
|
77 |
@@ -1,11 +1,68 | |||||
1 |
{% extends " |
|
1 | {% extends "base.html" %} | |
|
2 | {% load bootstrap3 %} | |||
|
3 | {% load static %} | |||
|
4 | {% load main_tags %} | |||
|
5 | ||||
|
6 | {% block conf-active %}active{% endblock %} | |||
|
7 | ||||
|
8 | {% block content-title %}{{title}}{% endblock %} | |||
|
9 | {% block content-suptitle %}{{suptitle}}{% endblock %} | |||
|
10 | ||||
|
11 | {% block content %} | |||
|
12 | ||||
|
13 | <table class="table table-bordered"> | |||
|
14 | <tr><th>Status</th><td>{%if connected == True %} ☘ Connected {% else %} ⛔ Disconnected {% endif %}</td></tr> | |||
|
15 | {% for item in dev_conf_keys %} | |||
|
16 | <tr><th>{{item|title}}</th><td>{{dev_conf|attr:item}}</td></tr> | |||
|
17 | {% endfor %} | |||
|
18 | ||||
|
19 | <tr><th>{{form.modulation.label}}</th><td>{{form.modulation}}</td></tr> | |||
|
20 | ||||
|
21 | {% if form.modulation.value == 0 %} | |||
|
22 | {% endif %} | |||
|
23 | ||||
|
24 | {% if form.modulation.value == 1 %} | |||
|
25 | <tr><th>{{form.frequency_mod.label}}</th><td>{{form.frequency_mod.value}}</td></tr> | |||
|
26 | {% endif %} | |||
|
27 | ||||
|
28 | {% if form.modulation.value == 2 %} | |||
|
29 | <tr><th>{{form.frequency_mod.label}}</th><td>{{form.frequency_mod.value}}</td></tr> | |||
|
30 | {% endif %} | |||
|
31 | ||||
|
32 | {% if form.modulation.value == 3 %} | |||
|
33 | <tr><th>{{form.frequency_mod.label}}</th><td>{{form.frequency_mod.value}}</td></tr> | |||
|
34 | {% endif %} | |||
|
35 | ||||
|
36 | {% if form.modulation.value == 4 %} | |||
|
37 | <tr><th>{{form.phase_mod.label}}</th><td>{{form.phase_mod.value}}</td></tr> | |||
|
38 | {% endif %} | |||
|
39 | </table> | |||
|
40 | ||||
|
41 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_read">Read</button> | |||
|
42 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_write">Write</button> | |||
|
43 | <button class="btn btn-primary pull-left" style="margin-left: 10px" id="bt_export">Export</button> | |||
|
44 | <button class="btn btn-primary pull-left" style="margin-left: 10px" id="bt_edit">Edit</button> | |||
|
45 | <br></br> | |||
|
46 | {% endblock %} | |||
|
47 | ||||
|
48 | {% block sidebar%} | |||
|
49 | {% include "sidebar_devices.html" %} | |||
|
50 | {% endblock %} | |||
2 |
|
51 | |||
3 | {% block extra-js%} |
|
52 | {% block extra-js%} | |
4 | <script type="text/javascript"> |
|
53 | <script type="text/javascript"> | |
5 |
|
54 | |||
6 | $("#bt_edit").click(function() { |
|
55 | $("#bt_edit").click(function() { | |
7 | document.location = "{% url 'url_edit_dds_conf' dev_conf.id%}"; |
|
56 | document.location = "{% url 'url_edit_dds_conf' dev_conf.id%}"; | |
8 | }); |
|
57 | }); | |
9 |
|
58 | |||
|
59 | $("#bt_write").click(function() { | |||
|
60 | document.location = "{% url 'url_dds_conf_write' dev_conf.id%}"; | |||
|
61 | }); | |||
|
62 | ||||
|
63 | $("#bt_read").click(function() { | |||
|
64 | document.location = "{% url 'url_dds_conf_read' dev_conf.id%}"; | |||
|
65 | }); | |||
|
66 | ||||
10 | </script> |
|
67 | </script> | |
11 | {% endblock %} No newline at end of file |
|
68 | {% endblock %} |
@@ -1,1 +1,90 | |||||
1 | {% extends "dev_conf_edit.html" %} No newline at end of file |
|
1 | {% extends "dev_conf_edit.html" %} | |
|
2 | {% load bootstrap3 %} | |||
|
3 | {% load static %} | |||
|
4 | {% load main_tags %} | |||
|
5 | ||||
|
6 | {% block extra-js%} | |||
|
7 | <script type="text/javascript"> | |||
|
8 | ||||
|
9 | $("#bt_cancel").click(function() { | |||
|
10 | document.location = "{% url 'url_dds_conf' id_dev%}"; | |||
|
11 | }); | |||
|
12 | ||||
|
13 | $("#bt_read").click(function() { | |||
|
14 | document.location = "{% url 'url_dds_conf_read' id_dev%}"; | |||
|
15 | }); | |||
|
16 | ||||
|
17 | $("#id_clock").on('change', function() { | |||
|
18 | updateFrequencies(); | |||
|
19 | }); | |||
|
20 | ||||
|
21 | $("#id_multiplier").on('change', function() { | |||
|
22 | updateFrequencies(); | |||
|
23 | }); | |||
|
24 | ||||
|
25 | $("#id_frequency").on('change', function() { | |||
|
26 | updateBinaryFrequencies(); | |||
|
27 | }); | |||
|
28 | ||||
|
29 | $("#id_frequency_bin").on('change', function() { | |||
|
30 | updateFrequencies(); | |||
|
31 | }); | |||
|
32 | ||||
|
33 | $("#id_frequency_mod").on('change', function() { | |||
|
34 | updateBinaryFrequencies(); | |||
|
35 | }); | |||
|
36 | ||||
|
37 | $("#id_frequency_mod_bin").on('change', function() { | |||
|
38 | updateFrequencies(); | |||
|
39 | }); | |||
|
40 | ||||
|
41 | function updateBinaryFrequencies() { | |||
|
42 | ||||
|
43 | var clock = $("#id_clock").val(); | |||
|
44 | var multiplier = $("#id_multiplier").val(); | |||
|
45 | var freq = $("#id_frequency").val(); | |||
|
46 | var freq_mod = $("#id_frequency_mod").val(); | |||
|
47 | ||||
|
48 | var mclock = clock*multiplier; | |||
|
49 | var k = Math.pow(2,48)/mclock; | |||
|
50 | ||||
|
51 | var freq_bin = parseInt(freq*k); | |||
|
52 | var freq_mod_bin = parseInt(freq_mod*k); | |||
|
53 | ||||
|
54 | $("#id_frequency_bin").val(freq_bin); | |||
|
55 | $("#id_frequency_mod_bin").val(freq_mod_bin); | |||
|
56 | ||||
|
57 | freq = freq_bin/k; | |||
|
58 | freq_mod = freq_mod_bin/k; | |||
|
59 | ||||
|
60 | $("#id_frequency").val(freq); | |||
|
61 | $("#id_frequency_mod").val(freq_mod); | |||
|
62 | ||||
|
63 | } | |||
|
64 | ||||
|
65 | function updateFrequencies() { | |||
|
66 | ||||
|
67 | var clock = $("#id_clock").val(); | |||
|
68 | var multiplier = $("#id_multiplier").val(); | |||
|
69 | var freq_bin = $("#id_frequency_bin").val(); | |||
|
70 | var freq_mod_bin = $("#id_frequency_mod_bin").val(); | |||
|
71 | ||||
|
72 | var mclock = clock*multiplier; | |||
|
73 | var k = Math.pow(2,48)/mclock; | |||
|
74 | ||||
|
75 | var freq = parseInt(freq_bin)/k; | |||
|
76 | var freq_mod = parseInt(freq_mod_bin)/k; | |||
|
77 | ||||
|
78 | $("#id_frequency").val(freq); | |||
|
79 | $("#id_frequency_mod").val(freq_mod); | |||
|
80 | ||||
|
81 | var freq_bin = parseInt(freq*k); | |||
|
82 | var freq_mod_bin = parseInt(freq_mod*k); | |||
|
83 | ||||
|
84 | $("#id_frequency_bin").val(freq_bin); | |||
|
85 | $("#id_frequency_mod_bin").val(freq_mod_bin); | |||
|
86 | ||||
|
87 | } | |||
|
88 | ||||
|
89 | </script> | |||
|
90 | {% endblock %} No newline at end of file |
@@ -1,6 +1,9 | |||||
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_conf>-?\d+)/$', 'apps.dds.views.dds_conf', name='url_dds_conf'), |
|
4 | url(r'^(?P<id_conf>-?\d+)/$', 'apps.dds.views.dds_conf', name='url_dds_conf'), | |
|
5 | url(r'^(?P<id_conf>-?\d+)/(?P<message>-?\d+)/$', 'apps.dds.views.dds_conf', name='url_dds_conf'), | |||
5 | url(r'^(?P<id_conf>-?\d+)/edit/$', 'apps.dds.views.dds_conf_edit', name='url_edit_dds_conf'), |
|
6 | url(r'^(?P<id_conf>-?\d+)/edit/$', 'apps.dds.views.dds_conf_edit', name='url_edit_dds_conf'), | |
|
7 | url(r'^(?P<id_conf>-?\d+)/write/$', 'apps.dds.views.dds_conf_write', name='url_dds_conf_write'), | |||
|
8 | url(r'^(?P<id_conf>-?\d+)/read/$', 'apps.dds.views.dds_conf_read', name='url_dds_conf_read'), | |||
6 | ) |
|
9 | ) |
@@ -1,63 +1,161 | |||||
1 | # Create your views here. |
|
1 | # Create your views here. | |
2 |
|
2 | from django.contrib import messages | ||
3 | from django.shortcuts import redirect, render, get_object_or_404 |
|
3 | from django.shortcuts import redirect, render, get_object_or_404 | |
4 |
|
4 | |||
5 | from apps.main.models import Experiment, Configuration |
|
5 | from apps.main.models import Experiment, Configuration | |
|
6 | from apps.main.views import sidebar | |||
|
7 | ||||
6 | from .models import DDSConfiguration |
|
8 | from .models import DDSConfiguration | |
7 | from .forms import DDSConfigurationForm |
|
9 | from .forms import DDSConfigurationForm | |
8 | # Create your views here. |
|
10 | # Create your views here. | |
9 |
|
11 | |||
|
12 | from radarsys_api import jro_device, dds | |||
|
13 | ||||
10 | def dds_conf(request, id_conf): |
|
14 | def dds_conf(request, id_conf): | |
11 |
|
15 | |||
12 | conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
16 | conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
13 |
|
17 | |||
|
18 | if request.method=='GET': | |||
|
19 | form = DDSConfigurationForm(instance=conf) | |||
|
20 | ||||
|
21 | answer = dds.echo(ip=str(conf.device.ip_address), port=conf.device.port_address) | |||
|
22 | ||||
14 | kwargs = {} |
|
23 | kwargs = {} | |
|
24 | kwargs['connected'] = (answer[0] == "1") | |||
|
25 | kwargs['form'] = form | |||
|
26 | ||||
15 | kwargs['dev_conf'] = conf |
|
27 | kwargs['dev_conf'] = conf | |
16 | kwargs['dev_conf_keys'] = ['experiment', 'device', |
|
28 | kwargs['dev_conf_keys'] = ['experiment', 'device', | |
17 | 'clock', 'multiplier', |
|
29 | 'clock', 'multiplier', | |
18 |
'freq |
|
30 | 'frequency', | |
19 |
' |
|
31 | # 'frequency_bin', | |
20 |
' |
|
32 | 'phase', | |
21 |
' |
|
33 | # 'phase_binary', | |
|
34 | 'amplitude_ch_A', 'amplitude_ch_B'] | |||
|
35 | # 'modulation', | |||
|
36 | # 'frequency_mod', | |||
|
37 | # 'frequency_mod_bin', | |||
|
38 | # 'phase_mod'] | |||
|
39 | # 'phase_binary_mod'] | |||
22 |
|
40 | |||
23 | kwargs['title'] = 'DDS Configuration' |
|
41 | kwargs['title'] = 'DDS Configuration' | |
24 | kwargs['suptitle'] = 'Details' |
|
42 | kwargs['suptitle'] = 'Details' | |
25 |
|
43 | |||
26 | kwargs['button'] = 'Edit Configuration' |
|
44 | kwargs['button'] = 'Edit Configuration' | |
27 |
|
45 | |||
28 | ###### SIDEBAR ###### |
|
46 | ###### SIDEBAR ###### | |
29 | experiments = Experiment.objects.filter(campaign=conf.experiment.campaign) |
|
47 | kwargs.update(sidebar(conf)) | |
30 | configurations = Configuration.objects.filter(experiment=conf.experiment) |
|
|||
31 |
|
||||
32 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] |
|
|||
33 | conf_keys = ['id', 'device__name', 'device__device_type__name', 'device__ip_address'] |
|
|||
34 |
|
||||
35 | kwargs['experiment_keys'] = exp_keys[1:] |
|
|||
36 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
|||
37 |
|
||||
38 | kwargs['configuration_keys'] = conf_keys[1:] |
|
|||
39 | kwargs['configurations'] = configurations.values(*conf_keys) |
|
|||
40 |
|
48 | |||
41 | return render(request, 'dds_conf.html', kwargs) |
|
49 | return render(request, 'dds_conf.html', kwargs) | |
42 |
|
50 | |||
43 | def dds_conf_edit(request, id_conf): |
|
51 | def dds_conf_edit(request, id_conf): | |
44 |
|
52 | |||
45 | conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
53 | conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
46 |
|
54 | |||
47 | if request.method=='GET': |
|
55 | if request.method=='GET': | |
48 | form = DDSConfigurationForm(instance=conf) |
|
56 | form = DDSConfigurationForm(instance=conf) | |
49 |
|
57 | |||
50 | if request.method=='POST': |
|
58 | if request.method=='POST': | |
51 | form = DDSConfigurationForm(request.POST, instance=conf) |
|
59 | form = DDSConfigurationForm(request.POST, instance=conf) | |
52 |
|
60 | |||
53 | if form.is_valid(): |
|
61 | if form.is_valid(): | |
54 | form.save() |
|
62 | conf = form.save(commit=False) | |
55 | return redirect('url_dds_conf', id_conf=id_conf) |
|
63 | ||
|
64 | if conf.verify_frequencies(): | |||
|
65 | ||||
|
66 | conf.save() | |||
|
67 | return redirect('url_dds_conf', id_conf=conf.id) | |||
|
68 | ||||
|
69 | ##ERRORS | |||
56 |
|
70 | |||
57 | kwargs = {} |
|
71 | kwargs = {} | |
|
72 | kwargs['id_dev'] = conf.id | |||
58 | kwargs['form'] = form |
|
73 | kwargs['form'] = form | |
59 | kwargs['title'] = 'Device Configuration' |
|
74 | kwargs['title'] = 'Device Configuration' | |
60 | kwargs['suptitle'] = 'Edit' |
|
75 | kwargs['suptitle'] = 'Edit' | |
61 |
kwargs['button'] = ' |
|
76 | kwargs['button'] = 'Save' | |
|
77 | kwargs['dds_nbits'] = conf.get_nbits() | |||
|
78 | ||||
|
79 | ###### SIDEBAR ###### | |||
|
80 | kwargs.update(sidebar(conf)) | |||
|
81 | ||||
|
82 | return render(request, 'dds_conf_edit.html', kwargs) | |||
|
83 | ||||
|
84 | def dds_conf_write(request, id_conf): | |||
|
85 | ||||
|
86 | conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |||
|
87 | ||||
|
88 | answer = dds.write_config(ip=str(conf.device.ip_address), | |||
|
89 | port=conf.device.port_address, | |||
|
90 | clock=conf.clock, | |||
|
91 | multiplier=conf.multiplier, | |||
|
92 | freq_regA=conf.frequency_bin, | |||
|
93 | freq_regB=conf.frequency_mod_bin, | |||
|
94 | modulation=conf.modulation, | |||
|
95 | phaseA=conf.phase, | |||
|
96 | phaseB=conf.phase_mod, | |||
|
97 | amplitude0=conf.amplitude_ch_A, | |||
|
98 | amplitude1=conf.amplitude_ch_B) | |||
|
99 | ||||
|
100 | if answer[0] == "1": | |||
|
101 | messages.success(request, answer[2:]) | |||
|
102 | else: | |||
|
103 | messages.error(request, answer) | |||
|
104 | ||||
|
105 | return redirect('url_dds_conf', id_conf=conf.id) | |||
|
106 | ||||
|
107 | def dds_conf_read(request, id_conf): | |||
|
108 | ||||
|
109 | conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |||
|
110 | ||||
|
111 | if request.method=='POST': | |||
|
112 | form = DDSConfigurationForm(request.POST, instance=conf) | |||
|
113 | ||||
|
114 | if form.is_valid(): | |||
|
115 | dds_model = form.save(commit=False) | |||
|
116 | ||||
|
117 | if dds_model.verify_frequencies(): | |||
|
118 | ||||
|
119 | dds_model.save() | |||
|
120 | return redirect('url_dds_conf', id_conf=conf.id) | |||
|
121 | ||||
|
122 | parms = None | |||
|
123 | ||||
|
124 | if request.method=='GET': | |||
|
125 | ||||
|
126 | #mult, freqA, freqB, modulation, phaseA, phaseB, amp0, amp1 | |||
|
127 | parms = dds.read_config(ip=conf.device.ip_address, | |||
|
128 | port=conf.device.port_address) | |||
|
129 | ||||
|
130 | if parms is None: | |||
|
131 | return redirect('url_dds_conf', id_conf=conf.id) | |||
|
132 | ||||
|
133 | data = {'experiment' : conf.experiment.id, | |||
|
134 | 'device' : conf.device.id, | |||
|
135 | 'clock' : conf.clock, | |||
|
136 | 'multiplier' : parms[0], | |||
|
137 | 'frequency' : conf.binary2freq(parms[1], parms[0]*conf.clock), | |||
|
138 | 'frequency_bin' : parms[1], | |||
|
139 | 'phase' : parms[4], | |||
|
140 | 'amplitude_ch_A' : parms[6], | |||
|
141 | 'amplitude_ch_B' : parms[7], | |||
|
142 | 'modulation' : parms[3], | |||
|
143 | 'frequency_mod' : conf.binary2freq(parms[2], parms[0]*conf.clock), | |||
|
144 | 'frequency_mod_bin' : parms[2], | |||
|
145 | 'phase_mod' : parms[5], | |||
|
146 | } | |||
|
147 | ||||
|
148 | form = DDSConfigurationForm(data) | |||
|
149 | ||||
|
150 | kwargs = {} | |||
|
151 | kwargs['id_dev'] = conf.id | |||
|
152 | kwargs['form'] = form | |||
|
153 | kwargs['title'] = 'Device Configuration' | |||
|
154 | kwargs['suptitle'] = 'Parameters read from device' | |||
|
155 | kwargs['button'] = 'Save' | |||
|
156 | kwargs['dds_nbits'] = conf.get_nbits() | |||
|
157 | ||||
|
158 | ###### SIDEBAR ###### | |||
|
159 | kwargs.update(sidebar(conf)) | |||
62 |
|
160 | |||
63 | return render(request, 'dds_conf_edit.html', kwargs) No newline at end of file |
|
161 | return render(request, 'dds_conf_edit.html', kwargs) |
@@ -1,15 +1,20 | |||||
1 | from django import forms |
|
1 | from django import forms | |
2 | from apps.main.models import Device |
|
2 | from apps.main.models import Device | |
3 | from .models import JARSConfiguration |
|
3 | from .models import JARSConfiguration | |
4 |
|
4 | |||
5 | class JARSConfigurationForm(forms.ModelForm): |
|
5 | class JARSConfigurationForm(forms.ModelForm): | |
6 | def __init__(self, *args, **kwargs): |
|
6 | def __init__(self, *args, **kwargs): | |
7 | super(JARSConfigurationForm, self).__init__(*args, **kwargs) |
|
7 | super(JARSConfigurationForm, self).__init__(*args, **kwargs) | |
8 | instance = getattr(self, 'instance', None) |
|
8 | instance = getattr(self, 'instance', None) | |
|
9 | ||||
9 | if instance and instance.pk: |
|
10 | if instance and instance.pk: | |
10 | self.fields['experiment'].widget.attrs['disabled'] = True |
|
11 | devices = Device.objects.filter(device_type__name='jars') | |
11 | self.fields['device'].widget.choices = [(item['id'], '%s | %s' % (item['device_type__name'], item['ip_address'])) for item in Device.objects.filter(device_type__name='jars').values('id', 'device_type__name', 'ip_address')] |
|
12 | ||
12 |
|
13 | self.fields['experiment'].widget.attrs['readonly'] = True | ||
|
14 | self.fields['experiment'].widget.choices = [(instance.experiment.id, instance.experiment)] | |||
|
15 | ||||
|
16 | self.fields['device'].widget.choices = [(device.id, device) for device in devices] | |||
|
17 | ||||
13 | class Meta: |
|
18 | class Meta: | |
14 | model = JARSConfiguration |
|
19 | model = JARSConfiguration | |
15 | exclude = ('parameters', 'status') |
|
20 | exclude = ('parameters', 'status') |
@@ -1,36 +1,38 | |||||
1 | {% extends "base.html" %} |
|
1 | {% extends "base.html" %} | |
2 | {% load bootstrap3 %} |
|
2 | {% load bootstrap3 %} | |
3 | {% load static %} |
|
3 | {% load static %} | |
4 | {% load main_tags %} |
|
4 | {% load main_tags %} | |
5 |
|
5 | |||
6 | {% block conf-active %}active{% endblock %} |
|
6 | {% block conf-active %}active{% endblock %} | |
7 |
|
7 | |||
8 | {% block content-title %}{{title}}{% endblock %} |
|
8 | {% block content-title %}{{title}}{% endblock %} | |
9 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
9 | {% block content-suptitle %}{{suptitle}}{% endblock %} | |
10 |
|
10 | |||
11 | {% block content %} |
|
11 | {% block content %} | |
|
12 | ||||
12 | <table class="table table-bordered"> |
|
13 | <table class="table table-bordered"> | |
|
14 | <tr><th>Status</th><td>{%if connected == True %} ☘ Connected {% else %} ⛔ Disconnected {% endif %}</td></tr> | |||
13 | {% for key in dev_conf_keys %} |
|
15 | {% for key in dev_conf_keys %} | |
14 | <tr><th>{{key|title}}</th><td>{{dev_conf|attr:key}}</td></tr> |
|
16 | <tr><th>{{key|title}}</th><td>{{dev_conf|attr:key}}</td></tr> | |
15 | {% endfor %} |
|
17 | {% endfor %} | |
16 | </table> |
|
18 | </table> | |
|
19 | ||||
17 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_send">Send</button> |
|
20 | <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_export">Export</button> |
|
21 | <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_edit">Edit</button> |
|
22 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_edit">Edit</button> | |
20 | <br></br> |
|
23 | <br></br> | |
21 | <br></br> |
|
|||
22 | {% endblock %} |
|
24 | {% endblock %} | |
23 |
|
25 | |||
24 | {% block sidebar%} |
|
26 | {% block sidebar%} | |
25 | {% include "sidebar_devices.html" %} |
|
27 | {% include "sidebar_devices.html" %} | |
26 | {% endblock %} |
|
28 | {% endblock %} | |
27 |
|
29 | |||
28 | {% block extra-js%} |
|
30 | {% block extra-js%} | |
29 | <script type="text/javascript"> |
|
31 | <script type="text/javascript"> | |
30 |
|
32 | |||
31 | $("#bt_edit").click(function() { |
|
33 | $("#bt_edit").click(function() { | |
32 | document.location = "{% url 'url_edit_dev_conf' dev_conf.id%}"; |
|
34 | document.location = "{% url 'url_edit_dev_conf' dev_conf.id%}"; | |
33 | }); |
|
35 | }); | |
34 |
|
36 | |||
35 | </script> |
|
37 | </script> | |
36 | {% endblock %} No newline at end of file |
|
38 | {% endblock %} |
@@ -1,474 +1,477 | |||||
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) |
|
457 | return render(request, 'item_delete.html', kwargs) | |
458 |
|
458 | |||
459 | def sidebar(conf): |
|
459 | def sidebar(conf): | |
460 |
|
460 | |||
461 | experiments = Experiment.objects.filter(campaign=conf.experiment.campaign) |
|
461 | experiments = Experiment.objects.filter(campaign=conf.experiment.campaign) | |
462 | configurations = Configuration.objects.filter(experiment=conf.experiment) |
|
462 | configurations = Configuration.objects.filter(experiment=conf.experiment) | |
463 |
|
463 | |||
464 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] |
|
464 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] | |
465 | conf_keys = ['id', 'device__name', 'device__device_type__name', 'device__ip_address'] |
|
465 | conf_keys = ['id', 'device__name', 'device__device_type__name', 'device__ip_address'] | |
466 |
|
466 | |||
467 | kwargs = {} |
|
467 | kwargs = {} | |
|
468 | ||||
|
469 | kwargs['dev_conf'] = conf | |||
|
470 | ||||
468 | kwargs['experiment_keys'] = exp_keys[1:] |
|
471 | kwargs['experiment_keys'] = exp_keys[1:] | |
469 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
472 | kwargs['experiments'] = experiments.values(*exp_keys) | |
470 |
|
473 | |||
471 | kwargs['configuration_keys'] = conf_keys[1:] |
|
474 | kwargs['configuration_keys'] = conf_keys[1:] | |
472 | kwargs['configurations'] = configurations.values(*conf_keys) |
|
475 | kwargs['configurations'] = configurations.values(*conf_keys) | |
473 |
|
476 | |||
474 | return kwargs No newline at end of file |
|
477 | return kwargs |
General Comments 0
You need to be logged in to leave comments.
Login now