def getEventsEitherSide(request): timestamp = request.timestamp collegeId = request.collegeId timestampdatetime = dt.datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S') upperbound = timestampdatetime + dt.timedelta(hours=12) lowerbound = timestampdatetime - dt.timedelta(hours=12) print timestampdatetime print upperbound print lowerbound college_key = ndb.Key('CollegeDb',int(collegeId)) print college_key eventlist = Event.query(Event.collegeId == college_key) newList = [] print eventlist for event in eventlist: start_datetime = event.start_time + dt.timedelta(hours=5,minutes=30) #print "Considering" #print event.title #print start_datetime if(start_datetime>=lowerbound and start_datetime<=upperbound): newList.append(event) #eventlist2 = Event.query(ndb.AND(Event.collegeId == college_key, ndb.OR(Event.completed == "N",Event.completed == "No"))).fetch() #print eventlist2 for event in eventlist: if(event.completed == "N" or event.completed == "No") : start_datetime = event.start_time + dt.timedelta(hours=5,minutes=30) if(start_datetime<=timestampdatetime): print event.completed if event not in newList: newList.append(event) newList.sort(key=lambda x: x.start_time) finallist = [] for x in newList: returnobj = GetEventsESReturnForm() returnobj.name = str(x.title) returnobj.startTime = str(x.start_time) returnobj.collegeId = str(x.collegeId) returnobj.status = str(x.completed) finallist.append(returnobj) return GetEventsResponse(items=finallist)
def getEventsEitherSide(request): timestamp = request.timestamp collegeId = request.collegeId timestampdatetime = dt.datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S') upperbound = timestampdatetime + dt.timedelta(hours=12) lowerbound = timestampdatetime - dt.timedelta(hours=12) print timestampdatetime print upperbound print lowerbound college_key = ndb.Key('CollegeDb', int(collegeId)) print college_key eventlist = Event.query(Event.collegeId == college_key) newList = [] print eventlist for event in eventlist: start_datetime = event.start_time + dt.timedelta(hours=5, minutes=30) #print "Considering" #print event.title #print start_datetime if (start_datetime >= lowerbound and start_datetime <= upperbound): newList.append(event) #eventlist2 = Event.query(ndb.AND(Event.collegeId == college_key, ndb.OR(Event.completed == "N",Event.completed == "No"))).fetch() #print eventlist2 for event in eventlist: if (event.completed == "N" or event.completed == "No"): start_datetime = event.start_time + dt.timedelta(hours=5, minutes=30) if (start_datetime <= timestampdatetime): print event.completed if event not in newList: newList.append(event) newList.sort(key=lambda x: x.start_time) finallist = [] for x in newList: returnobj = GetEventsESReturnForm() returnobj.name = str(x.title) returnobj.startTime = str(x.start_time) returnobj.collegeId = str(x.collegeId) returnobj.status = str(x.completed) finallist.append(returnobj) return GetEventsResponse(items=finallist)
def changeStatusCompletedEvents(): logging.basicConfig(level=logging.DEBUG) LOG = logging.getLogger(__name__) current = dt.datetime.now().replace(microsecond = 0) current_utc = current + dt.timedelta(hours =5,minutes=30) currentDate = current.date() currentTime = current.time() LOG.info("Current datetime") LOG.info(current_utc) eventlist = [] event_query = Event.query(ndb.OR(Event.completed == "N",Event.completed == "No")).fetch() for event in event_query: LOG.info("Event") LOG.info(event.title) end_datetime = event.end_time + dt.timedelta(hours =5,minutes=30) LOG.info(end_datetime) LOG.info(event.completed) if(end_datetime<=current_utc): #event has been completed event.completed = "Yes" event.put()
def changeStatusCompletedEvents(): logging.basicConfig(level=logging.DEBUG) LOG = logging.getLogger(__name__) current = dt.datetime.now().replace(microsecond=0) current_utc = current + dt.timedelta(hours=5, minutes=30) currentDate = current.date() currentTime = current.time() LOG.info("Current datetime") LOG.info(current_utc) eventlist = [] event_query = Event.query( ndb.OR(Event.completed == "N", Event.completed == "No")).fetch() for event in event_query: LOG.info("Event") LOG.info(event.title) end_datetime = event.end_time + dt.timedelta(hours=5, minutes=30) LOG.info(end_datetime) LOG.info(event.completed) if (end_datetime <= current_utc): #event has been completed event.completed = "Yes" event.put()
def getEventsBasedonTimeLeft(): logging.basicConfig(level=logging.DEBUG) LOG = logging.getLogger(__name__) current = dt.datetime.now().replace(microsecond = 0) #current_utc = current - dt.timedelta(hours =5,minutes=30) currentDate = current.date() currentTime = current.time() LOG.info("Current time") LOG.info(currentTime) eventlist = [] event_query = Event.query().fetch() for event in event_query: #LOG.info("Event") #LOG.info(event.title) #LOG.info(event.start_time) start_time_utc = event.start_time - dt.timedelta(hours=5,minutes=30) start_date = start_time_utc.date() diff = start_date - currentDate #LOG.info("Considering this event") #LOG.info(event.title) if(diff == dt.timedelta(hours=0) and diff == dt.timedelta(minutes=0) and diff == dt.timedelta(seconds = 0)): LOG.info("this event is happening today") LOG.info(event.title) start_time = start_time_utc.time() FMT = '%H:%M:%S' tdelta = datetime.strptime(str(start_time), FMT) - datetime.strptime(str(currentTime), FMT) LOG.info("Time delta is") LOG.info(tdelta) b = dt.timedelta(days = 0) c = dt.timedelta(hours = 2) if tdelta >= b: LOG.info("made through first part") if(tdelta<=c): LOG.info(event.title) eventlist.append(event.key) LOG.info("has reached here") LOG.info("Creating notification") group = event.club_id.get() groupName = group.name data = {'message': event.title + "About to start soon","title": groupName, 'id':str(event.key.id()),'type':"Event" } LOG.info(data) #get the followers of the club pids. Get GCM Id's from those and send LOG.info("Event attendees list") LOG.info(event.attendees) attendeeslist = [] if (event.attendees): newNotif = Notifications( clubName = groupName, clubId = event.club_id, clubphotoUrl = group.photoUrl, eventName = event.title, eventId = event.key, timestamp = dt.datetime.now().replace(microsecond = 0), type = "Reminder") for pid in event.attendees: person = pid.get() LOG.info("PID is") LOG.info(person) gcmId = person.gcmId #to_pid = pid) if (gcmId): attendeeslist.append(gcmId) newNotif.to_pid_list.append(pid) #newNotif = Notifications( # clubName = groupName, # clubId = event.club_id, # clubphotoUrl = group.photoUrl, # eventName = event.title, # eventId = event.key, # timestamp = dt.datetime.now().replace(microsecond = 0), # type = "Reminder", # to_pid = pid) newNotifKey = newNotif.put() LOG.info("Attendees GCM list is") LOG.info(attendeeslist) gcm_message = GCMMessage(attendeeslist, data) gcm_conn = GCMConnection() gcm_conn.notify_device(gcm_message) LOG.info("Chill") else: LOG.info("This event is still some time away from notification") else: LOG.info("This event is over") LOG.info(eventlist)
def eventEntry(requestentity=None): event_request = Event() #college = CollegeDb(name = 'NITK',student_sup='Anirudh',collegeId='NITK-123') #college_key = college.put() query = CollegeDb.query() start = "" end = "" flag = 0 profile_key = "" if requestentity: print "Begun" profile_key=ndb.Key('Profile',int(getattr(requestentity,"eventCreator"))) person = profile_key.get() print "Person's email-id ", person.email person_collegeId = person.collegeId for field in ('title','description','clubId','venue','startTime','endTime','attendees','completed','tags','views','isAlumni','eventCreator','collegeId','timestamp','photo','photoUrl'): if hasattr(requestentity, field): print(field,"is there") val = getattr(requestentity, field) if(field=="clubId"): club_key=ndb.Key('Club',int(getattr(requestentity,"clubId"))) setattr(event_request, 'club_id', club_key) elif(field=="views"): setattr(event_request, field, 0) elif field == "eventCreator": profile_key=ndb.Key('Profile',int(getattr(requestentity,"eventCreator"))) person = profile_key.get() print "Person's email-id ", person.email person_collegeId = person.collegeId setattr(event_request, 'event_creator', profile_key) #setattr(event_request, 'from_pid', profile_key) elif field == "startTime": temp = datetime.strptime(getattr(requestentity,"startDate"),"%Y-%m-%d").date() temp1 = datetime.strptime(getattr(requestentity,"startTime"),"%H:%M:%S").time() setattr(event_request,'start_time',datetime.combine(temp,temp1)) start = datetime.combine(temp,temp1) elif field == "endTime": temp = datetime.strptime(getattr(requestentity,"endDate"),"%Y-%m-%d").date() temp1 = datetime.strptime(getattr(requestentity,"endTime"),"%H:%M:%S").time() setattr(event_request,'end_time',datetime.combine(temp,temp1)) end = datetime.combine(temp,temp1) elif field=="photoUrl" and val == None: setattr(event_request, field, "https://lh3.googleusercontent.com/VLbWVdaJaq2HoYnu6J3T5aKC9DP_ku0KC3eelxawe6sqsPdNTarc5Vc0sx6VGqZ1Y-MlguZNd0plkDEZKYM9OnDbvR2tomX-Kg") #elif field == "end_time": # temp = datetime.strptime(getattr(requestentity,field),"%H:%M:%S").time() # setattr(event_request,field,temp) elif field == "attendees": profile_key=ndb.Key('Profile',int(getattr(requestentity,"eventCreator"))) pylist = [] pylist.append(profile_key) setattr(event_request,field,pylist) elif field == "tags": print("TAGS Value is",val) setattr(event_request, field, val) elif val: print("Value is",val) setattr(event_request, field, str(val)) elif field == "collegeId": setattr(event_request, field, person_collegeId) elif field == "timestamp": temp = datetime.strptime(getattr(requestentity,"date"),"%Y-%m-%d").date() temp1 = datetime.strptime(getattr(requestentity,"time"),"%H:%M:%S").time() setattr(event_request,field,datetime.combine(temp,temp1)) print("About to create Event") print(event_request) if(start<end): flag=1 print "SATISFIED" if(flag==1): event_id= event_request.put() print "INSERTED THE EVENT" person = profile_key.get() list1 = person.eventsAttending if list1 == None: list2 = [] list2.append(event_id) person.eventsAttending = list2 person.put() else: person.eventsAttending.append(event_id) person.put() return event_request
def getEventsBasedonTimeLeft(): logging.basicConfig(level=logging.DEBUG) LOG = logging.getLogger(__name__) current = dt.datetime.now().replace(microsecond=0) #current_utc = current - dt.timedelta(hours =5,minutes=30) currentDate = current.date() currentTime = current.time() LOG.info("Current time") LOG.info(currentTime) eventlist = [] event_query = Event.query().fetch() for event in event_query: #LOG.info("Event") #LOG.info(event.title) #LOG.info(event.start_time) start_time_utc = event.start_time - dt.timedelta(hours=5, minutes=30) start_date = start_time_utc.date() diff = start_date - currentDate #LOG.info("Considering this event") #LOG.info(event.title) if (diff == dt.timedelta(hours=0) and diff == dt.timedelta(minutes=0) and diff == dt.timedelta(seconds=0)): LOG.info("this event is happening today") LOG.info(event.title) start_time = start_time_utc.time() FMT = '%H:%M:%S' tdelta = datetime.strptime(str(start_time), FMT) - datetime.strptime( str(currentTime), FMT) LOG.info("Time delta is") LOG.info(tdelta) b = dt.timedelta(days=0) c = dt.timedelta(hours=2) if tdelta >= b: LOG.info("made through first part") if (tdelta <= c): LOG.info(event.title) eventlist.append(event.key) LOG.info("has reached here") LOG.info("Creating notification") group = event.club_id.get() groupName = group.name data = { 'message': event.title + "About to start soon", "title": groupName, 'id': str(event.key.id()), 'type': "Event" } LOG.info(data) #get the followers of the club pids. Get GCM Id's from those and send LOG.info("Event attendees list") LOG.info(event.attendees) attendeeslist = [] if (event.attendees): newNotif = Notifications( clubName=groupName, clubId=event.club_id, clubphotoUrl=group.photoUrl, eventName=event.title, eventId=event.key, timestamp=dt.datetime.now().replace(microsecond=0), type="Reminder") for pid in event.attendees: person = pid.get() LOG.info("PID is") LOG.info(person) gcmId = person.gcmId #to_pid = pid) if (gcmId): attendeeslist.append(gcmId) newNotif.to_pid_list.append(pid) #newNotif = Notifications( # clubName = groupName, # clubId = event.club_id, # clubphotoUrl = group.photoUrl, # eventName = event.title, # eventId = event.key, # timestamp = dt.datetime.now().replace(microsecond = 0), # type = "Reminder", # to_pid = pid) newNotifKey = newNotif.put() LOG.info("Attendees GCM list is") LOG.info(attendeeslist) gcm_message = GCMMessage(attendeeslist, data) gcm_conn = GCMConnection() gcm_conn.notify_device(gcm_message) LOG.info("Chill") else: LOG.info( "This event is still some time away from notification") else: LOG.info("This event is over") LOG.info(eventlist)
def eventEntry(requestentity=None): event_request = Event() #college = CollegeDb(name = 'NITK',student_sup='Anirudh',collegeId='NITK-123') #college_key = college.put() query = CollegeDb.query() start = "" end = "" flag = 0 profile_key = "" if requestentity: print "Begun" profile_key = ndb.Key('Profile', int(getattr(requestentity, "eventCreator"))) person = profile_key.get() print "Person's email-id ", person.email person_collegeId = person.collegeId for field in ('title', 'description', 'clubId', 'venue', 'startTime', 'endTime', 'attendees', 'completed', 'tags', 'views', 'isAlumni', 'eventCreator', 'collegeId', 'timestamp', 'photo', 'photoUrl'): if hasattr(requestentity, field): print(field, "is there") val = getattr(requestentity, field) if (field == "clubId"): club_key = ndb.Key('Club', int(getattr(requestentity, "clubId"))) setattr(event_request, 'club_id', club_key) elif (field == "views"): setattr(event_request, field, 0) elif field == "eventCreator": profile_key = ndb.Key( 'Profile', int(getattr(requestentity, "eventCreator"))) person = profile_key.get() print "Person's email-id ", person.email person_collegeId = person.collegeId setattr(event_request, 'event_creator', profile_key) #setattr(event_request, 'from_pid', profile_key) elif field == "startTime": temp = datetime.strptime( getattr(requestentity, "startDate"), "%Y-%m-%d").date() temp1 = datetime.strptime( getattr(requestentity, "startTime"), "%H:%M:%S").time() setattr(event_request, 'start_time', datetime.combine(temp, temp1)) start = datetime.combine(temp, temp1) elif field == "endTime": temp = datetime.strptime(getattr(requestentity, "endDate"), "%Y-%m-%d").date() temp1 = datetime.strptime( getattr(requestentity, "endTime"), "%H:%M:%S").time() setattr(event_request, 'end_time', datetime.combine(temp, temp1)) end = datetime.combine(temp, temp1) elif field == "photoUrl" and val == None: setattr( event_request, field, "https://lh3.googleusercontent.com/VLbWVdaJaq2HoYnu6J3T5aKC9DP_ku0KC3eelxawe6sqsPdNTarc5Vc0sx6VGqZ1Y-MlguZNd0plkDEZKYM9OnDbvR2tomX-Kg" ) #elif field == "end_time": # temp = datetime.strptime(getattr(requestentity,field),"%H:%M:%S").time() # setattr(event_request,field,temp) elif field == "attendees": profile_key = ndb.Key( 'Profile', int(getattr(requestentity, "eventCreator"))) pylist = [] pylist.append(profile_key) setattr(event_request, field, pylist) elif field == "tags": print("TAGS Value is", val) setattr(event_request, field, val) elif val: print("Value is", val) setattr(event_request, field, str(val)) elif field == "collegeId": setattr(event_request, field, person_collegeId) elif field == "timestamp": temp = datetime.strptime(getattr(requestentity, "date"), "%Y-%m-%d").date() temp1 = datetime.strptime(getattr(requestentity, "time"), "%H:%M:%S").time() setattr(event_request, field, datetime.combine(temp, temp1)) print("About to create Event") print(event_request) if (start < end): flag = 1 print "SATISFIED" if (flag == 1): event_id = event_request.put() print "INSERTED THE EVENT" person = profile_key.get() list1 = person.eventsAttending if list1 == None: list2 = [] list2.append(event_id) person.eventsAttending = list2 person.put() else: person.eventsAttending.append(event_id) person.put() return event_request
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()