本文整理汇总了Python中kazhal.model.Session.query方法的典型用法代码示例。如果您正苦于以下问题:Python Session.query方法的具体用法?Python Session.query怎么用?Python Session.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kazhal.model.Session
的用法示例。
在下文中一共展示了Session.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createbasket
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import query [as 别名]
def createbasket(self):
came_from = str(request.GET.get('came_from', ''))
values = dict(request.params)
for item in values:
if item.startswith('product_id.'):
id = int(item.split('.')[-1])
try:
product = Session.query(Product).filter_by(id=id).one()
except:
h.flash(_('No product exist with ID: %s')%id)
redirect(url(controller='product',action='list'))
if values['quant']!='':
quantity = int(values['quant'])
else:
quantity =1
if session.has_key('basket'):
session['basket'][id]=quantity
else:
session['basket']={id:quantity}
product = Session.query(Product).filter_by(id=id).one()
h.flash(_('%s of product %s added to basket')%(quantity,product.name))
if came_from !='':
return redirect(came_from)
redirect(url(controller='product',action='list'))
示例2: edit2
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import query [as 别名]
def edit2(self,id):
product = Session.query(Product).filter_by(id=int(id)).one()
jd = jcal.gregorian_to_jd(product.buy_date.year, product.buy_date.month, product.buy_date.day)
jalali = jcal.jd_to_jalali(jd)
jalali = str(jalali[0])+'/'+str(jalali[1])+'/'+str(jalali[2])
values={
'code':product.code,
'name':product.name,
'brand':product.brand,
'quantity':product.quantity,
'description':product.description,
'buy_price':product.buy_price,
'sell_price':product.sell_price,
'wholesale_price':product.wholesale_price,
'buy_date':jalali,
}
tags = Session.query(ProductTag).all()
for i,tag in enumerate(tags):
for ptag in product.tags:
if ptag.tag == tag.tag:
values['tag-%i.%i'%(i,tag.id)]=1
return render_edit2_form(
self.menu_items,
values,
number_of_photos=number_of_photos(values),
id=product.id,
photos=product.photos)
示例3: list
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import query [as 别名]
def list(self,id=None,page=1):
if "repoze.who.identity" in request.environ:
user = request.environ.get('repoze.who.identity')['user']
wholesale_tag = Session.query(UserTag).filter_by(tag='wholesale').one()
if wholesale_tag in user.tags:
c.wholesale=True
c.tags = Session.query(ProductTag).all()
c.menu_items = h.top_menu(self.menu_items,_('Shop online'))
if session.has_key('product_querystr'):
if session.has_key('paliasedtags'):
for item in session['paliasedtags']:
exec(item)
products = eval(session['product_querystr']+".filter(Product.deleted==False)")
c.paginator = paginate.Page(products,
page=int(request.params.get('page', page)),
items_per_page = 10)
html = render('/derived/product/list.html')
return htmlfill.render(html,defaults=session['product_search_values'])
else:
products = Session.query(Product).filter_by(deleted=False)
c.paginator = paginate.Page(products,
page=int(request.params.get('page', page)),
items_per_page = 10)
return render('/derived/product/list.html')
示例4: delcommons
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import query [as 别名]
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)
示例5: save2
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import query [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'))
示例6: edit
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import query [as 别名]
def edit(self,id):
values={}
group = Session.query(Group).filter_by(id=id).one()
values['group']= group.group
c.permissions = Session.query(Permission).all()
for i,perm in enumerate(c.permissions):
for permission in group.permissions:
if permission.name == perm.name:
values['permissions-%i.%i'%(i,perm.id)]= 1
c.menu_items = h.top_menu(self.menu_items,_('Customers'))
html = render('/derived/group/edit.html')
return htmlfill.render(html, defaults=values)
示例7: delete
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import query [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)
示例8: render_new_form
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import query [as 别名]
def render_new_form(menu_items,values=None, errors=None, number_of_photos=0):
c.number_of_photos = number_of_photos
c.menu_items = h.top_menu(menu_items,_('Products'))
c.tags = Session.query(ProductTag).all()
#c.roles = ['test1','test2']
html = render('/derived/product/new.html')
return htmlfill.render(html, defaults=values, errors=errors)
示例9: view
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import query [as 别名]
def view(self,id):
if "repoze.who.identity" in request.environ:
user = request.environ.get('repoze.who.identity')['user']
wholesale_tag = Session.query(UserTag).filter_by(tag='wholesale').one()
if wholesale_tag in user.tags:
c.wholesale = True
try:
product = Session.query(Product).filter_by(id=id).one()
except:
h.flash(_('No product exist with ID: %s')%id)
redirect(url(controller='product',action='list'))
if request.environ.get("repoze.who.identity") is not None:
c.permissions = request.environ["repoze.what.credentials"]["permissions"]
c.product = product
c.menu_items = h.top_menu(self.menu_items,_('Products'))
return render('/derived/product/view.html')
示例10: validate_python
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import query [as 别名]
def validate_python(self,value, state):
try:
phone = Session.query(Phone).filter_by(phone_number=str(int(value))).one()
except:
return
else:
raise Invalid(_('This phone number allready registered an acount'),value,state)
示例11: _to_python
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import query [as 别名]
def _to_python(self,value,state):
#items = value.items()
try:
customer = Session.query(User).filter(User.user_name.like('%%'+str(value)+'%%')).all()
return customer
except:
raise Invalid("No User with name like this exists!", value, state)
示例12: index
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import query [as 别名]
def index(self,page=1):
c.menu_items = h.top_menu(self.menu_items,_('Products'))
products = Session.query(Product)
c.paginator = paginate.Page(products,
page=int(request.params.get('page', page)),
items_per_page = 10)
return render('/derived/product/index.html')
示例13: render_edit_form_admin
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import query [as 别名]
def render_edit_form_admin(menu_items,values=None, errors=None, id=None):
if "repoze.who.identity" in request.environ:
user = request.environ.get('repoze.who.identity')['user']
wholesale_tag = Session.query(UserTag).filter_by(tag='wholesale').one()
if wholesale_tag in user.tags:
c.wholesale = True
c.menu_items = h.top_menu(menu_items,_('Shop online'))
invoice = Session.query(Invoice).filter_by(id=int(id)).one()
invoice_items = Session.query(Invoice_item).filter_by(invoice_id=invoice.id).order_by(Invoice_item.product_id).all()
c.invoice_items = invoice_items
c.invoice = invoice
if values is None:
return render('/derived/invoice/staff/edit.html')
else :
html = render('/derived/invoice/staff/edit.html')
return htmlfill.render(html, defaults=values, errors=errors)
示例14: index
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import query [as 别名]
def index(self,page=1):
c.menu_items = h.top_menu(self.menu_items,_('Home'))
tags = Session.query(ProductTag)
c.paginator = paginate.Page(tags,
page=int(request.params.get('page', page)),
items_per_page = 10)
return render('/derived/producttag/staff/index.html')
示例15: create_dict
# 需要导入模块: from kazhal.model import Session [as 别名]
# 或者: from kazhal.model.Session import query [as 别名]
def create_dict(user):
adict = {}
if user.phones != []:
for i, phone in enumerate(user.phones):
adict["phone-%s.phone_number" % i] = phone.phone_number
adict["phone-%s.p_type" % i] = phone.p_type
adict["phone-%s.id" % i] = phone.phone_number
if user.addresses != []:
for i, address in enumerate(user.addresses):
adict["address-%i.city" % i] = address.city
adict["address-%i.state" % i] = address.state
adict["address-%i.add1" % i] = address.add1
adict["address-%i.add2" % i] = address.add2
adict["address-%i.po_code" % i] = address.po_code
adict["address-%s.id" % i] = address.id
if user.photo:
adict["phto"] = user.photo
if user.emails != []:
for i, email in enumerate(user.emails):
adict["email-%s.email_address" % i] = email.email_address
adict["email-%s.confirm_email_address" % i] = email.email_address
adict["email-%s.id" % i] = email.email_address
if user.tags != []:
tags = Session.query(UserTag).all()
for i, tagp in enumerate(tags):
for tag in user.tags:
if tagp.tag == tag.tag:
adict["tag-%s.%s" % (i, tag.id)] = 1
# adict['tagid-%s.id'%i]=tag.id
if user.groups != []:
groups = Session.query(Group).all()
for i, group in enumerate(groups):
for groupu in user.groups:
if groupu.group == group.group:
adict["role-%s.%s" % (i, group.id)] = 1
# adict['roleid-%s.id'%i] = group.id
adict["first_name"] = user.first_name
adict["last_name"] = user.last_name
adict["user_name"] = user.user_name
adict["password"] = ""
adict["confirm_password"] = ""
adict["birth_date"] = h.gtoj(user.birth_date)
adict["SSN"] = user.SSN
adict["balance"] = user.balance
adict["cradit"] = user.cradit
return adict