initial work on submitting job logic
[qcg-portal.git] / qcg / forms.py
index e078fe7..7c715d9 100644 (file)
@@ -8,6 +8,10 @@ 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}$')
+env_name_validator = RegexValidator(r'^[a-zA-Z_][a-zA-Z0-9_]*$')
+
+CHOICES_PLACEHOLDER = (None, '')
 
 
 class FiltersForm(forms.Form):
@@ -56,6 +60,118 @@ class FiltersForm(forms.Form):
             for host in Allocation.objects.values_list('host_name', flat=True).order_by('host_name').distinct())
 
 
+class JobDescriptionForm(forms.Form):
+    class Host(object):
+        GALERA = 'galera.task.gda.pl'
+        HYDRA = 'hydra.icm.edu.pl'
+        INULA = 'inula.man.poznan.pl'
+        MOSS = 'moss.man.poznan.pl'
+        NOVA = 'nova.wcss.wroc.pl'
+        REEF = 'reef.man.poznan.pl'
+        ZEUS = 'zeus.cyfronet.pl'
+
+        CHOICES = (
+            CHOICES_PLACEHOLDER,
+            (GALERA, u'Galera'),
+            (HYDRA, u'Hydra'),
+            (INULA, u'Inula'),
+            (MOSS, u'Moss'),
+            (NOVA, u'Supernova'),
+            (REEF, u'Reef'),
+            (ZEUS, u'Zeus'),
+        )
+    APPLICATION_CHOICES = (
+        CHOICES_PLACEHOLDER,
+        ('bash', 'BASH'),
+        ('gromacs/4.6.3', 'GROMACS 4.6.3'),
+        ('matlab', 'MATLAB'),
+        ('python', 'Python'),
+    )
+    QUEUE_CHOICES = (
+        CHOICES_PLACEHOLDER,
+        ('plgid', 'plgrid'),
+        ('plgid-long', 'plgrid-long'),
+        ('plgid-testing', 'plgrid-testing'),
+    )
+    MODULES_CHOICES = (
+        ('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'),
+    )
+
+    application = forms.ChoiceField(choices=APPLICATION_CHOICES, label=u"Aplikacja", required=False)  # TODO choices
+    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
+    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)
+
+    host = forms.ChoiceField(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)
+    nodes = forms.CharField(label=u"Topologia węzłów", max_length=10, validators=[nodes_validator], required=False)
+    wall_time = forms.IntegerField(label=u"Wall time (s)", min_value=0, required=False)  # TODO duration field
+    memory = forms.IntegerField(label=u"Pamięć (MB)", min_value=0, required=False)
+    memory_per_slot = forms.IntegerField(label=u"Pamięci per proces (MB)", min_value=0, required=False)
+    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.CharField(label=u"Stage in", max_length=500, required=False)
+    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,
+                                    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_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_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_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)
+    persistent = forms.BooleanField(label=u"Trwałe", required=False)
+
+    def __init__(self, data=None, *args, **kwargs):
+        super(JobDescriptionForm, self).__init__(data, *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'))
+
+
+class EnvForm(forms.Form):
+    name = forms.CharField(label=u"Nazwa", max_length=100, validators=[env_name_validator],
+                           widget=forms.TextInput(attrs={'placeholder': u'Nazwa'}))
+    value = forms.CharField(label=u"Wartość", max_length=500,
+                            widget=forms.TextInput(attrs={'placeholder': u'Wartość'}))
+
+
+EnvFormSet = forms.formset_factory(EnvForm, can_delete=True, extra=0)
+
+
 class ColumnsForm(forms.Form):
     JOB_ID, DESCRIPTION, SUBMISSION, START, END, STATUS, HOST = range(7)
     COLUMNS_CHOICES = (
@@ -68,5 +184,5 @@ class ColumnsForm(forms.Form):
         (HOST, u"Host"),
     )
 
-    columns = forms.MultipleChoiceField(choices=COLUMNS_CHOICES, label=u"Kolumny", required=False,
-                                        widget=forms.CheckboxSelectMultiple)
\ No newline at end of file
+    columns = forms.MultipleChoiceField(choices=COLUMNS_CHOICES, initial=[k for k, v in COLUMNS_CHOICES[1:]],
+                                        label=u"Kolumny", required=False, widget=forms.CheckboxSelectMultiple)