source: cows_wps/trunk/cows_wps/controllers/submit.py @ 6116

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows_wps/trunk/cows_wps/controllers/submit.py@6116
Revision 6116, 2.9 KB checked in by astephen, 11 years ago (diff)

more fixes and improvements

Line 
1import logging
2import urllib2
3
4from pylons import request, response, session, tmpl_context as c
5from pylons.controllers.util import abort, redirect_to
6
7from cows_wps.renderer.ui_renderer import *
8from cows_wps.controllers import *
9from cows_wps.lib.ui.proc_config import *
10
11log = logging.getLogger(__name__)
12
13
14class SubmitController(BaseController):
15
16    def index(self):
17        """
18        Submits a job.
19        """
20        args = {}
21        for key in request.params.keys():
22            # Ignore items prefixed with underscore
23            if str(key)[0] == "_": continue
24
25            # Use getall for all args and pipe join them if more than one
26            values = request.params.getall(key)
27            if values[0] == "-- Please select --":
28                del values[0]
29
30            # Remove if no values provided
31            if len(values) == 0: continue
32
33            value = "|".join([str(i) for i in values])
34            args[str(key)] = urllib2.quote(value)
35
36        if not args.has_key("proc_id"):
37            return "Must provide 'proc_id' arg at the very minimum."
38
39        proc_id = args["proc_id"]
40        del args["proc_id"]
41
42        wps_url_format = "/wps?Request=Execute&Format=text/xml&Identifier=%s&Store=false&Status=false&DataInputs="
43        wps_request = wps_url_format % proc_id
44
45        for (key, value) in args.items():
46            wps_request += "%s,%s," % (key, value)
47
48        # remove comma
49        wps_request = wps_request[:-1]
50
51        return redirect_to(wps_request) 
52
53    def choose(self):
54        """
55        Shows a drop-down list of possible procs to submit - to choose from.
56        """
57        pc = ProcConfig()
58        procs = pc.getProcList()
59
60        resp = """      <form action="/submit/form">
61                <p>Please select a process from the drop-down menu below and press 'GO' to generate a form to submit a job.</p>
62                <select name="proc_id">"""
63
64        for (proc, long_name) in procs.items():
65            resp += ('                  <option name="%s" value="%s">%s</option>\n' % (proc, proc, long_name))
66
67        resp += """             </select>
68                <input type="submit" value="GO" />
69        </form>"""
70
71        renderer = UIPageRenderer()
72        resp = renderer.render("Submission Form",
73                               [("Choose a process to submit a job to", resp)])
74
75        return resp
76
77
78    def form(self):
79        """
80        Displays a form for submitting a job.
81        """
82        proc = request.params.get("proc_id", None)
83        if proc == None:
84            return "Please provide an argument proc_id=&lt;Something&gt;"
85
86        pc = ProcConfig()
87        proc_submission_form_html = pc.renderProcSubmissionForm(proc)
88        resp = proc_submission_form_html
89
90        renderer = UIPageRenderer()
91        resp = renderer.render("Submission Form for: '%s'" % proc,
92                               [("Define your inputs", resp)])
93        return resp
94
Note: See TracBrowser for help on using the repository browser.