本文整理汇总了Python中model.Category.get方法的典型用法代码示例。如果您正苦于以下问题:Python Category.get方法的具体用法?Python Category.get怎么用?Python Category.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Category
的用法示例。
在下文中一共展示了Category.get方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getCategory
# 需要导入模块: from model import Category [as 别名]
# 或者: from model.Category import get [as 别名]
def getCategory(current_category_key):
current_category = None
lineage = []
try:
current_category = Category.get(db.Key(current_category_key))
lineage = [Category.get(key) for key in current_category.lineage]
except db.BadKeyError:
pass
except AttributeError:
pass
#todo - massive oppurtunity for optimization
retval = current_category.key().__str__() + ',' + current_category.name + ';'
for category in lineage:
retval += category.key().__str__() + ',' + category.name + ','
retval += ';'
for category in Category.children(current_category):
retval += category.key().__str__() + ',' + category.name + ','
print 'Content-Type: text/plain;charset=UTF-8'
print ''
print retval
示例2: post
# 需要导入模块: from model import Category [as 别名]
# 或者: from model.Category import get [as 别名]
def post(self, caid):
try:
categoryattr = CategoryAttr.get(id = caid)
category = Category.get(id = categoryattr.cid)
except:
self.flash("此分类属性不存在")
self.redirect("/admin/categorys")
return
name = self.get_argument("name", None)
dec = self.get_argument("dec", "")
order = int(self.get_argument("order", 1))
categoryattr.name = name
categoryattr.dec = dec
categoryattr.order = order
try:
categoryattr.validate()
categoryattr.save()
self.flash(u"分类属性%s修改成功" % name)
self.redirect("/admin/categoryattrs/%d" % int(categoryattr.cid))
return
except Exception, ex:
self.flash(str(ex))
示例3: post
# 需要导入模块: from model import Category [as 别名]
# 或者: from model.Category import get [as 别名]
def post(self, cid):
try:
category = Category.get(id = cid)
except:
self.flash("此分类不存在")
self.redirect("/admin/categorys")
return
name = self.get_argument("name", None)
dec = self.get_argument("dec", "")
order = int(self.get_argument("order", 1))
categoryattr = CategoryAttr()
categoryattr.cid = cid
categoryattr.name = name
categoryattr.dec = dec
categoryattr.order = order
try:
categoryattr.validate()
categoryattr.save()
self.flash("分类属性%s添加成功" % name)
self.redirect("/admin/categoryattrs/%d" % int(cid))
return
except Exception as ex:
self.flash(str(ex))
self.render('admin/addcategoryattr.html', category = category, maxorder = CategoryAttr.maxorder(cid))
示例4: get
# 需要导入模块: from model import Category [as 别名]
# 或者: from model.Category import get [as 别名]
def get(self, cid):
try:
category = Category.get(id = cid)
except:
self.flash("此分类不存在")
self.redirect("/admin/categorys")
return
self.render('admin/addcategoryattr.html', category = category, maxorder = CategoryAttr.maxorder(cid))
示例5: get
# 需要导入模块: from model import Category [as 别名]
# 或者: from model.Category import get [as 别名]
def get(self):
current_category_key = self.request.get("category")
current_category = None
lineage = []
try:
current_category = Category.get(db.Key(current_category_key))
lineage = [Category.get(key) for key in current_category.lineage]
except db.BadKeyError:
pass
except AttributeError:
pass
child_categories = Category.children(current_category)
self.tpl_vars["current_category"] = current_category
self.tpl_vars["child_categories"] = child_categories
self.tpl_vars["lineage"] = lineage
path = os.path.join(os.path.dirname(__file__), "templates/admin/index.html")
self.response.out.write(template.render(path, self.tpl_vars))
示例6: post
# 需要导入模块: from model import Category [as 别名]
# 或者: from model.Category import get [as 别名]
def post(self):
parent_key = self.request.get("parent_key")
name = self.request.get("category_name")
if len(name) < 3:
pass # no feedback, as of now
else:
try:
parent = Category.get(db.Key(parent_key))
Category.new(name, parent)
except db.BadKeyError:
pass # no feedback, as of now
except:
pass # no feedback, as of now
self.redirect("./?category=" + parent_key)
示例7: get
# 需要导入模块: from model import Category [as 别名]
# 或者: from model.Category import get [as 别名]
def get(self, ename):
try:
shop = Shop.get(ename = ename)
shop.views = shop.views + 1
shop.save()
category = Category.get(id = shop.cid)
except:
raise HTTPError(404)
return
categoryattrs = CategoryAttr.select().where(CategoryAttr.cid == shop.cid)
shopattrs = ShopAttr.select().where(ShopAttr.sid == shop.id)
if shop.args:
shop.args = simplejson.loads(shop.args)
pics = ShopPic.select().where(ShopPic.sid == shop.id)
recomshops = Shop.select().where((Shop.status == 1) & (Shop.id != shop.id)).paginate(1, 5)
self.render("shop/shop.html", shop = shop, category = category, categoryattrs = categoryattrs, shopattrs = shopattrs, pics = pics, recomshops = recomshops)