本文整理汇总了Python中models.category.Category类的典型用法代码示例。如果您正苦于以下问题:Python Category类的具体用法?Python Category怎么用?Python Category使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Category类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
def post(self, *args, **kwargs):
category_list = self.get_angular_argument('category_list')
if not category_list:
return
Category.update_position(category_list)
示例2: get
def get(self,key):
user = User()
categroy = Category()
user_keys = user.allKey()
category_keys = categroy.allKey()
_data_user = user.all(user_keys)
_data_category = categroy.all(category_keys)
data = {}
if key:
board = Board()
board.data = board.get(key)
data['title'] = board.data['title']
data['key'] = board.data['key']
data['user'] = board.data['user']
data['category'] = board.data['category']
data['createTime'] = board.data['createTime']
data['follow'] = board.data['follow']
else:
data['title'] = ''
data['key'] = ''
data['user'] = ''
data['category'] = ''
self.render('manager/board_new.html',data = data,data_user = _data_user,data_category = _data_category)
示例3: update
def update(category_id):
try:
data = request.form.to_dict()
temp_data = data
ancestorpath = []
data = dict((k, v) for (k, v) in data.iteritems() if len(str(v).strip()) > 0)
category = Category.objects.get(id=str(category_id)) # cha
if category is None:
return abort(400)
update_map = dict([("set__" + key, value) for key, value in data.items()])
if update_map.has_key("set__parent"):
if update_map["set__parent"] == category_id:
return abort(400)
parent = Category.objects(id=str(update_map["set__parent"])).first() # con
if parent is None:
return abort(400)
ancestorpath = parent.ancestors
ancestorpath.append(parent)
"""
Check category in child's ancestors when update a category with its parent is its descendant
If category in child's ancestors return True
else return False
"""
def ancestors(parent, child):
if parent.id == child.id:
return True
if child.parent is None:
return False
return ancestors(parent, child.parent)
if ancestors(category, parent):
return abort(400)
if temp_data.has_key("parent"):
if len(str(temp_data["parent"]).strip()) == 0:
update_map["set__parent"] = None
update_map["set__ancestors"] = ancestorpath
category.update(**update_map)
category.reload
# get all child
children = Category.objects(ancestors__contains=category.id)
def getpath(path, child):
if child.parent is None:
return path
path.insert(0, child.parent)
return getpath(path, child.parent)
# update ancestors in child
for child in children:
child_path = getpath([], child)
child.ancestors = child_path
child.save()
rebuilt_category_product()
return render.template("admin/category/detail.html", category=category.reload()), 200
except Exception as e:
print e
abort(400)
示例4: modify_blog
def modify_blog(cls, blog_id, title, tag, category, hide, content):
blog = cls.get(cls.id == blog_id)
blog.title = title
if hide == 'False':
blog.hide = False
else:
blog.hide = True
blog.content_md = content
blog.content_html = md2html(content)
blog.save()
check_tag = Tags.has_tag(tag)
blogtags = BlogTags.get(BlogTags.blog_id == blog.id)
if check_tag:
blogtags.tags_id = check_tag.id
else:
tag = Tags.create(tag=tag)
blogtags.tags_id = tag.id
blogtags.save()
check_category = Category.has_category(category)
blogcategory = BlogCategory.get(BlogCategory.blog_id == blog.id)
if check_category:
blogcategory.category_id = check_category.id
else:
category = Category.create(category=category)
blogcategory.category_id = category.id
blogcategory.save()
示例5: get
def get(self,cat_key):
if cat_key == 'All':
self.redirect('/')
else:
uri = self.request.uri
request = {}
pin = Pin()
pin_keys = pin.getByCat(cat_key)
pin_count = len(pin_keys)
query = {}
query['q'] = "category:%s" % cat_key
query['start'] = "0"
query['rows'] = globalSetting['max_index_pin_rows']
query['sort'] = "createTime"
if "page" in uri:
request = urldecode(uri)
print request
page = int(request['page'])
query['start'] = query['rows']*page
if pin_count < query['rows']*page:
return ''
pin_data = pin.solr(query)
#print len(pin_data)
marks_dict = pin.formatPins(pin_data)
if request:
#print request
callback_result = {
'filter':'pin:index',
'pins':marks_dict
}
callback_response = "%s(%s)" % (request['callback'],json.dumps(callback_result))
self.set_header("Content-Type", "text/html; charset=utf-8")
return self.write(callback_response)
else:
marks = ''
for _mark_t in marks_dict:
marks = self.render_string('mark.html',mark=_mark_t)+marks
if marks == '':
marks = """
<div class="pin category wfc isotope-item" style="margin-bottom: 15px; position: absolute; left: 0px; top: 0px; -webkit-transform: translate3d(0px, 0px, 0px); ">
NO PINS
</div>
"""
category = Category()
cats = category.getCats()
self.render('index.html',user=self.currentUserInfo(),marks=marks,cats = cats,urlname = cat_key)
示例6: get
def get(self):
loginTitle = ""
loginURL = ""
user = users.get_current_user()
if user:
loginTitle = "logout"
loginURL= users.create_logout_url('/')
else:
loginTitle = "login"
loginURL= users.create_login_url('/')
photos = {}
categories = Category.query().order(Category.categoryName)
for category in categories:
photos[category.key] = category.picture.get()
templateVars = {
"title" : "Manage Categories",
"loginURL" : loginURL,
"loginTitle": loginTitle,
"categories": categories,
"photos": photos
}
self.render_template("/templates/adminCategories.html", templateVars)
示例7: detail
def detail(category_id):
try:
category = Category.objects(id=str(category_id)).first()
if category is None:
return abort(404)
return render.template("admin/category/detail.html", category=category)
except Exception, e:
abort(404)
示例8: user_delete
def user_delete():
try:
id = request.form['id'].split(',')
except KeyError:
return error(400, u'参数错误')
if not Category.delete(id):
return error(10020, 'delete failed')
return 'delete ok'
示例9: category_retrieve
def category_retrieve():
id = request.args.get('id', 0)
if id:
category = Category.get(id)
if not category:
return error(404, 'category not exist')
return category
# start = request.args.get('start', 0)
# limit = int(request.args.get('limit', PAGE_LIMIT))
# category还要start??,
data = {}
data['start'] = 0
data['data'] = Category.get_all()
data['count'] = len(data['data'])
return data
示例10: category_create
def category_create():
try:
name = request.form['name']
except KeyError:
return error(400, u'参数错误')
category = Category.create(**locals())
if not category:
return error(100021, 'create category failed')
return category
示例11: rebuilt_category_product
def rebuilt_category_product():
Category_Product.objects().delete()
categories = Category.objects()
for category in categories:
product_of_categorys = Product.objects(category=category.id)
bulk = []
for product_of_category in product_of_categorys:
bulk.append(Category_Product(product=product_of_category.id, category=category.id))
if len(bulk) > 0:
Category_Product.objects.insert(bulk)
children = Category.objects(ancestors__contains=category.id)
for child in children:
product_of_childs = Product.objects(category=child.id)
bulk = []
for product_of_child in product_of_childs:
bulk.append(Category_Product(product=product_of_child.id, category=category.id))
if len(bulk) > 0:
Category_Product.objects.insert(bulk)
示例12: category_update
def category_update():
try:
name = request.form['name']
id = request.form['id']
except KeyError:
return error(400, u'参数错误')
category = Category.update(**locals())
if not category:
return error(10022, 'update category failed')
return category
示例13: get_blog_detail
def get_blog_detail(cls, blog_id):
blog = cls.get(cls.id == blog_id)
blogtags = BlogTags.get(BlogTags.blog_id == blog.id)
tag = Tags.get(Tags.id == blogtags.tags_id).tag
blogcategory = BlogCategory.get(BlogCategory.blog_id == blog_id)
category = Category.get(Category.id == blogcategory.category_id).category
return blog, tag, category
示例14: put
def put(self, cat_id):
form = ApiCategoryForm(request.form)
if form.validate():
c = Category.get(cat_id)
if c.user_id != session['user_id']:
return jsonify({'code': 2, 'message': 'has no permission to modify the category'})
else:
form.fill_data_to_instance(c)
return jsonify(code=0, data=c.json)
return jsonify({'code': 1, 'message': form.errors})
示例15: get
def get(self, cid):
if not cid or not Category.get(cid):
abort(404)
if cid == 1:
return redirect(url_for('main.home'))
news_header = News.get_by_category(cid, order='create_time desc', start=0, limit=7)
news_latest = News.get_by_category(cid, order='create_time desc', start=7)
news_popular = News.get_by_category(cid, order='read_count desc', start=0)
loginform = LoginForm()
regform = RegisterForm()
return render_template('index.html', **locals())