X-Git-Url: http://mmka.chem.univ.gda.pl/gitweb/?a=blobdiff_plain;f=qcg%2Fforms.py;h=ea0804683037478d88816c882abb74f6f5e5436f;hb=1547dbc536b4848a93ce0a39493c0c69b853c576;hp=a3524d5e44eb86fe7ebe5648a95f6de21cb87ff3;hpb=d0c4e22c88d0509418e5dbb092d6cfda5bbb81ae;p=qcg-portal.git diff --git a/qcg/forms.py b/qcg/forms.py index a3524d5..ea08046 100644 --- a/qcg/forms.py +++ b/qcg/forms.py @@ -9,7 +9,7 @@ from qcg.models import Task, Allocation date_range_validator = RegexValidator(r'[0-9]{2}\.[0-9]{2}\.[0-9]{4} - [0-9]{2}\.[0-9]{2}\.[0-9]{4}') -nodes_validator = RegexValidator(r'^[0-9]{1,3}(:[0-9]{1,2}){0,2}$') +nodes_validator = RegexValidator(r'^[0-9]{1,3}:[0-9]{1,2}(:[0-9]{1,2})?$') env_name_validator = RegexValidator(r'^[a-zA-Z_][a-zA-Z0-9_]*$') CHOICES_PLACEHOLDER = (None, '') @@ -81,6 +81,18 @@ class JobDescriptionForm(forms.Form): (REEF, u'Reef'), (ZEUS, u'Zeus'), ) + + class Process(object): + NONE = '' + CMD = 'c' + SCRIPT = 's' + + CHOICES = ( + (NONE, u'Brak'), + (CMD, u'Polecenie'), + (SCRIPT, u'Skrypt'), + ) + APPLICATION_CHOICES = ( CHOICES_PLACEHOLDER, ('bash', 'BASH'), @@ -98,15 +110,10 @@ class JobDescriptionForm(forms.Form): ('plgrid/apps/python', 'plgrid/apps/python'), ('plgrid/apps/matlab', 'plgrid/apps/matlab'), ) - NOTIFY_CHOICES = ( - (0, u'Brak'), - (1, u'E-mail'), - (2, u'XMPP'), - ) - PROCESS_CHOICES = ( - (0, u'Brak'), - (1, u'Polecenie'), - (2, u'Skrypt'), + PROTOCOL_CHOICES = ( + ('', u'Brak'), + ('mailto', u'E-mail'), + ('xmpp', u'XMPP'), ) application = forms.ChoiceField(choices=APPLICATION_CHOICES, label=u"Aplikacja", required=False) # TODO choices @@ -116,7 +123,7 @@ class JobDescriptionForm(forms.Form): 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) - host = forms.MultipleChoiceField(label=u"Host", choices=Host.CHOICES, 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) queue = forms.ChoiceField(choices=QUEUE_CHOICES, label=u"Kolejka", required=False) procs = forms.IntegerField(label=u"Liczba procesów", min_value=0, required=False) @@ -133,20 +140,20 @@ class JobDescriptionForm(forms.Form): stage_out = forms.CharField(label=u"Stage out", max_length=500, required=False) monitoring = forms.BooleanField(label=u"Portal QCG-Monitoring", required=False) - notify_type = forms.ChoiceField(label=u"Monitorowanie stanu", choices=NOTIFY_CHOICES, required=False, initial=0, + notify_type = forms.ChoiceField(label=u"Monitorowanie stanu", choices=PROTOCOL_CHOICES, required=False, initial='', widget=forms.RadioSelect) notify_address = forms.EmailField(label=u"Adres", required=False) - watch_output_type = forms.ChoiceField(label=u"Monitorowanie wyjścia", choices=NOTIFY_CHOICES, required=False, - initial=0, widget=forms.RadioSelect) + watch_output_type = forms.ChoiceField(label=u"Monitorowanie wyjścia", choices=PROTOCOL_CHOICES, required=False, + initial='', widget=forms.RadioSelect) watch_output_address = forms.EmailField(label=u"Adres", required=False) watch_output_pattern = forms.CharField(label=u"Wzorzec", max_length=500, required=False) - preprocess_type = forms.ChoiceField(label=u"Preprocessing", choices=PROCESS_CHOICES, required=False, initial=0, - widget=forms.RadioSelect) + 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 - postprocess_type = forms.ChoiceField(label=u"Postprocessing", choices=PROCESS_CHOICES, required=False, initial=0, - widget=forms.RadioSelect) + 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 native = forms.MultipleChoiceField(label=u"Opcje systemu kolejkowego", required=False) @@ -162,6 +169,37 @@ class JobDescriptionForm(forms.Form): self.fields['properties'].choices += ((v, v) for v in data.getlist('properties')) self.fields['native'].choices += ((v, v) for v in data.getlist('native')) + def clean(self): + data = super(JobDescriptionForm, self).clean() + + 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'] = '' + + def clean_application(self): + return self.cleaned_data['application'].split('/', 1) + + def clean_nodes(self): + return map(int, self.cleaned_data['nodes'].split(':', 2)) + class EnvForm(forms.Form): name = forms.CharField(label=u"Nazwa", max_length=100, validators=[env_name_validator],