@@ -1,87 +1,29 | |||||
1 | from django import forms |
|
1 | from django import forms | |
2 | from apps.main.models import Device, Experiment |
|
2 | from apps.main.models import Device, Experiment | |
3 | from .models import JARSConfiguration |
|
3 | from .models import JARSConfiguration | |
4 |
|
4 | |||
5 | class JARSConfigurationForm(forms.ModelForm): |
|
5 | class JARSConfigurationForm(forms.ModelForm): | |
6 | def __init__(self, *args, **kwargs): |
|
6 | def __init__(self, *args, **kwargs): | |
7 | super(JARSConfigurationForm, self).__init__(*args, **kwargs) |
|
7 | super(JARSConfigurationForm, self).__init__(*args, **kwargs) | |
8 | instance = getattr(self, 'instance', None) |
|
8 | instance = getattr(self, 'instance', None) | |
9 |
|
9 | |||
10 | if instance and instance.pk: |
|
10 | if instance and instance.pk: | |
11 | devices = Device.objects.filter(device_type__name='jars') |
|
11 | devices = Device.objects.filter(device_type__name='jars') | |
12 |
|
12 | |||
13 | if instance.experiment: |
|
13 | if instance.experiment: | |
14 | experiments = Experiment.objects.filter(pk=instance.experiment.id) |
|
14 | experiments = Experiment.objects.filter(pk=instance.experiment.id) | |
15 | self.fields['experiment'].widget.choices = [(experiment.id, experiment) for experiment in experiments] |
|
15 | self.fields['experiment'].widget.choices = [(experiment.id, experiment) for experiment in experiments] | |
16 |
|
16 | |||
17 | self.fields['device'].widget.choices = [(device.id, device) for device in devices] |
|
17 | self.fields['device'].widget.choices = [(device.id, device) for device in devices] | |
18 |
|
18 | |||
19 | #-------------JARS Configuration needs an Experiment----------------- |
|
19 | #-------------JARS Configuration needs an Experiment----------------- | |
20 | def clean(self): |
|
20 | def clean(self): | |
21 | cleaned_data = super(JARSConfigurationForm, self).clean() |
|
21 | cleaned_data = super(JARSConfigurationForm, self).clean() | |
22 | experiment = cleaned_data.get('experiment') |
|
22 | experiment = cleaned_data.get('experiment') | |
23 | if experiment == None: |
|
23 | if experiment == None: | |
24 | msg = "Error: Jars Configuration needs an Experiment" |
|
24 | msg = "Error: Jars Configuration needs an Experiment" | |
25 | self.add_error('experiment', msg) |
|
25 | self.add_error('experiment', msg) | |
26 |
|
26 | |||
27 | class Meta: |
|
27 | class Meta: | |
28 | model = JARSConfiguration |
|
28 | model = JARSConfiguration | |
29 |
exclude = ('type', 'parameters', 'status' |
|
29 | exclude = ('type', 'parameters', 'status') No newline at end of file | |
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 | exclude = ('type', 'parameters', 'status') |
|
General Comments 0
You need to be logged in to leave comments.
Login now