fixes for updated api
[qcg-portal.git] / qcg / views.py
index c34af9b..0be3d73 100644 (file)
@@ -163,56 +163,35 @@ def job_new(request):
 
             desc = JobDescription(Credential(request.session['proxy']))
 
-            application = form.cleaned_data['application']
-            if '/' in application:
-                app, ver = application.split('1', 1)
-                desc.application.set_name(app)
-                desc.application.set_version(ver)
-            else:
-                desc.application.set_name(application)
+            direct_map = ('application', 'arguments', 'note', 'grant', 'hosts', 'properties', 'queue', 'procs', 'nodes',
+                          'wall_time', 'memory', 'memory_per_slot', 'modules', 'native', 'notify', 'preprocess',
+                          'postprocess', 'persistent')
 
+            for name in direct_map:
+                if form.cleaned_data[name]:
+                    setattr(desc, name, form.cleaned_data[name])
+
+            desc.reservation = ('LOCAL', form.cleaned_data['reservation'])
+            desc.watch_output = (form.cleaned_data['watch_output'], form.cleaned_data['watch_output_pattern'])
+            desc.env_variables += [(env['name'], env['value']) for env in env_formset.cleaned_data if not env['DELETE']]
             # TODO script
             # TODO executable
-            desc.arguments = form.cleaned_data['arguments']
-            desc.note = form.cleaned_data['note']
-            desc.grant = form.cleaned_data['grant']
-            desc.host_candidates = [(form.cleaned_data['host'], 'type?')]  # FIXME WTF ?!?
-            desc.properties = form.cleaned_data['properties']
-            # TODO queue
-            # TODO procs
-            # TODO nodes
-            desc.wall_time = timedelta(seconds=form.cleaned_data['wall_time'])  # FIXME odpowiedni typ pola
-            desc.memory = form.cleaned_data['memory']
-            desc.memory_per_slot = form.cleaned_data['memory_per_slot']
-            desc.variable = [(env['name'], env['value']) for env in env_formset.cleaned_data if not env['DELETE']]
-            desc.modules = form.cleaned_data['modules']
-            desc.natives = form.cleaned_data['native']
-            desc.reservation = ("LOCAL", form.cleaned_data['reservation'])
             # TODO input
             # TODO stage_in
             # TODO stage_out
             # TODO monitoring
-            # TODO notify_type
-            # TODO notify_address
-            # TODO watch_output_type
-            # TODO watch_output_address
-            # TODO watch_output_pattern
-            # TODO preprocess_type
-            # TODO preprocess_cmd
-            # TODO preprocess_script
-            # TODO postprocess_type
-            # TODO postprocess_cmd
-            # TODO postprocess_script
-            desc.persistent = form.cleaned_data['persistent']
-
-            for prop in ('arguments', 'note', 'grant', 'host_candidates', 'wall_time', 'memory',
-                         'memory_per_slot', 'properties', 'variable', 'modules', 'natives', 'persistent', 'reservation'):
+
+            for prop in direct_map + ('env_variables', 'reservation', 'watch_output'):
                 print prop, type(getattr(desc, prop)), repr(getattr(desc, prop))
 
             print desc.xml_description
 
+        print repr(form.errors)
+        print repr(env_formset.errors)
     else:
         form = JobDescriptionForm()
         env_formset = EnvFormSet()
 
-    return render(request, 'qcg/job_new.html', {'form': form, 'env_formset': env_formset})
+    errors = form.errors or (env_formset.is_bound and not env_formset.is_valid)
+
+    return render(request, 'qcg/job_new.html', {'form': form, 'env_formset': env_formset, 'errors': errors})