Example #1
0
def main():
    # randomly generate cuisines
    for i in range(1, 100):
        cname = "Cuisine Type " + str(i)
        print "inserting", cname

        cuisine = models.Cuisine(cname)
        models.db.session.add(cuisine)
        models.db.session.commit()
        print "done"

    # populate mappings
    chefs = models.get_all_chefs()
    cuisines = models.get_all_cuisines()
    fooditems = models.get_all_fooditems()
    
    # insert chef-cuisine mapping first (chef special)
    for chef in chefs:
        randcuisine = random.choice(cuisines)
        print chef.chefid, randcuisine

        chefspec = models.ChefSpecial(chef.chefid, randcuisine.cuisineid)
        models.db.session.add(chefspec)
    models.db.session.commit()
    print "commited chef-cuisine"    

    # insert fooditem-cuisine mapping (cuisine item)
    for fooditem in fooditems:
        randcuisine = random.choice(cuisines)
        print fooditem.foodid, randcuisine

        cuisineitem = models.CuisineItem(fooditem.foodid, randcuisine.cuisineid)
        models.db.session.add(cuisineitem)
    models.db.session.commit()
    print "commited fooditem-cuisine"
Example #2
0
def foodlist():
    form = forms.FindFoodForm(request.form)
    form.cuisine.choices = [(c.cuisineid, c.cuisine_name)
                            for c in models.get_all_cuisines()]

    if (request.method == 'POST' and form.validate()):
        cuisineid = form.cuisine.data
        print cuisineid
        foods = models.get_fooditems_by_cuisine_id(cuisineid)

        return render_template('foodlist.html', form=form, foods=foods)

    return render_template('foodlist.html', form=form, foods=[])
Example #3
0
def orderpage():
    # to place an order:
    #   - first pick a cuisine type
    #   - then pick a meal
    #   - then pick a chef and time
    form = forms.OrderPageForm(request.form)
    form.cuisine.choices = [(c.cuisineid, c.cuisine_name)
                            for c in models.get_all_cuisines()]

    if (request.method == 'POST' and form.validate()):
        return render_template('orderpage.html')

    return render_template('orderpage.html', form=form)
Example #4
0
def account():
    form = forms.AccountForm(request.form)
    form.country.choices = [(c.countryid, c.countryname)
                            for c in models.get_all_countries()]
    form.chefspec.choices = [(c.cuisineid, c.cuisine_name)
                             for c in models.get_all_cuisines()]
    form.chefspec.choices.append((-1, "Pick a Specialty..."))
    #form.custpref.choices = [(c.cuisineid, c.cuisine_name) for c in models.get_all_cuisines()]

    # populate form with existing info
    user = models.get_user_by_id(session['userid'])
    chef = models.get_chef_by_id(session['chefid'])
    cust = models.get_customer_by_id(session['custid'])

    print form.first_name.data, form.last_name.data
    print form.country.data, form.usertype.data
    print request.method, form.validate()

    if (request.method == 'POST'):
        print request.form

        # delete chef/cust only options from the form to get through validation
        if (not chef):
            del form.chefspec
        if (not cust):
            del form.custpref

        if (form.validate()):
            print "posting..."
            fname = form.first_name.data
            lname = form.last_name.data
            email = form.email_id.data
            passwd = sha256_crypt.encrypt(str(form.password.data))
            user_type = form.usertype.data
            aptno = form.apartment_no.data
            street = form.street.data
            city = form.city.data
            state = form.state.data
            zipcode = int(form.zipcode.data) if form.zipcode.data else None
            country = int(form.country.data) if form.country.data else None
            phoneno = int(
                form.phone_number.data) if form.phone_number.data else None
            chefspec = None
            reachouts = None
            custpref = None

            if (chef):
                chefspec = int(form.chefspec.data)
                reachouts = form.reachouts.data
            if (cust):
                custpref = form.custpref.data

            # update with new info if necessary
            r = user.update(fname, lname, email, passwd, user_type, aptno,
                            street, city, state, zipcode, country, phoneno,
                            chefspec, reachouts, custpref)

            update_session(user)

            if (r == 0):
                flash(
                    'User details updated. Visit account page again to see new fields',
                    'success')
            else:
                flash('Update failed, check the submitted data for errors',
                      'danger')

            return render_template('account.html',
                                   form=form,
                                   chef=chef,
                                   cust=cust)
        else:
            flash('Update failed, check the submitted data for errors',
                  'danger')
            return render_template('account.html',
                                   form=form,
                                   chef=chef,
                                   cust=cust)

    elif (request.method == 'GET'):
        usertype = ""
        aptno, street, city, state, zipcode, countryid, phoneno = (None, ) * 7
        chefspec = None
        custpref = None
        reachouts = None
        if (chef and cust):
            usertype = "both"
            aptno = chef.address
            street = chef.street
            city = chef.city
            state = chef.state
            zipcode = chef.zipcode
            countryid = chef.countryid
            phoneno = chef.phone_number
            chefspec = chef.get_specialty()
            reachouts = chef.get_reachouts_str()
            custpref = cust.preference
        elif (chef):
            usertype = "chef"
            aptno = chef.address
            street = chef.street
            city = chef.city
            state = chef.state
            zipcode = chef.zipcode
            countryid = chef.countryid
            phoneno = chef.phone_number
            chefspec = chef.get_specialty()
            reachouts = chef.get_reachouts_str()
        elif (cust):
            usertype = "customer"
            aptno = cust.address
            street = cust.street
            city = cust.city
            state = cust.state
            zipcode = cust.zipcode
            countryid = cust.countryid
            phoneno = cust.phone_number
            custpref = cust.preference

        form.first_name.data = user.fname
        form.last_name.data = user.lname
        form.email_id.data = user.email
        form.password.data = None
        form.usertype.data = usertype

        form.apartment_no.data = aptno
        form.street.data = street
        form.city.data = city
        form.state.data = state
        form.zipcode.data = str(zipcode)
        form.country.data = countryid
        form.phone_number.data = str(phoneno)

        form.chefspec.data = chefspec.cuisineid if chefspec else -1
        form.reachouts.data = reachouts
        form.custpref.data = custpref

        if (not chef):
            del form.chefspec
            del form.reachouts
        if (not cust):
            del form.custpref

        return render_template('account.html', form=form, chef=chef, cust=cust)
    flash('Update failed', 'danger')
    return render_template('account.html', form=form, chef=chef, cust=cust)