def createResume(): ''' Add a new resume to the resume dashboard. Resumes are given a unique URL that users can share them. They are accessible to anyone with the URL. ''' if 'username' not in login_session: return redirect(url_for('welcome')) form = ResumeForm() if request.method == 'POST' and form.validate_on_submit(): user = getUserInfo(user_id=login_session['user_id']) #Create unique code for resume to use in the resume's URL. code = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in xrange(6)) #In the unlikely event resume code already exists, create a new one. while session.query(Resume).filter_by(code = code).first(): code = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in xrange(6)) #Store the courses required for the resume. course_ids_for_resume = request.form.getlist('course') for course_id in course_ids_for_resume: courseAndResume = ResumeCourse(code = code, course_id = course_id) session.add(courseAndResume) newResume = Resume(code = code, user_id = user.id, title = form.title.data) session.add(newResume) session.commit() flash('New Resume Successfully Created') return redirect(url_for('fullResumeList', code=code, user_id = login_session['user_id'])) else: courses = session.query(Course).filter_by(user_id = login_session['user_id']) return render_template('newresume.html', courses = courses, time = time.time(), form = form)
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)