Giter Site home page Giter Site logo

bitnp / contest-bitnp Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 4.0 3.49 MB

国防知识竞赛

Home Page: https://contest.bitnp.net

Python 73.12% HTML 16.37% Just 1.50% JavaScript 7.42% CSS 0.20% Dockerfile 1.25% Shell 0.15%
beijing-institute-of-technology django quiz

contest-bitnp's People

Contributors

dependabot[bot] avatar everything411 avatar initialmoon avatar phoupraw avatar pre-commit-ci[bot] avatar xdt6 avatar ydx-2147483647 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

contest-bitnp's Issues

答题前应提示

  • 不答题时,导航栏不要显示答题。
  • 发卷前请同学确认:答题次数有限,计时无法暂停。

适配 WebVPN

https://everything411.top/https://webvpn.bit.edu.cn/https/77726476706e69737468656265737421f5e1448e3e246059700fddfdc91b373ac0/

已知的问题

大约不支持 ESM

Uncaught SyntaxError: import declarations may only appear at top level of a module
vpn_eval((function(){
import{d as e}from"./_rollupPluginBabelHelpers-b026cde4.js";
}
).toString().slice(12, -2),"");

URL 中./

<script id="data:update-url" type="application/json">"/contest/update/"</script>

原理

vpn_eval大致如下。

function vpn_eval(t: string) {
        try {
          return eval['call'](vpnGlobal, Ae(t))
        } catch (t) {
          
        }
}

Ae基本是恒等映射。

相关链接

资源访问控制系统(WebVPN) 公司产品-北京网瑞达科技有限公司

https://github.com/bugfan/mytools/blob/66530adedb30917207a15bf7338d19bcfad1e6c8/vpn/%E8%B0%83%E8%AF%95webvpn.md

feat: 自动收卷

自动把DraftResponse转换为Response

现在只有收到quiz:contest_submit时才会转换。

可能的方案

定时清理

这些是类似 crontab 的方案。它们原本场景中,数据天生需要定时更新,例如天气。

同学操作时再清理

如果同学放着不管了,暂时不清理也无妨,一切结束后整理即可。

响应quiz:index时清理。

答题次数提示

界面需要加个已经进行了多少次考试,还有多少次机会的提示

重放`quiz:contest_submit`不报错而无限重定向

在 URL 和登录之间循环重定向。

https://github.com/Phoupraw/contest-bitnp/blob/df39fbf135ea70f4e39c9ae620ba726afb61fddf/contest/quiz/views.py#L194-L199

@login_required
# 不符合则转登录
@student_only
# 不符合则转 not_student.html(“只有学生能访问这里……”)
@user_passes_test(is_student_taking_contest)
# user_passes_test 似乎本来是限制用户类型,所以会转登录……
@require_POST
def contest_submit(request: AuthenticatedHttpRequest) -> HttpResponse:
    ...

user_passes_test的文档以及实现

quiz:contest_submit同理。

可能的解决方案

自己做个user_passes_test

Roadmap

  • 改进各种模板,如base.html
  • 题库
  • 随时保存进度

  • 网络安全
  • 自动暂存 local storage Django WebSocket JavaScript

答题逻辑添加缓存

用户答题答案不应每次都更新入数据库,而应该增加一层缓存,选取合适节点统一提交数据库,从而提升性能,防止被高峰挤爆。

考虑使用进程内缓存或者redis。

改进样式

  • 题目

    电脑设备中间可以加个背景框,题和题间加个分割线,另外加个题号。

  • 进度条

    • 不知道最大进度
    • 响应式设计到中等size的时候感觉有点太长了,居中一个固定大小就行感觉
    • 超宽屏标题卡片有限长,但进度条对齐到最右,布局有点失调?可能和上面卡片平齐会好一点

检查文本

问问老师。

  • 是“国防知识竞赛”还是“国防科技知识竞赛”?

Relates-to: #69

BIT 正式 CAS 服务器没有姓名

可能的解决方案

适配 CAS

PHP 旧项目:

$school = phpCAS::getAttribute('eduPersonOrgDN');
$cname = phpCAS::getAttribute('cn');
$stuNum = phpCAS::getAttribute('uid');

$SQL = "INSERT INTO users(casid, name, stuNum, school, status, problems, keyans) VALUES('$CASid', '$cname', '$stuNum
', '$school', 2, '$problems', '$keyans')";

设置CAS_RENAME_ATTRIBUTES

绕开 CAS

本地保存姓名、学号映射表,初次登录时查表。

https://github.com/Phoupraw/contest-bitnp/blob/f64781e1136901bdcf79dae0c02ec535297a3e9b/contest/quiz/auth_backends.py#L17-L29

相关

#69

超时后提交按钮失效

在答题页,提示超时后关闭弹窗,单击表单里的“提交”,会 403 Forbidden。正常应该能提交。

不过无法复现。

Poetry in CI

https://github.com/radoering/poetry/blob/692f410942dd6def4ad91080c80ca792e09b53bb/docs/_index.md?plain=1#L292-L305

Version pinning

Whatever method you use, it is highly recommended to explicitly control the version of Poetry used, so that you are able
to upgrade after performing your own validation. Each install method has a different syntax for setting the version that
is used in the following examples.

Using pipx

Just as pipx is a powerful tool for development use, it is equally useful in a CI environment
and should be one of your top choices for use of Poetry in CI.

pipx install poetry==1.2.0

相关

#34 介绍了缓存方法。

按照通知修改

  • 删除国防教育协会

    大家都不清楚这个社团现在在哪儿。

  • 9月1日0:00–2日24:00

  • 20题,每题5分,300秒,2次

No module named 'django_browser_reload' in deployment

按照doc/deploy.md操作,migrate 会失败。

  File "…\contest-bitnp\contest\contest\urls.py", line 28, in <module>
    path("__reload__/", include("django_browser_reload.urls")),
  File "…\contest-bitnp\.venv\lib\site-packages\django\urls\conf.py", line 38, in include
    urlconf_module = import_module(urlconf_module)
  File "…\Python310\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'django_browser_reload'

不知 CI 能过。这大约因为缓存了 dev 的包,注意poetry install时提示 No dependencies to install or update。

人类可读的题库

方便人工检查题目。

from __future__ import annotations

from pathlib import Path
from typing import TYPE_CHECKING

from quiz.models import Question

if TYPE_CHECKING:
    from typing import Generator

PREFIX = {
    True: "【应选】",
    False: "",
}


def lines() -> Generator[str, None, None]:
    for q in Question.objects.all():
        yield f"# {q.content}\n\n"
        yield "\n\n".join(PREFIX[c.correct] + c.content for c in q.choice_set.all())
        yield "\n\n"


if __name__ == "__main__":
    Path("problems.txt").write_text("".join(lines()), encoding="utf-8")

可复制到just shell运行。另外 django-extensions · PyPI 似乎能runscript

KeyError at /admin/ 'constants'

用没权限的账号访问/admin/,后端报错django.core.exceptions.PermissionDenied: You do not have staff privileges.,此时前端会用base.html,而缺乏constants

https://github.com/Phoupraw/contest-bitnp/blob/108b7420af41f20b2726f64568c4855fadb83c2d/contest/quiz/templates/base.html#L14

https://github.com/Phoupraw/contest-bitnp/blob/108b7420af41f20b2726f64568c4855fadb83c2d/contest/quiz/templatetags/current_page.py#L32

也许 python 部分不强制要求有constants即可。(Django 模板部分似乎会整体解析 variablesa不存在时a.b能转换为string_if_invalid。)

constants: ConstantsNamespace | None = context.get("constants")

导出答题数据

要求

  • 各连总分数、人数、答题人数、平均分(含没答题的)。
  • 全员成绩单。

示例

$ poetry run python -m pip install polars
$ just shell
In [1]: from quiz.models import Student

In [2]: import polars as pl

In [3]: pl.DataFrame({ "score": s.final_score(), "name": s.name, "id": s.user.id } for s in Student.objects.all())
Out[3]:
shape: (14, 3)
┌───────────┬──────────┬─────┐
│ score     ┆ name     ┆ id  │
│ ---       ┆ ---      ┆ --- │
│ f64       ┆ str      ┆ i64 │
╞═══════════╪══════════╪═════╡
│ 100.0     ┆ 侯□□     ┆ 2   │
│ 0.0       ┆ A Worker ┆ 3   │
│ 66.666667 ┆ a        ┆ 10  │
│ 0.0       ┆ b        ┆ 11  │
│ …         ┆ …        ┆ …   │
│ 10.0      ┆ new      ┆ 19  │
│ 10.0      ┆ .        ┆ 20  │
│ 0.0       ┆ -        ┆ 21  │
│ 20.0      ┆ ,        ┆ 22  │
└───────────┴──────────┴─────┘

相关

production deployment and website launching checklist

  • BIT CAS用户登录验证
    • 有无姓名?
  • 往年题目导入测试
  • 新网站行为与原网站行为一致性
  • 答题流程无明显的阻碍正常用户答题的恶性BUG
  • 网站用户交互流畅,不易引发误解,常规报错能给出原因
  • 网协容器基础设施对接,生产环境部署
  • 生产环境安全性(secret_key)
  • 正式题目导入
  • 网站正式运行
  • 导出功能正常执行
  • 答题结束

回顾历史

有时间可以做一个简单的回顾功能,把历史答题记录稍微显示一下。

要显示具体对错,还是仅仅展示答题记录?后者。

对表

覆盖暂存记录应以客户端发送时间为准,现在是以来服务端收到时间为准。

Relates-to: #104

ci: Pre-commit on GitHub

安装后可以在 GitHub 上运行 pre-commit。这样就不会有 #52 那样的格式问题了。

安装方法:仓库所有者到 https://pre-commit.ci 按提示登录、管理即可。

价格

pre-commit.ci will always be free for open source repositories.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.