示例#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)
示例#2
0
def _spawn_items(pl):
    items_to_cr8 = [loremipsum.sentence(30) for _ in range(choice(range(10, 20)))]
    all_items = []
    for item_name in items_to_cr8:
        i = Item()
        i.name = item_name
        i.description = loremipsum.paragraph()
        i.price = choice(range(1, 100))
        i.container_id = container_from_path(pl)._id
        i._id = i.save()
        all_items += [i]
    return all_items
示例#3
0
def _spawn_items_containers(pl):
    containers_to_cr8 = [loremipsum.sentence(30) for _ in range(choice(range(1, 3)))]
    all_pl = map(lambda x: pl + [x], containers_to_cr8)
    items_to_cr8 = [loremipsum.sentence(30) for _ in range(choice(range(5, 10)))]

    for item_name in items_to_cr8:
        i = Item()
        i.name = item_name
        i.description = loremipsum.paragraph()
        i.price = choice(range(1, 100))
        i.container_id = container_from_path(pl)._id
        i.save()
    for container_pl_to_cr8 in all_pl:
        save_container_path(container_pl_to_cr8)
    return all_pl