Beispiel #1
0
def check_user_ignore(update):
    user_id = update.message.from_user.id
    with db_session:
        query = User.select(lambda p: p.tg_user_id == user_id)

        if not list(query):
            return False
        user = list(query)
        if user[0].tg_user_ignore is True:
            return True
        return False
Beispiel #2
0
def insert_user_by_update(update):
    with db_session:
        user_id = update.message.from_user.id
        query = User.select(lambda p: p.tg_user_id == user_id)
        if not list(query):
            User(tg_user_id=update.message.from_user.id,
                 tg_user_username=update.message.from_user.username,
                 tg_user_nickname="{} {}".format(
                     update.message.from_user.first_name,
                     "" if not update.message.from_user.last_name else
                     update.message.from_user.last_name),
                 tg_user_ignore=0)
            commit()
def get_coupon_state():
    """
    get a list of all users and their bookings and remaining coupons
    """
    ret = []
    for user in User.select():
        bookings = Booking.select().where(
            user.user_name == Booking.booked_by)
        ret.append({
            "name": user.user_name,
            "num_bookings": len(bookings),
            "coupons": user.coupons
        })
    return ret
Beispiel #4
0
def get_users():
    """
    SELECT u.user_name, u.coupons, COUNT(b.id)
    FROM "user" u
    JOIN booking b ON b.booked_by = u.user_name
    GROUP BY u.user_name, u.coupons
    """
    users = User.select().where(User.role != UserRoles.ANON).order_by(User.role.desc(), User.user_name)
    return [{
        "user_name": user.user_name,
        "is_admin": user.role == UserRoles.ADMIN,
        "total_bookings": len(Booking.select().where(
            user.user_name == Booking.booked_by)),
        "coupons": user.coupons
    } for user in users]
def get_coupon_state():
    """
    SELECT u.user_name, u.coupons, COUNT(b.id)
    FROM "user" u
    JOIN booking b ON b.booked_by = u.user_name
    GROUP BY u.user_name, u.coupons
    """
    ret = []
    for user in User.select():
        bookings = Booking.select().where(user.user_name == Booking.booked_by)
        ret.append({
            "name": user.user_name,
            "num_bookings": len(bookings),
            "coupons": user.coupons
        })
    return ret
Beispiel #6
0
def check_user_in_db(user_id):
    with db_session:
        query = User.select(lambda p: p.tg_user_id == user_id)
        if not list(query):
            return False
        return True