2 from django import forms
3 from django.core.validators import RegexValidator
4 from django.template.defaultfilters import capfirst
5 from pyqcg.utils import TaskStatus
7 from qcg.fields import TimeRangeField
8 from qcg.models import Task, Allocation, JobTemplate
11 date_range_validator = RegexValidator(r'[0-9]{2}\.[0-9]{2}\.[0-9]{4} - [0-9]{2}\.[0-9]{2}\.[0-9]{4}')
12 nodes_validator = RegexValidator(r'^[0-9]{1,3}:[0-9]{1,2}(:[0-9]{1,2})?$')
13 env_name_validator = RegexValidator(r'^[a-zA-Z_][a-zA-Z0-9_]*$')
15 CHOICES_PLACEHOLDER = (None, '')
18 class FiltersForm(forms.Form):
19 ACTIVE, FINISHED, FAILED = range(3)
22 (FINISHED, u"Zakończone"),
23 (FAILED, u"Niepowodzenia"),
28 Task.STATUS_CHOICES_REVERSED[TaskStatus.UNSUBMITTED],
29 Task.STATUS_CHOICES_REVERSED[TaskStatus.UNCOMMITTED],
30 Task.STATUS_CHOICES_REVERSED[TaskStatus.QUEUED],
31 Task.STATUS_CHOICES_REVERSED[TaskStatus.PREPROCESSING],
32 Task.STATUS_CHOICES_REVERSED[TaskStatus.PENDING],
33 Task.STATUS_CHOICES_REVERSED[TaskStatus.RUNNING],
34 Task.STATUS_CHOICES_REVERSED[TaskStatus.STOPPED],
35 Task.STATUS_CHOICES_REVERSED[TaskStatus.POSTPROCESSING],
38 Task.STATUS_CHOICES_REVERSED[TaskStatus.FINISHED],
41 Task.STATUS_CHOICES_REVERSED[TaskStatus.FAILED],
42 Task.STATUS_CHOICES_REVERSED[TaskStatus.CANCELED],
45 STATUS_CHOICES_DICT = dict(STATUS_CHOICES)
47 keywords = forms.CharField(max_length=100, label=u"Wyszukaj frazę", required=False)
48 status = forms.MultipleChoiceField(choices=STATUS_CHOICES, label=u"Status", required=False,
49 widget=forms.CheckboxSelectMultiple)
52 host = forms.MultipleChoiceField(label=u"Host", required=False, widget=forms.CheckboxSelectMultiple)
53 purged = forms.TypedChoiceField(label=u"Istniejący katalog roboczy?", required=False, coerce=lambda x: bool(int(x)),
54 choices=((0, 'Tak'), (1, 'Nie')), widget=forms.RadioSelect)
55 submission = forms.CharField(label=u"Data zlecenia", validators=[date_range_validator], required=False)
56 finish = forms.CharField(label=u"Data zakończenia", validators=[date_range_validator], required=False)
58 def __init__(self, *args, **kwargs):
59 super(FiltersForm, self).__init__(*args, **kwargs)
61 self.fields['host'].choices = tuple(
62 (host, capfirst(host.split('.', 1)[0]))
63 for host in Allocation.objects.values_list('host_name', flat=True).order_by('host_name').distinct())
66 class JobDescriptionForm(forms.Form):
68 GALERA = 'galera.task.gda.pl'
69 HYDRA = 'hydra.icm.edu.pl'
70 INULA = 'inula.man.poznan.pl'
71 MOSS = 'moss.man.poznan.pl'
72 NOVA = 'nova.wcss.wroc.pl'
73 REEF = 'reef.man.poznan.pl'
74 ZEUS = 'zeus.cyfronet.pl'
81 class Process(object):
92 APPLICATION_CHOICES = (
94 ('unres-gab', 'UNRES GAB'),
95 ('unres-e0ll2y', 'UNRES E0LL2Y'),
100 ('plgrid', 'plgrid'),
101 ('plgrid-long', 'plgrid-long'),
102 ('plgrid-testing', 'plgrid-testing'),
109 ('mailto', u'E-mail'),
113 FORCE_FIELD_CHOICES = (
115 ('E0LL2Y', u'E0LL2Y'),
118 nstep = forms.IntegerField(label=u"NSTEP", help_text=u"Liczba kroków w trajektorii", min_value=1, initial=500000, required=False)
119 ntwe = forms.IntegerField(label=u"NTWE", help_text=u"Częstość zapisu energii w krokach", min_value=0, initial=100, required=False)
120 ntwx = forms.IntegerField(label=u"NTWX", help_text=u"Częstość zapisu współrzędnych w krokach", min_value=0, initial=1000, required=False)
121 dt = forms.DecimalField(label=u"DT", help_text=u"Krok czasowy. Wartość kroku równa jedności to 48.9 fs", max_digits=5, decimal_places=2, min_value=0.01, initial=0.1, required=False)
122 damax = forms.DecimalField(label=u"DAMAX", help_text=u"Maksymalna dopuszczalna zmiana przyspieszenia podczas jednego kroku czasowego", max_digits=5, decimal_places=2, min_value=0.01, initial=1.0, required=False)
123 force_field = forms.ChoiceField(choices=FORCE_FIELD_CHOICES, label=u"Pole siłowe", required=False, initial='GAB')
125 pdb_file = forms.CharField(label=u"Plik PDB", max_length=500, required=False)
126 #retmin = forms.IntegerField(label=u"RETMIN", help_text=u"Dolny zakres temparatur dla wymiany replik", min_value=2, initial=250, required=False)
127 #retmax = forms.IntegerField(label=u"RETMAX", help_text=u"Górny zakres temperatur dla wymiany replik", min_value=2, initial=450, required=False)
128 sequence = forms.CharField(label=u"Sekwencja", help_text=u"Sekwencja aminokwasów w zapisie jednoliterowym", widget=forms.Textarea(attrs={'rows': 2, 'cols': 40}), required=False)
131 application = forms.ChoiceField(choices=APPLICATION_CHOICES, label=u"Aplikacja", required=False, initial='unres-gab') # TODO choices
132 master_file = forms.CharField(label=u"Plik główny", max_length=500, required=False)
133 executable = forms.CharField(label=u"Plik wykonywalny", max_length=500, required=False)
134 script = forms.CharField(label=u"Skrypt", widget=forms.Textarea(attrs={'rows': 2, 'cols': 40}), required=False)
135 arguments = forms.MultipleChoiceField(label=u"Argumenty", required=False)
136 note = forms.CharField(label=u"Opis", widget=forms.Textarea(attrs={'rows': 2, 'cols': 40}), required=False)
137 grant = forms.CharField(label=u"Grant", max_length=100, required=False)
139 hosts = forms.MultipleChoiceField(label=u"Host", choices=Host.CHOICES, required=False)
140 properties = forms.CharField(label=u"Właściwości węzłów", required=False)
141 queue = forms.ChoiceField(choices=QUEUE_CHOICES, label=u"Kolejka", required=False)
142 procs = forms.IntegerField(label=u"Liczba procesów", min_value=0, required=False)
143 nodes = forms.CharField(label=u"Topologia węzłów", max_length=10, validators=[nodes_validator], required=False)
144 wall_time = TimeRangeField(label=u"Wall time", required=False)
145 memory = forms.IntegerField(label=u"Pamięć (MB)", min_value=0, required=False)
146 memory_per_slot = forms.IntegerField(label=u"Pamięci per proces (MB)", min_value=0, required=False)
147 modules = forms.MultipleChoiceField(label=u"Moduły", choices=MODULES_CHOICES, required=False) # TODO choices
148 reservation = forms.CharField(label=u"Rezerwacja", max_length=100, required=False)
150 input = forms.CharField(label=u"Standardowe wejście", max_length=500, required=False)
151 stage_in = forms.MultipleChoiceField(label=u"Stage in", required=False)
153 monitoring = forms.BooleanField(label=u"Portal QCG-Monitoring", required=False)
154 notify_type = forms.ChoiceField(label=u"Monitorowanie stanu", choices=PROTOCOL_CHOICES, required=False, initial='',
155 widget=forms.RadioSelect)
156 notify_address = forms.EmailField(label=u"Adres", required=False)
157 watch_output_type = forms.ChoiceField(label=u"Monitorowanie wyjścia", choices=PROTOCOL_CHOICES, required=False,
158 initial='', widget=forms.RadioSelect)
159 watch_output_address = forms.EmailField(label=u"Adres", required=False)
160 watch_output_pattern = forms.CharField(label=u"Wzorzec", max_length=500, required=False)
162 preprocess_type = forms.ChoiceField(label=u"Preprocessing", choices=Process.CHOICES, required=False,
163 initial=Process.NONE, widget=forms.RadioSelect)
164 preprocess_cmd = forms.CharField(label=u"Polecenie", max_length=1000, required=False)
165 preprocess_script = forms.CharField(label=u"Skrypt", max_length=500, required=False)
166 postprocess_type = forms.ChoiceField(label=u"Postprocessing", choices=Process.CHOICES, required=False,
167 initial=Process.NONE, widget=forms.RadioSelect)
168 postprocess_cmd = forms.CharField(label=u"Polecenie", max_length=1000, required=False)
169 postprocess_script = forms.CharField(label=u"Skrypt", max_length=500, required=False)
170 native = forms.MultipleChoiceField(label=u"Opcje systemu kolejkowego", required=False)
171 persistent = forms.BooleanField(label=u"Trwałe", required=False)
173 def __init__(self, data=None, initial=None, *args, **kwargs):
174 super(JobDescriptionForm, self).__init__(data, initial=initial, *args, **kwargs)
177 self._init_user_choices('queue', data, initial)
178 self._init_user_choices('arguments', data, initial)
179 self._init_user_choices('native', data, initial)
180 self._init_user_choices('stage_in', data, initial)
183 data = super(JobDescriptionForm, self).clean()
185 force_field = data.get('force_field')
187 if force_field == u'GAB':
188 data['application'] = [u'unres-gab']
190 data['application'] = [u'unres-e0ll2y']
192 '''if data['master_file']:
193 self.add_error('master_file', u"Należy podać plik główny. :"+data['master_file'])
195 if data['procs'] and data['nodes']:
196 self.add_error(None, u"Zdefiniuj tylko jedno z pól: liczbę procesów lub topologię węzłów")
198 notify_type = data.get('notify_type')
199 data['notify'] = u'{}:{}'.format(notify_type, data['notify_address']) if notify_type else ''
201 wo_type = data.get('watch_output_type')
202 data['watch_output'] = u'{}:{}'.format(wo_type, data['watch_output_address']) if wo_type else ''
204 preprocess_type = data.get('preprocess_type')
205 if preprocess_type == self.Process.CMD:
206 data['preprocess'] = data['preprocess_cmd']
207 elif preprocess_type == self.Process.SCRIPT:
208 data['preprocess'] = data['preprocess_script']
210 data['preprocess'] = ''
212 postprocess_type = data.get('postprocess_type')
213 if postprocess_type == self.Process.CMD:
214 data['postprocess'] = data['postprocess_cmd']
215 elif postprocess_type == self.Process.SCRIPT:
216 data['postprocess'] = data['postprocess_script']
218 data['postprocess'] = ''
222 def clean_application(self):
223 return self.cleaned_data['application'].split('/', 1) if self.cleaned_data['application'] else ''
225 def clean_nodes(self):
226 return map(int, self.cleaned_data['nodes'].split(':', 2)) if self.cleaned_data['nodes'] else ''
228 def clean_executable(self):
229 return self._gsiftp_suffix(self.cleaned_data['executable'])
231 def clean_master_file(self):
232 return self._gsiftp_suffix(self.cleaned_data['master_file'])
234 def clean_input(self):
235 return self._gsiftp_suffix(self.cleaned_data['input'])
237 def clean_stage_in(self):
238 return [self._gsiftp_suffix(item) for item in self.cleaned_data['stage_in']]
240 def clean_preprocess_script(self):
241 return self._gsiftp_suffix(self.cleaned_data['preprocess_script'])
243 def clean_postprocess_script(self):
244 return self._gsiftp_suffix(self.cleaned_data['postprocess_script'])
246 def clean_pdb_file(self):
247 return self._gsiftp_suffix(self.cleaned_data['pdb_file'])
250 def _gsiftp_suffix(url):
252 return url if url.startswith('gsiftp://') else 'gsiftp://' + url
254 def _init_user_choices(self, name, data, initial):
255 initial = initial.get(name) if initial is not None else None
256 choices = data.getlist(name)[:] if data is not None else []
259 choices += initial if isinstance(initial, list) else [initial]
260 self.fields[name].initial = initial
263 self.fields[name].choices += ((v, v) for v in choices)
266 class EnvForm(forms.Form):
267 name = forms.CharField(label=u"Nazwa", max_length=100, validators=[env_name_validator],
268 widget=forms.TextInput(attrs={'placeholder': u'Nazwa'}))
269 value = forms.CharField(label=u"Wartość", max_length=500,
270 widget=forms.TextInput(attrs={'placeholder': u'Wartość'}))
273 EnvFormSet = forms.formset_factory(EnvForm, can_delete=True, extra=0)
276 class ColumnsForm(forms.Form):
277 JOB_ID, DESCRIPTION, SUBMISSION, START, END, STATUS, HOST = range(7)
279 (JOB_ID, u"Identyfikator zadania"),
280 (DESCRIPTION, u"Opis"),
281 (SUBMISSION, u"Wysłane"),
288 columns = forms.MultipleChoiceField(choices=COLUMNS_CHOICES, initial=[k for k, v in COLUMNS_CHOICES[1:]],
289 label=u"Kolumny", required=False, widget=forms.CheckboxSelectMultiple)
292 class JobTemplateForm(forms.ModelForm):