예제 #1
0
 def make_order(self, update: Update, context: CallbackContext):
     delete_messages(update, context)
     context.user_data["order"] = products_table.find_one(
         {'_id': ObjectId(update.callback_query.data.split('/')[1])})
     send_product_template(update, context, context.user_data["order"],
                           strings["confirm_order"], keyboards["confirm_order_kb"])
     return CONFIRM_ORDER
예제 #2
0
 def confirm_delete_product(self, update: Update, context: CallbackContext):
     delete_messages(update, context)
     context.user_data["product"] = products_table.find_one(
         {"_id": ObjectId(update.callback_query.data.split('/')[1])})
     send_product_template(update, context, context.user_data["product"],
                           strings["confirm_delete"],
                           keyboards["confirm_delete_product"])
     return CONFIRM_DELETE_PRODUCT
예제 #3
0
 def new_product(update, context, _id):
     extra_str = f"\n\n{strings['success_adding']}"
     product = products_table.find_one({"_id": _id})
     for chat_id in conf["ADMINS"]:
         context.bot.send_photo(chat_id if chat_id else update.effective_chat.id,
                                product["image_id"],
                                product_template(product) + extra_str,
                                parse_mode=ParseMode.MARKDOWN)
예제 #4
0
    def send_orders_layout(self, update, context, choose_kb=False):
        per_page = conf["ORDERS_PER_PAGE"]
        # Take users reports from db
        all_data = orders_table.find().sort([["_id", -1]])
        # if no documents - send notification message
        if all_data.count() == 0:
            context.user_data["to_delete"].append(
                context.bot.send_message(update.effective_chat.id,
                                         strings["no_orders"]))
        # if page is first - take first n items
        if context.user_data["page"] == 1:
            data_to_send = all_data.limit(per_page)
        # if page is not first - take items on given page
        else:
            last_on_prev_page = (context.user_data["page"] - 1) * per_page
            data_to_send = [
                i for i in all_data[last_on_prev_page:last_on_prev_page +
                                    per_page]
            ]

        # SENDING DATA
        # Title
        title = f"{strings['select_buyer_title']}" \
                f"\n{product_template(context.user_data['product'])}" \
            if choose_kb else strings["orders_title"].format(all_data.count())
        context.user_data['to_delete'].append(
            context.bot.send_message(update.callback_query.message.chat_id,
                                     title,
                                     parse_mode=ParseMode.MARKDOWN))
        # Orders
        for order in data_to_send:
            # orders_table.find({})
            # kb = [[InlineKeyboardButton(strings["mark_as_completed_btn"],
            #                             callback_data=f"mark_as_completed/{order['_id']}")]]
            # if order["deleted_on_user_side"]:
            #     kb = [[InlineKeyboardButton(strings["delete_order_btn"],
            #                                 callback_data=f"delete_order/{order['_id']}")]]
            kb = None
            if choose_kb:
                Order(order_dict=order).send_short_template(update, context)
            else:
                product = products_table.find_one({"_id": order["product_id"]})
                context.user_data['to_delete'].append(
                    context.bot.send_photo(update.effective_chat.id,
                                           product["image_id"],
                                           admin_order_template(
                                               order, product),
                                           reply_markup=kb,
                                           parse_mode=ParseMode.MARKDOWN))
        # Pages navigation
        context.user_data['to_delete'].append(
            context.bot.send_message(
                update.effective_chat.id,
                strings["current_page"].format(context.user_data['page']),
                reply_markup=self.pagin(context, all_data, self.back_button,
                                        per_page),
                parse_mode=ParseMode.MARKDOWN))
예제 #5
0
    def send_user_template(self, update, context):

        product = products_table.find_one({"_id": self.order["product_id"]})

        context.user_data["to_delete"].append(
            context.bot.send_photo(update.effective_chat.id,
                                   product["image_id"],
    #                                order_template(order, product) + extra_str,
    #                                reply_markup=kb,
                                   parse_mode=ParseMode.MARKDOWN))
예제 #6
0
def send_user_order_template(update, context, order_id, extra_str="", kb=None):
    if type(order_id) == str:
        order_id = ObjectId(order_id)
    order = orders_table.find_one({"_id": order_id})
    product = products_table.find_one({"_id": order["product_id"]})
    context.user_data["to_delete"].append(
        context.bot.send_photo(update.effective_chat.id,
                               product["image_id"],
                               order_template(order, product) + extra_str,
                               reply_markup=kb,
                               parse_mode=ParseMode.MARKDOWN))
예제 #7
0
 def send_user_template(self, update, context, kb=None):
     order_status = "😘 Продан Вам" if self.order[
         "status"] else "⚠ В ожидании ️"
     product = products_table.find_one({"_id": self.order["product_id"]})
     if not product:
         context.user_data["to_delete"].append()
     context.user_data["to_delete"].append(
         context.bot.send_photo(
             update.effective_chat.id,
             product["image_id"],
             Product().template(product) + strings["order_template"].format(
                 str(self.order['creation_timestamp']).split('.')[0],
                 order_status),
             reply_markup=kb,
             parse_mode=ParseMode.MARKDOWN))
예제 #8
0
 def choose_buyer(self, update: Update, context: CallbackContext):
     delete_messages(update, context)
     if update.callback_query.data.startswith("mark_as_sold"):
         context.user_data["product"] = products_table.find_one(
             {"_id": ObjectId(update.callback_query.data.split('/')[1])})
     try:
         context.user_data['page'] = int(update.callback_query.data)
     except ValueError:
         if update.callback_query.data == 'all_orders':
             context.user_data['page'] = 1
     context.user_data["extra_pagin_btn"] = [[
         InlineKeyboardButton(strings["not_telegram_client_btn"],
                              callback_data="set_not_telegram_buyer")
     ]]
     self.send_orders_layout(update, context, choose_kb=True)
     return CHOOSE_BUYER
예제 #9
0
    def confirm_delete_order(self, update: Update, context: CallbackContext):
        delete_messages(update, context)
        context.user_data["order"] = orders_table.find_one(
            {"_id": ObjectId(update.callback_query.data.split('/')[1])})
        product = products_table.find_one(
            {"_id": context.user_data["order"]["product_id"]})
        # todo
        # if context.user_data["order"] and product:
        #     pass
        # else:
        #     "ваш заказ уже удалён потому что товар был продан или удалён"

        context.user_data["to_delete"].append(
            context.bot.send_photo(update.effective_chat.id,
                                   context.user_data["order"]["product_object"]["image_id"],
                                   order_template(context.user_data["order"], product) +
                                   strings["delete_order"],
                                   reply_markup=keyboards["confirm_delete_order"],
                                   parse_mode=ParseMode.MARKDOWN))
        return CONFIRM_DELETE_ORDER
예제 #10
0
 def new_order(update, context, _id):
     extra_str = strings["new_order_notification"]
     product = products_table.find_one({"_id": _id})
     for chat_id in conf["ADMINS"]:
         send_product_template(update, context, product, extra_str, chat_id=chat_id)