예제 #1
0
 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)
예제 #2
0
 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)
예제 #3
0
    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)
예제 #4
0
 def raise_400(request):
     raise muffin.HTTPBadRequest()