Пример #1
0
def clear(obj):
    """
    Clear an object of tags

    :param obj:
    :return:
    """
    id = obj._id
    coll_name = obj.__class__.coll_name()
    Tag.collection().remove({
        "coll_name": coll_name,
        "obj_id": id,
    })
Пример #2
0
def get_tags(obj):
    """
    Get all tags that an object is tagged with

    :param obj:
    :return list of tags:
    """
    id = obj._id
    coll_name = obj.__class__.coll_name()
    lis = Tag.collection().find({
        "coll_name": coll_name,
        "obj_id": id,
    })
    return [Tag.unserialize(dic) for dic in lis]
Пример #3
0
def get_all(obj_cls, tag_name):
    """
    Gets a list of objects from a object class that is tagged with the provided tag_name

    :return list of objects:
    """
    all_tag_objs = Tag.collection().find({
        "coll_name": obj_cls.coll_name(),
        "tag": tag_name,
    })

    all_obj_ids = map(lambda x: x["obj_id"], all_tag_objs)
    all_objs = obj_cls.collection().find({
        "_id": {
            "$in": [all_obj_ids]
        }
    })
    return map(lambda x: obj_cls.unserialize(x), all_objs)
Пример #4
0
def save(tag_obj):
    return Tag.collection().save(tag_obj.serialize())