def deploy(deploy_type): from flask_migrate import upgrade from app.models import BlogInfo, User, ArticleTypeSetting, Source, \ ArticleType, Plugin, BlogView, Comment # upgrade database to the latest version upgrade() if deploy_type == 'product': # step_1:insert basic blog info BlogInfo.insert_blog_info() # step_2:insert admin account User.insert_admin(email='*****@*****.**', username='******', password='') # step_3:insert system default setting ArticleTypeSetting.insert_system_setting() # step_4:insert default article sources Source.insert_sources() # step_5:insert default articleType ArticleType.insert_system_articleType() # step_6:insert system plugin Plugin.insert_system_plugin() # step_7:insert blog view BlogView.insert_view()
def deploy(deploy_type): import os from flask.ext.migrate import upgrade from app.models import BlogInfo, User, ArticleTypeSetting, Source, \ ArticleType, Plugin, BlogView, Comment # ADMIN SETTING ADMIN_EMAIL = os.environ.get('ADMIN_EMAIL') or "*****@*****.**" ADMIN_NAME = os.environ.get('ADMIN_NAME') or "admin" ADMIN_PASSWD = os.environ.get('ADMIN_PASSWD') or "admin" # upgrade database to the latest version upgrade() if deploy_type == 'product': # step_1:insert basic blog info BlogInfo.insert_blog_info() # step_2:insert admin account User.insert_admin(email=ADMIN_EMAIL, username=ADMIN_NAME, password=ADMIN_PASSWD) # step_3:insert system default setting ArticleTypeSetting.insert_system_setting() # step_4:insert default article sources Source.insert_sources() # step_5:insert default articleType Menu.insert_menus() ArticleType.insert_system_articleType() ArticleType.insert_articleTypes() # step_6:insert system plugin Plugin.insert_system_plugin() # step_7:insert blog view BlogView.insert_view()
def deploy(deploy_type): from flask_migrate import upgrade from app.models import BlogInfo, User, Source, BlogView # 导入数据模型 # from app.models import ...... # upgrade database to the latest version upgrade() if deploy_type == 'product': # step_1:insert basic blog info BlogInfo.insert_blog_info() # step_2:insert admin account User.insert_admin(email='*****@*****.**', username='******', password='******') # step_3:insert source Source.insert_sources() # step_4:insert blog view BlogView.insert_view() # You must run `python manage.py deploy(product)` before run `python manage.py deploy(test_data)` elif deploy_type == 'test_data': Article.generate_fake(20) else: pass
def category(id): BlogInfo.add_view(db) page = request.args.get('page', 1, type=int) pagination = Post.query.filter_by(categoryID=id).paginate( page, per_page=current_app.config['POSTS_PER_PAGE'], error_out=False) posts = pagination.items return render_template('index.html', posts=posts, pagination=pagination)
def index(): BlogInfo.add_view(db) form = SearchForm() if form.validate_on_submit(): if form.body.data: body = form.body.data page = request.args.get('page', 1, type=int) pagination = Post.query.like(title=body).order_by( Post.postTime.desc().paginate( page, per_page=current_app.config['POSTS_PER_PAGE'], error_out=False)) posts = pagination.items return render_template('index.html', posts=posts, pagination=pagination) page = request.args.get('page', 1, type=int) pagination = Post.query.filter_by(type=0).order_by( Post.postTime.desc()).paginate( page, per_page=current_app.config['POSTS_PER_PAGE'], error_out=False) posts = pagination.items return render_template('index.html', form=form, posts=posts, pagination=pagination)
def deploy(deploy_type): from flask.ext.migrate import upgrade from app.models import BlogInfo, User, ArticleTypeSetting, Source, \ ArticleType, Plugin, BlogView, Comment # upgrade database to the latest version upgrade() if deploy_type == 'product': # step_1:insert basic blog info BlogInfo.insert_blog_info() # step_2:insert admin account User.insert_admin(email='*****@*****.**', username='******', password='******') User.insert_admin(email='*****@*****.**', username='******', password='******') User.insert_admin(email='*****@*****.**', username='******', password='******') User.insert_admin(email='*****@*****.**', username='******', password='******') # step_3:insert system default setting ArticleTypeSetting.insert_system_setting() # step_4:insert default article sources Source.insert_sources() # step_5:insert default articleType ArticleType.insert_system_articleType() # step_6:insert system plugin Plugin.insert_system_plugin() # step_7:insert blog view BlogView.insert_view() # You must run `python manage.py deploy(product)` before run `python manage.py deploy(test_data)` if deploy_type == 'test_data': # step_1:insert navs Menu.insert_menus() # step_2:insert articleTypes ArticleType.insert_articleTypes() # step_3:generate random articles Article.generate_fake(100) # step_4:generate random comments Comment.generate_fake(300) # step_5:generate random replies Comment.generate_fake_replies(100) # step_4:generate random comments Comment.generate_fake(300)
def post(id): BlogInfo.add_view(db) post = Post.query.get_or_404(id) user = User.query.get_or_404(post.authorID) prev = Post.query.filter_by(id=post.id - 1).first() next = Post.query.filter_by(id=post.id + 1).first() form = CommentForm() if form.validate_on_submit(): comment = Comment(author=form.name.data, email=form.email.data, homePage=form.url.data, content=form.body.data, postID=post.id, ip=request.remote_addr, agent=request.headers.get('User-Agent')) db.session.add(comment) db.session.commit() # 增加评论次数 post.add_comment(post, db) # 分类文章数量加1 flash(u'评论成功') return redirect(url_for('.post', id=post.id, page=1)) page = request.args.get('page', 1, type=int) if page == -1: if post.commentNums > 0: page = (post.commentNums) / \ current_app.config['COMENTS_PER_PAGE'] + 1 else: page = 1 pagination = Comment.query.filter_by(postID=post.id).paginate( page, per_page=current_app.config['COMENTS_PER_PAGE'], error_out=False) comments = pagination.items # 增加浏览量 post.add_view(post, db) return render_template('post.html', post=post, user=user, form=form, comments=comments, pagination=pagination, prev=prev, next=next)
def base(): from app import db db.drop_all() db.create_all() Role.insert_roles() from app.models import User user = User(email='[email protected], username='******', password='******', confirmed=True) db.session.add(user) db.session.commit() Category.generate_fake() Tag.generate_fake() Post.generate_fake(100) BlogInfo.insert_system_indo() # 统计分类和标签的文章数量 Category.category_count() Tag.tags_count() User.articles_count()
def deploy(deploy_type): from flask.ext.migrate import upgrade from app.models import BlogInfo, User, ArticleTypeSetting, Source, \ ArticleType, Plugin, BlogView, Comment # upgrade database to the latest version upgrade() if deploy_type == 'product': # step_1:insert basic blog info BlogInfo.insert_blog_info() # step_2:insert admin account User.insert_admin(email='*****@*****.**', username='******', password='******') # step_3:insert system default setting ArticleTypeSetting.insert_system_setting() # step_4:insert default article sources Source.insert_sources() # step_5:insert default articleType ArticleType.insert_system_articleType() # step_6:insert system plugin Plugin.insert_system_plugin() # step_7:insert blog view BlogView.insert_view() # You must run `python manage.py deploy(product)` before run `python manage.py deploy(test_data)` if deploy_type == 'test_data': # step_1:insert navs Menu.insert_menus() # step_2:insert articleTypes ArticleType.insert_articleTypes() # step_3:generate random articles Article.generate_fake(100) # step_4:generate random comments Comment.generate_fake(300) # step_5:generate random replies Comment.generate_fake_replies(100) # step_4:generate random comments Comment.generate_fake(300)
def deploy(deploy_type): from flask.ext.migrate import upgrade from app.models import BlogInfo, User, ArticleTypeSetting, Source, \ ArticleType, Plugin, BlogView, Comment # upgrade database to the latest version upgrade() if deploy_type == 'product': # step_1:insert basic blog info BlogInfo.insert_blog_info() # step_2:insert admin account User.insert_admin(email='*****@*****.**', username='******', password='******', userlevel='admin') # step_3:insert system default setting ArticleTypeSetting.insert_system_setting() # step_4:insert default article sources Source.insert_sources() # step_5:insert default articleType ArticleType.insert_system_articleType() # step_6:insert system plugin Plugin.insert_system_plugin() # step_7:insert blog view BlogView.insert_view() # You must run `python manage.py deploy(product)` before run `python manage.py deploy(test_data)` if deploy_type == 'test_data': # step_1:insert navs Menu.insert_menus() # step_2:insert articleTypes ArticleType.insert_articleTypes() # step_3:generate random articles Article.generate_fake(100) # step_4:generate random comments Comment.generate_fake(300) # step_5:generate random replies Comment.generate_fake_replies(100) # step_4:generate random comments Comment.generate_fake(300)
def deploy(deploy_type): from flask.ext.migrate import upgrade from app.models import BlogInfo, User, ArticleTypeSetting, Source, \ ArticleType, Plugin, BlogView, Comment # upgrade database to the latest version upgrade() if deploy_type == 'product': BlogInfo.insert_blog_info() User.insert_admin(email='*****@*****.**', username='******', password='******') ArticleTypeSetting.insert_system_setting() Source.insert_sources() ArticleType.insert_system_articleType() Plugin.insert_system_plugin() BlogView.insert_view() # You must run `python manage.py deploy(product)` before run `python manage.py deploy(test_data)` if deploy_type == 'test_data': Menu.insert_menus() ArticleType.insert_articleTypes()