Exemplo n.º 1
0
def article_add():
    if current_user.is_admin == 0:
        flash(u'只有管理员才有权限查看当前页面!')
        return redirect(url_for('main.index'))
    else:
        import sys
        reload(sys)
        sys.setdefaultencoding(u"utf-8")

        f = request.files['article']

        title = request.form.get('art_title')
        if ArticleDao().get_article_by_title(title) is not None:
            articles, info1 = ArticleDao().get_articles()
            categories = CategoryDAO().get_categories()
            authors = AuthorDAO().get_authors()
            return render_template('admin/article.html',
                                   articles=articles,
                                   categories=categories,
                                   authors=authors,
                                   info=u'文章标题已经存在!')

        f.save(u'blogs/{file}'.format(file=f.filename))

        art_author = request.form.get('art_author')
        author_id = art_author.split('--')[0] if art_author is not None else 1
        author_name = art_author.split(
            '--')[1] if art_author is not None else u'admin'
        category = request.form.get('art_cate')
        cate_id = category.split('--')[0] if category is not None else 1
        cate_name = category.split('--')[1] if category is not None else u'未分类'
        intro = request.form.get('art_intro')
        tags = request.form.get('art_tags')
        tags = tags.replace(u',', ',')

        result, info = ArticleDao().new_article(
            title=title,
            intro=intro,
            author_id=author_id,
            author_name=author_name,
            cate_id=cate_id,
            cate_name=cate_name,
            filepath=u'blogs/{file}'.format(file=f.filename),
            tags=tags)
        articles, info1 = ArticleDao().get_articles()
        categories = CategoryDAO().get_categories()
        authors = AuthorDAO().get_authors()
        return render_template('admin/article.html',
                               articles=articles,
                               categories=categories,
                               authors=authors,
                               info=info)
Exemplo n.º 2
0
def tags(tag):
    articles, more = ArticleDao().get_article_by_tag(tag)
    categories = CategoryDAO().get_categories()
    return render_template('main/index.html',
                           categories=categories,
                           articles=articles,
                           more=True if more == 'more' else False)
Exemplo n.º 3
0
def index():
    cate_dao = CategoryDAO()
    categories = cate_dao.get_categories()
    articles, more = ArticleDao().get_articles()
    return render_template('main/index.html',
                           categories=categories,
                           articles=articles,
                           more=True if more == 'more' else False)
Exemplo n.º 4
0
def article(article_id):
    categories = CategoryDAO().get_categories()
    article1 = ArticleDao().get_article_by_id(article_id)
    if article1 is None:
        return abort(404)
    return render_template('main/article.html',
                           categories=categories,
                           article_id=article1.id,
                           active_cat=article1.cate_id)
Exemplo n.º 5
0
def comment():
    article_id = request.form['article']
    if ArticleDao().get_article_by_id(article_id) is None:
        abort(404)
    comment = request.form['comment']
    result, info = CommentDAO().new_comment(article_id, comment)
    if result:
        return redirect('/article/{art_id}'.format(art_id=article_id))
    else:
        abort(404)
Exemplo n.º 6
0
def article():
    if current_user.is_admin == 0:
        flash(u'只有管理员才有权限查看当前页面!')
        return redirect(url_for('main.index'))
    else:
        articles, info = ArticleDao().get_articles()
        categories = CategoryDAO().get_categories()
        authors = AuthorDAO().get_authors()
        return render_template('admin/article.html',
                               articles=articles,
                               categories=categories,
                               authors=authors)
Exemplo n.º 7
0
def article_delete():
    if current_user.is_admin == 0:
        flash(u'只有管理员才有权限查看当前页面!')
        return redirect(url_for('main.index'))
    else:
        art_id = request.form.get('art_id')
        art_dao = ArticleDao()
        article = art_dao.get_article_by_id(art_id)
        if article is not None:
            result, info = art_dao.delete_article(article)
        else:
            info = u'要删除的文章ID不存在!'

        articles, info1 = art_dao.get_articles()
        categories = CategoryDAO().get_categories()
        authors = AuthorDAO().get_authors()
        return render_template('admin/article.html',
                               articles=articles,
                               categories=categories,
                               authors=authors,
                               info=info)
Exemplo n.º 8
0
def get_article_content(article_id):
    try:
        article = ArticleDao().get_article_by_id(article_id)
        if article is None:
            abort(404)

        filename = os.path.sep.join([os.path.dirname(os.path.realpath(__file__)), '..', '..', article.file_path])
        with open(filename) as blog:
            html = '\n'.join(blog.readlines())
        return html
    except IOError:
        abort(500)
Exemplo n.º 9
0
def category(category_id):
    cate_dao = CategoryDAO()
    if cate_dao.get_cate_by_id(category_id) is None:
        abort(404)
    categories = cate_dao.get_categories()

    articles, more = ArticleDao().get_articles_by_cate(category_id)

    return render_template('main/index.html',
                           categories=categories,
                           articles=articles,
                           active_cat=category_id,
                           more=True if more == 'more' else False)
Exemplo n.º 10
0
def get_article_comment(article_id):
    article = ArticleDao().get_article_by_id(article_id)
    if article is None:
        abort(404)
    # return json.dumps(
    #     [
    #         {
    #             'user': '******'
    #             , 'create_time': '2017-12-12 12:12:12'
    #             , 'content': '这是测试文章的测试评论,所以评论内容可能一堆你看不懂的东西,这你应该能理解吧~'
    #             , 'good': 10
    #             , 'bad': 0
    #             , 'replay': "renjie,,,2017-12-12 12:12:12,,,这是回复内容"
    #         }, {
    #             'user': '******'
    #             , 'create_time': '2017-12-12 12:12:13'
    #             , 'content': '这是测试文章的测试评论,所以评论内容可能一堆你看不懂的东西,这你应该能理解吧~'
    #             , 'good': 10
    #             , 'bad': 0
    #             , 'replay': "renjie,,,2017-12-12 12:12:13,,,这是回复内容"
    #         }
    #     ]
    # )
    results, info = CommentDAO().get_comments_by_article(article_id)

    comment_list = []
    for comment in results:
        c = {}
        c['id'] = comment.id
        c['article_id'] = comment.article_id
        c['user'] = comment.user
        c['comment'] = comment.comment
        c['good'] = comment.good
        c['bad'] = comment.bad
        c['replay'] = comment.replay
        c['create_time'] = comment.create_time.strftime('%Y-%m-%d %H:%M:%S')
        c['modified_time'] = comment.modified_time.strftime('%Y-%m-%d %H:%M:%S')
        print c
        comment_list.append(c)
    return json.dumps(comment_list)