Пример #1
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)
Пример #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):
        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)
Пример #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)