def post(self): iKwargs = request.form.to_dict() categorys = CategoryModel.getAllData() names = [category['name'] for category in categorys] category = CategoryModel() if iKwargs['name'] in names: raise ModelRepeat(iKwargs['name']) data = {'name': iKwargs['name'], 'articleList': {}} category.create(data) return data
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()
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
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)
description='Custom Portrait', price=29, stock=80) Product.create(store_id=2, name='Key Chain', description='Custom Key Chain', price=4.9, stock=80) # 5 query = User.insert(username='******', password='******') query.execute() # Create categories Category.create(name='Storage', description='Storage') Category.create(name='Kingstong', description='Kingstong') Category.create(name='Toshiba', description='Toshiba') Category.create(name='Accesory', description='Accesory') Category.create(name='Custom', description='Custom') Category.create(name='Clothes', description='Clothes') CategoriesProducts.create(product=1, category=1) CategoriesProducts.create(product=1, category=2) CategoriesProducts.create(product=2, category=1) CategoriesProducts.create(product=2, category=3) CategoriesProducts.create(product=3, category=1) CategoriesProducts.create(product=3, category=2) CategoriesProducts.create(product=1, category=1) CategoriesProducts.create(product=4, category=1) CategoriesProducts.create(product=4, category=4)