Esempio n. 1
0
    def get_intro_message(self):
        db = get_db()
        trip = db.query(Trip).get(self.data['show'])

        return BotMessage(
            text=self.get_text(trip),
            buttons=self.get_buttons()
        )
Esempio n. 2
0
    def _initialize_seat(self):
        db = get_db()

        last_purchase = db.query(Purchase).filter(
            Purchase.user_id == self.user.id
        ).order_by(Purchase.created_at.desc()).first()

        if last_purchase is None:
            return

        self.data['seat'] = last_purchase.seats
Esempio n. 3
0
    async def _answer_callback(cls, client, remote_user, bot_messages):
        sender = ViberSender(client)
        try:
            await sender.send_messages(remote_user, bot_messages)
        except:
            logger.exception(
                'Got exception during sending message to Viber server. Messages:\n%s',
                bot_messages)

            set_db(Session())
            try:
                user = UserService.get_by_viber_id(remote_user.id)
                messages = cls.handle_exception(user)
                get_db().commit()
                await sender.send_messages(remote_user, messages)
            except:
                logger.exception("Couldn't even reset the state.")

            finally:
                get_db().close()
Esempio n. 4
0
    def _initialize_station(self):
        db = get_db()
        trip = db.query(Trip).get(self.data['show'])

        last_purchase = db.query(Purchase).join(Trip, Car, Provider).filter(and_(
            Trip.direction == trip.direction,
            Purchase.user_id == self.user.id,
            Provider.id == trip.car.provider_id,
        )).first()
        if last_purchase is None:
            return

        self.data['station'] = last_purchase.station.id
        self.data['station_name'] = last_purchase.station.name
Esempio n. 5
0
 def add(cls, **kwargs):
     instance = cls.model(**kwargs)
     get_db().add(instance)
     return instance
Esempio n. 6
0
 def query(cls):
     return get_db().query(cls.model)
Esempio n. 7
0
    def db(self):
        if not self._db:
            self._db = get_db()

        return self._db