def addmenu(): # login session if 'user_id' not in session: return redirect(url_for('view.login')) user_id = session['user_id'] Session = sessionmaker(bind=maco_db) s = Session() user = s.query(models.User).filter_by(id=user_id).first() if user is None: current_app.logger.error(f'Unexpected error: {user_id} is not found in DB') return redirect(url_for('view.login')) if request.method == 'POST': current_app.logger.info(f'Requested form {request.form}') date = request.form['dateinfo'] menu1 = request.form['menu1'] menu2 = request.form['menu2'] menu3 = request.form['menu3'] try: date = int(date) except: return render_template('addmenu.html', error='日付が正しくありません') if date <= update_date(): return render_template('addmenu.html', error='日付が正しくありません') user_id = session['user_id'] try: s.add(models.Menu(date, user_id, menu1, menu2, menu3)) s.commit() except: return render_template('addmenu.html', error='日付が正しくありません') return redirect(url_for('view.index')) return render_template('addmenu.html', date=next_date())
def __init__(self, game): self.bg_list = [ constants.load_image("main_bg1.jpg").convert(), constants.load_image("main_bg2.jpg").convert(), constants.load_image("main_bg3.jpg").convert() ] self.bg_no = 0 self.bg = self.bg_list[0] self.speaker = models.Speaker(screen, 700, 20, constants.MUSIC_LIST[constants.MAIN]) self.gamejolt = models.Gj(screen, 55, 30) new_key = models.MenuItem("newgame_text.png", True, (295, 209), (275, 185)) con_key = models.MenuItem("continue_text.png", False, (300, 305), (275, 280), True) high_score = models.MenuItem("high_score_text.png", False, (295, 398), (275, 375)) ex_key = models.MenuItem("exit_text.png", False, (350, 490), (275, 470)) self.menu = models.Menu(screen, [new_key, con_key, high_score, ex_key]) self.cursor = Display.cursor self.game = game self.title = constants.load_image("tetris.png") pygame.time.set_timer(25, 500)
def __init__(self): self.bg_list = [ constants.load_image("main_bg1.jpg").convert(), constants.load_image("main_bg2.jpg").convert(), constants.load_image("main_bg3.jpg").convert() ] self.bg_no = 0 self.bg = self.bg_list[0] back_key = models.MenuItem("back_text.png", False, (335, 500), (275, 480)) self.menu = models.Menu(screen, [back_key]) self.cursor = Display.cursor self.score_block_img = constants.load_image("score_block.png") pygame.time.set_timer(25, 500)
def createMenuItem(restaurant_id): session = DBSession() form = MenuItemForm() if form.validate_on_submit(): name = form.name.data course = form.course.data category = form.category.data price = form.price.data description = form.description.data menuItem = models.Menu(name=name, course =course, category=category, description = description, price= price, restaurant_id=restaurant_id) session.add(menuItem) session.commit() session.close() flash("Added {} ".format(name)) return redirect(url_for('viewRestaurantDetails', restaurant_id = restaurant_id)) return render_template('menu/createmenu.html', form=form)
def post(self): data = Menu.parser.parse_args() #경로를 위한 변수 설정 server_path = '' data = request.form if 'category_pk' not in data.keys(): return Response(status = 404) if 'image' in request.files: #local_path 저장할 경로, server_path 이미지 접근 가능 url 저장 image = request.files['image'] local_path = os.path.join(saveImgDir, 'main/', secure_filename(image.filename)) image.save(local_path) server_path = os.path.join(serverImgDir, 'main/', secure_filename(image.filename)) main_menu = models.Menu() #request에 이미지 파일이 존재하면 객체 menu_image필드에 server_path 저장 if server_path != '': main_menu.menu_image = server_path for i in data.keys(): if i == 'category_pk': main_menu.category_pk = data['category_pk'] elif i == 'menu_name': main_menu.menu_name = data['menu_name'] elif i == 'menu_price': main_menu.menu_price = data['menu_price'] elif i == 'menu_soldout': main_menu.menu_soldout = data['menu_soldout'] elif i == 'menu_description': main_menu.menu_description = data['menu_description'] session.add(main_menu) session.flush() session.commit() session.close() return Response(status = 201)
def insert_into_hotel_menu(db: Session, menu_items, user_id: int): print(menu_items) item = {} item['hotel_id'] = user_id item['items'] = menu_items print(item) qr_code = qrcode.QRCode(version=1, box_size=10, border=4) qr_code.add_data(menu_items) qr_code.make(fit=True) print('----------------------') dir_path = '/'.join(os.path.abspath(os.getcwd()).split('\\')) print(dir_path) folders = [x[0] for x in os.walk(dir_path)] print(folders) print('----------------------') qr_image = qr_code.make_image(fill='black', back_color='yellow') qr_image.save(dir_path + '/' + 'qr_menus' + '/' + str(item['hotel_id']) + '_' + "menu.png") qr_path = dir_path + '/' + 'qr_menus' + '/' + str( item['hotel_id']) + '_' + "menu.png" print(qr_image) print(os.getcwd()) try: db_menu_item = models.Menu(hotel_id=user_id, items=menu_items, qr_menu_path=qr_path) qrl.log_info( logging, f'hotel_id: {user_id},\nmenu_items: {menu_items},\nqr_menu_path:{qr_path}' ) print(db_menu_item) db.add(db_menu_item) db.commit() db.refresh(db_menu_item) return db_menu_item except Exception as e: qrl.log_exception(logging, repr(e)) return repr(e)
def post(self): data = request.form server_path = '' print(3) if 'category_pk' not in data.keys(): return Response(status=404) if 'image' in request.files: image = request.files['image'] print(image.filename) local_path = os.path.join(saveImgDir, 'main/', secure_filename(image.filename)) image.save(local_path) print(local_path) server_path = os.path.join(serverImgDir, 'main/', secure_filename(image.filename)) main_menu = models.Menu() if server_path != '': main_menu.menu_image = server_path for i in data.keys(): if i == 'category_pk': main_menu.category_pk = data['category_pk'] elif i == 'menu_name': main_menu.menu_name = data['menu_name'] elif i == 'menu_price': main_menu.menu_price = data['menu_price'] elif i == 'menu_soldout': main_menu.menu_soldout = data['menu_soldout'] elif i == 'menu_description': main_menu.menu_description = data['menu_description'] session.add(main_menu) session.flush() session.commit() return Response(status=201)
import shutil import sys import models from constant import * main = models.Menu(None, MAINMENU) telmenu = models.Menu(main, TELMENU) main.show_menu()
def edit(request): z = check_login_cookie(request) if z == 0: return redirect('/login/') if z[0] == 1: return redirect('/') rest = md.Restaurant.objects.filter(id=z[1]) rest = rest[0] if request.POST: type = request.POST['submit'] if type == "Modify": menuid = int(request.POST['menuid']) menu = md.Menu.objects.filter(id=menuid).\ update(price=int(request.POST['price']),quantity=int(request.POST['quantity'])) elif type == "Add": itemid = int(request.POST['item']) item = md.Item.objects.filter(id=itemid) item = item[0] menu = md.Menu() menu.item_id = item menu.restaurant_id = rest menu.price = int(request.POST['price']) menu.quantity = int(request.POST['quantity']) menu.save() else: menuid = int(request.POST['menuid']) menu = md.Menu.objects.filter(id=menuid) menu[0].delete() menuitems = md.Menu.objects.filter(restaurant_id=rest) menu = [] for x in menuitems: cmenu = [] cmenu.append(x.item_id) cmenu.append(x.price) cmenu.append(x.quantity) cmenu.append(x.id) menu.append(cmenu) menuitems = md.Item.objects.all() items = [] for y in menuitems: citem = [] citem.append(y.id) citem.append(y.name) items.append(citem) context = { "loggedin": 2, "username": z[1], "items": items, "menu": menu, } return render(request, 'edit.html', context)