def likePost(request): lp = LikePost() post_id = ndb.Key('Post', int(request.postId)) from_pid = ndb.Key('Profile', int(request.fromPid)) post = post_id.get() pylist = post.likers if (from_pid not in pylist): post.likes = post.likes + 1 post.likers.append(from_pid) post.put() else: print "Sorry Already liked" return message_types.VoidMessage
def deleteProfile(request): #Steps to be incorporated for deletion of a profile #1) Check if fromKey == pidKey from_key = ndb.Key('Profile', int(request.fromPid)) pid_key = ndb.Key('Profile', int(request.pid)) if (from_key == pid_key and pid_key != None): profile = pid_key.get() print profile.name #2) Remove the profile key from followers and members of every club #3) If the profile is in club.admin then remove it from club.admin and make Superadmin the admin of the club clubList = Club.query() for club in clubList: if (len(club.members) != 0): if pid_key in club.members: print("club key is", club.key) club.members.remove(pid_key) if (len(club.follows) != 0): if pid_key in club.follows: club.follows.remove(pid_key) if pid_key == club.admin: #obtain super admin profile of college college = club.collegeId.get() emailId = college.sup_emailId profileret = Profile.query(Profile.email == emailId) for superadmin in profileret: print("Superadmin", superadmin.name) superadmin.admin.append(club.key) club.admin = superadmin.key superadmin.clubsJoined.append(club.key) superadmin.follows.append(club.key) club.members.admin(superadmin.key) club.follows.admin(superadmin.key) superadmin.put() club.put() #4 Delete Posts which are created by the profile postRet = Post.query(Post.from_pid == pid_key) for posts in postRet: likePostmini = LikePost() likePostmini.from_pid = str(pid_key.id()) likePostmini.postId = str(posts.key.id()) deletePost(likePostmini) # Remove pid_key from event_attendees list eventlist = Event.query() for event in eventlist: if (len(event.attendees) != 0): if (pid_key in event.attendees): event.attendees.remove(pid_key) event.put() #Remove Events created by that profile eventRet = Event.query(Event.event_creator == pid_key) for events in eventRet: modifyeventmini = ModifyEvent() modifyeventmini.from_pid = str(pid_key.id()) modifyeventmini.eventId = str(events.key.id()) deleteEvent(modifyeventmini) #Remove Club_Creation requests by that profile or to that profile clubcreationlist = Club_Creation.query( ndb.OR(Club_Creation.from_pid == pid_key, Club_Creation.to_pid == pid_key)) for clubcreation in clubcreationlist: print clubcreation clubcreation.key.delete() #Remove Join Creation, Join Requests, Post_Requests joinCreationRet = Join_Creation.query( ndb.OR(Join_Creation.from_pid == pid_key, Join_Creation.to_pid == pid_key)) for jc in joinCreationRet: print jc jc.key.delete() joinReqRet = Join_Request.query( ndb.OR(Join_Request.from_pid == pid_key, Join_Request.to_pid == pid_key)) for jr in joinReqRet: print jr jr.key.delete() postReqRet = Post_Request.query( ndb.OR(Post_Request.from_pid == pid_key or Post_Request.to_pid == pid_key)) for pr in postReqRet: print pr pr.key.delete() commentlist = Comments.query(Comments.pid == pid_key) for comments in commentlist: print comments comments.key.delete() #notificationsRet = Notifications.query(Notifications.to_pid == pid_key) notificationsRet = Notifications.query( Notifications.to_pid_list.IN([pid_key])) for notif in notificationsRet: notif.key.delete() notificationsRet2 = Notifications.query(Notifications.to_pid == pid) for notif in notificationsRet2: notif.key.delete() #Delete the profile entity pid_key.delete()
def deleteClub(request): #Steps to be incorporated for deletion of a club #1) Remove the club key from the clubsJoined list of every profile #2) Remove the club key from the follows list of every profile #3) Remove the club key from the admin list of everyprofile #4) Remove from college group list #5) Remove notifications that have the club id = given club id #6)Remove Join Creations and Join Requests #Call deleteEvent and deletePost for all events and posts that belong to the club #Delete the club entity club_key_id = request.clubId pid = request.pid print("Club_key_id", club_key_id) clubKey = ndb.Key('Club', int(request.clubId)) pidKey = ndb.Key('Profile', int(request.pid)) profileconsidered = pidKey.get() club = clubKey.get() print("Club to be removed", club) # Check if the club's collegeId and Profile's collegeId are the same print("club.coolegeId", club.collegeId) print("profileconsidered.collegeId", profileconsidered.collegeId) if (club.collegeId == profileconsidered.collegeId): #check if the profile is the admin of the club or if he is the super admin of the college print("entered first part") print("Club.admin", club.admin) print("pidKey", pidKey) if (club.admin == pidKey or club.collegeId in profileconsidered.superadmin): # Operation 1 : for every profile key in member list of club, extract profile and remove the club # from the clubsJoined list print("Ive Entered Corrctly") for profile_key in club.members: profile = profile_key.get() profile.clubsJoined.remove(clubKey) profile.put() # Operation 2 : for every profile key in follows list of club, extract profile and remove the club # from the follows list of Profile for profile_key in club.follows: profile = profile_key.get() profile.follows.remove(clubKey) profile.put() #Operation 3 : Get the profile of the admin and remove the club key from his admin list adminProfile = club.admin.get() adminProfile.admin.remove(clubKey) adminProfile.put() #Operation 4 : Get the college and remove the club key from his grouplist college = club.collegeId.get() college.group_list.remove(clubKey) college.put() #Operation 5 : Get all notifications where it matches with clubKey and remove them notificationsRet = Notifications.query( Notifications.clubId == clubKey) for notif in notificationsRet: notif.key.delete() #Operation 6 : Get all JoinCreations and JoinRequests where it matches with clubKey and remove them joinCreationRet = Join_Creation.query( Join_Creation.club_id == clubKey) for jc in joinCreationRet: jc.key.delete() joinReqRet = Join_Request.query(Join_Request.club_id == clubKey) for jr in joinReqRet: jr.key.delete() postReqRet = Post_Request.query(Post_Request.club_id == clubKey) for pr in postReqRet: pr.key.delete() #Operation 7 - Posts and Events delete postRet = Post.query(Post.club_id == clubKey) for posts in postRet: likePostmini = LikePost() likePostmini.from_pid = str(club.admin.id()) likePostmini.postId = str(posts.key.id()) deletePost(likePostmini) eventRet = Event.query(Event.club_id == clubKey) for events in eventRet: modifyeventmini = ModifyEvent() modifyeventmini.from_pid = str(club.admin.id()) modifyeventmini.eventId = str(events.key.id()) deleteEvent(modifyeventmini) #Operation 8 - delete club clubKey.delete()
def deleteClub(request): #Steps to be incorporated for deletion of a club #1) Remove the club key from the clubsJoined list of every profile #2) Remove the club key from the follows list of every profile #3) Remove the club key from the admin list of everyprofile #4) Remove from college group list #5) Remove notifications that have the club id = given club id #6)Remove Join Creations and Join Requests #Call deleteEvent and deletePost for all events and posts that belong to the club #Delete the club entity club_key_id = request.clubId pid = request.pid print ("Club_key_id",club_key_id) clubKey = ndb.Key('Club',int(request.clubId)) pidKey = ndb.Key('Profile',int(request.pid)) profileconsidered = pidKey.get() club = clubKey.get() print ("Club to be removed",club) # Check if the club's collegeId and Profile's collegeId are the same print ("club.coolegeId",club.collegeId) print ("profileconsidered.collegeId",profileconsidered.collegeId) if(club.collegeId == profileconsidered.collegeId): #check if the profile is the admin of the club or if he is the super admin of the college print ("entered first part") print ("Club.admin",club.admin) print ("pidKey",pidKey) if(club.admin == pidKey or club.collegeId in profileconsidered.superadmin): # Operation 1 : for every profile key in member list of club, extract profile and remove the club # from the clubsJoined list print("Ive Entered Corrctly") for profile_key in club.members: profile = profile_key.get() profile.clubsJoined.remove(clubKey) profile.put() # Operation 2 : for every profile key in follows list of club, extract profile and remove the club # from the follows list of Profile for profile_key in club.follows: profile = profile_key.get() profile.follows.remove(clubKey) profile.put() #Operation 3 : Get the profile of the admin and remove the club key from his admin list adminProfile = club.admin.get() adminProfile.admin.remove(clubKey) adminProfile.put() #Operation 4 : Get the college and remove the club key from his grouplist college = club.collegeId.get() college.group_list.remove(clubKey) college.put() #Operation 5 : Get all notifications where it matches with clubKey and remove them notificationsRet = Notifications.query(Notifications.clubId == clubKey) for notif in notificationsRet: notif.key.delete() #Operation 6 : Get all JoinCreations and JoinRequests where it matches with clubKey and remove them joinCreationRet = Join_Creation.query(Join_Creation.club_id == clubKey) for jc in joinCreationRet: jc.key.delete() joinReqRet = Join_Request.query(Join_Request.club_id == clubKey) for jr in joinReqRet: jr.key.delete() postReqRet = Post_Request.query(Post_Request.club_id == clubKey) for pr in postReqRet: pr.key.delete() #Operation 7 - Posts and Events delete postRet = Post.query(Post.club_id == clubKey) for posts in postRet: likePostmini = LikePost() likePostmini.from_pid = str(club.admin.id()) likePostmini.postId = str(posts.key.id()) deletePost(likePostmini) eventRet = Event.query(Event.club_id == clubKey) for events in eventRet: modifyeventmini = ModifyEvent() modifyeventmini.from_pid = str(club.admin.id()) modifyeventmini.eventId = str(events.key.id()) deleteEvent(modifyeventmini) #Operation 8 - delete club clubKey.delete()
def deleteProfile(request): #Steps to be incorporated for deletion of a profile #1) Check if fromKey == pidKey from_key = ndb.Key('Profile',int(request.fromPid)) pid_key = ndb.Key('Profile',int(request.pid)) if(from_key == pid_key and pid_key!=None): profile = pid_key.get() print profile.name #2) Remove the profile key from followers and members of every club #3) If the profile is in club.admin then remove it from club.admin and make Superadmin the admin of the club clubList = Club.query() for club in clubList: if(len(club.members)!=0): if pid_key in club.members: print ("club key is",club.key) club.members.remove(pid_key) if(len(club.follows)!=0): if pid_key in club.follows: club.follows.remove(pid_key) if pid_key == club.admin: #obtain super admin profile of college college = club.collegeId.get() emailId = college.sup_emailId profileret = Profile.query(Profile.email == emailId) for superadmin in profileret: print ("Superadmin",superadmin.name) superadmin.admin.append(club.key) club.admin = superadmin.key superadmin.clubsJoined.append(club.key) superadmin.follows.append(club.key) club.members.admin(superadmin.key) club.follows.admin(superadmin.key) superadmin.put() club.put() #4 Delete Posts which are created by the profile postRet = Post.query(Post.from_pid == pid_key) for posts in postRet: likePostmini = LikePost() likePostmini.from_pid = str(pid_key.id()) likePostmini.postId = str(posts.key.id()) deletePost(likePostmini) # Remove pid_key from event_attendees list eventlist = Event.query() for event in eventlist: if(len(event.attendees)!=0): if(pid_key in event.attendees): event.attendees.remove(pid_key) event.put() #Remove Events created by that profile eventRet = Event.query(Event.event_creator == pid_key) for events in eventRet: modifyeventmini = ModifyEvent() modifyeventmini.from_pid = str(pid_key.id()) modifyeventmini.eventId = str(events.key.id()) deleteEvent(modifyeventmini) #Remove Club_Creation requests by that profile or to that profile clubcreationlist = Club_Creation.query(ndb.OR(Club_Creation.from_pid == pid_key,Club_Creation.to_pid == pid_key)) for clubcreation in clubcreationlist: print clubcreation clubcreation.key.delete() #Remove Join Creation, Join Requests, Post_Requests joinCreationRet = Join_Creation.query(ndb.OR(Join_Creation.from_pid == pid_key,Join_Creation.to_pid == pid_key)) for jc in joinCreationRet: print jc jc.key.delete() joinReqRet = Join_Request.query(ndb.OR(Join_Request.from_pid == pid_key,Join_Request.to_pid == pid_key)) for jr in joinReqRet: print jr jr.key.delete() postReqRet = Post_Request.query(ndb.OR(Post_Request.from_pid == pid_key or Post_Request.to_pid == pid_key )) for pr in postReqRet: print pr pr.key.delete() commentlist = Comments.query(Comments.pid == pid_key) for comments in commentlist: print comments comments.key.delete() #notificationsRet = Notifications.query(Notifications.to_pid == pid_key) notificationsRet = Notifications.query(Notifications.to_pid_list.IN([pid_key])) for notif in notificationsRet: notif.key.delete() notificationsRet2 = Notifications.query(Notifications.to_pid == pid) for notif in notificationsRet2: notif.key.delete() #Delete the profile entity pid_key.delete()