-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
添加功能: 吱声
- Loading branch information
Showing
9 changed files
with
216 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,50 @@ | ||
#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 | ||
if not config.config['site']['zisheng']['enable']: | ||
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('/') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters