source: cows_wps/trunk/cows_wps/renderer/ui_renderer.py @ 7095

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows_wps/trunk/cows_wps/renderer/ui_renderer.py@7095
Revision 7095, 2.2 KB checked in by astephen, 10 years ago (diff)

fixing up jobs page and moving renderer code into renderer package

Line 
1import os
2
3from pylons import config, tmpl_context as c
4
5
6from genshi.template import TemplateLoader
7from genshi.builder import * 
8from genshi import HTML
9
10c.tester = "OOJOJ"
11
12
13class UIPageRenderer(object):
14    """
15    A set of rendering methods.
16    """
17
18    def __init__(self):
19        # Instantiate Genshi template loader
20        self.template_dir = config["wps.template_dir"]
21        self.templateLoader = TemplateLoader(self.template_dir, auto_reload=True)
22
23    def _htmlifyItems(self, items):
24        """
25        Ensures that template treats all content items as HTML.
26        """
27        new_items = []
28
29        for i in range(len(items)):
30            new_items.append((items[i][0], HTML(items[i][1])))
31
32        return new_items
33
34    def render(self, title, items, bbox_required=False):
35        """
36        Renders the page using title and then a list of tuples of
37         (section_title, section_content).
38        """
39        tmpl_gen = self.templateLoader.load("ui_template.html")
40        # Make sure items are HTML and won't be escaped
41        items = self._htmlifyItems(items)
42        stream = tmpl_gen.generate(title=title, items=items, 
43                        wps_capabilities_url="/wps?Service=WPS&Request=GetCapabilities&Format=text/xml",
44                        bbox_required=bbox_required)
45        return stream.render('xhtml')
46
47
48    def renderJobsPage(self, jobs, total_matches, args, bad_args):
49        """
50        Renders jobs page.
51        """
52        rjobs = '<table border="2"><tr><td>Job id</td><td>Job type</td><td>User</td><td>Submission time</td><td>Job status</td></tr>\n'
53        for  (job_id, user, status, job_type, created) in jobs:
54            created = created.split(".")[0]
55            row = "<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n" % (job_id, job_type, user, created, status)
56            rjobs += row
57
58        rjobs += "</table>"
59 
60        items = [("Jobs Page", "This is where you can view jobs."),
61                 ("Warning bad args", str(bad_args)),
62                 ("Filtering Area", str(args)),
63                 ("Total Matches", str(total_matches)),
64                 ("Jobs", rjobs)]  #["<br>%s = %s" % (job[0], str(job)) for job in jobs])]
65
66        return self.render("Jobs Page", items)
67
Note: See TracBrowser for help on using the repository browser.