예제 #1
0
def _doProfile(email, save_request=None):
    """Get user Profile and return to user, possibly updating it first."""
    print("Here Bitch")

    prof = _getProfileFromEmail(email)
    print("Profile is", prof)

    if (prof.email == ''):
        key = None
    else:
        key = prof.key
        print key
    flag = 0
    college = CollegeDb()
    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 == 'followsNames' or field.name == 'follows' or field.name == 'clubsJoined' or field.name == 'club_names':
                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))
                    college = collegeId.get()
                    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:
            k1 = prof.put()

            if (key == None):
                length = college.student_count
                if (length == None):
                    length = 0

                length = length + 1
                college.student_count = length
                college.put()

            print "Inserted"
            print k1

    return _copyProfileToForm(prof)
예제 #2
0
파일: ClubAPI_v1.py 프로젝트: RJJ11/SAMPLE
def getClub(request=None):

    retClub = ClubMiniForm()
    clubKey = ndb.Key('Club', int(request.clubId))
    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.clubId = str(club.key.id())
        retClub.adminName = 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
예제 #3
0
def getClub(request=None):

        retClub = ClubMiniForm()
        clubKey = ndb.Key('Club',int(request.clubId))
        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.clubId = str(club.key.id())
             retClub.adminName = 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
예제 #4
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.clubId
            key1 = ndb.Key('Club',int(requestentity.clubId))
            key2 = ndb.Key('Profile',int(requestentity.fromPid))
        else:
            key1 = requestentity.clubId
            key2 = requestentity.fromPid

        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','clubId','fromPid','likes','views','timestamp','photo','photoUrl','tags'):

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

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

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

                        elif field=="photoUrl" and val == None:
                            setattr(newPost, field, "https://lh3.googleusercontent.com/VLbWVdaJaq2HoYnu6J3T5aKC9DP_ku0KC3eelxawe6sqsPdNTarc5Vc0sx6VGqZ1Y-MlguZNd0plkDEZKYM9OnDbvR2tomX-Kg")

                        elif field=="tags":
                            print("Value is",val)
                            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
예제 #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.clubId))
        key2 = ndb.Key('Profile',int(requestentity.fromPid))
        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','clubId','description','status','post_request_id','collegeId','title','fromPid','likers','timestamp','photoUrl'):
                if hasattr(requestentity, field):
                    print(field,"is there")
                    val = getattr(requestentity, field)
                    if(field=="clubId"):
                        setattr(post_request, 'club_id', club_key)
                    elif(field=="fromPid"):
                        setattr(post_request, 'from_pid', 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 createPostRequest")
        print(post_request)
        post_request.put()

        return post_request
예제 #6
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
        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
예제 #7
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
    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
예제 #8
0
파일: PostsAPI_v1.py 프로젝트: RJJ11/SAMPLE
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.clubId
        key1 = ndb.Key('Club', int(requestentity.clubId))
        key2 = ndb.Key('Profile', int(requestentity.fromPid))
    else:
        key1 = requestentity.clubId
        key2 = requestentity.fromPid

    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', 'clubId', 'fromPid', 'likes',
                          'views', 'timestamp', 'photo', 'photoUrl', 'tags'):

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

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

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

                    elif field == "photoUrl" and val == None:
                        setattr(
                            newPost, field,
                            "https://lh3.googleusercontent.com/VLbWVdaJaq2HoYnu6J3T5aKC9DP_ku0KC3eelxawe6sqsPdNTarc5Vc0sx6VGqZ1Y-MlguZNd0plkDEZKYM9OnDbvR2tomX-Kg"
                        )

                    elif field == "tags":
                        print("Value is", val)
                        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
예제 #9
0
파일: PostsAPI_v1.py 프로젝트: RJJ11/SAMPLE
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.clubId))
    key2 = ndb.Key('Profile', int(requestentity.fromPid))
    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', 'clubId', 'description', 'status',
                      'post_request_id', 'collegeId', 'title', 'fromPid',
                      'likers', 'timestamp', 'photoUrl'):
            if hasattr(requestentity, field):
                print(field, "is there")
                val = getattr(requestentity, field)
                if (field == "clubId"):
                    setattr(post_request, 'club_id', club_key)
                elif (field == "fromPid"):
                    setattr(post_request, 'from_pid', 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 createPostRequest")
    print(post_request)
    post_request.put()

    return post_request
예제 #10
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
예제 #11
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
예제 #12
0
def _doProfile(email,save_request=None):
        """Get user Profile and return to user, possibly updating it first."""
        print ("Here Bitch")

        prof = _getProfileFromEmail(email)
        print ("Profile is",prof)

        if(prof.email == ''):
           key = None 
        else:
           key = prof.key
           print key   
        flag=0
        college = CollegeDb()
        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=='followsNames' or field.name=='follows' or field.name=='clubsJoined' or field.name=='club_names':
                    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))
                        college = collegeId.get()
                        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:
                k1 = prof.put()
                
                if (key==None):
                    length = college.student_count
                    if(length == None):
                       length = 0                   
 
                    length = length + 1
                    college.student_count = length
                    college.put()

                print "Inserted"
                print k1

        return _copyProfileToForm(prof)
예제 #13
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','studentSup','alumniSup','email'):
                val = getattr(requestentity, field)
                if field == "name":
                    collegeName = getattr(requestentity, field).strip()
                if val:
                    val = val.strip()
                    print("Value is",val)
                    if field == 'studentSup':
                        setattr(newCollege, 'student_sup', str(val))
                    elif field == 'alumniSup':
                        setattr(newCollege, 'alumni_sup', str(val))
                    else:
                        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, "studentSup")==None):
                isAlumni = "Yes"
                person_name = getattr(requestentity, "alumniSup")
            else:
                isAlumni = "No"
                person_name = getattr(requestentity, "studentSup")

            collegeId = newCollege.put()
            profile =  Profile(name = person_name ,
                            email = email,
                            phone = phone,
                            isAlumni=isAlumni,
                            collegeId= collegeId)
            profile.superadmin.append(collegeId)
            key1 = profile.put()
            newCollege.student_count = 1
            newCollege.put()
            return newCollege
예제 #14
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', 'studentSup',
                      'alumniSup', 'email'):
            val = getattr(requestentity, field)
            if field == "name":
                collegeName = getattr(requestentity, field).strip()
            if val:
                val = val.strip()
                print("Value is", val)
                if field == 'studentSup':
                    setattr(newCollege, 'student_sup', str(val))
                elif field == 'alumniSup':
                    setattr(newCollege, 'alumni_sup', str(val))
                else:
                    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, "studentSup") == None):
            isAlumni = "Yes"
            person_name = getattr(requestentity, "alumniSup")
        else:
            isAlumni = "No"
            person_name = getattr(requestentity, "studentSup")

        collegeId = newCollege.put()
        profile = Profile(name=person_name,
                          email=email,
                          phone=phone,
                          isAlumni=isAlumni,
                          collegeId=collegeId)
        profile.superadmin.append(collegeId)
        key1 = profile.put()
        newCollege.student_count = 1
        newCollege.put()
        return newCollege