Exemple #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)
Exemple #2
0
 def POST(self):
     post_params = web.input()
     cookbookID = None
     currentUser = session.user
     editAbout = False
     viewingOwnProfile = False
     recipe_photos = []
     recipes = []
     if 'userID' in post_params:
         userID = post_params['userID']
         if userID == session.user:
             viewingOwnProfile = True
     elif session.user:
         userID = session.user
         viewingOwnProfile = True
     else:
         return render_template('login.html')
     if 'editAboutMe' in post_params:
         editAbout = True
     if 'newAboutMe' in post_params:
         editAbout = False
         sqlitedb.updateAboutMe(userID, post_params['newAboutMe'])
     if 'deleteCookbook' in post_params:
         sqlitedb.deleteCookbook(post_params['deleteCookbook'])
     if 'cookbook' in post_params:
         cookbookID = sqlitedb.assignCookbookID()
         sqlitedb.addCookbook(cookbookID, session.user,
                              post_params['cookbook'])
     if 'deleteRecipe' in post_params:
         recipeID = post_params['deleteRecipe']
         sqlitedb.deleteRecipe(recipeID)
         currentUser = session.user
     if 'userID' in post_params:
         userID = post_params['userID']
         userRecipes = sqlitedb.getUserRecipes(userID)
         for recipe in userRecipes:
             recipes.append(recipe['RecipeID'])
         if len(recipes) > 0:
             all_photos = sqlitedb.getRecipePhotos(recipes)
             for r in all_photos:
                 recipe_photos.append(r['Photo'])
         userAboutMe = sqlitedb.getAboutMe(userID)
         userFollowers = sqlitedb.getFollowers(userID)
         userFollowing = sqlitedb.getFollowing(userID)
         userCookbooks = sqlitedb.getCookbooks(userID)
     if 'unfollowing' in post_params:
         sqlitedb.unfollow(session.user, post_params['unfollowing'])
     if 'addFollower' in post_params:
         sqlitedb.addFollower(post_params['addFollower'], session.user)
     return render_template('view_user.html',
                            userID=userID,
                            userRecipes=userRecipes,
                            userAboutMe=userAboutMe,
                            userFollowers=userFollowers,
                            userFollowing=userFollowing,
                            userCookbooks=userCookbooks,
                            viewingOwnProfile=viewingOwnProfile,
                            currentUser=currentUser,
                            editAbout=editAbout,
                            recipe_photos=recipe_photos)
Exemple #3
0
 def GET(self):
     if session.user == None:
         return render_template('login.html')
     post_params = web.input()
     userID = None
     userRecipes = None
     userAboutMe = None
     userFollowers = None
     userFollowing = None
     userCookbooks = None
     viewingOwnProfile = False
     editAbout = False
     follower = False
     recipes = []
     recipe_photos = []
     currentUser = session.user
     if 'userID' in post_params:
         userID = post_params['userID']
         if userID == session.user:
             viewingOwnProfile = True
     elif session.user:
         userID = session.user
         viewingOwnProfile = True
     else:
         return render_template('login.html')
     if 'editAboutMe' in post_params:
         editAbout = True
     if 'newAboutMe' in post_params:
         editAbout = False
         sqlitedb.updateAboutMe(userID, post_params['newAboutMe'])
     following = sqlitedb.getFollowing(currentUser)
     for r in following:
         print r['UserID']
         if r['UserID'] == userID:
             follower = True
     userRecipes = sqlitedb.getUserRecipes(userID)
     for recipe in userRecipes:
         recipes.append(recipe['RecipeID'])
     if len(recipes) > 0:
         all_photos = sqlitedb.getRecipePhotos(recipes)
         for r in all_photos:
             recipe_photos.append(r['Photo'])
     userAboutMe = sqlitedb.getAboutMe(userID)
     userFollowers = sqlitedb.getFollowers(userID)
     userFollowing = sqlitedb.getFollowing(userID)
     userCookbooks = sqlitedb.getCookbooks(userID)
     if 'unfollowing' in post_params:
         sqlitedb.unfollow(session.user, post_params['unfollowing'])
     print recipe_photos
     return render_template('view_user.html', userID = userID, userRecipes = userRecipes, userAboutMe = userAboutMe, userFollowers = userFollowers, userFollowing = userFollowing, userCookbooks = userCookbooks, viewingOwnProfile = viewingOwnProfile, currentUser = currentUser, editAbout = editAbout, follower = follower, recipe_photos = recipe_photos)
Exemple #4
0
 def POST(self):
     post_params = web.input()
     cookbookID = None
     currentUser = session.user
     editAbout = False
     viewingOwnProfile = False
     recipe_photos = []
     recipes = []
     if 'userID' in post_params:
         userID = post_params['userID']
         if userID == session.user:
             viewingOwnProfile = True
     elif session.user:
         userID = session.user
         viewingOwnProfile = True
     else:
         return render_template('login.html')
     if 'editAboutMe' in post_params:
         editAbout = True
     if 'newAboutMe' in post_params:
         editAbout = False
         sqlitedb.updateAboutMe(userID, post_params['newAboutMe'])
     if 'deleteCookbook' in post_params:
         sqlitedb.deleteCookbook(post_params['deleteCookbook'])
     if 'cookbook' in post_params:
         cookbookID = sqlitedb.assignCookbookID()
         sqlitedb.addCookbook(cookbookID, session.user, post_params['cookbook'])
     if 'deleteRecipe' in post_params:
         recipeID = post_params['deleteRecipe']
         sqlitedb.deleteRecipe(recipeID)
         currentUser = session.user
     if 'userID' in post_params:
         userID = post_params['userID']
         userRecipes = sqlitedb.getUserRecipes(userID)
         for recipe in userRecipes:
             recipes.append(recipe['RecipeID'])
         if len(recipes) > 0:
             all_photos = sqlitedb.getRecipePhotos(recipes)
             for r in all_photos:
                 recipe_photos.append(r['Photo'])
         userAboutMe = sqlitedb.getAboutMe(userID)
         userFollowers = sqlitedb.getFollowers(userID)
         userFollowing = sqlitedb.getFollowing(userID)
         userCookbooks = sqlitedb.getCookbooks(userID)
     if 'unfollowing' in post_params:
         sqlitedb.unfollow(session.user, post_params['unfollowing'])
     if 'addFollower' in post_params:
         sqlitedb.addFollower(post_params['addFollower'], session.user)
     return render_template('view_user.html', userID = userID, userRecipes = userRecipes, userAboutMe = userAboutMe, userFollowers = userFollowers, userFollowing = userFollowing, userCookbooks = userCookbooks, viewingOwnProfile=viewingOwnProfile, currentUser = currentUser, editAbout = editAbout, recipe_photos = recipe_photos)
Exemple #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)
Exemple #6
0
 def GET(self):
     if session.user == None:
         return render_template('login.html')
     post_params = web.input()
     userID = None
     userRecipes = None
     userAboutMe = None
     userFollowers = None
     userFollowing = None
     userCookbooks = None
     viewingOwnProfile = False
     editAbout = False
     follower = False
     recipes = []
     recipe_photos = []
     currentUser = session.user
     if 'userID' in post_params:
         userID = post_params['userID']
         if userID == session.user:
             viewingOwnProfile = True
     elif session.user:
         userID = session.user
         viewingOwnProfile = True
     else:
         return render_template('login.html')
     if 'editAboutMe' in post_params:
         editAbout = True
     if 'newAboutMe' in post_params:
         editAbout = False
         sqlitedb.updateAboutMe(userID, post_params['newAboutMe'])
     following = sqlitedb.getFollowing(currentUser)
     for r in following:
         print r['UserID']
         if r['UserID'] == userID:
             follower = True
     userRecipes = sqlitedb.getUserRecipes(userID)
     for recipe in userRecipes:
         recipes.append(recipe['RecipeID'])
     if len(recipes) > 0:
         all_photos = sqlitedb.getRecipePhotos(recipes)
         for r in all_photos:
             recipe_photos.append(r['Photo'])
     userAboutMe = sqlitedb.getAboutMe(userID)
     userFollowers = sqlitedb.getFollowers(userID)
     userFollowing = sqlitedb.getFollowing(userID)
     userCookbooks = sqlitedb.getCookbooks(userID)
     if 'unfollowing' in post_params:
         sqlitedb.unfollow(session.user, post_params['unfollowing'])
     print recipe_photos
     return render_template('view_user.html',
                            userID=userID,
                            userRecipes=userRecipes,
                            userAboutMe=userAboutMe,
                            userFollowers=userFollowers,
                            userFollowing=userFollowing,
                            userCookbooks=userCookbooks,
                            viewingOwnProfile=viewingOwnProfile,
                            currentUser=currentUser,
                            editAbout=editAbout,
                            follower=follower,
                            recipe_photos=recipe_photos)
Exemple #7
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)
Exemple #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)