本文整理汇总了Python中models.category.Category类的典型用法代码示例。如果您正苦于以下问题:Python Category类的具体用法?Python Category怎么用?Python Category使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Category类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:Siglud,项目名称:ff,代码行数:7,代码来源:category_manage_handler.py
示例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)
开发者ID:aviatorBeijing,项目名称:ptpy,代码行数:26,代码来源:board.py
示例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)
开发者ID:phuclc,项目名称:dienthoai,代码行数:60,代码来源:category.py
示例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()
开发者ID:hooops,项目名称:PersonalWebsite,代码行数:28,代码来源:blog.py
示例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)
开发者ID:aviatorBeijing,项目名称:ptpy,代码行数:54,代码来源:default.py
示例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)
开发者ID:demosthenes48,项目名称:galleryApp,代码行数:26,代码来源:AdminCategoriesController.py
示例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)
开发者ID:phuclc,项目名称:dienthoai,代码行数:8,代码来源:category.py
示例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'
开发者ID:DlutCS,项目名称:nserver_py,代码行数:8,代码来源:admin.py
示例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
开发者ID:DlutCS,项目名称:nserver_py,代码行数:17,代码来源:admin.py
示例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
开发者ID:DlutCS,项目名称:nserver_py,代码行数:9,代码来源:admin.py
示例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)
开发者ID:phuclc,项目名称:dienthoai,代码行数:18,代码来源:cache.py
示例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
开发者ID:DlutCS,项目名称:nserver_py,代码行数:10,代码来源:admin.py
示例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
开发者ID:hooops,项目名称:PersonalWebsite,代码行数:10,代码来源:blog.py
示例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})
开发者ID:flreey,项目名称:private-navigation,代码行数:10,代码来源:category.py
示例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())
开发者ID:DlutCS,项目名称:nserver_py,代码行数:11,代码来源:home.py
示例16: post
def post(self):
categoryName = self.request.get('categoryName')
photoName = self.request.get('photoName')
#get the photo specified by the user
photo = File.query(File.file_name==photoName.upper()).get()
#check to see if a category with that name already exists
existingCategory = Category.query(Category.categoryName==categoryName).get()
if existingCategory:
#if an category with that name already exists, then update the information with the form data
existingCategory.categoryName=categoryName
existingCategory.picture=photo.key
existingCategory.uploaded_by=users.get_current_user()
existingCategory.put()
existingCategory.add_to_search_index()
message = "Successfully updated category record: " + existingCategory.categoryName
else:
#add a new category entry if no category with that name already exists
category = Category(categoryName=categoryName, picture=photo.key, uploaded_by=users.get_current_user())
category.put()
category.add_to_search_index()
message = "Successfully created category record: " + category.categoryName
self.response.write(message)
开发者ID:demosthenes48,项目名称:galleryApp,代码行数:28,代码来源:AdminCategoriesController.py
示例17: create_new_blog
def create_new_blog(cls, title, tag, category, hide, content):
blog = cls.create(title=title,
content_md=content)
if hide == 'False':
blog.hide = False
else:
blog.hide = True
blog.content_html = md2html(content)
blog.save()
check_tag = Tags.has_tag(tag)
if check_tag:
BlogTags.create(blog_id=blog.id, tags_id=check_tag.id)
else:
tag = Tags.create(tag=tag)
BlogTags.create(blog_id=blog.id, tags_id=tag.id)
check_category = Category.has_category(category)
if check_category:
BlogCategory.create(blog_id=blog.id, category_id=check_category.id)
else:
category = Category.create(category=category)
BlogCategory.create(blog_id=blog.id, category_id=category.id)
开发者ID:hooops,项目名称:PersonalWebsite,代码行数:24,代码来源:blog.py
示例18: get
def get(self):
template = JINJA_ENVIRONMENT.get_template('/templates/publicHome.html')
photos = {}
categories = Category.query().order(Category.categoryName)
for category in categories:
photos[category.key] = category.picture.get()
templateVars = {
"title" : "Nick Michael's Fine Gallery",
"categories": categories,
"photos": photos}
self.response.write(template.render(templateVars))
开发者ID:demosthenes48,项目名称:galleryApp,代码行数:15,代码来源:PublicHomeController.py
示例19: add_category
def add_category():
status_code = 0
error_msg = 'error'
try:
ins = Category()
ins.title = getparms('title','new category')
ins.sort_num = int(getparms('sort_num','0'))
ins.join_date = datetime.now()
ins.status = 1
ins.save()
status_code = 1
error_msg = '成功'
except Exception as e:
error_msg = '出错了 %r' % e
result = {'status_code':status_code,'msg':error_msg }
return jsonify(result)
开发者ID:code945,项目名称:learnflask,代码行数:16,代码来源:api_category.py
示例20: delete
def delete(self, category_id=0, *args, **kwargs):
"""删除"""
category_id = category_id
if not category_id:
self.on_error(**ErrorCodeMessage.category_not_exists)
return
category = Category.init_from_category_id(category_id)
if not category:
self.on_error(**ErrorCodeMessage.category_not_exists)
return
if category.delete():
self.on_success()
else:
self.on_error(**ErrorCodeMessage.database_error)
开发者ID:Siglud,项目名称:ff,代码行数:18,代码来源:category_manage_handler.py
注:本文中的models.category.Category类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论