本文整理汇总了Python中pyramid_simpleform.Form.validate方法的典型用法代码示例。如果您正苦于以下问题:Python Form.validate方法的具体用法?Python Form.validate怎么用?Python Form.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid_simpleform.Form
的用法示例。
在下文中一共展示了Form.validate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SearchView
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import validate [as 别名]
class SearchView(BaseView):
def __init__(self, request):
BaseView.__init__(self, request)
self.form = Form(self.request, schema=SearchFormAsin())
@view_config(route_name='search_form',
renderer='templates/results.mako')
def finder(self):
items = []
if self.request.POST:
data = self._validate_input()
query_params, can_be_executed = query_preparator.prepare_params(data)
if can_be_executed:
items = item_getter.execute_query(query_params)
else:
self.request.session.flash('Please provide less than 5 asins')
return dict(form=FormRenderer(self.form),
items=items)
def _validate_input(self):
self.form.validate()
if self.form.errors:
self.request.session.flash('Please provide asins')
return self.form.data
示例2: band_add
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import validate [as 别名]
def band_add(request):
form = Form(request, BandSchema)
if 'form.submitted' in request.POST and not form.validate():
# form didn't validate
request.session.flash('form does not validate!')
if 'form.submitted' in request.POST and form.validate():
request.session.flash('form validated!')
dbsession = DBSession()
band_registrar = request.user
if 'registrar_is_member' in form.data:
request.session.flash(
"reg_is_member: " + form.data['registrar_is_member'])
band = Band(
name=form.data['band_name'],
homepage=form.data['band_homepage'],
email=form.data['band_email'],
registrar=request.user.username,
registrar_id=request.user.id,
)
dbsession.add(band)
dbsession.flush()
return HTTPFound(route_url('band_view', request, band_id=band.id))
return {
'viewer_username': authenticated_userid(request),
'form': FormRenderer(form)
}
示例3: concept_save_view
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import validate [as 别名]
def concept_save_view(request):
if "concept" in request.POST:
form = Form(request, schema=ConceptAnswersSchema())
if form.validate():
answers = []
concept_answers = form.bind(models.ConceptAnswer())
concept = concept_answers.concept
concept_answers = concept_answers.concept_answer
for concept_answer in concept_answers:
answer = models.ConceptAnswer()
answer.concept = concept
answer.concept_answer = concept_answer
answers.append(answer)
with transaction.manager:
models.DBSession.add_all(answers)
else:
print form.all_errors()
print "NOT VALIDATED"
return "I saw it"
form = Form(request, schema=ConceptSchema())
concept_model = None
if form.validate():
concept = form.bind(models.Concept())
#with transaction.manager:
# models.DBSession.add(concept)
concept_model = models.DBSession.merge(concept)
models.DBSession.flush()
return HTTPFound(request.route_url("concept_edit_page", page="Concepts",\
concept_id=concept_model.id))
else:
print "Failed"
示例4: license_create
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import validate [as 别名]
def license_create(request):
viewer_username = authenticated_userid(request)
if viewer_username == "":
viewer_username = "not logged in"
# form = Form(request, LicenseSchema)
form = Form(request)
if 'form.submitted' in request.POST and not form.validate():
# form didn't validate
request.session.flash('form does not validate!')
request.session.flash(form.data['license_name'])
request.session.flash(form.data['license_url'])
if 'form.submitted' in request.POST and form.validate():
request.session.flash('form validated!')
license_name = form.data['license_name']
license = License(
license_name=form.data['license_name'],
license_album=form.data['license_album'],
license_url=form.data['license_url'],
)
dbsession.add(license)
request.session.flash(u'writing to database ...')
# ToDo: https://redmine.local/issues/5
return {
'viewer_username': viewer_username,
'form': FormRenderer(form)
}
示例5: test_is_validated_with_specified_params
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import validate [as 别名]
def test_is_validated_with_specified_params(self):
from pyramid_simpleform import Form
request = testing.DummyRequest()
request.method = "POST"
form = Form(request, SimpleFESchema)
form.validate(params={'name' : 'foo'})
obj = form.bind(SimpleObj())
self.assert_(obj.name == 'foo')
示例6: manage
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import validate [as 别名]
def manage(self):
errors = None
if self.request.method == 'POST':
sid = self.request.params.get('sid', None)
else:
sid = self.request.matchdict.get('sid', None)
try:
if sid: #edit
model = supplierService.GetSupplier(sid, self.TenantId)
if not model:
return HTTPFound(location='/suppliers/index')
form = Form(self.request, schema=SupplierSchema, obj=model)
cntform = vForm(prefix='suppliercontact-', request=self.request, schema=ContactSchema, obj=model.Contacts[0])
valid = form.validate()
valid = cntform.validate() and valid
if valid:
form.bind(model)
cntform.bind(model.Contacts[0])
model.UpdatedBy = self.UserId
model.Status = True
if supplierService.SaveSupplier(model):
return HTTPFound(location='/suppliers/index')
else:
errors = 'Unable to add suppliers details!'
else: #add
model = Supplier()
form = Form(self.request, schema=SupplierSchema, defaults={})
cntform = vForm(prefix='suppliercontact-', request=self.request, schema=ContactSchema, defaults={})
valid = form.validate()
valid = cntform.validate() and valid
if valid:
model = form.bind(Supplier())
contact = cntform.bind(SupplierContactDetails())
model.Contacts.append(contact)
model.TenantId = self.TenantId
model.CreatedBy = self.UserId
model.Status = True
if supplierService.AddSupplier(model):
return HTTPFound(location='/suppliers/index')
else:
errors = 'Unable to save suppliers details!'
except Exception, e:
errors = str(e)
示例7: test_bind_with_include
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import validate [as 别名]
def test_bind_with_include(self):
from pyramid_simpleform import Form
request = testing.DummyRequest()
request.method = "POST"
request.POST['name'] = 'test'
form = Form(request, SimpleFESchema)
form.validate()
obj = form.bind(SimpleObj(), include=['foo'])
self.assert_(obj.name == None)
示例8: test_bind
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import validate [as 别名]
def test_bind(self):
from pyramid_simpleform import Form
request = testing.DummyRequest()
request.method = "POST"
request.POST["name"] = "test"
form = Form(request, SimpleFESchema)
form.validate()
obj = form.bind(SimpleObj())
self.assert_(obj.name == "test")
示例9: test_bind_with_exclude
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import validate [as 别名]
def test_bind_with_exclude(self):
from pyramid_simpleform import Form
request = testing.DummyRequest()
request.method = "POST"
request.POST["name"] = "test"
form = Form(request, SimpleFESchema)
form.validate()
obj = form.bind(SimpleObj(), exclude=["name"])
self.assertTrue(obj.name == None)
示例10: managepurchase
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import validate [as 别名]
def managepurchase(self):
errors = None
model = None
form = None
productmodel = Product()
pForm = Form(self.request, schema=ProductSchema, defaults=productmodel.toDict())
log.info(self.request.method)
if self.request.method == 'GET':
pid = self.request.matchdict.get('pid', None)
else:
pid = self.request.params.get('pid', None)
lstSuppliers = self.GetSuppliers()
try:
if pid:
model = stockService.GetPurchase(pid, self.TenantId)
if not model:
return HTTPFound(location='/stock/purchases')
form = Form(self.request, schema=PurchaseSchema, obj=model)
if form.validate():
form.bind(model)
model.TenantId = self.TenantId
model.UpdatedBy = self.UserId
model.Status = True
if stockService.SavePurchase(model):
return HTTPFound(location=self.request.route_url('purchases'))
else:
errors = 'Unable to save purchase details!'
else:
model = Purchase()
form = Form(self.request, schema=PurchaseSchema, defaults=model.toDict())
if form.validate():
model = form.bind(Purchase())
model.TenantId = self.TenantId
model.CreatedBy = self.UserId
model.Status = True
if stockService.AddPurchase(model):
return HTTPFound(location=self.request.route_url('editpurchase',pid=model.Id))
else:
errors = 'Unable to save purchase details!'
except Exception, e:
errors = str(e)
log.debug(e)
DBSession.rollback()
示例11: band_edit
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import validate [as 别名]
def band_edit(request):
band_id = request.matchdict['band_id']
band = Band.get_by_band_id(band_id)
if not isinstance(band, Band):
msg = "Band id not found in database" # TODO: check template!
return HTTPFound(route_url('not_found', request))
# no change through form, so reuse old value (for now)
band_registrar = band.registrar
band_registrar_id = band.registrar_id
form = Form(request, schema=BandEditSchema, obj=band)
if 'form.submitted' in request.POST and not form.validate():
# form didn't validate
request.session.flash('form does not validate!')
#request.session.flash(form.data['name'])
#request.session.flash(form.data['homepage'])
#request.session.flash(form.data['email'])
if 'form.submitted' in request.POST and form.validate():
if form.data['name'] != band.name:
band.name = form.data['name']
if DEBUG: # pragma: no cover
print "changing band name"
request.session.flash('changing band name')
if form.data['homepage'] != band.homepage:
band.homepage = form.data['homepage']
if DEBUG: # pragma: no cover
print "changing band homepage"
request.session.flash('changing band homepage')
if form.data['email'] != band.email:
band.email = form.data['email']
if DEBUG: # pragma: no cover
print "changing band email"
request.session.flash('changing band email')
# TODO: trigger email_verification process
#request.session.flash(u'writing to database ...')
dbsession.flush()
# if all went well, redirect to band view
return HTTPFound(route_url('band_view', request, band_id=band.id))
return {
'viewer_username': authenticated_userid(request),
'form': FormRenderer(form)
}
示例12: test_errorlist_with_field
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import validate [as 别名]
def test_errorlist_with_field(self):
from pyramid_simpleform import Form
from pyramid_simpleform.renderers import FormRenderer
request = testing.DummyRequest()
request.method = "POST"
form = Form(request, SimpleFESchema)
form.validate()
renderer = FormRenderer(form)
self.assertEqual(renderer.errorlist("name"), '<ul class="error"><li>Missing value</li></ul>')
示例13: manage
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import validate [as 别名]
def manage(self):
errors = None
if self.request.method == 'POST':
cid = self.request.params.get('cid', None)
else:
cid = self.request.matchdict.get('cid', None)
try:
if cid:
model = customerService.GetCustomer(cid, self.TenantId)
if not model:
return HTTPFound(location='/customers/index')
form = Form(self.request, schema=CustomerSchema, obj=model)
cntform = Form(self.request, schema=ContactSchema, obj=model.Contacts[0])
if form.validate() and cntform.validate():
form.bind(model)
cntform.bind(model.Contacts[0])
model.UpdatedBy = self.UserId
model.Status = True
if customerService.SaveCustomer(model):
return HTTPFound(location='/customers/index')
else:
errors = 'Unable to add customer details!'
else:
model = Customer()
form = Form(self.request, schema=CustomerSchema, defaults={})
cntform = Form(self.request, schema=ContactSchema, defaults={})
if form.validate() and cntform.validate():
model = form.bind(Customer())
contact = cntform.bind(CustomerContactDetails())
model.Contacts.append(contact)
model.TenantId = self.TenantId
model.CreatedBy = self.UserId
model.Status = True
log.info('adding new customer')
if customerService.AddCustomer(model):
return HTTPFound(location='/customers/index')
else:
errors = 'Unable to save customer details!'
except Exception, e:
errors = str(e)
示例14: test_errorlist_with_no_errors
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import validate [as 别名]
def test_errorlist_with_no_errors(self):
from pyramid_simpleform import Form
from pyramid_simpleform.renderers import FormRenderer
request = testing.DummyRequest()
request.method = "POST"
request.POST['name'] = 'test'
form = Form(request, SimpleFESchema)
form.validate()
renderer = FormRenderer(form)
self.assert_(renderer.errorlist() == '')
示例15: user_add
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import validate [as 别名]
def user_add(request):
form = Form(request, schema=RegistrationSchema)
if "form.submitted" in request.POST and form.validate():
session = DBSession()
username = form.data["username"]
user = User(username=username, password=form.data["password"], name=form.data["name"], email=form.data["email"])
session.add(user)
headers = remember(request, username)
redirect_url = request.route_url("main")
return HTTPFound(location=redirect_url, headers=headers)
login_form = login_form_view(request)
return {
"form": FormRenderer(form),
"toolbar": toolbar_view(request),
"cloud": cloud_view(request),
"latest": latest_view(request),
"login_form": login_form,
}