@@ -1,36 +1,50 | |||
|
1 | 1 | from django import forms |
|
2 | 2 | from apps.main.models import Device |
|
3 | 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 | 7 | class DDSConfigurationForm(forms.ModelForm): |
|
8 | 8 | |
|
9 | frequency = forms.FloatField(label='Frequency (MHz)', validators=[MinValueValidator(0), MaxValueValidator(150)]) | |
|
10 | phase = forms.FloatField(label='Phase (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)]) | |
|
9 | # frequency_bin = forms.IntegerField(label='Frequency (Binary)', required=False) | |
|
10 | # phase_bin = forms.IntegerField(label='Phase (Binary)', required=False) | |
|
11 | 11 | |
|
12 |
frequency_mod = forms. |
|
|
13 | phase_mod = forms.FloatField(label='Phase (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)], required=False) | |
|
12 | # frequency_mod_bin = forms.IntegerField(label='Frequency Mod (Binary)', 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 | 28 | def __init__(self, *args, **kwargs): |
|
16 | 29 | #request = kwargs.pop('request') |
|
17 | 30 | super(DDSConfigurationForm, self).__init__(*args, **kwargs) |
|
18 | 31 | |
|
19 | 32 | instance = getattr(self, 'instance', None) |
|
20 | 33 | |
|
21 | 34 | if instance and instance.pk: |
|
22 | 35 | |
|
23 | 36 | devices = Device.objects.filter(device_type__name='dds') |
|
24 | items = devices.values('id', 'name', 'device_type__name', 'ip_address') | |
|
25 | 37 | |
|
26 | 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 | 44 | def clean(self): |
|
31 | 45 | # Custom validation to force an integer when type of unit = "Unit" |
|
32 | 46 | return |
|
33 | 47 | |
|
34 | 48 | class Meta: |
|
35 | 49 | model = DDSConfiguration |
|
36 | fields = ('experiment', 'device', 'clock', 'multiplier', 'modulation') | |
|
50 | exclude = ('type','parameters') |
@@ -1,31 +1,77 | |||
|
1 | 1 | from django.db import models |
|
2 | 2 | from apps.main.models import Configuration |
|
3 | 3 | # Create your models here. |
|
4 | 4 | |
|
5 | 5 | from django.core.validators import MinValueValidator, MaxValueValidator |
|
6 | from django.core.exceptions import ValidationError | |
|
6 | 7 | |
|
7 | 8 | MOD_TYPES = ( |
|
8 | 9 | (None, 'Select a modulation type'), |
|
9 |
(0, ' |
|
|
10 |
(1, ' |
|
|
11 | (2, 'FSK'), | |
|
12 |
(3, ' |
|
|
10 | (0, 'Single Tone'), | |
|
11 | (1, 'FSK'), | |
|
12 | (2, 'Ramped FSK'), | |
|
13 | (3, 'Chirp'), | |
|
14 | (4, 'BPSK'), | |
|
13 | 15 | ) |
|
14 | 16 | |
|
15 | 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 | 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) | |
|
20 |
|
|
|
23 | ||
|
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 |
|
|
|
23 |
|
|
|
27 | phase = models.FloatField(verbose_name='Phase (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)]) | |
|
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 | 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) | |
|
27 |
|
|
|
34 | ||
|
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 | 75 | class Meta: |
|
30 | 76 | db_table = 'dds_configurations' |
|
31 | 77 | No newline at end of file |
@@ -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 | 52 | {% block extra-js%} |
|
4 | 53 | <script type="text/javascript"> |
|
5 | 54 | |
|
6 | 55 | $("#bt_edit").click(function() { |
|
7 | 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 | 67 | </script> |
|
11 | 68 | {% endblock %} No newline at end of file |
@@ -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 | 1 | from django.conf.urls import url |
|
2 | 2 | |
|
3 | 3 | urlpatterns = ( |
|
4 | 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 | 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 | 1 | # Create your views here. |
|
2 | ||
|
2 | from django.contrib import messages | |
|
3 | 3 | from django.shortcuts import redirect, render, get_object_or_404 |
|
4 | 4 | |
|
5 | 5 | from apps.main.models import Experiment, Configuration |
|
6 | from apps.main.views import sidebar | |
|
7 | ||
|
6 | 8 | from .models import DDSConfiguration |
|
7 | 9 | from .forms import DDSConfigurationForm |
|
8 | 10 | # Create your views here. |
|
9 | 11 | |
|
12 | from radarsys_api import jro_device, dds | |
|
13 | ||
|
10 | 14 | def dds_conf(request, id_conf): |
|
11 | 15 | |
|
12 | 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 | 23 | kwargs = {} |
|
24 | kwargs['connected'] = (answer[0] == "1") | |
|
25 | kwargs['form'] = form | |
|
26 | ||
|
15 | 27 | kwargs['dev_conf'] = conf |
|
16 | 28 | kwargs['dev_conf_keys'] = ['experiment', 'device', |
|
17 | 29 | 'clock', 'multiplier', |
|
18 |
'freq |
|
|
19 |
' |
|
|
20 |
' |
|
|
21 |
' |
|
|
30 | 'frequency', | |
|
31 | # 'frequency_bin', | |
|
32 | 'phase', | |
|
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 | 41 | kwargs['title'] = 'DDS Configuration' |
|
24 | 42 | kwargs['suptitle'] = 'Details' |
|
25 | 43 | |
|
26 | 44 | kwargs['button'] = 'Edit Configuration' |
|
27 | 45 | |
|
28 | 46 | ###### SIDEBAR ###### |
|
29 | experiments = Experiment.objects.filter(campaign=conf.experiment.campaign) | |
|
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) | |
|
47 | kwargs.update(sidebar(conf)) | |
|
40 | 48 | |
|
41 | 49 | return render(request, 'dds_conf.html', kwargs) |
|
42 | 50 | |
|
43 | 51 | def dds_conf_edit(request, id_conf): |
|
44 | 52 | |
|
45 | 53 | conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
46 | 54 | |
|
47 | 55 | if request.method=='GET': |
|
48 | 56 | form = DDSConfigurationForm(instance=conf) |
|
49 | 57 | |
|
50 | 58 | if request.method=='POST': |
|
51 | 59 | form = DDSConfigurationForm(request.POST, instance=conf) |
|
52 | 60 | |
|
53 | 61 | if form.is_valid(): |
|
54 | form.save() | |
|
55 | return redirect('url_dds_conf', id_conf=id_conf) | |
|
62 | conf = form.save(commit=False) | |
|
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 | 71 | kwargs = {} |
|
72 | kwargs['id_dev'] = conf.id | |
|
58 | 73 | kwargs['form'] = form |
|
59 | 74 | kwargs['title'] = 'Device Configuration' |
|
60 | 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 | 161 | return render(request, 'dds_conf_edit.html', kwargs) No newline at end of file |
@@ -1,15 +1,20 | |||
|
1 | 1 | from django import forms |
|
2 | 2 | from apps.main.models import Device |
|
3 | 3 | from .models import JARSConfiguration |
|
4 | 4 | |
|
5 | 5 | class JARSConfigurationForm(forms.ModelForm): |
|
6 | 6 | def __init__(self, *args, **kwargs): |
|
7 | 7 | super(JARSConfigurationForm, self).__init__(*args, **kwargs) |
|
8 | 8 | instance = getattr(self, 'instance', None) |
|
9 | ||
|
9 | 10 | if instance and instance.pk: |
|
10 | self.fields['experiment'].widget.attrs['disabled'] = True | |
|
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 | ||
|
11 | devices = Device.objects.filter(device_type__name='jars') | |
|
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 | 18 | class Meta: |
|
14 | 19 | model = JARSConfiguration |
|
15 | 20 | exclude = ('parameters', 'status') |
@@ -1,36 +1,38 | |||
|
1 | 1 | {% extends "base.html" %} |
|
2 | 2 | {% load bootstrap3 %} |
|
3 | 3 | {% load static %} |
|
4 | 4 | {% load main_tags %} |
|
5 | 5 | |
|
6 | 6 | {% block conf-active %}active{% endblock %} |
|
7 | 7 | |
|
8 | 8 | {% block content-title %}{{title}}{% endblock %} |
|
9 | 9 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
10 | 10 | |
|
11 | 11 | {% block content %} |
|
12 | ||
|
12 | 13 | <table class="table table-bordered"> |
|
14 | <tr><th>Status</th><td>{%if connected == True %} ☘ Connected {% else %} ⛔ Disconnected {% endif %}</td></tr> | |
|
13 | 15 | {% for key in dev_conf_keys %} |
|
14 | 16 | <tr><th>{{key|title}}</th><td>{{dev_conf|attr:key}}</td></tr> |
|
15 | 17 | {% endfor %} |
|
16 | 18 | </table> |
|
19 | ||
|
17 | 20 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_send">Send</button> |
|
18 | 21 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_export">Export</button> |
|
19 | 22 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_edit">Edit</button> |
|
20 | 23 | <br></br> |
|
21 | <br></br> | |
|
22 | 24 | {% endblock %} |
|
23 | 25 | |
|
24 | 26 | {% block sidebar%} |
|
25 | 27 | {% include "sidebar_devices.html" %} |
|
26 | 28 | {% endblock %} |
|
27 | 29 | |
|
28 | 30 | {% block extra-js%} |
|
29 | 31 | <script type="text/javascript"> |
|
30 | 32 | |
|
31 | 33 | $("#bt_edit").click(function() { |
|
32 | 34 | document.location = "{% url 'url_edit_dev_conf' dev_conf.id%}"; |
|
33 | 35 | }); |
|
34 | 36 | |
|
35 | 37 | </script> |
|
36 | 38 | {% endblock %} No newline at end of file |
@@ -1,474 +1,477 | |||
|
1 | 1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse |
|
2 | 2 | |
|
3 | 3 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm |
|
4 | 4 | from apps.cgs.forms import CGSConfigurationForm |
|
5 | 5 | from apps.jars.forms import JARSConfigurationForm |
|
6 | 6 | from apps.usrp.forms import USRPConfigurationForm |
|
7 | 7 | from apps.abs.forms import ABSConfigurationForm |
|
8 | 8 | from apps.rc.forms import RCConfigurationForm |
|
9 | 9 | from apps.dds.forms import DDSConfigurationForm |
|
10 | 10 | |
|
11 | 11 | from .models import Campaign, Experiment, Device, Configuration |
|
12 | 12 | from apps.cgs.models import CGSConfiguration |
|
13 | 13 | from apps.jars.models import JARSConfiguration |
|
14 | 14 | from apps.usrp.models import USRPConfiguration |
|
15 | 15 | from apps.abs.models import ABSConfiguration |
|
16 | 16 | from apps.rc.models import RCConfiguration |
|
17 | 17 | from apps.dds.models import DDSConfiguration |
|
18 | 18 | |
|
19 | 19 | # Create your views here. |
|
20 | 20 | |
|
21 | 21 | CONF_FORMS = { |
|
22 | 22 | 'rc': RCConfigurationForm, |
|
23 | 23 | 'dds': DDSConfigurationForm, |
|
24 | 24 | 'jars': JARSConfigurationForm, |
|
25 | 25 | 'cgs': CGSConfigurationForm, |
|
26 | 26 | 'abs': ABSConfigurationForm, |
|
27 | 27 | 'usrp': USRPConfigurationForm, |
|
28 | 28 | } |
|
29 | 29 | |
|
30 | 30 | CONF_MODELS = { |
|
31 | 31 | 'rc': RCConfiguration, |
|
32 | 32 | 'dds': DDSConfiguration, |
|
33 | 33 | 'jars': JARSConfiguration, |
|
34 | 34 | 'cgs': CGSConfiguration, |
|
35 | 35 | 'abs': ABSConfiguration, |
|
36 | 36 | 'usrp': USRPConfiguration, |
|
37 | 37 | } |
|
38 | 38 | |
|
39 | 39 | def index(request): |
|
40 | 40 | kwargs = {} |
|
41 | 41 | |
|
42 | 42 | return render(request, 'index.html', kwargs) |
|
43 | 43 | |
|
44 | 44 | def devices(request): |
|
45 | 45 | |
|
46 | 46 | devices = Device.objects.all().order_by('device_type__name') |
|
47 | 47 | |
|
48 | 48 | # keys = ['id', 'device_type__name', 'name', 'ip_address'] |
|
49 | 49 | keys = ['id', 'name', 'ip_address', 'device_type'] |
|
50 | 50 | |
|
51 | 51 | kwargs = {} |
|
52 | 52 | kwargs['device_keys'] = keys[1:] |
|
53 | 53 | kwargs['devices'] = devices#.values(*keys) |
|
54 | 54 | kwargs['title'] = 'Device' |
|
55 | 55 | kwargs['suptitle'] = 'List' |
|
56 | 56 | kwargs['button'] = 'New Device' |
|
57 | 57 | |
|
58 | 58 | return render(request, 'devices.html', kwargs) |
|
59 | 59 | |
|
60 | 60 | def device(request, id_dev): |
|
61 | 61 | |
|
62 | 62 | device = get_object_or_404(Device, pk=id_dev) |
|
63 | 63 | |
|
64 | 64 | kwargs = {} |
|
65 | 65 | kwargs['device'] = device |
|
66 | 66 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] |
|
67 | 67 | |
|
68 | 68 | kwargs['title'] = 'Device' |
|
69 | 69 | kwargs['suptitle'] = 'Details' |
|
70 | 70 | |
|
71 | 71 | kwargs['button'] = 'Add Device' |
|
72 | 72 | |
|
73 | 73 | return render(request, 'device.html', kwargs) |
|
74 | 74 | |
|
75 | 75 | def device_new(request): |
|
76 | 76 | |
|
77 | 77 | if request.method == 'GET': |
|
78 | 78 | form = DeviceForm() |
|
79 | 79 | |
|
80 | 80 | if request.method == 'POST': |
|
81 | 81 | form = DeviceForm(request.POST) |
|
82 | 82 | |
|
83 | 83 | if form.is_valid(): |
|
84 | 84 | form.save() |
|
85 | 85 | return redirect('url_devices') |
|
86 | 86 | |
|
87 | 87 | kwargs = {} |
|
88 | 88 | kwargs['form'] = form |
|
89 | 89 | kwargs['title'] = 'Device' |
|
90 | 90 | kwargs['suptitle'] = 'New' |
|
91 | 91 | kwargs['button'] = 'Create' |
|
92 | 92 | |
|
93 | 93 | return render(request, 'device_edit.html', kwargs) |
|
94 | 94 | |
|
95 | 95 | def device_edit(request, id_dev): |
|
96 | 96 | |
|
97 | 97 | device = get_object_or_404(Device, pk=id_dev) |
|
98 | 98 | |
|
99 | 99 | if request.method=='GET': |
|
100 | 100 | form = DeviceForm(instance=device) |
|
101 | 101 | |
|
102 | 102 | if request.method=='POST': |
|
103 | 103 | form = DeviceForm(request.POST, instance=device) |
|
104 | 104 | |
|
105 | 105 | if form.is_valid(): |
|
106 | 106 | form.save() |
|
107 | 107 | return redirect('url_devices') |
|
108 | 108 | |
|
109 | 109 | kwargs = {} |
|
110 | 110 | kwargs['form'] = form |
|
111 | 111 | kwargs['title'] = 'Device' |
|
112 | 112 | kwargs['suptitle'] = 'Edit' |
|
113 | 113 | kwargs['button'] = 'Update' |
|
114 | 114 | |
|
115 | 115 | return render(request, 'device_edit.html', kwargs) |
|
116 | 116 | |
|
117 | 117 | def device_delete(request, id_dev): |
|
118 | 118 | |
|
119 | 119 | device = get_object_or_404(Device, pk=id_dev) |
|
120 | 120 | |
|
121 | 121 | if request.method=='POST': |
|
122 | 122 | |
|
123 | 123 | if request.user.is_staff: |
|
124 | 124 | device.delete() |
|
125 | 125 | return redirect('url_devices') |
|
126 | 126 | |
|
127 | 127 | return HttpResponse("Not enough permission to delete this object") |
|
128 | 128 | |
|
129 | 129 | kwargs = {'object':device, 'dev_active':'active', |
|
130 | 130 | 'url_cancel':'url_device', 'id_item':id_dev} |
|
131 | 131 | |
|
132 | 132 | return render(request, 'item_delete.html', kwargs) |
|
133 | 133 | |
|
134 | 134 | def campaigns(request): |
|
135 | 135 | |
|
136 | 136 | campaigns = Campaign.objects.all().order_by('start_date') |
|
137 | 137 | |
|
138 | 138 | keys = ['id', 'name', 'start_date', 'end_date'] |
|
139 | 139 | |
|
140 | 140 | kwargs = {} |
|
141 | 141 | kwargs['campaign_keys'] = keys[1:] |
|
142 | 142 | kwargs['campaigns'] = campaigns#.values(*keys) |
|
143 | 143 | kwargs['title'] = 'Campaign' |
|
144 | 144 | kwargs['suptitle'] = 'List' |
|
145 | 145 | kwargs['button'] = 'New Campaign' |
|
146 | 146 | |
|
147 | 147 | return render(request, 'campaigns.html', kwargs) |
|
148 | 148 | |
|
149 | 149 | def campaign(request, id_camp): |
|
150 | 150 | |
|
151 | 151 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
152 | 152 | experiments = Experiment.objects.filter(campaign=campaign) |
|
153 | 153 | |
|
154 | 154 | form = CampaignForm(instance=campaign) |
|
155 | 155 | |
|
156 | 156 | kwargs = {} |
|
157 | 157 | kwargs['campaign'] = campaign |
|
158 | 158 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
159 | 159 | |
|
160 | 160 | keys = ['id', 'name', 'start_time', 'end_time'] |
|
161 | 161 | |
|
162 | 162 | kwargs['experiment_keys'] = keys[1:] |
|
163 | 163 | kwargs['experiments'] = experiments.values(*keys) |
|
164 | 164 | |
|
165 | 165 | kwargs['title'] = 'Campaign' |
|
166 | 166 | kwargs['suptitle'] = 'Details' |
|
167 | 167 | |
|
168 | 168 | kwargs['form'] = form |
|
169 | 169 | kwargs['button'] = 'Add Experiment' |
|
170 | 170 | |
|
171 | 171 | return render(request, 'campaign.html', kwargs) |
|
172 | 172 | |
|
173 | 173 | def campaign_new(request): |
|
174 | 174 | |
|
175 | 175 | if request.method == 'GET': |
|
176 | 176 | form = CampaignForm() |
|
177 | 177 | |
|
178 | 178 | if request.method == 'POST': |
|
179 | 179 | form = CampaignForm(request.POST) |
|
180 | 180 | |
|
181 | 181 | if form.is_valid(): |
|
182 | 182 | campaign = form.save() |
|
183 | 183 | return redirect('url_campaign', id_camp=campaign.id) |
|
184 | 184 | |
|
185 | 185 | kwargs = {} |
|
186 | 186 | kwargs['form'] = form |
|
187 | 187 | kwargs['title'] = 'Campaign' |
|
188 | 188 | kwargs['suptitle'] = 'New' |
|
189 | 189 | kwargs['button'] = 'Create' |
|
190 | 190 | |
|
191 | 191 | return render(request, 'campaign_edit.html', kwargs) |
|
192 | 192 | |
|
193 | 193 | def campaign_edit(request, id_camp): |
|
194 | 194 | |
|
195 | 195 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
196 | 196 | |
|
197 | 197 | if request.method=='GET': |
|
198 | 198 | form = CampaignForm(instance=campaign) |
|
199 | 199 | |
|
200 | 200 | if request.method=='POST': |
|
201 | 201 | form = CampaignForm(request.POST, instance=campaign) |
|
202 | 202 | |
|
203 | 203 | if form.is_valid(): |
|
204 | 204 | form.save() |
|
205 | 205 | return redirect('url_campaign', id_camp=id_camp) |
|
206 | 206 | |
|
207 | 207 | kwargs = {} |
|
208 | 208 | kwargs['form'] = form |
|
209 | 209 | kwargs['title'] = 'Campaign' |
|
210 | 210 | kwargs['suptitle'] = 'Edit' |
|
211 | 211 | kwargs['button'] = 'Update' |
|
212 | 212 | |
|
213 | 213 | return render(request, 'campaign_edit.html', kwargs) |
|
214 | 214 | |
|
215 | 215 | def campaign_delete(request, id_camp): |
|
216 | 216 | |
|
217 | 217 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
218 | 218 | |
|
219 | 219 | if request.method=='POST': |
|
220 | 220 | if request.user.is_staff: |
|
221 | 221 | campaign.delete() |
|
222 | 222 | return redirect('url_campaigns') |
|
223 | 223 | |
|
224 | 224 | return HttpResponse("Not enough permission to delete this object") |
|
225 | 225 | |
|
226 | 226 | kwargs = {'object':campaign, 'camp_active':'active', |
|
227 | 227 | 'url_cancel':'url_campaign', 'id_item':id_camp} |
|
228 | 228 | |
|
229 | 229 | return render(request, 'item_delete.html', kwargs) |
|
230 | 230 | |
|
231 | 231 | def experiments(request): |
|
232 | 232 | |
|
233 | 233 | experiment_list = Experiment.objects.all().order_by('campaign') |
|
234 | 234 | |
|
235 | 235 | keys = ['id', 'name', 'start_time', 'end_time', 'campaign'] |
|
236 | 236 | |
|
237 | 237 | kwargs = {} |
|
238 | 238 | |
|
239 | 239 | kwargs['experiment_keys'] = keys[1:] |
|
240 | 240 | kwargs['experiments'] = experiment_list#.values(*keys) |
|
241 | 241 | |
|
242 | 242 | kwargs['title'] = 'Experiment' |
|
243 | 243 | kwargs['suptitle'] = 'List' |
|
244 | 244 | kwargs['button'] = 'New Experiment' |
|
245 | 245 | |
|
246 | 246 | return render(request, 'experiments.html', kwargs) |
|
247 | 247 | |
|
248 | 248 | def experiment(request, id_exp): |
|
249 | 249 | |
|
250 | 250 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
251 | 251 | |
|
252 | 252 | experiments = Experiment.objects.filter(campaign=experiment.campaign) |
|
253 | 253 | configurations = Configuration.objects.filter(experiment=experiment) |
|
254 | 254 | |
|
255 | 255 | kwargs = {} |
|
256 | 256 | |
|
257 | 257 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] |
|
258 | 258 | conf_keys = ['id', 'device__name', 'device__device_type__name', 'device__ip_address'] |
|
259 | 259 | |
|
260 | 260 | |
|
261 | 261 | kwargs['experiment_keys'] = exp_keys[1:] |
|
262 | 262 | kwargs['experiment'] = experiment |
|
263 | 263 | |
|
264 | 264 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
265 | 265 | |
|
266 | 266 | kwargs['configuration_keys'] = conf_keys[1:] |
|
267 | 267 | kwargs['configurations'] = configurations.values(*conf_keys) |
|
268 | 268 | |
|
269 | 269 | kwargs['title'] = 'Experiment' |
|
270 | 270 | kwargs['suptitle'] = 'Details' |
|
271 | 271 | |
|
272 | 272 | kwargs['button'] = 'Add Device' |
|
273 | 273 | |
|
274 | 274 | return render(request, 'experiment.html', kwargs) |
|
275 | 275 | |
|
276 | 276 | def experiment_new(request, id_camp=0): |
|
277 | 277 | |
|
278 | 278 | if request.method == 'GET': |
|
279 | 279 | form = ExperimentForm(initial={'campaign':id_camp}) |
|
280 | 280 | |
|
281 | 281 | if request.method == 'POST': |
|
282 | 282 | form = ExperimentForm(request.POST, initial={'campaign':id_camp}) |
|
283 | 283 | |
|
284 | 284 | if form.is_valid(): |
|
285 | 285 | experiment = form.save() |
|
286 | 286 | return redirect('url_experiment', id_exp=experiment.id) |
|
287 | 287 | |
|
288 | 288 | kwargs = {} |
|
289 | 289 | kwargs['form'] = form |
|
290 | 290 | kwargs['title'] = 'Experiment' |
|
291 | 291 | kwargs['suptitle'] = 'New' |
|
292 | 292 | kwargs['button'] = 'Create' |
|
293 | 293 | |
|
294 | 294 | return render(request, 'experiment_edit.html', kwargs) |
|
295 | 295 | |
|
296 | 296 | def experiment_edit(request, id_exp): |
|
297 | 297 | |
|
298 | 298 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
299 | 299 | |
|
300 | 300 | if request.method == 'GET': |
|
301 | 301 | form = ExperimentForm(instance=experiment) |
|
302 | 302 | |
|
303 | 303 | if request.method=='POST': |
|
304 | 304 | form = ExperimentForm(request.POST, instance=experiment) |
|
305 | 305 | |
|
306 | 306 | if form.is_valid(): |
|
307 | 307 | experiment = form.save() |
|
308 | 308 | return redirect('url_experiment', id_exp=experiment.id) |
|
309 | 309 | |
|
310 | 310 | kwargs = {} |
|
311 | 311 | kwargs['form'] = form |
|
312 | 312 | kwargs['title'] = 'Experiment' |
|
313 | 313 | kwargs['suptitle'] = 'Edit' |
|
314 | 314 | kwargs['button'] = 'Update' |
|
315 | 315 | |
|
316 | 316 | return render(request, 'experiment_edit.html', kwargs) |
|
317 | 317 | |
|
318 | 318 | def experiment_delete(request, id_exp): |
|
319 | 319 | |
|
320 | 320 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
321 | 321 | |
|
322 | 322 | if request.method=='POST': |
|
323 | 323 | if request.user.is_staff: |
|
324 | 324 | id_camp = experiment.campaign.id |
|
325 | 325 | experiment.delete() |
|
326 | 326 | return redirect('url_campaign', id_camp=id_camp) |
|
327 | 327 | |
|
328 | 328 | return HttpResponse("Not enough permission to delete this object") |
|
329 | 329 | |
|
330 | 330 | kwargs = {'object':experiment, 'exp_active':'active', |
|
331 | 331 | 'url_cancel':'url_experiment', 'id_item':id_exp} |
|
332 | 332 | |
|
333 | 333 | return render(request, 'item_delete.html', kwargs) |
|
334 | 334 | |
|
335 | 335 | def dev_confs(request): |
|
336 | 336 | |
|
337 | 337 | configurations = Configuration.objects.all().order_by('experiment') |
|
338 | 338 | |
|
339 | 339 | # keys = ['id', 'device__device_type__name', 'device__name', 'experiment__campaign__name', 'experiment__name'] |
|
340 | 340 | |
|
341 | 341 | keys = ['id', 'device', 'experiment'] |
|
342 | 342 | |
|
343 | 343 | kwargs = {} |
|
344 | 344 | |
|
345 | 345 | kwargs['configuration_keys'] = keys[1:] |
|
346 | 346 | kwargs['configurations'] = configurations#.values(*keys) |
|
347 | 347 | |
|
348 | 348 | kwargs['title'] = 'Configuration' |
|
349 | 349 | kwargs['suptitle'] = 'List' |
|
350 | 350 | kwargs['button'] = 'New Configuration' |
|
351 | 351 | |
|
352 | 352 | return render(request, 'dev_confs.html', kwargs) |
|
353 | 353 | |
|
354 | 354 | def dev_conf(request, id_conf): |
|
355 | 355 | |
|
356 | 356 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
357 | 357 | |
|
358 | 358 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
359 | 359 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
360 | 360 | |
|
361 | 361 | kwargs = {} |
|
362 | 362 | kwargs['dev_conf'] = dev_conf |
|
363 | 363 | kwargs['dev_conf_keys'] = ['experiment', 'device'] |
|
364 | 364 | |
|
365 | 365 | kwargs['title'] = 'Configuration' |
|
366 | 366 | kwargs['suptitle'] = 'Details' |
|
367 | 367 | |
|
368 | 368 | kwargs['button'] = 'Edit Configuration' |
|
369 | 369 | |
|
370 | 370 | ###### SIDEBAR ###### |
|
371 | 371 | experiments = Experiment.objects.filter(campaign=conf.experiment.campaign) |
|
372 | 372 | configurations = Configuration.objects.filter(experiment=conf.experiment) |
|
373 | 373 | |
|
374 | 374 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] |
|
375 | 375 | conf_keys = ['id', 'device__name', 'device__device_type__name', 'device__ip_address'] |
|
376 | 376 | |
|
377 | 377 | kwargs['experiment_keys'] = exp_keys[1:] |
|
378 | 378 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
379 | 379 | |
|
380 | 380 | kwargs['configuration_keys'] = conf_keys[1:] |
|
381 | 381 | kwargs['configurations'] = configurations.values(*conf_keys) |
|
382 | 382 | |
|
383 | 383 | return render(request, 'dev_conf.html', kwargs) |
|
384 | 384 | |
|
385 | 385 | def dev_conf_new(request, id_exp=0): |
|
386 | 386 | |
|
387 | 387 | if request.method == 'GET': |
|
388 | 388 | form = ConfigurationForm(initial={'experiment':id_exp}) |
|
389 | 389 | |
|
390 | 390 | if request.method == 'POST': |
|
391 | 391 | form = ConfigurationForm(request.POST) |
|
392 | 392 | |
|
393 | 393 | if form.is_valid(): |
|
394 | 394 | experiment = Experiment.objects.get(pk=request.POST['experiment']) |
|
395 | 395 | device = Device.objects.get(pk=request.POST['device']) |
|
396 | 396 | |
|
397 | 397 | exp_devices = Device.objects.filter(configuration__experiment=experiment) |
|
398 | 398 | |
|
399 | 399 | if device.id not in exp_devices.values('id',): |
|
400 | 400 | |
|
401 | 401 | DevConfModel = CONF_MODELS[device.device_type.name] |
|
402 | 402 | conf = DevConfModel(experiment=experiment, device=device) |
|
403 | 403 | conf.save() |
|
404 | 404 | |
|
405 | 405 | return redirect('url_experiment', id_exp=experiment.id) |
|
406 | 406 | |
|
407 | 407 | kwargs = {} |
|
408 | 408 | kwargs['form'] = form |
|
409 | 409 | kwargs['title'] = 'Configuration' |
|
410 | 410 | kwargs['suptitle'] = 'New' |
|
411 | 411 | kwargs['button'] = 'Create' |
|
412 | 412 | |
|
413 | 413 | return render(request, 'dev_conf_edit.html', kwargs) |
|
414 | 414 | |
|
415 | 415 | def dev_conf_edit(request, id_conf): |
|
416 | 416 | |
|
417 | 417 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
418 | 418 | |
|
419 | 419 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
420 | 420 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
421 | 421 | |
|
422 | 422 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
423 | 423 | |
|
424 | 424 | if request.method=='GET': |
|
425 | 425 | form = DevConfForm(instance=dev_conf) |
|
426 | 426 | |
|
427 | 427 | if request.method=='POST': |
|
428 | 428 | form = DevConfForm(request.POST, instance=dev_conf) |
|
429 | 429 | |
|
430 | 430 | if form.is_valid(): |
|
431 | 431 | form.save() |
|
432 | 432 | return redirect('url_dev_conf', id_conf=id_conf) |
|
433 | 433 | |
|
434 | 434 | kwargs = {} |
|
435 | 435 | kwargs['form'] = form |
|
436 | 436 | kwargs['title'] = 'Device Configuration' |
|
437 | 437 | kwargs['suptitle'] = 'Edit' |
|
438 | 438 | kwargs['button'] = 'Update' |
|
439 | 439 | |
|
440 | 440 | return render(request, 'dev_conf_edit.html', kwargs) |
|
441 | 441 | |
|
442 | 442 | def dev_conf_delete(request, id_conf): |
|
443 | 443 | |
|
444 | 444 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
445 | 445 | |
|
446 | 446 | if request.method=='POST': |
|
447 | 447 | if request.user.is_staff: |
|
448 | 448 | id_exp = conf.experiment.id |
|
449 | 449 | conf.delete() |
|
450 | 450 | return redirect('url_experiment', id_exp=id_exp) |
|
451 | 451 | |
|
452 | 452 | return HttpResponse("Not enough permission to delete this object") |
|
453 | 453 | |
|
454 | 454 | kwargs = {'object':conf, 'conf_active':'active', |
|
455 | 455 | 'url_cancel':'url_dev_conf', 'id_item':id_conf} |
|
456 | 456 | |
|
457 | 457 | return render(request, 'item_delete.html', kwargs) |
|
458 | 458 | |
|
459 | 459 | def sidebar(conf): |
|
460 | 460 | |
|
461 | 461 | experiments = Experiment.objects.filter(campaign=conf.experiment.campaign) |
|
462 | 462 | configurations = Configuration.objects.filter(experiment=conf.experiment) |
|
463 | 463 | |
|
464 | 464 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] |
|
465 | 465 | conf_keys = ['id', 'device__name', 'device__device_type__name', 'device__ip_address'] |
|
466 | 466 | |
|
467 | 467 | kwargs = {} |
|
468 | ||
|
469 | kwargs['dev_conf'] = conf | |
|
470 | ||
|
468 | 471 | kwargs['experiment_keys'] = exp_keys[1:] |
|
469 | 472 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
470 | 473 | |
|
471 | 474 | kwargs['configuration_keys'] = conf_keys[1:] |
|
472 | 475 | kwargs['configurations'] = configurations.values(*conf_keys) |
|
473 | 476 | |
|
474 | 477 | return kwargs No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now