diff --git a/.gitignore b/.gitignore index 41810c6..3019213 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,8 @@ #config config.py +config_fudan.py + # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/app.py b/app.py index 585e89e..1edd5b8 100644 --- a/app.py +++ b/app.py @@ -2,41 +2,30 @@ from flask import Flask, request, render_template, send_from_directory, abort, r from flask_sqlalchemy import SQLAlchemy from flask_limiter import Limiter from flask_limiter.util import get_remote_address -from mastodon import Mastodon import re import random from datetime import datetime from dateutil.tz import tzlocal import html2text -from config import C +from config_fudan import C app = Flask(__name__) -app.config.from_object('config.C') +app.config.from_object('config_fudan.C') app.secret_key = C.session_key -th = Mastodon( - access_token = C.token, - api_base_url = 'https://' + C.domain -) - limiter = Limiter( app, key_func=get_remote_address, default_limits=["50 / minute"], ) -h2t = html2text.HTML2Text() -h2t.ignore_links = True - db = SQLAlchemy(app) class Candidate(db.Model): id = db.Column(db.Integer, primary_key=True) content = db.Column(db.String(4000)) private = db.Column(db.String(1000)) - url = db.Column(db.String(50)) time = db.Column(db.DateTime) - toot = db.Column(db.BigInteger) likeNum = db.Column(db.Integer, default=0) # always increment 1 for the id of a new record @@ -87,7 +76,7 @@ def can_list(): } for name, ques, hint, ans in C.verify ] - return render_template('list.html', pagination=pag, vs=vs, showPrivate=(key==C.key), sort_by=sort_by, key=key) + return render_template('list.html', pagination=pag, vs=vs, showPrivate=(key==C.key), sort_by=sort_by, key=key, text1=C.text1, text2=C.text2) @app.route('/ordinary/new', methods=['POST']) @limiter.limit("5 / hour; 1 / 2 second") @@ -95,7 +84,6 @@ def new_one(): content = request.form.get('text') private = request.form.get('privateText') - url = request.form.get('url') for name, ques, hint, ans in C.verify: if request.form.get(name) != ans: @@ -114,19 +102,11 @@ def new_one(): if not content or len(content)>4000: abort(422) if private and len(private)>1000: abort(422) - if url and not re.match('https://(cloud\.tsinghua\.edu\.cn/f/[0-9a-z]+/(\?dl=1)?|closed\.social/safeShare/\d([a-zA-Z]+)?)', url): abort(422) if not Candidate.query.filter_by(content=content).first(): - toot = th.status_post( - f"有新的自荐报名(大家可以直接在此处评论):\n\n{content}", - visibility=C.visibility - ) - c = Candidate( content=content, private=private, - url=url, - toot=toot.id, time=datetime.now() ) db.session.add(c) @@ -134,48 +114,19 @@ def new_one(): return redirect(".") -@limiter.limit("100 / hour; 2 / second") -@app.route('/ordinary//comments') -def get_comments(toot): - c = Candidate.query.filter_by(toot=toot).first() - if not c: - abort(404) - - context = th.status_context(toot) - replies = [ - { - 'disp': (t.account.display_name or t.account.acct), - 'url': t.account.url, - 'content': h2t.handle(t.content).replace(C.bot_name,'').strip(), - 'time': str(t.created_at) - } - for t in context.descendants - ] - d = list(filter( - lambda r: r['content'] == '删除' and r['url'].split('/@')[1] in C.admins, - replies - )) - if d: - db.session.delete(c) - db.session.commit() - th.status_delete(toot) - return '该内容已被删除', 404 - - return {'replies': replies} - @limiter.limit("100 / hour") -@app.route('/ordinary//like', methods=['POST']) -def like(toot): - c = Candidate.query.filter_by(toot=toot).first() +@app.route('/ordinary//like', methods=['POST']) +def like(id): + c = Candidate.query.get(id) if not c: abort(404) uid = session['uid'] if not uid: abort(401) - if Like.query.filter_by(uid=uid, cid=c.id).first(): + if Like.query.filter_by(uid=uid, cid=id).first(): return '点赞过了', 403 - l = Like(uid=uid, cid=c.id) + l = Like(uid=uid, cid=id) c.likeNum += 1 db.session.add(l) db.session.commit() diff --git a/static/img/ord_fudan/bg.jpg b/static/img/ord_fudan/bg.jpg new file mode 100644 index 0000000..ce05aba Binary files /dev/null and b/static/img/ord_fudan/bg.jpg differ diff --git a/static/img/ord_fudan/bg_sm.jpg b/static/img/ord_fudan/bg_sm.jpg new file mode 100644 index 0000000..31ee86a Binary files /dev/null and b/static/img/ord_fudan/bg_sm.jpg differ diff --git a/static/img/ord_fudan/logo.png b/static/img/ord_fudan/logo.png new file mode 100644 index 0000000..6b16972 Binary files /dev/null and b/static/img/ord_fudan/logo.png differ diff --git a/static/img/ord_fudan/logo_sm.png b/static/img/ord_fudan/logo_sm.png new file mode 100644 index 0000000..4cc2ed0 Binary files /dev/null and b/static/img/ord_fudan/logo_sm.png differ diff --git a/static/img/ord_fudan/poster.jpg b/static/img/ord_fudan/poster.jpg new file mode 100644 index 0000000..a334013 Binary files /dev/null and b/static/img/ord_fudan/poster.jpg differ diff --git a/static/img/ord_fudan/poster_sm.jpg b/static/img/ord_fudan/poster_sm.jpg new file mode 100644 index 0000000..cb44a90 Binary files /dev/null and b/static/img/ord_fudan/poster_sm.jpg differ diff --git a/templates/list.html b/templates/list.html index 049d750..e08a920 100644 --- a/templates/list.html +++ b/templates/list.html @@ -7,10 +7,10 @@ - - + + - 华清大学特普通奖 报名页面 + 复旦大学特普通奖 报名页面 - +
- +
@@ -199,25 +194,14 @@

自荐提名

- -
- -
-
- -
- -
-
+
+
{% for v in vs %}
- -
+ +
@@ -226,62 +210,12 @@
-
-
    -
  • 如需附上补充材料,请使用清华云盘。为了避免泄露姓名推荐使用safeShare。其他云盘是不被接受的。
  • -
  • 需要回答几个简单的问题以初步验证学生身份,入围后的线上答辩环节将于闭社平台进行(需清华邮箱注册)以正式验证身份。
  • -
  • 如果出错(例如验证问题答错了),请回退,多数浏览器都会恢复之前填写的内容。
  • -
  • 获得五个赞并留下联系方式(如微信号、手机号或邮箱)者被视为正式提名,会有工作人员与之联系并发放奖品。
  • -
  • 点击倒三角按钮展开评论,发布评论请前往闭社
  • -
  • 如需删除报名,请联系工作人员(微信:ordinary_thuer)。
  • -
-
-
-
-
-
-

成为评委

-
-

为了更好地选出十位普通人的代表,为了更好地展现大众的声音,我们希望招募更多的评委。

-

成为评委的条件:

-
    -
  • 是华清大学在读学生
  • -
  • 没有报名参选
  • -
  • 愿意对所有报名者进行评分
  • -
-

我们原则上不拒绝任何的评委报名。

-

目前在三个平台上建了三个评委群,分别是闭聊(Matrix),Telegram,微信。前两个消息自动同步,加入哪个都是等价的,微信群与另外两个群不连通。(注意Telegram墙内不可直接访问。闭聊由闭社提供,使用闭社帐号登陆,如使用其他服务器上的Matrix帐号加群需要验证华清身份。)

-

选择想加入的群,完成验证,进入评委群。如果不愿意加群,也可以私信主办方保持沟通和上传打分结果。

-
- -
-
- - -
-
- - -
-
- - -
-
-
- {% for v in vs %} -
- -
- -
-
- {% endfor %} -

(火热开发中... 马上就可以点了)

-
-
+ @@ -327,7 +261,7 @@ {% endif %} -
-
- 加载中... -
{% endfor %} @@ -378,7 +302,7 @@
@@ -410,45 +334,22 @@ } $(document).ready(function(){ + if(window.innerWidth > 1000) + showNew(); $('.timeago').timeago(); $('.twin').click((e) => { + showNew(); if($(e.currentTarget).hasClass('front')) return; let behind_box = $('.behind'); let front_box = $('.front'); behind_box.toggleClass('behind front'); front_box.toggleClass('front behind'); - }); - - $('.collapse').on('show.bs.collapse', (e) => { - let self = e.target; - let toot = self.id.split('-')[1]; - $.ajax({ - type: 'GET', - url: toot + '/comments', - success: (result, status, xhr) => { - if (result.replies.length) { - $(self).empty(); - result.replies.forEach((rp) => { - $(self).append(`

${rp.disp}:

${rp.content}
`) - }); - $(self).find('.timeago').timeago(); - } else { - $(self).empty(); - $(self).append(`
(暂无评论)
`) - } - }, - error: (xhr, status, error) => { - console.log(error, status, xhr.status, xhr.responseText); - $(self).empty(); - $(self).append(`

${xhr.status} ${xhr.responseText}

`); - if (xhr.status == 404) - setTimeout(() => { - $(self).parent().remove() - }, 3000); - } - }); + setTimeout(() => { + $('.poster.front a').attr('href', '/img/ord_fudan/poster.jpg'); + $('.poster.behind a').removeAttr('href'); + }, 300); }); });