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

« back to all changes in this revision

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

ivle.webapp.errors: Add, with a base HTTPError and BadRequest, FileNotFound
    and Forbidden errors.

ivle.webapp.base.views#JSONRESTView: Implement the X-IVLE-Patch-Semantics flag,
    the PATCH method, and raise a BadRequest on an unknown method.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
import cjson
21
21
 
 
22
from ivle.webapp.errors import BadRequest
 
23
 
22
24
class BaseView(object):
23
25
    """
24
26
    Abstract base class for all view objects.
56
58
    def render(self, req):
57
59
        if req.method == 'GET':
58
60
            outjson = self.GET(req)
59
 
        # XXX PATCH hack
60
 
        if req.method == 'PUT':
 
61
        elif req.method == 'PATCH' or (req.method == 'PUT' and
 
62
              'X-IVLE-Patch-Semantics' in req.headers_in and
 
63
              req.headers_in['X-IVLE-Patch-Semantics'].lower() == 'yes'):
61
64
            outjson = self.PATCH(req, cjson.decode(req.read()))
 
65
        elif req.method == 'PUT':
 
66
            outjson = self.PUT(req, cjson.decode(req.read()))
 
67
        else:
 
68
            raise BadRequest
62
69
        req.content_type = self.content_type
63
70
        if outjson is not None:
64
71
            req.write(cjson.encode(outjson))