X-Git-Url: http://mmka.chem.univ.gda.pl/gitweb/?a=blobdiff_plain;f=qcg%2Fforms.py;h=d10456295c9ed79216c77b3a71c3bc981704a507;hb=074716e0052d3c928ce5b34f5ae8cfc9d05ec806;hp=ef571a60570ad8dc34f0fbf57275ebd2fd99d669;hpb=eb0c9af5b8eb444d8db3e8759d3a83e8c6d41ee1;p=qcg-portal.git diff --git a/qcg/forms.py b/qcg/forms.py index ef571a6..d104562 100644 --- a/qcg/forms.py +++ b/qcg/forms.py @@ -5,7 +5,7 @@ from django.template.defaultfilters import capfirst from pyqcg.utils import TaskStatus from qcg.fields import TimeRangeField -from qcg.models import Task, Allocation +from qcg.models import Task, Allocation, JobTemplate date_range_validator = RegexValidator(r'[0-9]{2}\.[0-9]{2}\.[0-9]{4} - [0-9]{2}\.[0-9]{2}\.[0-9]{4}') @@ -44,12 +44,14 @@ class FiltersForm(forms.Form): } STATUS_CHOICES_DICT = dict(STATUS_CHOICES) + keywords = forms.CharField(max_length=100, label=u"Wyszukaj frazę", required=False) status = forms.MultipleChoiceField(choices=STATUS_CHOICES, label=u"Status", required=False, widget=forms.CheckboxSelectMultiple) - host = forms.MultipleChoiceField(label=u"Host", required=False, widget=forms.CheckboxSelectMultiple) # advanced - keywords = forms.CharField(max_length=100, label=u"Wyszukaj frazę", required=False) + host = forms.MultipleChoiceField(label=u"Host", required=False, widget=forms.CheckboxSelectMultiple) + purged = forms.TypedChoiceField(label=u"Istniejący katalog roboczy?", required=False, coerce=lambda x: bool(int(x)), + choices=((0, 'Tak'), (1, 'Nie')), widget=forms.RadioSelect) submission = forms.CharField(label=u"Data zlecenia", validators=[date_range_validator], required=False) finish = forms.CharField(label=u"Data zakończenia", validators=[date_range_validator], required=False) @@ -117,15 +119,15 @@ class JobDescriptionForm(forms.Form): ) application = forms.ChoiceField(choices=APPLICATION_CHOICES, label=u"Aplikacja", required=False) # TODO choices - master_file = forms.CharField(label=u"Plik główny", max_length=500, required=False) # TODO grid ftp - executable = forms.CharField(label=u"Plik wykonywalny", max_length=500, required=False) # TODO grid ftp - script = forms.CharField(label=u"Skrypt", widget=forms.Textarea(attrs={'rows': 2, 'cols': 40}), required=False) # TODO saving to grid ftp + master_file = forms.CharField(label=u"Plik główny", max_length=500, required=False) + executable = forms.CharField(label=u"Plik wykonywalny", max_length=500, required=False) + script = forms.CharField(label=u"Skrypt", widget=forms.Textarea(attrs={'rows': 2, 'cols': 40}), required=False) arguments = forms.MultipleChoiceField(label=u"Argumenty", required=False) note = forms.CharField(label=u"Opis", widget=forms.Textarea(attrs={'rows': 2, 'cols': 40}), required=False) grant = forms.CharField(label=u"Grant", max_length=100, required=False) hosts = forms.MultipleChoiceField(label=u"Host", choices=Host.CHOICES, required=False) - properties = forms.MultipleChoiceField(label=u"Właściwości węzłów", required=False) + properties = forms.CharField(label=u"Właściwości węzłów", required=False) queue = forms.ChoiceField(choices=QUEUE_CHOICES, label=u"Kolejka", required=False) procs = forms.IntegerField(label=u"Liczba procesów", min_value=0, required=False) nodes = forms.CharField(label=u"Topologia węzłów", max_length=10, validators=[nodes_validator], required=False) @@ -135,10 +137,8 @@ class JobDescriptionForm(forms.Form): modules = forms.MultipleChoiceField(label=u"Moduły", choices=MODULES_CHOICES, required=False) # TODO choices reservation = forms.CharField(label=u"Rezerwacja", max_length=100, required=False) - # TODO grid ftp input = forms.CharField(label=u"Standardowe wejście", max_length=500, required=False) stage_in = forms.MultipleChoiceField(label=u"Stage in", required=False) - # stage_out = forms.MultipleChoiceField(label=u"Stage out", required=False) monitoring = forms.BooleanField(label=u"Portal QCG-Monitoring", required=False) notify_type = forms.ChoiceField(label=u"Monitorowanie stanu", choices=PROTOCOL_CHOICES, required=False, initial='', @@ -152,29 +152,36 @@ class JobDescriptionForm(forms.Form): preprocess_type = forms.ChoiceField(label=u"Preprocessing", choices=Process.CHOICES, required=False, initial=Process.NONE, widget=forms.RadioSelect) preprocess_cmd = forms.CharField(label=u"Polecenie", max_length=1000, required=False) - preprocess_script = forms.CharField(label=u"Skrypt", max_length=500, required=False) # TODO grid ftp + preprocess_script = forms.CharField(label=u"Skrypt", max_length=500, required=False) postprocess_type = forms.ChoiceField(label=u"Postprocessing", choices=Process.CHOICES, required=False, initial=Process.NONE, widget=forms.RadioSelect) postprocess_cmd = forms.CharField(label=u"Polecenie", max_length=1000, required=False) - postprocess_script = forms.CharField(label=u"Skrypt", max_length=500, required=False) # TODO grid ftp + postprocess_script = forms.CharField(label=u"Skrypt", max_length=500, required=False) 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['properties'].choices += ((v, v) for v in data.getlist('properties')) - 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')) - # self.fields['stage_out'].choices += ((v, v) for v in data.getlist('stage_out')) + 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 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 '' @@ -197,20 +204,48 @@ class JobDescriptionForm(forms.Form): else: data['postprocess'] = '' + return data + def clean_application(self): return self.cleaned_data['application'].split('/', 1) if self.cleaned_data['application'] else '' - def clean_executable(self): - return 'gsiftp://' + self.cleaned_data['executable'] if self.cleaned_data['executable'] 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 'gsiftp://' + self.cleaned_data['input'] if self.cleaned_data['input'] else '' + 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']) + + def clean_postprocess_script(self): + return self._gsiftp_suffix(self.cleaned_data['postprocess_script']) + + @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) + class EnvForm(forms.Form): name = forms.CharField(label=u"Nazwa", max_length=100, validators=[env_name_validator], @@ -236,3 +271,9 @@ class ColumnsForm(forms.Form): columns = forms.MultipleChoiceField(choices=COLUMNS_CHOICES, initial=[k for k, v in COLUMNS_CHOICES[1:]], label=u"Kolumny", required=False, widget=forms.CheckboxSelectMultiple) + + +class JobTemplateForm(forms.ModelForm): + class Meta: + model = JobTemplate + fields = ('name',)