@@ -0,0 +1,13 | |||
|
1 | ||
|
2 | function freq2Binary(mclock, frequency) { | |
|
3 | ||
|
4 | var freq_bin = parseInt(frequency * (Math.pow(2,48)/mclock)); | |
|
5 | return freq_bin; | |
|
6 | ||
|
7 | } | |
|
8 | ||
|
9 | function binary2Freq(mclock, binary) { | |
|
10 | ||
|
11 | var frequency = (1.0*binary) / (Math.pow(2,48)/mclock); | |
|
12 | return frequency; | |
|
13 | } No newline at end of file |
@@ -1,6 +1,10 | |||
|
1 | 1 | from django.conf.urls import url |
|
2 | 2 | |
|
3 | 3 | urlpatterns = ( |
|
4 | 4 | url(r'^(?P<id_conf>-?\d+)/$', 'apps.main.views.dev_conf', name='url_abs_conf'), |
|
5 | 5 | url(r'^(?P<id_conf>-?\d+)/edit/$', 'apps.main.views.dev_conf_edit', name='url_edit_abs_conf'), |
|
6 | url(r'^(?P<id_conf>-?\d+)/write/$', 'apps.main.views.dev_conf_write', name='url_write_abs_conf'), | |
|
7 | url(r'^(?P<id_conf>-?\d+)/read/$', 'apps.main.views.dev_conf_read', name='url_read_abs_conf'), | |
|
8 | url(r'^(?P<id_conf>-?\d+)/import/$', 'apps.main.views.dev_conf_import', name='url_import_abs_conf'), | |
|
9 | url(r'^(?P<id_conf>-?\d+)/export/$', 'apps.main.views.dev_conf_export', name='url_export_abs_conf'), | |
|
6 | 10 |
) |
@@ -1,9 +1,13 | |||
|
1 | 1 | from django.conf.urls import url |
|
2 | 2 | |
|
3 | 3 | urlpatterns = ( |
|
4 | 4 | #url(r'^configuration/$', 'apps.cgs.views.configurate_frequencies', name='new_device'), |
|
5 | 5 | # url(r'^(?P<id>-?\d+)/$', 'apps.cgs.views.configurate_frequencies', name='new_device'), |
|
6 | 6 | url(r'^(?P<id_conf>-?\d+)/$', 'apps.main.views.dev_conf', name='url_cgs_conf'), |
|
7 | 7 | url(r'^(?P<id_conf>-?\d+)/edit/$', 'apps.main.views.dev_conf_edit', name='url_edit_cgs_conf'), |
|
8 | url(r'^(?P<id_conf>-?\d+)/write/$', 'apps.main.views.dev_conf_write', name='url_write_cgs_conf'), | |
|
9 | url(r'^(?P<id_conf>-?\d+)/read/$', 'apps.main.views.dev_conf_read', name='url_read_cgs_conf'), | |
|
10 | url(r'^(?P<id_conf>-?\d+)/import/$', 'apps.main.views.dev_conf_import', name='url_import_cgs_conf'), | |
|
11 | url(r'^(?P<id_conf>-?\d+)/export/$', 'apps.main.views.dev_conf_export', name='url_export_cgs_conf'), | |
|
8 | 12 | ) |
|
9 | 13 |
@@ -1,77 +1,76 | |||
|
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 | 6 | from django.core.exceptions import ValidationError |
|
7 | 7 | |
|
8 | 8 | MOD_TYPES = ( |
|
9 | (None, 'Select a modulation type'), | |
|
10 | 9 | (0, 'Single Tone'), |
|
11 | 10 | (1, 'FSK'), |
|
12 | 11 | (2, 'Ramped FSK'), |
|
13 | 12 | (3, 'Chirp'), |
|
14 | 13 | (4, 'BPSK'), |
|
15 | 14 | ) |
|
16 | 15 | |
|
17 | 16 | class DDSConfiguration(Configuration): |
|
18 | 17 | |
|
19 | 18 | DDS_NBITS = 48 |
|
20 | 19 | |
|
21 | clock = models.FloatField(verbose_name='Clock Master (MHz)',validators=[MinValueValidator(5), MaxValueValidator(75)]) | |
|
20 | clock = models.FloatField(verbose_name='Clock Master (MHz)',validators=[MinValueValidator(5), MaxValueValidator(75)], null=True) | |
|
22 | 21 | multiplier = models.PositiveIntegerField(verbose_name='Multiplier',validators=[MinValueValidator(1), MaxValueValidator(20)], default=4) |
|
23 | 22 | |
|
24 |
frequency = models.DecimalField(verbose_name='Frequency (MHz)', validators=[MinValueValidator(0), MaxValueValidator(150)], max_digits=1 |
|
|
23 | frequency = models.DecimalField(verbose_name='Frequency (MHz)', validators=[MinValueValidator(0), MaxValueValidator(150)], max_digits=18, decimal_places=16) | |
|
25 | 24 | frequency_bin = models.BigIntegerField(verbose_name='Frequency (Binary)',validators=[MinValueValidator(0), MaxValueValidator(2**DDS_NBITS-1)]) |
|
26 | 25 | |
|
27 | phase = models.FloatField(verbose_name='Phase (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)]) | |
|
26 | phase = models.FloatField(verbose_name='Phase (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)], default=0) | |
|
28 | 27 | # phase_binary = models.PositiveIntegerField(verbose_name='Phase (Binary)',validators=[MinValueValidator(0), MaxValueValidator(2**14-1)]) |
|
29 | 28 | |
|
30 | 29 | amplitude_ch_A = models.PositiveIntegerField(verbose_name='Amplitude CHA',validators=[MinValueValidator(0), MaxValueValidator(2**10-1)], blank=True, null=True) |
|
31 | 30 | amplitude_ch_B = models.PositiveIntegerField(verbose_name='Amplitude CHB',validators=[MinValueValidator(0), MaxValueValidator(2**10-1)], blank=True, null=True) |
|
32 | 31 | |
|
33 | modulation = models.PositiveIntegerField(choices = MOD_TYPES, default = 0) | |
|
32 | modulation = models.PositiveIntegerField(verbose_name='Modulation Type', choices = MOD_TYPES, default = 0) | |
|
34 | 33 | |
|
35 |
frequency_mod = models.DecimalField(verbose_name='Frequency |
|
|
36 |
frequency_mod_bin = models.BigIntegerField(verbose_name='Frequency |
|
|
34 | frequency_mod = models.DecimalField(verbose_name='Mod: Frequency (MHz)', validators=[MinValueValidator(0), MaxValueValidator(150)], max_digits=18, decimal_places=16, blank=True, null=True) | |
|
35 | frequency_mod_bin = models.BigIntegerField(verbose_name='Mod: Frequency (Binary)',validators=[MinValueValidator(0), MaxValueValidator(2**DDS_NBITS-1)], blank=True, null=True) | |
|
37 | 36 | |
|
38 |
phase_mod = models.FloatField(verbose_name='Phase |
|
|
37 | phase_mod = models.FloatField(verbose_name='Mod: Phase (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)], blank=True, null=True) | |
|
39 | 38 | # phase_binary_mod = models.PositiveIntegerField(verbose_name='Phase Mod (Binary)',validators=[MinValueValidator(0), MaxValueValidator(2**14-1)], blank=True, null=True) |
|
40 | 39 | |
|
41 | 40 | def get_nbits(self): |
|
42 | 41 | |
|
43 | 42 | return self.DDS_NBITS |
|
44 | 43 | |
|
45 | 44 | def clean(self): |
|
46 | 45 | |
|
47 | 46 | if self.modulation in [1,2,3]: |
|
48 | 47 | if self.frequency_mod is None or self.frequency_mod_bin is None: |
|
49 | 48 | raise ValidationError({ |
|
50 | 49 | 'frequency_mod': 'Frequency modulation has to be defined when FSK or Chirp modulation is selected' |
|
51 | 50 | }) |
|
52 | 51 | |
|
53 | 52 | if self.modulation in [4,]: |
|
54 | 53 | if self.phase_mod is None: |
|
55 | 54 | raise ValidationError({ |
|
56 | 55 | 'phase_mod': 'Phase modulation has to be defined when BPSK modulation is selected' |
|
57 | 56 | }) |
|
58 | 57 | |
|
59 | 58 | def verify_frequencies(self): |
|
60 | 59 | |
|
61 | 60 | return True |
|
62 | 61 | |
|
63 | 62 | def freq2binary(self, freq, mclock): |
|
64 | 63 | |
|
65 | 64 | binary = (float(freq)/mclock)*(2**self.DDS_NBITS) |
|
66 | 65 | |
|
67 | 66 | return binary |
|
68 | 67 | |
|
69 | 68 | def binary2freq(self, binary, mclock): |
|
70 | 69 | |
|
71 | 70 | freq = (float(binary)/(2**self.DDS_NBITS))*mclock |
|
72 | 71 | |
|
73 | 72 | return freq |
|
74 | 73 | |
|
75 | 74 | class Meta: |
|
76 | 75 | db_table = 'dds_configurations' |
|
77 | 76 | No newline at end of file |
@@ -1,68 +1,1 | |||
|
1 |
{% extends " |
|
|
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 %} | |
|
51 | ||
|
52 | {% block extra-js%} | |
|
53 | <script type="text/javascript"> | |
|
54 | ||
|
55 | $("#bt_edit").click(function() { | |
|
56 | document.location = "{% url 'url_edit_dds_conf' dev_conf.id%}"; | |
|
57 | }); | |
|
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 | ||
|
67 | </script> | |
|
68 | {% endblock %} No newline at end of file | |
|
1 | {% extends "dev_conf.html" %} No newline at end of file |
@@ -1,90 +1,83 | |||
|
1 | 1 | {% extends "dev_conf_edit.html" %} |
|
2 | 2 | {% load bootstrap3 %} |
|
3 | 3 | {% load static %} |
|
4 | 4 | {% load main_tags %} |
|
5 | 5 | |
|
6 | 6 | {% block extra-js%} |
|
7 | <script src="{% static 'js/dds_conversion.js' %}"></script> | |
|
7 | 8 | <script type="text/javascript"> |
|
8 | 9 | |
|
9 | 10 | $("#bt_cancel").click(function() { |
|
10 | 11 | document.location = "{% url 'url_dds_conf' id_dev%}"; |
|
11 | 12 | }); |
|
12 | 13 | |
|
13 | 14 | $("#bt_read").click(function() { |
|
14 |
document.location = "{% url 'url_dds_conf |
|
|
15 | document.location = "{% url 'url_read_dds_conf' id_dev%}"; | |
|
15 | 16 | }); |
|
16 | 17 | |
|
17 | 18 | $("#id_clock").on('change', function() { |
|
18 | 19 | updateFrequencies(); |
|
19 | 20 | }); |
|
20 | 21 | |
|
21 | 22 | $("#id_multiplier").on('change', function() { |
|
22 | 23 | updateFrequencies(); |
|
23 | 24 | }); |
|
24 | 25 | |
|
25 | 26 | $("#id_frequency").on('change', function() { |
|
26 | 27 | updateBinaryFrequencies(); |
|
27 | 28 | }); |
|
28 | 29 | |
|
29 | 30 | $("#id_frequency_bin").on('change', function() { |
|
30 | 31 | updateFrequencies(); |
|
31 | 32 | }); |
|
32 | 33 | |
|
33 | 34 | $("#id_frequency_mod").on('change', function() { |
|
34 | 35 | updateBinaryFrequencies(); |
|
35 | 36 | }); |
|
36 | 37 | |
|
37 | 38 | $("#id_frequency_mod_bin").on('change', function() { |
|
38 | 39 | updateFrequencies(); |
|
39 | 40 | }); |
|
40 | 41 | |
|
41 | 42 | function updateBinaryFrequencies() { |
|
42 | 43 | |
|
43 | 44 | var clock = $("#id_clock").val(); |
|
44 | 45 | var multiplier = $("#id_multiplier").val(); |
|
45 | 46 | var freq = $("#id_frequency").val(); |
|
46 | 47 | var freq_mod = $("#id_frequency_mod").val(); |
|
47 | 48 | |
|
48 | 49 | var mclock = clock*multiplier; |
|
49 | var k = Math.pow(2,48)/mclock; | |
|
50 | 50 | |
|
51 |
var freq_bin = |
|
|
52 |
var freq_mod_bin = |
|
|
51 | var freq_bin = freq2Binary(mclock, freq); | |
|
52 | var freq_mod_bin = freq2Binary(mclock, freq_mod); | |
|
53 | 53 | |
|
54 | 54 | $("#id_frequency_bin").val(freq_bin); |
|
55 | 55 | $("#id_frequency_mod_bin").val(freq_mod_bin); |
|
56 | 56 | |
|
57 |
freq = freq_bin |
|
|
58 |
freq_mod = freq_mod_bin |
|
|
57 | freq = binary2Freq(mclock, freq_bin); | |
|
58 | freq_mod = binary2Freq(mclock, freq_mod_bin); | |
|
59 | 59 | |
|
60 | 60 | $("#id_frequency").val(freq); |
|
61 | 61 | $("#id_frequency_mod").val(freq_mod); |
|
62 | 62 | |
|
63 | 63 | } |
|
64 | 64 | |
|
65 | 65 | function updateFrequencies() { |
|
66 | 66 | |
|
67 | 67 | var clock = $("#id_clock").val(); |
|
68 | 68 | var multiplier = $("#id_multiplier").val(); |
|
69 | 69 | var freq_bin = $("#id_frequency_bin").val(); |
|
70 | 70 | var freq_mod_bin = $("#id_frequency_mod_bin").val(); |
|
71 | 71 | |
|
72 | 72 | var mclock = clock*multiplier; |
|
73 | var k = Math.pow(2,48)/mclock; | |
|
74 | 73 | |
|
75 |
var freq = |
|
|
76 |
var freq_mod = |
|
|
74 | var freq = binary2Freq(mclock, freq_bin); | |
|
75 | var freq_mod = binary2Freq(mclock, freq_mod_bin); | |
|
77 | 76 | |
|
78 | 77 | $("#id_frequency").val(freq); |
|
79 | 78 | $("#id_frequency_mod").val(freq_mod); |
|
80 | 79 | |
|
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 | 80 | } |
|
88 | 81 | |
|
89 | 82 | </script> |
|
90 | 83 | {% endblock %} No newline at end of file |
@@ -1,9 +1,11 | |||
|
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 | 5 | url(r'^(?P<id_conf>-?\d+)/(?P<message>-?\d+)/$', 'apps.dds.views.dds_conf', name='url_dds_conf'), |
|
6 | 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 |
|
|
8 |
url(r'^(?P<id_conf>-?\d+)/read/$', 'apps.dds.views.dds_conf_read', name='url_dds_conf |
|
|
7 | url(r'^(?P<id_conf>-?\d+)/write/$', 'apps.dds.views.dds_conf_write', name='url_write_dds_conf'), | |
|
8 | url(r'^(?P<id_conf>-?\d+)/read/$', 'apps.dds.views.dds_conf_read', name='url_read_dds_conf'), | |
|
9 | url(r'^(?P<id_conf>-?\d+)/import/$', 'apps.main.views.dev_conf_import', name='url_import_dds_conf'), | |
|
10 | url(r'^(?P<id_conf>-?\d+)/export/$', 'apps.main.views.dev_conf_export', name='url_export_dds_conf'), | |
|
9 | 11 | ) |
@@ -1,161 +1,163 | |||
|
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 | from apps.main.models import Experiment, Configuration | |
|
5 | # from apps.main.models import Experiment, Configuration | |
|
6 | 6 | from apps.main.views import sidebar |
|
7 | 7 | |
|
8 | 8 | from .models import DDSConfiguration |
|
9 | 9 | from .forms import DDSConfigurationForm |
|
10 | 10 | # Create your views here. |
|
11 | 11 | |
|
12 |
from radarsys_api import |
|
|
12 | from radarsys_api import dds | |
|
13 | 13 | |
|
14 | 14 | def dds_conf(request, id_conf): |
|
15 | 15 | |
|
16 | 16 | conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
17 | 17 | |
|
18 | if request.method=='GET': | |
|
19 | form = DDSConfigurationForm(instance=conf) | |
|
20 | ||
|
21 | 18 | answer = dds.echo(ip=str(conf.device.ip_address), port=conf.device.port_address) |
|
22 | 19 | |
|
23 | 20 | kwargs = {} |
|
24 | 21 |
kwargs['connected'] = (answer[0] == "1") |
|
25 | kwargs['form'] = form | |
|
26 | 22 | |
|
27 | 23 | kwargs['dev_conf'] = conf |
|
28 | 24 | kwargs['dev_conf_keys'] = ['experiment', 'device', |
|
29 | 25 | 'clock', 'multiplier', |
|
30 | 26 | 'frequency', |
|
31 |
|
|
|
27 | 'frequency_bin', | |
|
32 | 28 | 'phase', |
|
33 | 29 | # 'phase_binary', |
|
34 |
'amplitude_ch_A', 'amplitude_ch_B' |
|
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
|
30 | 'amplitude_ch_A', 'amplitude_ch_B', | |
|
31 | 'modulation', | |
|
32 | 'frequency_mod', | |
|
33 | 'frequency_mod_bin', | |
|
34 | 'phase_mod'] | |
|
39 | 35 | # 'phase_binary_mod'] |
|
40 | 36 | |
|
41 | 37 | kwargs['title'] = 'DDS Configuration' |
|
42 | 38 | kwargs['suptitle'] = 'Details' |
|
43 | 39 | |
|
44 | 40 | kwargs['button'] = 'Edit Configuration' |
|
45 | 41 | |
|
46 | 42 | ###### SIDEBAR ###### |
|
47 | 43 | kwargs.update(sidebar(conf)) |
|
48 | 44 | |
|
49 | 45 | return render(request, 'dds_conf.html', kwargs) |
|
50 | 46 | |
|
51 | 47 | def dds_conf_edit(request, id_conf): |
|
52 | 48 | |
|
53 | 49 | conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
54 | 50 | |
|
55 | 51 | if request.method=='GET': |
|
56 | 52 | form = DDSConfigurationForm(instance=conf) |
|
57 | 53 | |
|
58 | 54 | if request.method=='POST': |
|
59 | 55 | form = DDSConfigurationForm(request.POST, instance=conf) |
|
60 | 56 | |
|
61 | 57 | if form.is_valid(): |
|
62 | 58 | conf = form.save(commit=False) |
|
63 | 59 | |
|
64 | 60 | if conf.verify_frequencies(): |
|
65 | 61 | |
|
66 | 62 | conf.save() |
|
67 | 63 | return redirect('url_dds_conf', id_conf=conf.id) |
|
68 | 64 | |
|
69 | 65 | ##ERRORS |
|
70 | 66 | |
|
71 | 67 | kwargs = {} |
|
72 | 68 | kwargs['id_dev'] = conf.id |
|
73 | 69 | kwargs['form'] = form |
|
74 | 70 | kwargs['title'] = 'Device Configuration' |
|
75 | 71 | kwargs['suptitle'] = 'Edit' |
|
76 | 72 | kwargs['button'] = 'Save' |
|
77 | kwargs['dds_nbits'] = conf.get_nbits() | |
|
78 | 73 | |
|
79 | 74 | ###### SIDEBAR ###### |
|
80 | 75 | kwargs.update(sidebar(conf)) |
|
81 | 76 | |
|
82 | 77 | return render(request, 'dds_conf_edit.html', kwargs) |
|
83 | 78 | |
|
84 | 79 | def dds_conf_write(request, id_conf): |
|
85 | 80 | |
|
86 | 81 | conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
87 | 82 | |
|
88 | 83 | answer = dds.write_config(ip=str(conf.device.ip_address), |
|
89 | 84 | port=conf.device.port_address, |
|
90 | 85 | clock=conf.clock, |
|
91 | 86 | multiplier=conf.multiplier, |
|
92 | 87 | freq_regA=conf.frequency_bin, |
|
93 | 88 | freq_regB=conf.frequency_mod_bin, |
|
94 | 89 | modulation=conf.modulation, |
|
95 | 90 | phaseA=conf.phase, |
|
96 | 91 | phaseB=conf.phase_mod, |
|
97 | 92 | amplitude0=conf.amplitude_ch_A, |
|
98 | 93 | amplitude1=conf.amplitude_ch_B) |
|
99 | 94 | |
|
100 | 95 | if answer[0] == "1": |
|
101 | 96 | messages.success(request, answer[2:]) |
|
97 | ||
|
98 | conf.pk = None | |
|
99 | conf.id = None | |
|
100 | conf.type = 1 | |
|
101 | conf.save() | |
|
102 | ||
|
102 | 103 | else: |
|
103 | 104 | messages.error(request, answer) |
|
104 | 105 | |
|
105 | 106 | return redirect('url_dds_conf', id_conf=conf.id) |
|
106 | 107 | |
|
107 | 108 | def dds_conf_read(request, id_conf): |
|
108 | 109 | |
|
109 | 110 | conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
110 | 111 |
|
|
111 | 112 | if request.method=='POST': |
|
112 | 113 | form = DDSConfigurationForm(request.POST, instance=conf) |
|
113 | 114 | |
|
114 | 115 | if form.is_valid(): |
|
115 | 116 | dds_model = form.save(commit=False) |
|
116 | 117 | |
|
117 | 118 | if dds_model.verify_frequencies(): |
|
118 | 119 | |
|
119 | 120 | dds_model.save() |
|
120 | 121 | return redirect('url_dds_conf', id_conf=conf.id) |
|
121 | 122 | |
|
122 | parms = None | |
|
123 | messages.error(request, "Parameters could not be saved. Invalid parameters") | |
|
123 | 124 | |
|
124 | if request.method=='GET': | |
|
125 | data = {} | |
|
125 | 126 | |
|
127 | if request.method=='GET': | |
|
126 | 128 | #mult, freqA, freqB, modulation, phaseA, phaseB, amp0, amp1 |
|
127 | 129 | parms = dds.read_config(ip=conf.device.ip_address, |
|
128 | 130 | port=conf.device.port_address) |
|
129 | 131 | |
|
130 |
if parms |
|
|
132 | if not parms: | |
|
133 | messages.error(request, "Could not read parameters from Device") | |
|
131 | 134 | return redirect('url_dds_conf', id_conf=conf.id) |
|
132 | 135 | |
|
133 | 136 | data = {'experiment' : conf.experiment.id, |
|
134 | 137 | 'device' : conf.device.id, |
|
135 | 138 | 'clock' : conf.clock, |
|
136 | 139 | 'multiplier' : parms[0], |
|
137 | 140 | 'frequency' : conf.binary2freq(parms[1], parms[0]*conf.clock), |
|
138 | 141 | 'frequency_bin' : parms[1], |
|
139 | 142 | 'phase' : parms[4], |
|
140 | 143 | 'amplitude_ch_A' : parms[6], |
|
141 | 144 | 'amplitude_ch_B' : parms[7], |
|
142 | 145 | 'modulation' : parms[3], |
|
143 | 146 | 'frequency_mod' : conf.binary2freq(parms[2], parms[0]*conf.clock), |
|
144 | 147 | 'frequency_mod_bin' : parms[2], |
|
145 | 148 | 'phase_mod' : parms[5], |
|
146 | 149 | } |
|
147 | 150 | |
|
148 | 151 | form = DDSConfigurationForm(data) |
|
149 | 152 | |
|
150 | 153 | kwargs = {} |
|
151 | 154 | kwargs['id_dev'] = conf.id |
|
152 | 155 | kwargs['form'] = form |
|
153 | 156 | kwargs['title'] = 'Device Configuration' |
|
154 | 157 | kwargs['suptitle'] = 'Parameters read from device' |
|
155 | 158 | kwargs['button'] = 'Save' |
|
156 | kwargs['dds_nbits'] = conf.get_nbits() | |
|
157 | 159 | |
|
158 | 160 | ###### SIDEBAR ###### |
|
159 | 161 | kwargs.update(sidebar(conf)) |
|
160 | 162 | |
|
161 | 163 | return render(request, 'dds_conf_edit.html', kwargs) No newline at end of file |
@@ -1,7 +1,11 | |||
|
1 | 1 | from django.conf.urls import url |
|
2 | 2 | |
|
3 | 3 | urlpatterns = ( |
|
4 | 4 | # url(r'^(?P<id>-?\d+)/$', 'apps.jars.views.jars_config', name='jars'), |
|
5 | 5 | url(r'^(?P<id_conf>-?\d+)/$', 'apps.main.views.dev_conf', name='url_jars_conf'), |
|
6 | 6 | url(r'^(?P<id_conf>-?\d+)/edit/$', 'apps.main.views.dev_conf_edit', name='url_edit_jars_conf'), |
|
7 | url(r'^(?P<id_conf>-?\d+)/write/$', 'apps.main.views.dev_conf_write', name='url_write_jars_conf'), | |
|
8 | url(r'^(?P<id_conf>-?\d+)/read/$', 'apps.main.views.dev_conf_read', name='url_read_jars_conf'), | |
|
9 | url(r'^(?P<id_conf>-?\d+)/import/$', 'apps.main.views.dev_conf_import', name='url_import_jars_conf'), | |
|
10 | url(r'^(?P<id_conf>-?\d+)/export/$', 'apps.main.views.dev_conf_export', name='url_export_jars_conf'), | |
|
7 | 11 | ) |
@@ -1,32 +1,35 | |||
|
1 | 1 | from django.shortcuts import render_to_response |
|
2 | 2 | from django.template import RequestContext |
|
3 | 3 | |
|
4 | 4 | from apps.main.models import Device |
|
5 | from apps.main.views import sidebar | |
|
6 | ||
|
5 | 7 | from .models import JARSConfiguration |
|
6 | 8 | from .forms import JARSConfigurationForm |
|
7 | 9 | # Create your views here. |
|
8 | 10 | |
|
9 | 11 | def jars_config(request, id): |
|
10 | 12 | |
|
11 | 13 | if id: |
|
12 | 14 | conf = JARSConfiguration.objects.get(pk=id) |
|
13 | 15 | devices = Device.objects.filter(configuration__experiment=conf.experiment) |
|
14 | 16 | devices = devices.values('configuration__id', 'device_type__name') |
|
15 | 17 | for device in devices: |
|
16 | 18 | if device['device_type__name']=='jars': |
|
17 | 19 | device['active'] = 'active' |
|
18 | form = JARSConfigurationForm(instance=conf) | |
|
19 | else: | |
|
20 | form = JARSConfigurationForm() | |
|
20 | # form = JARSConfigurationForm(instance=conf) | |
|
21 | # else: | |
|
22 | # form = JARSConfigurationForm() | |
|
21 | 23 | |
|
22 | 24 | kwargs = { |
|
23 | 'form': form, | |
|
24 | 'devices':devices, | |
|
25 | 25 | 'dev_conf': conf |
|
26 | 26 | } |
|
27 | 27 | |
|
28 | ###### SIDEBAR ###### | |
|
29 | kwargs.update(sidebar(conf)) | |
|
30 | ||
|
28 | 31 | return render_to_response('jars.html', kwargs, context_instance=RequestContext(request)) |
|
29 | 32 | |
|
30 | 33 | |
|
31 | 34 | |
|
32 | 35 |
@@ -1,112 +1,131 | |||
|
1 | 1 | from itertools import chain |
|
2 | 2 | from django.db import models |
|
3 | 3 | from polymorphic import PolymorphicModel |
|
4 | 4 | |
|
5 | 5 | CONF_TYPES = ( |
|
6 | 6 | (0, 'Active'), |
|
7 | 7 | (1, 'Historical'), |
|
8 | 8 | ) |
|
9 | 9 | |
|
10 | 10 | DEV_STATES = ( |
|
11 | 11 | (0, 'No connected'), |
|
12 | 12 | (1, 'Connected'), |
|
13 | 13 | (2, 'Configured'), |
|
14 | 14 | (3, 'Running'), |
|
15 | 15 | ) |
|
16 | 16 | |
|
17 | 17 | DEV_TYPES = ( |
|
18 | 18 | ('', 'Select a device type'), |
|
19 | 19 | ('rc', 'Radar Controller'), |
|
20 | 20 | ('dds', 'Direct Digital Synthesizer'), |
|
21 | 21 | ('jars', 'Jicamarca Radar Acquisition System'), |
|
22 | 22 | ('usrp', 'Universal Software Radio Peripheral'), |
|
23 | 23 | ('cgs', 'Clock Generator System'), |
|
24 | 24 | ('abs', 'Automatic Beam Switching'), |
|
25 | 25 | ) |
|
26 | 26 | |
|
27 | 27 | # Create your models here. |
|
28 | 28 | |
|
29 | 29 | class DeviceType(models.Model): |
|
30 | 30 | |
|
31 | 31 | name = models.CharField(max_length = 10, choices = DEV_TYPES, default = 'rc') |
|
32 | 32 | |
|
33 | 33 | description = models.TextField(blank=True, null=True) |
|
34 | 34 | |
|
35 | 35 | # info = models.TextField(blank=True, null=True) |
|
36 | 36 | # status = models.PositiveSmallIntegerField(default=1, choices=STATES) |
|
37 | 37 | |
|
38 | 38 | class Meta: |
|
39 | 39 | db_table = 'db_device_types' |
|
40 | 40 | |
|
41 | 41 | def __unicode__(self): |
|
42 | 42 | return u'%s' % self.get_name_display() |
|
43 | 43 | |
|
44 | 44 | class Device(models.Model): |
|
45 | 45 | |
|
46 | 46 | device_type = models.ForeignKey(DeviceType) |
|
47 | 47 | name = models.CharField(max_length=40, default='') |
|
48 | 48 | ip_address = models.GenericIPAddressField(protocol='IPv4', default='0.0.0.0') |
|
49 | 49 | port_address = models.PositiveSmallIntegerField(default=2000) |
|
50 | 50 | description = models.TextField(blank=True, null=True) |
|
51 | 51 | status = models.PositiveSmallIntegerField(default=0, choices=DEV_STATES) |
|
52 | 52 | |
|
53 | 53 | # serial_number = models.CharField(max_length=40, default='') |
|
54 | 54 | # mac_address = models.CharField(max_length = 20, null=True, blank=True) |
|
55 | 55 | |
|
56 | 56 | |
|
57 | 57 | class Meta: |
|
58 | 58 | db_table = 'db_devices' |
|
59 | 59 | |
|
60 | 60 | def __unicode__(self): |
|
61 | 61 | return u'%s | %s' % (self.name, self.ip_address) |
|
62 | 62 | |
|
63 | 63 | class Campaign(models.Model): |
|
64 | 64 | |
|
65 | 65 | name = models.CharField(max_length=40, unique=True) |
|
66 | 66 | start_date = models.DateTimeField(blank=True, null=True) |
|
67 | 67 | end_date = models.DateTimeField(blank=True, null=True) |
|
68 | 68 | tags = models.CharField(max_length=40) |
|
69 | 69 | description = models.TextField(blank=True, null=True) |
|
70 | 70 | template = models.BooleanField(default=False) |
|
71 | 71 | |
|
72 | 72 | class Meta: |
|
73 | 73 | db_table = 'db_campaigns' |
|
74 | 74 | |
|
75 | 75 | def __unicode__(self): |
|
76 | 76 | return u'%s' % (self.name) |
|
77 | 77 | |
|
78 | 78 | class Experiment(models.Model): |
|
79 | 79 | |
|
80 | 80 | campaign = models.ForeignKey(Campaign) |
|
81 | 81 | name = models.CharField(max_length=40, default='') |
|
82 | 82 | start_time = models.TimeField(default='00:00:00') |
|
83 | 83 | end_time = models.TimeField(default='23:59:59') |
|
84 | 84 | |
|
85 | 85 | class Meta: |
|
86 | 86 | db_table = 'db_experiments' |
|
87 | 87 | |
|
88 | 88 | def __unicode__(self): |
|
89 | 89 | return u'[%s]: %s' % (self.campaign.name, self.name) |
|
90 | 90 | |
|
91 | 91 | class Configuration(PolymorphicModel): |
|
92 | 92 | |
|
93 | 93 | experiment = models.ForeignKey(Experiment) |
|
94 | 94 | device = models.ForeignKey(Device) |
|
95 | 95 | type = models.PositiveSmallIntegerField(default=0, choices=CONF_TYPES) |
|
96 | 96 | |
|
97 | 97 | created_date = models.DateTimeField(auto_now_add=True) |
|
98 | 98 | programmed_date = models.DateTimeField(auto_now=True) |
|
99 | 99 | |
|
100 | 100 | parameters = models.TextField(default='{}') |
|
101 | 101 | |
|
102 | 102 | class Meta: |
|
103 | 103 | db_table = 'db_configurations' |
|
104 | 104 | |
|
105 | 105 | def __unicode__(self): |
|
106 | 106 | return u'[%s - %s]: %s' % (self.experiment.campaign.name, |
|
107 | 107 | self.experiment.name, |
|
108 | 108 | self.device.name) |
|
109 | 109 | def get_absolute_url(self): |
|
110 | 110 | from django.core.urlresolvers import reverse |
|
111 | 111 | return reverse('url_%s_conf' % self.device.device_type.name, args=[str(self.id)]) |
|
112 | 112 | |
|
113 | def get_absolute_url_edit(self): | |
|
114 | from django.core.urlresolvers import reverse | |
|
115 | return reverse('url_edit_%s_conf' % self.device.device_type.name, args=[str(self.id)]) | |
|
116 | ||
|
117 | def get_absolute_url_import(self): | |
|
118 | from django.core.urlresolvers import reverse | |
|
119 | return reverse('url_import_%s_conf' % self.device.device_type.name, args=[str(self.id)]) | |
|
120 | ||
|
121 | def get_absolute_url_export(self): | |
|
122 | from django.core.urlresolvers import reverse | |
|
123 | return reverse('url_export_%s_conf' % self.device.device_type.name, args=[str(self.id)]) | |
|
124 | ||
|
125 | def get_absolute_url_write(self): | |
|
126 | from django.core.urlresolvers import reverse | |
|
127 | return reverse('url_write_%s_conf' % self.device.device_type.name, args=[str(self.id)]) | |
|
128 | ||
|
129 | def get_absolute_url_read(self): | |
|
130 | from django.core.urlresolvers import reverse | |
|
131 | return reverse('url_read_%s_conf' % self.device.device_type.name, args=[str(self.id)]) No newline at end of file |
@@ -1,126 +1,127 | |||
|
1 | 1 | <!DOCTYPE html> |
|
2 | 2 | {% load static %} |
|
3 | 3 | <html lang="en"> |
|
4 | 4 | <head> |
|
5 | 5 | <meta charset="utf-8"> |
|
6 | 6 | <title>{% block title %}Jicamarca Integrated Radar System:::::{% endblock %}</title> |
|
7 | 7 | <meta name="description" content=""> |
|
8 | 8 | <meta name="author" content=""> |
|
9 | 9 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
|
10 | 10 | {# bootstrap_css #} |
|
11 | 11 | <link href="{% static 'css/bootstrap-flatly.min.css' %}" media="all" rel="stylesheet"> |
|
12 | 12 | <style type="text/css"> |
|
13 | 13 | body {padding-top: 60px} |
|
14 | 14 | .logo {padding-top: 5px; height: 50px} |
|
15 | 15 | .clickable-row {cursor: pointer;} |
|
16 | 16 | </style> |
|
17 | 17 | <!--[if lt IE 9]> |
|
18 | 18 | <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script> |
|
19 | 19 | <![endif]--> |
|
20 | 20 | {% block extra-head %} |
|
21 | 21 | {% endblock %} |
|
22 | 22 | </head> |
|
23 | 23 | |
|
24 | 24 | <body> |
|
25 | 25 | |
|
26 | 26 | {% block main_menu %} |
|
27 | 27 | <nav class="navbar navbar-default navbar-fixed-top" role="banner"> |
|
28 | 28 | <div class="container-fluid"> |
|
29 | 29 | <div class="navbar-header"> |
|
30 | 30 | <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navigationbar"> |
|
31 | 31 | <span class="sr-only">Toggle navigation</span> |
|
32 | 32 | <span class="icon-bar"></span> |
|
33 | 33 | <span class="icon-bar"></span> |
|
34 | 34 | <span class="icon-bar"></span> |
|
35 | 35 | </button> |
|
36 | 36 | <a class="navbar-brand" href="{% url 'index' %}" style="padding-top:1px"><img class="logo" alt="JRO" src="{% static "images/logo-jro-white-trans.png" %}"></a> |
|
37 | 37 | </div> |
|
38 | 38 | <div class="collapse navbar-collapse" id="navigationbar"> |
|
39 | 39 | <ul class="nav navbar-nav"> |
|
40 | 40 | <li class=" dropdown {% block dev-active %}{% endblock %}"><a href="{% url 'url_devices'%}">Devices</a> |
|
41 | 41 | </li> |
|
42 | 42 | <li class=" dropdown {% block camp-active %}{% endblock %}"><a href="{% url 'url_campaigns'%}">Campaigns</a> |
|
43 | 43 | </li> |
|
44 | 44 | <li class=" dropdown {% block exp-active %}{% endblock %}"><a href="{% url 'url_experiments'%}">Experiments</a> |
|
45 | 45 | </li> |
|
46 | 46 | <li class=" dropdown {% block conf-active %}{% endblock %}"><a href="{% url 'url_dev_confs'%}">Device Configurations</a> |
|
47 | 47 | </li> |
|
48 | 48 | </ul> |
|
49 | 49 | <ul class="nav navbar-nav navbar-right"> |
|
50 | 50 | <li class="nav-divider"></li> |
|
51 | 51 | {% if user.is_authenticated %} |
|
52 | 52 | <li class="dropdown"> |
|
53 | 53 | <a href="#" class="dropdown-toggle" data-toggle="dropdown">Hi {{ user.username }}<span class="caret"></span></a> |
|
54 | 54 | <ul class="dropdown-menu" role="menu"> |
|
55 | 55 | <li><a href="#">Control Panel</a></li> |
|
56 | 56 | <li><a href="{% url 'django.contrib.auth.views.logout' %}">Logout</a></li> |
|
57 | 57 | </ul> |
|
58 | 58 | </li> |
|
59 | 59 | {% else %} |
|
60 | 60 | <li><a href="{% url 'django.contrib.auth.views.login' %}?next={{request.get_full_path}}">Login</a></li> |
|
61 | 61 | {% endif %} |
|
62 | 62 | </ul> |
|
63 | 63 | </div> |
|
64 | 64 | </div> |
|
65 | 65 | </nav> |
|
66 | 66 | <div style="clear: both;"></div> |
|
67 | 67 | {% endblock %} |
|
68 | 68 | |
|
69 | 69 | <div class="container"> |
|
70 | 70 | <div id="page" class="row" style="min-height:600px"> |
|
71 | 71 | |
|
72 | 72 | <div class="col-md-3 hidden-xs hidden-sm" role="complementary"> |
|
73 | 73 | <br><br> |
|
74 | 74 | <div id="sidebar"> |
|
75 | 75 | {% block sidebar%} |
|
76 | 76 | {% endblock %} |
|
77 | 77 | </div> |
|
78 | 78 | </div> |
|
79 | 79 | |
|
80 | 80 | <div class="col-md-9 col-xs-12" role="main"> |
|
81 | 81 | <div class="page-header"> |
|
82 | 82 | <h1>{% block content-title %}{% endblock %} <small>{% block content-suptitle %}{% endblock %}</small></h1> |
|
83 | 83 | <hr> |
|
84 | 84 | </div> |
|
85 | 85 | {% block messages %} |
|
86 | 86 | {% if messages %} |
|
87 | 87 | {% for message in messages %} |
|
88 | 88 | <div class="alert alert-{% if message.tags %}{% if 'error' in message.tags %}danger{% else %}{{ message.tags }}{% endif %}{% else %}info{% endif %} alert-dismissible" role="alert"> |
|
89 | 89 | <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button> |
|
90 | 90 | <strong>{{message.tags|title}}!</strong> {{ message }} |
|
91 | 91 | </div> |
|
92 | 92 |
{% endfor %} |
|
93 | <br> | |
|
93 | 94 | {% endif %} |
|
94 | 95 | {% endblock %} |
|
95 | <br> | |
|
96 | ||
|
96 | 97 | {% block content %} |
|
97 | 98 | {% endblock %} |
|
98 | 99 | <br> |
|
99 | 100 | </div> |
|
100 | 101 | |
|
101 | 102 | |
|
102 | 103 | </div><!--/row--> |
|
103 | 104 | </div> <!-- container --> |
|
104 | 105 | |
|
105 | 106 | <div id="debug">{{debug}}</div> |
|
106 | 107 | |
|
107 | 108 | {% block footer %} |
|
108 | 109 | <footer class="footer"> |
|
109 | 110 | <div class="container"> |
|
110 | 111 | <p><hr></p> |
|
111 | 112 | <p> |
|
112 | 113 | © <a href="http://jro.igp.gob.pe">Jicamarca Radio Observatory</a> - {% now "Y" %} |
|
113 | 114 | </p> |
|
114 | 115 | </div> |
|
115 | 116 | </footer> |
|
116 | 117 | {% endblock %} |
|
117 | 118 | |
|
118 | 119 | {# bootstrap_javascript jquery=True #} |
|
119 | 120 | <script src="{% static 'js/jquery.min.js' %}"></script> |
|
120 | 121 | <script src="{% static 'js/bootstrap.min.js' %}"></script> |
|
121 | 122 | <script src="{% static 'js/jquery-ui.min.js' %}"></script> |
|
122 | 123 | {% block extra-js %} |
|
123 | 124 | {% endblock%} |
|
124 | 125 | </body> |
|
125 | 126 | </html> |
|
126 | 127 |
@@ -1,38 +1,64 | |||
|
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 | 13 | <table class="table table-bordered"> |
|
14 | <tr><th>Status</th><td>{%if connected == True %} ☘ Connected {% else %} ⛔ Disconnected {% endif %}</td></tr> | |
|
14 | <tr> | |
|
15 | <th>Status</th> | |
|
16 | <td>{%if connected == True %} ☘ Connected {% else %} ⛔ Disconnected {% endif %}</td> | |
|
17 | </tr> | |
|
18 | ||
|
15 | 19 | {% for key in dev_conf_keys %} |
|
16 | <tr><th>{{key|title}}</th><td>{{dev_conf|attr:key}}</td></tr> | |
|
20 | <tr> | |
|
21 | <th>{% get_verbose_field_name dev_conf key %}</th> | |
|
22 | <td>{{dev_conf|attr:key}}</td> | |
|
23 | </tr> | |
|
17 | 24 | {% endfor %} |
|
18 | 25 | </table> |
|
19 | 26 | |
|
20 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_send">Send</button> | |
|
21 | 27 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_export">Export</button> |
|
28 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_import">Import</button> | |
|
22 | 29 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_edit">Edit</button> |
|
23 | <br></br> | |
|
30 | ||
|
31 | <button class="btn btn-primary pull-left" style="margin-left: 10px" id="bt_read">Read</button> | |
|
32 | <button class="btn btn-primary pull-left" style="margin-left: 10px" id="bt_write">Write</button> | |
|
33 | ||
|
24 | 34 | {% endblock %} |
|
25 | 35 | |
|
26 | 36 | {% block sidebar%} |
|
27 | 37 | {% include "sidebar_devices.html" %} |
|
28 | 38 | {% endblock %} |
|
29 | 39 | |
|
30 | 40 | {% block extra-js%} |
|
31 | 41 | <script type="text/javascript"> |
|
32 | 42 | |
|
33 | 43 | $("#bt_edit").click(function() { |
|
34 |
document.location = "{ |
|
|
44 | document.location = "{{ dev_conf.get_absolute_url_edit }}"; | |
|
45 | }); | |
|
46 | ||
|
47 | $("#bt_read").click(function() { | |
|
48 | document.location = "{{ dev_conf.get_absolute_url_read }}"; | |
|
49 | }); | |
|
50 | ||
|
51 | $("#bt_write").click(function() { | |
|
52 | document.location = "{{ dev_conf.get_absolute_url_write }}"; | |
|
53 | }); | |
|
54 | ||
|
55 | $("#bt_import").click(function() { | |
|
56 | document.location = "{{ dev_conf.get_absolute_url_import }}"; | |
|
57 | }); | |
|
58 | ||
|
59 | $("#bt_export").click(function() { | |
|
60 | document.location = "{{ dev_conf.get_absolute_url_export }}"; | |
|
35 | 61 | }); |
|
36 | 62 | |
|
37 | 63 | </script> |
|
38 | 64 | {% endblock %} No newline at end of file |
@@ -1,50 +1,50 | |||
|
1 | 1 | {% extends "base.html" %} |
|
2 | 2 | {% load bootstrap3 %} |
|
3 | 3 | {% load static %} |
|
4 | 4 | {% load main_tags %} |
|
5 | 5 | {% block extra-head %} |
|
6 | 6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> |
|
7 | 7 | {% endblock %} |
|
8 | 8 | |
|
9 | 9 | {% block conf-active %}active{% endblock %} |
|
10 | 10 | |
|
11 | 11 | {% block content-title %}{{title}}{% endblock %} |
|
12 | 12 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
13 | 13 | |
|
14 | 14 | {% block content %} |
|
15 | 15 | <table class="table table-hover"> |
|
16 | 16 | <tr> |
|
17 | 17 | <th>#</th> |
|
18 | 18 | {% for key in configuration_keys %} |
|
19 | 19 | <th>{{ key|title }}</th> |
|
20 | 20 | {% endfor%} |
|
21 | 21 | </tr> |
|
22 | 22 | {% for item in configurations %} |
|
23 |
<tr class="clickable-row" data-href=" |
|
|
23 | <tr class="clickable-row" data-href="{{item.get_absolute_url}}"> | |
|
24 | 24 | <td>{{ forloop.counter }}</td> |
|
25 | 25 | {% for key in configuration_keys %} |
|
26 | 26 | <td>{{ item|attr:key }}</td> |
|
27 | 27 | {% endfor %} |
|
28 | 28 | </tr> |
|
29 | 29 | {% endfor %} |
|
30 | 30 | </table> |
|
31 | 31 | <button class="btn btn-primary pull-right" id="bt_add">{{button}}</button> |
|
32 | 32 | {% endblock %} |
|
33 | 33 | |
|
34 | 34 | {% block sidebar%} |
|
35 | 35 | {% include "sidebar_devices.html" %} |
|
36 | 36 | {% endblock %} |
|
37 | 37 | |
|
38 | 38 | {% block extra-js%} |
|
39 | 39 | <script type="text/javascript"> |
|
40 | 40 | |
|
41 | 41 | $("#bt_add").click(function() { |
|
42 | 42 | document.location = "{% url 'url_add_dev_conf' 0%}"; |
|
43 | 43 | }); |
|
44 | 44 | |
|
45 | 45 | $(".clickable-row").click(function() { |
|
46 | 46 | document.location = $(this).data("href"); |
|
47 | 47 | }); |
|
48 | 48 | |
|
49 | 49 | </script> |
|
50 | 50 | {% endblock %} No newline at end of file |
@@ -1,11 +1,25 | |||
|
1 | 1 | from django.template.defaulttags import register |
|
2 | 2 | |
|
3 | 3 | @register.filter |
|
4 |
def attr( |
|
|
5 | if hasattr(object, key): | |
|
6 | return getattr(object, key) | |
|
7 | return object.get(key) | |
|
4 | def attr(instance, key): | |
|
5 | ||
|
6 | display_key = "get_" + key + "_display" | |
|
7 | ||
|
8 | if hasattr(instance, display_key): | |
|
9 | return getattr(instance, display_key)() | |
|
10 | ||
|
11 | if hasattr(instance, key): | |
|
12 | return getattr(instance, key) | |
|
13 | ||
|
14 | return instance.get(key) | |
|
8 | 15 | |
|
9 | 16 | @register.filter |
|
10 | 17 | def title(s): |
|
11 | 18 | return s.replace('_', ' ').title() |
|
19 | ||
|
20 | @register.simple_tag | |
|
21 | def get_verbose_field_name(instance, field_name): | |
|
22 | """ | |
|
23 | Returns verbose_name for a field. | |
|
24 | """ | |
|
25 | return instance._meta.get_field(field_name).verbose_name.title() No newline at end of file |
@@ -1,477 +1,569 | |||
|
1 | 1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse |
|
2 | from django.contrib import messages | |
|
2 | 3 | |
|
3 | 4 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm |
|
4 | 5 | from apps.cgs.forms import CGSConfigurationForm |
|
5 | 6 | from apps.jars.forms import JARSConfigurationForm |
|
6 | 7 | from apps.usrp.forms import USRPConfigurationForm |
|
7 | 8 | from apps.abs.forms import ABSConfigurationForm |
|
8 | 9 | from apps.rc.forms import RCConfigurationForm |
|
9 | 10 | from apps.dds.forms import DDSConfigurationForm |
|
10 | 11 | |
|
11 | 12 | from .models import Campaign, Experiment, Device, Configuration |
|
12 | 13 | from apps.cgs.models import CGSConfiguration |
|
13 | 14 | from apps.jars.models import JARSConfiguration |
|
14 | 15 | from apps.usrp.models import USRPConfiguration |
|
15 | 16 | from apps.abs.models import ABSConfiguration |
|
16 | 17 | from apps.rc.models import RCConfiguration |
|
17 | 18 | from apps.dds.models import DDSConfiguration |
|
18 | 19 | |
|
19 | 20 | # Create your views here. |
|
20 | 21 | |
|
21 | 22 | CONF_FORMS = { |
|
22 | 23 | 'rc': RCConfigurationForm, |
|
23 | 24 | 'dds': DDSConfigurationForm, |
|
24 | 25 | 'jars': JARSConfigurationForm, |
|
25 | 26 | 'cgs': CGSConfigurationForm, |
|
26 | 27 | 'abs': ABSConfigurationForm, |
|
27 | 28 | 'usrp': USRPConfigurationForm, |
|
28 | 29 | } |
|
29 | 30 | |
|
30 | 31 | CONF_MODELS = { |
|
31 | 32 | 'rc': RCConfiguration, |
|
32 | 33 | 'dds': DDSConfiguration, |
|
33 | 34 | 'jars': JARSConfiguration, |
|
34 | 35 | 'cgs': CGSConfiguration, |
|
35 | 36 | 'abs': ABSConfiguration, |
|
36 | 37 | 'usrp': USRPConfiguration, |
|
37 | 38 | } |
|
38 | 39 | |
|
39 | 40 | def index(request): |
|
40 | 41 | kwargs = {} |
|
41 | 42 | |
|
42 | 43 | return render(request, 'index.html', kwargs) |
|
43 | 44 | |
|
44 | 45 | def devices(request): |
|
45 | 46 | |
|
46 | 47 | devices = Device.objects.all().order_by('device_type__name') |
|
47 | 48 | |
|
48 | 49 | # keys = ['id', 'device_type__name', 'name', 'ip_address'] |
|
49 | 50 | keys = ['id', 'name', 'ip_address', 'device_type'] |
|
50 | 51 | |
|
51 | 52 | kwargs = {} |
|
52 | 53 | kwargs['device_keys'] = keys[1:] |
|
53 | 54 | kwargs['devices'] = devices#.values(*keys) |
|
54 | 55 | kwargs['title'] = 'Device' |
|
55 | 56 | kwargs['suptitle'] = 'List' |
|
56 | 57 | kwargs['button'] = 'New Device' |
|
57 | 58 | |
|
58 | 59 | return render(request, 'devices.html', kwargs) |
|
59 | 60 | |
|
60 | 61 | def device(request, id_dev): |
|
61 | 62 | |
|
62 | 63 | device = get_object_or_404(Device, pk=id_dev) |
|
63 | 64 | |
|
64 | 65 | kwargs = {} |
|
65 | 66 | kwargs['device'] = device |
|
66 | 67 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] |
|
67 | 68 | |
|
68 | 69 | kwargs['title'] = 'Device' |
|
69 | 70 | kwargs['suptitle'] = 'Details' |
|
70 | 71 | |
|
71 | 72 | kwargs['button'] = 'Add Device' |
|
72 | 73 | |
|
73 | 74 | return render(request, 'device.html', kwargs) |
|
74 | 75 | |
|
75 | 76 | def device_new(request): |
|
76 | 77 | |
|
77 | 78 | if request.method == 'GET': |
|
78 | 79 | form = DeviceForm() |
|
79 | 80 | |
|
80 | 81 | if request.method == 'POST': |
|
81 | 82 | form = DeviceForm(request.POST) |
|
82 | 83 | |
|
83 | 84 | if form.is_valid(): |
|
84 | 85 | form.save() |
|
85 | 86 | return redirect('url_devices') |
|
86 | 87 | |
|
87 | 88 | kwargs = {} |
|
88 | 89 | kwargs['form'] = form |
|
89 | 90 | kwargs['title'] = 'Device' |
|
90 | 91 | kwargs['suptitle'] = 'New' |
|
91 | 92 | kwargs['button'] = 'Create' |
|
92 | 93 | |
|
93 | 94 | return render(request, 'device_edit.html', kwargs) |
|
94 | 95 | |
|
95 | 96 | def device_edit(request, id_dev): |
|
96 | 97 | |
|
97 | 98 | device = get_object_or_404(Device, pk=id_dev) |
|
98 | 99 | |
|
99 | 100 | if request.method=='GET': |
|
100 | 101 | form = DeviceForm(instance=device) |
|
101 | 102 | |
|
102 | 103 | if request.method=='POST': |
|
103 | 104 | form = DeviceForm(request.POST, instance=device) |
|
104 | 105 | |
|
105 | 106 | if form.is_valid(): |
|
106 | 107 | form.save() |
|
107 | 108 | return redirect('url_devices') |
|
108 | 109 | |
|
109 | 110 | kwargs = {} |
|
110 | 111 | kwargs['form'] = form |
|
111 | 112 | kwargs['title'] = 'Device' |
|
112 | 113 | kwargs['suptitle'] = 'Edit' |
|
113 | 114 | kwargs['button'] = 'Update' |
|
114 | 115 | |
|
115 | 116 | return render(request, 'device_edit.html', kwargs) |
|
116 | 117 | |
|
117 | 118 | def device_delete(request, id_dev): |
|
118 | 119 | |
|
119 | 120 | device = get_object_or_404(Device, pk=id_dev) |
|
120 | 121 | |
|
121 | 122 | if request.method=='POST': |
|
122 | 123 | |
|
123 | 124 | if request.user.is_staff: |
|
124 | 125 | device.delete() |
|
125 | 126 | return redirect('url_devices') |
|
126 | 127 | |
|
127 | 128 | return HttpResponse("Not enough permission to delete this object") |
|
128 | 129 | |
|
129 | 130 | kwargs = {'object':device, 'dev_active':'active', |
|
130 | 131 | 'url_cancel':'url_device', 'id_item':id_dev} |
|
131 | 132 | |
|
132 | 133 | return render(request, 'item_delete.html', kwargs) |
|
133 | 134 | |
|
134 | 135 | def campaigns(request): |
|
135 | 136 | |
|
136 | 137 | campaigns = Campaign.objects.all().order_by('start_date') |
|
137 | 138 | |
|
138 | 139 | keys = ['id', 'name', 'start_date', 'end_date'] |
|
139 | 140 | |
|
140 | 141 | kwargs = {} |
|
141 | 142 | kwargs['campaign_keys'] = keys[1:] |
|
142 | 143 | kwargs['campaigns'] = campaigns#.values(*keys) |
|
143 | 144 | kwargs['title'] = 'Campaign' |
|
144 | 145 | kwargs['suptitle'] = 'List' |
|
145 | 146 | kwargs['button'] = 'New Campaign' |
|
146 | 147 | |
|
147 | 148 | return render(request, 'campaigns.html', kwargs) |
|
148 | 149 | |
|
149 | 150 | def campaign(request, id_camp): |
|
150 | 151 | |
|
151 | 152 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
152 | 153 | experiments = Experiment.objects.filter(campaign=campaign) |
|
153 | 154 | |
|
154 | 155 | form = CampaignForm(instance=campaign) |
|
155 | 156 | |
|
156 | 157 | kwargs = {} |
|
157 | 158 | kwargs['campaign'] = campaign |
|
158 | 159 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
159 | 160 | |
|
160 | 161 | keys = ['id', 'name', 'start_time', 'end_time'] |
|
161 | 162 | |
|
162 | 163 | kwargs['experiment_keys'] = keys[1:] |
|
163 | 164 | kwargs['experiments'] = experiments.values(*keys) |
|
164 | 165 | |
|
165 | 166 | kwargs['title'] = 'Campaign' |
|
166 | 167 | kwargs['suptitle'] = 'Details' |
|
167 | 168 | |
|
168 | 169 | kwargs['form'] = form |
|
169 | 170 | kwargs['button'] = 'Add Experiment' |
|
170 | 171 | |
|
171 | 172 | return render(request, 'campaign.html', kwargs) |
|
172 | 173 | |
|
173 | 174 | def campaign_new(request): |
|
174 | 175 | |
|
175 | 176 | if request.method == 'GET': |
|
176 | 177 | form = CampaignForm() |
|
177 | 178 | |
|
178 | 179 | if request.method == 'POST': |
|
179 | 180 | form = CampaignForm(request.POST) |
|
180 | 181 | |
|
181 | 182 | if form.is_valid(): |
|
182 | 183 | campaign = form.save() |
|
183 | 184 | return redirect('url_campaign', id_camp=campaign.id) |
|
184 | 185 | |
|
185 | 186 | kwargs = {} |
|
186 | 187 | kwargs['form'] = form |
|
187 | 188 | kwargs['title'] = 'Campaign' |
|
188 | 189 | kwargs['suptitle'] = 'New' |
|
189 | 190 | kwargs['button'] = 'Create' |
|
190 | 191 | |
|
191 | 192 | return render(request, 'campaign_edit.html', kwargs) |
|
192 | 193 | |
|
193 | 194 | def campaign_edit(request, id_camp): |
|
194 | 195 | |
|
195 | 196 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
196 | 197 | |
|
197 | 198 | if request.method=='GET': |
|
198 | 199 | form = CampaignForm(instance=campaign) |
|
199 | 200 | |
|
200 | 201 | if request.method=='POST': |
|
201 | 202 | form = CampaignForm(request.POST, instance=campaign) |
|
202 | 203 | |
|
203 | 204 | if form.is_valid(): |
|
204 | 205 | form.save() |
|
205 | 206 | return redirect('url_campaign', id_camp=id_camp) |
|
206 | 207 | |
|
207 | 208 | kwargs = {} |
|
208 | 209 | kwargs['form'] = form |
|
209 | 210 | kwargs['title'] = 'Campaign' |
|
210 | 211 | kwargs['suptitle'] = 'Edit' |
|
211 | 212 | kwargs['button'] = 'Update' |
|
212 | 213 | |
|
213 | 214 | return render(request, 'campaign_edit.html', kwargs) |
|
214 | 215 | |
|
215 | 216 | def campaign_delete(request, id_camp): |
|
216 | 217 | |
|
217 | 218 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
218 | 219 | |
|
219 | 220 | if request.method=='POST': |
|
220 | 221 | if request.user.is_staff: |
|
221 | 222 | campaign.delete() |
|
222 | 223 | return redirect('url_campaigns') |
|
223 | 224 | |
|
224 | 225 | return HttpResponse("Not enough permission to delete this object") |
|
225 | 226 | |
|
226 | 227 | kwargs = {'object':campaign, 'camp_active':'active', |
|
227 | 228 | 'url_cancel':'url_campaign', 'id_item':id_camp} |
|
228 | 229 | |
|
229 | 230 | return render(request, 'item_delete.html', kwargs) |
|
230 | 231 | |
|
231 | 232 | def experiments(request): |
|
232 | 233 | |
|
233 | 234 | experiment_list = Experiment.objects.all().order_by('campaign') |
|
234 | 235 | |
|
235 | 236 | keys = ['id', 'name', 'start_time', 'end_time', 'campaign'] |
|
236 | 237 | |
|
237 | 238 | kwargs = {} |
|
238 | 239 | |
|
239 | 240 | kwargs['experiment_keys'] = keys[1:] |
|
240 | 241 | kwargs['experiments'] = experiment_list#.values(*keys) |
|
241 | 242 | |
|
242 | 243 | kwargs['title'] = 'Experiment' |
|
243 | 244 | kwargs['suptitle'] = 'List' |
|
244 | 245 | kwargs['button'] = 'New Experiment' |
|
245 | 246 | |
|
246 | 247 | return render(request, 'experiments.html', kwargs) |
|
247 | 248 | |
|
248 | 249 | def experiment(request, id_exp): |
|
249 | 250 | |
|
250 | 251 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
251 | 252 | |
|
252 | 253 | experiments = Experiment.objects.filter(campaign=experiment.campaign) |
|
253 | 254 | configurations = Configuration.objects.filter(experiment=experiment) |
|
254 | 255 | |
|
255 | 256 | kwargs = {} |
|
256 | 257 | |
|
257 | 258 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] |
|
258 | 259 | conf_keys = ['id', 'device__name', 'device__device_type__name', 'device__ip_address'] |
|
259 | 260 | |
|
260 | 261 | |
|
261 | 262 | kwargs['experiment_keys'] = exp_keys[1:] |
|
262 | 263 | kwargs['experiment'] = experiment |
|
263 | 264 | |
|
264 | 265 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
265 | 266 | |
|
266 | 267 | kwargs['configuration_keys'] = conf_keys[1:] |
|
267 | 268 | kwargs['configurations'] = configurations.values(*conf_keys) |
|
268 | 269 | |
|
269 | 270 | kwargs['title'] = 'Experiment' |
|
270 | 271 | kwargs['suptitle'] = 'Details' |
|
271 | 272 | |
|
272 | 273 | kwargs['button'] = 'Add Device' |
|
273 | 274 | |
|
274 | 275 | return render(request, 'experiment.html', kwargs) |
|
275 | 276 | |
|
276 | 277 | def experiment_new(request, id_camp=0): |
|
277 | 278 | |
|
278 | 279 | if request.method == 'GET': |
|
279 | 280 | form = ExperimentForm(initial={'campaign':id_camp}) |
|
280 | 281 | |
|
281 | 282 | if request.method == 'POST': |
|
282 | 283 | form = ExperimentForm(request.POST, initial={'campaign':id_camp}) |
|
283 | 284 | |
|
284 | 285 | if form.is_valid(): |
|
285 | 286 | experiment = form.save() |
|
286 | 287 | return redirect('url_experiment', id_exp=experiment.id) |
|
287 | 288 | |
|
288 | 289 | kwargs = {} |
|
289 | 290 | kwargs['form'] = form |
|
290 | 291 | kwargs['title'] = 'Experiment' |
|
291 | 292 | kwargs['suptitle'] = 'New' |
|
292 | 293 | kwargs['button'] = 'Create' |
|
293 | 294 | |
|
294 | 295 | return render(request, 'experiment_edit.html', kwargs) |
|
295 | 296 | |
|
296 | 297 | def experiment_edit(request, id_exp): |
|
297 | 298 | |
|
298 | 299 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
299 | 300 | |
|
300 | 301 | if request.method == 'GET': |
|
301 | 302 | form = ExperimentForm(instance=experiment) |
|
302 | 303 | |
|
303 | 304 | if request.method=='POST': |
|
304 | 305 | form = ExperimentForm(request.POST, instance=experiment) |
|
305 | 306 | |
|
306 | 307 | if form.is_valid(): |
|
307 | 308 | experiment = form.save() |
|
308 | 309 | return redirect('url_experiment', id_exp=experiment.id) |
|
309 | 310 | |
|
310 | 311 | kwargs = {} |
|
311 | 312 | kwargs['form'] = form |
|
312 | 313 | kwargs['title'] = 'Experiment' |
|
313 | 314 | kwargs['suptitle'] = 'Edit' |
|
314 | 315 | kwargs['button'] = 'Update' |
|
315 | 316 | |
|
316 | 317 | return render(request, 'experiment_edit.html', kwargs) |
|
317 | 318 | |
|
318 | 319 | def experiment_delete(request, id_exp): |
|
319 | 320 | |
|
320 | 321 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
321 | 322 | |
|
322 | 323 | if request.method=='POST': |
|
323 | 324 | if request.user.is_staff: |
|
324 | 325 | id_camp = experiment.campaign.id |
|
325 | 326 | experiment.delete() |
|
326 | 327 | return redirect('url_campaign', id_camp=id_camp) |
|
327 | 328 | |
|
328 | 329 | return HttpResponse("Not enough permission to delete this object") |
|
329 | 330 | |
|
330 | 331 | kwargs = {'object':experiment, 'exp_active':'active', |
|
331 | 332 | 'url_cancel':'url_experiment', 'id_item':id_exp} |
|
332 | 333 | |
|
333 | 334 | return render(request, 'item_delete.html', kwargs) |
|
334 | 335 | |
|
335 | 336 | def dev_confs(request): |
|
336 | 337 | |
|
337 | 338 | configurations = Configuration.objects.all().order_by('experiment') |
|
338 | 339 | |
|
339 | 340 | # keys = ['id', 'device__device_type__name', 'device__name', 'experiment__campaign__name', 'experiment__name'] |
|
340 | 341 | |
|
341 | keys = ['id', 'device', 'experiment'] | |
|
342 | keys = ['id', 'device', 'experiment', 'type', 'programmed_date'] | |
|
342 | 343 | |
|
343 | 344 | kwargs = {} |
|
344 | 345 | |
|
345 | 346 | kwargs['configuration_keys'] = keys[1:] |
|
346 | 347 | kwargs['configurations'] = configurations#.values(*keys) |
|
347 | 348 | |
|
348 | 349 | kwargs['title'] = 'Configuration' |
|
349 | 350 | kwargs['suptitle'] = 'List' |
|
350 | 351 | kwargs['button'] = 'New Configuration' |
|
351 | 352 | |
|
352 | 353 | return render(request, 'dev_confs.html', kwargs) |
|
353 | 354 | |
|
354 | 355 | def dev_conf(request, id_conf): |
|
355 | 356 | |
|
356 | 357 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
357 | 358 | |
|
358 | 359 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
359 | 360 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
360 | 361 | |
|
361 | 362 | kwargs = {} |
|
362 | 363 | kwargs['dev_conf'] = dev_conf |
|
363 | 364 | kwargs['dev_conf_keys'] = ['experiment', 'device'] |
|
364 | 365 | |
|
365 | 366 | kwargs['title'] = 'Configuration' |
|
366 | 367 | kwargs['suptitle'] = 'Details' |
|
367 | 368 | |
|
368 | 369 | kwargs['button'] = 'Edit Configuration' |
|
369 | 370 | |
|
370 | 371 | ###### SIDEBAR ###### |
|
371 | experiments = Experiment.objects.filter(campaign=conf.experiment.campaign) | |
|
372 | configurations = Configuration.objects.filter(experiment=conf.experiment) | |
|
373 | ||
|
374 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] | |
|
375 | conf_keys = ['id', 'device__name', 'device__device_type__name', 'device__ip_address'] | |
|
376 | ||
|
377 | kwargs['experiment_keys'] = exp_keys[1:] | |
|
378 | kwargs['experiments'] = experiments.values(*exp_keys) | |
|
379 | ||
|
380 | kwargs['configuration_keys'] = conf_keys[1:] | |
|
381 | kwargs['configurations'] = configurations.values(*conf_keys) | |
|
372 | kwargs.update(sidebar(conf)) | |
|
382 | 373 | |
|
383 | 374 | return render(request, 'dev_conf.html', kwargs) |
|
384 | 375 | |
|
385 | 376 | def dev_conf_new(request, id_exp=0): |
|
386 | 377 | |
|
387 | 378 | if request.method == 'GET': |
|
388 | 379 | form = ConfigurationForm(initial={'experiment':id_exp}) |
|
389 | 380 | |
|
390 | 381 | if request.method == 'POST': |
|
391 | 382 | form = ConfigurationForm(request.POST) |
|
392 | 383 | |
|
393 | 384 | if form.is_valid(): |
|
394 | 385 | experiment = Experiment.objects.get(pk=request.POST['experiment']) |
|
395 | 386 | device = Device.objects.get(pk=request.POST['device']) |
|
396 | 387 | |
|
397 | 388 | exp_devices = Device.objects.filter(configuration__experiment=experiment) |
|
398 | 389 | |
|
399 | 390 | if device.id not in exp_devices.values('id',): |
|
400 | 391 | |
|
401 | 392 | DevConfModel = CONF_MODELS[device.device_type.name] |
|
402 | 393 | conf = DevConfModel(experiment=experiment, device=device) |
|
403 | 394 | conf.save() |
|
404 | 395 | |
|
405 | 396 | return redirect('url_experiment', id_exp=experiment.id) |
|
406 | 397 | |
|
407 | 398 | kwargs = {} |
|
408 | 399 | kwargs['form'] = form |
|
409 | 400 | kwargs['title'] = 'Configuration' |
|
410 | 401 | kwargs['suptitle'] = 'New' |
|
411 | 402 | kwargs['button'] = 'Create' |
|
412 | 403 | |
|
404 | ###### SIDEBAR ###### | |
|
405 | kwargs.update(sidebar(conf)) | |
|
406 | ||
|
413 | 407 | return render(request, 'dev_conf_edit.html', kwargs) |
|
414 | 408 | |
|
415 | 409 | def dev_conf_edit(request, id_conf): |
|
416 | 410 | |
|
417 | 411 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
418 | 412 | |
|
419 | 413 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
420 | 414 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
421 | 415 | |
|
422 | 416 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
423 | 417 | |
|
424 | 418 | if request.method=='GET': |
|
425 | 419 | form = DevConfForm(instance=dev_conf) |
|
426 | 420 | |
|
427 | 421 | if request.method=='POST': |
|
428 | 422 | form = DevConfForm(request.POST, instance=dev_conf) |
|
429 | 423 | |
|
430 | 424 | if form.is_valid(): |
|
431 | 425 | form.save() |
|
432 | 426 | return redirect('url_dev_conf', id_conf=id_conf) |
|
433 | 427 | |
|
434 | 428 | kwargs = {} |
|
435 | 429 | kwargs['form'] = form |
|
436 | 430 | kwargs['title'] = 'Device Configuration' |
|
437 | 431 | kwargs['suptitle'] = 'Edit' |
|
438 | 432 | kwargs['button'] = 'Update' |
|
439 | 433 | |
|
434 | ###### SIDEBAR ###### | |
|
435 | kwargs.update(sidebar(conf)) | |
|
436 | ||
|
440 | 437 | return render(request, 'dev_conf_edit.html', kwargs) |
|
441 | 438 | |
|
439 | def dev_conf_read(request, id_conf): | |
|
440 | ||
|
441 | conf = get_object_or_404(Configuration, pk=id_conf) | |
|
442 | ||
|
443 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
|
444 | dev_conf = DevConfModel.objects.get(pk=id_conf) | |
|
445 | ||
|
446 | kwargs = {} | |
|
447 | kwargs['dev_conf'] = dev_conf | |
|
448 | kwargs['dev_conf_keys'] = ['experiment', 'device'] | |
|
449 | ||
|
450 | kwargs['title'] = 'Configuration' | |
|
451 | kwargs['suptitle'] = 'Details' | |
|
452 | ||
|
453 | kwargs['button'] = 'Edit Configuration' | |
|
454 | ||
|
455 | ###### SIDEBAR ###### | |
|
456 | kwargs.update(sidebar(conf)) | |
|
457 | ||
|
458 | messages.error(request, "Read View not implemented yet for this configuration") | |
|
459 | ||
|
460 | return render(request, 'dev_conf.html', kwargs) | |
|
461 | ||
|
462 | def dev_conf_write(request, id_conf): | |
|
463 | ||
|
464 | conf = get_object_or_404(Configuration, pk=id_conf) | |
|
465 | ||
|
466 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
|
467 | dev_conf = DevConfModel.objects.get(pk=id_conf) | |
|
468 | ||
|
469 | kwargs = {} | |
|
470 | kwargs['dev_conf'] = dev_conf | |
|
471 | kwargs['dev_conf_keys'] = ['experiment', 'device'] | |
|
472 | ||
|
473 | kwargs['title'] = 'Configuration' | |
|
474 | kwargs['suptitle'] = 'Details' | |
|
475 | ||
|
476 | kwargs['button'] = 'Edit Configuration' | |
|
477 | ||
|
478 | ###### SIDEBAR ###### | |
|
479 | kwargs.update(sidebar(conf)) | |
|
480 | ||
|
481 | messages.error(request, "Write View not implemented yet for this configuration") | |
|
482 | ||
|
483 | return render(request, 'dev_conf.html', kwargs) | |
|
484 | ||
|
485 | def dev_conf_import(request, id_conf): | |
|
486 | ||
|
487 | conf = get_object_or_404(Configuration, pk=id_conf) | |
|
488 | ||
|
489 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
|
490 | dev_conf = DevConfModel.objects.get(pk=id_conf) | |
|
491 | ||
|
492 | kwargs = {} | |
|
493 | kwargs['dev_conf'] = dev_conf | |
|
494 | kwargs['dev_conf_keys'] = ['experiment', 'device'] | |
|
495 | ||
|
496 | kwargs['title'] = 'Configuration' | |
|
497 | kwargs['suptitle'] = 'Details' | |
|
498 | ||
|
499 | kwargs['button'] = 'Edit Configuration' | |
|
500 | ||
|
501 | ###### SIDEBAR ###### | |
|
502 | kwargs.update(sidebar(conf)) | |
|
503 | ||
|
504 | messages.error(request, "Import View not implemented yet for this configuration") | |
|
505 | ||
|
506 | return render(request, 'dev_conf.html', kwargs) | |
|
507 | ||
|
508 | def dev_conf_export(request, id_conf): | |
|
509 | ||
|
510 | conf = get_object_or_404(Configuration, pk=id_conf) | |
|
511 | ||
|
512 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
|
513 | dev_conf = DevConfModel.objects.get(pk=id_conf) | |
|
514 | ||
|
515 | kwargs = {} | |
|
516 | kwargs['dev_conf'] = dev_conf | |
|
517 | kwargs['dev_conf_keys'] = ['experiment', 'device'] | |
|
518 | ||
|
519 | kwargs['title'] = 'Configuration' | |
|
520 | kwargs['suptitle'] = 'Details' | |
|
521 | ||
|
522 | kwargs['button'] = 'Edit Configuration' | |
|
523 | ||
|
524 | ###### SIDEBAR ###### | |
|
525 | kwargs.update(sidebar(conf)) | |
|
526 | ||
|
527 | messages.error(request, "Export View not implemented yet for this configuration") | |
|
528 | ||
|
529 | return render(request, 'dev_conf.html', kwargs) | |
|
530 | ||
|
442 | 531 | def dev_conf_delete(request, id_conf): |
|
443 | 532 | |
|
444 | 533 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
445 | 534 | |
|
446 | 535 | if request.method=='POST': |
|
447 | 536 | if request.user.is_staff: |
|
448 | 537 | id_exp = conf.experiment.id |
|
449 | 538 | conf.delete() |
|
450 | 539 | return redirect('url_experiment', id_exp=id_exp) |
|
451 | 540 | |
|
452 | 541 | return HttpResponse("Not enough permission to delete this object") |
|
453 | 542 | |
|
454 | 543 | kwargs = {'object':conf, 'conf_active':'active', |
|
455 | 544 | 'url_cancel':'url_dev_conf', 'id_item':id_conf} |
|
456 | 545 | |
|
546 | ###### SIDEBAR ###### | |
|
547 | kwargs.update(sidebar(conf)) | |
|
548 | ||
|
457 | 549 | return render(request, 'item_delete.html', kwargs) |
|
458 | 550 | |
|
459 | 551 | def sidebar(conf): |
|
460 | 552 | |
|
461 | 553 | experiments = Experiment.objects.filter(campaign=conf.experiment.campaign) |
|
462 | configurations = Configuration.objects.filter(experiment=conf.experiment) | |
|
554 | configurations = Configuration.objects.filter(experiment=conf.experiment, type=0) | |
|
463 | 555 | |
|
464 | 556 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] |
|
465 | 557 | conf_keys = ['id', 'device__name', 'device__device_type__name', 'device__ip_address'] |
|
466 | 558 | |
|
467 | 559 | kwargs = {} |
|
468 | 560 | |
|
469 | 561 | kwargs['dev_conf'] = conf |
|
470 | 562 | |
|
471 | 563 | kwargs['experiment_keys'] = exp_keys[1:] |
|
472 | 564 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
473 | 565 | |
|
474 | 566 | kwargs['configuration_keys'] = conf_keys[1:] |
|
475 | 567 | kwargs['configurations'] = configurations.values(*conf_keys) |
|
476 | 568 | |
|
477 | 569 | return kwargs No newline at end of file |
@@ -1,11 +1,16 | |||
|
1 | 1 | from django.conf.urls import url |
|
2 | 2 | |
|
3 | 3 | urlpatterns = ( |
|
4 | 4 | url(r'^(?P<id>-?\d+)/$', 'apps.rc.views.conf', name='url_rc_conf'), |
|
5 | 5 | url(r'^(?P<id>-?\d+)/edit/$', 'apps.rc.views.conf_edit', name='url_edit_rc_conf'), |
|
6 | url(r'^(?P<id_conf>-?\d+)/write/$', 'apps.main.views.dev_conf_write', name='url_write_rc_conf'), | |
|
7 | url(r'^(?P<id_conf>-?\d+)/read/$', 'apps.main.views.dev_conf_read', name='url_read_rc_conf'), | |
|
8 | url(r'^(?P<id_conf>-?\d+)/import/$', 'apps.main.views.dev_conf_import', name='url_import_rc_conf'), | |
|
9 | url(r'^(?P<id_conf>-?\d+)/export/$', 'apps.main.views.dev_conf_export', name='url_export_rc_conf'), | |
|
10 | ||
|
6 | 11 | url(r'^(?P<conf_id>-?\d+)/add_line/$', 'apps.rc.views.add_line', name='url_add_rc_line'), |
|
7 | 12 | url(r'^(?P<conf_id>-?\d+)/update_lines/$', 'apps.rc.views.update_lines', name='url_update_rc_lines'), |
|
8 | 13 | url(r'^(?P<conf_id>-?\d+)/edit_lines/$', 'apps.rc.views.edit_lines', name='url_edit_rc_lines'), |
|
9 | 14 | url(r'^(?P<conf_id>-?\d+)/add_line/(?P<line_type_id>-?\d+)/$', 'apps.rc.views.add_line', name='url_add_rc_line'), |
|
10 | 15 | url(r'^(?P<conf_id>-?\d+)/line/(?P<line_id>-?\d+)/delete/$', 'apps.rc.views.remove_line', name='url_remove_rc_line'), |
|
11 | 16 | ) |
@@ -1,6 +1,10 | |||
|
1 | 1 | from django.conf.urls import url |
|
2 | 2 | |
|
3 | 3 | urlpatterns = ( |
|
4 | 4 | url(r'^(?P<id_conf>-?\d+)/$', 'apps.main.views.dev_conf', name='url_usrp_conf'), |
|
5 | 5 | url(r'^(?P<id_conf>-?\d+)/edit/$', 'apps.main.views.dev_conf_edit', name='url_edit_usrp_conf'), |
|
6 | url(r'^(?P<id_conf>-?\d+)/write/$', 'apps.main.views.dev_conf_write', name='url_write_usrp_conf'), | |
|
7 | url(r'^(?P<id_conf>-?\d+)/read/$', 'apps.main.views.dev_conf_read', name='url_read_usrp_conf'), | |
|
8 | url(r'^(?P<id_conf>-?\d+)/import/$', 'apps.main.views.dev_conf_import', name='url_import_usrp_conf'), | |
|
9 | url(r'^(?P<id_conf>-?\d+)/export/$', 'apps.main.views.dev_conf_export', name='url_export_usrp_conf'), | |
|
6 | 10 | ) |
General Comments 0
You need to be logged in to leave comments.
Login now