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

« back to all changes in this revision

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

  • Committer: William Grant
  • Date: 2010-07-28 05:06:15 UTC
  • Revision ID: grantw@unimelb.edu.au-20100728050615-uwbxn9frla3pdw8m
Encode content_type when downloading files. cjson made us write bad code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
from ivle.webapp.publisher import NoPath
32
32
from ivle.webapp.breadcrumbs import Breadcrumber
33
33
 
34
 
class XHTMLView(BaseView):
 
34
 
 
35
class GenshiLoaderMixin(object):
 
36
    """Mixin for classes which need to render Genshi templates.
 
37
 
 
38
    A TemplateLoader is shared between all instances, so templates are
 
39
    cached across multiple instances and therefore also requests.
 
40
    """
 
41
    _loader = None
 
42
 
 
43
    def __init__(self, *args, **kwargs):
 
44
        super(GenshiLoaderMixin, self).__init__(*args, **kwargs)
 
45
 
 
46
        # We use a single loader for all views, so we can cache the
 
47
        # parsed templates. auto_reload is convenient and has a minimal
 
48
        # performance penalty, so we'll leave it on.
 
49
        if GenshiLoaderMixin._loader is None:
 
50
            GenshiLoaderMixin._loader = genshi.template.TemplateLoader(
 
51
                ".", auto_reload=True,
 
52
                max_cache_size=100)
 
53
 
 
54
 
 
55
class XHTMLView(GenshiLoaderMixin, BaseView):
35
56
    """
36
57
    A view which provides a base class for views which need to return XHTML
37
58
    It is expected that apps which use this view will be written using Genshi
41
62
    template = 'template.html'
42
63
    allow_overlays = True
43
64
    breadcrumb_text = None
44
 
    _loader = None
45
65
 
46
66
    def __init__(self, *args, **kwargs):
47
67
        super(XHTMLView, self).__init__(*args, **kwargs)
48
68
 
49
 
        # We use a single loader for all views, so we can cache the
50
 
        # parsed templates. auto_reload is convenient and has a minimal
51
 
        # performance penalty, so we'll leave it on.
52
 
        if self.__class__._loader is None:
53
 
            self.__class__._loader = genshi.template.TemplateLoader(
54
 
                ".", auto_reload=True,
55
 
                max_cache_size=100)
56
 
 
57
69
        self.overlay_blacklist = []
58
70
 
59
71
        self.plugin_scripts = {}