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

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

Got bounding box added to MIDAS extractors. And in doing so they will work for all.

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