本文整理汇总了Python中model.Category.put方法的典型用法代码示例。如果您正苦于以下问题:Python Category.put方法的具体用法?Python Category.put怎么用?Python Category.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Category
的用法示例。
在下文中一共展示了Category.put方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_category
# 需要导入模块: from model import Category [as 别名]
# 或者: from model.Category import put [as 别名]
def create_category(category_name):
""" Create a category in datastore """
query = Category.all()
query.filter("description =", category_name)
ret = query.get()
if ret is None:
ret = Category()
ret.description = category_name
ret.put()
return ret
示例2: post
# 需要导入模块: from model import Category [as 别名]
# 或者: from model.Category import put [as 别名]
def post(self):
name = urllib.quote(self.request.get('name').encode('utf8'))
category = Category.all().filter('name',name).get()
if category is not None:
self.response.out.write('category: %s has already existed' % (name))
else:
category = Category()
category.name = name
category.put()
categories = Category.all()
template_values = {
'categories': categories,
}
self.generate('../templates/admin.html', template_values)
示例3: post
# 需要导入模块: from model import Category [as 别名]
# 或者: from model.Category import put [as 别名]
def post(self):
result = {'message': '', 'status': 'success', 'content': ''}
logging.info(self.request.POST)
current_cate_id = self.request.POST.get("current_cate_id")
cate_name = self.request.POST.get("cate_name")
cate_slug = self.request.POST.get("cate_slug")
operation = self.request.POST.get("operation")
logging.info("CategoryManager post: current_cate_id = %s, cate_name = %s, cate_slug = %s, operation = %s" % (current_cate_id, cate_name, cate_slug, operation))
if current_cate_id:
# edit existed link
cate = Category.get_by_id(long(current_cate_id))
if cate:
# current_cate_id exists
if operation == "delete":
if cate.entrycount == 0:
cate.delete()
result['message'] = "category %s has been deleted" % (current_cate_id)
else:
result['status'] = 'failed'
result['message'] = "category %s can't be delete since it's still being used!" % (current_cate_id)
else:
cate.name = cate_name
cate.slug = cate_slug
cate.put()
result['message'] = "category %s has been updated" % (cate.name)
else:
logging.info("category id=%s does not exist!" % (current_cate_id))
else:
# create new cate
cate = Category(name=cate_name, slug=cate_slug)
cate.put()
result['message'] = "category %s has been created" % (cate.name)
result['content'] = render_template("category_block.html", {'cate': cate}, "", True)
logging.info("content = %s" % (result['content']))
# return json result
self.response.content_type = 'application/json'
return self.response.out.write(json.encode(result))