本文整理汇总了Python中uni_form.helpers.FormHelper.add_input方法的典型用法代码示例。如果您正苦于以下问题:Python FormHelper.add_input方法的具体用法?Python FormHelper.add_input怎么用?Python FormHelper.add_input使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类uni_form.helpers.FormHelper
的用法示例。
在下文中一共展示了FormHelper.add_input方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_game
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_input [as 别名]
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
}
示例2: render
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_input [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))
示例3: edit_note
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_input [as 别名]
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)
示例4: new_letter
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_input [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))
示例5: edit_letter
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_input [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))
示例6: add_task
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_input [as 别名]
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)
示例7: helper
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_input [as 别名]
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
示例8: profile_edit
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_input [as 别名]
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)
)
示例9: edit_client
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_input [as 别名]
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)
示例10: add_client
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_input [as 别名]
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)
示例11: edit_client_contact
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_input [as 别名]
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)
示例12: add_job
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_input [as 别名]
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)
示例13: edit_job
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_input [as 别名]
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)
示例14: edit_staff
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_input [as 别名]
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)
示例15: helper
# 需要导入模块: from uni_form.helpers import FormHelper [as 别名]
# 或者: from uni_form.helpers.FormHelper import add_input [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