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

« back to all changes in this revision

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

  • Committer: William Grant
  • Date: 2010-02-25 07:34:50 UTC
  • Revision ID: grantw@unimelb.edu.au-20100225073450-zcl8ev5hlyhbszeu
Activate the Storm C extensions if possible. Moar speed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import genshi.template
27
27
 
28
28
from ivle.webapp.base.views import BaseView
 
29
from ivle.webapp.base.xhtml import GenshiLoaderMixin
29
30
from ivle.webapp.errors import BadRequest, MethodNotAllowed, Unauthorized
30
31
 
31
32
class RESTView(BaseView):
35
36
    """
36
37
    content_type = "application/octet-stream"
37
38
 
38
 
    def __init__(self, req, *args, **kwargs):
39
 
        for key in kwargs:
40
 
            setattr(self, key, kwargs[key])
41
 
 
42
39
    def render(self, req):
43
40
        raise NotImplementedError()
44
41
 
59
56
        if not hasattr(op, '_rest_api_permission'):
60
57
            raise Unauthorized()
61
58
 
62
 
        if op._rest_api_permission not in self.get_permissions(req.user):
 
59
        if (op._rest_api_permission not in
 
60
            self.get_permissions(req.user, req.config)):
63
61
            raise Unauthorized()
64
62
    
65
63
    def convert_bool(self, value):
152
150
            req.write("\n")
153
151
 
154
152
 
155
 
class XHTMLRESTView(JSONRESTView):
 
153
class XHTMLRESTView(GenshiLoaderMixin, JSONRESTView):
156
154
    """A special type of RESTView which takes enhances the standard JSON
157
155
    with genshi XHTML functions.
158
156
    
161
159
    template = None
162
160
    ctx = genshi.template.Context()
163
161
 
164
 
    def __init__(self, req, *args, **kwargs):
165
 
        for key in kwargs:
166
 
            setattr(self, key, kwargs[key])
167
 
    
168
162
    def render_fragment(self):
169
163
        if self.template is None:
170
164
            raise NotImplementedError()
171
165
 
172
166
        rest_template = os.path.join(os.path.dirname(
173
167
                inspect.getmodule(self).__file__), self.template)
174
 
        loader = genshi.template.TemplateLoader(".", auto_reload=True)
175
 
        tmpl = loader.load(rest_template)
 
168
        tmpl = self._loader.load(rest_template)
176
169
 
177
170
        return tmpl.generate(self.ctx).render('xhtml', doctype='xhtml')
178
171