finish self-motion deploy

This commit is contained in:
xpleaf
2016-03-05 22:05:07 +08:00
parent 187d8859ab
commit f6636aee0f
5 changed files with 186 additions and 32 deletions
+4 -4
View File
@@ -38,10 +38,10 @@ class User(UserMixin, db.Model):
return check_password_hash(self.password_hash, password)
def __init__(self, **kwargs):
super(Comment, self).__init__(**kwargs)
super(User, self).__init__(**kwargs)
if self.email is not None and self.avatar_hash is None:
self.avatar_hash = hashlib.md5(
self.author_email.encode('utf-8')).hexdigest()
self.email.encode('utf-8')).hexdigest()
def gravatar(self, size=40, default='identicon', rating='g'):
# if request.is_secure:
@@ -257,7 +257,7 @@ class Comment(db.Model):
for i in range(count):
a = Article.query.offset(randint(0, article_count - 1)).first()
c = Comment(content=forgery_py.lorem_ipsum.sentences(randint(3, 5)),
timestamp=forgery_py.date.date(True, -10, 0),
timestamp=forgery_py.date.date(True),
author_name=forgery_py.internet.user_name(True),
author_email=forgery_py.internet.email_address(),
article=a)
@@ -277,7 +277,7 @@ class Comment(db.Model):
for i in range(count):
followed = Comment.query.offset(randint(0, comment_count - 1)).first()
c = Comment(content=forgery_py.lorem_ipsum.sentences(randint(3, 5)),
timestamp=forgery_py.date.date(True, -20, -10),
timestamp=forgery_py.date.date(True),
author_name=forgery_py.internet.user_name(True),
author_email=forgery_py.internet.email_address(),
article=followed.article, comment_type='reply',
BIN
View File
Binary file not shown.
+41
View File
@@ -33,5 +33,46 @@ def make_shell_context():
manager.add_command("shell", Shell(make_context=make_shell_context))
@manager.command
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='blog_mini@163.com', username='blog_mini', password='blog_mini')
# 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)
if __name__ == '__main__':
manager.run()
@@ -1,28 +0,0 @@
"""add avatar_hash to User model
Revision ID: 15f151e77105
Revises: None
Create Date: 2016-03-05 11:12:18.468485
"""
# revision identifiers, used by Alembic.
revision = '15f151e77105'
down_revision = None
from alembic import op
import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_unique_constraint(None, 'plugins', ['title'])
op.add_column('user', sa.Column('avatar_hash', sa.String(length=32), nullable=True))
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('user', 'avatar_hash')
op.drop_constraint(None, 'plugins', type_='unique')
### end Alembic commands ###
@@ -0,0 +1,141 @@
"""ready for deplying
Revision ID: 5e321c21ec2a
Revises: None
Create Date: 2016-03-05 21:49:03.285373
"""
# revision identifiers, used by Alembic.
revision = '5e321c21ec2a'
down_revision = None
from alembic import op
import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_table('articleTypeSettings',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=64), nullable=True),
sa.Column('protected', sa.Boolean(), nullable=True),
sa.Column('hide', sa.Boolean(), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name')
)
op.create_table('blog_info',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('title', sa.String(length=64), nullable=True),
sa.Column('signature', sa.String(length=128), nullable=True),
sa.Column('navbar', sa.String(length=64), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('blog_view',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('num_of_view', sa.BigInteger(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('menus',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=64), nullable=True),
sa.Column('order', sa.Integer(), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name')
)
op.create_table('plugins',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('title', sa.String(length=64), nullable=True),
sa.Column('note', sa.String(length=128), nullable=True),
sa.Column('content', sa.String(), nullable=True),
sa.Column('order', sa.Integer(), nullable=True),
sa.Column('disabled', sa.Boolean(), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('title')
)
op.create_table('sources',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=64), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name')
)
op.create_table('user',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('email', sa.String(length=64), nullable=True),
sa.Column('username', sa.String(length=64), nullable=True),
sa.Column('password_hash', sa.String(length=128), nullable=True),
sa.Column('avatar_hash', sa.String(length=32), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_user_email'), 'user', ['email'], unique=True)
op.create_index(op.f('ix_user_username'), 'user', ['username'], unique=True)
op.create_table('articleTypes',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=64), nullable=True),
sa.Column('introduction', sa.String(length=128), nullable=True),
sa.Column('menu_id', sa.Integer(), nullable=True),
sa.Column('setting_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['menu_id'], ['menus.id'], ),
sa.ForeignKeyConstraint(['setting_id'], ['articleTypeSettings.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name')
)
op.create_table('articles',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('title', sa.String(length=64), nullable=True),
sa.Column('content', sa.Text(), nullable=True),
sa.Column('summary', sa.Text(), nullable=True),
sa.Column('create_time', sa.DateTime(), nullable=True),
sa.Column('update_time', sa.DateTime(), nullable=True),
sa.Column('num_of_view', sa.Integer(), nullable=True),
sa.Column('articleType_id', sa.Integer(), nullable=True),
sa.Column('source_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['articleType_id'], ['articleTypes.id'], ),
sa.ForeignKeyConstraint(['source_id'], ['sources.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('title')
)
op.create_index(op.f('ix_articles_create_time'), 'articles', ['create_time'], unique=False)
op.create_index(op.f('ix_articles_update_time'), 'articles', ['update_time'], unique=False)
op.create_table('comments',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('content', sa.Text(), nullable=True),
sa.Column('timestamp', sa.DateTime(), nullable=True),
sa.Column('author_name', sa.String(length=64), nullable=True),
sa.Column('author_email', sa.String(length=64), nullable=True),
sa.Column('avatar_hash', sa.String(length=32), nullable=True),
sa.Column('article_id', sa.Integer(), nullable=True),
sa.Column('disabled', sa.Boolean(), nullable=True),
sa.Column('comment_type', sa.String(), nullable=True),
sa.Column('reply_to', sa.String(), nullable=True),
sa.ForeignKeyConstraint(['article_id'], ['articles.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('follows',
sa.Column('follower_id', sa.Integer(), nullable=False),
sa.Column('followed_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['followed_id'], ['comments.id'], ),
sa.ForeignKeyConstraint(['follower_id'], ['comments.id'], ),
sa.PrimaryKeyConstraint('follower_id', 'followed_id')
)
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_table('follows')
op.drop_table('comments')
op.drop_index(op.f('ix_articles_update_time'), table_name='articles')
op.drop_index(op.f('ix_articles_create_time'), table_name='articles')
op.drop_table('articles')
op.drop_table('articleTypes')
op.drop_index(op.f('ix_user_username'), table_name='user')
op.drop_index(op.f('ix_user_email'), table_name='user')
op.drop_table('user')
op.drop_table('sources')
op.drop_table('plugins')
op.drop_table('menus')
op.drop_table('blog_view')
op.drop_table('blog_info')
op.drop_table('articleTypeSettings')
### end Alembic commands ###