コード例 #1
0
ファイル: mock.py プロジェクト: nubela/unifide-plop
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
コード例 #2
0
ファイル: items.py プロジェクト: nubela/unifide-backend
def put_container():
    """
    (PUT: container)
    """
    path_lis_json = request.form.get("path_lis")
    description = request.form.get("description", None)
    path_lis = json.loads(path_lis_json)
    container_obj = items.save_container_path(path_lis)
    container_obj.description = description
    items.save_container(container_obj)
    return jsonify({
        "status": "ok",
    })
コード例 #3
0
ファイル: mock.py プロジェクト: nubela/unifide-plop
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
コード例 #4
0
ファイル: mock.py プロジェクト: nubela/unifide-plop
def gen_model(model, existing_path_lis=None):
    if existing_path_lis is None: existing_path_lis = []

    if Generate.ITEMS_CONTAINERS == model:
        max_depth = choice(range(1, 3))
        to_gen = _spawn_items_containers(existing_path_lis)
        for g in to_gen:
            depth = len(g) - len(existing_path_lis)
            if depth > max_depth: break
            to_gen += _spawn_items_containers(g)
        return

    for container_name, attr_dic in model.items():
        #save container
        path_lis = existing_path_lis + [container_name]

        #only create if container doesnt already exists
        if items.container_from_path(path_lis) is None:
            container_obj = save_container_path(path_lis)
            if ContainerAttr.DESCRIPTION in model: container_obj.description = model[ContainerAttr.DESCRIPTION]
            container_obj.save()

            #create items
            if "items" in model:
                for item in model["items"]:
                    custom_type = item["custom"] if "custom" in item else None
                    if custom_type is None:
                        i = Item(**{item})
                        i.container_id = container_from_path(existing_path_lis)
                        i.save()
                    elif custom_type == Generate.ITEMS_ONLY:
                        all_items = _spawn_items(existing_path_lis)
                        custom_attr = item["custom_attr"] if "custom_attr" in item else {}
                        for k, v in custom_attr:
                            for new_item in all_items:
                                setattr(new_item, k, v)
                        map(lambda x: x.save(), all_items)

        #gen recursive models
        if "containers" in attr_dic:
            gen_model(attr_dic["containers"], path_lis)
コード例 #5
0
ファイル: mock.py プロジェクト: nubela/unifide-plop
def gen_article_path():
    save_container_path(ARTICLE_PATH)
コード例 #6
0
ファイル: action.py プロジェクト: nubela/unifide-plop
def __get_or_create_org_container():
    container_obj = items.container_from_path(ORG_PATH)
    if container_obj is None:
        items.save_container_path([ORG_PATH])
        container_obj = items.container_from_path(ORG_PATH)
    return container_obj