本文整理汇总了Python中uni_form.helpers.FormHelper.form_id方法的典型用法代码示例。如果您正苦于以下问题:Python FormHelper.form_id方法的具体用法?Python FormHelper.form_id怎么用?Python FormHelper.form_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类uni_form.helpers.FormHelper
的用法示例。
在下文中一共展示了FormHelper.form_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_letter
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import form_id [as 别名]
def edit_letter(request, id):
data = {}
letter = Letter.objects.get(id=id)
if not request.user in letter.owners.all():
messages.error(request, _(u"Zugriff verweigert!"))
return redirect_to_prev_page(request)
if not request.method == 'POST':
letter_form = LetterForm(instance=letter)
else:
letter_form = LetterForm(request.POST, instance=letter)
if letter_form.is_valid():
letter = letter_form.save()
messages.success(request, _(u"Brief erfolgreich bearbeitet."))
return redirect(letter)
else:
messages.error(request, _(u"Es gibt noch Fehler im Formular."))
helper = FormHelper()
helper.form_id = "foobar"
helper.form_class = "search"
submit = Submit("send", _(u"Speichern"))
helper.add_input(submit)
reset = Submit("reset", _(u"Zurücksetzen"))
helper.add_input(reset)
data['form'] = letter_form
data['helper'] = helper
data.update(csrf(request))
return render_to_response("lettr/edit_letter.html", data, context_instance=RequestContext(request))
示例2: view_helper
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import form_id [as 别名]
def view_helper(request):
# Create the form
if request.method == "POST":
form = TestForm(request.POST)
else:
form = TestForm()
# create a formHelper
helper = FormHelper()
# Add in a class and id
helper.form_id = 'this-form-rocks'
helper.form_class = 'search'
# add in a submit and reset button
submit = Submit('search','search this site')
helper.add_input(submit)
reset = Reset('reset','reset button')
helper.add_input(reset)
hidden = Hidden('not-seen','hidden value stored here')
helper.add_input(hidden)
# create the response dictionary
response_dictionary = {'form':form, 'helper': helper, 'title':'view helper test'}
return render_to_response('test_app/generic_form_test.html',
response_dictionary,
context_instance=RequestContext(request))
示例3: test_uni_form_helper_form_attributes
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import form_id [as 别名]
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)
示例4: test_uni_form_formset
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import form_id [as 别名]
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)
示例5: test_uni_form_formset_with_helper_without_layout
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import form_id [as 别名]
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)
示例6: render
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import form_id [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))
示例7: test_uni_form_with_helper_attributes
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import form_id [as 别名]
def test_uni_form_with_helper_attributes(self):
form_helper = FormHelper()
form_helper.form_id = 'this-form-rocks'
form_helper.form_class = 'forms-that-rock'
form_helper.form_method = 'GET'
form_helper.form_action = 'simpleAction'
template = get_template_from_string(u"""
{% load uni_form_tags %}
{% uni_form form form_helper %}
""")
# 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)
self.assertTrue('action="%s"' % reverse('simpleAction') 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
html = template.render(c)
self.assertFalse('<form' 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)
示例8: test_uni_form_formset
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import form_id [as 别名]
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 = "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)
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)
示例9: new_letter
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import form_id [as 别名]
def new_letter(request):
data = {}
if not request.method == 'POST':
from datetime import date
data = {'my_date':date.today(),
}
letter_form = LetterForm(data)
letter_form.fields["sender"].queryset = Sender.objects.filter(owners__username=request.user.username)
else:
letter_form = LetterForm(request.POST)
if letter_form.is_valid():
letter = letter_form.save()
ownership = Ownership_Letter.objects.create(owner=request.user, letter=letter)
return redirect(letter)
else:
messages.error(request, _(u"Es gibt noch Fehler im Formular."))
helper = FormHelper()
helper.form_id = "foobar"
helper.form_class = "search"
submit = Submit("send", _(u"Absenden"))
helper.add_input(submit)
reset = Submit("reset", _(u"Zurücksetzen"))
helper.add_input(reset)
data['form'] = letter_form
data['helper'] = helper
data.update(csrf(request))
return render_to_response("lettr/new_letter.html", data, context_instance=RequestContext(request))
示例10: setUp
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import form_id [as 别名]
def setUp(self):
form_helper = FormHelper()
form_helper.form_id = 'this-formset-rocks'
form_helper.form_class = 'formsets-that-rock'
form_helper.form_method = 'GET'
self.c = Context({'formset': TestFormset(),
'formset_helper': form_helper})
示例11: index
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import form_id [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,
},
)
示例12: test_formset_layout
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import form_id [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)
示例13: test_uni_form_helper_generic_attributes
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import form_id [as 别名]
def test_uni_form_helper_generic_attributes(self):
form_helper = FormHelper()
form_helper.form_id = 'this-form-rocks'
form_helper.form_class = 'forms-that-rock'
form_helper.form_method = 'GET'
c = Context({'form':TestForm(),'form_helper':form_helper})
template = get_template_from_string("""
{% load uni_form_tags %}
{% uni_form form form_helper %}
""")
html = template.render(c)
good_response = """<form action="" class="uniForm forms-that-rock" method="POST" id="this-form-rocks" >"""
示例14: helper
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import form_id [as 别名]
def helper(self):
helper = FormHelper()
layout = Layout(
Fieldset('Choose a School or create a new one',
HTML('<div id="choose">'),
Row('school', HTML('<input type="button" id="new" onclick="click_new()" value="Add a new school"/>')),
HTML('</div>'),
HTML('<div id="create">'),
'school_name',
'school_url',
'school_email',
'school_phone',
'school_address',
'school_city',
'school_country',
HTML('<input type="button" id="old" onclick="click_old()" value="Choose an already existent school"/>'),
HTML('</div>'),
),
Fieldset('',
HTML('<p> </p>'),
),
Fieldset('Fill in the course information',
'name',
'lecturer',
'language',
'level',
'type',
'url',
'description',
)
)
helper.add_layout(layout)
submit = Submit('submit','Save')
helper.add_input(submit)
helper.form_method = 'POST'
helper.form_id = 'my_form'
#helper.form_action = "/add_course/?status='old'"
return helper
示例15: test_formset_layout
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import form_id [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)