本文整理汇总了Python中kazhal.model.Session.commit方法的典型用法代码示例。如果您正苦于以下问题:Python Session.commit方法的具体用法?Python Session.commit怎么用?Python Session.commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kazhal.model.Session
的用法示例。
在下文中一共展示了Session.commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import commit [as 别名]
def create(self):
values = dict(request.params)
usertag = UserTag(values['usertag'])
Session.add(usertag)
Session.commit()
h.flash(_("User tag %s created successfully")%values['usertag'])
return redirect(url(controller='usertag',action='index'))
示例2: create
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import commit [as 别名]
def create(self):
values = dict(request.params)
producttag = ProductTag(values['producttag'])
Session.add(producttag)
Session.commit()
h.flash(_("Product tag %s created successfully")%values['producttag'])
return redirect(url(controller='producttag',action='index'))
示例3: update
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import commit [as 别名]
def update(self,id):
values = dict(request.params)
producttag = Session.query(ProductTag).filter_by(id=id).one()
producttag.tag = values['producttag']
Session.add(producttag)
Session.commit()
h.flash(_("Tag %s edited successfully")%producttag.tag)
return redirect(url(controller='producttag',action='index'))
示例4: create
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import commit [as 别名]
def create(self):
#if Session.query(Group).filter_by(group=request.POST['group']).one() != None:
#abort(404)
newgroup = Group(request.POST['group'])
newgroup.permissions = self.form_result['permissions']
Session.add(newgroup)
Session.commit()
h.flash(_('Group successfully Created.'))
redirect(url(controller='addgroup', action='list'))
示例5: undelete
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import commit [as 别名]
def undelete(self, id):
came_from = str(request.GET.get("came_from", "")) or url(controller="user", action="admin")
try:
user = Session.query(User).filter_by(id=id).one()
except:
h.flash(_("No user with ID:%s to delete" % id))
return redirect(h.url(controller="user", action="index"))
user.deleted = False
Session.add(user)
Session.commit()
h.flash(_("User %s undeleted!") % user.user_name)
return redirect(came_from)
示例6: delete
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import commit [as 别名]
def delete(self,id):
if id is None:
abort(404)
group = Session.query(Group).filter_by(id=id).one()
if group is None:
abort(404)
h.flash(_('Group successfully deleted.'))
Session.delete(group)
Session.commit()
redirect(url(controller='addgroup', action='list'))
return "Group Deleted"
示例7: save2
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import commit [as 别名]
def save2(self):
values = dict(request.params)
photos_inform=[]
for item in values:
if item.startswith('product_id'):
product_id = item.split('.')[-1]
if item.startswith('photo-'):
photos_inform.append(int(item.split('-')[-1]))
product = Session.query(Product).filter_by(id=product_id).one()
action = request.params.getone('action')
del values['action']
if action == 'Save':
# we need a new schema to be on par with the new Ajax form
schema = EditProductForm()
try:
result = schema.to_python(dict(request.params), c)
except Invalid, e:
return render_edit2_form(
self.menu_items,
values=values,
id=product.id,
errors=variabledecode.variable_encode(
e.unpack_errors() or {},
add_repetitions=False
),
number_of_photos=number_of_photos(values),
photos = product.photos
)
else:
# Move the save photo to photo controller
photos = Session.query(Photo).filter(Photo.id.in_(photos_inform)).all()
product.code = result['code']
product.name = result['name']
product.description = result['description']
product.quantity= result['quantity']
product.buy_price = result['buy_price']
product.sell_price = result['sell_price']
product.wholesale_price = result['wholesale_price']
product.buy_date = result['buy_date']
product.brand = result['brand']
product.photos = photos
product.tags = result['tag']
Session.add(product)
Session.commit()
h.flash(_('Product edited successfully.'))
redirect(url(controller='product',action='admin'))
示例8: save
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import commit [as 别名]
def save(self,id):
if id is None:
abort(404)
group = self.form_result['group']
del self.form_result['group']
for k,v in self.form_result.items():
if getattr(group, k) != v:
setattr(group, k, v)
Session.add(group)
Session.commit()
response.status_int = 302
response.headers['location'] = url(controller='addgroup', action='list')
return "Moved temporarily"
示例9: upload
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import commit [as 别名]
def upload(self):
values = dict(request.params)
overwrite = False
if "files[]" in values:
picfile = values["files[]"]
fname = picfile.filename.replace(os.sep, "_")
file_path = os.path.join(config["pylons.paths"]["static_files"], "pics", fname)
if os.path.isfile(file_path):
overwrite = True
thumb_path = os.path.join(config["pylons.paths"]["static_files"], "pics", "thumbs", fname)
watermark_path = os.path.join(config["pylons.paths"]["static_files"], "pics", "watermark2.PNG")
permanent_file = open(file_path, "wb")
shutil.copyfileobj(picfile.file, permanent_file)
picfile.file.close()
fsize = os.fstat(permanent_file.fileno())[6]
if not overwrite:
photo = Photo(fname)
Session.add(photo)
Session.commit()
else:
photo = Session.query(Photo).filter_by(file_path=fname).one()
permanent_file.close()
# use image magic to resize and water mark the photo
call(["convert", file_path, "-strip", file_path])
# convert "prepared/$i" -colorspace RGB "prepared/$i"
call(["convert", file_path, "-colorspace", "RGB", file_path])
# convert -resize 300x300 -quality 70% $img $img
call(["convert", "-resize", "300x300", "-quality", "70%%", file_path, file_path])
# convert -define jpeg:size=200x200 "$i" -thumbnail '69x69>' "thumbs/$i
call(["convert", "-define", "jpeg:size=200x200", file_path, "-thumbnail", "69x69>", thumb_path])
# composite -dissolve 6 -tile watermark2.PNG $img $img
call(["composite", "-dissolve", "6", "-tile", watermark_path, file_path, file_path])
session["photos"]["files"].append({"name": fname, "size": fsize, "id": photo.id})
session.save()
retval = []
for item in session["photos"]["files"]:
retdict = dict()
retdict["name"] = item["name"]
retdict["size"] = item["size"]
retdict["id"] = item["id"]
retdict["type"] = ("image\/jpeg",)
retdict["url"] = "/pics/%s" % item["name"]
retdict["thumbnail_url"] = "/pics/thumbs/%s" % item["name"]
retdict["delete_url"] = "/photo/delete?id=%s" % item["id"]
retdict["delete_type"] = "DELETE"
if overwrite:
retdict["info"] = "File over writen on photo with id %s" % item["id"]
retval.append(retdict)
return retval
示例10: forgotaction
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import commit [as 别名]
def forgotaction(self):
values = dict(request.params)
del values["action"]
msg = ""
settingsf = file(config["settings_file"], "rb")
session["site_settings"] = pickle.load(settingsf)
settingsf.close()
session.save()
captchres = h.captcha.submit(
values["recaptcha_challenge_field"],
values["recaptcha_response_field"],
"6LepGccSAAAAAMfzDtmvyRjJ7-A1FWuJa5qUTxX2",
session["site_settings"]["ip_address"],
)
if not captchres.is_valid:
c.menu_items = h.top_menu(self.menu_items, _("Customers"))
html = render("/derived/user/forgot.html")
return htmlfill.render(html, values, errors={"captcha": _("Invalid Captcha try again")})
user = Session.query(User).join(User.emails).filter(Email.email_address == values["email"]).one()
confcode = str(uuid.uuid1())
uconf = UserConfirm(user, confcode)
Session.add(uconf)
Session.commit()
message = Message(
session["site_settings"]["forgotpass"],
user.emails[0].email_address,
_("Kazhal trading Reset password"),
encoding="utf-8",
)
msg += _("If you requested a password reset click the below link\n")
##msg += "%s%s"%(request.application_url,h.url(controller='user',action='resetpassEmail',id=user.id,confcode=confcode))
msg += "%s%s" % (
request.application_url,
url(controller="user", action="resetpassEmail", id=user.id, confcode=confcode),
)
c.contents = msg
msgHtml = render(_("/derived/emails/forgotpass.html"))
message.rich = msgHtml
message.plain = msg
message.send()
h.flash(
_(
"An email has been sent to your address.To reset your password check your email and click on the confirm link."
)
)
return redirect(url(controller="user", action="forgot"))
示例11: _save
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import commit [as 别名]
def _save(self,result,invoice):
invoice_totalprice = 0
invoice.Description = result['status']
for item in result['items']:
id = item['id']
invoice_item = Session.query(Invoice_item).filter_by(id=id).one()
product = invoice_item.product
invoice_item.quantity = item['quantity']
invoice_item.unitprice = item['unitprice']
invoice_item.total_price =item['quantity']*item['unitprice']
Session.add(invoice_item)
invoice_totalprice += invoice_item.total_price
invoice.total_price = invoice_totalprice
Session.add(invoice)
Session.commit()
示例12: delete
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import commit [as 别名]
def delete(self, id):
def delcommons(user):
phones = Session.query(Phone).filter_by(user_id=user.id).all()
addresses = Session.query(Address).filter_by(user_id=user.id).all()
emails = Session.query(Email).filter_by(user_id=user.id).all()
for phone in phones:
Session.delete(phone)
for address in addresses:
Session.delete(address)
for email in emails:
Session.delete(email)
came_from = str(request.GET.get("came_from", "")) or url(controller="user", action="admin")
try:
user = Session.query(User).filter_by(id=id).one()
except:
h.flash(_("No user with ID:%s to delete" % id))
return redirect(h.url(controller="user", action="index"))
if user.user_name == "admin":
h.flash("Did u lost your mind?! deleting admin user will destroy ur program!")
return redirect(came_from)
if user.pending:
conf = Session.query(UserConfirm).filter_by(user_id=user.id).one()
Session.delete(conf)
delcommons(user)
Session.delete(user)
else:
invoices = Session.query(Invoice).filter_by(customer_id=user.id).filter_by(pending=False).all()
if invoices == []:
invoices = Session.query(Invoice).filter_by(customer_id=user.id).all()
for invoice in invoices:
for invoice_item in invoice.invoice_items:
Session.delete(invoice_item)
Session.delete(invoice)
delcommons(user)
Session.delete(user)
h.flash("user and all his/her pending orders were deleted")
else:
h.flash(
"you can not delete users permanently with confirmed orders from this site.instead this user has been marked as deleted and is unable to use his/her account anymore"
)
user.deleted = True
Session.add(user)
Session.commit()
h.flash(_("User %s deleted!") % user.user_name)
return redirect(came_from)
示例13: _delete
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import commit [as 别名]
def _delete(self,invoice):
if not invoice.pending:
h.flash(_('You can not delete a confirmed invoice.'))
return redirect(h.url(controller='invoice',action='index'))
invoice.deleted = True
customer = invoice.customer
invoice_items=[]
for invoice_item in invoice.invoice_items:
product = invoice_item.product
product.quantity += invoice_item.quantity
customer.balance += invoice_item.total_price
Session.add(customer)
Session.add(product)
Session.add(invoice_item)
Session.add(invoice)
Session.commit()
h.flash(_('Invoice %s was marked as deleted')%invoice.id)
return redirect(url(controller='invoice',action='index'))
示例14: confirmuser
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import commit [as 别名]
def confirmuser(self):
confirmcode = request.GET.get("confirmcode", "")
try:
conf = Session.query(UserConfirm).filter_by(confirm_code=confirmcode).one()
except:
h.flash(_("Wrong confirmation code"))
redirect(url(controller="home", action="index"))
if conf.confirm_code[:3] != u"cu-":
h.flash(_("Not a user confirmation"))
redirect(url(controller="product", action="list"))
user = conf.user
user.pending = False
Session.add(user)
Session.delete(conf)
Session.commit()
h.flash(_("Confirmation ok. you can now login with your user name and password"))
redirect(url(controller="home", action="index"))
示例15: _confirm
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import commit [as 别名]
def _confirm(self,invoice):
customer = invoice.customer
if not is_met(has_permission('confirm_invoice')):
h.flash(_("You don't have enough permision to confirm ivoice"))
return redirect(url(controller='invoice', action='edit',id=invoice.id))
if invoice.total_price > customer.balance + customer.cradit:
h.flash(_("Customer balance is low. <a href='%s'>Give him enough cradit or contanct him about the funds</a>")%url(controller='user',action='edit',id=customer.id))
invoice.Description = _("Low balance")
Session.add(invoice)
Session.commit()
return redirect(url(controller='invoice',action='edit',id=invoice.id))
invoice_id = invoice.id
invoice_items=[]
for invoice_item in invoice.invoice_items:
product = invoice_item.product
product.quantity -= invoice_item.quantity
customer.balance -= invoice_item.total_price
Session.add(product)
Session.add(customer)
invoice.pending = False
Session.add(invoice)
Session.commit()