Beispiel #1
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())
Beispiel #2
0
def edit(user):
    person = fluid_filter('fluiddb/users/username="******"' % user)
    if not person:
        abort(404)
    form = ResumeForm()
    person = Person(person[0], user)
    jobs = fluid_filter('has %s/employer' % user)
    jobs = [Work(uid, user) for uid in jobs]
    for job in jobs:
        form.jobs.append_entry()
        # join functions list to paragraph
        job.functions = r"\n".join(job.functions).strip()

    schools = fluid_filter('has %s/attended' % user)
    schools = [Education(uid, user) for uid in schools]
    for school in schools:
        form.schools.append_entry()

    if form.validate_on_submit():
        denied = False
        logging.debug('Valid form for %s' % user)
        password = form.person.password.data

        if not person.update_from_form(form.person):
            denied = True

        for job_form in form.jobs:
            # it seems that we get 1 or more phantom jobs here...
            if not job_form.url.data:
                continue
            # this seems kinda weird, but I'm not sure of a better way to
            # find the correct work object yet
            found_job = False
            logging.info("working on job: %s" % job_form.url.data)
            for job in jobs:
                if job.about == job_form.url.data:
                    if not job.update_from_form(job_form, password):
                        denied = True
                    found_job = True

            if not found_job:
                job = Work.create(job_form.url.data, user)
                if not job.update_from_form(job_form, password):
                    denied = True

        for school_form in form.schools:
            # it seems that we get 1 or more phantom schools here...
            if not school_form.url.data:
                continue
            # this seems kinda weird, but I'm not sure of a better way to
            # find the correct work object yet
            found_school = False
            logging.info("working on school: %s" % school_form.url.data)
            for school in schools:
                if school.about == school_form.url.data:
                    if not school.update_from_form(school_form, password):
                        denied = True
                    found_school = True

            if not found_school:
                school = Education.create(school_form.url.data, user)
                if not school.update_from_form(school_form, password):
                    denied = True

        if form.skills.data:
            OReillySkill.update_from_form(form.skills, user, password)

        if denied:
            flash("Permission Denied!", category='error')
        else:
            flash("Success!", category='info')

        # gotta reload the attributes to show changes
        person.reload_tags()
        for job in jobs:
            job.reload_tags()
        for school in schools:
            school.reload_tags()

    skills = fluid_filter('has %s/skill' % user)
    skills = [OReillySkill(uid) for uid in skills]
    skill_list = json.dumps([{'id'   : skill.uid,
                              'name' : skill.title}
                             for skill in skills])

    return render_template('edit.html', person=person, jobs=jobs,
                           schools=schools, form=form, user=user,
                           skill_list=skill_list)