+
+ def __init__(self, data=None, initial=None, *args, **kwargs):
+ super(JobDescriptionForm, self).__init__(data, initial=initial, *args, **kwargs)
+
+ if data or initial:
+ self._init_user_choices('queue', data, initial)
+ self._init_user_choices('arguments', data, initial)
+ self._init_user_choices('native', data, initial)
+ self._init_user_choices('stage_in', data, initial)
+
+ def clean(self):
+ data = super(JobDescriptionForm, self).clean()
+
+ if bool(data['application']) + bool(data['executable']) + bool(data['script']) != 1:
+ self.add_error(None, u"Dokładnie jedno z następujących pól jest wymagane do uruchomienia zadania: "
+ u"Aplikacja, Plik wykonywalny lub Skrypt.")
+
+ if data['application'] and not data['master_file']:
+ self.add_error('master_file', u"W trybie uruchamiania aplikacji należy podać plik główny")
+
+ if data['procs'] and data['nodes']:
+ self.add_error(None, u"Zdefiniuj tylko jedno z pól: liczbę procesów lub topologię węzłów")
+
+ notify_type = data.get('notify_type')
+ data['notify'] = u'{}:{}'.format(notify_type, data['notify_address']) if notify_type else ''
+
+ wo_type = data.get('watch_output_type')
+ data['watch_output'] = u'{}:{}'.format(wo_type, data['watch_output_address']) if wo_type else ''
+
+ preprocess_type = data.get('preprocess_type')
+ if preprocess_type == self.Process.CMD:
+ data['preprocess'] = data['preprocess_cmd']
+ elif preprocess_type == self.Process.SCRIPT:
+ data['preprocess'] = data['preprocess_script']
+ else:
+ data['preprocess'] = ''
+
+ postprocess_type = data.get('postprocess_type')
+ if postprocess_type == self.Process.CMD:
+ data['postprocess'] = data['postprocess_cmd']
+ elif postprocess_type == self.Process.SCRIPT:
+ data['postprocess'] = data['postprocess_script']
+ else:
+ data['postprocess'] = ''
+
+ return data
+
+ def clean_application(self):
+ return self.cleaned_data['application'].split('/', 1) if self.cleaned_data['application'] else ''
+
+ def clean_nodes(self):
+ return map(int, self.cleaned_data['nodes'].split(':', 2)) if self.cleaned_data['nodes'] else ''
+
+ def clean_executable(self):
+ return self._gsiftp_suffix(self.cleaned_data['executable'])
+
+ def clean_master_file(self):
+ return self._gsiftp_suffix(self.cleaned_data['master_file'])
+
+ def clean_input(self):
+ return self._gsiftp_suffix(self.cleaned_data['input'])
+
+ def clean_stage_in(self):
+ return [self._gsiftp_suffix(item) for item in self.cleaned_data['stage_in']]
+
+ def clean_preprocess_script(self):
+ return self._gsiftp_suffix(self.cleaned_data['preprocess_script'])
+
+ def clean_postprocess_script(self):
+ return self._gsiftp_suffix(self.cleaned_data['postprocess_script'])
+
+ def clean_pdb_file(self):
+ return self._gsiftp_suffix(self.cleaned_data['pdb_file'])
+
+ @staticmethod
+ def _gsiftp_suffix(url):
+ if url:
+ return url if url.startswith('gsiftp://') else 'gsiftp://' + url
+
+ def _init_user_choices(self, name, data, initial):
+ initial = initial.get(name) if initial is not None else None
+ choices = data.getlist(name)[:] if data is not None else []
+
+ if initial:
+ choices += initial if isinstance(initial, list) else [initial]
+ self.fields[name].initial = initial
+
+ if choices:
+ self.fields[name].choices += ((v, v) for v in choices)