Esempio n. 1
0
def patch(request):
    """Updates an existing record."""
    model_id = request.matchdict['model_id']
    record_id = request.matchdict['record_id']

    if request.user:
        username = request.user['name']
    else:
        username = Everyone

    try:
        data = request.db.get_record(model_id, record_id)
    except RecordNotFound:
        request.response.status = "404 Not Found"
        return {"msg": "%s: record not found %s" % (model_id, record_id)}

    data.update(json.loads(request.body.decode('utf-8')))
    definition = request.db.get_model_definition(model_id)
    validate_against_schema(request, RecordValidator(definition), data)
    if not request.errors:
        request.db.put_record(model_id, data, [username], record_id)
    return {'id': record_id}
Esempio n. 2
0
def patch(request):
    """Updates an existing record."""
    model_id = request.matchdict['model_id']
    record_id = request.matchdict['record_id']

    if request.credentials_id:
        credentials_id = request.credentials_id
    else:
        credentials_id = Everyone

    try:
        record = request.db.get_record(model_id, record_id)
    except RecordNotFound:
        request.errors.add('path', record_id, "record not found")
        request.errors.status = "404 Not Found"
        return

    record.update(json.loads(request.body.decode('utf-8')))
    definition = request.db.get_model_definition(model_id)
    validate_against_schema(request, RecordSchema(definition), record)
    if not request.errors:
        request.db.put_record(model_id, record, [credentials_id], record_id)
        request.notify('RecordUpdated', model_id, record_id)
    return {'id': record_id}
Esempio n. 3
0
def patch(request):
    """Updates an existing record."""
    model_id = request.matchdict['model_id']
    record_id = request.matchdict['record_id']

    if request.credentials_id:
        credentials_id = request.credentials_id
    else:
        credentials_id = Everyone

    try:
        record = request.db.get_record(model_id, record_id)
    except RecordNotFound:
        request.errors.add('path', record_id, "record not found")
        request.errors.status = "404 Not Found"
        return

    record.update(json.loads(request.body.decode('utf-8')))
    definition = request.db.get_model_definition(model_id)
    validate_against_schema(request, RecordSchema(definition), record)
    if not request.errors:
        request.db.put_record(model_id, record, [credentials_id], record_id)
        request.notify('RecordUpdated', model_id, record_id)
    return {'id': record_id}