Ejemplo n.º 1
0
def deploy():
    """
    执行部署任务
    :return:
    """

    # 清空数据库
    # TODO

    # 为MongoDB 添加专用自增序列尾值记录表
    add_mongo_counters()
    # 默认角色添加
    Role.insert_default_roles()
    # 权限数据库索引与默认数据添加
    Permission.create_table_indexes()
    Permission.insert_defaults_permissions()
    # 权限角色关系数据库索引与默认数据添加
    PermissionsRoles.create_table_indexes()
    PermissionsRoles.insert_defaults_permissions_roles()
    # 文章数据库索引
    Post.create_table_indexes()
    # 用户数据库索引
    User.create_table_indexes()
    # 设置数据库索引与默认数据添加
    Setting.insert_default_settings()
    # 标签数据库索引
    Tag.create_table_indexes()
    # 评论数据库索引
    Comment.create_table_indexes()
Ejemplo n.º 2
0
def deploy():
    """
    执行部署任务
    :return:
    """

    # 清空数据库
    # TODO

    # 为MongoDB 添加专用自增序列尾值记录表
    add_mongo_counters()
    # 默认角色添加
    Role.insert_default_roles()
    # 权限数据库索引与默认数据添加
    Permission.create_table_indexes()
    Permission.insert_defaults_permissions()
    # 权限角色关系数据库索引与默认数据添加
    PermissionsRoles.create_table_indexes()
    PermissionsRoles.insert_defaults_permissions_roles()
    # 文章数据库索引
    Post.create_table_indexes()
    # 用户数据库索引
    User.create_table_indexes()
    # 设置数据库索引与默认数据添加
    Setting.insert_default_settings()
    # 标签数据库索引
    Tag.create_table_indexes()
    # 评论数据库索引
    Comment.create_table_indexes()
Ejemplo n.º 3
0
def article_detail(post_id):
    post = Post.get_post(post_id)
    if not post or not post.post_id or post.status != "published":
        abort(404)
    author = User(user_id=post.author_id)
    comment_form = CommentForm()
    return render_template("article.html", post=post, author=author, comment_form=comment_form)
Ejemplo n.º 4
0
def article_detail(post_id):
    post = Post.get_post(post_id)
    if not post or not post.post_id or post.status != 'published':
        abort(404)
    author = User(user_id=post.author_id)
    comment_form = CommentForm()
    return render_template('article.html',
                           post=post,
                           author=author,
                           comment_form=comment_form)
Ejemplo n.º 5
0
def add_post():
    if not g.current_user.can('add_posts'):
        return jsonify({'success': 0, 'error': 'permission denied', 'message': u'没有权限添加文章'})
    pid_token = request.form.get('pidToken', '')
    if pid_token:
        post_id = Post.get_pid_from_token(pid_token)
    else:
        post_id = None
    title = request.form.get('title', 'Untitled')
    markdown = request.form.get('markdown')
    slug = request.form.get('slug')
    image = request.form.get('thumbUrl', '')
    meta_title = request.form.get('metaTitle', '')
    meta_description = request.form.get('metaDescription', '')
    type = 'page' if request.form.get('postType') == 'page' else 'post'
    tag_ids = request.form.get('tags', '')  # 为 tag id 以逗号拼接的字符串
    action = 'draft' if request.form.get('action') not in ['publish', 'update', 'draft'] else request.form.get('action')
    author_id = g.current_user.get_id()
    update_by = g.current_user.get_id()

    if post_id and action == 'update':
        pid = Post.update_post(post_id, title=title, markdown=markdown, slug=slug, image=image, meta_title=meta_title,
                               meta_description=meta_description, type=type, tag_ids=tag_ids,
                               author_id=author_id, update_by=update_by)
        if not pid:
            return action_failed(message=u'更新文章失败')
        post = Post.get_post_json(pid)
        return jsonify({'success': 1, 'post': post, 'postId': pid})

    if action == 'publish':
        pid = Post.publish_post(post_id, title=title, markdown=markdown, slug=slug, image=image, meta_title=meta_title,
                                meta_description=meta_description, type=type, tag_ids=tag_ids,
                                author_id=author_id, update_by=update_by)
        message = u'发表文章失败'
    else:
        pid = Post.draft_post(post_id, title=title, markdown=markdown, slug=slug, image=image, meta_title=meta_title,
                              meta_description=meta_description, type=type, tag_ids=tag_ids,
                              author_id=author_id, update_by=update_by)
        message = u'添加文章失败'
    if not pid:
        return action_failed(message=message)
    post = Post.get_post_json(pid)
    return jsonify({'success': 1, 'post': post, 'postId': pid, 'editUrl': url_for('dashboard.edit_post', post_id=pid,
                                                                                  _external=True)})
Ejemplo n.º 6
0
def edit_post(post_id):
    post = Post.get_post(post_id)
    return render_template('dashboard/dash_post_edit.html', post=post)
Ejemplo n.º 7
0
def add_post():
    if not g.current_user.can('add_posts'):
        return jsonify({
            'success': 0,
            'error': 'permission denied',
            'message': u'没有权限添加文章'
        })
    pid_token = request.form.get('pidToken', '')
    if pid_token:
        post_id = Post.get_pid_from_token(pid_token)
    else:
        post_id = None
    title = request.form.get('title', 'Untitled')
    markdown = request.form.get('markdown')
    slug = request.form.get('slug')
    image = request.form.get('thumbUrl', '')
    meta_title = request.form.get('metaTitle', '')
    meta_description = request.form.get('metaDescription', '')
    type = 'page' if request.form.get('postType') == 'page' else 'post'
    tag_ids = request.form.get('tags', '')  # 为 tag id 以逗号拼接的字符串
    action = 'draft' if request.form.get('action') not in [
        'publish', 'update', 'draft'
    ] else request.form.get('action')
    author_id = g.current_user.get_id()
    update_by = g.current_user.get_id()

    if post_id and action == 'update':
        pid = Post.update_post(post_id,
                               title=title,
                               markdown=markdown,
                               slug=slug,
                               image=image,
                               meta_title=meta_title,
                               meta_description=meta_description,
                               type=type,
                               tag_ids=tag_ids,
                               author_id=author_id,
                               update_by=update_by)
        if not pid:
            return action_failed(message=u'更新文章失败')
        post = Post.get_post_json(pid)
        return jsonify({'success': 1, 'post': post, 'postId': pid})

    if action == 'publish':
        pid = Post.publish_post(post_id,
                                title=title,
                                markdown=markdown,
                                slug=slug,
                                image=image,
                                meta_title=meta_title,
                                meta_description=meta_description,
                                type=type,
                                tag_ids=tag_ids,
                                author_id=author_id,
                                update_by=update_by)
        message = u'发表文章失败'
    else:
        pid = Post.draft_post(post_id,
                              title=title,
                              markdown=markdown,
                              slug=slug,
                              image=image,
                              meta_title=meta_title,
                              meta_description=meta_description,
                              type=type,
                              tag_ids=tag_ids,
                              author_id=author_id,
                              update_by=update_by)
        message = u'添加文章失败'
    if not pid:
        return action_failed(message=message)
    post = Post.get_post_json(pid)
    return jsonify({
        'success':
        1,
        'post':
        post,
        'postId':
        pid,
        'editUrl':
        url_for('dashboard.edit_post', post_id=pid, _external=True)
    })