Ejemplo n.º 1
0
def new_item(container_obj, custom_attr, custom_media, custom_tags, description, file_media_map, media_obj, name, price,
             quantity, status, group_id):
    item_obj = Item()
    item_obj.name = name
    item_obj.description = description
    item_obj.quantity = quantity
    item_obj.price = price
    item_obj.container_id = container_obj.obj_id()
    item_obj.status = status
    item_obj.custom_attr_lis = custom_attr
    item_obj.custom_media_lis = custom_media
    item_obj.media_id = media_obj.obj_id() if request.form.get("media_file", None) is not None else None
    if group_id:
        item_obj.group_id = group_id
    for k, v in file_media_map.items():
        if k == "media_file": continue
        if hasattr(item_obj, k): continue
        setattr(item_obj, k, v.obj_id() if v is not None else None)
    for k in custom_attr:
        if hasattr(item_obj, k): continue
        setattr(item_obj, k, request.form.get(k, None))

    #save it
    item_obj._id = items.save(item_obj)

    #tag it
    for tag_name in custom_tags:
        tags.tag(item_obj, tag_name)
Ejemplo n.º 2
0
def save(org_info_obj):
    """
    Saves `OrgInfo` object
    """
    container_obj = __get_or_create_org_container()
    all_org_items = items.get_all(items.container_from_path(ORG_PATH))
    for k, v in vars(org_info_obj).items():
        existing_item = __has_item(all_org_items, k)
        if existing_item:
            if existing_item.description != v:
                existing_item.description = v
                items.save(existing_item)
        else:
            container_obj = items.container_from_path(ORG_PATH)
            item_obj = Item.unserialize({
                "name": k,
                "description": v,
                "container_id": container_obj.obj_id(),
            })
            items.save(item_obj)
Ejemplo n.º 3
0
def update_item(custom_attr, custom_media, custom_tags, description, file_media_map, name, obj_id, price, quantity):
    item_obj = items.get(obj_id)
    item_obj.name = name
    item_obj.description = description
    item_obj.price = price
    item_obj.quantity = quantity
    item_obj.custom_attr_lis = custom_attr
    item_obj.custom_media_lis = custom_media

    item_obj.media_id = file_media_map["media_file"].obj_id() if request.form.get("media_file", None) is not None else item_obj.media_id
    for k, v in file_media_map.items():
        if k == "media_file": continue
        if v is not None:
            setattr(item_obj, k, v.obj_id())

    for k in custom_attr:
        setattr(item_obj, k, request.form.get(k, None))
    items.save(item_obj)
    #remove all tags
    tags.clear(item_obj)
    #tag it
    for tag_name in custom_tags:
        tags.tag(item_obj, tag_name)
Ejemplo n.º 4
0
def gen_items(total_items=5):
    container_obj = items.container_from_path(GEN_ITEM_PATH_LIS)
    if container_obj is None:
        container_obj = items.save_container_path(GEN_ITEM_PATH_LIS)

    item_lis = []
    for _ in range(total_items):
        dic = {
            "name": loremipsum.sentence(max_char=choice(range(10, 20))),
            "media": None,
            "description": loremipsum.paragraph(max_char=choice(range(40, 100))),
            "quantity": choice(range(1, 20)),
            "price": choice(range(1, 20)),
            "container_id": container_obj.obj_id(),
        }
        item_obj = items.Item.unserialize(dic)
        item_obj._id = items.save(item_obj)
        item_lis += [item_obj]

    return item_lis