• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python helpers.FormHelper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中uni_form.helpers.FormHelper的典型用法代码示例。如果您正苦于以下问题:Python FormHelper类的具体用法?Python FormHelper怎么用?Python FormHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了FormHelper类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_uni_form_formset_with_helper_without_layout

    def test_uni_form_formset_with_helper_without_layout(self):
        template = get_template_from_string(u"""
            {% load uni_form_tags %}
            {% uni_form testFormSet formset_helper %}
        """)
        
        form_helper = FormHelper()    
        form_helper.form_id = 'thisFormsetRocks'
        form_helper.form_class = 'formsets-that-rock'
        form_helper.form_method = 'POST'
        form_helper.form_action = 'simpleAction'
                
        TestFormSet = formset_factory(TestForm, extra = 3)
        testFormSet = TestFormSet()
        
        c = Context({'testFormSet': testFormSet, 'formset_helper': form_helper, 'csrf_token': _get_new_csrf_key()})
        html = template.render(c)        

        self.assertEqual(html.count('<form'), 1)
        self.assertEqual(html.count("<input type='hidden' name='csrfmiddlewaretoken'"), 1)

        # Check formset management form
        self.assertTrue('form-TOTAL_FORMS' in html)
        self.assertTrue('form-INITIAL_FORMS' in html)
        self.assertTrue('form-MAX_NUM_FORMS' in html)
    
        self.assertTrue('class="uniForm formsets-that-rock"' in html)
        self.assertTrue('method="post"' in html)
        self.assertTrue('id="thisFormsetRocks">' in html)
        self.assertTrue('action="%s"' % reverse('simpleAction') in html)
开发者ID:EnTeQuAk,项目名称:django-uni-form,代码行数:30,代码来源:tests.py


示例2: create_game

def create_game(request):
    if request.method == 'POST':
        form = CreateGameForm(request.user, request.POST)
        if form.is_valid():
            game = form.create_game()
            return HttpResponseRedirect(game.get_absolute_url())
    else:
        form = CreateGameForm(request.user)

    # add in a submit button
    helper = FormHelper()
    submit = Submit('create','create a new game')
    helper.add_input(submit)

    # XXX need friends model
    friends = User.objects.exclude(pk=request.user.pk)
    friends_json = json.dumps(dict((u.pk, escape(u.username))
                              for u in friends))

    return {
        'form': form,
        'helper': helper,
        'friends': friends_json,
        'username': request.user.username
    }
开发者ID:keegancsmith,项目名称:scrabble,代码行数:25,代码来源:views.py


示例3: test_change_layout_dynamically_delete_field

    def test_change_layout_dynamically_delete_field(self):
        template = get_template_from_string(
            u"""
            {% load uni_form_tags %}
            {% uni_form form form_helper %}
        """
        )

        form = TestForm()
        form_helper = FormHelper()
        form_helper.add_layout(
            Layout(
                Fieldset(u"Company Data", "is_company", "email", "password1", "password2", css_id="multifield_info"),
                Column("first_name", "last_name", css_id="column_name"),
            )
        )

        # We remove email field on the go
        # Layout needs to be adapted for the new form fields
        del form.fields["email"]
        del form_helper.layout.fields[0].fields[1]

        c = Context({"form": form, "form_helper": form_helper})
        html = template.render(c)
        self.assertFalse("email" in html)
开发者ID:Bauke900,项目名称:dnevnik,代码行数:25,代码来源:tests.py


示例4: test_invalid_helper_method

 def test_invalid_helper_method(self):
     form_helper = FormHelper()
     try:
         form_helper.form_method = "superPost"
         self.fail("Setting an invalid form_method within the helper should raise an Exception")
     except FormHelpersException:
         pass
开发者ID:Bauke900,项目名称:dnevnik,代码行数:7,代码来源:tests.py


示例5: add_job

def add_job(request):
  context_vars = dict()
  context_vars['header'] = capfirst(_('add new job'))
  form = AddJobForm()
  helper = FormHelper()
  helper.form_class = 'uniform'
  submit = Submit('save',_('save'))
  helper.add_input(submit)
  if request.method == "POST":
    form = AddJobForm(request.POST, request.FILES)
    if form.is_valid():
      job = Job()
      job.name = form.cleaned_data['name']
      job.description = form.cleaned_data['description']
      job.start_date = strptime(form.cleaned_data['start_date'], '%Y%m%d')
      job.due_date = strptime(form.cleaned_data['due_date'], '%Y%m%d')
      client_id = form.cleaned_data['client']
      client = Client.objects.get(id=client_id)
      job.clients = [client,]
      job = job.save()
      return HttpResponseRedirect(reverse('workflowmax-job', args=[job.id]))
  
  context_vars['form'] = form
  context_vars['helper'] = helper
  return direct_to_template(request, template='workflowmax/form.html', extra_context=context_vars)
开发者ID:pombredanne,项目名称:xscheduling,代码行数:25,代码来源:views.py


示例6: test_uni_form_helper_form_attributes

    def test_uni_form_helper_form_attributes(self):
        

        template = get_template_from_string("""
            {% load uni_form_tags %}
            {% uni_form form form_helper %}
        """)        

        # First we build a standard form helper
        form_helper = FormHelper()    
        form_helper.form_id = 'this-form-rocks'
        form_helper.form_class = 'forms-that-rock'
        form_helper.form_method = 'GET'
    
        # now we render it
        c = Context({'form':TestForm(),'form_helper':form_helper})            
        html = template.render(c)        
        # Lets make sure everything loads right
        self.assertTrue("""<form""" in html)                
        self.assertTrue("""class="uniForm forms-that-rock" """ in html)
        self.assertTrue("""method="get" """ in html)
        self.assertTrue("""id="this-form-rocks">""" in html)        
        
        # now lets remove the form tag and render it again. All the True items above
        # should now be false because the form tag is removed.
        form_helper.form_tag = False
        c = Context({'form':TestForm(),'form_helper':form_helper})            
        html = template.render(c)        
        self.assertFalse("""<form""" in html)        
        self.assertFalse("""id="this-form-rocks">""" in html)                
        self.assertFalse("""class="uniForm forms-that-rock" """ in html)
        self.assertFalse("""method="get" """ in html)
        self.assertFalse("""id="this-form-rocks">""" in html)
开发者ID:digi604,项目名称:django-uni-form,代码行数:33,代码来源:tests.py


示例7: add_task

def add_task(request, object_id):
  context_vars = dict()
  try:
    object_id = int(object_id)
    job = Job.objects.get(id=object_id)
  except ValueError:
    return HttpResponseRedirect(reverse('job-list'))
  except ObjectDoesNotExist:
    return HttpResponseRedirect(reverse('job-list'))

  form = TaskForm()
  helper = FormHelper()
  submit = Submit('save',_('save'))
  helper.add_input(submit)
  
  if request.method == "POST":
    form = TaskForm(request.POST, request.FILES)
    if form.is_valid():
      task = form.save(commit=False)
      task.job = job
      task.save()
      form.save_m2m()
#      if settings.WORKFLOWMAX_APIKEY and settings.WORKFLOWMAX_ACCOUNTKEY:
#        task.wm_sync()
      messages.success(request, capfirst(_('task was added successfully')), fail_silently=True)
      return HttpResponseRedirect(reverse('job-view', args=[job.id]))
  
  context_vars['form'] = form
  context_vars['helper'] = helper
  return direct_to_template(request, template='job/uniform.html', extra_context=context_vars)  
开发者ID:pombredanne,项目名称:xscheduling,代码行数:30,代码来源:views.py


示例8: edit_job

def edit_job(request, object_id):
  context_vars = dict()
  context_vars['header'] = '%s %s' % (capfirst(_('job')), object_id)
  job = Job.objects.get(id=object_id)
  form = EditJobForm(job.to_dict())
  helper = FormHelper()
  helper.form_class = 'uniform'
  submit = Submit('save',_('save'))
  helper.add_input(submit)
  if request.method == "POST":
    form = EditJobForm(request.POST, request.FILES)
    if form.is_valid():
      job.state = form.cleaned_data['state']
      if form.cleaned_data['assigned']:
        job.assigned = []
        for assigned_id in form.cleaned_data['assigned']:
          try:
            job.assigned.append(Staff.objects.get(id=assigned_id))
          except ResponseStatusError:
            pass
      job.save()
      return HttpResponseRedirect(reverse('workflowmax-job', args=[job.id]))
  
  context_vars['form'] = form
  context_vars['helper'] = helper
  return direct_to_template(request, template='workflowmax/form.html', extra_context=context_vars)
开发者ID:pombredanne,项目名称:xscheduling,代码行数:26,代码来源:views.py


示例9: test_uni_form_formset

    def test_uni_form_formset(self):
        template = get_template_from_string(u"""
            {% load uni_form_tags %}
            {% uni_form testFormSet formset_helper %}
        """)
        
        form_helper = FormHelper()    
        form_helper.form_id = 'this-formset-rocks'
        form_helper.form_class = 'formsets-that-rock'
        form_helper.form_method = 'GET'
        form_helper.form_action = 'simpleAction'
                
        from django.forms.models import formset_factory
        TestFormSet = formset_factory(TestForm, extra = 3)
        testFormSet = TestFormSet()
        
        c = Context({'testFormSet': testFormSet, 'formset_helper': form_helper})
        html = template.render(c)        

        self.assertTrue('<form' in html)
        self.assertEqual(html.count('<form'), 1)
        self.assertTrue('class="uniForm formsets-that-rock"' in html)
        self.assertTrue('method="get"' in html)
        self.assertTrue('id="this-formset-rocks">' in html)
        self.assertTrue('action="%s"' % reverse('simpleAction') in html)
开发者ID:typeish,项目名称:django-uni-form,代码行数:25,代码来源:tests.py


示例10: edit_client

def edit_client(request, object_id):
  try:
    object_id = int(object_id)
  except ValueError:
    return HttpResponseRedirect(reverse('workflowmax-client-list'))
  context_vars = dict()
  context_vars['header'] = '%s %d' % (capfirst(_('client')), object_id)
  client = Client.objects.get(id=object_id)
  form = ClientForm(client.to_dict())
  helper = FormHelper()
  helper.form_class = 'uniform'
  submit = Submit('save',_('save'))
  helper.add_input(submit)
  if request.method == "POST":
    form = ClientForm(request.POST, request.FILES)
    if form.is_valid():
      client.name = form.cleaned_data['name']
      client.address = form.cleaned_data['address']
      client.postal_address = form.cleaned_data['postal_address']
      client.phone = form.cleaned_data['phone']
      client.fax = form.cleaned_data['fax']
      client.website = form.cleaned_data['website']
      client.referral_source = form.cleaned_data['referral_source']
      client.save()
      return HttpResponseRedirect(reverse('workflowmax-client', args=[client.id]))
  
  context_vars['form'] = form
  context_vars['helper'] = helper
  return direct_to_template(request, template='workflowmax/form.html', extra_context=context_vars)
开发者ID:pombredanne,项目名称:xscheduling,代码行数:29,代码来源:views.py


示例11: add_client

def add_client(request):
  context_vars = dict()
  context_vars['header'] = capfirst(_('add new client'))
  form = ClientForm()
  helper = FormHelper()
  helper.form_class = 'uniform'
  submit = Submit('save',_('save'))
  helper.add_input(submit)
  if request.method == "POST":
    form = ClientForm(request.POST, request.FILES)
    if form.is_valid():
      client = Client()
      client.name = form.cleaned_data['name']
      client.address = form.cleaned_data['address']
      client.postal_address = form.cleaned_data['postal_address']
      client.phone = form.cleaned_data['phone']
      client.fax = form.cleaned_data['fax']
      client.website = form.cleaned_data['website']
      client.referral_source = form.cleaned_data['referral_source']
      client = client.save()
      return HttpResponseRedirect(reverse('workflowmax-client', args=[client.id]))
  
  context_vars['form'] = form
  context_vars['helper'] = helper
  return direct_to_template(request, template='workflowmax/form.html', extra_context=context_vars)
开发者ID:pombredanne,项目名称:xscheduling,代码行数:25,代码来源:views.py


示例12: edit_client_contact

def edit_client_contact(request, owner_id, object_id):
  try:
    owner_id = int(owner_id)
  except ValueError:
    return HttpResponseRedirect(reverse('workflowmax-client-list'))
  try:
    object_id = int(object_id)
  except ValueError:
    return HttpResponseRedirect(reverse('workflowmax-client', args=[owner_id]))
  context_vars = dict()
  context_vars['header'] = capfirst(_('edit contact %d') % object_id)
  contact = Contact.objects.get(id=object_id)
  form = ContactForm(contact.to_dict())
  helper = FormHelper()
  helper.form_class = 'uniform'
  submit = Submit('save',_('save'))
  helper.add_input(submit)
  if request.method == "POST":
    form = ContactForm(request.POST, request.FILES)
    if form.is_valid():
      contact.name = form.cleaned_data['name']
      contact.mobile = form.cleaned_data['mobile']
      contact.email = form.cleaned_data['email']
      contact.phone = form.cleaned_data['phone']
      contact.position = form.cleaned_data['position']
      contact.save()
      return HttpResponseRedirect(reverse('workflowmax-client', args=[owner_id]))
  
  context_vars['form'] = form
  context_vars['helper'] = helper
  return direct_to_template(request, template='workflowmax/form.html', extra_context=context_vars)
开发者ID:pombredanne,项目名称:xscheduling,代码行数:31,代码来源:views.py


示例13: edit_staff

def edit_staff(request, object_id):
  try:
    object_id = int(object_id)
  except ValueError:
    return HttpResponseRedirect(reverse('workflowmax-staff-list'))
  context_vars = dict()
  context_vars['header'] = capfirst(_('edit staff %d') % object_id)
  staff = Staff.objects.get(id=object_id)
  form = StaffForm(staff.to_dict())
  helper = FormHelper()
  helper.form_class = 'uniform'
  submit = Submit('save',_('save'))
  helper.add_input(submit)
  if request.method == "POST":
    form = StaffForm(request.POST, request.FILES)
    if form.is_valid():
      staff.name = form.cleaned_data['name']
      staff.address = form.cleaned_data['address']
      staff.phone = form.cleaned_data['phone']
      staff.mobile = form.cleaned_data['mobile']
      staff.email = form.cleaned_data['email']
      staff.payrollcode = form.cleaned_data['payrollcode']
      staff.save()
      return HttpResponseRedirect(reverse('workflowmax-staff', args=[staff.id]))
  
  context_vars['form'] = form
  context_vars['helper'] = helper
  return direct_to_template(request, template='workflowmax/form.html', extra_context=context_vars)
开发者ID:pombredanne,项目名称:xscheduling,代码行数:28,代码来源:views.py


示例14: test_change_layout_dynamically_delete_field

    def test_change_layout_dynamically_delete_field(self):
        template = get_template_from_string(u"""
            {% load uni_form_tags %}
            {% uni_form form form_helper %}
        """)        
        
        form = TestForm()
        form_helper = FormHelper()
        form_helper.add_layout(
            Layout(
                Fieldset(
                    u'Company Data',
                    'is_company',
                    'email',
                    'password1', 
                    'password2',
                    css_id = "multifield_info",
                ),
                Column(
                    'first_name',
                    'last_name',
                    css_id = "column_name",
                )
            )
        )

        # We remove email field on the go
        # Layout needs to be adapted for the new form fields
        del form.fields['email']
        del form_helper.layout.fields[0].fields[1]

        c = Context({'form': form, 'form_helper': form_helper})
        html = template.render(c)
        self.assertFalse('email' in html)
开发者ID:EnTeQuAk,项目名称:django-uni-form,代码行数:34,代码来源:tests.py


示例15: profile_edit

def profile_edit(request, template_name="profiles/profile_edit.html"):

    helper = FormHelper()
    submit = Submit('edit','Edit')
    helper.add_input(submit)
    reset = Reset('reset','Reset')
    helper.add_input(reset)

    profile = get_object_or_404(Profile, user=request.user)
    form = ProfileForm(request.POST or None, instance=profile)

    if form.is_valid():
        form.save()
        msg = 'Profile edited'
        messages.add_message(request, messages.INFO, msg)
        return HttpResponseRedirect(reverse("profile_detail", kwargs={"username":profile.user.username }))

    return render_to_response(template_name,
        {
            "profile": profile,
            "form": form,
            "helper":helper,
        },
        context_instance=RequestContext(request)
    )
开发者ID:kennethlove,项目名称:opencomparison,代码行数:25,代码来源:views.py


示例16: test_second_layout_multifield_column

    def test_second_layout_multifield_column(self):
        form_helper = FormHelper()
        form_helper.add_layout(
            Layout(
                MultiField(
                    'is_company',
                    'email',
                    'password1', 
                    'password2',
                    css_id = "multifield_info",
                ),
                Column(
                    'first_name',
                    'last_name',
                    css_id = "column_name",
                )
            )
        )

        template = get_template_from_string(u"""
            {% load uni_form_tags %}
            {% uni_form form form_helper %}
        """)        
        c = Context({'form': TestForm(), 'form_helper': form_helper})
        html = template.render(c)

        self.assertTrue('multiField' in html)
        self.assertTrue('formColumn' in html)
        self.assertTrue('id="multifield_info"' in html)
        self.assertTrue('id="column_name"' in html)
开发者ID:typeish,项目名称:django-uni-form,代码行数:30,代码来源:tests.py


示例17: test_second_layout_multifield_column_buttonholder_submit

    def test_second_layout_multifield_column_buttonholder_submit(self):
        form_helper = FormHelper()
        form_helper.add_layout(
            Layout(
                MultiField(
                    "Some company data", "is_company", "email", "password1", "password2", css_id="multifield_info"
                ),
                Column("first_name", "last_name", css_id="column_name"),
                ButtonHolder(Submit("Save", "Save", css_class="button white")),
            )
        )

        template = get_template_from_string(
            u"""
            {% load uni_form_tags %}
            {% uni_form form form_helper %}
        """
        )
        c = Context({"form": TestForm(), "form_helper": form_helper})
        html = template.render(c)

        self.assertTrue("multiField" in html)
        self.assertTrue("formColumn" in html)
        self.assertTrue('id="multifield_info"' in html)
        self.assertTrue('id="column_name"' in html)
        self.assertTrue('div class="buttonHolder">' in html)
        self.assertTrue('input type="submit"' in html)
        self.assertTrue('name="save"' in html)
开发者ID:Bauke900,项目名称:dnevnik,代码行数:28,代码来源:tests.py


示例18: edit_note

def edit_note(request, owner_id, object_id):
  context_vars = dict()
  try:
    owner_id = int(owner_id)
    job = Job.objects.get(id=owner_id)
  except ValueError:
    return HttpResponseRedirect(reverse('job-list'))
  except ObjectDoesNotExist:
    return HttpResponseRedirect(reverse('job-list'))
  try:
    object_id = int(object_id)
    note = Note.objects.get(id=object_id)
  except ValueError:
    return HttpResponseRedirect(reverse('job-view', args=[job.id]))
  except ObjectDoesNotExist:
    return HttpResponseRedirect(reverse('job-view', args=[job.id]))

  form = NoteForm(instance=note)
  helper = FormHelper()
  submit = Submit('save',_('save'))
  helper.add_input(submit)
  
  if request.method == "POST":
    form = NoteForm(request.POST, request.FILES, instance=note)
    if form.is_valid():
      form.save()
#      if settings.WORKFLOWMAX_APIKEY and settings.WORKFLOWMAX_ACCOUNTKEY:
#        note.wm_sync()
      messages.success(request, capfirst(_('note was modified successfully')), fail_silently=True)
      return HttpResponseRedirect(reverse('job-view', args=[job.id]))
  
  context_vars['form'] = form
  context_vars['helper'] = helper
  return direct_to_template(request, template='job/uniform.html', extra_context=context_vars)
开发者ID:pombredanne,项目名称:xscheduling,代码行数:34,代码来源:views.py


示例19: helper

 def helper(self):
     helper = FormHelper()
     submit = Submit('submit', 'Submit your application')
     helper.add_input(submit)
     helper.form_action = self.form_action
     helper.form_method = 'POST'
     return helper
开发者ID:keegancsmith,项目名称:Umonya-Website,代码行数:7,代码来源:forms.py


示例20: helper

 def helper(self):
     helper = FormHelper()
     helper.add_input(Submit('submit', _('Search')))
     
     helper.form_action = reverse('search:search')
     helper.form_method = 'get'
     return helper
开发者ID:GISAElkartea,项目名称:antxetamedia,代码行数:7,代码来源:forms.py



注:本文中的uni_form.helpers.FormHelper类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python unicode_helper.p函数代码示例发布时间:2022-05-27
下一篇:
Python underworld.rank函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap