本文整理汇总了Python中uni_form.helpers.FormHelper.set_form_action方法的典型用法代码示例。如果您正苦于以下问题:Python FormHelper.set_form_action方法的具体用法?Python FormHelper.set_form_action怎么用?Python FormHelper.set_form_action使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类uni_form.helpers.FormHelper
的用法示例。
在下文中一共展示了FormHelper.set_form_action方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: root
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import set_form_action [as 别名]
def root(request, client_name=None, client_id=None, add_job=False):
client_query = request.GET.get('q', '')
if client_query:
return HttpResponseRedirect(reverse('schedule-client', args=[client_query,]))
context_vars = dict()
context_vars['header'] = capfirst(_('schedule'))
try:
staff = Staff.objects.get(user_ptr=request.user)
context_vars['staff'] = staff
except ObjectDoesNotExist:
staff = None
client = None
if client_id:
try:
client = Client.objects.get(id=client_id)
except ObjectDoesNotExist:
return HttpResponseRedirect(reverse('schedule-root'))
if client_name:
clients = Client.objects.search(client_name)
if clients:
if len(clients) == 1:
client = clients[0]
else:
context_vars['clients'] = clients
else:
context_vars['client_form'] = RootPageClientForm(prefix='client', instance=Client(name=client_name))
context_vars['client_form'].action = reverse('schedule-client-add')
context_vars['address_form'] = RootPageAddressForm(prefix='address')
if client:
context_vars['client'] = client
try:
job = client.jobs.latest()
except ObjectDoesNotExist:
add_job = True
if add_job:
job_form = RootPageAddJobForm()
helper = FormHelper()
helper.set_form_action('%s?return_to=%s' % (reverse('job-add'), reverse('schedule-client-byid', args=[client.id,])))
submit = Submit('save',_('save'))
helper.add_input(submit)
layout = Layout(
HTML('<h3>%s</h3>' % capfirst(_('job details'))),
'description', 'type',
HTML('<h3>%s</h3>' % capfirst(_('time and staff'))),
'start_date', 'due_date', 'staff'
)
helper.add_layout(layout)
context_vars['job_form'] = job_form
client_input = Hidden('client', client.id)
helper.add_input(client_input)
context_vars['helper'] = helper
else:
context_vars['job_edit_form'] = RootPageEditJobForm(instance=job)
editjob_helper = FormHelper()
editjob_helper.set_form_action('%s?return_to=%s' % (reverse('job-edit', args=[job.id]), reverse('schedule-client-byid', args=[client.id,])))
submit = Submit('save',_('save'))
editjob_helper.add_input(submit)
recomended_staff_html = ''
for s in ['%s, ' % staff for staff in job.get_valid_staff()]: recomended_staff_html +=s
layout = Layout(
'state',
Row(HTML('<span style="color:red">Recommended: %s</span>' % recomended_staff_html), HTML('<a href="%s">%s</a>' % (reverse('staff-add'), _('add new'))), 'staff'),
)
editjob_helper.add_layout(layout)
context_vars['edit_job_helper'] = editjob_helper
context_vars['staff_list'] = Staff.objects.all()
return direct_to_template(request, template='schedule/root.html', extra_context=context_vars)