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

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

Added a lot of UI related stuff.

Line 
1import os
2
3from genshi.template import TemplateLoader
4from genshi.builder import * 
5from genshi import HTML
6
7
8class UIPageRenderer(object):
9    """
10    A set of rendering methods.
11    """
12
13    def __init__(self):
14        # Instantiate Genshi template loader
15        self.templateLoader = TemplateLoader(
16           os.path.join(os.getcwd(), 'cows_wps/templates'),
17           auto_reload=True)
18
19    def _htmlifyItems(self, items):
20        """
21        Ensures that template treats all content items as HTML.
22        """
23        new_items = []
24
25        for i in range(len(items)):
26            new_items.append((items[i][0], HTML(items[i][1])))
27
28        return new_items
29
30    def render(self, title, items):
31        """
32        Renders the page using title and then a list of tuples of
33         (section_title, section_content).
34        """
35        tmpl_gen = self.templateLoader.load("ui_template.html")
36        # Make sure items are HTML and won't be escaped
37        items = self._htmlifyItems(items)
38        stream = tmpl_gen.generate(title=title, items=items, 
39                        wps_capabilities_url="/wps?Service=WPS&Request=GetCapabilities&Format=text/xml")
40        return stream.render('xhtml')
41
Note: See TracBrowser for help on using the repository browser.