コード例 #1
0
ファイル: ClubAPI_v1.py プロジェクト: sid-reddevil1803/SAMPLE
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
コード例 #2
0
ファイル: ClubAPI_v1.py プロジェクト: RJJ11/SAMPLE
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