@@ -7,14 +7,14 from django.core.validators import MinValueValidator, MaxValueValidator | |||||
7 | from apps.main.models import Device, Experiment |
|
7 | from apps.main.models import Device, Experiment | |
8 |
|
8 | |||
9 | from files import read_json_file |
|
9 | from files import read_json_file | |
10 | # Create your models here. |
|
10 | # Create your models here. validators=[MinValueValidator(62.5e6), MaxValueValidator(450e6)] | |
11 |
|
11 | |||
12 | class CGSConfiguration(Configuration): |
|
12 | class CGSConfiguration(Configuration): | |
13 |
|
13 | |||
14 |
freq0 = models. |
|
14 | freq0 = models.IntegerField(verbose_name='Frequency 0',validators=[MinValueValidator(0), MaxValueValidator(450e6)], blank=True, null=True) | |
15 |
freq1 = models. |
|
15 | freq1 = models.IntegerField(verbose_name='Frequency 1',validators=[MinValueValidator(0), MaxValueValidator(450e6)], blank=True, null=True) | |
16 |
freq2 = models. |
|
16 | freq2 = models.IntegerField(verbose_name='Frequency 2',validators=[MinValueValidator(0), MaxValueValidator(450e6)], blank=True, null=True) | |
17 |
freq3 = models. |
|
17 | freq3 = models.IntegerField(verbose_name='Frequency 3',validators=[MinValueValidator(0), MaxValueValidator(450e6)], blank=True, null=True) | |
18 | #jfreqs = JSONField(default={"frequencies":[{"f0":freq0,"f1":freq1,"f2":freq2,"f3":freq3}]}, blank=True) |
|
18 | #jfreqs = JSONField(default={"frequencies":[{"f0":freq0,"f1":freq1,"f2":freq2,"f3":freq3}]}, blank=True) | |
19 |
|
19 | |||
20 |
|
20 |
@@ -1,5 +1,6 | |||||
1 | from django.shortcuts import redirect, render, get_object_or_404 |
|
1 | from django.shortcuts import redirect, render, get_object_or_404 | |
2 | from django.contrib import messages |
|
2 | from django.contrib import messages | |
|
3 | from django.http import HttpResponse | |||
3 |
|
4 | |||
4 | from apps.main.models import Experiment, Configuration |
|
5 | from apps.main.models import Experiment, Configuration | |
5 | from .models import CGSConfiguration |
|
6 | from .models import CGSConfiguration | |
@@ -76,21 +77,14 def cgs_conf_edit(request, id_conf): | |||||
76 | form = CGSConfigurationForm(request.POST, instance=conf) |
|
77 | form = CGSConfigurationForm(request.POST, instance=conf) | |
77 |
|
78 | |||
78 | if form.is_valid(): |
|
79 | if form.is_valid(): | |
|
80 | if conf.freq0 == None: conf.freq0 = 0 | |||
|
81 | if conf.freq1 == None: conf.freq1 = 0 | |||
|
82 | if conf.freq2 == None: conf.freq2 = 0 | |||
|
83 | if conf.freq3 == None: conf.freq3 = 0 | |||
|
84 | ||||
79 | conf = form.save(commit=False) |
|
85 | conf = form.save(commit=False) | |
80 |
|
86 | |||
81 | if conf.verify_frequencies(): |
|
87 | if conf.verify_frequencies(): | |
82 |
|
||||
83 | if conf.freq0 == None: conf.freq0 = 0 |
|
|||
84 | if conf.freq1 == None: conf.freq0 = 0 |
|
|||
85 | if conf.freq2 == None: conf.freq0 = 0 |
|
|||
86 | if conf.freq3 == None: conf.freq0 = 0 |
|
|||
87 |
|
||||
88 |
|
||||
89 | data = {'f0': str(conf.freq0), 'f1': str(conf.freq1), |
|
|||
90 | 'f2': str(conf.freq2), 'f3': str(conf.freq3)} |
|
|||
91 | json_data = json.dumps(data) |
|
|||
92 | conf.parameters = json_data |
|
|||
93 |
|
||||
94 | conf.save() |
|
88 | conf.save() | |
95 | return redirect('url_cgs_conf', id_conf=conf.id) |
|
89 | return redirect('url_cgs_conf', id_conf=conf.id) | |
96 |
|
90 | |||
@@ -116,14 +110,10 def cgs_conf_write(request, id_conf): | |||||
116 | port=conf.device.port_address |
|
110 | port=conf.device.port_address | |
117 |
|
111 | |||
118 | #Frequencies from form |
|
112 | #Frequencies from form | |
119 | if conf.freq0 == None: conf.freq0 = 0 |
|
113 | f0 = conf.freq0 | |
120 | if conf.freq1 == None: conf.freq0 = 0 |
|
114 | f1 = conf.freq1 | |
121 | if conf.freq2 == None: conf.freq0 = 0 |
|
115 | f2 = conf.freq2 | |
122 | if conf.freq3 == None: conf.freq0 = 0 |
|
116 | f3 = conf.freq3 | |
123 | f0 = int(conf.freq0) |
|
|||
124 | f1 = int(conf.freq1) |
|
|||
125 | f2 = int(conf.freq2) |
|
|||
126 | f3 = int(conf.freq3) |
|
|||
127 |
|
117 | |||
128 | try: |
|
118 | try: | |
129 | post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} |
|
119 | post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} | |
@@ -302,9 +292,31 def cgs_conf_export(request, id_conf): | |||||
302 | ip=conf.device.ip_address |
|
292 | ip=conf.device.ip_address | |
303 | port=conf.device.port_address |
|
293 | port=conf.device.port_address | |
304 |
|
294 | |||
305 |
if request.method==' |
|
295 | if request.method=='GET': | |
306 | return HttpResponse(conf.parameters, content_type="application/json") |
|
296 | data = {"Frequencies": [ | |
|
297 | ["freq0", conf.freq0], | |||
|
298 | ["freq1", conf.freq1], | |||
|
299 | ["freq2", conf.freq2], | |||
|
300 | ["freq3", conf.freq3] | |||
|
301 | ]} | |||
|
302 | json_data = json.dumps(data) | |||
|
303 | conf.parameters = json_data | |||
|
304 | response = HttpResponse(conf.parameters, content_type="application/json") | |||
|
305 | response['Content-Disposition'] = 'attachment; filename="data.json"' | |||
|
306 | ||||
|
307 | return response | |||
307 |
|
308 | |||
308 | return render(request, 'cgs_conf.html') |
|
309 | kwargs = {} | |
309 | #return redirect(conf.get_absolute_url()) |
|
310 | kwargs['dev_conf'] = conf | |
310 |
|
311 | kwargs['dev_conf_keys'] = ['experiment', 'device', | ||
|
312 | 'freq0', 'freq1', | |||
|
313 | 'freq2', 'freq3'] | |||
|
314 | ||||
|
315 | kwargs['title'] = 'CGS Configuration' | |||
|
316 | kwargs['suptitle'] = 'Details' | |||
|
317 | ||||
|
318 | kwargs['button'] = 'Edit Configuration' | |||
|
319 | ||||
|
320 | ###### SIDEBAR ###### | |||
|
321 | kwargs.update(sidebar(conf)) | |||
|
322 | return render(request, 'cgs_conf.html', kwargs) No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now