def submit(self, form: models.Form, user_agent: UserAgent): """ 提交表单 """ if form.validate(): session = db.session v = form.values() v.assemble_from_user_agent(user_agent) form.increase_value_sequence() v.sequence = form.value_sequence session.add(v) session.commit() return v return None
def submit(self, form: models.Form, user, user_agent: UserAgent): """ 提交表单 """ if form.validate(): session = db.session v = form.values() v.assemble_from_user_agent(user_agent) user_id = (user and not user.is_anonymous) and user.id or None v.user_id = user_id form.increase_value_sequence() v.sequence = form.value_sequence session.add(v) session.commit() return v return None
def submit(self, form: models.Form, user, user_agent: UserAgent): """ 提交表单 """ if form.validate(): session = db.session v = form.values() v.assemble_from_user_agent(user_agent) user_id = (user and not user.is_anonymous) and user.id or None v.user_id = user_id # 查找所有的选项字段并保存选择的结果 def find_option_id(field, value): for option in field.options: if value == option.value: return option.id return -1 for field in form.select_fields: for value in field.value: choice = Choice(form_id=form.id, field_id=field.id, option_id=find_option_id( field, value['value']), value=value['value']) session.add(choice) form.increase_value_sequence() v.sequence = form.value_sequence session.add(v) session.commit() return v return None