本文整理汇总了Python中models.Person.update_from_form方法的典型用法代码示例。如果您正苦于以下问题:Python Person.update_from_form方法的具体用法?Python Person.update_from_form怎么用?Python Person.update_from_form使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Person
的用法示例。
在下文中一共展示了Person.update_from_form方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit
# 需要导入模块: from models import Person [as 别名]
# 或者: from models.Person import update_from_form [as 别名]
def edit(user):
person = fluid_filter('fluiddb/users/username="%s"' % 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)