def get_all_for_sets(sets): def fetch_parts(): parts = {"total_count": 0, "parts": {}} for s in sets: set_parts = s.get_inventory().inventory_parts for sp in set_parts: part_num = sp.part.part_num if part_num not in parts["parts"]: parts["parts"][part_num] = { "part": sp.part, "count": 0, "display": 0, "storage": 0, "colors": {} } parts["parts"][part_num]["count"] += sp.quantity display_key = "display" if s.is_on_display() else "storage" parts["parts"][part_num][display_key] += sp.quantity color_id = str(sp.color_id) if color_id not in parts["parts"][part_num]["colors"]: parts["parts"][part_num]["colors"][color_id] = { "display": 0, "storage": 0 } parts["parts"][part_num]["colors"][color_id][ display_key] += sp.quantity parts["total_count"] += sp.quantity return parts return cache.remember("parts", "all_for_my_sets", fetch_parts)
def for_inventory_id(inventory_id): def create(): results = db_conn.query(query_by_inventory_id, {"inventory_id": inventory_id}) return Inventory([InventoryPart(r, Part(r)) for r in results]) return cache.remember("inventory_part_list", inventory_id, create)
def get_all_my_sets_containing_part(part_num, color): def fetch(): return [ Set(row) for row in db_conn.query(query_all_my_sets_containing_part, { "part_num": part_num, "color_id": color }) ] return cache.remember('my_sets_containing_part', '%s:%s' % (part_num, color), fetch)
def from_id(id): def create(): return Color(db_conn.query_one(query_by_id, {'id': id})) return cache.remember('color', id, create)
def get_all_my_sets(): def fetch(): return [Set(row) for row in db_conn.query(query_all_my_sets)] return cache.remember('my_sets', 'all', fetch)
def from_set_num(set_num): def create(): return Set(db_conn.query_one(query_by_id, {"set_num": set_num})) return cache.remember("set", set_num, create)
def get_all_categories(): def create(): results = db_conn.query(query_all_part_categories) return [PartCategory(r) for r in results] return cache.remember("part_category", "all", create)
def get_all_for_category_id(category_id): def create(): results = db_conn.query(query_by_category_id, {"cat_id": category_id}) return [Part(r) for r in results] return cache.remember("category_part_list", category_id, create)
def category_from_id(id): def create(): return PartCategory(db_conn.query_one(query_category_by_id, {"id": id})) return cache.remember("part_category", id, create)
def from_id(id): def create(): return Theme(db_conn.query_one(query_by_id, {"id": id})) return cache.remember("theme", id, create)