Esempio n. 1
0
def getFile(_id):
    """
    Retrieve the data from the GenericFile collection
    for the given _id or db_ref

    Returns the data in Binary.  If you know it's a txt file and want a string,
    convert with str()

    Maybe this will be automatically deref'd most of the time?
    Only if they're mongoengine ReferenceFields...
    """

    try:
        _id = _id.id

    except AttributeError:
        pass

    f = GenericFile.objects(__raw__={'_id': _id})  # yes it's '_id' here but just 'id' below, gofigure
    return _try0_dict_key(f, 'file', 'id', _id, None,
                           dict_key='data')