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

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

added and fixed stuff for new UI

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
60        submitter_url = url_for(controller='/submitter', wps_request_url = wps_request,
61                                proc_id = proc_id)
62        #return redirect_to(wps_request)
63        #return "%s" % submitter_url
64        return redirect_to(submitter_url)
65
66    def _handleTextAreaInput(self, value):
67        "Removes any newlines in value and returns as list of strings."
68        value = str(value).replace("\r", "").replace("\n", "").strip().split()
69        return value
70
71    def choose(self):
72        """
73        Shows a drop-down list of possible procs to submit - to choose from.
74        """
75        pc = ProcConfig()
76        procs = pc.getProcList()
77
78        resp = """      <form action="/submit/form">
79                <p>Please select a process from the drop-down menu below and press 'GO' to generate a form to submit a job.</p>
80                <select name="proc_id">"""
81
82        for (proc, long_name) in procs.items():
83            resp += ('                  <option name="%s" value="%s">%s</option>\n' % (proc, proc, long_name))
84
85        resp += """             </select>
86                <input type="submit" value="GO" />
87        </form>"""
88
89        renderer = UIPageRenderer()
90        resp = renderer.render("Submission Form",
91                               [("Choose a process to submit a job to", resp)])
92
93        return resp
94
95
96    def form(self):
97        """
98        Displays a form for submitting a job.
99        """
100        proc = request.params.get("proc_id", None)
101        if proc == None:
102            return "Please provide an argument proc_id=&lt;Something&gt;"
103
104        pc = ProcConfig()
105        proc_submission_form_html = pc.renderProcSubmissionForm(proc)
106        bbox_required = pc.bbox_arg_found
107        resp = proc_submission_form_html
108
109        renderer = UIPageRenderer()
110        resp = renderer.render("Submission Form for: '%s'" % proc,
111                               [("Define your inputs", resp)],
112                               bbox_required=bbox_required)
113        return resp
114
Note: See TracBrowser for help on using the repository browser.