def search_categories(query): query = query.lower().strip() categories = Category.select().where( (fn.lower(Category.name).contains(query)) | (fn.lower(Category.extra).contains(query)) ) return categories
def get_categorys(self): categorys = self.memcachedb.get('categorys') if not categorys: categorys = [category for category in Category.select()] self.memcachedb.set('categorys', categorys, 86400) return categorys
def get_categorys(self): categorys = self.session.get('categorys') if not categorys: categorys = [category for category in Category.select()] self.session.set('categorys', categorys, 86400) return categorys
def _select_category_buttons(callback_action=None): if callback_action is None: # set default callback_action = CallbackActions.SELECT_BOT_FROM_CATEGORY categories = Category.select().order_by(Category.name.asc()).execute() buttons = util.build_menu([InlineKeyboardButton( '{}{}'.format(emoji.emojize(c.emojis, use_aliases=True), c.name), callback_data=util.callback_for_action( callback_action, {'id': c.id})) for c in categories], 2) buttons.insert(0, [InlineKeyboardButton( '🆕 New Bots', callback_data=util.callback_for_action(CallbackActions.NEW_BOTS_SELECTED))]) return buttons
def edit_bot_category(bot, update, for_bot, callback_action=None): if callback_action is None: callback_action = CallbackActions.EDIT_BOT_CAT_SELECTED uid = util.uid_from_update(update) categories = Category.select().order_by(Category.name.asc()).execute() buttons = util.build_menu([ InlineKeyboardButton( '{}{}'.format(emoji.emojize(c.emojis, use_aliases=True), c.name), callback_data=util.callback_for_action(callback_action, { 'cid': c.id, 'bid': for_bot.id })) for c in categories ], 2) return bot.formatter.send_or_edit( uid, util.action_hint("Please select a category" + (" for {}".format(for_bot) if for_bot else '')), to_edit=util.mid_from_update(update), reply_markup=InlineKeyboardMarkup(buttons))
if cattext: name = cattext + ' | ' + title else: name = title cat_names[node_id] = name for subnode in subnodes: node.append(nodes[subnode]) subtree(subnode, name) custom_order = peewee.Case(CategoryLang.id_lang, [ (LANG_ID, 100), (0, 99), ], -1000) for category in Category.select(Category, CategoryLang.name, peewee.fn.max(custom_order)).join(CategoryLang, on = (Category.id_category == CategoryLang.id_category)) \ .where(CategoryLang.id_lang == LANG_ID and \ CategoryLang.id_shop == SHOP_ID).group_by(Category.id_category).dicts(): #print(category) node = Element("ITEM") node_id = category['id_category'] i = SubElement(node, "URL") i.text = CATEGORY_URL_TEMPLATE.format(id_category = category['id_category']) i = SubElement(node, "TITLE") i.text = category['name'] subcats[category['id_parent']].append(node_id) nodes[node_id] = node if category['is_root_category']: if root_id is None: root_id = category['id_category']