Пример #1
0
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()
Пример #2
0
def createClub(request=None):

    #When createClubRequest is called

    print("Request Entity for Create Club ", request)
    clubRequest = Club_Creation()

    collegeId = ndb.Key('CollegeDb', int(request.collegeId))
    college = CollegeDb.query(CollegeDb.key == collegeId).fetch(1)

    college_key = college[0].key

    if request and college:

        for field in ('abbreviation', 'club_name', 'from_pid', 'to_pid',
                      'isAlumni', 'collegeId', 'description',
                      'approval_status', 'photoUrl', 'timestamp'):

            if field == "abbreviation":
                clubRequest.abbreviation = request.abbreviation
            elif field == "club_name":
                clubRequest.club_name = request.clubName
            elif field == "description":
                clubRequest.description = request.description

            elif field == "from_pid":
                profile_key = ndb.Key('Profile', int(request.fromPid))
                print("Finished frompid")
                setattr(clubRequest, field, profile_key)
            elif field == "to_pid":
                '''print("Entered To PID")
                     profile =  Profile(
                               name = 'SiddharthRec',
                               email = '*****@*****.**',
                               phone = '7760531994',
                               isAlumni='N',
                               collegeId=college_key
                               )'''
                #get the college of the from_pid guy
                #Get the email of the college
                #correspond it to the SUP profile
                #get his key and save it

                from_pid_key = ndb.Key('Profile', int(request.fromPid))
                from_profile = from_pid_key.get()

                print("From Profile is", from_profile)
                college_key = from_profile.collegeId
                college = college_key.get()

                email = college.sup_emailId

                print("Email is", email)

                query = Profile.query(Profile.email == email).fetch(1)

                if (query[0]):
                    to_pid_key = query[0].key
                    print("to_pid_key", to_pid_key)
                    setattr(clubRequest, field, to_pid_key)
            elif field == "isAlumni":
                setattr(clubRequest, field, "N")
            elif field == "collegeId":
                setattr(clubRequest, field, college_key)
            elif field == "approval_status":
                setattr(clubRequest, field, "N")
            elif field == "photoUrl":
                if (request.photoUrl):
                    setattr(clubRequest, field, str(request.photoUrl))

            elif field == "timestamp":
                print("Going to enter timestamp")
                setattr(clubRequest, field,
                        dt.datetime.now().replace(microsecond=0))

        clubRequest.put()

    return clubRequest
Пример #3
0
def createClub(request=None):

        #When createClubRequest is called

        print("Request Entity for Create Club ", request)
        clubRequest = Club_Creation()


        collegeId = ndb.Key('CollegeDb',int(request.collegeId))
        college = CollegeDb.query(CollegeDb.key == collegeId).fetch(1)

        college_key = college[0].key



        if request and college :

            for field in ('abbreviation','club_name','from_pid','to_pid','isAlumni','collegeId','description','approval_status','photoUrl','timestamp'):


                if field == "abbreviation":
                    clubRequest.abbreviation = request.abbreviation
                elif field == "club_name":
                    clubRequest.club_name = request.clubName
                elif field == "description":
                    clubRequest.description = request.description

                elif field == "from_pid":
                     profile_key = ndb.Key('Profile',int(request.fromPid))
                     print("Finished frompid")
                     setattr(clubRequest, field, profile_key)
                elif field == "to_pid":
                     '''print("Entered To PID")
                     profile =  Profile(
                               name = 'SiddharthRec',
                               email = '*****@*****.**',
                               phone = '7760531994',
                               isAlumni='N',
                               collegeId=college_key
                               )'''
                     #get the college of the from_pid guy
                     #Get the email of the college
                     #correspond it to the SUP profile
                     #get his key and save it

                     from_pid_key = ndb.Key('Profile',int(request.fromPid))
                     from_profile = from_pid_key.get()

                     print("From Profile is",from_profile)
                     college_key = from_profile.collegeId
                     college = college_key.get()

                     email = college.sup_emailId

                     print("Email is",email)

                     query = Profile.query(Profile.email == email).fetch(1)

                     if(query[0]):
                         to_pid_key = query[0].key
                         print("to_pid_key",to_pid_key)
                         setattr(clubRequest, field, to_pid_key)
                elif field == "isAlumni":
                     setattr(clubRequest, field, "N")
                elif field == "collegeId":
                     setattr(clubRequest, field, college_key)
                elif field == "approval_status":
                     setattr(clubRequest, field, "N")
                elif field == "photoUrl":
                     if(request.photoUrl):
                         setattr(clubRequest, field, str(request.photoUrl))

                elif field == "timestamp":
                     print ("Going to enter timestamp")
                     setattr(clubRequest, field, dt.datetime.now().replace(microsecond = 0))
                

            clubRequest.put()

        return clubRequest
Пример #4
0
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()