def check_mark_value(id,mark,values,id_client,dish_id,text):
    if mark > 5:
        print('Max value is 5')
    else:
        row = Marks(id=id, mark_value=values,client_id = id_client,dish_id = dish_id,text_reviw = text)
        session.add(row)
        session.commit()
Esempio n. 2
0
def add_user_mark(mark, client_username, dish_name):

    if bool(session.query(Marks.id).filter_by(id='1').first()) is False:
        id_found = (session.query(Clients).filter(
            Clients.client_username == client_username).first()).id
        dish_id = (session.query(Dishes).filter(
            Dishes.dish_name == dish_name).first()).id

        row = Marks(id='1',
                    mark_value=mark,
                    client_id=id_found,
                    dish_id=dish_id,
                    user_name=client_username)
        session.add(row)
        session.commit()
        return 'Вы наш первый пользователь.Мы успешно добавили вашу первую оценку'

    elif bool(
            session.query(Marks).filter(
                Marks.user_name == client_username).first()) is True:
        session.query(Marks).filter(Marks.user_name == client_username).update(
            {Marks.mark_value: mark}, synchronize_session=False)
        session.commit()
        return 'Мы успешно обновили вашу оценку'
    else:
        id_found = (session.query(Clients).filter(
            Clients.client_username == client_username).one()).id
        dish_id = (session.query(Dishes).filter(
            Dishes.dish_name == dish_name).one()).id
        id_value = session.query(Marks.id).count()
        row = Marks(id=id_value + 1,
                    mark_value=mark,
                    client_id=id_found,
                    dish_id=dish_id,
                    user_name=client_username)
        session.add(row)
        session.commit()
        return 'Мы успешно добавили вашу оценку'