本文整理汇总了Python中pyramid_simpleform.Form.bind方法的典型用法代码示例。如果您正苦于以下问题:Python Form.bind方法的具体用法?Python Form.bind怎么用?Python Form.bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid_simpleform.Form
的用法示例。
在下文中一共展示了Form.bind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: concept_save_view
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import bind [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"
示例2: login
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import bind [as 别名]
def login(self):
if self.logged_in:
self.request.session.flash('You are already connected!', queue='notice')
return HTTPFound(
location=self.request.route_url('home')
)
self.c.pagename = 'Login'
self.c.active_header_nav = 'tools'
self.c.active_footer_nav = 'tools-login'
params = self.request.params
form = Form(self.request, schema=LoginForm, obj=params)
if form.validate():
form.bind(params)
#clear the cache for user
User.by_username(params.get('username'), invalidate=True)
user = User.by_username(params.get('username'), cache=None)
if user:
password = params.get('password')
if user.password == User.pass_crypt(password)\
and user.status == 1:
user.last_login_date = sa.func.now()
self.request.session.flash(u'Welcome back %s !' % user.username, queue='success')
headers = security.remember(self.request,
user.username)
return HTTPFound(location=self.request.route_url('home'),
headers=headers)
self.request.session.flash(u'Wrong username or password!', queue='notice')
return {
'item': params,
'form': FormRenderer(form)
}
示例3: update_ticket
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import bind [as 别名]
def update_ticket(self):
project = self.context.project
ticket = self.context.ticket
form = Form(self.request, schema=s.TicketSchema, obj=ticket)
if form.validate():
form.bind(ticket)
return HTTPFound(location=h.ticket_url(self.request, ticket))
示例4: edit
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import bind [as 别名]
def edit(request):
"""customer edit """
id = request.matchdict['id']
dbsession = DBSession()
customer = dbsession.query(Customer).filter_by(id=id).one()
print customer
address = dbsession.query(Address).filter_by(user_id=id).one()
if customer is None or address is None:
request.session.flash("error;Customer not found!")
return HTTPFound(location=request.route_url("customer_list"))
generalForm = Form(request, schema=CustomerForm, obj=customer)
locationForm = Form(request, schema=LocationForm, obj=address)
if "general_submitted" in request.POST and generalForm.validate():
generalForm.bind(customer)
dbsession.add(customer)
request.session.flash("success; Successful call to update customer")
if "location_submitted" in request.POST:
locationForm.bind(address)
dbsession.add(address)
request.session.flash("success; Successful call to update location")
action_url = request.route_url("customer_edit", id=id)
return dict(generalForm=FormRenderer(generalForm),
locationForm=FormRenderer(locationForm),
action_url=action_url)
示例5: password_edit_view
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import bind [as 别名]
def password_edit_view(request):
""" Render the change password form page.
Seek the database for the user datas based on user_id used in the route. If
the user did not exist then add an error flash message and redirect to the
user list.
If the user exist then render an empty password form. If the form is
validated then change the user password in the database and add
success flash message. If the form is not valid, then display again the
form with validation errors.
:param request: a ``pyramid.request`` object
"""
_ = request.translate
user_id = request.matchdict['user_id']
user = AuthUser.get_by_id(user_id)
if not user:
request.session.flash(_(u"This user did not exist!"), 'error')
return HTTPFound(location=request.route_path('tools.user_list'))
form = Form(request, schema=UserPasswordForm, obj=user)
if 'form_submitted' in request.params and form.validate():
form.bind(user)
DBSession.add(user)
request.session.flash(_(u"Password updated."), 'success')
return HTTPFound(location=request.route_path('tools.user_list'))
return dict(renderer=FormRenderer(form))
示例6: index
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import bind [as 别名]
def index(self):
tenant = None
errors = None
success = None
tenantForm = None
contactForm = None
try:
tenantService = TenantService()
tenant = tenantService.GetTenantDetails(self.TenantId)
tenantForm = Form(self.request, schema=TenantSchema, obj=tenant)
contactForm = vForm(
request=self.request, prefix="tenantcontact-", schema=ContactSchema, obj=tenant.Contacts[0]
)
valid = tenantForm.validate()
valid = contactForm.validate() and valid
if valid:
tenantForm.bind(tenant)
contactForm.bind(tenant.Contacts[0])
tenant.UpdatedBy = self.UserId
tenant.UpdatedOn = datetime.utcnow()
if tenantService.SaveTenant(tenant):
success = "Company details saved successfully!"
else:
errors = "Error while saving Company details. Please try later."
except Exception, e:
log.info(e)
errors = e.message
示例7: edit
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import bind [as 别名]
def edit(txt, request):
if not request.usr:
return HTTPForbidden()
form = Form(request, TxtSchema, obj=txt)
if form.validate():
form.bind(txt)
request.bus.fire(TxtEditedEvent(txt=txt))
return HTTPFound(location=request.route_url('txt.view', txt_id=txt.id))
return {'form': FormRenderer(form), 'txt': txt}
示例8: usr_edit
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import bind [as 别名]
def usr_edit(request):
form = Form(request, EditSchema(usr=request.usr), obj=request.usr)
if form.validate():
form.bind(request.usr)
DBSession.add(request.usr)
request.session.flash(('success', u'Saved changes to profile.'))
return HTTPFound(
location=request.route_url('usr.view')
)
return {'usr': request.usr, 'form': FormRenderer(form)}
示例9: manage
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import bind [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)
示例10: usr_passwd
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import bind [as 别名]
def usr_passwd(request):
form = Form(request, PasswdSchema)
if form.validate():
form.bind(request.usr)
DBSession.add(request.usr)
request.session.flash(('success', u'Password successfully changed.'))
return HTTPFound(
location=request.route_url('usr.view')
)
return {'usr': request.usr, 'form': FormRenderer(form)}
示例11: save
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import bind [as 别名]
def save(self):
instance_id = self.request.params.get('instance_id')
query = models.DBSession.query(models.InstanceModel)
instance = query.filter_by(instance_id=instance_id).first()
if instance is None:
raise exc.HTTPNotFound()
form = Form(self.request, schema=self.schema, obj=instance)
if not form.validate():
raise exc.HTTPBadRequest()
form.bind(instance)
return {"result": "ok"}
示例12: addpurchaselineitem
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import bind [as 别名]
def addpurchaselineitem(self):
purchaseId = self.request.params.get('pid', None)
supplierId = self.request.params.get('SupplierId', None)
if purchaseId and supplierId:
model = None
productId = self.request.params.get('ProductId', None)
quantity = float(self.request.params.get('Quantity', 0.0))
taxAmount = float(self.request.params.get('TaxAmount', 0.0))
try:
if productId:
model = stockService.GetProduct(productId, self.TenantId)
if not model:
model = Product()
pForm = Form(self.request, schema=ProductSchema, obj=model)
if pForm.validate():
pForm.bind(model)
model.SupplierId = supplierId
model.TenantId = self.TenantId
model.Status = True
if model.Id:
model.UpdatedBy = self.UserId
stockService.SaveProduct(model)
else:
model.CreatedBy = self.UserId
stockService.AddProduct(model)
litem = PurchaseLineItem()
litem.PurchaseId = purchaseId
litem.ProductId = model.Id
litem.Name = model.Name
litem.Barcode = model.Barcode
litem.MRP = model.MRP
litem.Tax = taxAmount
litem.BuyPrice = model.BuyPrice
litem.Discount = model.Discount
litem.Quantity = quantity
result = stockService.AddPurchaseLineItem(litem, self.TenantId)
if result:
return dict(status=True, id=litem.Id, message="Item added successfully!")
else:
DBSession.rollback()
else:
log.info('pForm validate failed : %s!' % (pForm.all_errors()))
return dict(status=False, message=pForm.all_errors())
except Exception, e:
log.debug(e)
DBSession.rollback()
return dict(status=False, message=e.message)
示例13: managepurchase
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import bind [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()
示例14: signup_post
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import bind [as 别名]
def signup_post(request):
dbsession = DBSession()
settings = request.registry.settings
form = Form(request, schema=schemas.Signup, obj=User())
if request.POST and form.validate():
if not validate_csrf(request):
return HTTPUnauthorized("Not authorized")
user = form.bind(User())
user.username = get_username(user.name, dbsession)
user.password = func.sha1(user.password)
cookie = facebook.get_user_from_cookie(
request.cookies, settings["facebook.app.id"], settings["facebook.app.secret"]
)
if cookie:
graph = facebook.GraphAPI(cookie["access_token"])
profile = graph.get_object("me")
user.fb_id = profile["id"]
user.fb_profile_url = profile["link"]
user.fb_access_token = cookie["access_token"]
try:
dbsession.add(user)
dbsession.commit()
headers = remember_me_header(request, user.email)
redirect_url = route_url("create_profile", request)
request.response_headerlist = headers
return {"status": 1, "url": redirect_url}
except IntegrityError:
return {"errors": {"form": "Invalid Information"}}
return {"errors": form.errors}
示例15: view_task
# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import bind [as 别名]
def view_task(request):
story_id = request.matchdict['story_id']
story = DBSession.query(Story).get(story_id)
task_id = request.matchdict['task_id']
task = DBSession.query(Task).get(task_id)
times_spent = DBSession.query(TimeSpent.duration).filter(
TimeSpent.task_id==task_id).all()
form = Form(request, schema=TimeSpentSchema())
if request.method == 'POST' and form.validate():
time_spent = form.bind(TimeSpent())
time_spent.task_id = task_id
time_spent.task = task
DBSession.add(time_spent)
DBSession.flush()
return HTTPFound(location='/story/%s/task/%s' % (story_id, task_id))
return {
'story': story,
'story_id': story_id,
'task': task,
'task_id': task_id,
'times_spent': times_spent,
'renderer': FormRenderer(form),
'form': form,
'total_time_spent': str(sum_time_spent(times_spent)),
'user': get_user(request),
}