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

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

various fixes, got ui renderer working instead of html pages. fixes zoom
and center of the bounding box on submit page.

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