示例#1
0
 def setUpClass(cls):
     fluid.login(USERNAME, PASSWORD)
     # create necessary tags
     rpcs = []
     for cls in [Person, Education, Work]:
         for tag in cls.TAGS:
             rpc = fluid.post('/tags/test', async=True,
                              body={'name' : tag,
                                    'description' : None,
                                    'indexed' : True})
             rpcs.append(rpc)
     for rpc in rpcs:
         resp = fluid.result(rpc)
         if resp.status_code not in [201, 412]:
             print 'Failed to create tag: %s' % tag
             print resp.headers
             sys.exit(1)
     fluid.logout()
示例#2
0
def cv(user):
    # quick check to make sure the user actually exists
    resp = fluid.get('/users/%s' % user)
    if resp.status_code == 404:
        abort(404)
    person_rpc = Person.filter('fluiddb/users/username="******"', user, async=True)
    # check for person's picture
    #logging.debug('Checking for %s/picture at %s' % (user, person.picture))
    #h = httplib2.Http()
    #head, cont = h.request(person.picture, 'HEAD')
    #if head['status'] == '200':
    #    person.has_pic = True
    #    logging.debug('%s/picture exists' % user)
    #else:
    #    person.has_pic = False
    #    logging.debug('%s/picture does not exist. Returned %s status' % (
    #        user, head['status']))
    # find user's jobs
    work_rpc = Work.filter('has %s/employer', user, async=True)
    # find user's schools
    school_rpc = Education.filter('has %s/attended', user, async=True)
    # find user's publications
    #publications = fluid_filter('has %s/publication' % user)
    #publications = [Publication(uid, user) for uid in publications]
    publications = []
    # find user's skills associated with o'reilly books
    oskill_rpc = OReillySkill.filter(
            'has %s/skill and has %%s/title' % user, 'oreilly.com', async=True)

    resp = fluid.result(person_rpc)
    logging.info('Person filter for %s returned %d' % (user, resp.status_code))
    if resp.status_code == 200 and resp.content['results']['id']:
        [(uid, tags)] = resp.content['results']['id'].items()
        person = Person(uid, user, tags)
    else:
        abort(404)

    resp = fluid.result(work_rpc)
    logging.info('Work filter for %s returned %d' % (user, resp.status_code))
    if resp.status_code == 200 and resp.content['results']['id']:
        resp = resp.content['results']['id']
        jobs = Work.from_response(user, resp)
    else:
        #FIXME need better error handling
        jobs = []

    resp = fluid.result(school_rpc)
    logging.info('School filter for %s returned %d' % (user, resp.status_code))
    if resp.status_code == 200 and resp.content['results']['id']:
        resp = resp.content['results']['id']
        schools = Education.from_response(user, resp)
    else:
        schools = []

    resp = fluid.result(oskill_rpc)
    logging.info('Skill filter for %s returned %d' % (user, resp.status_code))
    if resp.status_code == 200 and resp.content['results']['id']:
        resp = resp.content['results']['id']
        oskills = OReillySkill.from_response(resp)
    else:
        oskills = []

    return render_template('cv.html', person=person, jobs=jobs,
                           schools=schools, publications=publications,
                           oskills=oskills,
                           current_date=datetime.now().date())