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 copyToCollegeFeed(personId,entity): feed = Feed() liked = "N" for field in feed.all_fields(): if field.name == "startTime": x = "start_time" elif field.name == "endTime": x = "end_time" elif field.name == "contentCreator": x = "event_creator" else: x = field.name if hasattr(entity, x): if x == 'start_time': print field.name setattr(feed,"startDate", str(entity.start_time.strftime("%Y-%m-%d"))) setattr(feed, "startTime", str(entity.start_time.strftime("%H:%M:%S"))) elif x == 'end_time': print field.name setattr(feed, "endDate", str(entity.end_time.strftime("%Y-%m-%d"))) setattr(feed, "endTime", str(entity.end_time.strftime("%H:%M:%S"))) elif x == 'clubName': print "field name" + field.name setattr(feed, "clubName", entity.club_id.get().name) elif x == 'clubId': setattr(feed, "clubId", str(entity.club_id.id())) elif x == 'collegeId': print x setattr(feed, x, entity.collegeId.get().name) elif (x=='event_creator'): #print entity, field.name setattr(feed, "contentCreator", entity.event_creator.get().name) elif (x=='likers'): print field.name pylist=[] pylist2=[] for key in entity.likers: pylist.append(key.get().name) if personId in entity.likers: liked = "Y" setattr(feed, x, pylist) print "JUST SET THE LIKERS WITH " , pylist #pylist2.append(str(entity.likers)) for y in entity.likers: pylist2.append(str(y.id())) setattr(feed,"likersList",pylist2) setattr(feed,"feedType","Post") elif (x=='attendees'): print x pylist=[] print entity.title isAttending = "N" if personId in entity.attendees: isAttending = "Y" #for key in entity.attendees: # pylist.append(key.get().name) setattr(feed, x, str(len(entity.attendees))) setattr(feed, "isAttending", isAttending) for y in entity.attendees: pylist.append(str(y.id())) #pylist.append(str(entity.attendees)) setattr(feed, "attendeeList", pylist) setattr(feed,"feedType","Event") elif (x=="tags"): setattr(feed, field.name, (getattr(entity, field.name))) print "JUST SET", field.name else: setattr(feed, field.name, str(getattr(entity, field.name))) print "JUST SET", field.name elif (field.name=='id'): print field.name setattr(feed, field.name, str(entity.key.id())) elif (field.name=='contentCreator'): #FOR THE POST PART print field.name, "HERE" #print "DATA" #print "ENTITY", entity setattr(feed, "contentCreator", entity.from_pid.get().name) elif field.name == 'clubphotoUrl': print "Reached here-1" #print entity #print str(post.club_id.get().picture) setattr(feed, field.name, entity.club_id.get().photoUrl) elif field.name == 'clubName': print "field name" + field.name #print entity setattr(feed, field.name, entity.club_id.get().name) elif field.name == 'clubId': #print entity setattr(feed, field.name , str(entity.club_id.id())) elif field.name == 'clubabbreviation': #print entity setattr(feed, field.name, entity.club_id.get().abbreviation) elif field.name == 'clubName': #print "field name" + field.name setattr(feed, "clubName", entity.club_id.get().name) elif field.name == 'clubId': #print entity setattr(feed, "clubId", str(entity.club_id.id())) """ elif field.name == 'date': setattr(feed, field.name, str(entity.timestamp.strftime("%Y-%m-%d"))) elif field.name == 'time': setattr(feed, field.name, str(entity.timestamp.strftime("%H:%M:%S"))) """ postId = ndb.Key('Post',entity.key.id()) query = Comments.query(Comments.postId==postId) count = 0 for q in query: count+=1 setattr(feed, "commentCount", str(count)) if feed.feedType == "Post": print "HAS FIELD LIKES" , feed setattr(feed,"hasLiked",liked) return feed else: print "DIDNT HAVE FIELD LIKES" , feed #delattr(feed,"likers") #feed.hasLiked = None return feed
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 copyToCollegeFeed(personId, entity): feed = Feed() liked = "N" for field in feed.all_fields(): if field.name == "startTime": x = "start_time" elif field.name == "endTime": x = "end_time" elif field.name == "contentCreator": x = "event_creator" else: x = field.name if hasattr(entity, x): if x == 'start_time': print field.name setattr(feed, "startDate", str(entity.start_time.strftime("%Y-%m-%d"))) setattr(feed, "startTime", str(entity.start_time.strftime("%H:%M:%S"))) elif x == 'end_time': print field.name setattr(feed, "endDate", str(entity.end_time.strftime("%Y-%m-%d"))) setattr(feed, "endTime", str(entity.end_time.strftime("%H:%M:%S"))) elif x == 'clubName': print "field name" + field.name setattr(feed, "clubName", entity.club_id.get().name) elif x == 'clubId': setattr(feed, "clubId", str(entity.club_id.id())) elif x == 'collegeId': print x setattr(feed, x, entity.collegeId.get().name) elif (x == 'event_creator'): #print entity, field.name setattr(feed, "contentCreator", entity.event_creator.get().name) elif (x == 'likers'): print field.name pylist = [] pylist2 = [] for key in entity.likers: pylist.append(key.get().name) if personId in entity.likers: liked = "Y" setattr(feed, x, pylist) print "JUST SET THE LIKERS WITH ", pylist #pylist2.append(str(entity.likers)) for y in entity.likers: pylist2.append(str(y.id())) setattr(feed, "likersList", pylist2) setattr(feed, "feedType", "Post") elif (x == 'attendees'): print x pylist = [] print entity.title isAttending = "N" if personId in entity.attendees: isAttending = "Y" #for key in entity.attendees: # pylist.append(key.get().name) setattr(feed, x, str(len(entity.attendees))) setattr(feed, "isAttending", isAttending) for y in entity.attendees: pylist.append(str(y.id())) #pylist.append(str(entity.attendees)) setattr(feed, "attendeeList", pylist) setattr(feed, "feedType", "Event") elif (x == "tags"): setattr(feed, field.name, (getattr(entity, field.name))) print "JUST SET", field.name else: setattr(feed, field.name, str(getattr(entity, field.name))) print "JUST SET", field.name elif (field.name == 'id'): print field.name setattr(feed, field.name, str(entity.key.id())) elif (field.name == 'contentCreator'): #FOR THE POST PART print field.name, "HERE" #print "DATA" #print "ENTITY", entity setattr(feed, "contentCreator", entity.from_pid.get().name) elif field.name == 'clubphotoUrl': print "Reached here-1" #print entity #print str(post.club_id.get().picture) setattr(feed, field.name, entity.club_id.get().photoUrl) elif field.name == 'clubName': print "field name" + field.name #print entity setattr(feed, field.name, entity.club_id.get().name) elif field.name == 'clubId': #print entity setattr(feed, field.name, str(entity.club_id.id())) elif field.name == 'clubabbreviation': #print entity setattr(feed, field.name, entity.club_id.get().abbreviation) elif field.name == 'clubName': #print "field name" + field.name setattr(feed, "clubName", entity.club_id.get().name) elif field.name == 'clubId': #print entity setattr(feed, "clubId", str(entity.club_id.id())) """ elif field.name == 'date': setattr(feed, field.name, str(entity.timestamp.strftime("%Y-%m-%d"))) elif field.name == 'time': setattr(feed, field.name, str(entity.timestamp.strftime("%H:%M:%S"))) """ postId = ndb.Key('Post', entity.key.id()) query = Comments.query(Comments.postId == postId) count = 0 for q in query: count += 1 setattr(feed, "commentCount", str(count)) if feed.feedType == "Post": print "HAS FIELD LIKES", feed setattr(feed, "hasLiked", liked) return feed else: print "DIDNT HAVE FIELD LIKES", feed #delattr(feed,"likers") #feed.hasLiked = None return feed