コード例 #1
0
ファイル: grub.py プロジェクト: 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)
コード例 #2
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)
コード例 #3
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)
コード例 #4
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)
コード例 #5
0
ファイル: grub.py プロジェクト: 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)
コード例 #6
0
ファイル: grub.py プロジェクト: 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)