Source

hydra / apps / all_docs / updates / partial.py

Full commit
def update_doc(doc, req):
    http = require('lib/http')

    if not doc:
        resp = http['404']('partial update requires existed document', req)
        return [None, resp]

    data = {}
    if req.get('body'):
        content = require('lib/content')['provider']()
        data = content.decode(req)
        if not isinstance(data, dict):
            msg = 'body as object expected, got %r' % type(data)
            return [None, http['400'](msg, req)]

    for key in list(data):
        if key.startswith('_'):
            data.pop(key)

    require('lib/doc/version')['make_as_attachment'](doc)

    doc.update(data)

    require('lib/doc/meta')['sign'](doc, req)

    return [doc, http['201']({'status': 'ok', 'id': doc['_id']}, req)]