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

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

added admin interface - still needs a db to talk to.

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
54        count = 0
55
56        for  (job_id, user, status, job_type, created) in jobs:
57            created = created.split(".")[0]
58
59            # Set colour style for row
60            count += 1
61            row_style = ("even_row", "odd_row")[count % 2]
62
63            # HTML for row
64            row = '<tr class="%s"><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n' % (row_style, job_id, job_type, user, created, status)
65            rjobs += row
66
67        rjobs += "</table>"
68 
69        items = [("Jobs Page", "This is where you can view jobs."),
70                 ("Warning bad args", str(bad_args)),
71                 ("Filtering Area", str(args)),
72                 ("Total Matches", str(total_matches)),
73                 ("Jobs", rjobs)]  #["<br>%s = %s" % (job[0], str(job)) for job in jobs])]
74
75        return self.render("Jobs Page", items)
76
Note: See TracBrowser for help on using the repository browser.