2 from django import forms
3 from django.core.validators import RegexValidator
4 from django.template.defaultfilters import capfirst
5 from pyqcg.utils import TaskStatus
7 from qcg.fields import TimeRangeField
8 from qcg.models import Task, Allocation
11 date_range_validator = RegexValidator(r'[0-9]{2}\.[0-9]{2}\.[0-9]{4} - [0-9]{2}\.[0-9]{2}\.[0-9]{4}')
12 nodes_validator = RegexValidator(r'^[0-9]{1,3}:[0-9]{1,2}(:[0-9]{1,2})?$')
13 env_name_validator = RegexValidator(r'^[a-zA-Z_][a-zA-Z0-9_]*$')
15 CHOICES_PLACEHOLDER = (None, '')
18 class FiltersForm(forms.Form):
19 ACTIVE, FINISHED, FAILED = range(3)
22 (FINISHED, u"Zakończone"),
23 (FAILED, u"Niepowodzenia"),
28 Task.STATUS_CHOICES_REVERSED[TaskStatus.UNSUBMITTED],
29 Task.STATUS_CHOICES_REVERSED[TaskStatus.UNCOMMITTED],
30 Task.STATUS_CHOICES_REVERSED[TaskStatus.QUEUED],
31 Task.STATUS_CHOICES_REVERSED[TaskStatus.PREPROCESSING],
32 Task.STATUS_CHOICES_REVERSED[TaskStatus.PENDING],
33 Task.STATUS_CHOICES_REVERSED[TaskStatus.RUNNING],
34 Task.STATUS_CHOICES_REVERSED[TaskStatus.STOPPED],
35 Task.STATUS_CHOICES_REVERSED[TaskStatus.POSTPROCESSING],
38 Task.STATUS_CHOICES_REVERSED[TaskStatus.FINISHED],
41 Task.STATUS_CHOICES_REVERSED[TaskStatus.FAILED],
42 Task.STATUS_CHOICES_REVERSED[TaskStatus.CANCELED],
45 STATUS_CHOICES_DICT = dict(STATUS_CHOICES)
47 status = forms.MultipleChoiceField(choices=STATUS_CHOICES, label=u"Status", required=False,
48 widget=forms.CheckboxSelectMultiple)
49 host = forms.MultipleChoiceField(label=u"Host", required=False, widget=forms.CheckboxSelectMultiple)
52 keywords = forms.CharField(max_length=100, label=u"Wyszukaj frazę", required=False)
53 submission = forms.CharField(label=u"Data zlecenia", validators=[date_range_validator], required=False)
54 finish = forms.CharField(label=u"Data zakończenia", validators=[date_range_validator], required=False)
56 def __init__(self, *args, **kwargs):
57 super(FiltersForm, self).__init__(*args, **kwargs)
59 self.fields['host'].choices = tuple(
60 (host, capfirst(host.split('.', 1)[0]))
61 for host in Allocation.objects.values_list('host_name', flat=True).order_by('host_name').distinct())
64 class JobDescriptionForm(forms.Form):
66 GALERA = 'galera.task.gda.pl'
67 HYDRA = 'hydra.icm.edu.pl'
68 INULA = 'inula.man.poznan.pl'
69 MOSS = 'moss.man.poznan.pl'
70 NOVA = 'nova.wcss.wroc.pl'
71 REEF = 'reef.man.poznan.pl'
72 ZEUS = 'zeus.cyfronet.pl'
85 class Process(object):
96 APPLICATION_CHOICES = (
99 ('gromacs/4.6.3', 'GROMACS 4.6.3'),
100 ('matlab', 'MATLAB'),
101 ('python', 'Python'),
106 ('plgid-long', 'plgrid-long'),
107 ('plgid-testing', 'plgrid-testing'),
110 ('plgrid/apps/python', 'plgrid/apps/python'),
111 ('plgrid/apps/matlab', 'plgrid/apps/matlab'),
115 ('mailto', u'E-mail'),
119 application = forms.ChoiceField(choices=APPLICATION_CHOICES, label=u"Aplikacja", required=False) # TODO choices
120 executable = forms.CharField(label=u"Plik wykonywalny", max_length=500, required=False) # TODO grid ftp
121 script = forms.CharField(label=u"Skrypt", widget=forms.Textarea(attrs={'rows': 2, 'cols': 40}), required=False) # TODO saving to grid ftp
122 arguments = forms.MultipleChoiceField(label=u"Argumenty", required=False)
123 note = forms.CharField(label=u"Opis", widget=forms.Textarea(attrs={'rows': 2, 'cols': 40}), required=False)
124 grant = forms.CharField(label=u"Grant", max_length=100, required=False)
126 hosts = forms.MultipleChoiceField(label=u"Host", choices=Host.CHOICES, required=False)
127 properties = forms.MultipleChoiceField(label=u"Właściwości węzłów", required=False)
128 queue = forms.ChoiceField(choices=QUEUE_CHOICES, label=u"Kolejka", required=False)
129 procs = forms.IntegerField(label=u"Liczba procesów", min_value=0, required=False)
130 nodes = forms.CharField(label=u"Topologia węzłów", max_length=10, validators=[nodes_validator], required=False)
131 wall_time = TimeRangeField(label=u"Wall time", required=False)
132 memory = forms.IntegerField(label=u"Pamięć (MB)", min_value=0, required=False)
133 memory_per_slot = forms.IntegerField(label=u"Pamięci per proces (MB)", min_value=0, required=False)
134 modules = forms.MultipleChoiceField(label=u"Moduły", choices=MODULES_CHOICES, required=False) # TODO choices
135 reservation = forms.CharField(label=u"Rezerwacja", max_length=100, required=False)
138 input = forms.CharField(label=u"Standardowe wejście", max_length=500, required=False)
139 stage_in = forms.CharField(label=u"Stage in", max_length=500, required=False)
140 stage_out = forms.CharField(label=u"Stage out", max_length=500, required=False)
142 monitoring = forms.BooleanField(label=u"Portal QCG-Monitoring", required=False)
143 notify_type = forms.ChoiceField(label=u"Monitorowanie stanu", choices=PROTOCOL_CHOICES, required=False, initial='',
144 widget=forms.RadioSelect)
145 notify_address = forms.EmailField(label=u"Adres", required=False)
146 watch_output_type = forms.ChoiceField(label=u"Monitorowanie wyjścia", choices=PROTOCOL_CHOICES, required=False,
147 initial='', widget=forms.RadioSelect)
148 watch_output_address = forms.EmailField(label=u"Adres", required=False)
149 watch_output_pattern = forms.CharField(label=u"Wzorzec", max_length=500, required=False)
151 preprocess_type = forms.ChoiceField(label=u"Preprocessing", choices=Process.CHOICES, required=False,
152 initial=Process.NONE, widget=forms.RadioSelect)
153 preprocess_cmd = forms.CharField(label=u"Polecenie", max_length=1000, required=False)
154 preprocess_script = forms.CharField(label=u"Skrypt", max_length=500, required=False) # TODO grid ftp
155 postprocess_type = forms.ChoiceField(label=u"Postprocessing", choices=Process.CHOICES, required=False,
156 initial=Process.NONE, widget=forms.RadioSelect)
157 postprocess_cmd = forms.CharField(label=u"Polecenie", max_length=1000, required=False)
158 postprocess_script = forms.CharField(label=u"Skrypt", max_length=500, required=False) # TODO grid ftp
159 native = forms.MultipleChoiceField(label=u"Opcje systemu kolejkowego", required=False)
160 persistent = forms.BooleanField(label=u"Trwałe", required=False)
162 def __init__(self, data=None, *args, **kwargs):
163 super(JobDescriptionForm, self).__init__(data, *args, **kwargs)
166 # accept user defined choices
167 self.fields['queue'].choices += ((data.get('queue'), data.get('queue')), )
168 self.fields['arguments'].choices += ((v, v) for v in data.getlist('arguments'))
169 self.fields['properties'].choices += ((v, v) for v in data.getlist('properties'))
170 self.fields['native'].choices += ((v, v) for v in data.getlist('native'))
173 data = super(JobDescriptionForm, self).clean()
175 notify_type = data.get('notify_type')
176 data['notify'] = u'{}:{}'.format(notify_type, data['notify_address']) if notify_type else ''
178 wo_type = data.get('watch_output_type')
179 data['watch_output'] = u'{}:{}'.format(wo_type, data['watch_output_address']) if wo_type else ''
181 preprocess_type = data.get('preprocess_type')
182 if preprocess_type == self.Process.CMD:
183 data['preprocess'] = data['preprocess_cmd']
184 elif preprocess_type == self.Process.SCRIPT:
185 data['preprocess'] = data['preprocess_script']
187 data['preprocess'] = ''
189 postprocess_type = data.get('postprocess_type')
190 if postprocess_type == self.Process.CMD:
191 data['postprocess'] = data['postprocess_cmd']
192 elif postprocess_type == self.Process.SCRIPT:
193 data['postprocess'] = data['postprocess_script']
195 data['postprocess'] = ''
197 def clean_application(self):
198 value = self.cleaned_data['application']
201 return value.split('/', 1)
205 def clean_nodes(self):
206 value = map(int, self.cleaned_data['nodes'].split(':', 2))
212 return nodes, slots, slots
215 class EnvForm(forms.Form):
216 name = forms.CharField(label=u"Nazwa", max_length=100, validators=[env_name_validator],
217 widget=forms.TextInput(attrs={'placeholder': u'Nazwa'}))
218 value = forms.CharField(label=u"Wartość", max_length=500,
219 widget=forms.TextInput(attrs={'placeholder': u'Wartość'}))
222 EnvFormSet = forms.formset_factory(EnvForm, can_delete=True, extra=0)
225 class ColumnsForm(forms.Form):
226 JOB_ID, DESCRIPTION, SUBMISSION, START, END, STATUS, HOST = range(7)
228 (JOB_ID, u"Identyfikator zadania"),
229 (DESCRIPTION, u"Opis"),
230 (SUBMISSION, u"Wysłane"),
237 columns = forms.MultipleChoiceField(choices=COLUMNS_CHOICES, initial=[k for k, v in COLUMNS_CHOICES[1:]],
238 label=u"Kolumny", required=False, widget=forms.CheckboxSelectMultiple)