source: cows_wps/trunk/cows_wps/controllers/submitter.py @ 6898

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

many fixes

Line 
1import os
2import re
3import glob
4import logging
5import urllib
6
7from pylons import request, response, session, tmpl_context as c
8from pylons.controllers.util import abort, redirect_to
9from routes import url_for
10
11
12from cows.exceptions import *
13from cows.pylons.ows_controller import render_ows_exception
14
15from cows_wps.controllers import *
16from cows_wps import utils
17from cows_wps.renderer.ui_renderer import *
18from cows_wps.model.managers import requestManager
19from cows_wps.process_handler.context.process_context import ProcessContext
20from cows_wps.renderer import xml_renderer
21
22from cows_wps.utils.parse_wps_config import wps_config_dict
23from cows_wps.utils.parse_capabilities_config import caps_config_dict
24
25
26from cows_wps.model.managers import requestManager
27
28log = logging.getLogger(__name__)
29
30
31class SubmitterController(BaseController):
32
33
34    def index(self):
35        wps_request_url = str(request.params.getone("wps_request_url"))
36        proc_id = str(request.params.getone("proc_id"))
37
38        async = self._isAsync(proc_id)
39       
40        # If quick process then just forward
41        if async == False:
42            base_url = "http://" + request.url[7:].split("/")[0]
43            full_url = base_url + wps_request_url
44            getter = urllib.urlopen(full_url)
45            xml = getter.read()
46            getter.close()
47            status_url = re.search('statusLocation="(.+?)"', xml).groups()[0]
48
49            jobviewer_url = url_for(controller='jobviewer', status_url = status_url) 
50            return redirect_to(jobviewer_url)
51
52        # Now we are only dealing with async requests
53        wps_resp_div = "wps_response_div"
54        resp = '<div>Submitting asynchronous request to get the cost of the request for: %s</div><div id="%s"></div>' % (proc_id, wps_resp_div)
55        resp += """<script type="text/javascript">
56
57        function init() {
58                makeWPSRequest('%s', '%s');
59        }
60
61</script>""" % (wps_request_url, wps_resp_div)
62
63        renderer = UIPageRenderer()
64        resp = renderer.render("Submitting here",
65                               [("Submits or shows confirmation", resp)])
66
67        return resp
68
69    def _isAsync(self, proc_id):
70        "Returns boolean by looking up if WPS is async."
71        process_conf = caps_config_dict[proc_id]
72        process_type = process_conf["wps_interface"]["process_type"]
73
74        if process_type == "async_l":
75            return True
76        else:
77            return False
78       
Note: See TracBrowser for help on using the repository browser.