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

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

fixed

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