Ejemplo n.º 1
0
Archivo: main.py Proyecto: zhddong/blog
def details():
    if request.method == "POST":
        ct_id = request.form.get("id")
        page = request.form.get("page")
        blog_comment = Comment(cfg)
        comment = blog_comment.comments_query(ct_id)
        # print(ct_id)
        if not comment:
            res = {"code": -1, "msg": "还没有评论", "count": 0, "data": []}
            res = json.dumps(res)
            response = make_response(res)
            return response
        list_comment = list(comment)
        comment_new = []
        for i in list_comment:
            name = i[0]  #用户名
            like = i[1]  #点赞量
            content = i[2]  #评论内容
            articlecontent = {
                "name": name,
                "like": like,
                "content": content[0:200]
            }
            # print(articlecontent)
            comment_new.append(articlecontent)
        page = int(page)
        page = page - 1
        page_final = page * 3
        comment_final = comment_new[page_final:page_final + 3]
        # print(c)
        if not comment_final:
            res = {"code": -1, "msg": "没有评论", "count": 0, "data": []}
        else:
            res = {"code": 0, "msg": "", "count": 0, "data": comment_final}
        res = json.dumps(res)
        response = make_response(res)
        response.headers["Access-Control-Allow-Origin"] = "*"
        return response
    else:
        ct_id = request.args.get("id")
        blog_article = Article(cfg)
        data = blog_article.ct_details(ct_id)
        # blog_comment = Comment(cfg)
        # comment = blog_comment.comments_query(ct_id)
        # print(comment)
        if not data:
            res = "该文章不存在!!!"
            response = make_response(res, 404)
            response.headers["Access-Control-Allow-Origin"] = "*"
            return response
        # ct_content = ""
        # for ct in data[0][1].split("\n"):
        #     ct_content += "<p>" + ct + "</p>"
        return render_template('details.html',
                               ct_title=data[0][0],
                               ct_content=data[0][1],
                               ct_time=data[0][2],
                               ct_read=data[0][5],
                               ct_like=data[0][6],
                               ct_id=ct_id)
Ejemplo n.º 2
0
Archivo: main.py Proyecto: zhddong/blog
def xianyan_dispaly():
    if request.method == "POST":
        create_time = request.form.get("create_time")
        title = request.form.get("title")
        content = request.form.get("content")
        page = request.form.get("page")
    else:
        create_time = request.args.get("create_time")
        title = request.args.get("title")
        content = request.args.get("content")
        page = request.args.get("page")
    blog_article = Article(cfg)
    data = blog_article.xianyan_display()
    # print(data)
    blog_content_info = Content_info(cfg)
    list_data = list(data)
    data_new = []
    for i in list_data:
        title = i[0]  #标题
        content = i[1]  #文章内容
        create_time = i[2]  #创建时间
        content_id = i[4]  #文章ID
        is_like = blog_content_info.fabulous_query(content_id)
        if not is_like:
            is_like = 0
        else:
            is_like = 1
        create_time = str(create_time)
        articlecontent = {
            "create_time": create_time,
            "title": title,
            "content": content[0:200],
            "id": content_id,
            "is_like": is_like
        }
        # print(articlecontent)
        data_new.append(articlecontent)
    if not page:
        page = 1
    else:
        page = int(page)
    page = page - 1
    page_final = page * 10
    data_final = data_new[page_final:page_final + 10]
    # print(c)
    if not data_final:
        res = {"code": -1, "msg": "没有找到", "count": 0, "data": []}
    else:
        res = {"code": 0, "msg": "", "count": len(data), "data": data_final}
    res = json.dumps(res)
    response = make_response(res)
    response.headers["Access-Control-Allow-Origin"] = "*"
    return response
Ejemplo n.º 3
0
Archivo: main.py Proyecto: zhddong/blog
def details_article():
    if request.method == "POST":
        ct_id = request.form.get("id")
        blog_article = Article(cfg)
        data = blog_article.ct_details(ct_id)
        blog_content_info = Content_info(cfg)
        data = list(data)
        data_new = []
        for i in data:
            title = i[0]  #标题
            content = i[1]  #文章内容
            create_time = i[2]  #创建时间
            content_id = i[4]  #文章ID
            read = i[5]  #阅读量
            like = i[6]  #点赞量
            is_like = blog_content_info.fabulous_query(content_id)
            if not is_like:
                is_like = 0
            else:
                is_like = 1
            create_time = str(create_time)
            exts = [
                'markdown.extensions.extra', 'markdown.extensions.codehilite',
                'markdown.extensions.tables', 'markdown.extensions.toc'
            ]
            content = markdown.markdown(content, extensions=exts)
            articlecontent = {
                "create_time": create_time,
                "title": title,
                "content": content,
                "read": read,
                "id": content_id,
                "is_like": is_like,
                "like": like
            }
            # print(articlecontent)
            data_new.append(articlecontent)
        if not data_new:
            res = {"code": -1, "msg": "没有找到", "count": 0, "data": []}
        else:
            res = {"code": 0, "msg": "", "count": len(data), "data": data_new}
        res = json.dumps(res)
        response = make_response(res)
        response.headers["Access-Control-Allow-Origin"] = "*"
        return response
Ejemplo n.º 4
0
Archivo: main.py Proyecto: zhddong/blog
def delete_articles():
    delete_id = request.form.get("id")
    # print(delete_id)
    blog_article = Article(cfg)
    blog_article.delete(delete_id)
    blog_article.commit()
    res = {"code": 0, "msg": "", "data": []}
    res = json.dumps(res)
    response = make_response(res)
    response.headers["Access-Control-Allow-Origin"] = "*"
    return response
Ejemplo n.º 5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 使用方法 python md2html.py  filename

import os, sys
sys.path.append("..")
import markdown
from model.blog_article import Article
import config
cfg = config.load_config("config/config.json")
model_article = Article(cfg)

head = """<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<style type="text/css">
code {
  color: inherit;
  background-color: rgba(0, 0, 0, 0.05);
}
</style>
</head>
<body>
"""

foot = """
</body>
</html>
"""
Ejemplo n.º 6
0
Archivo: main.py Proyecto: zhddong/blog
def content_list():
    if request.method == "POST":
        req_id = request.form.get("id")
        req_author = request.form.get("author")
        req_title = request.form.get("title")
        req_label = request.form.get("label")
        page = request.form.get("page")
        blog_article = Article(cfg)
        data = blog_article.data_all_display()
        # print(data)
        if not data:
            res = {"code": -1, "msg": "没有找到", "count": 0, "data": []}
            # res = json.dumps(res)
            # response = make_response(res)
            # response.headers["Access-Control-Allow-Origin"] = "*"
            # return response
        list_data = list(data)
        data_new = []
        for i in list_data:
            id = i[0]  #文章id
            name = i[1]  #作者
            title = i[2]  #文章标题
            label = i[3]  #标签
            content = i[4]  #文章内容
            create_time = str(i[5])  #创建时间
            status = i[6]  #文章状态
            if req_id and int(req_id) != id:
                continue
            if req_author and req_author != name:
                continue
            if req_title and req_title not in title:
                continue
            if req_label and int(req_label) != label:
                continue
            # if req_author in name and req_id=None and req_label=None:
            # data = blog_article.data_name_display(req_author)
            # if req_author not in name:
            #     continue
            # if req_title not in title:
            #     continue
            # if status == 0:
            #     status_0 = 0
            # else:
            #     status_0 = 1
            label_id = transformation_2(label)
            articlecontent = {
                "id": id,
                "label": label_id,
                "title": title,
                "author": name,
                "content": content,
                "uploadtime": create_time,
                "status": status
            }
            data_new.append(articlecontent)
            # print(articlecontent)
        if not page:
            page = 1
        else:
            page = int(page)
        # print(page)
        page = page - 1
        page_final = page * 10
        # print(b)
        if not data_new:
            res = {"code": -1, "msg": "没有找到", "count": 0, "data": []}
        else:
            res = {
                "code": 0,
                "msg": "",
                "count": len(data),
                "data": data_new[page_final:page_final + 10]
            }
        res = json.dumps(res)
        response = make_response(res)
        response.headers["Access-Control-Allow-Origin"] = "*"
        return response
    else:
        req_id = request.args.get("id")
        req_author = request.args.get("author")
        req_title = request.args.get("title")
        req_label = request.args.get("label")
        page = request.args.get("page")
        blog_article = Article(cfg)
        data = blog_article.data_all_display()
        if not data:
            res = {"code": -1, "msg": "没有找到", "count": 0, "data": []}
        list_data = list(data)
        data_new = []
        for i in list_data:
            id = i[0]  #文章id
            name = i[1]  #作者
            title = i[2]  #文章标题
            label = i[3]  #标签
            content = i[4]  #文章内容
            create_time = str(i[5])  #创建时间
            status = i[6]  #文章状态
            if req_id and int(req_id) != id:
                continue
            if req_author and req_author != name:
                continue
            if req_title and req_title not in title:
                continue
            if req_label and int(req_label) != label:
                continue
            label_id = transformation_2(label)
            articlecontent = {
                "id": id,
                "label": label_id,
                "title": title,
                "author": name,
                "content": content,
                "uploadtime": create_time,
                "status": status
            }
            data_new.append(articlecontent)
        if not page:
            page = 1
        else:
            page = int(page)
        page = page - 1
        page_final = page * 10
        if not data_new:
            res = {"code": -1, "msg": "没有找到", "count": 0, "data": []}
        else:
            res = {
                "code": 0,
                "msg": "",
                "count": len(data),
                "data": data_new[page_final:page_final + 10]
            }
        res = json.dumps(res)
        response = make_response(res)
        response.headers["Access-Control-Allow-Origin"] = "*"
        return response
Ejemplo n.º 7
0
Archivo: main.py Proyecto: zhddong/blog
def browse():
    blog_article = Article(cfg)
    data = blog_article.browse(ct_id)
Ejemplo n.º 8
0
Archivo: main.py Proyecto: zhddong/blog
def content():
    if request == "POST":
        title = request.form.get("title")
        user_id = request.form.get("author")
        content = request.form.get("content")
        label = request.form.get("label")
        classification = request.form.get("classification")
        status = request.form.get("status")
        status = status_num(status)
        user_id = int(user_id)
        content = cgi.escape(content)
        blog_article = Article(cfg)
        label_id = transformation(label)
        class_id = transformation1(classification)
        blog_article.increase(user_id, title, class_id, content, label_id,
                              status)
        blog_article.commit()
        res = {"code": 0, "msg": "", "data": []}
        res = json.dumps(res)
        response = make_response(res)
        response.headers["Access-Control-Allow-Origin"] = "*"
        return response
    else:
        title = request.args.get("title")
        user_id = request.args.get("author")
        content = request.args.get("content")
        label = request.args.get("label")
        classification = request.args.get("classification")
        status = request.args.get("status")
        status = status_num(status)
        user_id = int(user_id)
        content = cgi.escape(content)
        blog_article = Article(cfg)
        label_id = transformation(label)
        class_id = transformation1(classification)
        blog_article.increase(user_id, title, class_id, content, label_id,
                              status)
        blog_article.commit()
        res = {"code": 0, "msg": "", "data": []}
        res = json.dumps(res)
        response = make_response(res)
        response.headers["Access-Control-Allow-Origin"] = "*"
        return response