def action_view_POST(self, req, page): submit_mtime = int(req.params.get('mtime') or '0') or None if page.mtime != submit_mtime: return exc.HTTPPreconditionFailed( "The page has been updated since you started editing it") page.set(title=req.params['title'], content=req.params['content']) resp = exc.HTTPSeeOther(location=req.path_url) resp.set_cookie('message', 'Page updated') return resp
def action_view_POST(self, req, page): submit_mtime = int(req.params.get("mtime") or "0") or None if page.mtime != submit_mtime: return exc.HTTPPreconditionFailed( "The page has been updated since you started editing it") page.set(title=req.params["title"], content=req.params["content"]) resp = exc.HTTPSeeOther(location=req.path_url) resp.set_cookie("message", "Page updated") return resp
def code2exception(code, detail): """Transforms a code + detail into a WebOb exception""" if code == 400: return exc.HTTPBadRequest(detail) if code == 401: return exc.HTTPUnauthorized(detail) if code == 402: return exc.HTTPPaymentRequired(detail) if code == 403: return exc.HTTPForbidden(detail) if code == 404: return exc.HTTPNotFound(detail) if code == 405: return exc.HTTPMethodNotAllowed(detail) if code == 406: return exc.HTTPNotAcceptable(detail) if code == 407: return exc.HTTPProxyAuthenticationRequired(detail) if code == 408: return exc.HTTPRequestTimeout(detail) if code == 409: return exc.HTTPConflict(detail) if code == 410: return exc.HTTPGone(detail) if code == 411: return exc.HTTPLengthRequired(detail) if code == 412: return exc.HTTPPreconditionFailed(detail) if code == 413: return exc.HTTPRequestEntityTooLarge(detail) if code == 414: return exc.HTTPRequestURITooLong(detail) if code == 415: return exc.HTTPUnsupportedMediaType(detail) if code == 416: return exc.HTTPRequestRangeNotSatisfiable(detail) if code == 417: return exc.HTTPExpectationFailed(detail) if code == 500: return exc.HTTPInternalServerError(detail) if code == 501: return exc.HTTPNotImplemented(detail) if code == 502: return exc.HTTPBadGateway(detail) if code == 503: return exc.HTTPServiceUnavailable(detail) if code == 504: return exc.HTTPGatewayTimeout(detail) if code == 505: return exc.HTTPVersionNotSupported(detail) raise NotImplementedError(code)
def action_view_POST(self, req, page): submit_mtime = int(req.params.get('mtime') or '0') or None if page.mtime != submit_mtime: return exc.HTTPPreconditionFailed( "The page has been updated since you started editing it") # fields has to be modified below in page.set that user will submit while filling the query or edit page page.set( title=req.params['title'], content=req.params['content']) resp = exc.HTTPSeeOther( location=req.path_url) resp.set_cookie('message', 'Page updated') return resp
def post_data(request): """The client should keep track of the last time it sent updates to the server, and send updates when there are newer applications. **NOTE:** there is a case when an update might be lost because of an update from another device; this would be okay except that the client doesn't know it needs to re-send that update. How do we confirm that ? The updates are sent with:: POST /collections/{user}/{collection}?lastget=somedate {origin: {...}, ...} Each object must have a `last_modified` key. The response is only:: {received: timestamp} XXX if lastget (timestamp) was provided and the collection has been changed since that date, we send back a 412 Precondition Failed. """ user, collection, dbtoken = check_auth(request) server_time = round_time() storage = get_storage(request) if 'delete' in request.params: # we were asked to delete the collection try: info = request.json_body except ValueError: raise bad_request(INVALID_JSON) if 'client_id' not in info: raise bad_request(MISSING_VALUE) client_id = info['client_id'] reason = info.get('reason', '') storage.delete(user, collection, client_id, reason, token=dbtoken) return {'received': server_time} elif 'lastget' in request.params: last_get = round_time(float(request.params['lastget'])) last_modified = storage.get_last_modified(user, collection, token=dbtoken) if last_modified > last_get: raise exc.HTTPPreconditionFailed() try: apps = request.json_body except ValueError: raise bad_request(INVALID_JSON) # in case this fails, the error will get logged # and the user will get a 503 (empty body) storage.add_applications(user, collection, apps, token=dbtoken) return {'received': server_time}