Ejemplo n.º 1
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))
Ejemplo n.º 2
0
 def __init__(self, _id=None, order_dict=None):
     """
     One of this filed required
     :param _id:        mongo _id of order document
     :param order_dict: dict with order data
     """
     if _id:
         if type(_id) == str:
             _id = ObjectId(_id)
         self.order = orders_table.find_one(
             {"_id": _id})
         # self.deleted = True if self.order else False
     if order_dict:
         self.order = order_dict
Ejemplo n.º 3
0
    def send_products_layout(self, update, context):
        per_page = conf["PRODUCTS_PER_PAGE"]
        # Take users reports from db
        all_data = products_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_products"]))
        # 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
        context.user_data['to_delete'].append(
            context.bot.send_message(update.callback_query.message.chat_id,
                                     strings["shop_title"].format(all_data.count()),
                                     parse_mode=ParseMode.MARKDOWN))
        # Products
        for product in data_to_send:
            # todo: fix this coz of repeating in template
            extra_string = ""
            kb = None
            if not product["sold"]:
                kb = InlineKeyboardMarkup(
                    [[InlineKeyboardButton(strings["make_order_btn"],
                                           callback_data=f"make_order/{product['_id']}")]])
            if orders_table.find_one(
                    {"user_id": update.effective_user.id,
                     "product_id": product["_id"],
                     "deleted_on_user_side": False}):
                extra_string += "\n\n_У вас уже есть заказ с данным товаром_"
                kb = None
            send_product_template(update, context, product, extra_string, kb)
        # 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))
Ejemplo n.º 4
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