@@ -1,87 +1,29 | |||
|
1 | 1 | from django import forms |
|
2 | 2 | from apps.main.models import Device, Experiment |
|
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 | 10 | if instance and instance.pk: |
|
11 | 11 | devices = Device.objects.filter(device_type__name='jars') |
|
12 | 12 | |
|
13 | 13 | if instance.experiment: |
|
14 | 14 | experiments = Experiment.objects.filter(pk=instance.experiment.id) |
|
15 | 15 | self.fields['experiment'].widget.choices = [(experiment.id, experiment) for experiment in experiments] |
|
16 | 16 | |
|
17 | 17 | self.fields['device'].widget.choices = [(device.id, device) for device in devices] |
|
18 | 18 | |
|
19 | 19 | #-------------JARS Configuration needs an Experiment----------------- |
|
20 | 20 | def clean(self): |
|
21 | 21 | cleaned_data = super(JARSConfigurationForm, self).clean() |
|
22 | 22 | experiment = cleaned_data.get('experiment') |
|
23 | 23 | if experiment == None: |
|
24 | 24 | msg = "Error: Jars Configuration needs an Experiment" |
|
25 | 25 | self.add_error('experiment', msg) |
|
26 | 26 | |
|
27 | 27 | class Meta: |
|
28 | 28 | model = JARSConfiguration |
|
29 | exclude = ('type', 'parameters', 'status', 'rc', 'cards_number', | |
|
30 | 'channels_number', 'channels', 'rd_directory', 'raw_data_blocks', | |
|
31 | 'data_type', 'acq_profiles', 'profiles_block', 'filter', | |
|
32 | 'create_directory', 'include_expname', 'acq_link', | |
|
33 | 'view_raw_data') | |
|
34 | ||
|
35 | ||
|
36 | class JARSConfigurationForm_Raw(forms.ModelForm): | |
|
37 | def __init__(self, *args, **kwargs): | |
|
38 | super(JARSConfigurationForm, self).__init__(*args, **kwargs) | |
|
39 | instance = getattr(self, 'instance', None) | |
|
40 | ||
|
41 | if instance and instance.pk: | |
|
42 | devices = Device.objects.filter(device_type__name='jars') | |
|
43 | ||
|
44 | if instance.experiment: | |
|
45 | experiments = Experiment.objects.filter(pk=instance.experiment.id) | |
|
46 | self.fields['experiment'].widget.choices = [(experiment.id, experiment) for experiment in experiments] | |
|
47 | ||
|
48 | self.fields['device'].widget.choices = [(device.id, device) for device in devices] | |
|
49 | ||
|
50 | #-------------JARS Configuration needs an Experiment----------------- | |
|
51 | def clean(self): | |
|
52 | cleaned_data = super(JARSConfigurationForm, self).clean() | |
|
53 | experiment = cleaned_data.get('experiment') | |
|
54 | if experiment == None: | |
|
55 | msg = "Error: Jars Configuration needs an Experiment" | |
|
56 | self.add_error('experiment', msg) | |
|
57 | ||
|
58 | class Meta: | |
|
59 | model = JARSConfiguration | |
|
60 | exclude = ('type', 'parameters', 'status') | |
|
61 | ||
|
62 | ||
|
63 | class JARSConfigurationForm_Pro(forms.ModelForm): | |
|
64 | def __init__(self, *args, **kwargs): | |
|
65 | super(JARSConfigurationForm, self).__init__(*args, **kwargs) | |
|
66 | instance = getattr(self, 'instance', None) | |
|
67 | ||
|
68 | if instance and instance.pk: | |
|
69 | devices = Device.objects.filter(device_type__name='jars') | |
|
70 | ||
|
71 | if instance.experiment: | |
|
72 | experiments = Experiment.objects.filter(pk=instance.experiment.id) | |
|
73 | self.fields['experiment'].widget.choices = [(experiment.id, experiment) for experiment in experiments] | |
|
74 | ||
|
75 | self.fields['device'].widget.choices = [(device.id, device) for device in devices] | |
|
76 | ||
|
77 | #-------------JARS Configuration needs an Experiment----------------- | |
|
78 | def clean(self): | |
|
79 | cleaned_data = super(JARSConfigurationForm, self).clean() | |
|
80 | experiment = cleaned_data.get('experiment') | |
|
81 | if experiment == None: | |
|
82 | msg = "Error: Jars Configuration needs an Experiment" | |
|
83 | self.add_error('experiment', msg) | |
|
84 | ||
|
85 | class Meta: | |
|
86 | model = JARSConfiguration | |
|
87 | 29 |
exclude = ('type', 'parameters', 'status') |
General Comments 0
You need to be logged in to leave comments.
Login now