当前位置: 首页>>代码示例>>Python>>正文


Python FormHelper.add_layout方法代码示例

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


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

示例1: helper

# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_layout [as 别名]
    def helper(self):
        helper = FormHelper()
    
        style = """
        <style>
            .uniForm label, .uniForm .label {
                display: inline;
            }
        </style>

        """

        layout = Layout(
            Fieldset('',
                     'email', 
                     'first_name',
                     'last_name',
                     'url',
                     'phone',
                     'work_address',
                     'city',
                     'country',
                     HTML(style),
                     'image',
                     )
            )
        
        helper.add_layout(layout)

        submit = Submit('submit','Update')
        helper.add_input(submit)
        helper.form_method = 'POST'

        return helper
开发者ID:marianabb,项目名称:REBUS,代码行数:36,代码来源:forms.py

示例2: test_change_layout_dynamically_delete_field

# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_layout [as 别名]
    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,代码行数:27,代码来源:tests.py

示例3: render

# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_layout [as 别名]
	def render (self, request, dct):
		## Preconditions & preparation:
		results = msgs = None
		cls = self.__class__
		
		## Main:
		# instantiate form in one of several ways ...
		form_cls = cls.ToolForm
		# if the form has been submitted...
		if request.method == 'POST':
			form = form_cls (request.POST, request.FILES)
			# if the form is valid
			if form.is_valid():
				# get the clean data and do the work
				msgs, results = self.process_form (form.cleaned_data)
			else:
				msgs, results = (
					messages.Error ('there was a problem processing the form'),
				)
		else:
			# if you're coming to the form anew, make an unbound form
			form = form_cls()

		helper = FormHelper()
		
		# Add in a class and id
		helper.form_id = 'this-form-rocks'
		helper.form_class = 'tool_form'
		
		# if necessary, do fieldsets
		if cls.fieldsets:
			sets = []
			for field_pair in cls.fieldsets:
				if (isinstance (field_pair, basestring)):
					# if just a naked field name
					field_pair = ['', field_pair]
				sets.append (Fieldset (*field_pair))
			helper.add_layout (Layout(*sets))
					

		# add in submit actions and a reset button
		for button in cls.actions:
			submit = Submit (button[0], button[1])
			helper.add_input (submit)
		reset = Reset ('reset','Reset form')
		helper.add_input (reset)
		
		## Postconditions & return:
		context = self.context()
		context.update ({
			'identifier' : self.identifier,
			'title' : self.title,
			'description': self.description,
			'form': form,
			'results': results,
			'msgs': msgs,
			'helper': helper,
		})
		return render_to_response ('relais.amergin/tool.html', context,
			context_instance=RequestContext(request))
开发者ID:agapow,项目名称:Amergin,代码行数:62,代码来源:toolcontroller.py

示例4: test_second_layout_multifield_column_buttonholder_submit

# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_layout [as 别名]
    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,代码行数:30,代码来源:tests.py

示例5: test_change_layout_dynamically_delete_field

# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_layout [as 别名]
    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,代码行数:36,代码来源:tests.py

示例6: test_second_layout_multifield_column

# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_layout [as 别名]
    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,代码行数:32,代码来源:tests.py

示例7: setUp

# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_layout [as 别名]
    def setUp(self):

        self.style = '<style>.formRow{color:red;}</style>'

        layout = Layout(
            # first fieldset shows the company
            Fieldset('', 'is_company'),
            # second fieldset shows the contact info
            Fieldset('Contact details',
                     'email',
                     Row('password1','password2'),
                     'first_name',
                     'last_name', ) )

        form_helper = FormHelper()
        form_helper.add_layout(layout)

        self.c = Context({'formset': TestFormset(),
                          'formset_helper': form_helper})

        template = get_template_from_string("""
{% load uni_form_tags %}
{% uni_form_set formset formset_helper %}
        """)
        self.html = template.render(self.c)
开发者ID:digi604,项目名称:django-uni-form,代码行数:27,代码来源:tests.py

示例8: index

# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_layout [as 别名]
    def index(cls, request):
        ## Preconditions & preparation:
        results = msgs = None

        ## Main:
        # instantiate form in one of several ways ...
        form_cls = cls.ToolForm
        # if the form has been submitted...
        if request.method == "POST":
            form = form_cls(request.POST, request.FILES)
            # if the form is valid
            if form.is_valid():
                # get the clean data and do the work
                msgs, results = cls.process_form(form.cleaned_data)
            else:
                msgs = [messages.Error("there was problem processing the form")]
        else:
            # if you're coming to the form anew, make an unbound form
            form = form_cls()

        helper = FormHelper()

        # Add in a class and id
        helper.form_id = "this-form-rocks"
        helper.form_class = "tool_form"

        # if necessary, do fieldsets
        if cls.fieldsets:
            sets = []
            for field_pair in cls.fieldsets:
                if isinstance(field_pair, basestring):
                    # if just a naked field name
                    field_pair = ["", field_pair]
                sets.append(Fieldset(*field_pair))
            helper.add_layout(Layout(*sets))

            # add in submit actions and a reset button
        for button in cls.actions:
            submit = Submit(button[0], button[1].title())
            helper.add_input(submit)
        reset = Reset("reset", "Reset form")
        helper.add_input(reset)

        ## Postconditions & return:
        return render_to_response(
            "relais.amergin/base_tool.html",
            {
                "identifier": cls.identifier,
                "title": cls.title,
                "description": cls.description,
                "form": form,
                "results": results,
                "messages": msgs,
                "helper": helper,
            },
        )
开发者ID:agapow,项目名称:Amergin,代码行数:58,代码来源:basetool.py

示例9: advanced_search

# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_layout [as 别名]
def advanced_search(request, reset=False):
    marketplace = request.marketplace

    if reset:
        form = AdvancedSearchForm(marketplace=marketplace)
    else:
        form = AdvancedSearchForm(marketplace=marketplace, data=request.GET)


    if request.GET.get("do"):

        result_list = []
        if form.is_valid():
    
            result_list = form.search()
            
            pager = Paginator(result_list, settings.HAYSTACK_SEARCH_RESULTS_PER_PAGE)

            try:
                page = int(request.GET.get("page", "1"))
            except:
                page = 1

            try:
                paginator = pager.page(page)
            except (EmptyPage, InvalidPage):
                raise Http404

            paged = (pager.num_pages > 1)

            return render_to_response(
                "%s/buy/advanced_search_results.html" % marketplace.template_prefix, 
                {"result_list": paginator, "form": form,  
                 "pages": pager.page_range, "paged": paged, "total": pager.count, 
                 "view_mode": form.cleaned_data["view_by"]}, RequestContext(request))

    form_helper = FormHelper()
    layout = Layout(
        Fieldset("", "q"),
        Fieldset("", Row("categories", "subcategories")),
        Fieldset("", "include"),
        Fieldset("", Row("from_price", "to_price")),
        Fieldset("", "sort"),
        Fieldset("", "view_by"),
    )
    form_helper.add_layout(layout)
    submit = Submit("do", _("Search"))
    submit.field_classes = "button_primary"
    form_helper.add_input(submit)

    return render_to_response(
        "%s/buy/advanced_search.html" % marketplace.template_prefix, 
        {"form": form, "helper": form_helper} , RequestContext(request))
开发者ID:MechanisM,项目名称:CollectorCity-Market-Place,代码行数:55,代码来源:views.py

示例10: test_formset_layout

# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_layout [as 别名]
    def test_formset_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'
        form_helper.add_layout(
            Layout(
                Fieldset("Item {{ forloop.counter }}",
                    'is_company',
                    'email',
                ),
                HTML("{% if forloop.first %}Note for first form only{% endif %}"),
                Row('password1', 'password2'),
                Fieldset("",
                    'first_name',
                    'last_name'
                )
            )
        )
                
        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)        

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

        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)

        # Check form layout
        self.assertTrue('Item 1' in html)
        self.assertTrue('Item 2' in html)
        self.assertTrue('Item 3' in html)
        self.assertEqual(html.count('Note for first form only'), 1)
        self.assertEqual(html.count('formRow'), 3)
开发者ID:EnTeQuAk,项目名称:django-uni-form,代码行数:53,代码来源:tests.py

示例11: edit_job

# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_layout [as 别名]
def edit_job(request, object_id):
  return_to = request.GET.get('return_to', '')

  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'))

  try:
    staff = Staff.objects.get(user_ptr=request.user)
    if not job in staff.jobs.all():
      return HttpResponseRedirect(reverse('job-list'))
  except ObjectDoesNotExist:
    pass

  context_vars['header'] = capfirst(_('edit job %s') % job.name)
  job_form = EditJobForm(instance=job)
  helper = FormHelper()
  submit = Submit('save',_('save'))
  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'),
    Row(HTML('<a href="%s">%s</a>' % (reverse('supplier-add'), _('add new'))), 'suppliers'),
    )
  helper.add_layout(layout)

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

示例12: test_double_rendered_field

# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_layout [as 别名]
    def test_double_rendered_field(self):
        form = TestForm()

        form_helper = FormHelper()
        form_helper.add_layout(Layout("is_company", "is_company"))

        template = get_template_from_string(
            u"""
            {% load uni_form_tags %}
            {% uni_form form form_helper %}
        """
        )
        c = Context({"form": TestForm(), "form_helper": form_helper})
        settings.UNIFORM_FAIL_SILENTLY = False
        self.assertRaises(Exception, lambda: template.render(c))
        del settings.UNIFORM_FAIL_SILENTLY
开发者ID:Bauke900,项目名称:dnevnik,代码行数:18,代码来源:tests.py

示例13: test_double_rendered_field

# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_layout [as 别名]
    def test_double_rendered_field(self):
        form = TestForm()
        
        form_helper = FormHelper()
        form_helper.add_layout(
            Layout(
                'is_company', 'is_company'
            )
        )

        template = get_template_from_string(u"""
            {% load uni_form_tags %}
            {% uni_form form form_helper %}
        """)        
        c = Context({'form': TestForm(), 'form_helper': form_helper})
        self.assertRaises(Exception, lambda:template.render(c))
开发者ID:typeish,项目名称:django-uni-form,代码行数:18,代码来源:tests.py

示例14: test_layout_within_layout

# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_layout [as 别名]
    def test_layout_within_layout(self):
        form_helper = FormHelper()
        form_helper.add_layout(
            Layout(
                Layout(
                    MultiField("Some company data",
                        'is_company',
                        'email',
                        css_id = "multifield_info",
                    ),
                ),
                Column(
                    'first_name',
                    # 'last_name', Missing a field on purpose
                    css_id = "column_name",
                    css_class = "columns",
                ),
                ButtonHolder(
                    Submit('Save', 'Save', css_class='button white'),
                ),
                Div(
                    'password1', 
                    'password2',
                    css_id="custom-div",
                    css_class="customdivs",
                )
            )
        )

        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('class="formColumn columns"' in html)
        self.assertTrue('class="buttonHolder">' in html)
        self.assertTrue('input type="submit"' in html)
        self.assertTrue('name="save"' in html)
        self.assertTrue('id="custom-div"' in html)
        self.assertTrue('class="customdivs"' in html)
        self.assertTrue('last_name' in html)
开发者ID:EnTeQuAk,项目名称:django-uni-form,代码行数:49,代码来源:tests.py

示例15: test_layout_fieldset_row_html_with_unicode_fieldnames

# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_layout [as 别名]
    def test_layout_fieldset_row_html_with_unicode_fieldnames(self):
        form_helper = FormHelper()
        form_helper.add_layout(
            Layout(
                Fieldset(
                    u'Company Data',
                    u'is_company',
                    css_id = "fieldset_company_data",
                    css_class = "fieldsets"
                ),
                Fieldset(
                    u'User Data',
                    u'email',
                    Row(
                        u'password1', 
                        u'password2',
                        css_id = "row_passwords",
                        css_class = "rows"
                    ),
                    HTML('<a href="#" id="testLink">test link</a>'),
                    HTML(u"""
                        {% if flag %}{{ message }}{% endif %}
                    """),
                    u'first_name',
                    u'last_name',
                )
            )
        )

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

        self.assertTrue('id="fieldset_company_data"' in html)
        self.assertTrue('class="fieldsets' in html)
        self.assertTrue('id="row_passwords"' in html)
        self.assertTrue('class="formRow rows"' in html)
        self.assertTrue('Hello!' in html)
        self.assertTrue('testLink' in html)
开发者ID:EnTeQuAk,项目名称:django-uni-form,代码行数:49,代码来源:tests.py


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