Пример #1
0
def postRequest(requestentity=None):

        post_request = Post_Request()
        #college = CollegeDb(name = 'NITK',student_sup='Anirudh',collegeId='NITK-123')
        #college_key = college.put()
        query = CollegeDb.query()
        key1 = ndb.Key('Club',int(requestentity.club_id))
        key2 = ndb.Key('Profile',int(requestentity.from_pid))
        club_key = key1
        print "Club key"
        print key1
        profile_key = key2
        #change the ID portion when merging with front end
                    #setattr(clubRequest, field, profile_key)

        if requestentity:
            for field in ('to_pid','club_id','description','status','post_request_id','collegeId','title','from_pid','likers'):
                if hasattr(requestentity, field):
                    print(field,"is there")
                    val = getattr(requestentity, field)
                    if(field=="club_id"):
                        setattr(post_request, field, club_key)
                    elif(field=="from_pid"):
                        setattr(post_request, field, profile_key)
                    elif val:
                        print("Value is",val)
                        setattr(post_request, field, str(val))



                elif field == "to_pid":

                    query = club_key.get()
                    print query
                    admin_id = query.admin
                    person = admin_id.get()
                    print "Person's email-id ", person.email
                    person_collegeId = person.collegeId
                    print "His college Id ", person.collegeId
                    college_details = person_collegeId.get()
                    print "The sup is ", college_details.student_sup
                    print("Finished to-pid")
                    setattr(post_request, field,admin_id)
                elif field == "status":
                    setattr(post_request, field, "Yes")
                elif field == "post_request_id":
                    setattr(post_request, field, "ABCD123")
                elif field == "collegeId":
                    setattr(post_request, field, person_collegeId)

        print("About to createClubRequest")
        print(post_request)
        post_request.put()

        return post_request
Пример #2
0
   def getPostRequests(self, request):
        """Update & return user profile."""

        to_pid = ndb.Key('Profile',int(request.pid))
        query = Post_Request.query(Post_Request.to_pid==to_pid)


        return GetAllPostRequests(items=[copyPostRequestToForm(x) for x in query])
Пример #3
0
   def getPostRequests(self, request):
        """Update & return user profile."""

        to_pid = ndb.Key('Profile',int(request.pid))
        query = Post_Request.query(Post_Request.to_pid==to_pid).order(-Post_Request.timestamp)


        return GetAllPostRequests(items=[copyPostRequestToForm(x) for x in query])
Пример #4
0
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.club_id
    pid = request.pid
    print("Club_key_id", club_key_id)
    clubKey = ndb.Key('Club', int(request.club_id))
    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()
Пример #5
0
def postRequest(requestentity=None):

        post_request = Post_Request()
        #college = CollegeDb(name = 'NITK',student_sup='Anirudh',collegeId='NITK-123')
        #college_key = college.put()
        query = CollegeDb.query()
        key1 = ndb.Key('Club',int(requestentity.club_id))
        key2 = ndb.Key('Profile',int(requestentity.from_pid))
        club_key = key1
        print "Club key"
        print key1
        profile_key = key2
        #change the ID portion when merging with front end
                    #setattr(clubRequest, field, profile_key)

        if requestentity:
            for field in ('to_pid','club_id','description','status','post_request_id','collegeId','title','from_pid','likers','timestamp','photoUrl'):
                if hasattr(requestentity, field):
                    print(field,"is there")
                    val = getattr(requestentity, field)
                    if(field=="club_id"):
                        setattr(post_request, field, club_key)
                    elif(field=="from_pid"):
                        setattr(post_request, field, profile_key)
                    elif val:
                        print("Value is",val)
                        setattr(post_request, field, str(val))



                elif field == "to_pid":

                    query = club_key.get()
                    print query
                    admin_id = query.admin
                    person = admin_id.get()
                    print "Person's email-id ", person.email
                    person_collegeId = person.collegeId
                    print "His college Id ", person.collegeId
                    college_details = person_collegeId.get()
                    print "The sup is ", college_details.student_sup
                    print("Finished to-pid")
                    setattr(post_request, field,admin_id)
                elif field == "status":
                    setattr(post_request, field, "Yes")
                elif field == "post_request_id":
                    setattr(post_request, field, "ABCD123")
                elif field == "collegeId":
                    setattr(post_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(post_request,field,datetime.combine(temp,temp1))
                
        

        print("About to createClubRequest")
        print(post_request)
        post_request.put()

        return post_request
Пример #6
0
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.club_id
    pid = request.pid
    print("Club_key_id", club_key_id)
    clubKey = ndb.Key("Club", int(request.club_id))
    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()