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 __init__(self, *args, **kwargs):
39
super(TextView, self).__init__(*args, **kwargs)
41
def get_context_ancestry(self, req):
42
return req.publisher.get_ancestors(self.context)
44
def filter(self, stream, ctx):
47
def render(self, req):
48
req.content_type = self.content_type
51
viewctx = genshi.template.Context()
52
self.populate(req, viewctx)
54
# The template is found in the directory of the module containing the
56
app_template = os.path.join(os.path.dirname(
57
inspect.getmodule(self).__file__), self.template)
58
tmpl = self._loader.load(app_template,
59
cls=genshi.template.text.NewTextTemplate)
60
app = self.filter(tmpl.generate(viewctx), viewctx)
62
self.populate_headings(req, viewctx)
63
req.write(tmpl.generate(viewctx).render())
65
def populate(self, req, ctx):
66
raise NotImplementedError()
68
def populate_headings(self, req, ctx):
69
ctx['root_dir'] = req.config['urls']['root']
70
ctx['public_host'] = req.config['urls']['public_host']
71
ctx['svn_base'] = req.config['urls']['svn_addr']
72
ctx['write_javascript_settings'] = req.write_javascript_settings
74
ctx['login'] = req.user.login
75
ctx['logged_in'] = True
76
ctx['nick'] = req.user.nick
79
ctx['logged_in'] = False
80
ctx['publicmode'] = req.publicmode