本文整理汇总了Python中uni_form.helpers.FormHelper类的典型用法代码示例。如果您正苦于以下问题:Python FormHelper类的具体用法?Python FormHelper怎么用?Python FormHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FormHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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
}
示例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)
示例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
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
)