示例#1
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.college_id))
        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'):


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

                elif field == "from_pid":
                     print("Entered from_pid")
                     profile =  Profile(
                            name = 'SiddharthSend',
                            email = '*****@*****.**',
                            phone = '7760531993',
                            isAlumni='N',
                            collegeId=college_key
                            )
                     profile_key = profile.put()
                     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
                               )
                     profile_key = profile.put()

                     setattr(clubRequest, field, profile_key)
                elif field == "isAlumni":
                     setattr(clubRequest, field, "N")
                elif field == "collegeId":
                     setattr(clubRequest, field, college_key)
            clubRequest.put()

        return clubRequest
示例#2
0
文件: clubapis.py 项目: RJJ11/SAMPLE
   def getAllColleges(self, request):
        print("Entered get all colleges Portion")
        newList = []
        colleges = CollegeDb.query()
        for x in colleges:
          if(str(x.key.id()) != '5720605454237696' and str(x.key.id()) != '5743114304094208'):
             newList.append(x)

        return Colleges(collegeList=[getColleges(x) for x in newList])
示例#3
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
示例#4
0
   def insertUnique(self,request):

        #This method is just a reference in order for you to reuse this code in order to insert unique entries in the DB
        college = CollegeDb(name = 'NITK',student_sup='Anirudh',collegeId='NITK-123')
        college_key = college.put()
        query = CollegeDb.query()

        profile =  Profile(name = 'RJJ',
                            email = '*****@*****.**',
                            phone = '7760532293',
                            password = '******',
                            pid = '1234',
                            isAlumni='N',
                            collegeId= college_key)

        profileret = Profile.query(Profile.pid == profile.pid).fetch(1)
        print("A is ", profileret)
        if profileret:
          print("Not inserting")
        else :
          print("Inserting")
          profile_key = profile.put()
示例#5
0
   def createClubRequest(self, request):

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

        print("College Ret",college_ret[0])
        if(college_ret):
           club_ret = Club.query(Club.name == request.club_name).filter(Club.abbreviation == request.abbreviation).filter(Club.collegeId == college_ret[0].key).fetch(1)
           print("Club Ret",club_ret)
           if(len(club_ret) == 0):
              clubRequest = createClub(request)
              print("Finished the clubRequest")

              '''newClub = createClubAfterApproval(clubRequest)
              print ("The new club is",newClub)
              #retClub = self.getClub(newClub)'''
        return message_types.VoidMessage()
示例#6
0
def _doProfile(save_request=None):
        """Get user Profile and return to user, possibly updating it first."""
        prof = _getProfileFromUser()
        pf = ProfileMiniForm()

        if save_request:
            for field in pf.all_fields():
                collegeLocation=getattr(save_request,'collegeLocation')
                print collegeLocation,"is location"
                if hasattr(save_request, field.name):
                    val = getattr(save_request, field.name)
                    if field.name is 'collegeLocation':
                        continue
                    if field.name is 'collegeName':
                        college=CollegeDb.query(CollegeDb.name==val,CollegeDb.location==collegeLocation).fetch()
                        setattr(prof,'collegeId',college[0].key)
                    else:
                        setattr(prof,field.name,val)
            prof.put()

        return _copyProfileToForm(prof)
示例#7
0
文件: ClubAPI.py 项目: RJJ11/SAMPLE
def getClub(request=None):

    retClub = ClubMiniForm()
    clubKey = ndb.Key('Club', int(request.club_id))
    club = clubKey.get()

    print("The retrieved club is", club)

    collegeidret = club.collegeId
    adminret = club.admin
    print("Admin ret", adminret)

    if club:
        college = CollegeDb.query(
            CollegeDb.collegeId == collegeidret.get().collegeId).fetch(1)

        print("Club id is", club.key.id())
        retClub.club_id = str(club.key.id())
        retClub.admin = adminret.get().name
        retClub.abbreviation = club.abbreviation
        retClub.name = club.name
        retClub.collegeName = college[0].name
        retClub.description = club.description
        retClub.photoUrl = club.photoUrl
        retClub.membercount = str(len(club.members))
        retClub.followercount = str(len(club.follows))

        if (request.pid != None):
            retClub.isMember = "N"
            retClub.isFollower = "N"
            profileKey = ndb.Key('Profile', int(request.pid))
            print("retrieved profile key is ", profileKey)

            if (profileKey in club.follows):
                retClub.isFollower = "Y"
            if (profileKey in club.members):
                retClub.isMember = "Y"

        #print retClub.members
    return retClub
示例#8
0
def _doProfile(email,save_request=None):
        """Get user Profile and return to user, possibly updating it first."""
        print ("Here Bitch")

        prof = _getProfileFromEmail(email)
        flag=0
        print ("Save Request",save_request)
        

        if save_request:
            print ("Entered here")
            pf = ProfileMiniForm()
            for field in pf.all_fields():
                #collegeLocation=getattr(save_request,'collegeLocation')
                #print collegeLocation,"is location"
                if field.name=='follows_names' or field.name=='follows' or field.name=='clubsJoined' or field.name=='club_names' or field.name=='tags':
                    continue

                if hasattr(save_request, field.name):
                    val = getattr(save_request, field.name)

                

                    if field.name is 'collegeId':
                        #college=CollegeDb.query(CollegeDb.name==val,CollegeDb.location==collegeLocation).fetch()
                        collegeId = ndb.Key('CollegeDb',int(val))
                        print ("coll",collegeId)
                        pylist = [x.key for x in CollegeDb.query()]
                        print pylist
                        if(collegeId in pylist):
                            flag = 1
                            setattr(prof,'collegeId',collegeId)
                        else:
                            flag = 0
                    else:
                        setattr(prof,field.name,val)
            if flag==1:
                prof.put()

        return _copyProfileToForm(prof)
示例#9
0
def getClub(request=None):

    retClub = ClubMiniForm()
    clubKey = ndb.Key("Club", int(request.club_id))
    club = clubKey.get()

    print("The retrieved club is", club)

    collegeidret = club.collegeId
    adminret = club.admin
    print("Admin ret", adminret)

    if club:
        college = CollegeDb.query(CollegeDb.collegeId == collegeidret.get().collegeId).fetch(1)

        print("Club id is", club.key.id())
        retClub.club_id = str(club.key.id())
        retClub.admin = adminret.get().name
        retClub.abbreviation = club.abbreviation
        retClub.name = club.name
        retClub.collegeName = college[0].name
        retClub.description = club.description
        retClub.photoUrl = club.photoUrl
        retClub.membercount = str(len(club.members))
        retClub.followercount = str(len(club.follows))

        if request.pid != None:
            retClub.isMember = "N"
            retClub.isFollower = "N"
            profileKey = ndb.Key("Profile", int(request.pid))
            print("retrieved profile key is ", profileKey)

            if profileKey in club.follows:
                retClub.isFollower = "Y"
            if profileKey in club.members:
                retClub.isMember = "Y"

        # print retClub.members
    return retClub
示例#10
0
def getClub(request=None):

        retClub = ClubMiniForm()
        clubKey = ndb.Key('Club',int(request.club_id))
        club = clubKey.get()

        print("The retrieved club is",club)

        collegeidret = club.collegeId
        adminret = club.admin
        print("Admin ret",adminret)

        if club:
             college = CollegeDb.query(CollegeDb.collegeId == collegeidret.get().collegeId).fetch(1)

             print("Club id is",club.key.id())
             retClub.club_id = str(club.key.id())
             retClub.admin = adminret.get().name
             retClub.abbreviation = club.abbreviation
             retClub.name = club.name
             retClub.collegeName = college[0].name
             retClub.description = club.description
        return retClub
示例#11
0
def _doProfile(email, save_request=None):
    """Get user Profile and return to user, possibly updating it first."""
    print("Here Bitch")

    prof = _getProfileFromEmail(email)
    flag = 0
    print("Save Request", save_request)

    if save_request:
        print("Entered here")
        pf = ProfileMiniForm()
        for field in pf.all_fields():
            #collegeLocation=getattr(save_request,'collegeLocation')
            #print collegeLocation,"is location"
            if field.name == 'follows_names' or field.name == 'follows' or field.name == 'clubsJoined' or field.name == 'club_names' or field.name == 'tags':
                continue

            if hasattr(save_request, field.name):
                val = getattr(save_request, field.name)

                if field.name is 'collegeId':
                    #college=CollegeDb.query(CollegeDb.name==val,CollegeDb.location==collegeLocation).fetch()
                    collegeId = ndb.Key('CollegeDb', int(val))
                    print("coll", collegeId)
                    pylist = [x.key for x in CollegeDb.query()]
                    print pylist
                    if (collegeId in pylist):
                        flag = 1
                        setattr(prof, 'collegeId', collegeId)
                    else:
                        flag = 0
                else:
                    setattr(prof, field.name, val)
        if flag == 1:
            prof.put()

    return _copyProfileToForm(prof)
示例#12
0
def eventEntry(requestentity=None):

        event_request = Event()
        #college = CollegeDb(name = 'NITK',student_sup='Anirudh',collegeId='NITK-123')
        #college_key = college.put()
        query = CollegeDb.query()

        if requestentity:
            print "Begun"
            for field in ('title','description','clubId','venue','date','start_time','attendees','completed','tags','views','isAlumni','event_creator','collegeId'):
                if hasattr(requestentity, field):
                    print(field,"is there")
                    val = getattr(requestentity, field)
                    if(field=="clubId"):
                        club_key=ndb.Key('Club',int(getattr(requestentity,field)))
                        setattr(event_request, field, club_key)


                    elif(field=="views"):
                        setattr(event_request, field, 0)


                    elif field == "event_creator":
                        """profile =  Profile(
                               name = 'SiddharthRec',
                               email = '*****@*****.**',
                               phone = '7760531994',
                               password = '******',
                               pid = '5678',
                               isAlumni='N',
                               collegeId=college_key
                               )
                        profile_key = profile.put()"""
                        profile_key=ndb.Key('Profile',int(getattr(requestentity,field)))
                        person = profile_key.get()
                        print "Person's email-id ", person.email
                        person_collegeId = person.collegeId
                        setattr(event_request, field, profile_key)

                    #setattr(event_request, 'from_pid', profile_key)

                    elif field == "date":
                        temp = datetime.strptime(getattr(requestentity,field),"%Y-%m-%d").date()
                        setattr(event_request,field,temp)

                    elif field == "start_time":
                        temp = datetime.strptime(getattr(requestentity,field),"%H:%M:%S").time()
                        setattr(event_request,field,temp)


                    #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,"event_creator")))
                        pylist = []
                        pylist.append(profile_key)
                        setattr(event_request,field,pylist)

                    elif field == "tags":
                        if (requestentity,field == "None"):
                            continue
                        pylist = getattr(requestentity,field).split(",")
                        length = len(pylist)
                        i = 0
                        newlist = []
                        while(i<length):
                            newlist.append(pylist[i])
                            i = i+1

                        setattr(event_request,field,newlist)

                    elif val:
                        print("Value is",val)
                        setattr(event_request, field, str(val))


                elif field == "collegeId":
                    setattr(event_request, field, person_collegeId)

        print("About to create Event")
        print(event_request)
        event_request.put()

        return event_request
示例#13
0
def postEntry(requestentity=None,check=0):

        newPost = Post()
        #college = CollegeDb(name = 'NITK',student_sup='Anirudh',collegeId='NITK-123')
        #college_key = college.put()
        query = CollegeDb.query()
        club_name = Club.query()
        if check==0:
            print "The request entity key is " + requestentity.club_id
            key1 = ndb.Key('Club',int(requestentity.club_id))
            key2 = ndb.Key('Profile',int(requestentity.from_pid))
        else:
            key1 = requestentity.club_id
            key2 = requestentity.from_pid

        persons = Profile.query()
        #print club_name[0]
        #print "The key is " + club_name[0].key
        club_key = key1
        profile_key = key2
        flag = 0
        print "Profile Key " + str(profile_key)
        for x in persons:
            print x.key
            if(x.key == profile_key):
                print "Same"
                flag=1
            else:
                print "NOPE"
                    #setattr(clubRequest, field, profile_key)

        if(flag==1):
            if requestentity:
                for field in ('title','description','club_id','from_pid','likes','views'):

                    if hasattr(requestentity, field):
                        print(field,"is there")
                        val = getattr(requestentity, field)
                        if(field=="club_id"):
                            print "Club_Id stage"
                            setattr(newPost, field, club_key)

                        elif field == "from_pid":
                            print "Entered here"
                            person = profile_key.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
                            setattr(newPost, field, profile_key)
                            print "Put PID"
                            setattr(newPost,'collegeId',person_collegeId)
                            print "Put college id"

                        elif val:
                            print("Value is",val)
                            setattr(newPost, field, str(val))


                    else:
                        setattr(newPost, "likes", 0)
                        setattr(newPost, "views", 0)

            print("About to create Post")
            print(newPost)
            newPost.put()


        else:
             print "Invalid Person"



        return
示例#14
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
示例#15
0
文件: ClubAPI.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.college_id))
    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.club_name
            elif field == "description":
                clubRequest.description = request.description

            elif field == "from_pid":
                profile_key = ndb.Key('Profile', int(request.from_pid))
                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.from_pid))
                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
示例#16
0
def postEntry(requestentity=None,check=0):

        newPost = Post()
        #college = CollegeDb(name = 'NITK',student_sup='Anirudh',collegeId='NITK-123')
        #college_key = college.put()
        query = CollegeDb.query()
        club_name = Club.query()
        if check==0:
            print "The request entity key is " + requestentity.club_id
            key1 = ndb.Key('Club',int(requestentity.club_id))
            key2 = ndb.Key('Profile',int(requestentity.from_pid))
        else:
            key1 = requestentity.club_id
            key2 = requestentity.from_pid

        persons = Profile.query()
        #print club_name[0]
        #print "The key is " + club_name[0].key
        club_key = key1
        profile_key = key2
        flag = 0
        flag1 = 0
        clubs = Club.query()

        print "Profile Key " + str(profile_key)
        for x in persons:
            print x.key
            if(x.key == profile_key):
                print "Same"
                flag=1
            else:
                print "NOPE"

        for x in clubs:
            print x.key
            if(x.key == club_key):
                print "Same"
                flag1=1
            else:
                print "NOPE"

                    #setattr(clubRequest, field, profile_key)

        if(flag==1 and flag1==1):
            if requestentity:
                for field in ('title','description','club_id','from_pid','likes','views','timestamp','photo','photoUrl'):

                    if hasattr(requestentity, field):
                        print(field,"is there")
                        val = getattr(requestentity, field)
                        if(field=="club_id"):
                            print "Club_Id stage"
                            setattr(newPost, field, club_key)

                        elif field == "from_pid":
                            print "Entered here"
                            person = profile_key.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
                            setattr(newPost, field, profile_key)
                            print "Put PID"
                            setattr(newPost,'collegeId',person_collegeId)
                            print "Put college id"

                        elif field=="timestamp":
                            setattr(newPost, field, val)

                        elif val:
                            print("Value is",val)
                            setattr(newPost, field, str(val))



                    else:
                        if field == "timestamp":
                            temp = datetime.strptime(getattr(requestentity,"date"),"%Y-%m-%d").date()
                            temp1 = datetime.strptime(getattr(requestentity,"time"),"%H:%M:%S").time()
                            setattr(newPost,field,datetime.combine(temp,temp1))

                        setattr(newPost, "likes", 0)
                        setattr(newPost, "views", 0)

            print("About to create Post")
            print(newPost)
            newPost.put()


        else:
             print "Invalid Entry"



        return newPost
示例#17
0
def createCollege(requestentity=None):

    newCollege = CollegeDb()
    query = CollegeDb.query()
    print "The data got on querying is ", query, " type is ", type(query), "\n"
    count = 0
    names = []
    location = []

    """profile =  Profile(name = 'RJJ',
                            email = '*****@*****.**',
                            phone = '7760532293',
                            password = '******',
                            pid = '1234',
                            isAlumni='N',
                            collegeId= 'NIoTK')
        profile_key = profile.put()
        """

    for records in query:
        print "The name of the college is ", records.name, " and location is ", records.location
        names.append(records.name)
        location.append(records.location)
        count += 1
        # print "\n"

    print "count is, ", count

    collegeName = ""
    if requestentity:
        for field in ("name", "abbreviation", "location", "student_sup", "alumni_sup"):
            val = getattr(requestentity, field)
            if field == "name":
                collegeName = getattr(requestentity, field).strip()
            if val:
                val = val.strip()
                print ("Value is", val)
                setattr(newCollege, field, str(val))
        # Now setting the attributes not recieved from the front-end.
        setattr(newCollege, "student_count", 0)
        setattr(newCollege, "group_count", 0)
        newlist = []
        setattr(newCollege, "group_list", newlist)
        # Making CollegeId
        newString = ""
        newString = collegeName[0]
        for x in xrange(len(collegeName)):
            if collegeName[x] == " ":
                newString += collegeName[x + 1]

        setattr(newCollege, "collegeId", newString)

    print (newCollege)
    flag = 0
    for var in xrange(count):
        if newCollege.name == names[var] and newCollege.location == location[var]:
            flag = 1

    if flag:
        print "Sorry already existing record"

    else:
        print "Unique"
        newCollege.put()

    return newCollege
示例#18
0
def createCollege(requestentity=None):

        newCollege = CollegeDb()
        query = CollegeDb.query()
        print "The data got on querying is " , query , " type is ", type(query), "\n"
        count = 0
        names = []
        location = []

        """profile =  Profile(name = 'RJJ',
                            email = '*****@*****.**',
                            phone = '7760532293',
                            password = '******',
                            pid = '1234',
                            isAlumni='N',
                            collegeId= 'NIoTK')
        profile_key = profile.put()
        """

        for records in query:
           print"The name of the college is ", records.name , " and location is " , records.location
           names.append(records.name)
           location.append(records.location)
           count += 1
           #print "\n"

        print "count is, " , count

        collegeName = ""
        if requestentity:
            for field in ('name','abbreviation','location','student_sup','alumni_sup','email'):
                val = getattr(requestentity, field)
                if field == "name":
                    collegeName = getattr(requestentity, field).strip()
                if val:
                    val = val.strip()
                    print("Value is",val)
                    setattr(newCollege, field, str(val))
            #Now setting the attributes not recieved from the front-end.
            setattr(newCollege, 'student_count', 0)
            setattr(newCollege, 'group_count', 0)
            newlist = []
            setattr(newCollege, 'group_list', newlist)
            setattr(newCollege,'sup_emailId',requestentity.email)
            # Making CollegeId
            newString = ""
            newString = collegeName[0]
            for x in xrange(len(collegeName)):
                if(collegeName[x]==' '):
                    newString+=collegeName[x+1]

            setattr(newCollege, 'collegeId', newString)

        print(newCollege)
        flag = 0
        for var in xrange(count):
            if(newCollege.name==names[var] and newCollege.location==location[var]):
                flag=1

        if(flag):
            print "Sorry already existing record"

        else:
            print "Unique"
            email = getattr(requestentity, "email")
            phone = getattr(requestentity, "phone")
            if(getattr(requestentity, "student_sup")==None):
                isAlumni = "Yes"
                person_name = getattr(requestentity, "alumni_sup")
            else:
                isAlumni = "No"
                person_name = getattr(requestentity, "student_sup")

            collegeId = newCollege.put()
            profile =  Profile(name = person_name ,
                            email = email,
                            phone = phone,
                            isAlumni=isAlumni,
                            collegeId= collegeId)
            profile.superadmin.append(collegeId)
            key1 = profile.put()
            return newCollege
示例#19
0
 def getAllColleges(self, request):
      print("Entered get all colleges Portion")
      colleges = CollegeDb.query()
      return Colleges(collegeList=[getColleges(x) for x in colleges])
示例#20
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.college_id))
    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.club_name
            elif field == "description":
                clubRequest.description = request.description

            elif field == "from_pid":
                profile_key = ndb.Key("Profile", int(request.from_pid))
                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.from_pid))
                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
示例#21
0
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
        if requestentity:
            print "Begun"
            for field in ('title','description','club_id','venue','start_time','end_time','attendees','completed','tags','views','isAlumni','event_creator','collegeId','timestamp','photo','photoUrl'):
                if hasattr(requestentity, field):
                    print(field,"is there")
                    val = getattr(requestentity, field)
                    if(field=="club_id"):
                        club_key=ndb.Key('Club',int(getattr(requestentity,field)))
                        setattr(event_request, field, club_key)


                    elif(field=="views"):
                        setattr(event_request, field, 0)


                    elif field == "event_creator":
                        profile_key=ndb.Key('Profile',int(getattr(requestentity,field)))
                        person = profile_key.get()
                        print "Person's email-id ", person.email
                        person_collegeId = person.collegeId
                        setattr(event_request, field, profile_key)

                    #setattr(event_request, 'from_pid', profile_key)

                    elif field == "start_time":
                        temp = datetime.strptime(getattr(requestentity,"start_date"),"%Y-%m-%d").date()
                        temp1 = datetime.strptime(getattr(requestentity,field),"%H:%M:%S").time()
                        setattr(event_request,field,datetime.combine(temp,temp1))
                        start = datetime.combine(temp,temp1)

                    elif field == "end_time":
                        temp = datetime.strptime(getattr(requestentity,"end_date"),"%Y-%m-%d").date()
                        temp1 = datetime.strptime(getattr(requestentity,field),"%H:%M:%S").time()
                        setattr(event_request,field,datetime.combine(temp,temp1))
                        end = datetime.combine(temp,temp1)

                    #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,"event_creator")))
                        pylist = []
                        pylist.append(profile_key)
                        setattr(event_request,field,pylist)

                    elif field == "tags":
                        if (requestentity,field == "None"):
                            continue
                        pylist = getattr(requestentity,field).split(",")
                        length = len(pylist)
                        i = 0
                        newlist = []
                        while(i<length):
                            newlist.append(pylist[i])
                            i = i+1

                        setattr(event_request,field,newlist)

                    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

        if(flag==1):

            event_request.put()

        return event_request
示例#22
0
文件: EventsAPI.py 项目: RJJ11/SAMPLE
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
    if requestentity:
        print "Begun"
        for field in ('title', 'description', 'club_id', 'venue', 'start_time',
                      'end_time', 'attendees', 'completed', 'tags', 'views',
                      'isAlumni', 'event_creator', 'collegeId', 'timestamp',
                      'photo', 'photoUrl'):
            if hasattr(requestentity, field):
                print(field, "is there")
                val = getattr(requestentity, field)
                if (field == "club_id"):
                    club_key = ndb.Key('Club',
                                       int(getattr(requestentity, field)))
                    setattr(event_request, field, club_key)

                elif (field == "views"):
                    setattr(event_request, field, 0)

                elif field == "event_creator":
                    profile_key = ndb.Key('Profile',
                                          int(getattr(requestentity, field)))
                    person = profile_key.get()
                    print "Person's email-id ", person.email
                    person_collegeId = person.collegeId
                    setattr(event_request, field, profile_key)

                #setattr(event_request, 'from_pid', profile_key)

                elif field == "start_time":
                    temp = datetime.strptime(
                        getattr(requestentity, "start_date"),
                        "%Y-%m-%d").date()
                    temp1 = datetime.strptime(getattr(requestentity, field),
                                              "%H:%M:%S").time()
                    setattr(event_request, field,
                            datetime.combine(temp, temp1))
                    start = datetime.combine(temp, temp1)

                elif field == "end_time":
                    temp = datetime.strptime(
                        getattr(requestentity, "end_date"), "%Y-%m-%d").date()
                    temp1 = datetime.strptime(getattr(requestentity, field),
                                              "%H:%M:%S").time()
                    setattr(event_request, field,
                            datetime.combine(temp, temp1))
                    end = datetime.combine(temp, temp1)

                #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,
                                               "event_creator")))
                    pylist = []
                    pylist.append(profile_key)
                    setattr(event_request, field, pylist)

                elif field == "tags":
                    if (requestentity, field == "None"):
                        continue
                    pylist = getattr(requestentity, field).split(",")
                    length = len(pylist)
                    i = 0
                    newlist = []
                    while (i < length):
                        newlist.append(pylist[i])
                        i = i + 1

                    setattr(event_request, field, newlist)

                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

    if (flag == 1):

        event_request.put()

    return event_request