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

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

Added various additions to allow dynamic generation of arguments based
on WPS calls.

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