Пример #1
0
def on_patch(resc, req, resp, rid):
    """ Deserialize the payload & update the single item """

    signals.pre_req.send(resc.model)
    signals.pre_req_update.send(resc.model)

    props = req.deserialize()
    model = find(resc.model, rid)

    from_rest(model, props)
    goldman.sess.store.update(model)

    props = to_rest_model(model, includes=req.includes)
    resp.last_modified = model.updated
    resp.serialize(props)

    signals.post_req.send(resc.model)
    signals.post_req_update.send(resc.model)
Пример #2
0
def on_post(resc, req, resp):
    """ Deserialize the payload & create the new single item """

    signals.pre_req.send(resc.model)
    signals.pre_req_create.send(resc.model)

    props = req.deserialize()
    model = resc.model()

    from_rest(model, props)
    goldman.sess.store.create(model)

    props = to_rest_model(model, includes=req.includes)
    resp.last_modified = model.updated
    resp.location = '%s/%s' % (req.path, model.rid_value)
    resp.status = falcon.HTTP_201
    resp.serialize(props)

    signals.post_req.send(resc.model)
    signals.post_req_create.send(resc.model)