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

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

added and fixed stuff for new UI

Line 
1import os
2import re
3import glob
4import logging
5import urllib
6import xml.etree.ElementTree as ET
7
8from pylons import request, response, session, tmpl_context as c
9from pylons.controllers.util import abort, redirect_to
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 JobviewerController(BaseController):
32
33
34    def index(self):
35        status_url = str(request.params.getone("status_url"))
36        job_xml = urllib.urlopen(status_url).read()
37
38        job_id = re.search("<JobID>(.*)</JobID>", job_xml).groups()[0]
39
40        job_xml_encoded = self._htmlifyXML(job_xml)
41        job_as_table = self._xmlToTable(job_xml)
42        job_as_plots = "THERE ARE NOT PLOTS FOUND IN THIS OUTPUT."
43
44        resp = """<div id="view_options" style="background: #dddddd; border:5px outset red; padding: 5px;">
45                <a href="javascript:switchViewTo('xml_view');">XML</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
46                <a href="javascript:switchViewTo('table_view');">Table</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
47                <a href="javascript:switchViewTo('plots_view');">Plots</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
48</div>
49<div id="view_container" style="background: white; border:5px outset red; padding: 5px;">
50        <div id="view_contents">
51                <div id="xml_view" style="visibility: hidden; height: 0px;">%s</div>
52                <div id="table_view" style="visibility: hidden; height: 0px;">%s</div>
53                <div id="plots_view" style="visibility: hidden; height: 0px;">%s</div>
54</div>""" % (job_xml_encoded, job_as_table, job_as_plots)
55
56        renderer = UIPageRenderer()
57        resp = renderer.render("WPS Job Information",
58                              [("Job: %s" % job_id, resp)])
59        return resp
60
61
62    def _xmlToTable(self, xml):
63        "Chops up xml to get table of outputs."
64        node = ET.fromstring(xml)
65
66        proc_id = node.find("{http://www.opengeospatial.net/ows}Identifier").text
67        job_details = node.find("{http://www.opengeospatial.net/wps}ProcessOutputs").find("{http://www.opengeospatial.net/wps}Output").find("{http://www.opengeospatial.net/wps}ComplexValue").find("{http://www.opengeospatial.net/wps}WPSResponseDetails").find("{http://www.opengeospatial.net/wps}JobDetails")
68
69        file_set_list = job_details.find("{http://www.opengeospatial.net/wps}FileSet").getchildren()
70
71        items = ["JobID", "JobCompletionTimeDate", "JobDuration", "JobVolume", "RequestDescription",
72                 "RequestType"]
73
74        resp = "<p><b>Details of job...</b></p>"
75
76        for i in items:
77            x = job_details.find("{http://www.opengeospatial.net/wps}" + i).text
78            resp += "<b>%s</b> = %s<br>" % (i, x.strip())
79
80        resp += "<h2>OUTPUTS</h2>"
81        for fnode in file_set_list:
82            furl = fnode.find("{http://www.opengeospatial.net/wps}FileURL").text
83            resp += "%s = %s</br>" % ("DOWNLOAD", furl)
84
85        return resp
86
87
88    def _htmlifyXML(self, xml):
89        "Returns html string that will make XML look ok on HTML page."
90        xml = xml.replace("<", "&lt;").replace(">", "&gt;").replace("\n", "<br>")
91        return xml
92
93
Note: See TracBrowser for help on using the repository browser.