Exemple #1
0
def add_food(stallid) :
    food_form = FoodForm(request.form)
    stall = Hawker.query.get(stallid)
     
    if request.method == 'POST' and food_form.validate() :
        food = Food()
        food.name = food_form.name.data
        food.description = food_form.description.data
        food.price = food_form.price.data
        food.is_available = food_form.is_available.data
        food.hawker_id = stallid
        image_file = request.files['image']
        food.image = secure_filename(image_file.filename)

        if image_file and allowed_file(image_file.filename) :
            filename = secure_filename(image_file.filename)
            image_file.save(os.path.join(vendor_page.config['UPLOADED_FILES_DEST'], filename))            
            thumb = Image.open(os.path.join(vendor_page.config['UPLOADED_FILES_DEST'], filename)).resize((40, 40), Image.ANTIALIAS)
            name,ext = filename.rsplit('.', 1)
            thumb_filename = '%s_thumb.%s'%(name, ext)
            thumb.save(os.path.join(vendor_page.config['UPLOADED_FILES_DEST'], thumb_filename))

        db.session.add(food)
        db.session.commit()
        
        return redirect(url_for('vendor_page.index'))
    return render_template('addfood.html', form=food_form, stall=stall)
Exemple #2
0
def populatedata() :
    from hawkers.models import db, Hawker, Food, User
    populatevendor()
    # Empty the tables first
    print(Hawker.query.delete(), " rows deleted from Hawker")
    print(Food.query.delete(), " rows deleted from Food")
    
	# add hawker
    h = Hawker()
    h.name = 'Indian Stall'
    h.address = 'Golden Palace Eating House, 5 Kallang Sector, Singapore'
    h.pincode = 349279
    h.contact_number = 99991111
    h.email = '*****@*****.**'
    h.owner = User.query.filter_by(login='******').first().id
    db.session.add(h)
    db.session.commit()
    
    # add foods for this menu
    f1 = Food()
    f1.name = 'Dosa'
    f1.description = 'Indian style lentil pancakes'
    f1.price = 1.00
    f1.is_available = True
    f1.image = 'dosa.jpg'
    f1.hawker_id = h.id

    f2 = Food()
    f2.name = 'South Indian Lunch'
    f2.description = 'Complete Platter with variety rice and side dish'
    f2.price = 3.20
    f2.is_available = False
    f2.image = '2.jpg'
    f2.hawker_id = h.id

    f3 = Food()
    f3.name = 'Idli'
    f3.description = 'Indian Style steamed rice cakes'
    f3.is_available = True
    f3.price = 1.00
    f3.image = 'idli.jpg'
    f3.hawker_id = h.id

    db.session.add_all([f1, f2, f3])
    db.session.commit()