示例#1
0
def restaurant_menu(name):
	response = make_response(render_template('404.html'))
	session_id = request.cookies.get('session_id')
	result_message = request.args.get('result_message')
	error_message = request.args.get('error_message')
	if session_id:
		flag, result = furls.auth_session_state(session_id)
		if flag and result['role'] == 'Manager':
			session_id = result['session_id']
			if flag:
				form = MenuItemForm()
				if form.validate_on_submit():
					menu_id = request.args.get('menu_id')
					restaurant_id = request.args.get('restaurant_id')
					flag, result = furls.restaurant_menu_item_create(restaurant_id, menu_id, form.data)
					if flag:
						response = redirect(url_for('main.restaurant_menu', name=name, result_message='Created!'))
					else:
						response = redirect(url_for('main.restaurant_menu', name=name,\
							error_message=result['message']))
				else:
					flag, restr_result = furls.restaurant_info(result['user_id'])
					flag, menu = furls.restaurant_menu(result['user_id'])
					if form.errors:	error_message = 'Incorrect values'			
					response = make_response(render_template('restaurant_menu.html',\
						user=restr_result, menu_data=menu,form=form,\
						error_message=error_message,result_message=result_message))
			response.set_cookie('session_id', session_id)
	return response
示例#2
0
def restaurant_menu_update(name):
	response = make_response(render_template('404.html'))
	session_id = request.cookies.get('session_id')
	result_message = request.args.get('result_message')
	error_message = request.args.get('error_message')
	menu_id = request.args.get('menu_id')
	restaurant_id = request.args.get('restaurant_id')
	menu_item_id = request.args.get('menu_item_id')
	if session_id:
		flag, result = furls.auth_session_state(session_id)
		if flag and result['role'] == 'Manager':
			form = MenuItemForm()
			if form.validate_on_submit():
				flag, result = furls.restaurant_menu_update(restaurant_id, menu_id, menu_item_id, form.data)
				if flag:
					response = redirect(url_for('main.restaurant_menu', name=name, result_message='Updated'))
				else:
					response = redirect(url_for('main.restaurant_menu_edit', name=name, \
					error_message=result['message'],menu_id=menu_id,\
					restaurant_id=restaurant_id,menu_item_id=menu_item_id))
			else:
				flag, restr_result = furls.restaurant_info(result['user_id'])
				form.title.default = request.args.get('title')
				form.price.default = request.args.get('price')
				form.info.default = request.args.get('info')
				form.process()
				response = make_response(render_template('restaurant_menu_edit.html',user=restr_result, form=form,\
				error_message=error_message,result_message=result_message,menu_id=menu_id,\
				restaurant_id=restaurant_id,menu_item_id=menu_item_id))
			response.set_cookie('session_id', session_id)
	return response
示例#3
0
def create_item(request, menu_id, library_code, parent=None, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u'Вы должны быть сотрудником этой организации')

    menu = get_object_or_404(Menu, id=menu_id)

    if not parent:
        parent = menu.root_item
    else:
        parent = get_object_or_404(MenuItem, id=parent)

    if request.method == 'POST':
        item_form = MenuItemForm(request.POST, prefix='item_form')

        if item_form.is_valid():

            item = item_form.save(commit=False)
            item.parent = parent
            item.show = parent.show
            item.save()
            return redirect('participant_menu:administration:menu_detail', menu_id=menu.id, library_code=library_code)
    else:
        item_form = MenuItemForm(prefix="item_form")

    return render(request, 'participant_menu/administration/create_item.html', {
        'library': library,
        'item_form': item_form,
        'menu': menu
    })
示例#4
0
def new_menu():
    form = MenuItemForm()

    if form.validate_on_submit():
        name = form.name.data
        price = form.price.data
        desc = form.desc.data
        photo = form.photo.data
        photo_name = secure_filename(photo.filename)
        photo_path = os.path.join('static/images/menus', photo_name)
        thumb_path = os.path.join('static/images/menus/thumbs', photo_name)
        thumb_size = 128, 128

        menu = db.engine.execute(
            text(
                "SELECT * FROM menus WHERE menu_name = :name AND menu_price = :price LIMIT 1"
            ), {
                "name": name,
                "price": price
            }).first()

        # add new staff if not exists
        if menu is None:
            # save staff photo
            photo.save(photo_path)

            # create thumbnail for staff
            try:
                im = Image.open(photo_path)
                im.thumbnail(thumb_size, Image.ANTIALIAS)
                im.save(thumb_path, "JPEG")
            except IOError:
                flash("cannot create thumbnail for this menu item")

            # save user and the thumbnail name
            insertSql = "INSERT INTO menus (menu_name, menu_price, menu_desc, menu_photo) VALUES (:mname, :mprice, :mdesc, :mphoto)"
            insertParams = {
                'mname': name,
                'mprice': price,
                'mdesc': desc,
                'mphoto': photo_name
            }
            db.engine.execute(text(insertSql), insertParams)

            flash('New menu item added successfully.')
            return redirect(url_for('menus'))

        else:
            flash('Menu item already exists.')

    return render_template('new-menu-item.html',
                           auth=current_user,
                           form=form,
                           async_mode=socketio.async_mode)
def deleteMenuItem(restaurant_id, menu_id):
    session = DBSession()
    form = MenuItemForm()
    menuItemToDelete = session.query(Menu).filter_by(id=menu_id).one()
    if form.validate_on_submit():
        session.delete(menuItemToDelete)
        session.commit()
        session.close()
        flash("Menu Item Deleted Successfully!!! ")
        return redirect(url_for('viewRestaurantDetails', restaurant_id=restaurant_id))

    return render_template('menu/deletemenu.html', item = menuItemToDelete, form=form)
示例#6
0
def create_item(request, menu_id, parent=None):
    menu = get_object_or_404(Menu, id=menu_id)

    if not parent:
        parent = menu.root_item
    else:
        parent = get_object_or_404(MenuItem, id=parent)

    if request.method == 'POST':
        item_form = MenuItemForm(request.POST,prefix='item_form')

        menu_item_title_forms = []
        for lang in settings.LANGUAGES:
            menu_item_title_forms.append({
                'form':MenuItemTitleForm(request.POST,prefix='menu_item_title_' + lang[0]),
                'lang':lang[0]
            })

        if item_form.is_valid():

            item = item_form.save(commit=False)
            item.parent = parent
            item.show = parent.show
            item.save()

            valid = False
            for menu_item_title_form in menu_item_title_forms:
                valid = menu_item_title_form['form'].is_valid()
                if not valid:
                    break

            if valid:
                for menu_item_title_form in menu_item_title_forms:
                    menu_item_title = menu_item_title_form['form'].save(commit=False)
                    menu_item_title.lang = menu_item_title_form['lang']
                    menu_item_title.item = item
                    menu_item_title.save()
                return redirect('menu:administration:item_list', menu_id=menu.id)
    else:
        item_form = MenuItemForm(prefix="item_form")
        menu_item_title_forms = []
        for lang in settings.LANGUAGES:
            menu_item_title_forms.append({
                'form':MenuItemTitleForm(initial={'url': u'/'+lang[0]+u'/#'},prefix='menu_item_title_' + lang[0]),
                'lang':lang[0]
            })

    return render(request, 'menu/administration/create_item.html', {
        'item_form': item_form,
        'menu_item_title_forms': menu_item_title_forms,
        'menu':menu
    })
示例#7
0
def add_item(request, menu_pk):
    menu = get_object_or_404(Menu, pk=menu_pk)
    
    extension_form = None    
    
    if request.method == 'POST':
        form = MenuItemForm(request.POST)
        
        if hasattr(settings, 'TREE_MENU_ITEM_EXTENSION_MODEL'):
            extension_form = get_extension_form_class()(request.POST)
        
        if form.is_valid() and (not hasattr(settings, 'TREE_MENU_ITEM_EXTENSION_MODEL') or extension_form.is_valid()):
            menu_item = form.save(commit=False)
            clean_ranks(menu_item.siblings()) # Clean ranks for new siblings
            menu_item.rank = menu_item.siblings().count()
            menu_item.menu = menu
            menu_item.save()
            
            if extension_form:
                extension = extension_form.save(commit=False)
                extension.menu_item = menu_item
                extension.save()
            
            
            msg = _('The menu item "%s" was added successfully.') % force_unicode(menu_item)
            
            if "_continue" in request.POST:
                request.user.message_set.create(message=msg + ' ' + _("You may edit it again below."))
                return HttpResponseRedirect("../items/%s/" % menu_item.pk)
            elif "_addanother" in request.POST:
                request.user.message_set.create(message=msg + ' ' + _("You may add another menu item below."))
                return HttpResponseRedirect(request.path)
                return HttpResponseRedirect("../../add_item/")
            else:
                request.user.message_set.create(message=msg)
                return HttpResponseRedirect(reverse('edit_menu', kwargs={ 'menu_pk': menu.pk }))
    else:
        form_class = MenuItemForm
        choices = get_parent_choices(menu)
        form_class.base_fields['parent'].choices = choices
        form = form_class()
        if hasattr(settings, 'TREE_MENU_ITEM_EXTENSION_MODEL'):
            extension_form = get_extension_form_class()()
    
    return render_to_response('admin/%s/add_edit_item.html' % APP_LABEL,
                              { 'form': form, 'extension_form': extension_form, 'menu': menu, 'title': _('Add menu item'), 'add_or_edit': 'add' },
                              context_instance=RequestContext(request))
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)
示例#9
0
def item_edit(request, id, library_code, menu_id=None, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(
            u'Вы должны быть сотрудником этой организации')

    menu = get_object_or_404(Menu, id=menu_id)
    item = get_object_or_404(MenuItem, id=id)

    if request.method == 'POST':
        item_form = MenuItemForm(request.POST,
                                 prefix='item_form',
                                 instance=item)
        if item_form.is_valid():
            item_form.save()
            return redirect('participant_menu:administration:menu_detail',
                            menu_id=menu_id,
                            library_code=library_code)

    else:
        item_form = MenuItemForm(prefix="item_form", instance=item)
    return render(request, 'participant_menu/administration/edit_item.html', {
        'library': library,
        'item': item,
        'item_form': item_form,
        'menu': menu
    })
示例#10
0
def menu_add(request, url_level=None):
    isInitial = False
    level = request.POST.get('level') or url_level or ""
    if not level:
        formset = SelectChoiceForm()
        isInitial = True
    elif request.POST.get('initial') == "True" or url_level:
        formset = MenuItemForm(initial={'level': level})
    elif request.method == 'POST':
        formset = MenuItemForm(request.POST)
        if formset.is_valid():
            instance = formset.save()
            MenuItem.get(instance.key()) # for refreshing purposes http://stackoverflow.com/questions/15773892/should-i-expect-stale-results-after-redirect-on-local-environment
            return redirect(menu_list)
    return render_to_response("menu_add.html", {        
                                    "formset": formset,
                                    "initial": isInitial,
                                    "level"  : level
                              }, context_instance=RequestContext(request))    
示例#11
0
def item_edit(request, id, library_code, menu_id=None, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u'Вы должны быть сотрудником этой организации')

    menu = get_object_or_404(Menu, id=menu_id)
    item = get_object_or_404(MenuItem, id=id)

    if request.method == 'POST':
        item_form = MenuItemForm(request.POST, prefix='item_form', instance=item)
        if item_form.is_valid():
            item_form.save()
            return redirect('participant_menu:administration:menu_detail', menu_id=menu_id, library_code=library_code)

    else:
        item_form = MenuItemForm(prefix="item_form", instance=item)
    return render(request, 'participant_menu/administration/edit_item.html', {
        'library': library,
        'item': item,
        'item_form': item_form,
        'menu': menu
    })
示例#12
0
def restaurant(request, slug):
    restaurant = get_object_or_404(Restaurant, slug=slug)
    mform = MenuItemForm(prefix="menu")
    cform = comments.get_form()(restaurant)
    ajax = process_ajax(request, restaurant)
    if ajax:
        return ajax
    if request.method == "POST":
        if request.GET["type"] == "menu":
            mform = MenuItemForm(request.POST, prefix="menu")
            if mform.is_valid():
                model = mform.save(commit=False)
                model.user = request.user
                model.restaurant = restaurant
                model.is_available = True
                model.save()
                mform = MenuItemForm(prefix="menu")
                return HttpResponseRedirect("./")
        else :
            cform = comments.get_form()(restaurant, data=request.POST.copy())
            if cform.is_valid():
                comment = cform.get_comment_object()
                comment.ip_address = request.META.get("REMOTE_ADDR", None)
                if request.user.is_authenticated():
                    comment.user = request.user
                comment.save()
                cform = comments.get_form()(restaurant)
                return HttpResponseRedirect("./")
    del cform.fields['honeypot']
    del cform.fields['url']  
    referer = request.environ.get("HTTP_REFERER")
    if referer != None:
        if  referer.startswith("http://stumptownvegans.com/") or referer.startswith("http://localhost:8000/") and not ReferingSite.objects.all().filter(url=referer) and not ReferingSite.objects.all().filter(restaurant=restaurant):
            try:
                ReferingSite(restaurant=restaurant, url=referer).save()
            except:
                logging.critical(traceback.format_exc())
    return render_to_response("restaurants/restaurant_detail.html", {'menu_form': mform, 'comment_form': cform, 'object': restaurant, 'menu':restaurant.menuitem_set.all().order_by("category") ,'tags':getTags(restaurant)}, context_instance=RequestContext(request))
def editMenuItem(restaurant_id, menu_id):
    session = DBSession()
    form = MenuItemForm()
    restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
    editedMenu = session.query(Menu).filter_by(id=menu_id).one()
    if form.validate_on_submit():
        if request.form['name']:
            editedMenu.name = form.name.data
        if request.form['course']:
            editedMenu.course = form.course.data
        if request.form['category']:
            editedMenu.category = form.category.data
        if request.form['price']:
            editedMenu.price = form.price.data
        if request.form['description']:
            editedMenu.description = form.description.data
        session.add(editedMenu)
        session.commit()
        session.close()
        flash("Menu Item Successfully Edited")
        return redirect(url_for('viewRestaurantDetails', restaurant_id = restaurant_id))

    return render_template('menu/editmenu.html', restaurant_id = restaurant_id, menu_id=menu_id, item=editedMenu, form=form)
示例#14
0
def menu_edit(request, key=None):
    if not key:
        return redirect(menu_list)
    m = MenuItem.get(key)
    if request.method == 'POST':
        formset = MenuItemForm(request.POST, instance=m)
        if formset.is_valid():
            m = formset.save()
            MenuItem.get(m.key())  # for refreshing purposes http://stackoverflow.com/questions/15773892/should-i-expect-stale-results-after-redirect-on-local-environment
            return redirect(menu_list)
    else:
        formset = MenuItemForm(instance=m)
    return render_to_response("menu_add.html", {        
                                    "formset": formset,
                                    "level"  : m.level
                              }, context_instance=RequestContext(request))     
示例#15
0
def create_item(request,
                menu_id,
                library_code,
                parent=None,
                managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(
            u'Вы должны быть сотрудником этой организации')

    menu = get_object_or_404(Menu, id=menu_id)

    if not parent:
        parent = menu.root_item
    else:
        parent = get_object_or_404(MenuItem, id=parent)

    if request.method == 'POST':
        item_form = MenuItemForm(request.POST, prefix='item_form')

        if item_form.is_valid():

            item = item_form.save(commit=False)
            item.parent = parent
            item.show = parent.show
            item.save()
            return redirect('participant_menu:administration:menu_detail',
                            menu_id=menu.id,
                            library_code=library_code)
    else:
        item_form = MenuItemForm(prefix="item_form")

    return render(request, 'participant_menu/administration/create_item.html',
                  {
                      'library': library,
                      'item_form': item_form,
                      'menu': menu
                  })
示例#16
0
def item_edit(request, id, menu_id=None):
    menu = get_object_or_404(Menu, id=menu_id)
    item = get_object_or_404(MenuItem, id=id)
    item_titles = MenuItemTitle.objects.filter(item=item)

    item_titles_langs = {}
    for lang in settings.LANGUAGES:
        item_titles_langs[lang] = None


    for item_title in item_titles:
        item_titles_langs[item_title.lang] = item_title


    if request.method == 'POST':
        item_form = MenuItemForm(request.POST, prefix='item_form', instance=item)
        menu_item_title_forms = []
        for lang in settings.LANGUAGES:
            if lang in item_titles_langs:
                lang = lang[0]
                if lang in item_titles_langs:
                    menu_item_title_forms.append({
                        'form':MenuItemTitleForm(request.POST,prefix='menu_item_title_' + lang, instance=item_titles_langs[lang]),
                        'lang':lang
                    })
                else:
                    menu_item_title_forms.append({
                        'form':MenuItemTitleForm(request.POST,prefix='menu_item_title_' + lang),
                        'lang':lang
                    })

        valid = False
        for menu_item_title_form in menu_item_title_forms:
            valid = menu_item_title_form['form'].is_valid()
            if not valid:
                break


        if not item_form.is_valid():
            valid = False

        if valid:
            item = item_form.save()
            for menu_item_title_form in menu_item_title_forms:
                menu_item_title = menu_item_title_form['form'].save(commit=False)
                menu_item_title.item = item
                menu_item_title.lang = menu_item_title_form['lang']
                menu_item_title.save()

            if not item.is_leaf_node():
                ditems = item.get_descendants()
                for ditem in ditems:
                    ditem.show = item.show
                    ditem.save()

            return redirect('menu:administration:item_list', menu_id=menu_id)


    else:
        item_form = MenuItemForm(prefix="item_form", instance=item)
        menu_item_title_forms = []
        for lang in settings.LANGUAGES:
            lang = lang[0]
            if lang in item_titles_langs:
                menu_item_title_forms.append({
                    'form':MenuItemTitleForm(prefix='menu_item_title_' + lang, instance=item_titles_langs[lang]),
                    'lang':lang
                })
            else:
                menu_item_title_forms.append({
                    'form':MenuItemTitleForm(prefix='menu_item_title_' + lang),
                    'lang':lang
                })

    return render(request, 'menu/administration/edit_item.html', {
        'item': item,
        'item_form': item_form,
        'menu_item_title_forms': menu_item_title_forms,
        'menu': menu
    })
示例#17
0
def item_edit(request, id, menu_id=None):
    menu = get_object_or_404(Menu, id=menu_id)
    item = get_object_or_404(MenuItem, id=id)
    item_titles = MenuItemTitle.objects.filter(item=item)

    item_titles_langs = {}
    for lang in settings.LANGUAGES:
        item_titles_langs[lang] = None

    for item_title in item_titles:
        item_titles_langs[item_title.lang] = item_title

    if request.method == 'POST':
        item_form = MenuItemForm(request.POST,
                                 prefix='item_form',
                                 instance=item)
        menu_item_title_forms = []
        for lang in settings.LANGUAGES:
            if lang in item_titles_langs:
                lang = lang[0]
                if lang in item_titles_langs:
                    menu_item_title_forms.append({
                        'form':
                        MenuItemTitleForm(request.POST,
                                          prefix='menu_item_title_' + lang,
                                          instance=item_titles_langs[lang]),
                        'lang':
                        lang
                    })
                else:
                    menu_item_title_forms.append({
                        'form':
                        MenuItemTitleForm(request.POST,
                                          prefix='menu_item_title_' + lang),
                        'lang':
                        lang
                    })

        valid = False
        for menu_item_title_form in menu_item_title_forms:
            valid = menu_item_title_form['form'].is_valid()
            if not valid:
                break

        if not item_form.is_valid():
            valid = False

        if valid:
            item = item_form.save()
            for menu_item_title_form in menu_item_title_forms:
                menu_item_title = menu_item_title_form['form'].save(
                    commit=False)
                menu_item_title.item = item
                menu_item_title.lang = menu_item_title_form['lang']
                menu_item_title.save()

            if not item.is_leaf_node():
                ditems = item.get_descendants()
                for ditem in ditems:
                    ditem.show = item.show
                    ditem.save()

            return redirect('menu:administration:item_list', menu_id=menu_id)

    else:
        item_form = MenuItemForm(prefix="item_form", instance=item)
        menu_item_title_forms = []
        for lang in settings.LANGUAGES:
            lang = lang[0]
            if lang in item_titles_langs:
                menu_item_title_forms.append({
                    'form':
                    MenuItemTitleForm(prefix='menu_item_title_' + lang,
                                      instance=item_titles_langs[lang]),
                    'lang':
                    lang
                })
            else:
                menu_item_title_forms.append({
                    'form':
                    MenuItemTitleForm(prefix='menu_item_title_' + lang),
                    'lang':
                    lang
                })

    return render(
        request, 'menu/administration/edit_item.html', {
            'item': item,
            'item_form': item_form,
            'menu_item_title_forms': menu_item_title_forms,
            'menu': menu
        })
示例#18
0
def create_item(request, menu_id, parent=None):
    menu = get_object_or_404(Menu, id=menu_id)

    if not parent:
        parent = menu.root_item
    else:
        parent = get_object_or_404(MenuItem, id=parent)

    if request.method == 'POST':
        item_form = MenuItemForm(request.POST, prefix='item_form')

        menu_item_title_forms = []
        for lang in settings.LANGUAGES:
            menu_item_title_forms.append({
                'form':
                MenuItemTitleForm(request.POST,
                                  prefix='menu_item_title_' + lang[0]),
                'lang':
                lang[0]
            })

        if item_form.is_valid():

            item = item_form.save(commit=False)
            item.parent = parent
            item.show = parent.show
            item.save()

            valid = False
            for menu_item_title_form in menu_item_title_forms:
                valid = menu_item_title_form['form'].is_valid()
                if not valid:
                    break

            if valid:
                for menu_item_title_form in menu_item_title_forms:
                    menu_item_title = menu_item_title_form['form'].save(
                        commit=False)
                    menu_item_title.lang = menu_item_title_form['lang']
                    menu_item_title.item = item
                    menu_item_title.save()
                return redirect('menu:administration:item_list',
                                menu_id=menu.id)
    else:
        item_form = MenuItemForm(prefix="item_form")
        menu_item_title_forms = []
        for lang in settings.LANGUAGES:
            menu_item_title_forms.append({
                'form':
                MenuItemTitleForm(initial={'url': u'/' + lang[0] + u'/#'},
                                  prefix='menu_item_title_' + lang[0]),
                'lang':
                lang[0]
            })

    return render(
        request, 'menu/administration/create_item.html', {
            'item_form': item_form,
            'menu_item_title_forms': menu_item_title_forms,
            'menu': menu
        })