def delete(self, method_id):
     abort_if_method_not_found(method_id)
     session = db_session.create_session()
     method = session.query(Methods).get(method_id)
     session.delete(method)
     session.commit()
     return jsonify({'success': 'OK'})
 def delete(self, save_lesson_id):
     abort_if_save_lesson_not_found(save_lesson_id)
     session = db_session.create_session()
     save_lesson = session.query(SaveLesson).get(save_lesson_id)
     session.delete(save_lesson)
     session.commit()
     return jsonify({'success': 'OK'})
 def post(self):
     args = parser.parse_args()
     session = db_session.create_session()
     save_lesson = SaveLesson(
         name=args['name'],
         ids=args['ids'],
         id_user=args['id_user'],
     )
     session.add(save_lesson)
     session.commit()
     return jsonify({'success': 'OK'})
Exemple #4
0
 def post(self):
     args = parser.parse_args()
     session = db_session.create_session()
     user = User(name_user=args['name_user'],
                 email=args['email'],
                 save_lesson=[],
                 methods_id=[])
     user.set_password(args['password'])
     session.add(user)
     session.commit()
     return jsonify({'success': 'OK'})
 def get(self, save_lesson_id):
     abort_if_save_lesson_not_found(save_lesson_id)
     session = db_session.create_session()
     save_lesson = session.query(SaveLesson).get(save_lesson_id)
     return jsonify({
         'save_lesson':
         save_lesson.to_dict(only=(
             'name',
             'ids',
             'id_user',
         ))
     })
 def get(self):
     session = db_session.create_session()
     save_lessons = session.query(SaveLesson).all()
     return jsonify({
         'categories': [
             item.to_dict(only=(
                 'name',
                 'ids',
                 'id_user',
             )) for item in save_lessons
         ]
     })
Exemple #7
0
 def get(self, user_id):
     abort_if_user_not_found(user_id)
     session = db_session.create_session()
     user = session.query(User).get(user_id)
     return jsonify({
         'user': {
             'name_user': user.name_user,
             'email': user.email,
             'save_lesson': user.save_lesson,
             "methods_id": [method.id for method in user.methods]
         }
     })
Exemple #8
0
def reqister():
    form = RegisterForm()
    if form.validate_on_submit():
        if form.password.data != form.password_again.data:
            return render_template('register.html',
                                   title='Регистрация',
                                   form=form,
                                   message="Пароли не совпадают")
        db_sess = db_session.create_session()
        if db_sess.query(User).filter(User.email == form.email.data).first():
            return render_template('register.html',
                                   title='Регистрация',
                                   form=form,
                                   message="Такой пользователь уже есть")
        ans = Handler.register(form.name.data, form.email.data,
                               form.password.data)
        if ans == "0":
            return redirect('/login')
    return render_template('register.html', title='Регистрация', form=form)
Exemple #9
0
def menu():
    db_sess = db_session.create_session()
    menu = dict()
    for category in db_sess.query(Categories).all():
        menu[category.name] = []
        for dish in category.dishes:
            if dish.is_sale:
                dish_dict = dict()
                dish_dict['name'] = dish.name
                if dish.add_info:
                    dish_dict['add_info'] = dish.add_info
                dish_dict['proportions'] = []
                for version in dish.versions:
                    dish_dict['proportions'].append({
                        'size': version.size,
                        'price': version.price
                    })
                if dish_dict['proportions']:
                    menu[category.name].append(dish_dict)
        if not menu[category.name]:
            menu.pop(category.name)
    return jsonify(menu)
 def post(self):
     args = parser.parse_args()
     session = db_session.create_session()
     method = Methods(
         name_method=args['name_method'],
         time=args['time'],
         id_user=args['id_user'],
         id_classes_number=args['id_classes_number'],
         id_type_method=args['id_type_method'],
         id_stage_method=args['id_stage_method'],
         id_fgos=args['id_fgos'],
         creative_thinking=args['creative_thinking'],
         critical_thinking=args['critical_thinking'],
         communication=args['communication'],
         cooperation=args['cooperation'],
         metacognitive_skills=args['metacognitive_skills'],
         literacy=args['literacy'],
         is_local=args['is_local'],
         text=args['text'],
     )
     session.add(method)
     session.commit()
     return jsonify({'success': 'OK'})
 def get(self):
     session = db_session.create_session()
     methods = session.query(Methods).all()
     return jsonify({
         'methods': [
             item.to_dict(only=(
                 'name_method',
                 'time',
                 'id_user',
                 'id_classes_number',
                 'id_type_method',
                 'id_stage_method',
                 'id_fgos',
                 'is_local',
                 'creative_thinking',
                 'critical_thinking',
                 'communication',
                 'cooperation',
                 'metacognitive_skills',
                 'literacy',
                 'text',
             )) for item in methods
         ]
     })
 def get(self, method_id):
     abort_if_method_not_found(method_id)
     session = db_session.create_session()
     method = session.query(Methods).get(method_id)
     return jsonify({
         'method':
         method.to_dict(only=(
             'name_method',
             'time',
             'id_user',
             'id_classes_number',
             'id_type_method',
             'id_stage_method',
             'id_fgos',
             'is_local',
             'creative_thinking',
             'critical_thinking',
             'communication',
             'cooperation',
             'metacognitive_skills',
             'literacy',
             'text',
         ))
     })
def abort_if_save_lesson_not_found(save_lesson_id):
    session = db_session.create_session()
    save_lesson = session.query(SaveLesson).get(save_lesson_id)
    if not save_lesson:
        abort(404, message=f"SaveLesson {save_lesson_id} not found")
Exemple #14
0
    def show_dishes_table(self):
        self.dishesTable = DishesTable(self.db_sess, self.message)
        self.setCentralWidget(self.dishesTable)

    def show_versions_table(self):
        self.versionsTable = VersionsTable(self.db_sess, self.message)
        self.setCentralWidget(self.versionsTable)

    @QtCore.pyqtSlot()
    def update_orders_list(self):
        if isinstance(self.centralWidget(), OrdersListWidget):
            self.centralWidget().update_list()

    def message(self, text):
        self.statusbar.showMessage(text)


def except_hook(cls, exception, traceback):
    sys.__excepthook__(cls, exception, traceback)


if __name__ == '__main__':
    db_session.global_init(f'db/{DB_NAME}.db')
    db_sess = db_session.create_session()

    app = QApplication(sys.argv)
    ex = AppWindow(db_sess)
    ex.show()
    sys.excepthook = except_hook
    sys.exit(app.exec())
def abort_if_method_not_found(method_id):
    session = db_session.create_session()
    method = session.query(Methods).get(method_id)
    if not method:
        abort(404, message=f"Method {method_id} not found")
Exemple #16
0
def make_order():
    parameters = load_pizzeria_parameters()
    telephone_number = parameters['telephone_number']
    if not request.json:
        return jsonify({
            'error': 'Empty request',
            'telephone_number': telephone_number
        })
    for key in ['name', 'telephone_number', 'address', 'sum_price', 'order']:
        if key not in request.json:
            return jsonify({
                'error': 'Have not parameter',
                'parameter': key,
                'telephone_number': telephone_number
            })
    if not request.json['order']:
        return jsonify({
            'error': 'Empty order',
            'telephone_number': telephone_number
        })
    db_sess = db_session.create_session()
    for dish_dict in request.json['order']:
        dish = db_sess.query(Dishes).filter(
            Dishes.name == dish_dict['name']).first()
        if not dish:
            return jsonify({
                'error': 'Nonexistent dish',
                'telephone_number': telephone_number
            })
        if not dish.is_sale:
            return jsonify({
                'error': 'Not sale dish',
                'telephone_number': telephone_number
            })
        version = db_sess.query(Versions).filter(
            Versions.dish == dish, Versions.size == dish_dict['size']).first()
        if not version:
            return jsonify({
                'error': 'Nonexistent version',
                'telephone_number': telephone_number
            })

    start_time = datetime.datetime.strptime(parameters['start_time'],
                                            '%H:%M').time()
    end_time = datetime.datetime.strptime(parameters['end_time'],
                                          '%H:%M').time()
    if not (start_time <= datetime.datetime.now().time() <= end_time):
        return jsonify({'error': 'Not working time', **parameters})

    order = Orders()
    if request.json['name']:
        order.customer_name = request.json['name']
    if request.json['telephone_number']:
        order.telephone_number = request.json['telephone_number']
    order.address = request.json['address']
    order.sum_price = request.json['sum_price']
    db_sess.add(order)
    db_sess.commit()
    for dish_dict in request.json['order']:
        dish = db_sess.query(Dishes).filter(
            Dishes.name == dish_dict['name']).first()
        version = db_sess.query(Versions).filter(
            Versions.dish == dish, Versions.size == dish_dict['size']).first()
        versions_to_orders = VersionsToOrders()
        versions_to_orders.version = version
        versions_to_orders.order = order
        versions_to_orders.count = dish_dict['count']
        db_sess.add(versions_to_orders)
        db_sess.commit()
    return jsonify({'error': 'OK', 'telephone_number': telephone_number})
Exemple #17
0
def abort_if_user_not_found(user_id):
    session = db_session.create_session()
    user = session.query(User).get(user_id)
    if not user:
        abort(404, message=f"User {user_id} not found")