X-Git-Url: http://mmka.chem.univ.gda.pl/gitweb/?a=blobdiff_plain;ds=sidebyside;f=qcg%2Fforms.py;h=d10456295c9ed79216c77b3a71c3bc981704a507;hb=3e29cd65efbb6b29b3db8c84e625f75829e550e7;hp=93f9c290a6f94dfd9094716f580278ef7b039f90;hpb=a48622a1086a47a1abc26dcd3d1d05a384eb1e8f;p=qcg-portal.git diff --git a/qcg/forms.py b/qcg/forms.py index 93f9c29..d104562 100644 --- a/qcg/forms.py +++ b/qcg/forms.py @@ -160,15 +160,14 @@ class JobDescriptionForm(forms.Form): native = forms.MultipleChoiceField(label=u"Opcje systemu kolejkowego", required=False) persistent = forms.BooleanField(label=u"Trwałe", required=False) - def __init__(self, data=None, *args, **kwargs): - super(JobDescriptionForm, self).__init__(data, *args, **kwargs) + def __init__(self, data=None, initial=None, *args, **kwargs): + super(JobDescriptionForm, self).__init__(data, initial=initial, *args, **kwargs) - if data is not None: - # accept user defined choices - self.fields['queue'].choices += ((data.get('queue'), data.get('queue')), ) - self.fields['arguments'].choices += ((v, v) for v in data.getlist('arguments')) - self.fields['native'].choices += ((v, v) for v in data.getlist('native')) - self.fields['stage_in'].choices += ((v, v) for v in data.getlist('stage_in')) + 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() @@ -176,6 +175,13 @@ class JobDescriptionForm(forms.Form): 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 not data['application'] and not data['executable'] and not data['script']: + self.add_error(None, u"Jedno z następujących pól jest niezbędne do uruchomienia zadania: " + u"Aplikacja, Plik wykonywalny lub Skrypt") + + 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 '' @@ -203,20 +209,20 @@ class JobDescriptionForm(forms.Form): 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_nodes(self): - return map(int, self.cleaned_data['nodes'].split(':', 2)) if self.cleaned_data['nodes'] else '' - def clean_input(self): return self._gsiftp_suffix(self.cleaned_data['input']) def clean_stage_in(self): - return ['gsiftp://' + item for item in self.cleaned_data['stage_in']] + 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']) @@ -226,7 +232,19 @@ class JobDescriptionForm(forms.Form): @staticmethod def _gsiftp_suffix(url): - return 'gsiftp://' + url if url else '' + 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) class EnvForm(forms.Form):