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

« back to all changes in this revision

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

  • Committer: David Coles
  • Date: 2009-12-08 02:10:26 UTC
  • Revision ID: coles.david@gmail.com-20091208021026-3a27ecdzm49y39me
Configuration documentation - fixing a few references

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