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