Example #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)
Example #2
0
def _copyProfileToForm(prof):
    pf = ProfileMiniForm()
    for field in pf.all_fields():
        if hasattr(prof, field.name):
            if field.name == 'collegeId':
                collegeId = getattr(prof, field.name)
                print "College Id"
                print collegeId
                setattr(pf, field.name, str(collegeId.id()))
            elif field.name == 'clubsJoined':
                pylist = []
                for x in prof.clubsJoined:
                    pylist.append(str(x.id()))
                    setattr(pf, field.name, pylist)
            elif field.name == 'follows':
                pylist = []
                for x in prof.follows:
                    pylist.append(str(x.id()))
                    setattr(pf, field.name, pylist)
            elif field.name == 'pid':
                setattr(pf, field.name, str(prof.key.id()))
            else:
                setattr(pf, field.name, getattr(prof, field.name))
        else:
            if field.name == 'clubNames':
                pylist = []
                for x in prof.clubsJoined:
                    ret_club = x.get()
                    #ret_club = obj.get()
                    format_club = ClubMiniForm()
                    format_club.name = ret_club.name
                    format_club.abbreviation = ret_club.abbreviation
                    format_club.adminName = ret_club.admin.get().name
                    format_club.collegeName = ret_club.collegeId.get().name
                    format_club.description = ret_club.description
                    format_club.clubId = str(ret_club.key.id())
                    pylist.append(format_club)
                setattr(pf, field.name, pylist)

            if field.name == 'followsNames':
                pylist = []
                for x in prof.follows:
                    clubs = x.get()
                    pylist.append(clubs.name)
                setattr(pf, field.name, pylist)

            if field.name == 'pid':
                setattr(pf, field.name, str(prof.key.id()))

    pf.check_initialized()
    return pf