-
Notifications
You must be signed in to change notification settings - Fork 0
/
adminManage.py
206 lines (183 loc) · 8.68 KB
/
adminManage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
"""
File Description
This file is mainly about the administrator backend control page
encoding: utf-8
@author: Zhang Jiajun
@contact: [email protected]
@software: Pycharm
@time: 2022/1/14
@gituhb: sanxiadaba/pythonBlog
"""
import platform
import sys
import time
from flask import Blueprint, render_template, request, session
from common.initDatabase import watchVersionOfMysql
from common.myLog import logDanger, adminLog, listLogger
from constant import classification, commentNum, regGiveCredit, loginEvereDayCredit, postArticleCredit, \
replyAndAddCommentCredit, rateCreditForArticle, creditListForReleaseArticle, howArticleInWeb, howCommentInArticle, \
maxUserPostArticleNum, maxUserPostArticleNumOfEditor, maxModifyArticleNum, maxUploadPicNum, blogLanguage, \
recommendedNumOfSide
from database.article import Article
from database.comment import Comment
from database.logs import Log
from database.users import Users
adminManage = Blueprint("adminManage", __name__)
instanceArticle = Article()
instanceUser = Users()
instanceLog = Log()
instanceComment = Comment()
@adminManage.route("/adminManage", methods=["GET"])
@logDanger
def baseAdminManage():
start = time.time()
webInfo = {}
webInfo["allNumOfArticle"] = instanceArticle.searchAllArticleNum()
webInfo["allArticleReply"], webInfo["allArticleRead"] = instanceArticle.searchALLNumberOfComment()
webInfo["allUserNum"] = instanceUser.searchAllNumOfUser()
webInfo["numOfAdmin"] = instanceUser.searchNumOfAdmin()
webInfo["numOfEditor"] = instanceUser.searchNumOfEditor()
webInfo["numOfUser"] = instanceUser.searchNumOfUser()
webInfo["numOfUserAndEditor"] = int(webInfo["numOfUser"]) + int(webInfo["numOfEditor"])
webInfo["pythonVersion"] = sys.version.split("(")[0]
webInfo["platForm"] = platform.platform()
webInfo["mysqlVersion"] = watchVersionOfMysql()
webInfo["lastServeTime"] = instanceLog.searchTimeOfLastTimeServe().split("in")[-1].strip()
# First convert the data type in the list to str otherwise, because join can only splice strings
for i in range(len(creditListForReleaseArticle)):
creditListForReleaseArticle[i] = str(creditListForReleaseArticle[i])
for i in range(len(recommendedNumOfSide)):
recommendedNumOfSide[i] = str(recommendedNumOfSide[i])
webInfo["classification"] = " ".join(classification)
webInfo["commentNum"] = commentNum
webInfo["regGiveCredit"] = regGiveCredit
webInfo["loginEvereDayCredit"] = loginEvereDayCredit
webInfo["postArticleCredit"] = postArticleCredit
webInfo["replyAndAddCommentCredit"] = replyAndAddCommentCredit
webInfo["rateCreditForArticle"] = rateCreditForArticle
webInfo["creditListForReleaseArticle"] = " ".join(creditListForReleaseArticle)
webInfo["howArticleInWeb"] = howArticleInWeb
webInfo["howCommentInArticle"] = howCommentInArticle
webInfo["maxUserPostArticleNum"] = maxUserPostArticleNum
webInfo["maxUserPostArticleNumOfEditor"] = maxUserPostArticleNumOfEditor
webInfo["maxModifyArticleNum"] = maxModifyArticleNum
webInfo["recommendedNumOfSide"] = " ".join(recommendedNumOfSide)
webInfo["maxUploadPicNum"] = maxUploadPicNum
webInfo["language"] = blogLanguage
usersInfo = instanceUser.searchInfoOfUserAndEditor()
commentInfo = instanceComment.searchCommentInfo()
end = time.time()
loadTime = end - start
webInfo["loadTime"] = loadTime
webNumOfDraft = instanceArticle.searchNumOfDraft()
webDraft = instanceArticle.searchDraft()
webArticles=instanceArticle.searchAllArtice()
return render_template("adminManage.html", webInfo=webInfo, usersInfo=usersInfo, commentInfo=commentInfo,
webDraft=webDraft, webNumOfDraft=webNumOfDraft,allArticles=webArticles)
# Jumping options for "memory" admin pages
@adminManage.route("/adminTiaoNum", methods=["GET", "POST"])
@logDanger
def adminTiaoNum():
if request.method == 'GET':
adminTiaoNum = session.get("adminTiaoNum")
session["adminTiaoNum"] = adminTiaoNum if adminTiaoNum != 0 and adminTiaoNum != "0" else "0"
if adminTiaoNum is not None and adminTiaoNum != "0" and adminTiaoNum != 0:
return str(adminTiaoNum)
else:
return "1"
elif request.method == 'POST':
session["adminTiaoNum"] = str(request.form.get("adminTiaoNum"))
return "1"
# Agree to the article being reviewed
@adminManage.route("/passDraft", methods=["POST"])
@logDanger
def passDraft():
articleid = int(request.form.get("articleid"))
userid = instanceArticle.searchUseridByArticleid(articleid)
username = instanceUser.searchUsernameByUserd(userid)
nickname = instanceUser.searchNicknameByUserid(userid)
headline = instanceArticle.searchHeadlineByArticleid(articleid)
info = f"userid is {userid},nickname is {username},nickname is {nickname} Administrators pass articleid is {articleid},headline is {headline} draft"
listLogger(userid, info, [3])
adminLog(info)
authorUserid = instanceArticle.searchUseridByArticleid(articleid)
authorUsername = instanceUser.searchUsernameByUserd(authorUserid)
authorNickname = instanceUser.searchNicknameByUserid(authorUserid)
info = f"userid is {authorUserid},nickname is {authorUsername},nickname is {authorNickname} Administrators pass articleid is {articleid},headline is {headline} draft"
listLogger(authorUserid, info, [3])
instanceArticle.passDraft(articleid)
return "1"
# Rejecting articles from review
@adminManage.route("/rejectDraft", methods=["POST"])
@logDanger
def rejectDraft():
articleid = int(request.form.get("articleid"))
userid = instanceArticle.searchUseridByArticleid(articleid)
username = instanceUser.searchUsernameByUserd(userid)
nickname = instanceUser.searchNicknameByUserid(userid)
headline = instanceArticle.searchHeadlineByArticleid(articleid)
info = f"userid is {userid},nickname is {username},nickname is {nickname} Administrators reject articleid is {articleid},headline is {headline} draft"
listLogger(userid, info, [3])
adminLog(info)
authorUserid = instanceArticle.searchUseridByArticleid(articleid)
authorUsername = instanceUser.searchUsernameByUserd(authorUserid)
authorNickname = instanceUser.searchNicknameByUserid(authorUserid)
info = f"userid is {authorUserid},nickname is {authorUsername},nickname is {authorNickname} Administrators reject articleid is {articleid},headline is {headline} draft"
listLogger(authorUserid, info, [3])
instanceArticle.passDraft(articleid)
return "1"
# Preview of draft articles
@adminManage.route("/reviewDraft/<int:articleid>")
@logDanger
def reviewDraft(articleid):
articleid = int(articleid)
article = instanceArticle.reviewDraft(articleid)
return render_template("reviewDraft.html", article=article)
# hide article
@adminManage.route("/hideArticle",methods=["POST"])
@logDanger
def hideArticle():
userid=session.get("userid")
username=instanceUser.searchUsernameByUserd(userid)
articleid = request.form.get('articleid')
instanceArticle.hideArticle(articleid)
info=f"userid is {userid}, username is {username} of the administrator, hidden articleid is {articleid} of the article"
listLogger(userid, info, [3])
adminLog(info)
return "1"
# cancle hide article
@adminManage.route("/cancleHideArticle",methods=["POST"])
@logDanger
def cancleHideArticle():
userid=session.get("userid")
username=instanceUser.searchUsernameByUserd(userid)
articleid = request.form.get('articleid')
instanceArticle.cancleHideArticle(articleid)
info=f"userid is {userid}, username is {username} of the administrator, cancle hide articleid is {articleid} of the article"
listLogger(userid, info, [3])
adminLog(info)
return "1"
# recommended the article
@adminManage.route("/recommendedArticle",methods=["POST"])
@logDanger
def recommendedArticle():
userid = session.get("userid")
username = instanceUser.searchUsernameByUserd(userid)
articleid = request.form.get('articleid')
instanceArticle.recommendedArticle(articleid)
info=f"userid is {userid},username is {username} of the administrator,recommended articleid is {articleid} of the article"
listLogger(userid, info, [3])
adminLog(info)
return "1"
# cancle recommended the article
@adminManage.route("/cancleRecommendedArticle",methods=["POST"])
@logDanger
def cancleRecommendedArticle():
userid = session.get("userid")
username = instanceUser.searchUsernameByUserd(userid)
articleid = request.form.get('articleid')
instanceArticle.cancleRecommendedArticle(articleid)
info=f"userid is {userid},username is {username} of the administrator,cancle recommended articleid is {articleid} of the article"
listLogger(userid, info, [3])
adminLog(info)
return "1"