Exemplo n.º 1
0
def add_stall() :
    stall_form = StallForm(request.form)
    # get a list of hawkers for this user. If admin, get all hawkers
    stalls = None
    users = None
    if g.user.is_admin :
        stalls = Hawker.query.all()
        for stall in stalls :
            owner = User.query.get(stall.owner)
            stall.user = owner
        users = User.query.all()
        stall_form.owner.choices = [(user.id, user.login) for user in users]
    else :
        stalls = Hawker.query.filter_by(owner=g.user.id).all()
        stall_form.owner.choices = [(g.user.id, g.user.login)]
        
    if request.method == 'POST' and stall_form.validate() :
        # add a stall for this hawker
        h = Hawker()
        h.owner = stall_form.owner.data
        h.name = stall_form.name.data
        h.address = stall_form.address.data
        h.pincode = stall_form.pincode.data
        h.email = stall_form.email.data
        h.contact_number = stall_form.contact_number.data
        db.session.add(h)
        db.session.commit()
        return redirect(url_for('vendor_page.index'))
        
    return render_template('addstall.html', form=stall_form)
Exemplo n.º 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()