##// END OF EJS Templates
Experiment detail view update
Experiment detail view update

File last commit:

r360:46316742ce9f
r365:24b24259841b
Show More
forms.py
110 lines | 4.0 KiB | text/x-python | PythonLexer
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 import os
Juan C. Espinoza
Add rc config mods...
r23 import json
Miguel Urco
Campaign has been added to RadarSys Model...
r13 from django import forms
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 from django.utils.safestring import mark_safe
from apps.main.models import Device
from apps.main.forms import add_empty_choice
Limpieza de código y funcionalidades usrp
r346 from .models import PedestalConfiguration
Juan C. Espinoza
Updates to models, views & forms for CR...
r25
Juan C. Espinoza
Fix TX_ref for codes & windows lines...
r149 def create_choices_from_model(model, conf_id, all_choice=False):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Limpieza de código y funcionalidades usrp
r346 instance = globals()[model]
choices = instance.objects.all().values_list('pk', 'name')
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Juan C. Espinoza
- Update rc app...
r79 return choices
Juan C. Espinoza
Update RC models, views, templates & statics...
r45
Limpieza de código y funcionalidades usrp
r346 class PedestalConfigurationForm(forms.ModelForm):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 def __init__(self, *args, **kwargs):
Limpieza de código y funcionalidades usrp
r346 super(PedestalConfigurationForm, self).__init__(*args, **kwargs)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 instance = getattr(self, 'instance', None)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 if instance and instance.pk:
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Primer commit radarsys_met
r345 devices = Device.objects.filter(device_type__name='pedestal')
New experiment views
r360 #if instance.experiment:
#self.fields['experiment'].widget.attrs['read_only'] = True
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #self.fields['experiment'].widget.choices = [(instance.experiment.id, instance.experiment)]
New experiment views
r360 #self.fields['device'].widget.choices = [(device.id, device) for device in devices]
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Juan C. Espinoza
Update several views and models in main app...
r85 if 'initial' in kwargs and 'experiment' in kwargs['initial'] and kwargs['initial']['experiment'] not in (0, '0'):
Juan C. Espinoza
- Add sequence mode in mix configurations....
r116 self.fields['experiment'].widget.attrs['readonly'] = True
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
Campaign has been added to RadarSys Model...
r13 class Meta:
Limpieza de código y funcionalidades usrp
r346 model = PedestalConfiguration
New experiment views
r360 exclude = ('template', 'type', 'parameters', 'status', 'total_units', 'author', 'hash')
Juan C. Espinoza
Add rc config mods...
r23
Juan C. Espinoza
- Update rc app...
r79 def clean(self):
Limpieza de código y funcionalidades usrp
r346 form_data = super(PedestalConfigurationForm, self).clean()
Juan C. Espinoza
- Update rc app...
r79 return form_data
Juan C. Espinoza
Update RC app (add support for mix configurations, bug plotting window line, )...
r107
Juan C. Espinoza
Update Views y several improvements
r316 def save(self, *args, **kwargs):
Limpieza de código y funcionalidades usrp
r346 conf = super(PedestalConfigurationForm, self).save(*args, **kwargs)
Juan C. Espinoza
- Add sequence mode in mix configurations....
r116 conf.save()
return conf
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
New experiment views
r360 class PedestalEditionForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(PedestalEditionForm, self).__init__(*args, **kwargs)
instance = getattr(self, 'instance', None)
if instance and instance.pk:
devices = Device.objects.filter(device_type__name='pedestal')
#if instance.experiment:
#self.fields['experiment'].widget.attrs['read_only'] = True
#self.fields['experiment'].widget.choices = [(instance.experiment.id, instance.experiment)]
#self.fields['device'].widget.choices = [(device.id, device) for device in devices]
if 'initial' in kwargs and 'experiment' in kwargs['initial'] and kwargs['initial']['experiment'] not in (0, '0'):
self.fields['experiment'].widget.attrs['readonly'] = True
class Meta:
model = PedestalConfiguration
exclude = ('device', 'label', 'template', 'type', 'parameters', 'status', 'total_units', 'author', 'hash')
def clean(self):
form_data = super(PedestalEditionForm, self).clean()
return form_data
def save(self, *args, **kwargs):
conf = super(PedestalEditionForm, self).save(*args, **kwargs)
conf.save()
return conf
Limpieza de código y funcionalidades usrp
r346 class ExtFileField(forms.FileField):
"""
Same as forms.FileField, but you can specify a file extension whitelist.
Juan C. Espinoza
Update RC app (add support for mix configurations, bug plotting window line, )...
r107
Limpieza de código y funcionalidades usrp
r346 >>> from django.core.files.uploadedfile import SimpleUploadedFile
>>>
>>> t = ExtFileField(ext_whitelist=(".pdf", ".txt"))
>>>
>>> t.clean(SimpleUploadedFile('filename.pdf', 'Some File Content'))
>>> t.clean(SimpleUploadedFile('filename.txt', 'Some File Content'))
>>>
>>> t.clean(SimpleUploadedFile('filename.exe', 'Some File Content'))
Traceback (most recent call last):
...
ValidationError: [u'Not allowed filetype!']
"""
Juan C. Espinoza
Add compatibility with embed CGS in RC
r328 def __init__(self, *args, **kwargs):
Limpieza de código y funcionalidades usrp
r346 extensions = kwargs.pop("extensions")
self.extensions = [i.lower() for i in extensions]
Juan C. Espinoza
Add compatibility with embed CGS in RC
r328
Limpieza de código y funcionalidades usrp
r346 super(ExtFileField, self).__init__(*args, **kwargs)
Juan C. Espinoza
Add compatibility with embed CGS in RC
r328
Limpieza de código y funcionalidades usrp
r346 def clean(self, *args, **kwargs):
data = super(ExtFileField, self).clean(*args, **kwargs)
filename = data.name
ext = os.path.splitext(filename)[1]
ext = ext.lower()
if ext not in self.extensions:
raise forms.ValidationError('Not allowed file type: %s' % ext)
Juan C. Espinoza
Add compatibility with embed CGS in RC
r328
Limpieza de código y funcionalidades usrp
r346 class PedestalImportForm(forms.Form):
Juan C. Espinoza
Add compatibility with embed CGS in RC
r328
Limpieza de código y funcionalidades usrp
r346 file_name = ExtFileField(extensions=['.racp', '.json', '.dat'])