def create(context, request): # parse JSON data from the request and create object try: values = json.decode(request.params.get("data", None), target_class=context.object_class) obj = context.object_class(**values) except: raise httpexceptions.HTTPBadRequest() manager = request.registry.getUtility(IObjectManager) manager.add(obj) return Created("%s/%s" % (request.url, ICollectable(obj).uuid))
def update(context, request): # parse JSON data from the request try: values = json.decode(request.params.get("data", None), context) except: raise httpexceptions.HTTPBadRequest() # drop uuid from values if "uuid" in values: values.pop("uuid") # iterate through schema and update fields for interface in context.__provides__.interfaces(): for name in getFieldNamesInOrder(interface): if name in values: field = interface[name].bind(context) field.validate(values[name]) field.set(context, values[name]) manager = request.registry.getUtility(IObjectManager) manager.update(context) return json.values(context)