def post(self, request): """Create/Edit items.""" form = yield from self.get_form(request) if not form.validate(): raise muffin.HTTPBadRequest( text=json.dumps(form.errors), content_type='application/json') yield from self.save_form(form, request) raise muffin.HTTPFound(self.url)
def post(self, request): """ Create a resource. """ form = yield from self.get_form(request) if not form.validate(): raise muffin.HTTPBadRequest( text=json.dumps(form.errors), content_type='application/json') resource = yield from self.save_form(form, request) return self.to_simple(resource)
def put(self, request, **resources): """ Update a resource. """ resource = resources.get(self.name) if not resource: raise muffin.HTTPNotFound('Resource not found') form = yield from self.get_form(request, **resources) if not form.validate(): raise muffin.HTTPBadRequest( text=json.dumps(form.errors), content_type='application/json') resource = yield from self.save_form(form, request, **resources) return self.to_simple(resource)
def raise_400(request): raise muffin.HTTPBadRequest()