~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/webapp/base/xhtml.py

[Uber-commit of holiday work because I lacked a local copy of the branch.]

 ivle.makeuser: Don't use jailconf.py as a header for the in-jail conf.py;
     generate the whole thing using string formatting operators and include
     the template inline.

 ivle.makeuser.make_conf_py: XXX the inclusion of ivle.conf.jail_base in
     the jail. It is simply there to placate ivle.studpath, and needs
     to go before we can entirely remove the in-jail config.

 ivle-buildjail:
   - Add. Converted from setup.buildjail.
   - Build the jail in __base_build__ and rsync it to __base__ when
     done, rather than operating only in ./jail
   - Rename --rebuildjail/-j to --recreate/-r, as the whole script
     is now for jail rebuilding. Also add a warning to the usage string about
     the large volume likely to be downloaded.
   - Check existence before removing trees.
   - Don't copy jailconf.py over conf.py in the jail. Also make
     sure that we remove conf.pyc.

 setup.configure:
   - Stop generating jailconf.py at all.
   - Add a jail_system_build setting, defaulting to __base_build__ next to
     the existing __base__.
   - Don't use an OptionParser before calling the real function, as that
     adds options dynamically.

 setup.install:
   - Add an option (-R) to avoid writing out svn revision info to
     $PREFIX/share/ivle/revision.txt.
   - Remove jail-copying things.
   - Install all services to the host, rather than just usrmgt-server. We do
     this so we can build the jail from the host without the source tree.
   - Shuffle some things, and don't install phpBB3 twice.
   - Add a --root argument, to take an alternate root directory to install
     into (as given to autotools in $DESTDIR).

 setup.build:
   - Allow running as non-root.
   - Take a --no-compile option to not byte-compile Python files.

 setup.util:
   - Include usrmgt-server in the list of services.
   - Add make_install_path(), a wrapper around os.path.join() that ensures
     the second path is relative.
   - Install ivle-buildjail with the other binaries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# IVLE - Informatics Virtual Learning Environment
2
 
# Copyright (C) 2007-2009 The University of Melbourne
3
 
#
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.
8
 
#
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.
13
 
#
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
17
 
 
18
 
# Author: Nick Chadwick
19
 
 
20
 
import inspect
21
 
import os.path
22
 
 
23
 
import genshi.template
24
 
 
25
 
from ivle.webapp.media import media_url
26
 
from ivle.webapp.base.views import BaseView
27
 
import ivle.conf
28
 
import ivle.util
29
 
 
30
 
class XHTMLView(BaseView):
31
 
    """
32
 
    A view which provides a base class for views which need to return XHTML
33
 
    It is expected that apps which use this view will be written using Genshi
34
 
    templates.
35
 
    """
36
 
 
37
 
    template = 'template.html'
38
 
    plugin_scripts = {}
39
 
    plugin_styles = {}
40
 
 
41
 
    def __init__(self, req, **kwargs):
42
 
        for key in kwargs:
43
 
            setattr(self, key, kwargs[key])
44
 
 
45
 
    def render(self, req):
46
 
        req.content_type = 'text/html' # TODO: Detect application/xhtml+xml
47
 
 
48
 
        # View template
49
 
        viewctx = genshi.template.Context()
50
 
        self.populate(req, viewctx)
51
 
 
52
 
        # The template is found in the directory of the module containing the
53
 
        # view.
54
 
        app_template = os.path.join(os.path.dirname(
55
 
                        inspect.getmodule(self).__file__), self.template) 
56
 
        req.write_html_head_foot = False
57
 
        loader = genshi.template.TemplateLoader(".", auto_reload=True)
58
 
        tmpl = loader.load(app_template)
59
 
        app = tmpl.generate(viewctx)
60
 
 
61
 
        for plugin in self.plugin_scripts:
62
 
            for path in self.plugin_scripts[plugin]:
63
 
                req.scripts.append(media_url(req, plugin, path))
64
 
 
65
 
        for plugin in self.plugin_styles:
66
 
            for path in self.plugin_styles[plugin]:
67
 
                req.styles.append(media_url(req, plugin, path))
68
 
 
69
 
        # Global template
70
 
        ctx = genshi.template.Context()
71
 
        ctx['app_styles'] = req.styles
72
 
        ctx['scripts'] = req.scripts
73
 
        ctx['scripts_init'] = req.scripts_init
74
 
        ctx['app_template'] = app
75
 
        self.populate_headings(req, ctx)
76
 
        tmpl = loader.load(os.path.join(os.path.dirname(__file__), 
77
 
                                                        'ivle-headings.html'))
78
 
        req.write(tmpl.generate(ctx).render('xhtml', doctype='xhtml'))
79
 
 
80
 
    def populate_headings(self, req, ctx):
81
 
        ctx['favicon'] = None
82
 
        ctx['root_dir'] = ivle.conf.root_dir
83
 
        ctx['public_host'] = ivle.conf.public_host
84
 
        ctx['write_javascript_settings'] = req.write_javascript_settings
85
 
        if req.user:
86
 
            ctx['login'] = req.user.login
87
 
            ctx['logged_in'] = True
88
 
            ctx['nick'] = req.user.nick
89
 
        else:
90
 
            ctx['login'] = None
91
 
        ctx['publicmode'] = req.publicmode
92
 
        ctx['apps_in_tabs'] = []
93
 
        for urlname in ivle.conf.apps.apps_in_tabs:
94
 
            new_app = {}
95
 
            app = ivle.conf.apps.app_url[urlname]
96
 
            new_app['this_app'] = hasattr(self, 'appname') \
97
 
                                  and urlname == self.appname
98
 
            if app.icon:
99
 
                new_app['has_icon'] = True
100
 
                icon_dir = ivle.conf.apps.app_icon_dir
101
 
                icon_url = ivle.util.make_path(os.path.join(icon_dir, app.icon))
102
 
                new_app['icon_url'] = icon_url
103
 
                if new_app['this_app']:
104
 
                    ctx['favicon'] = icon_url
105
 
            else:
106
 
                new_app['has_icon'] = False
107
 
            new_app['path'] = ivle.util.make_path(urlname)
108
 
            new_app['desc'] = app.desc
109
 
            new_app['name'] = app.name
110
 
            ctx['apps_in_tabs'].append(new_app)