1
# IVLE - Informatics Virtual Learning Environment
2
# Copyright (C) 2007-2009 The University of Melbourne
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
import genshi.template
25
from ivle.webapp.base.views import BaseView
26
from ivle.webapp.base.xhtml import GenshiLoaderMixin
29
class TextView(GenshiLoaderMixin, BaseView):
31
A view which provides a base class for views which need to return plain
32
text results using Genshi text templates.
35
template = 'template.txt'
36
content_type = 'text/plain'
38
def get_context_ancestry(self, req):
39
return req.publisher.get_ancestors(self.context)
41
def filter(self, stream, ctx):
44
def render(self, req):
45
req.content_type = self.content_type
48
viewctx = genshi.template.Context()
49
self.populate(req, viewctx)
51
# The template is found in the directory of the module containing the
53
app_template = os.path.join(os.path.dirname(
54
inspect.getmodule(self).__file__), self.template)
55
tmpl = self._loader.load(app_template,
56
cls=genshi.template.text.NewTextTemplate)
57
app = self.filter(tmpl.generate(viewctx), viewctx)
59
self.populate_headings(req, viewctx)
60
req.write(tmpl.generate(viewctx).render())
62
def populate(self, req, ctx):
63
raise NotImplementedError()
65
def populate_headings(self, req, ctx):
66
ctx['root_dir'] = req.config['urls']['root']
67
ctx['public_host'] = req.config['urls']['public_host']
68
ctx['svn_base'] = req.config['urls']['svn_addr']
69
ctx['write_javascript_settings'] = req.write_javascript_settings
71
ctx['login'] = req.user.login
72
ctx['logged_in'] = True
73
ctx['nick'] = req.user.nick
76
ctx['logged_in'] = False
77
ctx['publicmode'] = req.publicmode