def showcase(): #get menu items menu_path = ["Menu", "Food", "Mains"] all_items = items.get_all(items.container_from_path(menu_path)) return render_template("showcase.html", **{ "items": all_items, })
def warnings(min_qty): """ Return items that are <= min_qty """ warning_items = [] for c in all_inventorized_containers(): items = items.get_all(c) for i in items: if hasattr(i, "quantity") and i.quantity <= min_qty: warning_items += [i] return warning_items
def get(): """ Returns a populated `OrgInfo` object """ org_info = OrgInfo() container_obj = __get_or_create_org_container() all_org_items = items.get_all(container_obj) for k, v in vars(OrgInfo).items(): if k[:2] != "__": #not a private attr attr_name = getattr(OrgInfo, k) item = __has_item(all_org_items, attr_name) if item: setattr(org_info, attr_name, item.description) return org_info
def get_containers_and_items(): """ (GET: container+item) Fetches the immediate child containers of a path, as well as the items in the specified container. """ path_lis_json_str = request.args.get("path_lis") path_lis = json.loads(path_lis_json_str) if path_lis_json_str is not None else None container_obj = items.container_from_path(path_lis) all_items = items.get_all(container_obj) all_child_containers = items.child_containers(container_obj) return jsonify({ "status": "ok", "description": container_obj.description if container_obj is not None else None, "items": [x.serialize(json_friendly=True) for x in all_items], "child_containers": [x.serialize(json_friendly=True) for x in all_child_containers] })
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)
def get_published_articles(limit=3): articles = items.get_all(__container_obj(), find_param_lis=[ {"publish_datetime": {"$lt": datetime.datetime.utcnow()}} ], limit=limit) return articles