@@ -0,0 +1,24 | |||
|
1 | from django import forms | |
|
2 | from .models import DDSConfiguration | |
|
3 | ||
|
4 | from django.core.validators import MinValueValidator, MaxValueValidator | |
|
5 | ||
|
6 | class DDSConfigurationForm(forms.ModelForm): | |
|
7 | ||
|
8 | freq0 = forms.FloatField(label='Frequency', validators=[MinValueValidator(0e6), MaxValueValidator(150e6)]) | |
|
9 | pha0 = forms.FloatField(label='Phase', validators=[MinValueValidator(0), MaxValueValidator(360)]) | |
|
10 | ||
|
11 | freq1 = forms.FloatField(label='Modulated Frequency', validators=[MinValueValidator(5e6), MaxValueValidator(150e6)], required=False) | |
|
12 | pha1 = forms.FloatField(label='Modulated Phase', validators=[MinValueValidator(0), MaxValueValidator(360)], required=False) | |
|
13 | ||
|
14 | def __init__(self, *args, **kwargs): | |
|
15 | #request = kwargs.pop('request') | |
|
16 | super(DDSConfigurationForm, self).__init__(*args, **kwargs) | |
|
17 | ||
|
18 | def clean(self): | |
|
19 | # Custom validation to force an integer when type of unit = "Unit" | |
|
20 | return | |
|
21 | ||
|
22 | class Meta: | |
|
23 | model = DDSConfiguration | |
|
24 | fields = ('clock', 'multiplier', 'modulation') |
@@ -0,0 +1,1 | |||
|
1 | {% extends "conf_device.html" %} No newline at end of file |
@@ -2,9 +2,20 from django.db import models | |||
|
2 | 2 | from apps.main.models import Configuration |
|
3 | 3 | # Create your models here. |
|
4 | 4 | |
|
5 | from django.core.validators import MinValueValidator, MaxValueValidator | |
|
6 | ||
|
5 | 7 | class DDSConfiguration(Configuration): |
|
6 | 8 | |
|
7 | ||
|
9 | clock = models.FloatField(verbose_name='Clock Master',validators=[MinValueValidator(5e6), MaxValueValidator(50e6)], blank=True, null=True) | |
|
10 | multiplier = models.PositiveIntegerField(verbose_name='Multiplier',validators=[MinValueValidator(0), MaxValueValidator(20)], default=4) | |
|
11 | modulation = models.PositiveIntegerField(verbose_name='Modulation',validators=[MinValueValidator(0), MaxValueValidator(3)], default=0) | |
|
12 | frequency0 = models.PositiveIntegerField(verbose_name='Frequency 0',validators=[MinValueValidator(0), MaxValueValidator(2**32-1)], blank=True, null=True) | |
|
13 | frequency1 = models.PositiveIntegerField(verbose_name='Frequency 1',validators=[MinValueValidator(0), MaxValueValidator(2**32-1)], blank=True, null=True) | |
|
14 | phase0 = models.PositiveIntegerField(verbose_name='Phase 0',validators=[MinValueValidator(0), MaxValueValidator(2**14-1)], blank=True, null=True) | |
|
15 | phase1 = models.PositiveIntegerField(verbose_name='Phase 1',validators=[MinValueValidator(0), MaxValueValidator(2**14-1)], blank=True, null=True) | |
|
16 | amplitude_chA = models.PositiveIntegerField(verbose_name='Amplitude CHA',validators=[MinValueValidator(0), MaxValueValidator(2**10-1)], blank=True, null=True) | |
|
17 | amplitude_chB = models.PositiveIntegerField(verbose_name='Amplitude CHB',validators=[MinValueValidator(0), MaxValueValidator(2**10-1)], blank=True, null=True) | |
|
18 | ||
|
8 | 19 | class Meta: |
|
9 | 20 | db_table = 'dds_configurations' |
|
10 | 21 | No newline at end of file |
@@ -1,5 +1,6 | |||
|
1 | 1 | from django.conf.urls import url |
|
2 | 2 | |
|
3 | 3 | urlpatterns = ( |
|
4 | ||
|
4 | url(r'^(?P<id_conf>-?\d+)/$', 'apps.dds.views.config_dds', name='url_conf_dds'), | |
|
5 | url(r'^(?P<id_conf>-?\d+)/edit/$', 'apps.dds.views.config_dds_edit', name='url_conf_dds_edit'), | |
|
5 | 6 | ) |
@@ -1,3 +1,57 | |||
|
1 | from django.shortcuts import render | |
|
1 | # Create your views here. | |
|
2 | ||
|
3 | from django.shortcuts import redirect, render | |
|
2 | 4 | |
|
5 | from apps.main.models import Device | |
|
6 | from .models import DDSConfiguration | |
|
7 | from .forms import DDSConfigurationForm | |
|
3 | 8 | # Create your views here. |
|
9 | ||
|
10 | def config_dds(request, id_conf): | |
|
11 | ||
|
12 | if id_conf: | |
|
13 | ||
|
14 | conf = DDSConfiguration.objects.get(pk=id_conf) | |
|
15 | form = DDSConfigurationForm(instance=conf) | |
|
16 | experiment = conf.experiment | |
|
17 | ||
|
18 | devices = Device.objects.filter(configuration__experiment=experiment) | |
|
19 | ||
|
20 | deviceList = devices.values('configuration__id', 'device_type__alias', 'device_type__name') | |
|
21 | ||
|
22 | for thisDevice in deviceList: | |
|
23 | if thisDevice['configuration__id'] == conf.id: | |
|
24 | thisDevice['active'] = 'active' | |
|
25 | break | |
|
26 | ||
|
27 | device = thisDevice | |
|
28 | ||
|
29 | else: | |
|
30 | form = DDSConfigurationForm() | |
|
31 | device = '' | |
|
32 | experiment = '' | |
|
33 | devices = {} | |
|
34 | ||
|
35 | kwargs = { | |
|
36 | 'form': form, | |
|
37 | 'device': device, | |
|
38 | 'experiment': experiment, | |
|
39 | 'devices': deviceList | |
|
40 | } | |
|
41 | ||
|
42 | # return render_to_response('conf_dds.html', kwargs, context_instance=RequestContext(request)) | |
|
43 | return render(request, 'conf_dds.html', kwargs) | |
|
44 | ||
|
45 | def config_dds_edit(request, id_conf): | |
|
46 | ||
|
47 | if request.method=='POST': | |
|
48 | ||
|
49 | conf = DDSConfiguration.objects.get(pk=id_conf) | |
|
50 | form = DDSConfigurationForm(instance=conf) | |
|
51 | ||
|
52 | if form.is_valid(): | |
|
53 | form.save() | |
|
54 | else: | |
|
55 | raise ValueError, "Error" | |
|
56 | ||
|
57 | return redirect('url_conf_dds', id_conf=id_conf) No newline at end of file |
|
1 | NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now