From ecf5eb56685cd4882046b978b6af8c52d9f2212d Mon Sep 17 00:00:00 2001 From: interestingLSY <2659723130@qq.com> Date: Wed, 1 May 2019 10:51:53 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD:=20?= =?UTF-8?q?=E5=90=B1=E5=A3=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... \347\232\204 \345\220\261\345\243\260.md" | 19 ++++++++ web/app.py | 2 +- web/config-example.json | 5 ++- web/sites/db.py | 30 +++++++++---- web/sites/home.py | 45 +++++++++++++++++-- web/templates/home.html | 29 ++++++++++++ 6 files changed, 115 insertions(+), 15 deletions(-) create mode 100644 "document/intoj \347\232\204 \345\220\261\345\243\260.md" diff --git "a/document/intoj \347\232\204 \345\220\261\345\243\260.md" "b/document/intoj \347\232\204 \345\220\261\345\243\260.md" new file mode 100644 index 00000000..7681a10f --- /dev/null +++ "b/document/intoj \347\232\204 \345\220\261\345\243\260.md" @@ -0,0 +1,19 @@ +# intoj 的 吱声.md + +--- + +数据库: + +- id +- username +- message +- send_time + +```sql +CREATE TABLE zisheng( + id INT NOT NULL PRIMARY KEY auto_increment, + username VARCHAR(20), + message TEXT, + send_time VARCHAR(50) +); +``` diff --git a/web/app.py b/web/app.py index 5a9dbcbd..4fa1d520 100644 --- a/web/app.py +++ b/web/app.py @@ -48,7 +48,7 @@ def Error_404(e): def Blank(): return render_template('base.html') -@app.route('/') +@app.route('/',methods=['GET','POST']) def Home(): return sites.home.Run() diff --git a/web/config-example.json b/web/config-example.json index 7b29b2d9..dedbce31 100644 --- a/web/config-example.json +++ b/web/config-example.json @@ -10,7 +10,10 @@ "port": 6379 }, "site": { - "use_resource": "online" + "use_resource": "online", + "zisheng": { + "max_length": "400" + } }, "enable_lang": [ { diff --git a/web/sites/db.py b/web/sites/db.py index 868c0d2a..ee823841 100644 --- a/web/sites/db.py +++ b/web/sites/db.py @@ -3,6 +3,7 @@ import modules,config def Generate_Limitation(limitation,allowed=[]): + if limitation == None: return '',[] answer = '' arg = [] for key,value in limitation.items(): @@ -51,13 +52,9 @@ def Read_Submissions(limitation=None,order="id DESC"): 'contest_id': ('eq','contest_id') } db,cur = Connect() - if limitation != None: - lim,arg = Generate_Limitation(limitation,allowed) - cmd = "SELECT * FROM records %s ORDER BY %s" % (lim,modules.Raw(order)) - cur.execute(cmd,arg) - else: - cur.execute("SELECT * FROM records ORDER BY %s"%order) - + lim,arg = Generate_Limitation(limitation,allowed) + cmd = "SELECT * FROM records %s ORDER BY %s" % (lim,modules.Raw(order)) + cur.execute(cmd,arg) submissions = cur.fetchall() End_Connect(db,cur) return submissions @@ -85,9 +82,9 @@ def Read_Contest_Ranklist(contest_id): def Read_Record(id): db,cur = Connect() cur.execute("SELECT * FROM records WHERE id=%s;",id) - urecord = cur.fetchone() + record = cur.fetchone() End_Connect(db,cur) - return urecord + return record def Read_Userlist(): db,cur = Connect() @@ -130,3 +127,18 @@ def User_Privilege(username,privilege_name): if user == None: return 0 if user['is_admin']: return 1 return user[privilege_name] + +def Read_Zisheng(limitation=None,top=10): + allowed = { + 'id': ('eq','id'), + 'username': ('eq','username') + } + db,cur = Connect() + + lim,arg = Generate_Limitation(limitation,allowed) + cmd = "SELECT * FROM zisheng %s ORDER BY id DESC LIMIT %d" % (lim,top) + cur.execute(cmd,arg) + zisheng = cur.fetchall() + + End_Connect(db,cur) + return zisheng diff --git a/web/sites/home.py b/web/sites/home.py index 020c801b..1255c8dd 100644 --- a/web/sites/home.py +++ b/web/sites/home.py @@ -1,10 +1,47 @@ #coding:utf-8 from flask import * -import db,modules +import db,modules,config +import datetime -def Run(): - contests = db.Read_Contestlist() +zisheng_delay_time = 3 +def GET(): + contests = db.Read_Contestlist() users = list(db.Read_Userlist()) users.sort( key = lambda x: (x['total_ac'],-x['total_submit']) , reverse=True ) - return render_template('home.html',contests=contests,users=users[:10]) + zishengs = db.Read_Zisheng() + return render_template('home.html',contests=contests,users=users[:10],zishengs=zishengs) + +def Send_Zisheng(): + if not modules.Is_Loggedin(): + flash('请先登录','error') + return False + + message = request.form['message'] + max_length = config.config['site']['zisheng']['max_length'] + if len(message) > max_length: + flash('超过最长长度: %d'%max_length,'error') + return False + + username = request.cookies['username'] + last_zisheng_time = modules.Get_Session('last_zisheng_time',username) + now_time = datetime.datetime.now() + if last_zisheng_time != None: + seconds = (now_time-last_zisheng_time).seconds + if seconds < zisheng_delay_time: + flash('请在 %ss 后提交'%(zisheng_delay_time-seconds),'error') + return False + modules.Set_Session('last_zisheng_time',username,now_time) + + nowtime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + db.Execute("INSERT INTO zisheng VALUES(NULL,%s,%s,%s);",(username,request.form['message'],nowtime)) + + flash('发送成功','ok') + return True + +def Run(): + if request.method == 'GET': + return GET() + else: + is_success = Send_Zisheng() + return redirect('/') diff --git a/web/templates/home.html b/web/templates/home.html index ed1fc830..be3e589d 100644 --- a/web/templates/home.html +++ b/web/templates/home.html @@ -41,6 +41,35 @@ +
+
+
吱声
+
+
+ + +
+
+
+ {% for zisheng in zishengs %} +
+
+ + + @ {{zisheng['username']}} + + + {{zisheng['send_time']}} + + +
+
+ {{- zisheng['message'] -}} +
+
+ {% endfor %} +
+
From b5309cd8b0a942867dfa3b6887a5d237f15db2b3 Mon Sep 17 00:00:00 2001 From: interestingLSY <2659723130@qq.com> Date: Wed, 1 May 2019 11:01:57 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=98=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E5=9C=A8=20config.json=20=E4=B8=AD=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E5=90=B1=E5=A3=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/config-example.json | 1 + web/sites/home.py | 3 +++ web/templates/home.html | 48 +++++++++++++++++++++++------------------ 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/web/config-example.json b/web/config-example.json index dedbce31..cf50d697 100644 --- a/web/config-example.json +++ b/web/config-example.json @@ -12,6 +12,7 @@ "site": { "use_resource": "online", "zisheng": { + "enable": true, "max_length": "400" } }, diff --git a/web/sites/home.py b/web/sites/home.py index 1255c8dd..e8a6e5d6 100644 --- a/web/sites/home.py +++ b/web/sites/home.py @@ -16,6 +16,9 @@ def Send_Zisheng(): if not modules.Is_Loggedin(): flash('请先登录','error') return False + if not config.config['site']['zisheng']['enable']: + flash('管理员已关闭「吱声」','error') + return False message = request.form['message'] max_length = config.config['site']['zisheng']['max_length'] diff --git a/web/templates/home.html b/web/templates/home.html index be3e589d..9537d208 100644 --- a/web/templates/home.html +++ b/web/templates/home.html @@ -44,30 +44,36 @@
吱声
-
-
- - -
-
-
- {% for zisheng in zishengs %} -
-
- - - @ {{zisheng['username']}} - - - {{zisheng['send_time']}} + {% if config['site']['zisheng']['enable'] %} +
+
+ + +
+
+
+ {% for zisheng in zishengs %} +
+
+ + + @ {{zisheng['username']}} + + + {{zisheng['send_time']}} + - -
-
- {{- zisheng['message'] -}} +
+
+ {{- zisheng['message'] -}} +
+ {% endfor %} + {% else %} +
+ 该功能已被管理员关闭
- {% endfor %} + {% endif %}
From 0b50211604564f8e3d5fff1513c288c44fa61f9d Mon Sep 17 00:00:00 2001 From: interestingLSY <2659723130@qq.com> Date: Wed, 1 May 2019 11:45:20 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=B8=BB=E9=A1=B5?= =?UTF-8?q?=E4=B8=AD=E6=98=BE=E7=A4=BA=E5=90=B1=E5=A3=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/app.py | 2 + web/sites/userhome.py | 3 +- web/static/css/ui.css | 11 --- web/templates/userhome.html | 144 ++++++++++++++++++++++-------------- 4 files changed, 91 insertions(+), 69 deletions(-) diff --git a/web/app.py b/web/app.py index 4fa1d520..fc11f34a 100644 --- a/web/app.py +++ b/web/app.py @@ -18,6 +18,8 @@ app.add_template_global(min,'min') app.add_template_global(max,'max') app.add_template_global(sum,'sum') +app.add_template_global(len,'len') +app.add_template_global(random.randint,'randint') app.add_template_global(sites.modules.Argstring,'Argstring') app.add_template_global(sites.modules.Score_Color,'Score_Color') diff --git a/web/sites/userhome.py b/web/sites/userhome.py index 5c6eae80..f7e915f7 100644 --- a/web/sites/userhome.py +++ b/web/sites/userhome.py @@ -16,4 +16,5 @@ def Run(username): return modules.Page_Back() status_cnt = User_Statistic(username) - return render_template('userhome.html',user=user,status_cnt=status_cnt) + zishengs = db.Read_Zisheng({'username':username}) + return render_template('userhome.html',user=user,status_cnt=status_cnt,zishengs=zishengs,top=1000) diff --git a/web/static/css/ui.css b/web/static/css/ui.css index 476e03a8..7a0c2222 100644 --- a/web/static/css/ui.css +++ b/web/static/css/ui.css @@ -138,17 +138,6 @@ div.block-mini-inner{ border-radius: 6px; } -/**************** footer ****************/ -#footer{ - background: #ffffff88; - width: 100%; - height: 22px; - margin-top: 30px; - padding-top: 5px; - font-size: 14px; - text-align: center; -} - /**************** tags ****************/ .tag{ background-color: #cfcfcf; diff --git a/web/templates/userhome.html b/web/templates/userhome.html index b16b8bb8..52d74357 100644 --- a/web/templates/userhome.html +++ b/web/templates/userhome.html @@ -1,15 +1,31 @@ {% extends 'base.html' %} {% block title %} {{user['username']}} {% endblock %} {% block body %} -{% set called = "我" if Is_Loggedin() and user['username'] == request.cookies['username'] else "她" if user['sex'] == 1 else "他" if user['sex'] == 0 else "Ta" %} -
+{% set called = "我" if Is_Loggedin() and user['username'] == request.cookies['username'] else "她" if user['sex'] == 1 else "他" if user['sex'] == 0 else "Ta " %} +
-
+
U{{user['id']}} - {{user['username']}}
-
+
+
+
+ {{user['total_ac']}} 通过 +
+
+ {{user['total_submit']}} 提交 +
+
+
+ +
+ +
+
+
+
{% if user['ac_list'] != None %}
AC 的题目 (点击查看)
{% endif %}
-
-
-
-
个性签名
-
-{{user['signature']}} -
-
-
-
邮箱地址
-
-{{user['email']}} -
-
性别
-
-{% if user['sex'] == 0 %} 男 -{% elif user['sex'] == 1 %} 女 -{% else %} Unknown -{% endif %} +
+
+
邮箱地址
+
+ {{-user['email']-}} +
+
性别
+
+ {%- if user['sex'] == 0 -%} 男 + {%- elif user['sex'] == 1 -%} 女 + {%- else -%} Unknown + {% endif %} +
+ {% if user['group'] != None %} +
小组
+
+ {{-user['group']-}} +
+ {% endif %} + {% if Current_User_Privilege('is_user_manager') %} + + + + {% endif %}
- {% if user['group'] != None %} -
小组
-
-{{user['group']}} + {% if User_Privilege(user['username'],'is_user_manager') or User_Privilege(user['username'],'is_problem_manager') or User_Privilege(user['username'],'is_contest_manager') or User_Privilege(user['username'],'is_tag_manager') %} +
+
权限
+
+ {% if User_Privilege(user['username'],'is_admin') %} 全站管理员
{% endif %} + {% if User_Privilege(user['username'],'is_user_manager') %} 用户管理员
{% endif %} + {% if User_Privilege(user['username'],'is_problem_manager') %} 题目管理员
{% endif %} + {% if User_Privilege(user['username'],'is_contest_manager') %} 比赛管理员
{% endif %} + {% if User_Privilege(user['username'],'is_tag_manager') %} 题目标签管理员
{% endif %} +
{% endif %} - {% if Current_User_Privilege('is_user_manager') %} - - - - {% endif %} -
- {% if User_Privilege(user['username'],'is_user_manager') or User_Privilege(user['username'],'is_problem_manager') or User_Privilege(user['username'],'is_contest_manager') or User_Privilege(user['username'],'is_tag_manager') %} -
-
权限
-
-{% if User_Privilege(user['username'],'is_admin') %} 全站管理员
{% endif %} -{% if User_Privilege(user['username'],'is_user_manager') %} 用户管理员
{% endif %} -{% if User_Privilege(user['username'],'is_problem_manager') %} 题目管理员
{% endif %} -{% if User_Privilege(user['username'],'is_contest_manager') %} 比赛管理员
{% endif %} -{% if User_Privilege(user['username'],'is_tag_manager') %} 题目标签管理员
{% endif %} -
- {% endif %}
-
-
-
- {{user['total_ac']}} 通过 -
-
- {{user['total_submit']}} 提交 +
+
+
个性签名
+
+ {{-user['signature']-}}
-
- -
- +
+
{{called}}的「吱声」
+
+ {% if len(zishengs) > 0 %} + {% for zisheng in zishengs %} +
+
+ + + @ {{zisheng['username']}} + + + {{zisheng['send_time']}} + + +
+
+ {{-zisheng['message']-}} +
+
+ {% endfor %} + {% else %} +
+ 这人太懒, 没吱过声. +
+ {% endif %}