@@ -0,0 +1,13 | |||
|
1 | {% extends "dev_conf_edit.html" %} | |
|
2 | ||
|
3 | {% block extra-js%} | |
|
4 | ||
|
5 | <script type="text/javascript"> | |
|
6 | ||
|
7 | $("#id_name").change(function() { | |
|
8 | var url = "{% url 'url_change_jars_filter' conf_id %}"; | |
|
9 | document.location = url + $(this).val()+"/"; | |
|
10 | }); | |
|
11 | ||
|
12 | </script> | |
|
13 | {% endblock %} |
@@ -1,2 +1,3 | |||
|
1 |
[{"fields": {"name": "49_92 |
|
|
2 | ] | |
|
1 | [{"fields": {"name": "49_92MHz_clock60MHz_F1KHz_12_25_2", "clock": 60, "mult": 5, "fch": 49.92, "fch_decimal": 721554506, "filter_fir": 2, "filter_2": 12, "filter_5": 25}, "model": "jars.jarsfilter", "pk": 1} | |
|
2 | {"fields": {"name": "49_920MHz_clock60MHz_F1MHz_10_1_6", "clock": 60, "mult": 5, "fch": 49.92, "fch_decimal": 721554506, "filter_fir": 6, "filter_2": 10, "filter_5": 1}, "model": "jars.jarsfilter", "pk": 2} | |
|
3 | ] |
@@ -1,88 +1,116 | |||
|
1 | 1 | import os |
|
2 | 2 | |
|
3 | 3 | from django import forms |
|
4 | 4 | from apps.main.models import Device, Experiment |
|
5 | 5 | from .models import JARSConfiguration, JARSfilter |
|
6 | 6 | from .widgets import SpectralWidget |
|
7 | from apps.main.forms import add_empty_choice | |
|
8 | ||
|
9 | def create_choices_from_model(model, filter_id=None): | |
|
10 | ||
|
11 | #instance = globals()[model] | |
|
12 | choices = model.objects.all().values_list('pk', 'name') | |
|
13 | choices = add_empty_choice(choices) | |
|
14 | return choices | |
|
7 | 15 | |
|
8 | 16 | class JARSConfigurationForm(forms.ModelForm): |
|
9 | 17 | def __init__(self, *args, **kwargs): |
|
10 | 18 | super(JARSConfigurationForm, self).__init__(*args, **kwargs) |
|
11 | 19 | instance = getattr(self, 'instance', None) |
|
12 | 20 | |
|
13 | 21 | if instance and instance.pk: |
|
14 | 22 | devices = Device.objects.filter(device_type__name='jars') |
|
15 | 23 | |
|
16 | 24 | if instance.experiment: |
|
17 | 25 | experiments = Experiment.objects.filter(pk=instance.experiment.id) |
|
18 | 26 | self.fields['experiment'].widget.choices = [(experiment.id, experiment) for experiment in experiments] |
|
19 | 27 | |
|
20 | 28 | self.fields['device'].widget.choices = [(device.id, device) for device in devices] |
|
21 | 29 | #self.fields['spectral'].widget = SpectralWidget() |
|
22 | 30 | self.fields['spectral_number'].widget.attrs['readonly'] = True |
|
23 | 31 | self.fields['spectral'].widget = SpectralWidget() |
|
24 | 32 | |
|
25 | 33 | #-------------JARS Configuration needs an Experiment----------------- |
|
26 | 34 | def clean(self): |
|
27 | 35 | cleaned_data = super(JARSConfigurationForm, self).clean() |
|
28 | 36 | experiment = cleaned_data.get('experiment') |
|
29 | 37 | if experiment == None: |
|
30 | 38 | msg = "Error: Jars Configuration needs an Experiment" |
|
31 | 39 | self.add_error('experiment', msg) |
|
32 | 40 | |
|
33 | 41 | class Meta: |
|
34 | 42 | model = JARSConfiguration |
|
35 | 43 | exclude = ('type', 'parameters', 'status', 'filter_parms') |
|
36 | 44 | |
|
37 | 45 | |
|
38 | 46 | class JARSfilterForm(forms.ModelForm): |
|
39 | 47 | def __init__(self, *args, **kwargs): |
|
40 | 48 | super(JARSfilterForm, self).__init__(*args, **kwargs) |
|
41 | 49 | instance = getattr(self, 'instance', None) |
|
42 | 50 | |
|
43 | 51 | self.fields['fch_decimal'].widget.attrs['readonly'] = True |
|
44 | ||
|
52 | ||
|
45 | 53 | if 'initial' in kwargs: |
|
46 | self.fields.pop('name') | |
|
47 | #self.fields['name'].widget.attrs['disabled'] = 'disabled' | |
|
48 | ||
|
54 | if 'filter_id' not in kwargs['initial']: | |
|
55 | self.fields.pop('name') | |
|
56 | else: | |
|
57 | self.fields['name'] = forms.ChoiceField(choices=create_choices_from_model(JARSfilter)) | |
|
58 | filter_id = kwargs['initial']['filter_id'] | |
|
59 | ||
|
60 | if filter_id == 0: | |
|
61 | for value in self.fields: | |
|
62 | if value != 'name': | |
|
63 | self.fields.pop(value) | |
|
64 | self.fields['name'].label = "Filter Template Name" | |
|
65 | else: | |
|
66 | self.fields['name'] = forms.ChoiceField(choices=create_choices_from_model(JARSfilter, kwargs['initial']['filter_id'])) | |
|
67 | jars_filter = JARSfilter.objects.get(pk=kwargs['initial']['filter_id']) | |
|
68 | labels = [f.name for f in jars_filter._meta.get_fields()] | |
|
69 | ||
|
70 | for label in ['id', 'jarsconfiguration']: | |
|
71 | labels.remove(label) | |
|
72 | for label in labels: | |
|
73 | self.fields['name'].initial = kwargs['initial']['filter_id'] | |
|
74 | self.fields[label].initial = getattr(jars_filter,label) | |
|
75 | self.fields['name'].label = "Filter Template Name" | |
|
49 | 76 | |
|
50 | 77 | class Meta: |
|
51 | 78 | model = JARSfilter |
|
52 | 79 | exclude = ('type', 'parameters', 'status') |
|
53 | 80 | |
|
81 | ||
|
54 | 82 | class ExtFileField(forms.FileField): |
|
55 | 83 | """ |
|
56 | 84 | Same as forms.FileField, but you can specify a file extension whitelist. |
|
57 | 85 | |
|
58 | 86 | >>> from django.core.files.uploadedfile import SimpleUploadedFile |
|
59 | 87 | >>> |
|
60 | 88 | >>> t = ExtFileField(ext_whitelist=(".pdf", ".txt")) |
|
61 | 89 | >>> |
|
62 | 90 | >>> t.clean(SimpleUploadedFile('filename.pdf', 'Some File Content')) |
|
63 | 91 | >>> t.clean(SimpleUploadedFile('filename.txt', 'Some File Content')) |
|
64 | 92 | >>> |
|
65 | 93 | >>> t.clean(SimpleUploadedFile('filename.exe', 'Some File Content')) |
|
66 | 94 | Traceback (most recent call last): |
|
67 | 95 | ... |
|
68 | 96 | ValidationError: [u'Not allowed filetype!'] |
|
69 | 97 | """ |
|
70 | 98 | def __init__(self, *args, **kwargs): |
|
71 | 99 | extensions = kwargs.pop("extensions") |
|
72 | 100 | self.extensions = [i.lower() for i in extensions] |
|
73 | 101 | |
|
74 | 102 | super(ExtFileField, self).__init__(*args, **kwargs) |
|
75 | 103 | |
|
76 | 104 | def clean(self, *args, **kwargs): |
|
77 | 105 | data = super(ExtFileField, self).clean(*args, **kwargs) |
|
78 | 106 | filename = data.name |
|
79 | 107 | ext = os.path.splitext(filename)[1] |
|
80 | 108 | ext = ext.lower() |
|
81 | 109 | if ext not in self.extensions: |
|
82 | 110 | raise forms.ValidationError('Not allowed file type: %s' % ext) |
|
83 | 111 | |
|
84 | 112 | |
|
85 | 113 | class JARSImportForm(forms.Form): |
|
86 | 114 | |
|
87 | 115 | #file_name = ExtFileField(extensions=['.racp', '.json', '.dat']) |
|
88 | 116 | file_name = ExtFileField(extensions=['.json']) |
@@ -1,282 +1,288 | |||
|
1 | 1 | import json |
|
2 | 2 | import requests |
|
3 | 3 | |
|
4 | 4 | from django.db import models |
|
5 | 5 | from django.core.validators import MinValueValidator, MaxValueValidator |
|
6 | 6 | from django.core.urlresolvers import reverse |
|
7 | 7 | |
|
8 | 8 | from apps.main.models import Configuration |
|
9 | 9 | from apps.main.utils import Params |
|
10 | 10 | # Create your models here. |
|
11 | 11 | |
|
12 | 12 | EXPERIMENT_TYPE = ( |
|
13 | 13 | (0, 'RAW_DATA'), |
|
14 | 14 | (1, 'PDATA'), |
|
15 | 15 | ) |
|
16 | 16 | |
|
17 | 17 | DATA_TYPE = ( |
|
18 | 18 | (0, 'SHORT'), |
|
19 | 19 | (1, 'FLOAT'), |
|
20 | 20 | ) |
|
21 | 21 | |
|
22 | 22 | DECODE_TYPE = ( |
|
23 | 23 | (0, 'None'), |
|
24 | 24 | (1, 'TimeDomain'), |
|
25 | 25 | (2, 'FreqDomain'), |
|
26 | 26 | (3, 'InvFreqDomain'), |
|
27 | 27 | ) |
|
28 | 28 | |
|
29 | 29 | class JARSfilter(models.Model): |
|
30 | 30 | |
|
31 | 31 | JARS_NBITS = 32 |
|
32 | 32 | |
|
33 | 33 | name = models.CharField(max_length=60, unique=True, default='') |
|
34 | 34 | clock = models.FloatField(verbose_name='Clock In (MHz)',validators=[MinValueValidator(5), MaxValueValidator(75)], null=True, default=60) |
|
35 | 35 | mult = models.PositiveIntegerField(verbose_name='Multiplier',validators=[MinValueValidator(1), MaxValueValidator(20)], default=5) |
|
36 |
fch = models. |
|
|
36 | fch = models.FloatField(verbose_name='Frequency (MHz)', validators=[MaxValueValidator(150)], null=True, default=49.9200) | |
|
37 | 37 | fch_decimal = models.BigIntegerField(verbose_name='Frequency (Decimal)',validators=[MinValueValidator(-9223372036854775808), MaxValueValidator(2**JARS_NBITS-1)], null=True, default=721554505) |
|
38 | 38 | filter_2 = models.PositiveIntegerField(verbose_name='Filter 2',validators=[MinValueValidator(2), MaxValueValidator(100)], default = 10) |
|
39 | 39 | filter_5 = models.PositiveIntegerField(verbose_name='Filter 5',validators=[MinValueValidator(1), MaxValueValidator(100)], default = 1) |
|
40 | 40 | filter_fir = models.PositiveIntegerField(verbose_name='FIR Filter',validators=[MinValueValidator(1), MaxValueValidator(100)], default = 6) |
|
41 | #speed = models.PositiveIntegerField(verbose_name='Speed',validators=[MinValueValidator(0), MaxValueValidator(100000)], default = 0) | |
|
42 | 41 | |
|
43 | 42 | class Meta: |
|
44 | 43 | db_table = 'jars_filters' |
|
45 | 44 | |
|
46 | 45 | def __unicode__(self): |
|
47 | 46 | return u'%s' % (self.name) |
|
48 | 47 | |
|
49 | 48 | def parms_to_dict(self): |
|
50 | 49 | |
|
51 | 50 | parameters = {} |
|
52 | 51 | |
|
53 | 52 | #parameters['name'] = self.name |
|
54 | 53 | parameters['clock'] = float(self.clock) |
|
55 | 54 | parameters['mult'] = int(self.mult) |
|
56 | 55 | parameters['fch'] = float(self.fch) |
|
57 | 56 | parameters['fch_decimal'] = int(self.fch) |
|
58 | 57 | parameters['filter_fir'] = int(self.filter_fir) |
|
59 | 58 | parameters['filter_2'] = int(self.filter_2) |
|
60 | 59 | parameters['filter_5'] = int(self.filter_5) |
|
61 | #parameters['speed'] = int(self.speed) | |
|
62 | 60 | |
|
63 | 61 | return parameters |
|
64 | 62 | |
|
65 | 63 | def dict_to_parms(self, parameters): |
|
66 | 64 | |
|
67 | 65 | #self.name = parameters['name'] |
|
68 | 66 | self.clock = parameters['clock'] |
|
69 | 67 | self.mult = parameters['mult'] |
|
70 | 68 | self.fch = parameters['fch'] |
|
71 | 69 | self.fch_decimal = parameters['fch_decimal'] |
|
72 | 70 | self.filter_fir = parameters['filter_fir'] |
|
73 | 71 | self.filter_2 = parameters['filter_2'] |
|
74 | 72 | self.filter_5 = parameters['filter_5'] |
|
75 | #self.speed = parameters['speed'] | |
|
76 | 73 | |
|
77 | 74 | |
|
78 | 75 | class JARSConfiguration(Configuration): |
|
79 | 76 | |
|
80 | 77 | ADC_RESOLUTION = 8 |
|
81 | 78 | PCI_DIO_BUSWIDTH = 32 |
|
82 | 79 | HEADER_VERSION = 1103 |
|
83 | 80 | BEGIN_ON_START = True |
|
84 | 81 | REFRESH_RATE = 1 |
|
85 | 82 | |
|
86 | #rc = models.ForeignKey(RCConfiguration, on_delete=models.CASCADE, null=True) | |
|
87 | 83 | exp_type = models.PositiveIntegerField(verbose_name='Experiment Type', choices=EXPERIMENT_TYPE, default=0) |
|
88 | 84 | cards_number = models.PositiveIntegerField(verbose_name='Number of Cards', validators=[MinValueValidator(1), MaxValueValidator(4)], default = 1) |
|
89 | 85 | channels_number = models.PositiveIntegerField(verbose_name='Number of Channels', validators=[MinValueValidator(1), MaxValueValidator(8)], default = 5) |
|
90 | 86 | channels = models.CharField(verbose_name='Channels', max_length=15, default = '1,2,3,4,5') |
|
91 | #rd_directory = models.CharField(verbose_name='Raw Data Directory', max_length=200, default='', blank=True, null=True) | |
|
92 | #pd_directory = models.CharField(verbose_name='Process Data Directory', max_length=200, default='', blank=True, null=True) | |
|
93 | 87 | data_type = models.PositiveIntegerField(verbose_name='Data Type', choices=DATA_TYPE, default=0) |
|
94 | 88 | raw_data_blocks = models.PositiveIntegerField(verbose_name='Raw Data Blocks', validators=[MaxValueValidator(5000)], default=60) |
|
95 | 89 | profiles_block = models.PositiveIntegerField(verbose_name='Profiles Per Block', default=400) |
|
96 | 90 | acq_profiles = models.PositiveIntegerField(verbose_name='Acquired Profiles', default=400) |
|
97 | 91 | ftp_interval = models.PositiveIntegerField(verbose_name='FTP Interval', default=60) |
|
98 | 92 | fftpoints = models.PositiveIntegerField(verbose_name='FFT Points',default=16) |
|
99 | 93 | cohe_integr_str = models.PositiveIntegerField(verbose_name='Coh. Int. Stride',validators=[MinValueValidator(1)], default=30) |
|
100 | 94 | cohe_integr = models.PositiveIntegerField(verbose_name='Coherent Integrations',validators=[MinValueValidator(1)], default=30) |
|
101 | 95 | incohe_integr = models.PositiveIntegerField(verbose_name='Incoherent Integrations',validators=[MinValueValidator(1)], default=30) |
|
102 | 96 | decode_data = models.PositiveIntegerField(verbose_name='Decode Data', choices=DECODE_TYPE, default=0) |
|
103 | 97 | post_coh_int = models.BooleanField(verbose_name='Post Coherent Integration', default=False) |
|
104 | 98 | filter = models.ForeignKey(JARSfilter, on_delete=models.CASCADE, null=True) |
|
105 | 99 | spectral_number = models.PositiveIntegerField(verbose_name='# Spectral Combinations',validators=[MinValueValidator(1)], default=1) |
|
106 | 100 | spectral = models.CharField(verbose_name='Combinations', max_length=5000, default = '[0, 0],') |
|
107 | 101 | create_directory = models.BooleanField(verbose_name='Create Directory Per Day', default=True) |
|
108 | 102 | include_expname = models.BooleanField(verbose_name='Experiment Name in Directory', default=False) |
|
109 | #acq_link = models.BooleanField(verbose_name='Acquisition Link', default=True) | |
|
110 | 103 | #view_raw_data = models.BooleanField(verbose_name='View Raw Data', default=True) |
|
111 | 104 | save_ch_dc = models.BooleanField(verbose_name='Save Channels DC', default=True) |
|
112 | 105 | save_data = models.BooleanField(verbose_name='Save Data', default=True) |
|
113 | filter_parms = models.CharField(max_length=10000, default='{}') | |
|
106 | filter_parms = models.CharField(max_length=10000, default='{"name": "49_92MHz_clock60MHz_F1KHz_12_25_2", "clock": 60, "mult": 5, "fch": 49.92, "fch_decimal": 721554506, "filter_fir": 2, "filter_2": 12, "filter_5": 25}, "model": "jars.jarsfilter", "pk": 1}') | |
|
114 | 107 | |
|
115 | 108 | class Meta: |
|
116 | 109 | db_table = 'jars_configurations' |
|
117 | 110 | |
|
118 | 111 | def add_parms_to_filter(self): |
|
119 | 112 | self.filter_parms = self.filter.parms_to_dict() |
|
120 | 113 | self.save() |
|
121 | 114 | |
|
115 | def filter_resolution(self): | |
|
116 | filter_parms = eval(self.filter_parms) | |
|
117 | if filter_parms.__class__.__name__=='str': | |
|
118 | filter_parms = eval(filter_parms) | |
|
119 | ||
|
120 | filter_clock = filter_parms['clock'] | |
|
121 | filter_2 = filter_parms['filter_2'] | |
|
122 | filter_5 = filter_parms['filter_5'] | |
|
123 | filter_fir = filter_parms['filter_fir'] | |
|
124 | ||
|
125 | resolution = round((filter_clock/(filter_2*filter_5*filter_fir)),2) | |
|
126 | return resolution | |
|
127 | ||
|
122 | 128 | def dict_to_parms(self, params, id=None): |
|
123 | 129 | |
|
124 | 130 | if id is not None: |
|
125 | 131 | data = Params(params).get_conf(id_conf=id) |
|
126 | 132 | else: |
|
127 | 133 | data = Params(params).get_conf(dtype='jars') |
|
128 | 134 | |
|
129 | 135 | self.name = data['name'] |
|
130 | 136 | self.exp_type = data['exp_type'] |
|
131 | 137 | #if data['exp_type'] in (1, '1') : |
|
132 | 138 | self.incohe_integr = data['incohe_integr'] |
|
133 | 139 | self.spectral_number = data['spectral_number'] |
|
134 | 140 | self.spectral = data['spectral'] |
|
135 | 141 | #self.pd_directory = data['pd_directory'] |
|
136 | 142 | self.cards_number = data['cards_number'] |
|
137 | 143 | self.channels_number = data['channels_number'] |
|
138 | 144 | self.channels = data['channels'] |
|
139 | 145 | #self.rd_directory = data['rd_directory'] |
|
140 | 146 | #self.raw_data_blocks = data['raw_data_blocks'] |
|
141 | 147 | self.data_type = data['data_type'] |
|
142 | 148 | self.cohe_integr_str = data['cohe_integr_str'] |
|
143 | 149 | self.acq_profiles = data['acq_profiles'] |
|
144 | 150 | self.profiles_block = data['profiles_block'] |
|
145 | 151 | self.ftp_interval = data['ftp_interval'] |
|
146 | 152 | self.fftpoints = data['fftpoints'] |
|
147 | 153 | self.cohe_integr = data['cohe_integr'] |
|
148 | 154 | self.filter_parms = json.dumps(data['filter_parms']) |
|
149 | 155 | self.create_directory = data['create_directory'] |
|
150 | 156 | self.include_expname = data['include_expname'] |
|
151 | 157 | #self.acq_link = data['acq_link'] |
|
152 | 158 | #self.view_raw_data = data['view_raw_data'] |
|
153 | 159 | self.save_ch_dc = data['save_ch_dc'] |
|
154 | 160 | self.save_data = data['save_data'] |
|
155 | 161 | self.save() |
|
156 | 162 | |
|
157 | 163 | def request(self, cmd, method='get', **kwargs): |
|
158 | 164 | |
|
159 | 165 | req = getattr(requests, method)(self.device.url(cmd), **kwargs) |
|
160 | 166 | payload = req.json() |
|
161 | 167 | return payload |
|
162 | 168 | |
|
163 | 169 | def status_device(self): |
|
164 | 170 | |
|
165 | 171 | try: |
|
166 | 172 | payload = self.request('status', |
|
167 | 173 | params={'name': self.experiment.name}) |
|
168 | 174 | self.device.status = payload['status'] |
|
169 | 175 | self.device.save() |
|
170 | 176 | self.message = payload['message'] |
|
171 | 177 | except Exception as e: |
|
172 | 178 | self.device.status = 0 |
|
173 | 179 | self.message = str(e) |
|
174 | 180 | self.device.save() |
|
175 | 181 | return False |
|
176 | 182 | |
|
177 | 183 | return True |
|
178 | 184 | |
|
179 | 185 | def stop_device(self): |
|
180 | 186 | |
|
181 | 187 | try: |
|
182 | 188 | payload = self.request('stop', 'post') |
|
183 | 189 | self.device.status = payload['status'] |
|
184 | 190 | self.device.save() |
|
185 | 191 | self.message = payload['message'] |
|
186 | 192 | except Exception as e: |
|
187 | 193 | self.device.status = 0 |
|
188 | 194 | self.message = str(e) |
|
189 | 195 | self.device.save() |
|
190 | 196 | return False |
|
191 | 197 | |
|
192 | 198 | return True |
|
193 | 199 | |
|
194 | 200 | def read_device(self): |
|
195 | 201 | |
|
196 | 202 | try: |
|
197 | 203 | payload = self.request('read', params={'name': self.experiment.name}) |
|
198 | 204 | self.message = 'Configuration loaded' |
|
199 | 205 | except: |
|
200 | 206 | self.device.status = 0 |
|
201 | 207 | self.device.save() |
|
202 | 208 | self.message = 'Could not read JARS configuration.' |
|
203 | 209 | return False |
|
204 | 210 | |
|
205 | 211 | return payload |
|
206 | 212 | |
|
207 | 213 | def write_device(self): |
|
208 | 214 | |
|
209 | 215 | if self.device.status == 3: |
|
210 | 216 | self.message = 'Could not configure device. Software Acquisition is running' |
|
211 | 217 | return False |
|
212 | 218 | |
|
213 | 219 | data = self.experiment.parms_to_dict() |
|
214 | 220 | |
|
215 | 221 | for key in data['configurations']['allIds']: |
|
216 | 222 | if data['configurations']['byId'][key]['device_type'] in ('dds', 'cgs'): |
|
217 | 223 | data['configurations']['allIds'].remove(key) |
|
218 | 224 | data['configurations']['byId'].pop(key) |
|
219 | 225 | elif data['configurations']['byId'][key]['device_type'] == 'jars': |
|
220 | 226 | data['configurations']['byId'][key] = self.parms_to_dict()['configurations']['byId'][str(self.pk)] |
|
221 | 227 | elif data['configurations']['byId'][key]['device_type'] == 'rc': |
|
222 | 228 | data['configurations']['byId'][key]['pulses'] = '' |
|
223 | 229 | data['configurations']['byId'][key]['delays'] = '' |
|
224 | 230 | rc_ids = [pk for pk in data['configurations']['allIds'] if data['configurations']['byId'][pk]['device_type']=='rc'] |
|
225 | 231 | mix_ids = [pk for pk in rc_ids if data['configurations']['byId'][pk]['mix']] |
|
226 | 232 | if mix_ids: |
|
227 | 233 | params = data['configurations']['byId'][mix_ids[0]]['parameters'] |
|
228 | 234 | rc = data['configurations']['byId'][params.split('-')[0].split('|')[0]] |
|
229 | 235 | rc['mix'] = True |
|
230 | 236 | data['configurations']['byId'][rc['id']] = rc |
|
231 | 237 | elif len(rc_ids)==0: |
|
232 | 238 | self.message = 'Missing RC configuration' |
|
233 | 239 | return False |
|
234 | 240 | |
|
235 | 241 | json_data = json.dumps(data) |
|
236 | 242 | print json_data |
|
237 | 243 | try: |
|
238 | 244 | payload = self.request('write', 'post', json=json_data) |
|
239 | 245 | self.device.status = payload['status'] |
|
240 | 246 | self.message = payload['message'] |
|
241 | 247 | self.device.save() |
|
242 | 248 | if self.device.status == 1: |
|
243 | 249 | return False |
|
244 | 250 | |
|
245 | 251 | except Exception as e: |
|
246 | 252 | self.device.status = 0 |
|
247 | 253 | self.message = str(e) |
|
248 | 254 | self.device.save() |
|
249 | 255 | return False |
|
250 | 256 | |
|
251 | 257 | return True |
|
252 | 258 | |
|
253 | 259 | def start_device(self): |
|
254 | 260 | |
|
255 | 261 | try: |
|
256 | 262 | payload = self.request('start', 'post', |
|
257 | 263 | json={'name': self.experiment.name}) |
|
258 | 264 | self.device.status = payload['status'] |
|
259 | 265 | self.message = payload['message'] |
|
260 | 266 | self.device.save() |
|
261 | 267 | if self.device.status == 1: |
|
262 | 268 | return False |
|
263 | 269 | |
|
264 | 270 | except Exception as e: |
|
265 | 271 | self.device.status = 0 |
|
266 | 272 | self.message = str(e) |
|
267 | 273 | self.device.save() |
|
268 | 274 | return False |
|
269 | 275 | |
|
270 | 276 | return True |
|
271 | 277 | |
|
272 | 278 | def update_from_file(self, filename): |
|
273 | 279 | |
|
274 | 280 | f = JARSFile(filename) |
|
275 | 281 | self.dict_to_parms(f.data) |
|
276 | 282 | self.save() |
|
277 | 283 | |
|
278 | 284 | def get_absolute_url_import(self): |
|
279 | 285 | return reverse('url_import_jars_conf', args=[str(self.id)]) |
|
280 | 286 | |
|
281 | 287 | def get_absolute_url_read(self): |
|
282 | 288 | return reverse('url_read_jars_conf', args=[str(self.id)]) |
@@ -1,1 +1,16 | |||
|
1 | {% extends "dev_conf.html" %} No newline at end of file | |
|
1 | {% extends "dev_conf.html" %} | |
|
2 | {% load static %} | |
|
3 | {% load bootstrap3 %} | |
|
4 | {% load main_tags %} | |
|
5 | ||
|
6 | ||
|
7 | {% block extra-content %} | |
|
8 | ||
|
9 | <div class="clearfix"></div> | |
|
10 | <h2>JARS filter: {{resolution}} (MHz)</h2> | |
|
11 | <hr> | |
|
12 | <div class="panel-group" id="div_lines" role="tablist" aria-multiselectable="true"> | |
|
13 | {% include "jars_filter.html" %} | |
|
14 | </div> | |
|
15 | ||
|
16 | {% endblock extra-content%} |
@@ -1,33 +1,32 | |||
|
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 content %} |
|
7 | 7 | <form class="form" method="post"> |
|
8 | 8 | {% csrf_token %} |
|
9 | 9 | {% bootstrap_form form layout='horizontal' size='medium' %} |
|
10 | 10 | <div style="clear: both;"></div> |
|
11 | <br> | |
|
12 | <div class="pull-right"> | |
|
13 | <button type="button" class="btn btn-primary" id="bt_view_filter">View Filter</button> | |
|
14 | <!-- <button type="button" class="btn btn-primary" onclick="{% if previous %}window.location.replace('{{ previous }}');{% else %}history.go(-1);{% endif %}">Cancel</button> --> | |
|
15 | <button type="button" class="btn btn-primary" id="bt_cancel">Cancel</button> | |
|
16 | <button type="submit" class="btn btn-primary">{{button}}</button> | |
|
11 | <h2>JARS filter</h2> | |
|
12 | <hr> | |
|
13 | <div class="panel-group" id="div_lines" role="tablist" aria-multiselectable="true"> | |
|
14 | {% include "jars_filter_edit.html" %} | |
|
17 | 15 | </div> |
|
16 | <div style="clear: both;"></div> | |
|
17 | <br> | |
|
18 | 18 | </form> |
|
19 | 19 | {% endblock %} |
|
20 | 20 | |
|
21 | ||
|
21 | 22 | {% block extra-js%} |
|
22 | 23 | <script src="{% static 'js/jars.js' %}"></script> |
|
23 | 24 | |
|
24 | 25 | <script type="text/javascript"> |
|
25 | $("#bt_view_filter").click(function() { | |
|
26 | document.location = "{% url 'url_jars_filter' id_dev filter_id%}"; | |
|
27 | }); | |
|
28 | ||
|
26 | ||
|
29 | 27 | $("#bt_cancel").click(function() { |
|
30 | 28 | document.location = "{% url 'url_jars_conf' id_dev %}"; |
|
31 |
|
|
|
29 | }); | |
|
30 | ||
|
32 | 31 | </script> |
|
33 | {% endblock %} No newline at end of file | |
|
32 | {% endblock %} |
@@ -1,59 +1,27 | |||
|
1 | {% extends "base.html" %} | |
|
2 | 1 | {% load bootstrap3 %} |
|
3 | 2 | {% load static %} |
|
4 | 3 | {% load main_tags %} |
|
5 | 4 | |
|
6 | {% block search-active %}active{% endblock %} | |
|
7 | ||
|
8 | {% block content-title %}{{title}}{% endblock %} | |
|
9 | {% block content-suptitle %}{{suptitle}}{% endblock %} | |
|
10 | ||
|
11 | 5 | {% block content %} |
|
12 | 6 | |
|
13 | 7 | {% block menu-actions %} |
|
14 | 8 | |
|
15 | 9 | {% endblock %} |
|
16 | 10 | |
|
17 | 11 | <table class="table table-bordered"> |
|
18 | ||
|
19 | {% for key in dev_conf_keys %} | |
|
20 | <tr> | |
|
21 | <th>{% get_verbose_field_name dev_conf key %}</th> | |
|
22 | <td>{{dev_conf|attr:key}}</td> | |
|
23 | </tr> | |
|
24 | {% endfor %} | |
|
12 | ||
|
13 | <tr> <th>Clock in (MHz)</th><td>{{filter.clock}}</td> </tr> | |
|
14 | <tr> <th>Multiplier</th><td>{{filter.mult}}</td> </tr> | |
|
15 | <tr> <th>Frequency (MHz)</th><td>{{filter.fch}}</td> </tr> | |
|
16 | <tr> <th>Frequency (Decimal)</th><td>{{filter.fch_decimal}}</td> </tr> | |
|
17 | <tr> <th>Filter 2</th><td>{{filter.filter_2}}</td> </tr> | |
|
18 | <tr> <th>Filter 5</th><td>{{filter.filter_5}}</td> </tr> | |
|
19 | <tr> <th>FIR Filter</th><td>{{filter.filter_fir}}</td> </tr> | |
|
20 | ||
|
25 | 21 | </table> |
|
26 | {% if button %} | |
|
27 | <div class="pull-right"> | |
|
28 | <button type="button" class="btn btn-primary" id="back_button">{% if cancel %}{{cancel}}{% else %}Back{% endif %}</button> | |
|
29 | <button type="button" id="edit_button" class="btn btn-primary">{{edit_button}}</button> | |
|
30 | <button type="button" id="new_button" class="btn btn-primary">{{add_button}}</button> | |
|
31 | </div> | |
|
32 | {% endif %} | |
|
33 | 22 | |
|
34 | {% block extra-content %} | |
|
35 | {% endblock %} | |
|
36 | 23 | |
|
24 | {% block extra-content %} | |
|
37 | 25 | {% endblock %} |
|
38 | 26 | |
|
39 | {% block sidebar%} | |
|
40 | {% include "sidebar_devices.html" %} | |
|
41 | 27 | {% endblock %} |
|
42 | ||
|
43 | {% block extra-js%} | |
|
44 | <script type="text/javascript"> | |
|
45 | ||
|
46 | $("#edit_button").click(function() { | |
|
47 | document.location = "{% url 'url_edit_jars_filter' conf.id filter.id%}"; | |
|
48 | }); | |
|
49 | ||
|
50 | $("#back_button").click(function() { | |
|
51 | document.location = "{% url 'url_edit_jars_conf' conf.id%}"; | |
|
52 | }); | |
|
53 | ||
|
54 | $("#new_button").click(function() { | |
|
55 | document.location = "{% url 'url_new_jars_filter' conf.id%}"; | |
|
56 | }); | |
|
57 | ||
|
58 | </script> | |
|
59 | {% endblock %} No newline at end of file |
@@ -1,21 +1,29 | |||
|
1 | {% extends "dev_conf_edit.html" %} | |
|
2 | 1 | {% load bootstrap3 %} |
|
3 | 2 | {% load static %} |
|
4 | 3 | {% load main_tags %} |
|
5 | 4 | |
|
6 | 5 | {% block content %} |
|
7 | 6 | <form class="form" method="post"> |
|
8 | 7 | {% csrf_token %} |
|
9 | {% bootstrap_form form layout='horizontal' size='medium' %} | |
|
8 | {% bootstrap_form filter_form layout='horizontal' size='medium' %} | |
|
10 | 9 | <div style="clear: both;"></div> |
|
11 | 10 | <br> |
|
12 | 11 | <div class="pull-right"> |
|
13 | <button type="button" class="btn btn-primary" onclick="{% if previous %}window.location.replace('{{ previous }}');{% else %}history.go(-1);{% endif %}">Cancel</button> | |
|
14 |
<button type=" |
|
|
12 | <button type="button" class="btn btn-primary" onclick="{% if previous %}window.location.replace('{{ previous }}');{% else %}history.go(-1);{% endif %}">Cancel</button> | |
|
13 | <button type="button" class="btn btn-primary" id="bt_change_filter">Change Filter</button> | |
|
14 | <button type="submit" class="btn btn-primary">{{button}}</button> | |
|
15 | 15 | </div> |
|
16 | 16 | </form> |
|
17 | 17 | {% endblock %} |
|
18 | 18 | |
|
19 | 19 | {% block extra-js%} |
|
20 | 20 | <script src="{% static 'js/filters.js' %}"></script> |
|
21 | {% endblock %} No newline at end of file | |
|
21 | ||
|
22 | <script type="text/javascript"> | |
|
23 | ||
|
24 | $("#bt_change_filter").click(function() { | |
|
25 | document.location = "{% url 'url_change_jars_filter' id_dev %}"; | |
|
26 | }); | |
|
27 | ||
|
28 | </script> | |
|
29 | {% endblock %} |
@@ -1,13 +1,15 | |||
|
1 | 1 | from django.conf.urls import url |
|
2 | 2 | |
|
3 | 3 | from apps.jars import views |
|
4 | 4 | |
|
5 | 5 | urlpatterns = ( |
|
6 | 6 | url(r'^(?P<id_conf>-?\d+)/$', views.jars_conf, name='url_jars_conf'), |
|
7 | 7 | url(r'^(?P<id_conf>-?\d+)/edit/$', views.jars_conf_edit, name='url_edit_jars_conf'), |
|
8 | 8 | url(r'^(?P<conf_id>-?\d+)/new_filter/$', views.new_filter, name='url_new_jars_filter'), |
|
9 | url(r'^(?P<conf_id>-?\d+)/change_filter/$', views.change_filter, name='url_change_jars_filter'), | |
|
10 | url(r'^(?P<conf_id>-?\d+)/change_filter/(?P<filter_id>-?\d+)/$', views.change_filter, name='url_change_jars_filter'), | |
|
9 | 11 | url(r'^(?P<conf_id>-?\d+)/view_filter/(?P<filter_id>-?\d+)/$', views.view_filter, name='url_jars_filter'), |
|
10 | 12 | url(r'^(?P<conf_id>-?\d+)/view_filter/(?P<filter_id>-?\d+)/edit$', views.edit_filter, name='url_edit_jars_filter'), |
|
11 | 13 | url(r'^(?P<conf_id>-?\d+)/import/$', views.import_file, name='url_import_jars_conf'), |
|
12 | 14 | url(r'^(?P<conf_id>-?\d+)/read/$', views.read_conf, name='url_read_jars_conf'), |
|
13 | 15 | ) |
@@ -1,246 +1,293 | |||
|
1 | 1 | from django.shortcuts import render_to_response |
|
2 | 2 | from django.template import RequestContext |
|
3 | 3 | from django.shortcuts import redirect, render, get_object_or_404 |
|
4 | 4 | from django.contrib import messages |
|
5 | 5 | |
|
6 | 6 | from apps.main.models import Device |
|
7 | 7 | from apps.main.views import sidebar |
|
8 | 8 | |
|
9 | 9 | from .models import JARSConfiguration, JARSfilter |
|
10 | 10 | from .forms import JARSConfigurationForm, JARSfilterForm, JARSImportForm |
|
11 | ||
|
12 | import json | |
|
11 | 13 | # Create your views here. |
|
12 | 14 | |
|
13 | 15 | def jars_conf(request, id_conf): |
|
14 | 16 | |
|
15 | 17 | conf = get_object_or_404(JARSConfiguration, pk=id_conf) |
|
16 | 18 | |
|
17 | ip=conf.device.ip_address | |
|
18 | port=conf.device.port_address | |
|
19 | filter_parms = eval(conf.filter_parms) | |
|
20 | if filter_parms.__class__.__name__=='str': | |
|
21 | filter_parms = eval(filter_parms) | |
|
19 | 22 | |
|
20 | 23 | kwargs = {} |
|
24 | kwargs['filter'] = filter_parms | |
|
25 | kwargs['filter_keys'] = ['clock', 'mult', 'fch', 'fch_decimal', | |
|
26 | 'filter_fir', 'filter_2', 'filter_5'] | |
|
27 | filter_resolution=conf.filter_resolution() | |
|
28 | kwargs['resolution'] = filter_resolution | |
|
29 | ||
|
21 | 30 | kwargs['status'] = conf.device.get_status_display() |
|
22 | 31 | |
|
23 | 32 | |
|
24 | 33 | kwargs['dev_conf'] = conf |
|
25 | 34 | kwargs['dev_conf_keys'] = ['name', |
|
26 | 35 | 'cards_number', 'channels_number', 'channels', |
|
27 | 36 | #'rd_directory', 'pd_directory', |
|
28 | 37 | 'data_type', |
|
29 | 38 | 'acq_profiles', 'profiles_block', 'raw_data_blocks', 'ftp_interval', 'fftpoints', |
|
30 | 39 | 'cohe_integr_str', 'decode_data', |
|
31 | 40 | 'incohe_integr', 'cohe_integr', 'spectral_number', |
|
32 | 41 | 'spectral', 'create_directory', 'include_expname', |
|
33 | 42 | 'save_ch_dc', 'save_data'] |
|
34 | 43 | |
|
35 | 44 | kwargs['title'] = 'JARS Configuration' |
|
36 | 45 | kwargs['suptitle'] = 'Details' |
|
37 | 46 | |
|
38 | 47 | kwargs['button'] = 'Edit Configuration' |
|
39 | 48 | |
|
40 | 49 | #kwargs['no_play'] = True |
|
41 | 50 | |
|
42 | 51 | #kwargs['only_stop'] = True |
|
43 | 52 | |
|
44 | 53 | ###### SIDEBAR ###### |
|
45 | 54 | kwargs.update(sidebar(conf=conf)) |
|
46 | 55 | |
|
47 | 56 | return render(request, 'jars_conf.html', kwargs) |
|
48 | 57 | |
|
49 | 58 | def jars_conf_edit(request, id_conf): |
|
50 | 59 | |
|
51 | 60 | conf = get_object_or_404(JARSConfiguration, pk=id_conf) |
|
52 | 61 | |
|
62 | filter_parms = eval(conf.filter_parms) | |
|
63 | if filter_parms.__class__.__name__=='str': | |
|
64 | filter_parms = eval(filter_parms) | |
|
65 | ||
|
53 | 66 | if request.method=='GET': |
|
54 | 67 | form = JARSConfigurationForm(instance=conf) |
|
68 | filter_form = JARSfilterForm(initial=filter_parms) | |
|
55 | 69 | |
|
56 | 70 | if request.method=='POST': |
|
57 | 71 | form = JARSConfigurationForm(request.POST, instance=conf) |
|
72 | filter_form = JARSfilterForm(request.POST) | |
|
73 | ||
|
74 | if filter_form.is_valid(): | |
|
75 | jars_filter = filter_form.cleaned_data | |
|
76 | try: | |
|
77 | jars_filter.pop('name') | |
|
78 | except: | |
|
79 | pass | |
|
58 | 80 | |
|
59 | 81 | if form.is_valid(): |
|
60 | 82 | conf = form.save(commit=False) |
|
83 | conf.filter_parms = json.dumps(jars_filter) | |
|
61 | 84 | conf.save() |
|
62 | 85 | return redirect('url_jars_conf', id_conf=conf.id) |
|
63 | 86 | |
|
64 | ##ERRORS | |
|
65 | ||
|
66 | 87 | kwargs = {} |
|
67 | 88 | |
|
68 | kwargs['filter_id'] = 1 | |
|
69 | 89 | kwargs['id_dev'] = conf.id |
|
70 | 90 | kwargs['form'] = form |
|
91 | kwargs['filter_form'] = filter_form | |
|
71 | 92 | kwargs['title'] = 'Device Configuration' |
|
72 | 93 | kwargs['suptitle'] = 'Edit' |
|
73 | 94 | kwargs['button'] = 'Save' |
|
74 | 95 | |
|
75 | 96 | return render(request, 'jars_conf_edit.html', kwargs) |
|
76 | 97 | |
|
77 | 98 | def import_file(request, conf_id): |
|
78 | 99 | |
|
79 | 100 | conf = get_object_or_404(JARSConfiguration, pk=conf_id) |
|
80 | 101 | if request.method=='POST': |
|
81 | 102 | form = JARSImportForm(request.POST, request.FILES) |
|
82 | 103 | if form.is_valid(): |
|
83 | 104 | #try: |
|
84 | 105 | if True: |
|
85 | 106 | data = conf.import_from_file(request.FILES['file_name']) |
|
86 | 107 | conf.dict_to_parms(data) |
|
87 | 108 | messages.success(request, 'Configuration "%s" loaded succesfully' % request.FILES['file_name']) |
|
88 | 109 | return redirect(conf.get_absolute_url_edit()) |
|
89 | 110 | |
|
90 | 111 | #except Exception as e: |
|
91 | 112 | # messages.error(request, 'Error parsing file: "%s" - %s' % (request.FILES['file_name'], e)) |
|
92 | 113 | |
|
93 | 114 | else: |
|
94 | 115 | messages.warning(request, 'Your current configuration will be replaced') |
|
95 | 116 | form = JARSImportForm() |
|
96 | 117 | |
|
97 | 118 | kwargs = {} |
|
98 | 119 | kwargs['form'] = form |
|
99 | 120 | kwargs['title'] = 'JARS Configuration' |
|
100 | 121 | kwargs['suptitle'] = 'Import file' |
|
101 | 122 | kwargs['button'] = 'Upload' |
|
102 | 123 | kwargs['previous'] = conf.get_absolute_url() |
|
103 | 124 | |
|
104 | 125 | return render(request, 'jars_import.html', kwargs) |
|
105 | 126 | |
|
106 | 127 | def read_conf(request, conf_id): |
|
107 | 128 | |
|
108 | 129 | conf = get_object_or_404(JARSConfiguration, pk=conf_id) |
|
109 | 130 | #filter = get_object_or_404(JARSfilter, pk=filter_id) |
|
110 | 131 | |
|
111 | 132 | if request.method=='GET': |
|
112 | 133 | |
|
113 | 134 | parms = conf.read_device() |
|
114 | 135 | conf.status_device() |
|
115 | 136 | |
|
116 | 137 | if not parms: |
|
117 | 138 | messages.error(request, conf.message) |
|
118 | 139 | return redirect(conf.get_absolute_url()) |
|
119 | 140 | |
|
120 | 141 | form = JARSConfigurationForm(initial=parms, instance=conf) |
|
121 | 142 | |
|
122 | 143 | if request.method=='POST': |
|
123 | 144 | form = JARSConfigurationForm(request.POST, instance=conf) |
|
124 | 145 | |
|
125 | 146 | if form.is_valid(): |
|
126 | 147 | form.save() |
|
127 | 148 | return redirect(conf.get_absolute_url()) |
|
128 | 149 | |
|
129 | 150 | messages.error(request, "Parameters could not be saved") |
|
130 | 151 | |
|
131 | 152 | kwargs = {} |
|
132 | 153 | kwargs['id_dev'] = conf.id |
|
133 | 154 | kwargs['filter_id'] = conf.filter.id |
|
134 | 155 | kwargs['form'] = form |
|
135 | 156 | kwargs['title'] = 'Device Configuration' |
|
136 | 157 | kwargs['suptitle'] = 'Parameters read from device' |
|
137 | 158 | kwargs['button'] = 'Save' |
|
138 | 159 | |
|
139 | 160 | ###### SIDEBAR ###### |
|
140 | 161 | kwargs.update(sidebar(conf=conf)) |
|
141 | 162 | |
|
142 | 163 | return render(request, 'jars_conf_edit.html', kwargs) |
|
143 | 164 | |
|
144 | 165 | def view_filter(request, conf_id, filter_id): |
|
145 | 166 | |
|
146 | 167 | conf = get_object_or_404(JARSConfiguration, pk=conf_id) |
|
147 | 168 | filter = get_object_or_404(JARSfilter, pk=filter_id) |
|
148 | 169 | |
|
149 | 170 | filter_parms = eval(conf.filter_parms) |
|
150 | 171 | if filter_parms.__class__.__name__=='str': |
|
151 | 172 | filter_parms = eval(filter_parms) |
|
152 | 173 | #filter.name = filter_parms['name'] |
|
153 | 174 | filter.clock = filter_parms['clock'] |
|
154 | 175 | filter.mult = filter_parms['mult'] |
|
155 | 176 | filter.fch = filter_parms['fch'] |
|
156 | 177 | filter.fch_decimal = filter_parms['fch_decimal'] |
|
157 | 178 | filter.filter_fir = filter_parms['filter_fir'] |
|
158 | 179 | filter.filter_2 = filter_parms['filter_2'] |
|
159 | 180 | filter.filter_5 = filter_parms['filter_5'] |
|
160 | 181 | |
|
161 | 182 | kwargs = {} |
|
162 | 183 | kwargs['conf'] = conf |
|
163 | 184 | kwargs['filter'] = filter |
|
164 | 185 | kwargs['dev_conf'] = filter |
|
165 | 186 | kwargs['dev_conf_keys'] = ['clock', 'mult', #'name', |
|
166 | 187 | 'fch', 'fch_decimal', |
|
167 | 188 | 'filter_2', 'filter_5', |
|
168 | 189 | 'filter_fir'] |
|
169 | 190 | |
|
170 | 191 | kwargs['title'] = 'Filter View' |
|
171 | 192 | kwargs['suptitle'] = 'Details' |
|
172 | 193 | kwargs['button'] = 'SI' |
|
173 | 194 | kwargs['edit_button'] = 'Edit Filter' |
|
174 | 195 | kwargs['add_button'] = 'New Filter' |
|
175 | 196 | |
|
176 | 197 | return render(request, 'jars_filter.html', kwargs) |
|
177 | 198 | |
|
178 | 199 | def edit_filter(request, conf_id, filter_id): |
|
179 | 200 | |
|
180 | 201 | conf = get_object_or_404(JARSConfiguration, pk=conf_id) |
|
181 | 202 | filter_parms = eval(conf.filter_parms) |
|
182 | 203 | |
|
183 | 204 | if filter_id: |
|
184 | 205 | filter = get_object_or_404(JARSfilter, pk=filter_id) |
|
185 | 206 | |
|
186 | 207 | if request.method=='GET': |
|
187 | 208 | form = JARSfilterForm(initial=filter_parms) |
|
188 | 209 | |
|
189 | 210 | if request.method=='POST': |
|
190 | 211 | parms = {} |
|
191 | 212 | #parms['name'] = request.POST['name'] |
|
192 | 213 | parms['clock'] = request.POST['clock'] |
|
193 | 214 | parms['mult'] = request.POST['mult'] |
|
194 | 215 | parms['fch'] = request.POST['fch'] |
|
195 | 216 | parms['fch_decimal'] = request.POST['fch_decimal'] |
|
196 | 217 | parms['filter_fir'] = request.POST['filter_fir'] |
|
197 | 218 | parms['filter_2'] = request.POST['filter_2'] |
|
198 | 219 | parms['filter_5'] = request.POST['filter_5'] |
|
199 | 220 | |
|
200 | 221 | conf.filter_parms = parms |
|
201 | 222 | conf.save() |
|
202 | 223 | |
|
203 | 224 | #form = JARSfilterForm(request.POST) |
|
204 | 225 | #form = JARSfilterForm(request.POST, instance=filter) |
|
205 | 226 | #if form.is_valid(): |
|
206 | 227 | #form.save() |
|
207 | 228 | # messages.success(request, 'JARS Filter successfully updated') |
|
208 | 229 | # return redirect('url_jars_filter', conf.id, filter.id) |
|
209 | 230 | return redirect('url_jars_filter', conf.id, filter.id) |
|
210 | 231 | |
|
211 | 232 | kwargs = {} |
|
212 | 233 | kwargs['form'] = form |
|
213 | 234 | kwargs['title'] = conf.name |
|
214 | 235 | kwargs['suptitle'] = 'Edit Filter' |
|
215 | 236 | kwargs['button'] = 'Save' |
|
216 | 237 | # kwargs['previous'] = conf.get_absolute_url_edit() |
|
217 | 238 | kwargs['dev_conf'] = conf |
|
218 | 239 | |
|
219 | 240 | return render(request, 'jars_filter_edit.html', kwargs) |
|
220 | 241 | |
|
221 | 242 | def new_filter(request, conf_id): |
|
222 | 243 | |
|
223 | 244 | conf = get_object_or_404(JARSConfiguration, pk=conf_id) |
|
224 | 245 | |
|
225 | 246 | if request.method=='GET': |
|
226 | 247 | form = JARSfilterForm() |
|
227 | 248 | |
|
228 | 249 | if request.method=='POST': |
|
229 | 250 | form = JARSfilterForm(request.POST) |
|
230 | 251 | if form.is_valid(): |
|
231 | 252 | form.save() |
|
232 | 253 | new_filter = get_object_or_404(JARSfilter, name=request.POST['name']) |
|
233 | 254 | conf.filter = new_filter |
|
234 | 255 | conf.add_parms_to_filter() |
|
235 | 256 | messages.success(request, 'New JARS Filter successfully created') |
|
236 | 257 | return redirect('url_edit_jars_conf', id_conf=conf.id) |
|
237 | 258 | |
|
238 | 259 | kwargs = {} |
|
239 | 260 | kwargs['form'] = form |
|
240 | 261 | kwargs['title'] = 'New Filter' |
|
241 | 262 | kwargs['suptitle'] = '' |
|
242 | 263 | kwargs['button'] = 'Create' |
|
243 | 264 | # kwargs['previous'] = conf.get_absolute_url_edit() |
|
244 | 265 | kwargs['dev_conf'] = conf |
|
245 | 266 | |
|
246 | 267 | return render(request, 'jars_new_filter.html', kwargs) |
|
268 | ||
|
269 | ||
|
270 | def change_filter(request, conf_id, filter_id=None): | |
|
271 | ||
|
272 | conf = get_object_or_404(JARSConfiguration, pk=conf_id) | |
|
273 | ||
|
274 | if filter_id: | |
|
275 | if filter_id.__class__.__name__ not in ['int', 'float']: | |
|
276 | filter_id = eval(filter_id) | |
|
277 | ||
|
278 | if filter_id == 0: | |
|
279 | return redirect('url_change_jars_filter', conf_id=conf.id) | |
|
280 | ||
|
281 | if request.method=='GET': | |
|
282 | if not filter_id: | |
|
283 | form = JARSfilterForm(initial={'jars_configuration':conf_id, 'filter_id': 0}) | |
|
284 | else: | |
|
285 | form = JARSfilterForm(initial={'jars_configuration':conf_id, 'filter_id': filter_id}) | |
|
286 | ||
|
287 | kwargs = {} | |
|
288 | kwargs['title'] = 'JARS Configuration' | |
|
289 | kwargs['suptitle'] = 'Change Filter' | |
|
290 | kwargs['form'] = form | |
|
291 | kwargs['conf_id'] = conf.id | |
|
292 | kwargs['filter_id'] = filter_id | |
|
293 | return render(request, 'change_jars_filter.html', kwargs) |
General Comments 0
You need to be logged in to leave comments.
Login now