示例#1
0
def handle_Unsale():
    god = Good.objects()
    for i in god:
        i.sale = i.saleSecond
        i.PriceWithSale = i.SecondSavePrice
        i.save()
    flash('Скидка для всех ботов вернулась', category='success')

    return redirect("/admin/bots")
示例#2
0
def handle_sale():
    form = SaleForm()
    if form.validate_on_submit():
        try:
            sale = int(form.sale.data)
            god = Good.objects()

            for i in god:
                saleFinal = i.sale
                i.sale = sale
                i.saleSecond = saleFinal
                i.PriceWithSale = str(
                    int(int(i.price) - (int(i.price) * (int(sale) / 100))))
                i.save()
            flash('Скидка применилась для всех ботов', category='success')
        except Exception as e:
            flash('Введены не правильные данные', category='danger')
    return render_template('sale.html', form=form)
示例#3
0
 def goods_state(self, message, entry=False):
     texts = self.get_texts()
     user = self.get_user(message)
     print("god")
     goods = group_by_name(Good.objects(city_id=str(user.city.id)))
     if self.botType == "fi":
         messId = message.chat.id
         keybd = keyboards2
     elif self.botType == "sec":
         messId = message.from_user.id
         keybd = keyboards
     else:
         messId = ""
         keybd = ""
     if entry:
         print("su1")
         self._bot.send_message(messId,
                                texts['choose_good_msg'],
                                reply_markup=keybd.set_keyboard(
                                    texts, goods.keys(), back_btn=True))
     else:
         print("su2")
         if self.botType == "fi":
             messText = message.text
         elif self.botType == "sec":
             messText = message.data
         else:
             messText = ""
         if messText == texts['back_btn']:
             self._go_to_state(message, self.cities_state)
         else:
             good = goods.get(messText)
             if good:
                 user.good = good
                 user.clicked_goods.append(good)
                 user.save()
                 self._go_to_state(message, self.districts_state)
             else:
                 self._bot.send_message(messId,
                                        texts['use_buttons_msg'],
                                        reply_markup=keybd.set_keyboard(
                                            texts,
                                            goods.keys(),
                                            back_btn=True))
示例#4
0
    def create_dub(self, bot_id, bot_2):
        try:
            telebot.TeleBot(bot_2).get_me()
        except Exception:
            return 'ERROR, go back'
        bot_2 = loads(
            BotProfile.objects(token=bot_2).first().to_json())['_id']['$oid']

        text = Texts.objects(bot_id=bot_id).first()

        if not (text is None):
            text_dict = loads(text.to_json())

            dub_text = {}

            for key in text_dict:
                if key != '_id':
                    dub_text.update({key: text_dict[key]})

            dub_text['bot_id'] = bot_2

            new_text = Texts(**dub_text)
            new_text.save()

        cities = City.objects(bot_id=bot_id)

        if cities is not None:
            for city in cities:
                if not (city is None):
                    city_dict = loads(city.to_json())

                    dub_city = {}

                    for key in city_dict:
                        if key != '_id':
                            dub_city.update({key: city_dict[key]})

                    dub_city['bot_id'] = bot_2

                    new_city = City(**dub_city)
                    new_city.save()
                    goods = Good.objects(city_id=city.id.binary.hex())

                    for good in goods:
                        if good is not None:
                            Good(name=good.name,
                                 city_id=new_city.id.binary.hex(),
                                 price=good.price,
                                 description=good.description,
                                 photo=good.photo,
                                 districts=good.districts).save()

        payment = Payment.objects(bot_id=bot_id).first()

        if not (payment is None):
            payment_dict = loads(payment.to_json())

            dub_payment = {}

            for key in payment_dict:
                if key != '_id':
                    dub_payment.update({key: payment_dict[key]})

            dub_payment['bot_id'] = bot_2

            new_payment = Payment(**dub_payment)
            new_payment.save()
        return str(bot_2)