Beispiel #1
0
def menu_page(cid):
    context = base_context()
    context['cart'] = carts.find_one(_id=ObjectId(cid));

    if request.method == 'POST':
        form = request.form
        tags = [t.strip() for t in form['tags'].split(',')]
        image = ''

        if request.files.has_key('file'):
            try:
                f = request.files['file']
                image = photos.insert(image_file=f, is_cart=False, is_default=False, title=form['name'])

            except IOError:
                print "error"

        menu_item = {'name': form['name'], 'price': form['price'], 'tags': tags, 'image': image.url_path}
        context['cart'].add_menu(menu_item)

    return render_template('menu.html', **context)
Beispiel #2
0
def load_images():
    photos.remove_all()
    photo_dir = "website/static/images"
    fnames = [os.path.realpath(os.path.join(root, name)) \
            for (root, dirs, files) in os.walk(photo_dir) for name in files]

    for name in fnames:
        f = open(name, 'r')
        fields = name.split('/')
        title = fields[len(fields) - 1]

        if 'food_cart' in title:
            photos.insert(image_file=f, is_cart= False, is_default=True, title=title)
            f.close()

        elif '.DS_Store' not in title:
            photos.insert(image_file=f, is_cart=True, is_default=False, title=title)
            f.close()

        else:
            photos.insert(image_file=f, is_cart=False, is_default=False, title=title)
            f.close()