Beispiel #1
0
def json_object_hook_handler(obj):
    obj_data = obj.get('$obj')
    if obj_data:
        object_type, obj_data = obj_data
        if object_type == 'oid':
            return ObjectId(obj_data)
        elif object_type == 'date':
            return datetime.datetime.fromtimestamp(obj_data / 1000.,
                                                   bson.tz_util.utc)
    return obj
Beispiel #2
0
def json_opt_oid(key):
    val = flask.request.json.get(key)
    return None if val is None else ObjectId(val)
Beispiel #3
0
def json_oid(key):
    return ObjectId(flask.request.json[key])