Esempio n. 1
0
    def GET(self):
        get_params = web.input()
        itemID = get_params['itemID']

        # get item tuple from item ID
        item = sqlitedb.getItemById(itemID)

        # get bids
        bids = sqlitedb.getBids(itemID)

        # get categories
        categories = sqlitedb.getCategories(itemID)

        # get auction status
        auction_status = sqlitedb.getAuctionStatus(itemID)

        # get winner if auction is closed
        winner = None
        if auction_status == sqlitedb.AuctionStatus.CLOSED:
            winner = sqlitedb.getWinner(itemID)

        return render_template('auction.html',
                               item=item,
                               bids=bids,
                               categories=categories,
                               auction_status=auction_status,
                               winner=winner)
Esempio n. 2
0
    def POST(self):
        post_params = web.input()
        item_id = post_params['item_id']
        # get bids
        bid_result = sqlitedb.getBids(item_id)
        item = sqlitedb.getItemById(item_id)
        categories = sqlitedb.getCategories(item_id)
        current_time = sqlitedb.getTime()
        if item['Buy_Price'] is not None:
            buy_price = item['Buy_Price']
        else:
            buy_price = float('inf')

        winner = None
        # check status
        if item['Ends'] > current_time and item['Currently'] < buy_price:
            open = True
        else:
            if item['Number_of_Bids'] > 0:
                winner = sqlitedb.getWinner(item_id,
                                            item['Currently'])['UserID']
            open = False

        return render_template('item.html',
                               bid_result=bid_result,
                               item=item,
                               categories=categories,
                               open=open,
                               winner=winner)
Esempio n. 3
0
File: grub.py Progetto: vchang2/grub
 def GET(self):
     if session.user == None:
         return render_template('login.html')
     post_params = web.input()
     editAbout = False
     if 'editAboutMe' in post_params:
         editAbout = True
     if 'newAboutMe' in post_params:
         editAbout = False
         sqlitedb.updateAboutMe(userID, post_params['newAboutMe'])
     recipeID = 0
     if 'recipeID' in post_params:
         recipeID = post_params['recipeID']
     recipe = sqlitedb.getRecipe(recipeID)
     instructions = sqlitedb.getInstructions(recipeID)
     ingredients = sqlitedb.getIngredients(recipeID)
     tags = sqlitedb.getTags(recipeID)
     photos = sqlitedb.getPhotos(recipeID)
     categories = sqlitedb.getCategories(recipeID)
     reviews = sqlitedb.getReviews(recipeID)
     userVotes = {0 : 'na'}
     for review in reviews:
         userVotes[review['ReviewID']] = sqlitedb.userVoted(review['ReviewID'], session.user)
     userHasReviewed = sqlitedb.hasUserReviewed(recipeID, session.user)
     cookbooks = sqlitedb.getCookbooks(session.user)
     userMatchesRecipeAuthor = False
     for result in recipe:
         if session.user == result['UserID']:
             userMatchesRecipeAuthor = True
     return render_template('view_recipe.html', recipe = recipe, recipeID = recipeID, instructions = instructions, ingredients = ingredients, tags = tags, photos = photos, categories = categories, reviews = reviews, cookbooks = cookbooks, currentUser = session.user, userHasReviewed = userHasReviewed, userMatchesRecipeAuthor = userMatchesRecipeAuthor, userVotes = userVotes, editAbout = editAbout)
Esempio n. 4
0
 def GET(self):
     #print itemID
     params = web.input()
     restaurantId = params['restaurantId']
     #print itemID
     t = sqlitedb.transaction()
     try:
         #print "try statement"
         result = sqlitedb.getRestaurantById(
             restaurantId)  #edit function to handle exception
         categories = sqlitedb.getCategories(restaurantId)
         categories_string = 'None'
         if categories:
             categories_string = ''
             for c in categories:
                 categories_string += c.Category
                 categories_string += '; '
     except Exception as e:
         t.rollback()
         error = str(e)
         return render_template('view.html', error=error)
     else:
         t.commit()
         if not result:
             return render_template('view.html')
         return render_template('view.html',
                                result=result,
                                categories=categories_string)
Esempio n. 5
0
 def GET(self):
     if session.user == None:
         return render_template('login.html')
     post_params = web.input()
     editAbout = False
     if 'editAboutMe' in post_params:
         editAbout = True
     if 'newAboutMe' in post_params:
         editAbout = False
         sqlitedb.updateAboutMe(userID, post_params['newAboutMe'])
     recipeID = 0
     if 'recipeID' in post_params:
         recipeID = post_params['recipeID']
     recipe = sqlitedb.getRecipe(recipeID)
     instructions = sqlitedb.getInstructions(recipeID)
     ingredients = sqlitedb.getIngredients(recipeID)
     tags = sqlitedb.getTags(recipeID)
     photos = sqlitedb.getPhotos(recipeID)
     categories = sqlitedb.getCategories(recipeID)
     reviews = sqlitedb.getReviews(recipeID)
     userVotes = {0: 'na'}
     for review in reviews:
         userVotes[review['ReviewID']] = sqlitedb.userVoted(
             review['ReviewID'], session.user)
     userHasReviewed = sqlitedb.hasUserReviewed(recipeID, session.user)
     cookbooks = sqlitedb.getCookbooks(session.user)
     userMatchesRecipeAuthor = False
     for result in recipe:
         if session.user == result['UserID']:
             userMatchesRecipeAuthor = True
     return render_template('view_recipe.html',
                            recipe=recipe,
                            recipeID=recipeID,
                            instructions=instructions,
                            ingredients=ingredients,
                            tags=tags,
                            photos=photos,
                            categories=categories,
                            reviews=reviews,
                            cookbooks=cookbooks,
                            currentUser=session.user,
                            userHasReviewed=userHasReviewed,
                            userMatchesRecipeAuthor=userMatchesRecipeAuthor,
                            userVotes=userVotes,
                            editAbout=editAbout)
Esempio n. 6
0
 def GET(self):
     #print itemID
     params = web.input()
     restaurantId = params['restaurantId']
     #print itemID
     t = sqlitedb.transaction()
     try:
         #print "try statement"
         result = sqlitedb.getRestaurantById(
             restaurantId)  #edit function to handle exception
         categories = sqlitedb.getCategories(restaurantId)
         categories_string = 'None'
         if categories:
             categories_string = ''
             for c in categories:
                 categories_string += c.Category
                 categories_string += '; '
         reviewsResult = sqlitedb.getReviewsByRestaurant(restaurantId)
         #print reviewsResult
     except Exception as e:
         t.rollback()
         error = str(e)
         #return json.dumps({'status': 1, 'error': error})
         return render_template('view.html', error=error)
     else:
         t.commit()
         if not result:
             #return json.dumps({'status': 0, 'message': 'no results'})
             return render_template('view.html')
         #return json.dumps({'status': 0, 'results': list(result)})
         if reviewsResult is None:
             return render_template('view.html',
                                    result=result,
                                    categories=categories_string)
         else:
             return render_template('view.html',
                                    result=result,
                                    categories=categories_string,
                                    reviews=reviewsResult)
Esempio n. 7
0
    def POST(self):
        recipeID = sqlitedb.assignRecipeID()
        data = web.input()

        sqlitedb.addRecipe(
            recipeID,
            session.user,  #TODO: ADD THE USER ID
            0,
            data.name,
            data.description,
            data.time,
            data.servings,
            data.spicy,
            data.diff)

        tags = data.tags
        tags = tags.split()
        for tag in tags:
            sqlitedb.addRecipeTags(recipeID, tag)

        numIngredients = int(data.numIngredients)
        for i in range(numIngredients):
            ingredient = data["ingredientIngredient" + str(i)]
            unit = "none"
            if ("ingredientUnit" + str(i)) in data:
                unit = data["ingredientUnit" + str(i)]
            numerator = 1
            denominator = 1
            if ("ingredientQuantity" + str(i)) in data:
                quantity = data["ingredientQuantity" + str(i)]
                if '/' in quantity:
                    quantityFraction = quantity.split('/')
                    numerator = int(quantityFraction[0])
                    denominator = int(quantityFraction[0])
                elif '.' in quantity:
                    quantityDecimal = float(quantity)
                    while (quantityDecimal % 1) != 0:
                        quantityDecimal *= 10
                        denominator *= 10
                    numerator = int(quantityDecimal)
                    factor = gcd(numerator, denominator)
                    numerator /= factor
                    denominator /= factor
                elif quantity != "":
                    numerator = int(quantity)
            sqlitedb.addRecipeIngredients(recipeID, ingredient, numerator,
                                          denominator, unit)

        numInstructions = int(data.numInstructions)
        for i in range(numInstructions):
            if ("instruction" + str(i)) in data:
                sqlitedb.addRecipeInstruction(recipeID, i + 1,
                                              data["instruction" + str(i)])

        sqlitedb.addRecipePhotos(recipeID, data.image)

        print data
        if 'categoriesBR' in data:
            sqlitedb.addRecipeCategories(recipeID, "breakfast")
        if 'categoriesLU' in data:
            sqlitedb.addRecipeCategories(recipeID, "lunch")
        if 'categoriesDI' in data:
            sqlitedb.addRecipeCategories(recipeID, "dinner")
        if 'categoriesSA' in data:
            sqlitedb.addRecipeCategories(recipeID, "savory")
        if 'categoriesSW' in data:
            sqlitedb.addRecipeCategories(recipeID, "sweet")
        if 'categoriesVE' in data:
            sqlitedb.addRecipeCategories(recipeID, "vegetarian")
        if 'categoriesGF' in data:
            sqlitedb.addRecipeCategories(recipeID, "gluten free")

        recipe = sqlitedb.getRecipe(recipeID)
        instructions = sqlitedb.getInstructions(recipeID)
        ingredients = sqlitedb.getIngredients(recipeID)
        tags = sqlitedb.getTags(recipeID)
        photos = sqlitedb.getPhotos(recipeID)
        categories = sqlitedb.getCategories(recipeID)
        reviews = sqlitedb.getReviews(recipeID)
        return render_template('view_recipe.html',
                               recipe=recipe,
                               instructions=instructions,
                               ingredients=ingredients,
                               tags=tags,
                               photos=photos,
                               categories=categories,
                               reviews=reviews)
Esempio n. 8
0
    def POST(self):
        post_params = web.input()
        editAbout = False
        recipeID = post_params['recipeID']
        print post_params
        if 'editAboutMe' in post_params:
            editAbout = True
        if 'newAboutMe' in post_params:
            editAbout = False
            sqlitedb.updateRecipeReview(post_params['reviewID'],
                                        post_params['newAboutMe'],
                                        int(post_params['stars']))

            #calculate new ratings
            ratings = sqlitedb.getReviews(recipeID)
            counter = 0.0
            total = 0
            for r in ratings:
                total += r['Rating']
                counter += 1.0
            new_rating = total / counter
            new_rating = format(new_rating, '.2f')
            sqlitedb.updateRating(recipeID, new_rating)
        if 'review' in post_params:
            reviewID = sqlitedb.assignReviewID()
            sqlitedb.addRecipeReview(reviewID, recipeID, session.user,
                                     post_params['review'],
                                     int(post_params['stars']), 0, 0)

            #need to update overall rating now
            ratings = sqlitedb.getReviews(recipeID)
            counter = 0.0
            total = 0
            for r in ratings:
                total += r['Rating']
                counter += 1.0
            new_rating = total / counter
            new_rating = format(new_rating, '.2f')
            sqlitedb.updateRating(recipeID, new_rating)
        if 'added_cookbookID' in post_params:
            sqlitedb.addCookbookRecipe(recipeID,
                                       post_params['added_cookbookID'])
        if 'd' in post_params:
            sqlitedb.deleteReview(post_params['DeleteReview'])
            #need to update overall rating now
            ratings = sqlitedb.getReviews(recipeID)
            counter = 0.0
            total = 0
            for r in ratings:
                total += r['Rating']
                counter += 1.0
            new_rating = total / counter
            new_rating = format(new_rating, '.2f')
            sqlitedb.updateRating(recipeID, new_rating)
        if 'HelpfulReview' in post_params:
            reviewID = post_params['reviewID']
            sqlitedb.addOneThumbsUp(reviewID, session.user)
            sqlitedb.updateVoteReviewStatus(reviewID, session.user, "up")
        if 'UnhelpfulReview' in post_params:
            reviewID = post_params['reviewID']
            sqlitedb.addOneThumbsDown(reviewID, session.user)
            sqlitedb.updateVoteReviewStatus(reviewID, session.user, "down")
        #reload page info
        recipe = sqlitedb.getRecipe(recipeID)
        instructions = sqlitedb.getInstructions(recipeID)
        ingredients = sqlitedb.getIngredients(recipeID)
        tags = sqlitedb.getTags(recipeID)
        photos = sqlitedb.getPhotos(recipeID)
        categories = sqlitedb.getCategories(recipeID)
        reviews = sqlitedb.getReviews(recipeID)
        userVotes = {0: 'na'}
        for review in reviews:
            userVotes[review['ReviewID']] = sqlitedb.userVoted(
                review['ReviewID'], session.user)
        print userVotes
        userHasReviewed = sqlitedb.hasUserReviewed(recipeID, session.user)
        cookbooks = sqlitedb.getCookbooks(session.user)
        userMatchesRecipeAuthor = False
        for result in recipe:
            if session.user == result['UserID']:
                userMatchesRecipeAuthor = True
        return render_template('view_recipe.html',
                               recipe=recipe,
                               instructions=instructions,
                               ingredients=ingredients,
                               tags=tags,
                               photos=photos,
                               categories=categories,
                               reviews=reviews,
                               cookbooks=cookbooks,
                               recipeID=recipeID,
                               currentUser=session.user,
                               userHasReviewed=userHasReviewed,
                               userMatchesRecipeAuthor=userMatchesRecipeAuthor,
                               userVotes=userVotes,
                               editAbout=editAbout)
Esempio n. 9
0
File: grub.py Progetto: vchang2/grub
    def POST(self):
        post_params = web.input()
        editAbout = False
        recipeID = post_params['recipeID']
        print post_params
        if 'editAboutMe' in post_params:
            editAbout = True
        if 'newAboutMe' in post_params:
            editAbout = False
            sqlitedb.updateRecipeReview(post_params['reviewID'], post_params['newAboutMe'], int(post_params['stars']))

            #calculate new ratings
            ratings = sqlitedb.getReviews(recipeID)
            counter = 0.0
            total = 0
            for r in ratings:
                total += r['Rating']
                counter += 1.0
            new_rating = total/counter
            new_rating = format(new_rating, '.2f')
            sqlitedb.updateRating(recipeID, new_rating)       
        if 'review' in post_params:
            reviewID = sqlitedb.assignReviewID()
            sqlitedb.addRecipeReview(reviewID, recipeID, session.user, post_params['review'], int(post_params['stars']), 0, 0)

            #need to update overall rating now
            ratings = sqlitedb.getReviews(recipeID)
            counter = 0.0
            total = 0
            for r in ratings:
                total += r['Rating']
                counter += 1.0
            new_rating = total/counter
            new_rating = format(new_rating, '.2f')
            sqlitedb.updateRating(recipeID, new_rating)
        if 'added_cookbookID' in post_params:
                sqlitedb.addCookbookRecipe(recipeID, post_params['added_cookbookID'])
        if 'd' in post_params:
            sqlitedb.deleteReview(post_params['DeleteReview'])
            #need to update overall rating now
            ratings = sqlitedb.getReviews(recipeID)
            counter = 0.0
            total = 0
            for r in ratings:
                total += r['Rating']
                counter += 1.0
            new_rating = total/counter
            new_rating = format(new_rating, '.2f')
            sqlitedb.updateRating(recipeID, new_rating)
        if 'HelpfulReview' in post_params:
            reviewID = post_params['reviewID']
            sqlitedb.addOneThumbsUp(reviewID, session.user)
            sqlitedb.updateVoteReviewStatus(reviewID, session.user, "up")
        if 'UnhelpfulReview' in post_params:
            reviewID = post_params['reviewID']
            sqlitedb.addOneThumbsDown(reviewID, session.user)
            sqlitedb.updateVoteReviewStatus(reviewID, session.user, "down")
        #reload page info
        recipe = sqlitedb.getRecipe(recipeID)
        instructions = sqlitedb.getInstructions(recipeID)
        ingredients = sqlitedb.getIngredients(recipeID)
        tags = sqlitedb.getTags(recipeID)
        photos = sqlitedb.getPhotos(recipeID)
        categories = sqlitedb.getCategories(recipeID)
        reviews = sqlitedb.getReviews(recipeID)
        userVotes = {0 : 'na'}
        for review in reviews:
            userVotes[review['ReviewID']] = sqlitedb.userVoted(review['ReviewID'], session.user)
        print userVotes
        userHasReviewed = sqlitedb.hasUserReviewed(recipeID, session.user)
        cookbooks = sqlitedb.getCookbooks(session.user)
        userMatchesRecipeAuthor = False
        for result in recipe:
            if session.user == result['UserID']:
                userMatchesRecipeAuthor = True
        return render_template('view_recipe.html', recipe = recipe, instructions = instructions, ingredients = ingredients, tags = tags, photos = photos, categories = categories, reviews = reviews, cookbooks = cookbooks, recipeID = recipeID, currentUser = session.user, userHasReviewed = userHasReviewed, userMatchesRecipeAuthor = userMatchesRecipeAuthor, userVotes = userVotes, editAbout = editAbout)
Esempio n. 10
0
File: grub.py Progetto: vchang2/grub
    def POST(self):
        recipeID = sqlitedb.assignRecipeID()
        data = web.input()

        sqlitedb.addRecipe(recipeID,
                session.user, #TODO: ADD THE USER ID
                0,
                data.name,
                data.description,
                data.time,
                data.servings,
                data.spicy,
                data.diff)

        tags = data.tags
        tags = tags.split()
        for tag in tags:
            sqlitedb.addRecipeTags(recipeID, tag)

        numIngredients = int(data.numIngredients)
        for i in range(numIngredients):
            ingredient = data["ingredientIngredient" + str(i)]
            unit = "none"
            if ("ingredientUnit" + str(i)) in data:
                unit = data["ingredientUnit" + str(i)]
            numerator = 1
            denominator = 1
            if ("ingredientQuantity" + str(i)) in data:
                quantity = data["ingredientQuantity" + str(i)]
                if '/' in quantity:
                    quantityFraction = quantity.split('/')
                    numerator = int(quantityFraction[0])
                    denominator = int(quantityFraction[0])
                elif '.' in quantity:
                    quantityDecimal = float(quantity)
                    while (quantityDecimal % 1) != 0:
                        quantityDecimal *= 10
                        denominator *= 10
                    numerator = int(quantityDecimal)
                    factor = gcd(numerator, denominator)
                    numerator /= factor
                    denominator /= factor
                elif quantity != "":
                    numerator = int(quantity)
            sqlitedb.addRecipeIngredients(recipeID, ingredient, numerator, denominator, unit)

        numInstructions = int(data.numInstructions)
        for i in range(numInstructions):
            if ("instruction" + str(i)) in data:
                sqlitedb.addRecipeInstruction(recipeID, i + 1, data["instruction" + str(i)])

        sqlitedb.addRecipePhotos(recipeID, data.image)

        print data
        if  'categoriesBR' in data:
            sqlitedb.addRecipeCategories(recipeID, "breakfast")
        if 'categoriesLU' in data:
            sqlitedb.addRecipeCategories(recipeID, "lunch")
        if 'categoriesDI' in data:
            sqlitedb.addRecipeCategories(recipeID, "dinner")
        if 'categoriesSA' in data:
            sqlitedb.addRecipeCategories(recipeID, "savory")
        if 'categoriesSW' in data:
            sqlitedb.addRecipeCategories(recipeID, "sweet")
        if 'categoriesVE' in data:
            sqlitedb.addRecipeCategories(recipeID, "vegetarian")
        if 'categoriesGF' in data:
            sqlitedb.addRecipeCategories(recipeID, "gluten free")

        recipe = sqlitedb.getRecipe(recipeID)
        instructions = sqlitedb.getInstructions(recipeID)
        ingredients = sqlitedb.getIngredients(recipeID)
        tags = sqlitedb.getTags(recipeID)
        photos = sqlitedb.getPhotos(recipeID)
        categories = sqlitedb.getCategories(recipeID)
        reviews = sqlitedb.getReviews(recipeID)
        return render_template('view_recipe.html', recipe = recipe, instructions = instructions, ingredients = ingredients, tags = tags, photos = photos, categories = categories, reviews = reviews)