Compare commits
1 commit
master
...
courseLuzi
Author | SHA1 | Date | |
---|---|---|---|
|
1797b9fe06 |
2505 changed files with 18473 additions and 41606 deletions
|
@ -11,7 +11,3 @@ repos:
|
||||||
rev: 22.12.0
|
rev: 22.12.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: black
|
- id: black
|
||||||
- repo: https://github.com/hadialqattan/pycln
|
|
||||||
rev: 'v2.3.0'
|
|
||||||
hooks:
|
|
||||||
- id: pycln
|
|
||||||
|
|
2
502.html
2
502.html
|
@ -49,7 +49,7 @@
|
||||||
<br>
|
<br>
|
||||||
<div class="popup">
|
<div class="popup">
|
||||||
<div>
|
<div>
|
||||||
<img class="logo" src="logo.svg" alt="LQDOJ">
|
<img class="logo" src="logo.png" alt="LQDOJ">
|
||||||
</div>
|
</div>
|
||||||
<h1 style="width: 100%;">Oops, LQDOJ is down now.</h1>
|
<h1 style="width: 100%;">Oops, LQDOJ is down now.</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
191
README.md
191
README.md
|
@ -31,197 +31,6 @@ Support plagiarism detection via [Stanford MOSS](https://theory.stanford.edu/~ai
|
||||||
Most of the setup are the same as DMOJ installations. You can view the installation guide of DMOJ here: https://docs.dmoj.ca/#/site/installation.
|
Most of the setup are the same as DMOJ installations. You can view the installation guide of DMOJ here: https://docs.dmoj.ca/#/site/installation.
|
||||||
There is one minor change: Instead of `git clone https://github.com/DMOJ/site.git`, you clone this repo `git clone https://github.com/LQDJudge/online-judge.git`.
|
There is one minor change: Instead of `git clone https://github.com/DMOJ/site.git`, you clone this repo `git clone https://github.com/LQDJudge/online-judge.git`.
|
||||||
|
|
||||||
|
|
||||||
- Bước 1: cài các thư viện cần thiết
|
|
||||||
- $ ở đây nghĩa là sudo. Ví dụ dòng đầu nghĩa là chạy lệnh `sudo apt update`
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
$ apt update
|
|
||||||
$ apt install git gcc g++ make python3-dev python3-pip libxml2-dev libxslt1-dev zlib1g-dev gettext curl redis-server
|
|
||||||
$ curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -
|
|
||||||
$ apt install nodejs
|
|
||||||
$ npm install -g sass postcss-cli postcss autoprefixer
|
|
||||||
```
|
|
||||||
|
|
||||||
- Bước 2: tạo DB
|
|
||||||
- Server đang dùng MariaDB ≥ 10.5, các bạn cũng có thể dùng Mysql nếu bị conflict
|
|
||||||
- Nếu các bạn chạy lệnh dưới này xong mà version mariadb bị cũ (< 10.5) thì có thể tra google cách cài MariaDB mới nhất (10.5 hoặc 10.6).
|
|
||||||
- Các bạn có thể thấy version MariaDB bằng cách gõ lệnh `sudo mysql` (Ctrl + C để quit)
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
$ apt update
|
|
||||||
$ apt install mariadb-server libmysqlclient-dev
|
|
||||||
```
|
|
||||||
|
|
||||||
- Bước 3: tạo table trong DB
|
|
||||||
- Các bạn có thể thay tên table và password
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
$ sudo mysql
|
|
||||||
mariadb> CREATE DATABASE dmoj DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_general_ci;
|
|
||||||
mariadb> GRANT ALL PRIVILEGES ON dmoj.* TO 'dmoj'@'localhost' IDENTIFIED BY '<password>';
|
|
||||||
mariadb> exit
|
|
||||||
```
|
|
||||||
|
|
||||||
- Bước 4: Cài đặt môi trường ảo (virtual env) và pull code
|
|
||||||
- Nếu `pip3 install mysqlclient` bị lỗi thì thử chạy `pip3 install mysqlclient==2.1.1`
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
$ python3 -m venv dmojsite
|
|
||||||
$ . dmojsite/bin/activate
|
|
||||||
|
|
||||||
(dmojsite) $ git clone https://github.com/LQDJudge/online-judge.git
|
|
||||||
(dmojsite) $ cd online-judge
|
|
||||||
(dmojsite) $ git submodule init
|
|
||||||
(dmojsite) $ git submodule update
|
|
||||||
(dmojsite) $ pip3 install -r requirements.txt
|
|
||||||
(dmojsite) $ pip3 install mysqlclient
|
|
||||||
(dmojsite) $ pre-commit install
|
|
||||||
```
|
|
||||||
|
|
||||||
- Bước 5: tạo local_settings.py. Đây là file để custom setting cho Django. Các bạn tạo file vào `online-judge/dmoj/local_settings.py`
|
|
||||||
- File mẫu: https://github.com/DMOJ/docs/blob/master/sample_files/local_settings.py
|
|
||||||
- Nếu bạn đổi tên hoặc mật khẩu table databases thì thay đổi thông tin tương ứng trong `Databases`
|
|
||||||
- Sau khi xong, chạy lệnh `(dmojsite) $ python3 manage.py check` để kiểm tra
|
|
||||||
- Bước 6: Compile CSS và translation
|
|
||||||
- Giải thích:
|
|
||||||
- Lệnh 1 và 2 gọi sau mỗi lần thay đổi 1 file css hoặc file js (file html thì không cần)
|
|
||||||
- Lệnh 3 và 4 gọi sau mỗi lần thay đổi file dịch
|
|
||||||
- Note: Sau khi chạy lệnh này, folder tương ứng với STATIC_ROOT trong local_settings phải được tạo. Nếu chưa được tạo thì mình cần tạo folder đó trước khi chạy 2 lệnh đầu.
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
(dmojsite) $ ./make_style.sh
|
|
||||||
(dmojsite) $ python3 manage.py collectstatic
|
|
||||||
(dmojsite) $ python3 manage.py compilemessages
|
|
||||||
(dmojsite) $ python3 manage.py compilejsi18n
|
|
||||||
```
|
|
||||||
|
|
||||||
- Bước 7: Thêm dữ liệu vào DB
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
(dmojsite) $ python3 manage.py migrate
|
|
||||||
(dmojsite) $ python3 manage.py loaddata navbar
|
|
||||||
(dmojsite) $ python3 manage.py loaddata language_small
|
|
||||||
(dmojsite) $ python3 manage.py loaddata demo
|
|
||||||
```
|
|
||||||
|
|
||||||
- Bước 8: Chạy site. Đến đây thì cơ bản đã hoàn thành (chưa có judge, websocket, celery). Các bạn có thể truy cập tại `localhost:8000`
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
python3 manage.py runserver 0.0.0.0:8000
|
|
||||||
```
|
|
||||||
|
|
||||||
**Một số lưu ý:**
|
|
||||||
|
|
||||||
1. (WSL) có thể tải ứng dụng Terminal trong Windows Store
|
|
||||||
2. (WSL) mỗi lần mở ubuntu, các bạn cần chạy lệnh sau để mariadb khởi động: `sudo service mysql restart` (tương tự cho một số service khác như memcached, celery)
|
|
||||||
3. Sau khi cài đặt, các bạn chỉ cần activate virtual env và chạy lệnh runserver là ok
|
|
||||||
```jsx
|
|
||||||
. dmojsite/bin/activate
|
|
||||||
python3 manage.py runserver
|
|
||||||
```
|
|
||||||
5. Đối với nginx, sau khi config xong theo guide của DMOJ, bạn cần thêm location như sau để sử dụng được tính năng profile image, thay thế `path/to/oj` thành đường dẫn nơi bạn đã clone source code.
|
|
||||||
|
|
||||||
```
|
|
||||||
location /profile_images/ {
|
|
||||||
root /path/to/oj;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
6. Quy trình dev:
|
|
||||||
1. Sau khi thay đổi code thì django tự build lại, các bạn chỉ cần F5
|
|
||||||
2. Một số style nằm trong các file .scss. Các bạn cần recompile css thì mới thấy được thay đổi.
|
|
||||||
|
|
||||||
**Optional:**
|
|
||||||
|
|
||||||
************Alias:************ Các bạn có thể lưu các alias này để sau này dùng cho nhanh
|
|
||||||
|
|
||||||
- mtrans: để generate translation khi các bạn add một string trong code
|
|
||||||
- trans: compile translation (sau khi bạn đã dịch tiếng Việt)
|
|
||||||
- cr: chuyển tới folder OJ
|
|
||||||
- pr: chạy server
|
|
||||||
- sm: restart service (chủ yếu dùng cho WSL)
|
|
||||||
- sd: activate virtual env
|
|
||||||
- css: compile các file css
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
alias mtrans='python3 manage.py makemessages -l vi && python3 manage.py makedmojmessages -l vi'
|
|
||||||
alias pr='python3 manage.py runserver'
|
|
||||||
alias sd='source ~/LQDOJ/dmojsite/bin/activate'
|
|
||||||
alias sm='sudo service mysql restart && sudo service redis-server start && sudo service memcached start'
|
|
||||||
alias trans='python3 manage.py compilemessages -l vi && python3 manage.py compilejsi18n -l vi'
|
|
||||||
alias cr='cd ~/LQDOJ/online-judge'
|
|
||||||
alias css='./make_style.sh && python3 manage.py collectstatic --noinput'
|
|
||||||
```
|
|
||||||
|
|
||||||
**Memcached:** dùng cho in-memory cache
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
$ sudo apt install memcached
|
|
||||||
```
|
|
||||||
|
|
||||||
**Websocket:** dùng để live update (như chat)
|
|
||||||
|
|
||||||
- Tạo file online-judge/websocket/config.js
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
module.exports = {
|
|
||||||
get_host: '127.0.0.1',
|
|
||||||
get_port: 15100,
|
|
||||||
post_host: '127.0.0.1',
|
|
||||||
post_port: 15101,
|
|
||||||
http_host: '127.0.0.1',
|
|
||||||
http_port: 15102,
|
|
||||||
long_poll_timeout: 29000,
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
- Cài các thư viện
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
(dmojsite) $ npm install qu ws simplesets
|
|
||||||
(dmojsite) $ pip3 install websocket-client
|
|
||||||
```
|
|
||||||
|
|
||||||
- Khởi động (trong 1 tab riêng)
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
(dmojsite) $ node websocket/daemon.js
|
|
||||||
```
|
|
||||||
|
|
||||||
**************Celery:************** (dùng cho một số task như batch rejudge_
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
celery -A dmoj_celery worker
|
|
||||||
```
|
|
||||||
|
|
||||||
**************Judge:**************
|
|
||||||
|
|
||||||
- Cài đặt ở 1 folder riêng bên ngoài site:
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
$ apt install python3-dev python3-pip build-essential libseccomp-dev
|
|
||||||
$ git clone https://github.com/LQDJudge/judge-server.git
|
|
||||||
$ cd judge-server
|
|
||||||
$ sudo pip3 install -e .
|
|
||||||
```
|
|
||||||
|
|
||||||
- Tạo một file judge.yml ở bên ngoài folder judge-server (file mẫu https://github.com/DMOJ/docs/blob/master/sample_files/judge_conf.yml)
|
|
||||||
- Thêm judge vào site bằng UI: Admin → Judge → Thêm Judge → nhập id và key (chỉ cần thêm 1 lần) hoặc dùng lệnh `(dmojsite) $ python3 managed.py addjudge <id> <key>`.
|
|
||||||
- Chạy Bridge (cầu nối giữa judge và site) trong 1 tab riêng trong folder online-judge:
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
(dmojsite) $ python3 managed.py runbridged
|
|
||||||
```
|
|
||||||
|
|
||||||
- Khởi động Judge (trong 1 tab riêng):
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
$ dmoj -c judge.yml localhost
|
|
||||||
```
|
|
||||||
|
|
||||||
- Lưu ý: mỗi lần sau này muốn chạy judge thì mở 1 tab cho bridge và n tab cho judge. Mỗi judge cần 1 file yml khác nhau (chứa authentication khác nhau)
|
|
||||||
|
|
||||||
### Some frequent difficulties when installation:
|
### Some frequent difficulties when installation:
|
||||||
|
|
||||||
1. Missing the `local_settings.py`. You need to copy the `local_settings.py` in order to pass the check.
|
1. Missing the `local_settings.py`. You need to copy the `local_settings.py` in order to pass the check.
|
||||||
|
|
|
@ -3,6 +3,3 @@ from django.apps import AppConfig
|
||||||
|
|
||||||
class ChatBoxConfig(AppConfig):
|
class ChatBoxConfig(AppConfig):
|
||||||
name = "chat_box"
|
name = "chat_box"
|
||||||
|
|
||||||
def ready(self):
|
|
||||||
from . import models
|
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2023-02-18 21:10
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("chat_box", "0010_auto_20221028_0300"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name="message",
|
|
||||||
name="hidden",
|
|
||||||
field=models.BooleanField(
|
|
||||||
db_index=True, default=False, verbose_name="is hidden"
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,34 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2023-03-08 07:17
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0154_add_submission_indexes"),
|
|
||||||
("chat_box", "0011_alter_message_hidden"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterModelOptions(
|
|
||||||
name="message",
|
|
||||||
options={
|
|
||||||
"ordering": ("-id",),
|
|
||||||
"verbose_name": "message",
|
|
||||||
"verbose_name_plural": "messages",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name="message",
|
|
||||||
name="hidden",
|
|
||||||
field=models.BooleanField(default=False, verbose_name="is hidden"),
|
|
||||||
),
|
|
||||||
migrations.AddIndex(
|
|
||||||
model_name="message",
|
|
||||||
index=models.Index(
|
|
||||||
fields=["hidden", "room", "-id"], name="chat_box_me_hidden_b2307a_idx"
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,20 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2023-08-28 01:24
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("chat_box", "0012_auto_20230308_1417"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name="message",
|
|
||||||
name="time",
|
|
||||||
field=models.DateTimeField(
|
|
||||||
auto_now_add=True, db_index=True, verbose_name="posted time"
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,38 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2023-08-28 06:02
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
def migrate(apps, schema_editor):
|
|
||||||
UserRoom = apps.get_model("chat_box", "UserRoom")
|
|
||||||
Message = apps.get_model("chat_box", "Message")
|
|
||||||
|
|
||||||
for ur in UserRoom.objects.all():
|
|
||||||
if not ur.room:
|
|
||||||
continue
|
|
||||||
messages = ur.room.message_set
|
|
||||||
last_msg = messages.first()
|
|
||||||
try:
|
|
||||||
if last_msg and last_msg.author != ur.user:
|
|
||||||
ur.unread_count = messages.filter(time__gte=ur.last_seen).count()
|
|
||||||
else:
|
|
||||||
ur.unread_count = 0
|
|
||||||
ur.save()
|
|
||||||
except:
|
|
||||||
continue
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("chat_box", "0013_alter_message_time"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="userroom",
|
|
||||||
name="unread_count",
|
|
||||||
field=models.IntegerField(db_index=True, default=0),
|
|
||||||
),
|
|
||||||
migrations.RunPython(migrate, migrations.RunPython.noop, atomic=True),
|
|
||||||
]
|
|
|
@ -1,33 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2023-11-02 01:41
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
def migrate(apps, schema_editor):
|
|
||||||
Room = apps.get_model("chat_box", "Room")
|
|
||||||
Message = apps.get_model("chat_box", "Message")
|
|
||||||
|
|
||||||
for room in Room.objects.all():
|
|
||||||
messages = room.message_set
|
|
||||||
last_msg = messages.first()
|
|
||||||
if last_msg:
|
|
||||||
room.last_msg_time = last_msg.time
|
|
||||||
room.save()
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("chat_box", "0014_userroom_unread_count"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="room",
|
|
||||||
name="last_msg_time",
|
|
||||||
field=models.DateTimeField(
|
|
||||||
db_index=True, null=True, verbose_name="last seen"
|
|
||||||
),
|
|
||||||
),
|
|
||||||
migrations.RunPython(migrate, migrations.RunPython.noop, atomic=True),
|
|
||||||
]
|
|
|
@ -1,32 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2024-08-22 03:12
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
def remove_duplicates(apps, schema_editor):
|
|
||||||
Room = apps.get_model("chat_box", "Room")
|
|
||||||
seen = set()
|
|
||||||
|
|
||||||
for room in Room.objects.all():
|
|
||||||
pair = (room.user_one_id, room.user_two_id)
|
|
||||||
reverse_pair = (room.user_two_id, room.user_one_id)
|
|
||||||
|
|
||||||
if pair in seen or reverse_pair in seen:
|
|
||||||
room.delete()
|
|
||||||
else:
|
|
||||||
seen.add(pair)
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("chat_box", "0015_room_last_msg_time"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.RunPython(remove_duplicates),
|
|
||||||
migrations.AlterUniqueTogether(
|
|
||||||
name="room",
|
|
||||||
unique_together={("user_one", "user_two")},
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,11 +1,9 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import CASCADE, Q
|
from django.db.models import CASCADE
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.utils.functional import cached_property
|
|
||||||
|
|
||||||
|
|
||||||
from judge.models.profile import Profile
|
from judge.models.profile import Profile
|
||||||
from judge.caching import cache_wrapper
|
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["Message", "Room", "UserRoom", "Ignore"]
|
__all__ = ["Message", "Room", "UserRoom", "Ignore"]
|
||||||
|
@ -18,44 +16,20 @@ class Room(models.Model):
|
||||||
user_two = models.ForeignKey(
|
user_two = models.ForeignKey(
|
||||||
Profile, related_name="user_two", verbose_name="user 2", on_delete=CASCADE
|
Profile, related_name="user_two", verbose_name="user 2", on_delete=CASCADE
|
||||||
)
|
)
|
||||||
last_msg_time = models.DateTimeField(
|
|
||||||
verbose_name=_("last seen"), null=True, db_index=True
|
|
||||||
)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
app_label = "chat_box"
|
|
||||||
unique_together = ("user_one", "user_two")
|
|
||||||
|
|
||||||
@cached_property
|
|
||||||
def _cached_info(self):
|
|
||||||
return get_room_info(self.id)
|
|
||||||
|
|
||||||
def contain(self, profile):
|
def contain(self, profile):
|
||||||
return profile.id in [self.user_one_id, self.user_two_id]
|
return self.user_one == profile or self.user_two == profile
|
||||||
|
|
||||||
def other_user(self, profile):
|
def other_user(self, profile):
|
||||||
return self.user_one if profile == self.user_two else self.user_two
|
return self.user_one if profile == self.user_two else self.user_two
|
||||||
|
|
||||||
def other_user_id(self, profile):
|
|
||||||
user_ids = [self.user_one_id, self.user_two_id]
|
|
||||||
return sum(user_ids) - profile.id
|
|
||||||
|
|
||||||
def users(self):
|
def users(self):
|
||||||
return [self.user_one, self.user_two]
|
return [self.user_one, self.user_two]
|
||||||
|
|
||||||
def last_message_body(self):
|
|
||||||
return self._cached_info["last_message"]
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def prefetch_room_cache(self, room_ids):
|
|
||||||
get_room_info.prefetch_multi([(i,) for i in room_ids])
|
|
||||||
|
|
||||||
|
|
||||||
class Message(models.Model):
|
class Message(models.Model):
|
||||||
author = models.ForeignKey(Profile, verbose_name=_("user"), on_delete=CASCADE)
|
author = models.ForeignKey(Profile, verbose_name=_("user"), on_delete=CASCADE)
|
||||||
time = models.DateTimeField(
|
time = models.DateTimeField(verbose_name=_("posted time"), auto_now_add=True)
|
||||||
verbose_name=_("posted time"), auto_now_add=True, db_index=True
|
|
||||||
)
|
|
||||||
body = models.TextField(verbose_name=_("body of comment"), max_length=8192)
|
body = models.TextField(verbose_name=_("body of comment"), max_length=8192)
|
||||||
hidden = models.BooleanField(verbose_name="is hidden", default=False)
|
hidden = models.BooleanField(verbose_name="is hidden", default=False)
|
||||||
room = models.ForeignKey(
|
room = models.ForeignKey(
|
||||||
|
@ -63,17 +37,14 @@ class Message(models.Model):
|
||||||
)
|
)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
|
new_message = self.id
|
||||||
self.body = self.body.strip()
|
self.body = self.body.strip()
|
||||||
super(Message, self).save(*args, **kwargs)
|
super(Message, self).save(*args, **kwargs)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = "message"
|
verbose_name = "message"
|
||||||
verbose_name_plural = "messages"
|
verbose_name_plural = "messages"
|
||||||
ordering = ("-id",)
|
ordering = ("-time",)
|
||||||
indexes = [
|
|
||||||
models.Index(fields=["hidden", "room", "-id"]),
|
|
||||||
]
|
|
||||||
app_label = "chat_box"
|
|
||||||
|
|
||||||
|
|
||||||
class UserRoom(models.Model):
|
class UserRoom(models.Model):
|
||||||
|
@ -82,11 +53,9 @@ class UserRoom(models.Model):
|
||||||
Room, verbose_name="room id", on_delete=CASCADE, default=None, null=True
|
Room, verbose_name="room id", on_delete=CASCADE, default=None, null=True
|
||||||
)
|
)
|
||||||
last_seen = models.DateTimeField(verbose_name=_("last seen"), auto_now_add=True)
|
last_seen = models.DateTimeField(verbose_name=_("last seen"), auto_now_add=True)
|
||||||
unread_count = models.IntegerField(default=0, db_index=True)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
unique_together = ("user", "room")
|
unique_together = ("user", "room")
|
||||||
app_label = "chat_box"
|
|
||||||
|
|
||||||
|
|
||||||
class Ignore(models.Model):
|
class Ignore(models.Model):
|
||||||
|
@ -99,15 +68,14 @@ class Ignore(models.Model):
|
||||||
)
|
)
|
||||||
ignored_users = models.ManyToManyField(Profile)
|
ignored_users = models.ManyToManyField(Profile)
|
||||||
|
|
||||||
class Meta:
|
|
||||||
app_label = "chat_box"
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def is_ignored(self, current_user, new_friend):
|
def is_ignored(self, current_user, new_friend):
|
||||||
try:
|
try:
|
||||||
return current_user.ignored_chat_users.ignored_users.filter(
|
return (
|
||||||
id=new_friend.id
|
current_user.ignored_chat_users.get()
|
||||||
).exists()
|
.ignored_users.filter(id=new_friend.id)
|
||||||
|
.exists()
|
||||||
|
)
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -118,16 +86,6 @@ class Ignore(models.Model):
|
||||||
except:
|
except:
|
||||||
return Profile.objects.none()
|
return Profile.objects.none()
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get_ignored_rooms(self, user):
|
|
||||||
try:
|
|
||||||
ignored_users = self.objects.get(user=user).ignored_users.all()
|
|
||||||
return Room.objects.filter(Q(user_one=user) | Q(user_two=user)).filter(
|
|
||||||
Q(user_one__in=ignored_users) | Q(user_two__in=ignored_users)
|
|
||||||
)
|
|
||||||
except:
|
|
||||||
return Room.objects.none()
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def add_ignore(self, current_user, friend):
|
def add_ignore(self, current_user, friend):
|
||||||
ignore, created = self.objects.get_or_create(user=current_user)
|
ignore, created = self.objects.get_or_create(user=current_user)
|
||||||
|
@ -144,11 +102,3 @@ class Ignore(models.Model):
|
||||||
self.remove_ignore(current_user, friend)
|
self.remove_ignore(current_user, friend)
|
||||||
else:
|
else:
|
||||||
self.add_ignore(current_user, friend)
|
self.add_ignore(current_user, friend)
|
||||||
|
|
||||||
|
|
||||||
@cache_wrapper(prefix="Rinfo")
|
|
||||||
def get_room_info(room_id):
|
|
||||||
last_msg = Message.objects.filter(room_id=room_id).first()
|
|
||||||
return {
|
|
||||||
"last_message": last_msg.body if last_msg else None,
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,14 +1,10 @@
|
||||||
from cryptography.fernet import Fernet
|
from cryptography.fernet import Fernet
|
||||||
import hmac
|
|
||||||
import hashlib
|
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db.models import OuterRef, Count, Subquery, IntegerField, Q
|
from django.db.models import OuterRef, Count, Subquery, IntegerField
|
||||||
from django.db.models.functions import Coalesce
|
from django.db.models.functions import Coalesce
|
||||||
|
|
||||||
from chat_box.models import Ignore, Message, UserRoom, Room
|
from chat_box.models import Ignore, Message, UserRoom
|
||||||
|
|
||||||
from judge.caching import cache_wrapper
|
|
||||||
|
|
||||||
secret_key = settings.CHAT_SECRET_KEY
|
secret_key = settings.CHAT_SECRET_KEY
|
||||||
fernet = Fernet(secret_key)
|
fernet = Fernet(secret_key)
|
||||||
|
@ -28,23 +24,25 @@ def decrypt_url(message_encrypted):
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
|
|
||||||
def encrypt_channel(channel):
|
def get_unread_boxes(profile):
|
||||||
return (
|
ignored_users = Ignore.get_ignored_users(profile)
|
||||||
hmac.new(
|
|
||||||
settings.CHAT_SECRET_KEY.encode(),
|
mess = (
|
||||||
channel.encode(),
|
Message.objects.filter(room=OuterRef("room"), time__gte=OuterRef("last_seen"))
|
||||||
hashlib.sha512,
|
.exclude(author=profile)
|
||||||
).hexdigest()[:16]
|
.exclude(author__in=ignored_users)
|
||||||
+ "%s" % channel
|
.order_by()
|
||||||
|
.values("room")
|
||||||
|
.annotate(unread_count=Count("pk"))
|
||||||
|
.values("unread_count")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@cache_wrapper(prefix="gub")
|
|
||||||
def get_unread_boxes(profile):
|
|
||||||
ignored_rooms = Ignore.get_ignored_rooms(profile)
|
|
||||||
unread_boxes = (
|
unread_boxes = (
|
||||||
UserRoom.objects.filter(user=profile, unread_count__gt=0)
|
UserRoom.objects.filter(user=profile, room__isnull=False)
|
||||||
.exclude(room__in=ignored_rooms)
|
.annotate(
|
||||||
|
unread_count=Coalesce(Subquery(mess, output_field=IntegerField()), 0),
|
||||||
|
)
|
||||||
|
.filter(unread_count__gte=1)
|
||||||
.count()
|
.count()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -21,23 +21,22 @@ from django.db.models import (
|
||||||
Exists,
|
Exists,
|
||||||
Count,
|
Count,
|
||||||
IntegerField,
|
IntegerField,
|
||||||
F,
|
|
||||||
Max,
|
|
||||||
)
|
)
|
||||||
from django.db.models.functions import Coalesce
|
from django.db.models.functions import Coalesce
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
|
||||||
from judge import event_poster as event
|
from judge import event_poster as event
|
||||||
from judge.jinja2.gravatar import gravatar
|
from judge.jinja2.gravatar import gravatar
|
||||||
from judge.models import Friend
|
from judge.models import Friend
|
||||||
|
|
||||||
from chat_box.models import Message, Profile, Room, UserRoom, Ignore, get_room_info
|
from chat_box.models import Message, Profile, Room, UserRoom, Ignore
|
||||||
from chat_box.utils import encrypt_url, decrypt_url, encrypt_channel, get_unread_boxes
|
from chat_box.utils import encrypt_url, decrypt_url
|
||||||
|
|
||||||
from reversion import revisions
|
import json
|
||||||
|
|
||||||
|
|
||||||
class ChatView(ListView):
|
class ChatView(ListView):
|
||||||
|
@ -49,29 +48,16 @@ class ChatView(ListView):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.room_id = None
|
self.room_id = None
|
||||||
self.room = None
|
self.room = None
|
||||||
|
self.paginate_by = 50
|
||||||
self.messages = None
|
self.messages = None
|
||||||
self.first_page_size = 20 # only for first request
|
self.paginator = None
|
||||||
self.follow_up_page_size = 50
|
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return self.messages
|
return self.messages
|
||||||
|
|
||||||
def has_next(self):
|
|
||||||
try:
|
|
||||||
msg = Message.objects.filter(room=self.room_id).earliest("id")
|
|
||||||
except Exception as e:
|
|
||||||
return False
|
|
||||||
return msg not in self.messages
|
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
request_room = kwargs["room_id"]
|
request_room = kwargs["room_id"]
|
||||||
page_size = self.follow_up_page_size
|
page = request.GET.get("page")
|
||||||
try:
|
|
||||||
last_id = int(request.GET.get("last_id"))
|
|
||||||
except Exception:
|
|
||||||
last_id = 1e15
|
|
||||||
page_size = self.first_page_size
|
|
||||||
only_messages = request.GET.get("only_messages")
|
|
||||||
|
|
||||||
if request_room:
|
if request_room:
|
||||||
try:
|
try:
|
||||||
|
@ -83,21 +69,23 @@ class ChatView(ListView):
|
||||||
else:
|
else:
|
||||||
request_room = None
|
request_room = None
|
||||||
|
|
||||||
|
if request_room != self.room_id or not self.messages:
|
||||||
self.room_id = request_room
|
self.room_id = request_room
|
||||||
self.messages = (
|
self.messages = Message.objects.filter(hidden=False, room=self.room_id)
|
||||||
Message.objects.filter(hidden=False, room=self.room_id, id__lt=last_id)
|
self.paginator = Paginator(self.messages, self.paginate_by)
|
||||||
.select_related("author")
|
|
||||||
.only("body", "time", "author__rating", "author__display_rank")[:page_size]
|
if page == None:
|
||||||
)
|
update_last_seen(request, **kwargs)
|
||||||
if not only_messages:
|
|
||||||
return super().get(request, *args, **kwargs)
|
return super().get(request, *args, **kwargs)
|
||||||
|
|
||||||
|
cur_page = self.paginator.get_page(page)
|
||||||
|
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
"chat/message_list.html",
|
"chat/message_list.html",
|
||||||
{
|
{
|
||||||
"object_list": self.messages,
|
"object_list": cur_page.object_list,
|
||||||
"has_next": self.has_next(),
|
"num_pages": self.paginator.num_pages,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -106,14 +94,9 @@ class ChatView(ListView):
|
||||||
|
|
||||||
context["title"] = self.title
|
context["title"] = self.title
|
||||||
context["last_msg"] = event.last()
|
context["last_msg"] = event.last()
|
||||||
context["status_sections"] = get_status_context(self.request.profile)
|
context["status_sections"] = get_status_context(self.request)
|
||||||
context["room"] = self.room_id
|
context["room"] = self.room_id
|
||||||
context["has_next"] = self.has_next()
|
|
||||||
context["unread_count_lobby"] = get_unread_count(None, self.request.profile)
|
context["unread_count_lobby"] = get_unread_count(None, self.request.profile)
|
||||||
context["chat_channel"] = encrypt_channel(
|
|
||||||
"chat_" + str(self.request.profile.id)
|
|
||||||
)
|
|
||||||
context["chat_lobby_channel"] = encrypt_channel("chat_lobby")
|
|
||||||
if self.room:
|
if self.room:
|
||||||
users_room = [self.room.user_one, self.room.user_two]
|
users_room = [self.room.user_one, self.room.user_two]
|
||||||
users_room.remove(self.request.profile)
|
users_room.remove(self.request.profile)
|
||||||
|
@ -137,89 +120,36 @@ def delete_message(request):
|
||||||
ret = {"delete": "done"}
|
ret = {"delete": "done"}
|
||||||
|
|
||||||
if request.method == "GET":
|
if request.method == "GET":
|
||||||
return HttpResponseBadRequest()
|
return JsonResponse(ret)
|
||||||
|
|
||||||
|
if request.user.is_staff:
|
||||||
try:
|
try:
|
||||||
messid = int(request.POST.get("message"))
|
messid = int(request.POST.get("message"))
|
||||||
mess = Message.objects.get(id=messid)
|
mess = Message.objects.get(id=messid)
|
||||||
except:
|
except:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
if not request.user.is_staff and request.profile != mess.author:
|
|
||||||
return HttpResponseBadRequest()
|
|
||||||
|
|
||||||
mess.hidden = True
|
mess.hidden = True
|
||||||
mess.save()
|
mess.save()
|
||||||
|
|
||||||
return JsonResponse(ret)
|
return JsonResponse(ret)
|
||||||
|
|
||||||
|
|
||||||
def mute_message(request):
|
|
||||||
ret = {"mute": "done"}
|
|
||||||
|
|
||||||
if request.method == "GET":
|
|
||||||
return HttpResponseBadRequest()
|
|
||||||
|
|
||||||
if not request.user.is_staff:
|
|
||||||
return HttpResponseBadRequest()
|
|
||||||
|
|
||||||
try:
|
|
||||||
messid = int(request.POST.get("message"))
|
|
||||||
mess = Message.objects.get(id=messid)
|
|
||||||
except:
|
|
||||||
return HttpResponseBadRequest()
|
|
||||||
|
|
||||||
with revisions.create_revision():
|
|
||||||
revisions.set_comment(_("Mute chat") + ": " + mess.body)
|
|
||||||
revisions.set_user(request.user)
|
|
||||||
mess.author.mute = True
|
|
||||||
mess.author.save()
|
|
||||||
|
|
||||||
Message.objects.filter(room=None, author=mess.author).update(hidden=True)
|
|
||||||
|
|
||||||
return JsonResponse(ret)
|
return JsonResponse(ret)
|
||||||
|
|
||||||
|
|
||||||
def check_valid_message(request, room):
|
|
||||||
if not room and len(request.POST["body"]) > 200:
|
|
||||||
return False
|
|
||||||
|
|
||||||
if not can_access_room(request, room) or request.profile.mute:
|
|
||||||
return False
|
|
||||||
|
|
||||||
last_msg = Message.objects.filter(room=room).first()
|
|
||||||
if (
|
|
||||||
last_msg
|
|
||||||
and last_msg.author == request.profile
|
|
||||||
and last_msg.body == request.POST["body"].strip()
|
|
||||||
):
|
|
||||||
return False
|
|
||||||
|
|
||||||
if not room:
|
|
||||||
four_last_msg = Message.objects.filter(room=room).order_by("-id")[:4]
|
|
||||||
if len(four_last_msg) >= 4:
|
|
||||||
same_author = all(msg.author == request.profile for msg in four_last_msg)
|
|
||||||
time_diff = timezone.now() - four_last_msg[3].time
|
|
||||||
if same_author and time_diff.total_seconds() < 300:
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def post_message(request):
|
def post_message(request):
|
||||||
ret = {"msg": "posted"}
|
ret = {"msg": "posted"}
|
||||||
|
|
||||||
if request.method != "POST":
|
if request.method != "POST":
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
if len(request.POST["body"]) > 5000 or len(request.POST["body"].strip()) == 0:
|
if len(request.POST["body"]) > 5000:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
room = None
|
room = None
|
||||||
if request.POST["room"]:
|
if request.POST["room"]:
|
||||||
room = Room.objects.get(id=request.POST["room"])
|
room = Room.objects.get(id=request.POST["room"])
|
||||||
|
|
||||||
if not check_valid_message(request, room):
|
if not can_access_room(request, room) or request.profile.mute:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
new_message = Message(author=request.profile, body=request.POST["body"], room=room)
|
new_message = Message(author=request.profile, body=request.POST["body"], room=room)
|
||||||
|
@ -227,7 +157,7 @@ def post_message(request):
|
||||||
|
|
||||||
if not room:
|
if not room:
|
||||||
event.post(
|
event.post(
|
||||||
encrypt_channel("chat_lobby"),
|
"chat_lobby",
|
||||||
{
|
{
|
||||||
"type": "lobby",
|
"type": "lobby",
|
||||||
"author_id": request.profile.id,
|
"author_id": request.profile.id,
|
||||||
|
@ -237,13 +167,9 @@ def post_message(request):
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
get_room_info.dirty(room.id)
|
|
||||||
room.last_msg_time = new_message.time
|
|
||||||
room.save()
|
|
||||||
|
|
||||||
for user in room.users():
|
for user in room.users():
|
||||||
event.post(
|
event.post(
|
||||||
encrypt_channel("chat_" + str(user.id)),
|
"chat_" + str(user.id),
|
||||||
{
|
{
|
||||||
"type": "private",
|
"type": "private",
|
||||||
"author_id": request.profile.id,
|
"author_id": request.profile.id,
|
||||||
|
@ -252,17 +178,14 @@ def post_message(request):
|
||||||
"tmp_id": request.POST.get("tmp_id"),
|
"tmp_id": request.POST.get("tmp_id"),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if user != request.profile:
|
|
||||||
UserRoom.objects.filter(user=user, room=room).update(
|
|
||||||
unread_count=F("unread_count") + 1
|
|
||||||
)
|
|
||||||
get_unread_boxes.dirty(user)
|
|
||||||
|
|
||||||
return JsonResponse(ret)
|
return JsonResponse(ret)
|
||||||
|
|
||||||
|
|
||||||
def can_access_room(request, room):
|
def can_access_room(request, room):
|
||||||
return not room or room.contain(request.profile)
|
return (
|
||||||
|
not room or room.user_one == request.profile or room.user_two == request.profile
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -278,7 +201,7 @@ def chat_message_ajax(request):
|
||||||
try:
|
try:
|
||||||
message = Message.objects.filter(hidden=False).get(id=message_id)
|
message = Message.objects.filter(hidden=False).get(id=message_id)
|
||||||
room = message.room
|
room = message.room
|
||||||
if not can_access_room(request, room):
|
if room and not room.contain(request.profile):
|
||||||
return HttpResponse("Unauthorized", status=401)
|
return HttpResponse("Unauthorized", status=401)
|
||||||
except Message.DoesNotExist:
|
except Message.DoesNotExist:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
@ -301,35 +224,35 @@ def update_last_seen(request, **kwargs):
|
||||||
room_id = request.POST.get("room")
|
room_id = request.POST.get("room")
|
||||||
else:
|
else:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
profile = request.profile
|
profile = request.profile
|
||||||
room = None
|
room = None
|
||||||
if room_id:
|
if room_id:
|
||||||
room = Room.objects.filter(id=int(room_id)).first()
|
room = Room.objects.get(id=int(room_id))
|
||||||
except Room.DoesNotExist:
|
except Room.DoesNotExist:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
except Exception as e:
|
||||||
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
if not can_access_room(request, room):
|
if room and not room.contain(profile):
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
user_room, _ = UserRoom.objects.get_or_create(user=profile, room=room)
|
user_room, _ = UserRoom.objects.get_or_create(user=profile, room=room)
|
||||||
user_room.last_seen = timezone.now()
|
user_room.last_seen = timezone.now()
|
||||||
user_room.unread_count = 0
|
|
||||||
user_room.save()
|
user_room.save()
|
||||||
|
|
||||||
get_unread_boxes.dirty(profile)
|
|
||||||
|
|
||||||
return JsonResponse({"msg": "updated"})
|
return JsonResponse({"msg": "updated"})
|
||||||
|
|
||||||
|
|
||||||
def get_online_count():
|
def get_online_count():
|
||||||
last_5_minutes = timezone.now() - timezone.timedelta(minutes=5)
|
last_two_minutes = timezone.now() - timezone.timedelta(minutes=2)
|
||||||
return Profile.objects.filter(last_access__gte=last_5_minutes).count()
|
return Profile.objects.filter(last_access__gte=last_two_minutes).count()
|
||||||
|
|
||||||
|
|
||||||
def get_user_online_status(user):
|
def get_user_online_status(user):
|
||||||
time_diff = timezone.now() - user.last_access
|
time_diff = timezone.now() - user.last_access
|
||||||
is_online = time_diff <= timezone.timedelta(minutes=5)
|
is_online = time_diff <= timezone.timedelta(minutes=2)
|
||||||
return is_online
|
return is_online
|
||||||
|
|
||||||
|
|
||||||
|
@ -366,66 +289,47 @@ def user_online_status_ajax(request):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_online_status(profile, other_profile_ids, rooms=None):
|
def get_online_status(request_user, queryset, rooms=None):
|
||||||
if not other_profile_ids:
|
if not queryset:
|
||||||
return None
|
return None
|
||||||
Profile.prefetch_profile_cache(other_profile_ids)
|
last_two_minutes = timezone.now() - timezone.timedelta(minutes=2)
|
||||||
|
|
||||||
joined_ids = ",".join([str(id) for id in other_profile_ids])
|
|
||||||
other_profiles = Profile.objects.raw(
|
|
||||||
f"SELECT * from judge_profile where id in ({joined_ids}) order by field(id,{joined_ids})"
|
|
||||||
)
|
|
||||||
last_5_minutes = timezone.now() - timezone.timedelta(minutes=5)
|
|
||||||
ret = []
|
ret = []
|
||||||
if rooms:
|
|
||||||
unread_count = get_unread_count(rooms, profile)
|
|
||||||
count = {}
|
|
||||||
last_msg = {}
|
|
||||||
room_of_user = {}
|
|
||||||
for i in unread_count:
|
|
||||||
room = Room.objects.get(id=i["room"])
|
|
||||||
other_profile = room.other_user(profile)
|
|
||||||
count[other_profile.id] = i["unread_count"]
|
|
||||||
rooms = Room.objects.filter(id__in=rooms)
|
|
||||||
for room in rooms:
|
|
||||||
other_profile_id = room.other_user_id(profile)
|
|
||||||
last_msg[other_profile_id] = room.last_message_body()
|
|
||||||
room_of_user[other_profile_id] = room.id
|
|
||||||
|
|
||||||
for other_profile in other_profiles:
|
|
||||||
is_online = False
|
|
||||||
if other_profile.last_access >= last_5_minutes:
|
|
||||||
is_online = True
|
|
||||||
user_dict = {"user": other_profile, "is_online": is_online}
|
|
||||||
if rooms:
|
if rooms:
|
||||||
user_dict.update(
|
unread_count = get_unread_count(rooms, request_user)
|
||||||
{
|
count = {}
|
||||||
"unread_count": count.get(other_profile.id),
|
for i in unread_count:
|
||||||
"last_msg": last_msg.get(other_profile.id),
|
count[i["other_user"]] = i["unread_count"]
|
||||||
"room": room_of_user.get(other_profile.id),
|
|
||||||
}
|
for user in queryset:
|
||||||
)
|
is_online = False
|
||||||
user_dict["url"] = encrypt_url(profile.id, other_profile.id)
|
if user.last_access >= last_two_minutes:
|
||||||
|
is_online = True
|
||||||
|
user_dict = {"user": user, "is_online": is_online}
|
||||||
|
if rooms and user.id in count:
|
||||||
|
user_dict["unread_count"] = count[user.id]
|
||||||
|
user_dict["url"] = encrypt_url(request_user.id, user.id)
|
||||||
ret.append(user_dict)
|
ret.append(user_dict)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def get_status_context(profile, include_ignored=False):
|
def get_status_context(request, include_ignored=False):
|
||||||
if include_ignored:
|
if include_ignored:
|
||||||
ignored_users = []
|
ignored_users = Profile.objects.none()
|
||||||
queryset = Profile.objects
|
queryset = Profile.objects
|
||||||
else:
|
else:
|
||||||
ignored_users = list(
|
ignored_users = Ignore.get_ignored_users(request.profile)
|
||||||
Ignore.get_ignored_users(profile).values_list("id", flat=True)
|
|
||||||
)
|
|
||||||
queryset = Profile.objects.exclude(id__in=ignored_users)
|
queryset = Profile.objects.exclude(id__in=ignored_users)
|
||||||
|
|
||||||
last_5_minutes = timezone.now() - timezone.timedelta(minutes=5)
|
last_two_minutes = timezone.now() - timezone.timedelta(minutes=2)
|
||||||
recent_profile = (
|
recent_profile = (
|
||||||
Room.objects.filter(Q(user_one=profile) | Q(user_two=profile))
|
Room.objects.filter(Q(user_one=request.profile) | Q(user_two=request.profile))
|
||||||
.annotate(
|
.annotate(
|
||||||
|
last_msg_time=Subquery(
|
||||||
|
Message.objects.filter(room=OuterRef("pk")).values("time")[:1]
|
||||||
|
),
|
||||||
other_user=Case(
|
other_user=Case(
|
||||||
When(user_one=profile, then="user_two"),
|
When(user_one=request.profile, then="user_two"),
|
||||||
default="user_one",
|
default="user_one",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -435,24 +339,50 @@ def get_status_context(profile, include_ignored=False):
|
||||||
.values("other_user", "id")[:20]
|
.values("other_user", "id")[:20]
|
||||||
)
|
)
|
||||||
|
|
||||||
recent_profile_ids = [str(i["other_user"]) for i in recent_profile]
|
recent_profile_id = [str(i["other_user"]) for i in recent_profile]
|
||||||
|
joined_id = ",".join(recent_profile_id)
|
||||||
recent_rooms = [int(i["id"]) for i in recent_profile]
|
recent_rooms = [int(i["id"]) for i in recent_profile]
|
||||||
Room.prefetch_room_cache(recent_rooms)
|
recent_list = None
|
||||||
|
if joined_id:
|
||||||
|
recent_list = Profile.objects.raw(
|
||||||
|
f"SELECT * from judge_profile where id in ({joined_id}) order by field(id,{joined_id})"
|
||||||
|
)
|
||||||
|
friend_list = (
|
||||||
|
Friend.get_friend_profiles(request.profile)
|
||||||
|
.exclude(id__in=recent_profile_id)
|
||||||
|
.exclude(id__in=ignored_users)
|
||||||
|
.order_by("-last_access")
|
||||||
|
)
|
||||||
admin_list = (
|
admin_list = (
|
||||||
queryset.filter(display_rank="admin")
|
queryset.filter(display_rank="admin")
|
||||||
.exclude(id__in=recent_profile_ids)
|
.exclude(id__in=friend_list)
|
||||||
.values_list("id", flat=True)
|
.exclude(id__in=recent_profile_id)
|
||||||
|
)
|
||||||
|
all_user_status = (
|
||||||
|
queryset.filter(display_rank="user", last_access__gte=last_two_minutes)
|
||||||
|
.annotate(is_online=Case(default=True, output_field=BooleanField()))
|
||||||
|
.order_by("-rating")
|
||||||
|
.exclude(id__in=friend_list)
|
||||||
|
.exclude(id__in=admin_list)
|
||||||
|
.exclude(id__in=recent_profile_id)[:30]
|
||||||
)
|
)
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"title": _("Recent"),
|
"title": "Recent",
|
||||||
"user_list": get_online_status(profile, recent_profile_ids, recent_rooms),
|
"user_list": get_online_status(request.profile, recent_list, recent_rooms),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"title": _("Admin"),
|
"title": "Following",
|
||||||
"user_list": get_online_status(profile, admin_list),
|
"user_list": get_online_status(request.profile, friend_list),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Admin",
|
||||||
|
"user_list": get_online_status(request.profile, admin_list),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Other",
|
||||||
|
"user_list": get_online_status(request.profile, all_user_status),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -463,7 +393,7 @@ def online_status_ajax(request):
|
||||||
request,
|
request,
|
||||||
"chat/online_status.html",
|
"chat/online_status.html",
|
||||||
{
|
{
|
||||||
"status_sections": get_status_context(request.profile),
|
"status_sections": get_status_context(request),
|
||||||
"unread_count_lobby": get_unread_count(None, request.profile),
|
"unread_count_lobby": get_unread_count(None, request.profile),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -487,6 +417,7 @@ def get_or_create_room(request):
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
request_id, other_id = decrypt_url(decrypted_other_id)
|
request_id, other_id = decrypt_url(decrypted_other_id)
|
||||||
|
|
||||||
if not other_id or not request_id or request_id != request.profile.id:
|
if not other_id or not request_id or request_id != request.profile.id:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
|
@ -507,36 +438,55 @@ def get_or_create_room(request):
|
||||||
user_room.last_seen = timezone.now()
|
user_room.last_seen = timezone.now()
|
||||||
user_room.save()
|
user_room.save()
|
||||||
|
|
||||||
room_url = reverse("chat", kwargs={"room_id": room.id})
|
|
||||||
if request.method == "GET":
|
if request.method == "GET":
|
||||||
return JsonResponse(
|
return JsonResponse({"room": room.id, "other_user_id": other_user.id})
|
||||||
{
|
return HttpResponseRedirect(reverse("chat", kwargs={"room_id": room.id}))
|
||||||
"room": room.id,
|
|
||||||
"other_user_id": other_user.id,
|
|
||||||
"url": room_url,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return HttpResponseRedirect(room_url)
|
|
||||||
|
|
||||||
|
|
||||||
def get_unread_count(rooms, user):
|
def get_unread_count(rooms, user):
|
||||||
if rooms:
|
if rooms:
|
||||||
return UserRoom.objects.filter(
|
mess = (
|
||||||
user=user, room__in=rooms, unread_count__gt=0
|
Message.objects.filter(
|
||||||
).values("unread_count", "room")
|
room=OuterRef("room"), time__gte=OuterRef("last_seen")
|
||||||
else: # lobby
|
)
|
||||||
user_room = UserRoom.objects.filter(user=user, room__isnull=True).first()
|
|
||||||
if not user_room:
|
|
||||||
return 0
|
|
||||||
last_seen = user_room.last_seen
|
|
||||||
res = (
|
|
||||||
Message.objects.filter(room__isnull=True, time__gte=last_seen)
|
|
||||||
.exclude(author=user)
|
.exclude(author=user)
|
||||||
.exclude(hidden=True)
|
.order_by()
|
||||||
.count()
|
.values("room")
|
||||||
|
.annotate(unread_count=Count("pk"))
|
||||||
|
.values("unread_count")
|
||||||
)
|
)
|
||||||
|
|
||||||
return res
|
return (
|
||||||
|
UserRoom.objects.filter(user=user, room__in=rooms)
|
||||||
|
.annotate(
|
||||||
|
unread_count=Coalesce(Subquery(mess, output_field=IntegerField()), 0),
|
||||||
|
other_user=Case(
|
||||||
|
When(room__user_one=user, then="room__user_two"),
|
||||||
|
default="room__user_one",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.filter(unread_count__gte=1)
|
||||||
|
.values("other_user", "unread_count")
|
||||||
|
)
|
||||||
|
else: # lobby
|
||||||
|
mess = (
|
||||||
|
Message.objects.filter(room__isnull=True, time__gte=OuterRef("last_seen"))
|
||||||
|
.exclude(author=user)
|
||||||
|
.order_by()
|
||||||
|
.values("room")
|
||||||
|
.annotate(unread_count=Count("pk"))
|
||||||
|
.values("unread_count")
|
||||||
|
)
|
||||||
|
|
||||||
|
res = (
|
||||||
|
UserRoom.objects.filter(user=user, room__isnull=True)
|
||||||
|
.annotate(
|
||||||
|
unread_count=Coalesce(Subquery(mess, output_field=IntegerField()), 0),
|
||||||
|
)
|
||||||
|
.values_list("unread_count", flat=True)
|
||||||
|
)
|
||||||
|
|
||||||
|
return res[0] if len(res) else 0
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
|
|
@ -162,7 +162,7 @@
|
||||||
]);
|
]);
|
||||||
|
|
||||||
window[widget.id] = editor;
|
window[widget.id] = editor;
|
||||||
setTimeout(() => $(widget).trigger('ace_load', [editor]), 100);
|
$(widget).trigger('ace_load', [editor]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
|
|
|
@ -66,7 +66,7 @@ class AceWidget(forms.Textarea):
|
||||||
if self.toolbar:
|
if self.toolbar:
|
||||||
toolbar = (
|
toolbar = (
|
||||||
'<div style="width: {}" class="django-ace-toolbar">'
|
'<div style="width: {}" class="django-ace-toolbar">'
|
||||||
'<a href="#" class="django-ace-max_min"></a>'
|
'<a href="./" class="django-ace-max_min"></a>'
|
||||||
"</div>"
|
"</div>"
|
||||||
).format(self.width)
|
).format(self.width)
|
||||||
html = toolbar + html
|
html = toolbar + html
|
||||||
|
|
|
@ -33,7 +33,6 @@ SITE_ID = 1
|
||||||
SITE_NAME = "LQDOJ"
|
SITE_NAME = "LQDOJ"
|
||||||
SITE_LONG_NAME = "LQDOJ: Le Quy Don Online Judge"
|
SITE_LONG_NAME = "LQDOJ: Le Quy Don Online Judge"
|
||||||
SITE_ADMIN_EMAIL = False
|
SITE_ADMIN_EMAIL = False
|
||||||
SITE_DOMAIN = "lqdoj.edu.vn"
|
|
||||||
|
|
||||||
DMOJ_REQUIRE_STAFF_2FA = True
|
DMOJ_REQUIRE_STAFF_2FA = True
|
||||||
|
|
||||||
|
@ -61,7 +60,6 @@ DMOJ_PROBLEM_MAX_TIME_LIMIT = 60 # seconds
|
||||||
DMOJ_PROBLEM_MIN_MEMORY_LIMIT = 0 # kilobytes
|
DMOJ_PROBLEM_MIN_MEMORY_LIMIT = 0 # kilobytes
|
||||||
DMOJ_PROBLEM_MAX_MEMORY_LIMIT = 1048576 # kilobytes
|
DMOJ_PROBLEM_MAX_MEMORY_LIMIT = 1048576 # kilobytes
|
||||||
DMOJ_PROBLEM_MIN_PROBLEM_POINTS = 0
|
DMOJ_PROBLEM_MIN_PROBLEM_POINTS = 0
|
||||||
DMOJ_SUBMISSION_ROOT = "/tmp"
|
|
||||||
DMOJ_RATING_COLORS = True
|
DMOJ_RATING_COLORS = True
|
||||||
DMOJ_EMAIL_THROTTLING = (10, 60)
|
DMOJ_EMAIL_THROTTLING = (10, 60)
|
||||||
DMOJ_STATS_LANGUAGE_THRESHOLD = 10
|
DMOJ_STATS_LANGUAGE_THRESHOLD = 10
|
||||||
|
@ -84,9 +82,6 @@ DMOJ_STATS_SUBMISSION_RESULT_COLORS = {
|
||||||
"CE": "#42586d",
|
"CE": "#42586d",
|
||||||
"ERR": "#ffa71c",
|
"ERR": "#ffa71c",
|
||||||
}
|
}
|
||||||
DMOJ_PROFILE_IMAGE_ROOT = "profile_images"
|
|
||||||
DMOJ_ORGANIZATION_IMAGE_ROOT = "organization_images"
|
|
||||||
DMOJ_TEST_FORMATTER_ROOT = "test_formatter"
|
|
||||||
|
|
||||||
MARKDOWN_STYLES = {}
|
MARKDOWN_STYLES = {}
|
||||||
MARKDOWN_DEFAULT_STYLE = {}
|
MARKDOWN_DEFAULT_STYLE = {}
|
||||||
|
@ -132,10 +127,13 @@ USE_SELENIUM = False
|
||||||
SELENIUM_CUSTOM_CHROME_PATH = None
|
SELENIUM_CUSTOM_CHROME_PATH = None
|
||||||
SELENIUM_CHROMEDRIVER_PATH = "chromedriver"
|
SELENIUM_CHROMEDRIVER_PATH = "chromedriver"
|
||||||
|
|
||||||
|
PYGMENT_THEME = "pygment-github.css"
|
||||||
INLINE_JQUERY = True
|
INLINE_JQUERY = True
|
||||||
INLINE_FONTAWESOME = True
|
INLINE_FONTAWESOME = True
|
||||||
JQUERY_JS = "//ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"
|
JQUERY_JS = "//ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"
|
||||||
FONTAWESOME_CSS = "//cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css"
|
FONTAWESOME_CSS = (
|
||||||
|
"//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"
|
||||||
|
)
|
||||||
DMOJ_CANONICAL = ""
|
DMOJ_CANONICAL = ""
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
@ -169,7 +167,7 @@ else:
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"model": "judge.Submission",
|
"model": "judge.Submission",
|
||||||
"icon": "fa-check-square",
|
"icon": "fa-check-square-o",
|
||||||
"children": [
|
"children": [
|
||||||
"judge.Language",
|
"judge.Language",
|
||||||
"judge.Judge",
|
"judge.Judge",
|
||||||
|
@ -249,7 +247,6 @@ INSTALLED_APPS += (
|
||||||
)
|
)
|
||||||
|
|
||||||
MIDDLEWARE = (
|
MIDDLEWARE = (
|
||||||
"judge.middleware.SlowRequestMiddleware",
|
|
||||||
"judge.middleware.ShortCircuitMiddleware",
|
"judge.middleware.ShortCircuitMiddleware",
|
||||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||||
"django.middleware.locale.LocaleMiddleware",
|
"django.middleware.locale.LocaleMiddleware",
|
||||||
|
@ -277,11 +274,8 @@ LANGUAGE_COOKIE_AGE = 8640000
|
||||||
|
|
||||||
FORM_RENDERER = "django.forms.renderers.TemplatesSetting"
|
FORM_RENDERER = "django.forms.renderers.TemplatesSetting"
|
||||||
|
|
||||||
IMPERSONATE = {
|
IMPERSONATE_REQUIRE_SUPERUSER = True
|
||||||
"REQUIRE_SUPERUSER": True,
|
IMPERSONATE_DISABLE_LOGGING = True
|
||||||
"DISABLE_LOGGING": True,
|
|
||||||
"ADMIN_DELETE_PERMISSION": True,
|
|
||||||
}
|
|
||||||
|
|
||||||
ACCOUNT_ACTIVATION_DAYS = 7
|
ACCOUNT_ACTIVATION_DAYS = 7
|
||||||
|
|
||||||
|
@ -325,6 +319,7 @@ TEMPLATES = [
|
||||||
"judge.template_context.site",
|
"judge.template_context.site",
|
||||||
"judge.template_context.site_name",
|
"judge.template_context.site_name",
|
||||||
"judge.template_context.misc_config",
|
"judge.template_context.misc_config",
|
||||||
|
"judge.template_context.math_setting",
|
||||||
"social_django.context_processors.backends",
|
"social_django.context_processors.backends",
|
||||||
"social_django.context_processors.login_redirect",
|
"social_django.context_processors.login_redirect",
|
||||||
],
|
],
|
||||||
|
@ -384,7 +379,6 @@ BRIDGED_JUDGE_ADDRESS = [("localhost", 9999)]
|
||||||
BRIDGED_JUDGE_PROXIES = None
|
BRIDGED_JUDGE_PROXIES = None
|
||||||
BRIDGED_DJANGO_ADDRESS = [("localhost", 9998)]
|
BRIDGED_DJANGO_ADDRESS = [("localhost", 9998)]
|
||||||
BRIDGED_DJANGO_CONNECT = None
|
BRIDGED_DJANGO_CONNECT = None
|
||||||
BRIDGED_AUTO_CREATE_JUDGE = False
|
|
||||||
|
|
||||||
# Event Server configuration
|
# Event Server configuration
|
||||||
EVENT_DAEMON_USE = False
|
EVENT_DAEMON_USE = False
|
||||||
|
@ -432,7 +426,7 @@ AUTHENTICATION_BACKENDS = (
|
||||||
"social_core.backends.google.GoogleOAuth2",
|
"social_core.backends.google.GoogleOAuth2",
|
||||||
"social_core.backends.facebook.FacebookOAuth2",
|
"social_core.backends.facebook.FacebookOAuth2",
|
||||||
"judge.social_auth.GitHubSecureEmailOAuth2",
|
"judge.social_auth.GitHubSecureEmailOAuth2",
|
||||||
"judge.authentication.CustomModelBackend",
|
"django.contrib.auth.backends.ModelBackend",
|
||||||
)
|
)
|
||||||
|
|
||||||
SOCIAL_AUTH_PIPELINE = (
|
SOCIAL_AUTH_PIPELINE = (
|
||||||
|
@ -478,24 +472,10 @@ ML_OUTPUT_PATH = None
|
||||||
# Use subdomain for organizations
|
# Use subdomain for organizations
|
||||||
USE_SUBDOMAIN = False
|
USE_SUBDOMAIN = False
|
||||||
|
|
||||||
# Chat
|
|
||||||
CHAT_SECRET_KEY = "QUdVFsxk6f5-Hd8g9BXv81xMqvIZFRqMl-KbRzztW-U="
|
|
||||||
|
|
||||||
# Nginx
|
|
||||||
META_REMOTE_ADDRESS_KEY = "REMOTE_ADDR"
|
|
||||||
|
|
||||||
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
|
|
||||||
|
|
||||||
# Chunk upload
|
|
||||||
CHUNK_UPLOAD_DIR = "/tmp/chunk_upload_tmp"
|
|
||||||
|
|
||||||
# Rate limit
|
|
||||||
RL_VOTE = "200/h"
|
|
||||||
RL_COMMENT = "30/h"
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(os.path.join(os.path.dirname(__file__), "local_settings.py")) as f:
|
with open(os.path.join(os.path.dirname(__file__), "local_settings.py")) as f:
|
||||||
exec(f.read(), globals())
|
exec(f.read(), globals())
|
||||||
except IOError:
|
except IOError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
|
||||||
|
|
241
dmoj/urls.py
241
dmoj/urls.py
|
@ -15,6 +15,14 @@ from django.contrib.auth.decorators import login_required
|
||||||
from django.conf.urls.static import static as url_static
|
from django.conf.urls.static import static as url_static
|
||||||
|
|
||||||
|
|
||||||
|
from judge.feed import (
|
||||||
|
AtomBlogFeed,
|
||||||
|
AtomCommentFeed,
|
||||||
|
AtomProblemFeed,
|
||||||
|
BlogFeed,
|
||||||
|
CommentFeed,
|
||||||
|
ProblemFeed,
|
||||||
|
)
|
||||||
from judge.forms import CustomAuthenticationForm
|
from judge.forms import CustomAuthenticationForm
|
||||||
from judge.sitemap import (
|
from judge.sitemap import (
|
||||||
BlogPostSitemap,
|
BlogPostSitemap,
|
||||||
|
@ -36,8 +44,6 @@ from judge.views import (
|
||||||
language,
|
language,
|
||||||
license,
|
license,
|
||||||
mailgun,
|
mailgun,
|
||||||
markdown_editor,
|
|
||||||
test_formatter,
|
|
||||||
notification,
|
notification,
|
||||||
organization,
|
organization,
|
||||||
preview,
|
preview,
|
||||||
|
@ -59,13 +65,7 @@ from judge.views import (
|
||||||
internal,
|
internal,
|
||||||
resolver,
|
resolver,
|
||||||
course,
|
course,
|
||||||
email,
|
|
||||||
custom_file_upload,
|
|
||||||
)
|
)
|
||||||
from judge import authentication
|
|
||||||
|
|
||||||
from judge.views.test_formatter import test_formatter
|
|
||||||
|
|
||||||
from judge.views.problem_data import (
|
from judge.views.problem_data import (
|
||||||
ProblemDataView,
|
ProblemDataView,
|
||||||
ProblemSubmissionDiff,
|
ProblemSubmissionDiff,
|
||||||
|
@ -77,6 +77,7 @@ from judge.views.register import ActivationView, RegistrationView
|
||||||
from judge.views.select2 import (
|
from judge.views.select2 import (
|
||||||
AssigneeSelect2View,
|
AssigneeSelect2View,
|
||||||
ChatUserSearchSelect2View,
|
ChatUserSearchSelect2View,
|
||||||
|
CommentSelect2View,
|
||||||
ContestSelect2View,
|
ContestSelect2View,
|
||||||
ContestUserSearchSelect2View,
|
ContestUserSearchSelect2View,
|
||||||
OrganizationSelect2View,
|
OrganizationSelect2View,
|
||||||
|
@ -84,7 +85,6 @@ from judge.views.select2 import (
|
||||||
TicketUserSelect2View,
|
TicketUserSelect2View,
|
||||||
UserSearchSelect2View,
|
UserSearchSelect2View,
|
||||||
UserSelect2View,
|
UserSelect2View,
|
||||||
ProblemAuthorSearchSelect2View,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
admin.autodiscover()
|
admin.autodiscover()
|
||||||
|
@ -104,19 +104,19 @@ register_patterns = [
|
||||||
# confusing 404.
|
# confusing 404.
|
||||||
url(
|
url(
|
||||||
r"^activate/(?P<activation_key>\w+)/$",
|
r"^activate/(?P<activation_key>\w+)/$",
|
||||||
ActivationView.as_view(title=_("Activation key invalid")),
|
ActivationView.as_view(title="Activation key invalid"),
|
||||||
name="registration_activate",
|
name="registration_activate",
|
||||||
),
|
),
|
||||||
url(
|
url(
|
||||||
r"^register/$",
|
r"^register/$",
|
||||||
RegistrationView.as_view(title=_("Register")),
|
RegistrationView.as_view(title="Register"),
|
||||||
name="registration_register",
|
name="registration_register",
|
||||||
),
|
),
|
||||||
url(
|
url(
|
||||||
r"^register/complete/$",
|
r"^register/complete/$",
|
||||||
TitledTemplateView.as_view(
|
TitledTemplateView.as_view(
|
||||||
template_name="registration/registration_complete.html",
|
template_name="registration/registration_complete.html",
|
||||||
title=_("Registration Completed"),
|
title="Registration Completed",
|
||||||
),
|
),
|
||||||
name="registration_complete",
|
name="registration_complete",
|
||||||
),
|
),
|
||||||
|
@ -124,7 +124,7 @@ register_patterns = [
|
||||||
r"^register/closed/$",
|
r"^register/closed/$",
|
||||||
TitledTemplateView.as_view(
|
TitledTemplateView.as_view(
|
||||||
template_name="registration/registration_closed.html",
|
template_name="registration/registration_closed.html",
|
||||||
title=_("Registration not allowed"),
|
title="Registration not allowed",
|
||||||
),
|
),
|
||||||
name="registration_disallowed",
|
name="registration_disallowed",
|
||||||
),
|
),
|
||||||
|
@ -141,7 +141,9 @@ register_patterns = [
|
||||||
url(r"^logout/$", user.UserLogoutView.as_view(), name="auth_logout"),
|
url(r"^logout/$", user.UserLogoutView.as_view(), name="auth_logout"),
|
||||||
url(
|
url(
|
||||||
r"^password/change/$",
|
r"^password/change/$",
|
||||||
authentication.CustomPasswordChangeView.as_view(),
|
auth_views.PasswordChangeView.as_view(
|
||||||
|
template_name="registration/password_change_form.html",
|
||||||
|
),
|
||||||
name="password_change",
|
name="password_change",
|
||||||
),
|
),
|
||||||
url(
|
url(
|
||||||
|
@ -181,17 +183,6 @@ register_patterns = [
|
||||||
),
|
),
|
||||||
name="password_reset_done",
|
name="password_reset_done",
|
||||||
),
|
),
|
||||||
url(r"^email/change/$", email.email_change_view, name="email_change"),
|
|
||||||
url(
|
|
||||||
r"^email/change/verify/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$",
|
|
||||||
email.verify_email_view,
|
|
||||||
name="email_change_verify",
|
|
||||||
),
|
|
||||||
url(
|
|
||||||
r"^email/change/pending$",
|
|
||||||
email.email_change_pending_view,
|
|
||||||
name="email_change_pending",
|
|
||||||
),
|
|
||||||
url(r"^social/error/$", register.social_auth_error, name="social_auth_error"),
|
url(r"^social/error/$", register.social_auth_error, name="social_auth_error"),
|
||||||
url(r"^2fa/$", totp.TOTPLoginView.as_view(), name="login_2fa"),
|
url(r"^2fa/$", totp.TOTPLoginView.as_view(), name="login_2fa"),
|
||||||
url(r"^2fa/enable/$", totp.TOTPEnableView.as_view(), name="enable_2fa"),
|
url(r"^2fa/enable/$", totp.TOTPEnableView.as_view(), name="enable_2fa"),
|
||||||
|
@ -240,19 +231,18 @@ urlpatterns = [
|
||||||
url(r"^problems/", paged_list_view(problem.ProblemList, "problem_list")),
|
url(r"^problems/", paged_list_view(problem.ProblemList, "problem_list")),
|
||||||
url(r"^problems/random/$", problem.RandomProblem.as_view(), name="problem_random"),
|
url(r"^problems/random/$", problem.RandomProblem.as_view(), name="problem_random"),
|
||||||
url(
|
url(
|
||||||
r"^problems/feed/$",
|
r"^problems/feed/",
|
||||||
problem.ProblemFeed.as_view(feed_type="for_you"),
|
paged_list_view(problem.ProblemFeed, "problem_feed", feed_type="for_you"),
|
||||||
name="problem_feed",
|
|
||||||
),
|
),
|
||||||
url(
|
url(
|
||||||
r"^problems/feed/new/$",
|
r"^problems/feed/new/",
|
||||||
problem.ProblemFeed.as_view(feed_type="new"),
|
paged_list_view(problem.ProblemFeed, "problem_feed_new", feed_type="new"),
|
||||||
name="problem_feed_new",
|
|
||||||
),
|
),
|
||||||
url(
|
url(
|
||||||
r"^problems/feed/volunteer/$",
|
r"^problems/feed/volunteer/",
|
||||||
problem.ProblemFeed.as_view(feed_type="volunteer"),
|
paged_list_view(
|
||||||
name="problem_feed_volunteer",
|
problem.ProblemFeed, "problem_feed_volunteer", feed_type="volunteer"
|
||||||
|
),
|
||||||
),
|
),
|
||||||
url(
|
url(
|
||||||
r"^problem/(?P<problem>[^/]+)",
|
r"^problem/(?P<problem>[^/]+)",
|
||||||
|
@ -379,10 +369,6 @@ urlpatterns = [
|
||||||
r"^submissions/user/(?P<user>\w+)/",
|
r"^submissions/user/(?P<user>\w+)/",
|
||||||
paged_list_view(submission.AllUserSubmissions, "all_user_submissions"),
|
paged_list_view(submission.AllUserSubmissions, "all_user_submissions"),
|
||||||
),
|
),
|
||||||
url(
|
|
||||||
r"^submissions/friends/",
|
|
||||||
paged_list_view(submission.AllFriendSubmissions, "all_friend_submissions"),
|
|
||||||
),
|
|
||||||
url(
|
url(
|
||||||
r"^src/(?P<submission>\d+)/raw$",
|
r"^src/(?P<submission>\d+)/raw$",
|
||||||
submission.SubmissionSourceRaw.as_view(),
|
submission.SubmissionSourceRaw.as_view(),
|
||||||
|
@ -398,41 +384,10 @@ urlpatterns = [
|
||||||
name="submission_status",
|
name="submission_status",
|
||||||
),
|
),
|
||||||
url(r"^/abort$", submission.abort_submission, name="submission_abort"),
|
url(r"^/abort$", submission.abort_submission, name="submission_abort"),
|
||||||
|
url(r"^/html$", submission.single_submission),
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
url(
|
|
||||||
r"^test_formatter/",
|
|
||||||
include(
|
|
||||||
[
|
|
||||||
url(
|
|
||||||
r"^$",
|
|
||||||
login_required(test_formatter.TestFormatter.as_view()),
|
|
||||||
name="test_formatter",
|
|
||||||
),
|
|
||||||
url(
|
|
||||||
r"^edit_page$",
|
|
||||||
login_required(test_formatter.EditTestFormatter.as_view()),
|
|
||||||
name="test_formatter_edit",
|
|
||||||
),
|
|
||||||
url(
|
|
||||||
r"^download_page$",
|
|
||||||
login_required(test_formatter.DownloadTestFormatter.as_view()),
|
|
||||||
name="test_formatter_download",
|
|
||||||
),
|
|
||||||
]
|
|
||||||
),
|
|
||||||
),
|
|
||||||
url(
|
|
||||||
r"^markdown_editor/",
|
|
||||||
markdown_editor.MarkdownEditor.as_view(),
|
|
||||||
name="markdown_editor",
|
|
||||||
),
|
|
||||||
url(
|
|
||||||
r"^submission_source_file/(?P<filename>(\w|\.)+)",
|
|
||||||
submission.SubmissionSourceFileView.as_view(),
|
|
||||||
name="submission_source_file",
|
|
||||||
),
|
|
||||||
url(
|
url(
|
||||||
r"^users/",
|
r"^users/",
|
||||||
include(
|
include(
|
||||||
|
@ -487,7 +442,6 @@ urlpatterns = [
|
||||||
reverse("all_user_submissions", args=[user])
|
reverse("all_user_submissions", args=[user])
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
url(r"^/toggle_follow/", user.toggle_follow, name="user_toggle_follow"),
|
|
||||||
url(
|
url(
|
||||||
r"^/$",
|
r"^/$",
|
||||||
lambda _, user: HttpResponsePermanentRedirect(
|
lambda _, user: HttpResponsePermanentRedirect(
|
||||||
|
@ -504,8 +458,6 @@ urlpatterns = [
|
||||||
url(r"^comments/upvote/$", comment.upvote_comment, name="comment_upvote"),
|
url(r"^comments/upvote/$", comment.upvote_comment, name="comment_upvote"),
|
||||||
url(r"^comments/downvote/$", comment.downvote_comment, name="comment_downvote"),
|
url(r"^comments/downvote/$", comment.downvote_comment, name="comment_downvote"),
|
||||||
url(r"^comments/hide/$", comment.comment_hide, name="comment_hide"),
|
url(r"^comments/hide/$", comment.comment_hide, name="comment_hide"),
|
||||||
url(r"^comments/get_replies/$", comment.get_replies, name="comment_get_replies"),
|
|
||||||
url(r"^comments/show_more/$", comment.get_show_more, name="comment_show_more"),
|
|
||||||
url(
|
url(
|
||||||
r"^comments/(?P<id>\d+)/",
|
r"^comments/(?P<id>\d+)/",
|
||||||
include(
|
include(
|
||||||
|
@ -535,58 +487,6 @@ urlpatterns = [
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
url(r"^contests/", paged_list_view(contests.ContestList, "contest_list")),
|
url(r"^contests/", paged_list_view(contests.ContestList, "contest_list")),
|
||||||
url(
|
|
||||||
r"^contests/summary/(?P<key>\w+)/",
|
|
||||||
paged_list_view(contests.ContestsSummaryView, "contests_summary"),
|
|
||||||
),
|
|
||||||
url(
|
|
||||||
r"^contests/official",
|
|
||||||
paged_list_view(contests.OfficialContestList, "official_contest_list"),
|
|
||||||
),
|
|
||||||
url(r"^courses/", paged_list_view(course.CourseList, "course_list")),
|
|
||||||
url(
|
|
||||||
r"^course/(?P<slug>[\w-]*)",
|
|
||||||
include(
|
|
||||||
[
|
|
||||||
url(r"^$", course.CourseDetail.as_view(), name="course_detail"),
|
|
||||||
url(
|
|
||||||
r"^/lesson/(?P<id>\d+)$",
|
|
||||||
course.CourseLessonDetail.as_view(),
|
|
||||||
name="course_lesson_detail",
|
|
||||||
),
|
|
||||||
url(
|
|
||||||
r"^/edit_lessons$",
|
|
||||||
course.EditCourseLessonsView.as_view(),
|
|
||||||
name="edit_course_lessons",
|
|
||||||
),
|
|
||||||
url(
|
|
||||||
r"^/grades$",
|
|
||||||
course.CourseStudentResults.as_view(),
|
|
||||||
name="course_grades",
|
|
||||||
),
|
|
||||||
url(
|
|
||||||
r"^/grades/lesson/(?P<id>\d+)$",
|
|
||||||
course.CourseStudentResultsLesson.as_view(),
|
|
||||||
name="course_grades_lesson",
|
|
||||||
),
|
|
||||||
url(
|
|
||||||
r"^/add_contest$",
|
|
||||||
course.AddCourseContest.as_view(),
|
|
||||||
name="add_course_contest",
|
|
||||||
),
|
|
||||||
url(
|
|
||||||
r"^/edit_contest/(?P<contest>\w+)$",
|
|
||||||
course.EditCourseContest.as_view(),
|
|
||||||
name="edit_course_contest",
|
|
||||||
),
|
|
||||||
url(
|
|
||||||
r"^/contests$",
|
|
||||||
course.CourseContestList.as_view(),
|
|
||||||
name="course_contest_list",
|
|
||||||
),
|
|
||||||
]
|
|
||||||
),
|
|
||||||
),
|
|
||||||
url(
|
url(
|
||||||
r"^contests/(?P<year>\d+)/(?P<month>\d+)/$",
|
r"^contests/(?P<year>\d+)/(?P<month>\d+)/$",
|
||||||
contests.ContestCalendar.as_view(),
|
contests.ContestCalendar.as_view(),
|
||||||
|
@ -629,9 +529,21 @@ urlpatterns = [
|
||||||
contests.ContestFinalRanking.as_view(),
|
contests.ContestFinalRanking.as_view(),
|
||||||
name="contest_final_ranking",
|
name="contest_final_ranking",
|
||||||
),
|
),
|
||||||
|
url(
|
||||||
|
r"^/ranking/ajax$",
|
||||||
|
contests.contest_ranking_ajax,
|
||||||
|
name="contest_ranking_ajax",
|
||||||
|
),
|
||||||
url(r"^/join$", contests.ContestJoin.as_view(), name="contest_join"),
|
url(r"^/join$", contests.ContestJoin.as_view(), name="contest_join"),
|
||||||
url(r"^/leave$", contests.ContestLeave.as_view(), name="contest_leave"),
|
url(r"^/leave$", contests.ContestLeave.as_view(), name="contest_leave"),
|
||||||
url(r"^/stats$", contests.ContestStats.as_view(), name="contest_stats"),
|
url(r"^/stats$", contests.ContestStats.as_view(), name="contest_stats"),
|
||||||
|
url(
|
||||||
|
r"^/rank/(?P<problem>\w+)/",
|
||||||
|
paged_list_view(
|
||||||
|
ranked_submission.ContestRankedSubmission,
|
||||||
|
"contest_ranked_submissions",
|
||||||
|
),
|
||||||
|
),
|
||||||
url(
|
url(
|
||||||
r"^/submissions/(?P<user>\w+)/(?P<problem>\w+)",
|
r"^/submissions/(?P<user>\w+)/(?P<problem>\w+)",
|
||||||
paged_list_view(
|
paged_list_view(
|
||||||
|
@ -645,13 +557,6 @@ urlpatterns = [
|
||||||
"contest_user_submissions_ajax",
|
"contest_user_submissions_ajax",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
url(
|
|
||||||
r"^/submissions",
|
|
||||||
paged_list_view(
|
|
||||||
submission.ContestSubmissions,
|
|
||||||
"contest_submissions",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
url(
|
url(
|
||||||
r"^/participations$",
|
r"^/participations$",
|
||||||
contests.ContestParticipationList.as_view(),
|
contests.ContestParticipationList.as_view(),
|
||||||
|
@ -686,6 +591,24 @@ urlpatterns = [
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
url(r"^courses/", paged_list_view(course.CourseList, "course_list" )),
|
||||||
|
url(
|
||||||
|
r"^courses/(?P<slug>[\w-]*)",
|
||||||
|
include(
|
||||||
|
[
|
||||||
|
url(
|
||||||
|
r"^$",
|
||||||
|
course.CourseDetail.as_view(),
|
||||||
|
name="course_detail"
|
||||||
|
),
|
||||||
|
url(
|
||||||
|
r"^/grades$",
|
||||||
|
course.CourseStudentResults.as_view(),
|
||||||
|
name="grades"
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
),
|
||||||
url(
|
url(
|
||||||
r"^organizations/$",
|
r"^organizations/$",
|
||||||
organization.OrganizationList.as_view(),
|
organization.OrganizationList.as_view(),
|
||||||
|
@ -847,7 +770,7 @@ urlpatterns = [
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
url(r"^blog/", blog.PostList.as_view(), name="blog_post_list"),
|
url(r"^blog/", paged_list_view(blog.PostList, "blog_post_list")),
|
||||||
url(r"^post/(?P<id>\d+)-(?P<slug>.*)$", blog.PostView.as_view(), name="blog_post"),
|
url(r"^post/(?P<id>\d+)-(?P<slug>.*)$", blog.PostView.as_view(), name="blog_post"),
|
||||||
url(r"^license/(?P<key>[-\w.]+)$", license.LicenseDetail.as_view(), name="license"),
|
url(r"^license/(?P<key>[-\w.]+)$", license.LicenseDetail.as_view(), name="license"),
|
||||||
url(
|
url(
|
||||||
|
@ -917,11 +840,6 @@ urlpatterns = [
|
||||||
AssigneeSelect2View.as_view(),
|
AssigneeSelect2View.as_view(),
|
||||||
name="ticket_assignee_select2_ajax",
|
name="ticket_assignee_select2_ajax",
|
||||||
),
|
),
|
||||||
url(
|
|
||||||
r"^problem_authors$",
|
|
||||||
ProblemAuthorSearchSelect2View.as_view(),
|
|
||||||
name="problem_authors_select2_ajax",
|
|
||||||
),
|
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -980,6 +898,19 @@ urlpatterns = [
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
url(
|
||||||
|
r"^feed/",
|
||||||
|
include(
|
||||||
|
[
|
||||||
|
url(r"^problems/rss/$", ProblemFeed(), name="problem_rss"),
|
||||||
|
url(r"^problems/atom/$", AtomProblemFeed(), name="problem_atom"),
|
||||||
|
url(r"^comment/rss/$", CommentFeed(), name="comment_rss"),
|
||||||
|
url(r"^comment/atom/$", AtomCommentFeed(), name="comment_atom"),
|
||||||
|
url(r"^blog/rss/$", BlogFeed(), name="blog_rss"),
|
||||||
|
url(r"^blog/atom/$", AtomBlogFeed(), name="blog_atom"),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
),
|
||||||
url(
|
url(
|
||||||
r"^stats/",
|
r"^stats/",
|
||||||
include(
|
include(
|
||||||
|
@ -1080,6 +1011,9 @@ urlpatterns = [
|
||||||
url(
|
url(
|
||||||
r"^contest/$", ContestSelect2View.as_view(), name="contest_select2"
|
r"^contest/$", ContestSelect2View.as_view(), name="contest_select2"
|
||||||
),
|
),
|
||||||
|
url(
|
||||||
|
r"^comment/$", CommentSelect2View.as_view(), name="comment_select2"
|
||||||
|
),
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -1115,7 +1049,6 @@ urlpatterns = [
|
||||||
name="chat",
|
name="chat",
|
||||||
),
|
),
|
||||||
url(r"^delete/$", chat.delete_message, name="delete_chat_message"),
|
url(r"^delete/$", chat.delete_message, name="delete_chat_message"),
|
||||||
url(r"^mute/$", chat.mute_message, name="mute_chat_message"),
|
|
||||||
url(r"^post/$", chat.post_message, name="post_chat_message"),
|
url(r"^post/$", chat.post_message, name="post_chat_message"),
|
||||||
url(r"^ajax$", chat.chat_message_ajax, name="chat_message_ajax"),
|
url(r"^ajax$", chat.chat_message_ajax, name="chat_message_ajax"),
|
||||||
url(
|
url(
|
||||||
|
@ -1155,37 +1088,13 @@ urlpatterns = [
|
||||||
internal.InternalProblem.as_view(),
|
internal.InternalProblem.as_view(),
|
||||||
name="internal_problem",
|
name="internal_problem",
|
||||||
),
|
),
|
||||||
url(
|
|
||||||
r"^problem_votes$",
|
|
||||||
internal.get_problem_votes,
|
|
||||||
name="internal_problem_votes",
|
|
||||||
),
|
|
||||||
url(
|
|
||||||
r"^request_time$",
|
|
||||||
internal.InternalRequestTime.as_view(),
|
|
||||||
name="internal_request_time",
|
|
||||||
),
|
|
||||||
url(
|
|
||||||
r"^request_time_detail$",
|
|
||||||
internal.InternalRequestTimeDetail.as_view(),
|
|
||||||
name="internal_request_time_detail",
|
|
||||||
),
|
|
||||||
url(
|
|
||||||
r"^internal_slow_request$",
|
|
||||||
internal.InternalSlowRequest.as_view(),
|
|
||||||
name="internal_slow_request",
|
|
||||||
),
|
|
||||||
url(
|
|
||||||
r"^internal_slow_request_detail$",
|
|
||||||
internal.InternalSlowRequestDetail.as_view(),
|
|
||||||
name="internal_slow_request_detail",
|
|
||||||
),
|
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
url(
|
url(
|
||||||
r"^notifications/",
|
r"^notifications/",
|
||||||
paged_list_view(notification.NotificationList, "notification"),
|
login_required(notification.NotificationList.as_view()),
|
||||||
|
name="notification",
|
||||||
),
|
),
|
||||||
url(
|
url(
|
||||||
r"^import_users/",
|
r"^import_users/",
|
||||||
|
@ -1215,7 +1124,6 @@ urlpatterns = [
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
url(r"^resolver/(?P<contest>\w+)", resolver.Resolver.as_view(), name="resolver"),
|
url(r"^resolver/(?P<contest>\w+)", resolver.Resolver.as_view(), name="resolver"),
|
||||||
url(r"^upload/$", custom_file_upload.file_upload, name="custom_file_upload"),
|
|
||||||
] + url_static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
] + url_static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||||
|
|
||||||
# if hasattr(settings, "INTERNAL_IPS"):
|
# if hasattr(settings, "INTERNAL_IPS"):
|
||||||
|
@ -1243,7 +1151,6 @@ favicon_paths = [
|
||||||
"favicon-32x32.png",
|
"favicon-32x32.png",
|
||||||
"favicon-16x16.png",
|
"favicon-16x16.png",
|
||||||
"android-chrome-192x192.png",
|
"android-chrome-192x192.png",
|
||||||
"android-chrome-512x512.png",
|
|
||||||
"android-chrome-48x48.png",
|
"android-chrome-48x48.png",
|
||||||
"mstile-310x150.png",
|
"mstile-310x150.png",
|
||||||
"apple-touch-icon-144x144.png",
|
"apple-touch-icon-144x144.png",
|
||||||
|
|
|
@ -1,14 +1,8 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.contrib.admin.models import LogEntry
|
from django.contrib.admin.models import LogEntry
|
||||||
from django.contrib.auth.models import User
|
|
||||||
|
|
||||||
from judge.admin.comments import CommentAdmin
|
from judge.admin.comments import CommentAdmin
|
||||||
from judge.admin.contest import (
|
from judge.admin.contest import ContestAdmin, ContestParticipationAdmin, ContestTagAdmin
|
||||||
ContestAdmin,
|
|
||||||
ContestParticipationAdmin,
|
|
||||||
ContestTagAdmin,
|
|
||||||
ContestsSummaryAdmin,
|
|
||||||
)
|
|
||||||
from judge.admin.interface import (
|
from judge.admin.interface import (
|
||||||
BlogPostAdmin,
|
BlogPostAdmin,
|
||||||
LicenseAdmin,
|
LicenseAdmin,
|
||||||
|
@ -17,18 +11,12 @@ from judge.admin.interface import (
|
||||||
)
|
)
|
||||||
from judge.admin.organization import OrganizationAdmin, OrganizationRequestAdmin
|
from judge.admin.organization import OrganizationAdmin, OrganizationRequestAdmin
|
||||||
from judge.admin.problem import ProblemAdmin, ProblemPointsVoteAdmin
|
from judge.admin.problem import ProblemAdmin, ProblemPointsVoteAdmin
|
||||||
from judge.admin.profile import ProfileAdmin, UserAdmin
|
from judge.admin.profile import ProfileAdmin
|
||||||
from judge.admin.runtime import JudgeAdmin, LanguageAdmin
|
from judge.admin.runtime import JudgeAdmin, LanguageAdmin
|
||||||
from judge.admin.submission import SubmissionAdmin
|
from judge.admin.submission import SubmissionAdmin
|
||||||
from judge.admin.taxon import (
|
from judge.admin.taxon import ProblemGroupAdmin, ProblemTypeAdmin
|
||||||
ProblemGroupAdmin,
|
|
||||||
ProblemTypeAdmin,
|
|
||||||
OfficialContestCategoryAdmin,
|
|
||||||
OfficialContestLocationAdmin,
|
|
||||||
)
|
|
||||||
from judge.admin.ticket import TicketAdmin
|
from judge.admin.ticket import TicketAdmin
|
||||||
from judge.admin.volunteer import VolunteerProblemVoteAdmin
|
from judge.admin.volunteer import VolunteerProblemVoteAdmin
|
||||||
from judge.admin.course import CourseAdmin
|
|
||||||
from judge.models import (
|
from judge.models import (
|
||||||
BlogPost,
|
BlogPost,
|
||||||
Comment,
|
Comment,
|
||||||
|
@ -52,9 +40,7 @@ from judge.models import (
|
||||||
Ticket,
|
Ticket,
|
||||||
VolunteerProblemVote,
|
VolunteerProblemVote,
|
||||||
Course,
|
Course,
|
||||||
ContestsSummary,
|
course,
|
||||||
OfficialContestCategory,
|
|
||||||
OfficialContestLocation,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -80,9 +66,5 @@ admin.site.register(Profile, ProfileAdmin)
|
||||||
admin.site.register(Submission, SubmissionAdmin)
|
admin.site.register(Submission, SubmissionAdmin)
|
||||||
admin.site.register(Ticket, TicketAdmin)
|
admin.site.register(Ticket, TicketAdmin)
|
||||||
admin.site.register(VolunteerProblemVote, VolunteerProblemVoteAdmin)
|
admin.site.register(VolunteerProblemVote, VolunteerProblemVoteAdmin)
|
||||||
admin.site.register(Course, CourseAdmin)
|
admin.site.register(course.Course)
|
||||||
admin.site.unregister(User)
|
admin.site.register(course.CourseAssignment)
|
||||||
admin.site.register(User, UserAdmin)
|
|
||||||
admin.site.register(ContestsSummary, ContestsSummaryAdmin)
|
|
||||||
admin.site.register(OfficialContestCategory, OfficialContestCategoryAdmin)
|
|
||||||
admin.site.register(OfficialContestLocation, OfficialContestLocationAdmin)
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ class CommentForm(ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
widgets = {
|
widgets = {
|
||||||
"author": AdminHeavySelect2Widget(data_view="profile_select2"),
|
"author": AdminHeavySelect2Widget(data_view="profile_select2"),
|
||||||
|
"parent": AdminHeavySelect2Widget(data_view="comment_select2"),
|
||||||
}
|
}
|
||||||
if HeavyPreviewAdminPageDownWidget is not None:
|
if HeavyPreviewAdminPageDownWidget is not None:
|
||||||
widgets["body"] = HeavyPreviewAdminPageDownWidget(
|
widgets["body"] = HeavyPreviewAdminPageDownWidget(
|
||||||
|
@ -21,24 +22,12 @@ class CommentForm(ModelForm):
|
||||||
|
|
||||||
class CommentAdmin(VersionAdmin):
|
class CommentAdmin(VersionAdmin):
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
(
|
(None, {"fields": ("author", "page", "parent", "score", "hidden")}),
|
||||||
None,
|
|
||||||
{
|
|
||||||
"fields": (
|
|
||||||
"author",
|
|
||||||
"parent",
|
|
||||||
"score",
|
|
||||||
"hidden",
|
|
||||||
"content_type",
|
|
||||||
"object_id",
|
|
||||||
)
|
|
||||||
},
|
|
||||||
),
|
|
||||||
("Content", {"fields": ("body",)}),
|
("Content", {"fields": ("body",)}),
|
||||||
)
|
)
|
||||||
list_display = ["author", "linked_object", "time"]
|
list_display = ["author", "linked_page", "time"]
|
||||||
search_fields = ["author__user__username", "body"]
|
search_fields = ["author__user__username", "page", "body"]
|
||||||
readonly_fields = ["score", "parent"]
|
readonly_fields = ["score"]
|
||||||
actions = ["hide_comment", "unhide_comment"]
|
actions = ["hide_comment", "unhide_comment"]
|
||||||
list_filter = ["hidden"]
|
list_filter = ["hidden"]
|
||||||
actions_on_top = True
|
actions_on_top = True
|
||||||
|
@ -77,6 +66,16 @@ class CommentAdmin(VersionAdmin):
|
||||||
|
|
||||||
unhide_comment.short_description = _("Unhide comments")
|
unhide_comment.short_description = _("Unhide comments")
|
||||||
|
|
||||||
|
def linked_page(self, obj):
|
||||||
|
link = obj.link
|
||||||
|
if link is not None:
|
||||||
|
return format_html('<a href="{0}">{1}</a>', link, obj.page)
|
||||||
|
else:
|
||||||
|
return format_html("{0}", obj.page)
|
||||||
|
|
||||||
|
linked_page.short_description = _("Associated page")
|
||||||
|
linked_page.admin_order_field = "page"
|
||||||
|
|
||||||
def save_model(self, request, obj, form, change):
|
def save_model(self, request, obj, form, change):
|
||||||
super(CommentAdmin, self).save_model(request, obj, form, change)
|
super(CommentAdmin, self).save_model(request, obj, form, change)
|
||||||
if obj.hidden:
|
if obj.hidden:
|
||||||
|
|
|
@ -14,14 +14,7 @@ from reversion.admin import VersionAdmin
|
||||||
from reversion_compare.admin import CompareVersionAdmin
|
from reversion_compare.admin import CompareVersionAdmin
|
||||||
|
|
||||||
from django_ace import AceWidget
|
from django_ace import AceWidget
|
||||||
from judge.models import (
|
from judge.models import Contest, ContestProblem, ContestSubmission, Profile, Rating
|
||||||
Contest,
|
|
||||||
ContestProblem,
|
|
||||||
ContestSubmission,
|
|
||||||
Profile,
|
|
||||||
Rating,
|
|
||||||
OfficialContest,
|
|
||||||
)
|
|
||||||
from judge.ratings import rate_contest
|
from judge.ratings import rate_contest
|
||||||
from judge.widgets import (
|
from judge.widgets import (
|
||||||
AdminHeavySelect2MultipleWidget,
|
AdminHeavySelect2MultipleWidget,
|
||||||
|
@ -31,8 +24,6 @@ from judge.widgets import (
|
||||||
AdminSelect2Widget,
|
AdminSelect2Widget,
|
||||||
HeavyPreviewAdminPageDownWidget,
|
HeavyPreviewAdminPageDownWidget,
|
||||||
)
|
)
|
||||||
from judge.views.contests import recalculate_contest_summary_result
|
|
||||||
from judge.utils.contest import maybe_trigger_contest_rescore
|
|
||||||
|
|
||||||
|
|
||||||
class AdminHeavySelect2Widget(AdminHeavySelect2Widget):
|
class AdminHeavySelect2Widget(AdminHeavySelect2Widget):
|
||||||
|
@ -80,6 +71,7 @@ class ContestProblemInlineForm(ModelForm):
|
||||||
"hidden_subtasks": TextInput(attrs={"size": "3"}),
|
"hidden_subtasks": TextInput(attrs={"size": "3"}),
|
||||||
"points": TextInput(attrs={"size": "1"}),
|
"points": TextInput(attrs={"size": "1"}),
|
||||||
"order": TextInput(attrs={"size": "1"}),
|
"order": TextInput(attrs={"size": "1"}),
|
||||||
|
"output_prefix_override": TextInput(attrs={"size": "1"}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -94,7 +86,7 @@ class ContestProblemInline(admin.TabularInline):
|
||||||
"is_pretested",
|
"is_pretested",
|
||||||
"max_submissions",
|
"max_submissions",
|
||||||
"hidden_subtasks",
|
"hidden_subtasks",
|
||||||
"show_testcases",
|
"output_prefix_override",
|
||||||
"order",
|
"order",
|
||||||
"rejudge_column",
|
"rejudge_column",
|
||||||
)
|
)
|
||||||
|
@ -157,26 +149,6 @@ class ContestForm(ModelForm):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class OfficialContestInlineForm(ModelForm):
|
|
||||||
class Meta:
|
|
||||||
widgets = {
|
|
||||||
"category": AdminSelect2Widget,
|
|
||||||
"location": AdminSelect2Widget,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class OfficialContestInline(admin.StackedInline):
|
|
||||||
fields = (
|
|
||||||
"category",
|
|
||||||
"year",
|
|
||||||
"location",
|
|
||||||
)
|
|
||||||
model = OfficialContest
|
|
||||||
can_delete = True
|
|
||||||
form = OfficialContestInlineForm
|
|
||||||
extra = 0
|
|
||||||
|
|
||||||
|
|
||||||
class ContestAdmin(CompareVersionAdmin):
|
class ContestAdmin(CompareVersionAdmin):
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
(None, {"fields": ("key", "name", "authors", "curators", "testers")}),
|
(None, {"fields": ("key", "name", "authors", "curators", "testers")}),
|
||||||
|
@ -187,11 +159,9 @@ class ContestAdmin(CompareVersionAdmin):
|
||||||
"is_visible",
|
"is_visible",
|
||||||
"use_clarifications",
|
"use_clarifications",
|
||||||
"hide_problem_tags",
|
"hide_problem_tags",
|
||||||
"public_scoreboard",
|
|
||||||
"scoreboard_visibility",
|
"scoreboard_visibility",
|
||||||
"run_pretests_only",
|
"run_pretests_only",
|
||||||
"points_precision",
|
"points_precision",
|
||||||
"rate_limit",
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
@ -251,7 +221,7 @@ class ContestAdmin(CompareVersionAdmin):
|
||||||
"user_count",
|
"user_count",
|
||||||
)
|
)
|
||||||
search_fields = ("key", "name")
|
search_fields = ("key", "name")
|
||||||
inlines = [ContestProblemInline, OfficialContestInline]
|
inlines = [ContestProblemInline]
|
||||||
actions_on_top = True
|
actions_on_top = True
|
||||||
actions_on_bottom = True
|
actions_on_bottom = True
|
||||||
form = ContestForm
|
form = ContestForm
|
||||||
|
@ -311,14 +281,31 @@ class ContestAdmin(CompareVersionAdmin):
|
||||||
|
|
||||||
super().save_model(request, obj, form, change)
|
super().save_model(request, obj, form, change)
|
||||||
|
|
||||||
|
# We need this flag because `save_related` deals with the inlines, but does not know if we have already rescored
|
||||||
|
self._rescored = False
|
||||||
|
if form.changed_data and any(
|
||||||
|
f in form.changed_data
|
||||||
|
for f in (
|
||||||
|
"start_time",
|
||||||
|
"end_time",
|
||||||
|
"time_limit",
|
||||||
|
"format_config",
|
||||||
|
"format_name",
|
||||||
|
"freeze_after",
|
||||||
|
)
|
||||||
|
):
|
||||||
|
self._rescore(obj.key)
|
||||||
|
self._rescored = True
|
||||||
|
|
||||||
def save_related(self, request, form, formsets, change):
|
def save_related(self, request, form, formsets, change):
|
||||||
super().save_related(request, form, formsets, change)
|
super().save_related(request, form, formsets, change)
|
||||||
# Only rescored if we did not already do so in `save_model`
|
# Only rescored if we did not already do so in `save_model`
|
||||||
formset_changed = False
|
if not self._rescored and any(formset.has_changed() for formset in formsets):
|
||||||
if any(formset.has_changed() for formset in formsets):
|
self._rescore(form.cleaned_data["key"])
|
||||||
formset_changed = True
|
obj = form.instance
|
||||||
|
obj.is_organization_private = obj.organizations.count() > 0
|
||||||
maybe_trigger_contest_rescore(form, form.instance, formset_changed)
|
obj.is_private = obj.private_contestants.count() > 0
|
||||||
|
obj.save()
|
||||||
|
|
||||||
def has_change_permission(self, request, obj=None):
|
def has_change_permission(self, request, obj=None):
|
||||||
if not request.user.has_perm("judge.edit_own_contest"):
|
if not request.user.has_perm("judge.edit_own_contest"):
|
||||||
|
@ -327,6 +314,11 @@ class ContestAdmin(CompareVersionAdmin):
|
||||||
return True
|
return True
|
||||||
return obj.is_editable_by(request.user)
|
return obj.is_editable_by(request.user)
|
||||||
|
|
||||||
|
def _rescore(self, contest_key):
|
||||||
|
from judge.tasks import rescore_contest
|
||||||
|
|
||||||
|
transaction.on_commit(rescore_contest.s(contest_key).delay)
|
||||||
|
|
||||||
def make_visible(self, request, queryset):
|
def make_visible(self, request, queryset):
|
||||||
if not request.user.has_perm("judge.change_contest_visibility"):
|
if not request.user.has_perm("judge.change_contest_visibility"):
|
||||||
queryset = queryset.filter(
|
queryset = queryset.filter(
|
||||||
|
@ -510,25 +502,3 @@ class ContestParticipationAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
show_virtual.short_description = _("virtual")
|
show_virtual.short_description = _("virtual")
|
||||||
show_virtual.admin_order_field = "virtual"
|
show_virtual.admin_order_field = "virtual"
|
||||||
|
|
||||||
|
|
||||||
class ContestsSummaryForm(ModelForm):
|
|
||||||
class Meta:
|
|
||||||
widgets = {
|
|
||||||
"contests": AdminHeavySelect2MultipleWidget(
|
|
||||||
data_view="contest_select2", attrs={"style": "width: 100%"}
|
|
||||||
),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class ContestsSummaryAdmin(admin.ModelAdmin):
|
|
||||||
fields = ("key", "contests", "scores")
|
|
||||||
list_display = ("key",)
|
|
||||||
search_fields = ("key", "contests__key")
|
|
||||||
form = ContestsSummaryForm
|
|
||||||
|
|
||||||
def save_model(self, request, obj, form, change):
|
|
||||||
super(ContestsSummaryAdmin, self).save_model(request, obj, form, change)
|
|
||||||
obj.refresh_from_db()
|
|
||||||
obj.results = recalculate_contest_summary_result(request, obj)
|
|
||||||
obj.save()
|
|
||||||
|
|
|
@ -1,52 +0,0 @@
|
||||||
from django.contrib import admin
|
|
||||||
from django.utils.html import format_html
|
|
||||||
from django.urls import reverse, reverse_lazy
|
|
||||||
from django.utils.translation import gettext, gettext_lazy as _, ungettext
|
|
||||||
from django.forms import ModelForm
|
|
||||||
|
|
||||||
from judge.models import Course, CourseRole
|
|
||||||
from judge.widgets import AdminSelect2MultipleWidget
|
|
||||||
from judge.widgets import (
|
|
||||||
AdminHeavySelect2MultipleWidget,
|
|
||||||
AdminHeavySelect2Widget,
|
|
||||||
HeavyPreviewAdminPageDownWidget,
|
|
||||||
AdminSelect2Widget,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class CourseRoleInlineForm(ModelForm):
|
|
||||||
class Meta:
|
|
||||||
widgets = {
|
|
||||||
"user": AdminHeavySelect2Widget(
|
|
||||||
data_view="profile_select2", attrs={"style": "width: 100%"}
|
|
||||||
),
|
|
||||||
"role": AdminSelect2Widget,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class CourseRoleInline(admin.TabularInline):
|
|
||||||
model = CourseRole
|
|
||||||
extra = 1
|
|
||||||
form = CourseRoleInlineForm
|
|
||||||
|
|
||||||
|
|
||||||
class CourseForm(ModelForm):
|
|
||||||
class Meta:
|
|
||||||
widgets = {
|
|
||||||
"organizations": AdminHeavySelect2MultipleWidget(
|
|
||||||
data_view="organization_select2"
|
|
||||||
),
|
|
||||||
"about": HeavyPreviewAdminPageDownWidget(
|
|
||||||
preview=reverse_lazy("blog_preview")
|
|
||||||
),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class CourseAdmin(admin.ModelAdmin):
|
|
||||||
prepopulated_fields = {"slug": ("name",)}
|
|
||||||
inlines = [
|
|
||||||
CourseRoleInline,
|
|
||||||
]
|
|
||||||
list_display = ("name", "is_public", "is_open")
|
|
||||||
search_fields = ("name",)
|
|
||||||
form = CourseForm
|
|
|
@ -53,7 +53,6 @@ class NavigationBarAdmin(DraggableMPTTAdmin):
|
||||||
class BlogPostForm(ModelForm):
|
class BlogPostForm(ModelForm):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(BlogPostForm, self).__init__(*args, **kwargs)
|
super(BlogPostForm, self).__init__(*args, **kwargs)
|
||||||
if "authors" in self.fields:
|
|
||||||
self.fields["authors"].widget.can_add_related = False
|
self.fields["authors"].widget.can_add_related = False
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
@ -33,6 +33,7 @@ class OrganizationAdmin(VersionAdmin):
|
||||||
"short_name",
|
"short_name",
|
||||||
"is_open",
|
"is_open",
|
||||||
"about",
|
"about",
|
||||||
|
"logo_override_image",
|
||||||
"slots",
|
"slots",
|
||||||
"registrant",
|
"registrant",
|
||||||
"creation_date",
|
"creation_date",
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
from operator import attrgetter
|
from operator import attrgetter
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib import admin, messages
|
from django.contrib import admin
|
||||||
from django.db import transaction, IntegrityError
|
from django.db import transaction
|
||||||
from django.db.models import Q, Avg, Count
|
from django.db.models import Q, Avg, Count
|
||||||
from django.db.models.aggregates import StdDev
|
from django.db.models.aggregates import StdDev
|
||||||
from django.forms import ModelForm, TextInput
|
from django.forms import ModelForm, TextInput
|
||||||
|
@ -11,7 +11,6 @@ from django.utils.html import format_html
|
||||||
from django.utils.translation import gettext, gettext_lazy as _, ungettext
|
from django.utils.translation import gettext, gettext_lazy as _, ungettext
|
||||||
from django_ace import AceWidget
|
from django_ace import AceWidget
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.core.exceptions import ValidationError
|
|
||||||
|
|
||||||
from reversion.admin import VersionAdmin
|
from reversion.admin import VersionAdmin
|
||||||
from reversion_compare.admin import CompareVersionAdmin
|
from reversion_compare.admin import CompareVersionAdmin
|
||||||
|
@ -26,7 +25,6 @@ from judge.models import (
|
||||||
Solution,
|
Solution,
|
||||||
Notification,
|
Notification,
|
||||||
)
|
)
|
||||||
from judge.models.notification import make_notification
|
|
||||||
from judge.widgets import (
|
from judge.widgets import (
|
||||||
AdminHeavySelect2MultipleWidget,
|
AdminHeavySelect2MultipleWidget,
|
||||||
AdminSelect2MultipleWidget,
|
AdminSelect2MultipleWidget,
|
||||||
|
@ -34,7 +32,6 @@ from judge.widgets import (
|
||||||
CheckboxSelectMultipleWithSelectAll,
|
CheckboxSelectMultipleWithSelectAll,
|
||||||
HeavyPreviewAdminPageDownWidget,
|
HeavyPreviewAdminPageDownWidget,
|
||||||
)
|
)
|
||||||
from judge.utils.problems import user_editable_ids, user_tester_ids
|
|
||||||
|
|
||||||
MEMORY_UNITS = (("KB", "KB"), ("MB", "MB"))
|
MEMORY_UNITS = (("KB", "KB"), ("MB", "MB"))
|
||||||
|
|
||||||
|
@ -57,16 +54,6 @@ class ProblemForm(ModelForm):
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
def clean_code(self):
|
|
||||||
code = self.cleaned_data.get("code")
|
|
||||||
if self.instance.pk:
|
|
||||||
return code
|
|
||||||
|
|
||||||
if Problem.objects.filter(code=code).exists():
|
|
||||||
raise ValidationError(_("A problem with this code already exists."))
|
|
||||||
|
|
||||||
return code
|
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
memory_unit = self.cleaned_data.get("memory_unit", "KB")
|
memory_unit = self.cleaned_data.get("memory_unit", "KB")
|
||||||
if memory_unit == "MB":
|
if memory_unit == "MB":
|
||||||
|
@ -142,7 +129,6 @@ class LanguageLimitInline(admin.TabularInline):
|
||||||
model = LanguageLimit
|
model = LanguageLimit
|
||||||
fields = ("language", "time_limit", "memory_limit", "memory_unit")
|
fields = ("language", "time_limit", "memory_limit", "memory_unit")
|
||||||
form = LanguageLimitInlineForm
|
form = LanguageLimitInlineForm
|
||||||
extra = 0
|
|
||||||
|
|
||||||
|
|
||||||
class LanguageTemplateInlineForm(ModelForm):
|
class LanguageTemplateInlineForm(ModelForm):
|
||||||
|
@ -157,7 +143,6 @@ class LanguageTemplateInline(admin.TabularInline):
|
||||||
model = LanguageTemplate
|
model = LanguageTemplate
|
||||||
fields = ("language", "source")
|
fields = ("language", "source")
|
||||||
form = LanguageTemplateInlineForm
|
form = LanguageTemplateInlineForm
|
||||||
extra = 0
|
|
||||||
|
|
||||||
|
|
||||||
class ProblemSolutionForm(ModelForm):
|
class ProblemSolutionForm(ModelForm):
|
||||||
|
@ -373,29 +358,12 @@ class ProblemAdmin(CompareVersionAdmin):
|
||||||
self._rescore(request, obj.id)
|
self._rescore(request, obj.id)
|
||||||
|
|
||||||
def save_related(self, request, form, formsets, change):
|
def save_related(self, request, form, formsets, change):
|
||||||
editors = set()
|
|
||||||
testers = set()
|
|
||||||
if "curators" in form.changed_data or "authors" in form.changed_data:
|
|
||||||
editors = set(form.instance.editor_ids)
|
|
||||||
if "testers" in form.changed_data:
|
|
||||||
testers = set(form.instance.tester_ids)
|
|
||||||
|
|
||||||
super().save_related(request, form, formsets, change)
|
super().save_related(request, form, formsets, change)
|
||||||
|
# Only rescored if we did not already do so in `save_model`
|
||||||
obj = form.instance
|
obj = form.instance
|
||||||
obj.curators.add(request.profile)
|
obj.curators.add(request.profile)
|
||||||
|
obj.is_organization_private = obj.organizations.count() > 0
|
||||||
if "curators" in form.changed_data or "authors" in form.changed_data:
|
obj.save()
|
||||||
del obj.editor_ids
|
|
||||||
editors = editors.union(set(obj.editor_ids))
|
|
||||||
if "testers" in form.changed_data:
|
|
||||||
del obj.tester_ids
|
|
||||||
testers = testers.union(set(obj.tester_ids))
|
|
||||||
|
|
||||||
for editor in editors:
|
|
||||||
user_editable_ids.dirty(editor)
|
|
||||||
for tester in testers:
|
|
||||||
user_tester_ids.dirty(tester)
|
|
||||||
|
|
||||||
# Create notification
|
# Create notification
|
||||||
if "is_public" in form.changed_data or "organizations" in form.changed_data:
|
if "is_public" in form.changed_data or "organizations" in form.changed_data:
|
||||||
users = set(obj.authors.all())
|
users = set(obj.authors.all())
|
||||||
|
@ -413,7 +381,14 @@ class ProblemAdmin(CompareVersionAdmin):
|
||||||
category = "Problem public: " + str(obj.is_public)
|
category = "Problem public: " + str(obj.is_public)
|
||||||
if orgs:
|
if orgs:
|
||||||
category += " (" + ", ".join(orgs) + ")"
|
category += " (" + ", ".join(orgs) + ")"
|
||||||
make_notification(users, category, html, request.profile)
|
for user in users:
|
||||||
|
notification = Notification(
|
||||||
|
owner=user,
|
||||||
|
html_link=html,
|
||||||
|
category=category,
|
||||||
|
author=request.profile,
|
||||||
|
)
|
||||||
|
notification.save()
|
||||||
|
|
||||||
def construct_change_message(self, request, form, *args, **kwargs):
|
def construct_change_message(self, request, form, *args, **kwargs):
|
||||||
if form.cleaned_data.get("change_message"):
|
if form.cleaned_data.get("change_message"):
|
||||||
|
|
|
@ -1,19 +1,12 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.forms import ModelForm, CharField, TextInput
|
from django.forms import ModelForm
|
||||||
from django.utils.html import format_html
|
from django.utils.html import format_html
|
||||||
from django.utils.translation import gettext, gettext_lazy as _, ungettext
|
from django.utils.translation import gettext, gettext_lazy as _, ungettext
|
||||||
from django.contrib.auth.admin import UserAdmin as OldUserAdmin
|
|
||||||
from django.core.exceptions import ValidationError
|
|
||||||
from django.contrib.auth.forms import UserChangeForm
|
|
||||||
|
|
||||||
from django_ace import AceWidget
|
|
||||||
|
|
||||||
from judge.models import Profile, ProfileInfo
|
|
||||||
from judge.widgets import AdminPagedownWidget, AdminSelect2Widget
|
|
||||||
|
|
||||||
from reversion.admin import VersionAdmin
|
from reversion.admin import VersionAdmin
|
||||||
|
|
||||||
import re
|
from django_ace import AceWidget
|
||||||
|
from judge.models import Profile
|
||||||
|
from judge.widgets import AdminPagedownWidget, AdminSelect2Widget
|
||||||
|
|
||||||
|
|
||||||
class ProfileForm(ModelForm):
|
class ProfileForm(ModelForm):
|
||||||
|
@ -60,13 +53,6 @@ class TimezoneFilter(admin.SimpleListFilter):
|
||||||
return queryset.filter(timezone=self.value())
|
return queryset.filter(timezone=self.value())
|
||||||
|
|
||||||
|
|
||||||
class ProfileInfoInline(admin.StackedInline):
|
|
||||||
model = ProfileInfo
|
|
||||||
can_delete = False
|
|
||||||
verbose_name_plural = "profile info"
|
|
||||||
fk_name = "profile"
|
|
||||||
|
|
||||||
|
|
||||||
class ProfileAdmin(VersionAdmin):
|
class ProfileAdmin(VersionAdmin):
|
||||||
fields = (
|
fields = (
|
||||||
"user",
|
"user",
|
||||||
|
@ -76,12 +62,15 @@ class ProfileAdmin(VersionAdmin):
|
||||||
"timezone",
|
"timezone",
|
||||||
"language",
|
"language",
|
||||||
"ace_theme",
|
"ace_theme",
|
||||||
|
"math_engine",
|
||||||
"last_access",
|
"last_access",
|
||||||
"ip",
|
"ip",
|
||||||
"mute",
|
"mute",
|
||||||
"is_unlisted",
|
"is_unlisted",
|
||||||
|
"is_banned_problem_voting",
|
||||||
"notes",
|
"notes",
|
||||||
"is_totp_enabled",
|
"is_totp_enabled",
|
||||||
|
"user_script",
|
||||||
"current_contest",
|
"current_contest",
|
||||||
)
|
)
|
||||||
readonly_fields = ("user",)
|
readonly_fields = ("user",)
|
||||||
|
@ -102,7 +91,6 @@ class ProfileAdmin(VersionAdmin):
|
||||||
actions_on_top = True
|
actions_on_top = True
|
||||||
actions_on_bottom = True
|
actions_on_bottom = True
|
||||||
form = ProfileForm
|
form = ProfileForm
|
||||||
inlines = (ProfileInfoInline,)
|
|
||||||
|
|
||||||
def get_queryset(self, request):
|
def get_queryset(self, request):
|
||||||
return super(ProfileAdmin, self).get_queryset(request).select_related("user")
|
return super(ProfileAdmin, self).get_queryset(request).select_related("user")
|
||||||
|
@ -137,7 +125,7 @@ class ProfileAdmin(VersionAdmin):
|
||||||
admin_user_admin.short_description = _("User")
|
admin_user_admin.short_description = _("User")
|
||||||
|
|
||||||
def email(self, obj):
|
def email(self, obj):
|
||||||
return obj.email
|
return obj.user.email
|
||||||
|
|
||||||
email.admin_order_field = "user__email"
|
email.admin_order_field = "user__email"
|
||||||
email.short_description = _("Email")
|
email.short_description = _("Email")
|
||||||
|
@ -171,57 +159,11 @@ class ProfileAdmin(VersionAdmin):
|
||||||
|
|
||||||
recalculate_points.short_description = _("Recalculate scores")
|
recalculate_points.short_description = _("Recalculate scores")
|
||||||
|
|
||||||
|
def get_form(self, request, obj=None, **kwargs):
|
||||||
class UserForm(UserChangeForm):
|
form = super(ProfileAdmin, self).get_form(request, obj, **kwargs)
|
||||||
def __init__(self, *args, **kwargs):
|
if "user_script" in form.base_fields:
|
||||||
super().__init__(*args, **kwargs)
|
# form.base_fields['user_script'] does not exist when the user has only view permission on the model.
|
||||||
self.fields["username"].help_text = _(
|
form.base_fields["user_script"].widget = AceWidget(
|
||||||
"Username can only contain letters, digits, and underscores."
|
"javascript", request.profile.ace_theme
|
||||||
)
|
)
|
||||||
|
return form
|
||||||
def clean_username(self):
|
|
||||||
username = self.cleaned_data.get("username")
|
|
||||||
if not re.match(r"^\w+$", username):
|
|
||||||
raise ValidationError(
|
|
||||||
_("Username can only contain letters, digits, and underscores.")
|
|
||||||
)
|
|
||||||
return username
|
|
||||||
|
|
||||||
|
|
||||||
class UserAdmin(OldUserAdmin):
|
|
||||||
# Customize the fieldsets for adding and editing users
|
|
||||||
form = UserForm
|
|
||||||
fieldsets = (
|
|
||||||
(None, {"fields": ("username", "password")}),
|
|
||||||
("Personal Info", {"fields": ("first_name", "last_name", "email")}),
|
|
||||||
(
|
|
||||||
"Permissions",
|
|
||||||
{
|
|
||||||
"fields": (
|
|
||||||
"is_active",
|
|
||||||
"is_staff",
|
|
||||||
"is_superuser",
|
|
||||||
"groups",
|
|
||||||
"user_permissions",
|
|
||||||
)
|
|
||||||
},
|
|
||||||
),
|
|
||||||
("Important dates", {"fields": ("last_login", "date_joined")}),
|
|
||||||
)
|
|
||||||
|
|
||||||
readonly_fields = ("last_login", "date_joined")
|
|
||||||
|
|
||||||
def get_readonly_fields(self, request, obj=None):
|
|
||||||
fields = self.readonly_fields
|
|
||||||
if not request.user.is_superuser:
|
|
||||||
fields += (
|
|
||||||
"is_staff",
|
|
||||||
"is_active",
|
|
||||||
"is_superuser",
|
|
||||||
"groups",
|
|
||||||
"user_permissions",
|
|
||||||
)
|
|
||||||
return fields
|
|
||||||
|
|
||||||
def has_add_permission(self, request):
|
|
||||||
return False
|
|
||||||
|
|
|
@ -194,16 +194,18 @@ class SubmissionAdmin(admin.ModelAdmin):
|
||||||
def has_add_permission(self, request):
|
def has_add_permission(self, request):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def has_change_permission(self, request, obj=None):
|
||||||
|
if not request.user.has_perm("judge.edit_own_problem"):
|
||||||
|
return False
|
||||||
|
if request.user.has_perm("judge.edit_all_problem") or obj is None:
|
||||||
|
return True
|
||||||
|
return obj.problem.is_editor(request.profile)
|
||||||
|
|
||||||
def lookup_allowed(self, key, value):
|
def lookup_allowed(self, key, value):
|
||||||
return super(SubmissionAdmin, self).lookup_allowed(key, value) or key in (
|
return super(SubmissionAdmin, self).lookup_allowed(key, value) or key in (
|
||||||
"problem__code",
|
"problem__code",
|
||||||
)
|
)
|
||||||
|
|
||||||
def save_model(self, request, obj, form, change):
|
|
||||||
super().save_model(request, obj, form, change)
|
|
||||||
if "case_points" in form.changed_data or "case_total" in form.changed_data:
|
|
||||||
obj.update_contest()
|
|
||||||
|
|
||||||
def judge(self, request, queryset):
|
def judge(self, request, queryset):
|
||||||
if not request.user.has_perm(
|
if not request.user.has_perm(
|
||||||
"judge.rejudge_submission"
|
"judge.rejudge_submission"
|
||||||
|
|
|
@ -56,11 +56,3 @@ class ProblemTypeAdmin(admin.ModelAdmin):
|
||||||
[o.pk for o in obj.problem_set.all()] if obj else []
|
[o.pk for o in obj.problem_set.all()] if obj else []
|
||||||
)
|
)
|
||||||
return super(ProblemTypeAdmin, self).get_form(request, obj, **kwargs)
|
return super(ProblemTypeAdmin, self).get_form(request, obj, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class OfficialContestCategoryAdmin(admin.ModelAdmin):
|
|
||||||
fields = ("name",)
|
|
||||||
|
|
||||||
|
|
||||||
class OfficialContestLocationAdmin(admin.ModelAdmin):
|
|
||||||
fields = ("name",)
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ class JudgeAppConfig(AppConfig):
|
||||||
# OPERATIONS MAY HAVE SIDE EFFECTS.
|
# OPERATIONS MAY HAVE SIDE EFFECTS.
|
||||||
# DO NOT REMOVE THINKING THE IMPORT IS UNUSED.
|
# DO NOT REMOVE THINKING THE IMPORT IS UNUSED.
|
||||||
# noinspection PyUnresolvedReferences
|
# noinspection PyUnresolvedReferences
|
||||||
from . import models, signals, jinja2 # noqa: F401, imported for side effects
|
from . import signals, jinja2 # noqa: F401, imported for side effects
|
||||||
|
|
||||||
from django.contrib.flatpages.models import FlatPage
|
from django.contrib.flatpages.models import FlatPage
|
||||||
from django.contrib.flatpages.admin import FlatPageAdmin
|
from django.contrib.flatpages.admin import FlatPageAdmin
|
||||||
|
|
|
@ -1,48 +0,0 @@
|
||||||
from django.contrib.auth.backends import ModelBackend
|
|
||||||
from django.contrib.auth.models import User
|
|
||||||
from django.contrib.auth.forms import PasswordChangeForm
|
|
||||||
from django.contrib.auth.views import PasswordChangeView
|
|
||||||
from django.urls import reverse_lazy
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class CustomModelBackend(ModelBackend):
|
|
||||||
def authenticate(self, request, username=None, password=None, **kwargs):
|
|
||||||
try:
|
|
||||||
# Check if the username is an email
|
|
||||||
user = User.objects.get(username=username)
|
|
||||||
except User.DoesNotExist:
|
|
||||||
# If the username is not an email, try authenticating with the username field
|
|
||||||
user = User.objects.filter(email=username).first()
|
|
||||||
|
|
||||||
if user and user.check_password(password):
|
|
||||||
return user
|
|
||||||
|
|
||||||
|
|
||||||
class CustomPasswordChangeForm(PasswordChangeForm):
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
super(CustomPasswordChangeForm, self).__init__(*args, **kwargs)
|
|
||||||
if not self.user.has_usable_password():
|
|
||||||
self.fields.pop("old_password")
|
|
||||||
|
|
||||||
def clean_old_password(self):
|
|
||||||
if "old_password" not in self.cleaned_data:
|
|
||||||
return
|
|
||||||
return super(CustomPasswordChangeForm, self).clean_old_password()
|
|
||||||
|
|
||||||
def clean(self):
|
|
||||||
cleaned_data = super(CustomPasswordChangeForm, self).clean()
|
|
||||||
if "old_password" not in self.cleaned_data and not self.errors:
|
|
||||||
cleaned_data["old_password"] = ""
|
|
||||||
return cleaned_data
|
|
||||||
|
|
||||||
|
|
||||||
class CustomPasswordChangeView(PasswordChangeView):
|
|
||||||
form_class = CustomPasswordChangeForm
|
|
||||||
success_url = reverse_lazy("password_change_done")
|
|
||||||
template_name = "registration/password_change_form.html"
|
|
||||||
|
|
||||||
def get_form_kwargs(self):
|
|
||||||
kwargs = super(CustomPasswordChangeView, self).get_form_kwargs()
|
|
||||||
kwargs["user"] = self.request.user
|
|
||||||
return kwargs
|
|
|
@ -10,11 +10,10 @@ from django import db
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.db.models import F
|
from django.db.models import F
|
||||||
from django.core.cache import cache
|
|
||||||
|
|
||||||
from judge import event_poster as event
|
from judge import event_poster as event
|
||||||
from judge.bridge.base_handler import ZlibPacketHandler, proxy_list
|
from judge.bridge.base_handler import ZlibPacketHandler, proxy_list
|
||||||
from judge.utils.problems import finished_submission
|
from judge.caching import finished_submission
|
||||||
from judge.models import (
|
from judge.models import (
|
||||||
Judge,
|
Judge,
|
||||||
Language,
|
Language,
|
||||||
|
@ -24,8 +23,6 @@ from judge.models import (
|
||||||
Submission,
|
Submission,
|
||||||
SubmissionTestCase,
|
SubmissionTestCase,
|
||||||
)
|
)
|
||||||
from judge.bridge.utils import VanishedSubmission
|
|
||||||
from judge.caching import cache_wrapper
|
|
||||||
|
|
||||||
logger = logging.getLogger("judge.bridge")
|
logger = logging.getLogger("judge.bridge")
|
||||||
json_log = logging.getLogger("judge.json.bridge")
|
json_log = logging.getLogger("judge.json.bridge")
|
||||||
|
@ -65,10 +62,10 @@ class JudgeHandler(ZlibPacketHandler):
|
||||||
"handshake": self.on_handshake,
|
"handshake": self.on_handshake,
|
||||||
}
|
}
|
||||||
self._working = False
|
self._working = False
|
||||||
self._working_data = {}
|
|
||||||
self._no_response_job = None
|
self._no_response_job = None
|
||||||
|
self._problems = []
|
||||||
self.executors = {}
|
self.executors = {}
|
||||||
self.problems = set()
|
self.problems = {}
|
||||||
self.latency = None
|
self.latency = None
|
||||||
self.time_delta = None
|
self.time_delta = None
|
||||||
self.load = 1e100
|
self.load = 1e100
|
||||||
|
@ -94,6 +91,12 @@ class JudgeHandler(ZlibPacketHandler):
|
||||||
|
|
||||||
def on_disconnect(self):
|
def on_disconnect(self):
|
||||||
self._stop_ping.set()
|
self._stop_ping.set()
|
||||||
|
if self._working:
|
||||||
|
logger.error(
|
||||||
|
"Judge %s disconnected while handling submission %s",
|
||||||
|
self.name,
|
||||||
|
self._working,
|
||||||
|
)
|
||||||
self.judges.remove(self)
|
self.judges.remove(self)
|
||||||
if self.name is not None:
|
if self.name is not None:
|
||||||
self._disconnected()
|
self._disconnected()
|
||||||
|
@ -105,29 +108,21 @@ class JudgeHandler(ZlibPacketHandler):
|
||||||
self._make_json_log(action="disconnect", info="judge disconnected")
|
self._make_json_log(action="disconnect", info="judge disconnected")
|
||||||
)
|
)
|
||||||
if self._working:
|
if self._working:
|
||||||
self.judges.judge(
|
Submission.objects.filter(id=self._working).update(
|
||||||
self._working,
|
status="IE", result="IE", error=""
|
||||||
self._working_data["problem"],
|
)
|
||||||
self._working_data["language"],
|
json_log.error(
|
||||||
self._working_data["source"],
|
self._make_json_log(
|
||||||
None,
|
sub=self._working,
|
||||||
0,
|
action="close",
|
||||||
|
info="IE due to shutdown on grading",
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def _authenticate(self, id, key):
|
def _authenticate(self, id, key):
|
||||||
try:
|
try:
|
||||||
judge = Judge.objects.get(name=id)
|
judge = Judge.objects.get(name=id, is_blocked=False)
|
||||||
except Judge.DoesNotExist:
|
except Judge.DoesNotExist:
|
||||||
if settings.BRIDGED_AUTO_CREATE_JUDGE:
|
|
||||||
judge = Judge()
|
|
||||||
judge.name = id
|
|
||||||
judge.auth_key = key
|
|
||||||
judge.save()
|
|
||||||
result = True
|
|
||||||
else:
|
|
||||||
result = False
|
|
||||||
else:
|
|
||||||
if judge.is_blocked:
|
|
||||||
result = False
|
result = False
|
||||||
else:
|
else:
|
||||||
result = hmac.compare_digest(judge.auth_key, key)
|
result = hmac.compare_digest(judge.auth_key, key)
|
||||||
|
@ -140,52 +135,11 @@ class JudgeHandler(ZlibPacketHandler):
|
||||||
)
|
)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _update_supported_problems(self, problem_packet):
|
|
||||||
# problem_packet is a dict {code: mtimes} from judge-server
|
|
||||||
self.problems = set(p for p, _ in problem_packet)
|
|
||||||
|
|
||||||
def _update_judge_problems(self):
|
|
||||||
chunk_size = 500
|
|
||||||
|
|
||||||
target_problem_codes = self.problems
|
|
||||||
current_problems = _get_judge_problems(self.judge)
|
|
||||||
|
|
||||||
updated = False
|
|
||||||
problems_to_add = list(target_problem_codes - current_problems)
|
|
||||||
problems_to_remove = list(current_problems - target_problem_codes)
|
|
||||||
|
|
||||||
if problems_to_add:
|
|
||||||
for i in range(0, len(problems_to_add), chunk_size):
|
|
||||||
chunk = problems_to_add[i : i + chunk_size]
|
|
||||||
problem_ids = Problem.objects.filter(code__in=chunk).values_list(
|
|
||||||
"id", flat=True
|
|
||||||
)
|
|
||||||
if not problem_ids:
|
|
||||||
continue
|
|
||||||
logger.info("%s: Add %d problems", self.name, len(problem_ids))
|
|
||||||
self.judge.problems.add(*problem_ids)
|
|
||||||
updated = True
|
|
||||||
|
|
||||||
if problems_to_remove:
|
|
||||||
for i in range(0, len(problems_to_remove), chunk_size):
|
|
||||||
chunk = problems_to_remove[i : i + chunk_size]
|
|
||||||
problem_ids = Problem.objects.filter(code__in=chunk).values_list(
|
|
||||||
"id", flat=True
|
|
||||||
)
|
|
||||||
if not problem_ids:
|
|
||||||
continue
|
|
||||||
logger.info("%s: Remove %d problems", self.name, len(problem_ids))
|
|
||||||
self.judge.problems.remove(*problem_ids)
|
|
||||||
updated = True
|
|
||||||
|
|
||||||
if updated:
|
|
||||||
_get_judge_problems.dirty(self.judge)
|
|
||||||
|
|
||||||
def _connected(self):
|
def _connected(self):
|
||||||
judge = self.judge = Judge.objects.get(name=self.name)
|
judge = self.judge = Judge.objects.get(name=self.name)
|
||||||
judge.start_time = timezone.now()
|
judge.start_time = timezone.now()
|
||||||
judge.online = True
|
judge.online = True
|
||||||
self._update_judge_problems()
|
judge.problems.set(Problem.objects.filter(code__in=list(self.problems.keys())))
|
||||||
judge.runtimes.set(Language.objects.filter(key__in=list(self.executors.keys())))
|
judge.runtimes.set(Language.objects.filter(key__in=list(self.executors.keys())))
|
||||||
|
|
||||||
# Delete now in case we somehow crashed and left some over from the last connection
|
# Delete now in case we somehow crashed and left some over from the last connection
|
||||||
|
@ -220,8 +174,6 @@ class JudgeHandler(ZlibPacketHandler):
|
||||||
def _disconnected(self):
|
def _disconnected(self):
|
||||||
Judge.objects.filter(id=self.judge.id).update(online=False)
|
Judge.objects.filter(id=self.judge.id).update(online=False)
|
||||||
RuntimeVersion.objects.filter(judge=self.judge).delete()
|
RuntimeVersion.objects.filter(judge=self.judge).delete()
|
||||||
self.judge.problems.clear()
|
|
||||||
_get_judge_problems.dirty(self.judge)
|
|
||||||
|
|
||||||
def _update_ping(self):
|
def _update_ping(self):
|
||||||
try:
|
try:
|
||||||
|
@ -252,7 +204,8 @@ class JudgeHandler(ZlibPacketHandler):
|
||||||
return
|
return
|
||||||
|
|
||||||
self.timeout = 60
|
self.timeout = 60
|
||||||
self._update_supported_problems(packet["problems"])
|
self._problems = packet["problems"]
|
||||||
|
self.problems = dict(self._problems)
|
||||||
self.executors = packet["executors"]
|
self.executors = packet["executors"]
|
||||||
self.name = packet["id"]
|
self.name = packet["id"]
|
||||||
|
|
||||||
|
@ -353,15 +306,7 @@ class JudgeHandler(ZlibPacketHandler):
|
||||||
|
|
||||||
def submit(self, id, problem, language, source):
|
def submit(self, id, problem, language, source):
|
||||||
data = self.get_related_submission_data(id)
|
data = self.get_related_submission_data(id)
|
||||||
if not data:
|
|
||||||
self._update_internal_error_submission(id, "Submission vanished")
|
|
||||||
raise VanishedSubmission()
|
|
||||||
self._working = id
|
self._working = id
|
||||||
self._working_data = {
|
|
||||||
"problem": problem,
|
|
||||||
"language": language,
|
|
||||||
"source": source,
|
|
||||||
}
|
|
||||||
self._no_response_job = threading.Timer(20, self._kill_if_no_response)
|
self._no_response_job = threading.Timer(20, self._kill_if_no_response)
|
||||||
self.send(
|
self.send(
|
||||||
{
|
{
|
||||||
|
@ -480,12 +425,14 @@ class JudgeHandler(ZlibPacketHandler):
|
||||||
|
|
||||||
def on_supported_problems(self, packet):
|
def on_supported_problems(self, packet):
|
||||||
logger.info("%s: Updated problem list", self.name)
|
logger.info("%s: Updated problem list", self.name)
|
||||||
self._update_supported_problems(packet["problems"])
|
self._problems = packet["problems"]
|
||||||
|
self.problems = dict(self._problems)
|
||||||
if not self.working:
|
if not self.working:
|
||||||
self.judges.update_problems(self)
|
self.judges.update_problems(self)
|
||||||
|
|
||||||
self._update_judge_problems()
|
self.judge.problems.set(
|
||||||
|
Problem.objects.filter(code__in=list(self.problems.keys()))
|
||||||
|
)
|
||||||
json_log.info(
|
json_log.info(
|
||||||
self._make_json_log(action="update-problems", count=len(self.problems))
|
self._make_json_log(action="update-problems", count=len(self.problems))
|
||||||
)
|
)
|
||||||
|
@ -702,11 +649,8 @@ class JudgeHandler(ZlibPacketHandler):
|
||||||
self._free_self(packet)
|
self._free_self(packet)
|
||||||
|
|
||||||
id = packet["submission-id"]
|
id = packet["submission-id"]
|
||||||
self._update_internal_error_submission(id, packet["message"])
|
|
||||||
|
|
||||||
def _update_internal_error_submission(self, id, message):
|
|
||||||
if Submission.objects.filter(id=id).update(
|
if Submission.objects.filter(id=id).update(
|
||||||
status="IE", result="IE", error=message
|
status="IE", result="IE", error=packet["message"]
|
||||||
):
|
):
|
||||||
event.post(
|
event.post(
|
||||||
"sub_%s" % Submission.get_id_secret(id), {"type": "internal-error"}
|
"sub_%s" % Submission.get_id_secret(id), {"type": "internal-error"}
|
||||||
|
@ -714,9 +658,9 @@ class JudgeHandler(ZlibPacketHandler):
|
||||||
self._post_update_submission(id, "internal-error", done=True)
|
self._post_update_submission(id, "internal-error", done=True)
|
||||||
json_log.info(
|
json_log.info(
|
||||||
self._make_json_log(
|
self._make_json_log(
|
||||||
sub=id,
|
packet,
|
||||||
action="internal-error",
|
action="internal-error",
|
||||||
message=message,
|
message=packet["message"],
|
||||||
finish=True,
|
finish=True,
|
||||||
result="IE",
|
result="IE",
|
||||||
)
|
)
|
||||||
|
@ -725,10 +669,10 @@ class JudgeHandler(ZlibPacketHandler):
|
||||||
logger.warning("Unknown submission: %s", id)
|
logger.warning("Unknown submission: %s", id)
|
||||||
json_log.error(
|
json_log.error(
|
||||||
self._make_json_log(
|
self._make_json_log(
|
||||||
sub=id,
|
packet,
|
||||||
action="internal-error",
|
action="internal-error",
|
||||||
info="unknown submission",
|
info="unknown submission",
|
||||||
message=message,
|
message=packet["message"],
|
||||||
finish=True,
|
finish=True,
|
||||||
result="IE",
|
result="IE",
|
||||||
)
|
)
|
||||||
|
@ -959,8 +903,3 @@ class JudgeHandler(ZlibPacketHandler):
|
||||||
|
|
||||||
def on_cleanup(self):
|
def on_cleanup(self):
|
||||||
db.connection.close()
|
db.connection.close()
|
||||||
|
|
||||||
|
|
||||||
@cache_wrapper(prefix="gjp", timeout=3600)
|
|
||||||
def _get_judge_problems(judge):
|
|
||||||
return set(judge.problems.values_list("code", flat=True))
|
|
||||||
|
|
|
@ -3,8 +3,6 @@ from collections import namedtuple
|
||||||
from operator import attrgetter
|
from operator import attrgetter
|
||||||
from threading import RLock
|
from threading import RLock
|
||||||
|
|
||||||
from judge.bridge.utils import VanishedSubmission
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from llist import dllist
|
from llist import dllist
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -41,8 +39,6 @@ class JudgeList(object):
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
judge.submit(id, problem, language, source)
|
judge.submit(id, problem, language, source)
|
||||||
except VanishedSubmission:
|
|
||||||
pass
|
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.exception(
|
logger.exception(
|
||||||
"Failed to dispatch %d (%s, %s) to %s",
|
"Failed to dispatch %d (%s, %s) to %s",
|
||||||
|
@ -93,7 +89,6 @@ class JudgeList(object):
|
||||||
logger.info("Judge available after grading %d: %s", submission, judge.name)
|
logger.info("Judge available after grading %d: %s", submission, judge.name)
|
||||||
del self.submission_map[submission]
|
del self.submission_map[submission]
|
||||||
judge._working = False
|
judge._working = False
|
||||||
judge._working_data = {}
|
|
||||||
self._handle_free_judge(judge)
|
self._handle_free_judge(judge)
|
||||||
|
|
||||||
def abort(self, submission):
|
def abort(self, submission):
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
class VanishedSubmission(Exception):
|
|
||||||
pass
|
|
121
judge/caching.py
121
judge/caching.py
|
@ -1,117 +1,10 @@
|
||||||
from inspect import signature
|
from django.core.cache import cache
|
||||||
from django.core.cache import cache, caches
|
|
||||||
from django.db.models.query import QuerySet
|
|
||||||
from django.core.handlers.wsgi import WSGIRequest
|
|
||||||
|
|
||||||
import hashlib
|
|
||||||
|
|
||||||
from judge.logging import log_debug
|
|
||||||
|
|
||||||
MAX_NUM_CHAR = 50
|
|
||||||
NONE_RESULT = "__None__"
|
|
||||||
|
|
||||||
|
|
||||||
def arg_to_str(arg):
|
def finished_submission(sub):
|
||||||
if hasattr(arg, "id"):
|
keys = ["user_complete:%d" % sub.user_id, "user_attempted:%s" % sub.user_id]
|
||||||
return str(arg.id)
|
if hasattr(sub, "contest"):
|
||||||
if isinstance(arg, list) or isinstance(arg, QuerySet):
|
participation = sub.contest.participation
|
||||||
return hashlib.sha1(str(list(arg)).encode()).hexdigest()[:MAX_NUM_CHAR]
|
keys += ["contest_complete:%d" % participation.id]
|
||||||
if len(str(arg)) > MAX_NUM_CHAR:
|
keys += ["contest_attempted:%d" % participation.id]
|
||||||
return str(arg)[:MAX_NUM_CHAR]
|
|
||||||
return str(arg)
|
|
||||||
|
|
||||||
|
|
||||||
def filter_args(args_list):
|
|
||||||
return [x for x in args_list if not isinstance(x, WSGIRequest)]
|
|
||||||
|
|
||||||
|
|
||||||
l0_cache = caches["l0"] if "l0" in caches else None
|
|
||||||
|
|
||||||
|
|
||||||
def cache_wrapper(prefix, timeout=None, expected_type=None):
|
|
||||||
def get_key(func, *args, **kwargs):
|
|
||||||
args_list = list(args)
|
|
||||||
signature_args = list(signature(func).parameters.keys())
|
|
||||||
args_list += [kwargs.get(k) for k in signature_args[len(args) :]]
|
|
||||||
args_list = filter_args(args_list)
|
|
||||||
args_list = [arg_to_str(i) for i in args_list]
|
|
||||||
key = prefix + ":" + ":".join(args_list)
|
|
||||||
key = key.replace(" ", "_")
|
|
||||||
return key
|
|
||||||
|
|
||||||
def _get(key):
|
|
||||||
if not l0_cache:
|
|
||||||
return cache.get(key)
|
|
||||||
result = l0_cache.get(key)
|
|
||||||
if result is None:
|
|
||||||
result = cache.get(key)
|
|
||||||
return result
|
|
||||||
|
|
||||||
def _set_l0(key, value):
|
|
||||||
if l0_cache:
|
|
||||||
l0_cache.set(key, value, 30)
|
|
||||||
|
|
||||||
def _set(key, value, timeout):
|
|
||||||
_set_l0(key, value)
|
|
||||||
cache.set(key, value, timeout)
|
|
||||||
|
|
||||||
def decorator(func):
|
|
||||||
def _validate_type(cache_key, result):
|
|
||||||
if expected_type and not isinstance(result, expected_type):
|
|
||||||
data = {
|
|
||||||
"function": f"{func.__module__}.{func.__qualname__}",
|
|
||||||
"result": str(result)[:30],
|
|
||||||
"expected_type": expected_type,
|
|
||||||
"type": type(result),
|
|
||||||
"key": cache_key,
|
|
||||||
}
|
|
||||||
log_debug("invalid_key", data)
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
def wrapper(*args, **kwargs):
|
|
||||||
cache_key = get_key(func, *args, **kwargs)
|
|
||||||
result = _get(cache_key)
|
|
||||||
if result is not None and _validate_type(cache_key, result):
|
|
||||||
_set_l0(cache_key, result)
|
|
||||||
if type(result) == str and result == NONE_RESULT:
|
|
||||||
result = None
|
|
||||||
return result
|
|
||||||
result = func(*args, **kwargs)
|
|
||||||
if result is None:
|
|
||||||
cache_result = NONE_RESULT
|
|
||||||
else:
|
|
||||||
cache_result = result
|
|
||||||
_set(cache_key, cache_result, timeout)
|
|
||||||
return result
|
|
||||||
|
|
||||||
def dirty(*args, **kwargs):
|
|
||||||
cache_key = get_key(func, *args, **kwargs)
|
|
||||||
cache.delete(cache_key)
|
|
||||||
if l0_cache:
|
|
||||||
l0_cache.delete(cache_key)
|
|
||||||
|
|
||||||
def prefetch_multi(args_list):
|
|
||||||
keys = []
|
|
||||||
for args in args_list:
|
|
||||||
keys.append(get_key(func, *args))
|
|
||||||
results = cache.get_many(keys)
|
|
||||||
for key, result in results.items():
|
|
||||||
if result is not None:
|
|
||||||
_set_l0(key, result)
|
|
||||||
|
|
||||||
def dirty_multi(args_list):
|
|
||||||
keys = []
|
|
||||||
for args in args_list:
|
|
||||||
keys.append(get_key(func, *args))
|
|
||||||
cache.delete_many(keys)
|
cache.delete_many(keys)
|
||||||
if l0_cache:
|
|
||||||
l0_cache.delete_many(keys)
|
|
||||||
|
|
||||||
wrapper.dirty = dirty
|
|
||||||
wrapper.prefetch_multi = prefetch_multi
|
|
||||||
wrapper.dirty_multi = dirty_multi
|
|
||||||
|
|
||||||
return wrapper
|
|
||||||
|
|
||||||
return decorator
|
|
||||||
|
|
194
judge/comments.py
Normal file
194
judge/comments.py
Normal file
|
@ -0,0 +1,194 @@
|
||||||
|
from django import forms
|
||||||
|
from django.conf import settings
|
||||||
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
|
from django.db.models import Count, FilteredRelation, Q
|
||||||
|
from django.db.models.expressions import F, Value
|
||||||
|
from django.db.models.functions import Coalesce
|
||||||
|
from django.forms import ModelForm
|
||||||
|
from django.http import (
|
||||||
|
HttpResponseForbidden,
|
||||||
|
HttpResponseNotFound,
|
||||||
|
HttpResponseRedirect,
|
||||||
|
)
|
||||||
|
from django.urls import reverse_lazy
|
||||||
|
from django.utils.decorators import method_decorator
|
||||||
|
from django.utils.translation import gettext as _
|
||||||
|
from django.views.generic import View
|
||||||
|
from django.views.generic.base import TemplateResponseMixin
|
||||||
|
from django.views.generic.detail import SingleObjectMixin
|
||||||
|
from reversion import revisions
|
||||||
|
from reversion.models import Revision, Version
|
||||||
|
|
||||||
|
from judge.dblock import LockModel
|
||||||
|
from judge.models import Comment, CommentLock, Notification
|
||||||
|
from judge.widgets import HeavyPreviewPageDownWidget
|
||||||
|
from judge.jinja2.reference import get_user_from_text
|
||||||
|
|
||||||
|
|
||||||
|
def add_mention_notifications(comment):
|
||||||
|
user_referred = get_user_from_text(comment.body).exclude(id=comment.author.id)
|
||||||
|
for user in user_referred:
|
||||||
|
notification_ref = Notification(owner=user, comment=comment, category="Mention")
|
||||||
|
notification_ref.save()
|
||||||
|
|
||||||
|
|
||||||
|
def del_mention_notifications(comment):
|
||||||
|
query = {"comment": comment, "category": "Mention"}
|
||||||
|
Notification.objects.filter(**query).delete()
|
||||||
|
|
||||||
|
|
||||||
|
class CommentForm(ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = Comment
|
||||||
|
fields = ["body", "parent"]
|
||||||
|
widgets = {
|
||||||
|
"parent": forms.HiddenInput(),
|
||||||
|
}
|
||||||
|
|
||||||
|
if HeavyPreviewPageDownWidget is not None:
|
||||||
|
widgets["body"] = HeavyPreviewPageDownWidget(
|
||||||
|
preview=reverse_lazy("comment_preview"),
|
||||||
|
preview_timeout=1000,
|
||||||
|
hide_preview_button=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
def __init__(self, request, *args, **kwargs):
|
||||||
|
self.request = request
|
||||||
|
super(CommentForm, self).__init__(*args, **kwargs)
|
||||||
|
self.fields["body"].widget.attrs.update({"placeholder": _("Comment body")})
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
if self.request is not None and self.request.user.is_authenticated:
|
||||||
|
profile = self.request.profile
|
||||||
|
if profile.mute:
|
||||||
|
raise ValidationError(_("Your part is silent, little toad."))
|
||||||
|
elif (
|
||||||
|
not self.request.user.is_staff
|
||||||
|
and not profile.submission_set.filter(
|
||||||
|
points=F("problem__points")
|
||||||
|
).exists()
|
||||||
|
):
|
||||||
|
raise ValidationError(
|
||||||
|
_(
|
||||||
|
"You need to have solved at least one problem "
|
||||||
|
"before your voice can be heard."
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return super(CommentForm, self).clean()
|
||||||
|
|
||||||
|
|
||||||
|
class CommentedDetailView(TemplateResponseMixin, SingleObjectMixin, View):
|
||||||
|
comment_page = None
|
||||||
|
|
||||||
|
def get_comment_page(self):
|
||||||
|
if self.comment_page is None:
|
||||||
|
raise NotImplementedError()
|
||||||
|
return self.comment_page
|
||||||
|
|
||||||
|
def is_comment_locked(self):
|
||||||
|
if self.request.user.has_perm("judge.override_comment_lock"):
|
||||||
|
return False
|
||||||
|
return CommentLock.objects.filter(page=self.get_comment_page()).exists() or (
|
||||||
|
self.request.in_contest
|
||||||
|
and self.request.participation.contest.use_clarifications
|
||||||
|
)
|
||||||
|
|
||||||
|
@method_decorator(login_required)
|
||||||
|
def post(self, request, *args, **kwargs):
|
||||||
|
self.object = self.get_object()
|
||||||
|
page = self.get_comment_page()
|
||||||
|
|
||||||
|
if self.is_comment_locked():
|
||||||
|
return HttpResponseForbidden()
|
||||||
|
|
||||||
|
parent = request.POST.get("parent")
|
||||||
|
if parent:
|
||||||
|
try:
|
||||||
|
parent = int(parent)
|
||||||
|
except ValueError:
|
||||||
|
return HttpResponseNotFound()
|
||||||
|
else:
|
||||||
|
if not Comment.objects.filter(
|
||||||
|
hidden=False, id=parent, page=page
|
||||||
|
).exists():
|
||||||
|
return HttpResponseNotFound()
|
||||||
|
|
||||||
|
form = CommentForm(request, request.POST)
|
||||||
|
if form.is_valid():
|
||||||
|
comment = form.save(commit=False)
|
||||||
|
comment.author = request.profile
|
||||||
|
comment.page = page
|
||||||
|
|
||||||
|
with LockModel(
|
||||||
|
write=(Comment, Revision, Version), read=(ContentType,)
|
||||||
|
), revisions.create_revision():
|
||||||
|
revisions.set_user(request.user)
|
||||||
|
revisions.set_comment(_("Posted comment"))
|
||||||
|
comment.save()
|
||||||
|
|
||||||
|
# add notification for reply
|
||||||
|
if comment.parent and comment.parent.author != comment.author:
|
||||||
|
notification_reply = Notification(
|
||||||
|
owner=comment.parent.author, comment=comment, category="Reply"
|
||||||
|
)
|
||||||
|
notification_reply.save()
|
||||||
|
|
||||||
|
# add notification for page authors
|
||||||
|
page_authors = comment.page_object.authors.all()
|
||||||
|
for user in page_authors:
|
||||||
|
if user == comment.author:
|
||||||
|
continue
|
||||||
|
notification = Notification(
|
||||||
|
owner=user, comment=comment, category="Comment"
|
||||||
|
)
|
||||||
|
notification.save()
|
||||||
|
# except Exception:
|
||||||
|
# pass
|
||||||
|
|
||||||
|
add_mention_notifications(comment)
|
||||||
|
|
||||||
|
return HttpResponseRedirect(request.path)
|
||||||
|
|
||||||
|
context = self.get_context_data(object=self.object, comment_form=form)
|
||||||
|
return self.render_to_response(context)
|
||||||
|
|
||||||
|
def get(self, request, *args, **kwargs):
|
||||||
|
self.object = self.get_object()
|
||||||
|
return self.render_to_response(
|
||||||
|
self.get_context_data(
|
||||||
|
object=self.object,
|
||||||
|
comment_form=CommentForm(
|
||||||
|
request, initial={"page": self.get_comment_page(), "parent": None}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super(CommentedDetailView, self).get_context_data(**kwargs)
|
||||||
|
queryset = Comment.objects.filter(hidden=False, page=self.get_comment_page())
|
||||||
|
context["has_comments"] = queryset.exists()
|
||||||
|
context["comment_lock"] = self.is_comment_locked()
|
||||||
|
queryset = (
|
||||||
|
queryset.select_related("author__user")
|
||||||
|
.defer("author__about")
|
||||||
|
.annotate(revisions=Count("versions"))
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.request.user.is_authenticated:
|
||||||
|
profile = self.request.profile
|
||||||
|
queryset = queryset.annotate(
|
||||||
|
my_vote=FilteredRelation(
|
||||||
|
"votes", condition=Q(votes__voter_id=profile.id)
|
||||||
|
),
|
||||||
|
).annotate(vote_score=Coalesce(F("my_vote__score"), Value(0)))
|
||||||
|
context["is_new_user"] = (
|
||||||
|
not self.request.user.is_staff
|
||||||
|
and not profile.submission_set.filter(
|
||||||
|
points=F("problem__points")
|
||||||
|
).exists()
|
||||||
|
)
|
||||||
|
context["comment_list"] = queryset
|
||||||
|
context["vote_hide_threshold"] = settings.DMOJ_COMMENT_VOTE_HIDE_THRESHOLD
|
||||||
|
return context
|
|
@ -4,5 +4,4 @@ from judge.contest_format.ecoo import ECOOContestFormat
|
||||||
from judge.contest_format.icpc import ICPCContestFormat
|
from judge.contest_format.icpc import ICPCContestFormat
|
||||||
from judge.contest_format.ioi import IOIContestFormat
|
from judge.contest_format.ioi import IOIContestFormat
|
||||||
from judge.contest_format.new_ioi import NewIOIContestFormat
|
from judge.contest_format.new_ioi import NewIOIContestFormat
|
||||||
from judge.contest_format.ultimate import UltimateContestFormat
|
|
||||||
from judge.contest_format.registry import choices, formats
|
from judge.contest_format.registry import choices, formats
|
||||||
|
|
|
@ -109,8 +109,6 @@ class BaseContestFormat(metaclass=ABCMeta):
|
||||||
)
|
)
|
||||||
for result in queryset:
|
for result in queryset:
|
||||||
problem = str(result["problem_id"])
|
problem = str(result["problem_id"])
|
||||||
if not (self.contest.freeze_after or hidden_subtasks.get(problem)):
|
|
||||||
continue
|
|
||||||
if format_data.get(problem):
|
if format_data.get(problem):
|
||||||
is_after_freeze = (
|
is_after_freeze = (
|
||||||
self.contest.freeze_after
|
self.contest.freeze_after
|
||||||
|
|
|
@ -1,55 +0,0 @@
|
||||||
from django.utils.translation import gettext_lazy
|
|
||||||
|
|
||||||
from judge.contest_format.ioi import IOIContestFormat
|
|
||||||
from judge.contest_format.registry import register_contest_format
|
|
||||||
from django.db.models import Min, OuterRef, Subquery
|
|
||||||
|
|
||||||
# This contest format only counts last submission for each problem.
|
|
||||||
|
|
||||||
|
|
||||||
@register_contest_format("ultimate")
|
|
||||||
class UltimateContestFormat(IOIContestFormat):
|
|
||||||
name = gettext_lazy("Ultimate")
|
|
||||||
|
|
||||||
def update_participation(self, participation):
|
|
||||||
cumtime = 0
|
|
||||||
score = 0
|
|
||||||
format_data = {}
|
|
||||||
|
|
||||||
queryset = participation.submissions
|
|
||||||
if self.contest.freeze_after:
|
|
||||||
queryset = queryset.filter(
|
|
||||||
submission__date__lt=participation.start + self.contest.freeze_after
|
|
||||||
)
|
|
||||||
|
|
||||||
queryset = (
|
|
||||||
queryset.values("problem_id")
|
|
||||||
.filter(
|
|
||||||
id=Subquery(
|
|
||||||
queryset.filter(problem_id=OuterRef("problem_id"))
|
|
||||||
.order_by("-id")
|
|
||||||
.values("id")[:1]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.values_list("problem_id", "submission__date", "points")
|
|
||||||
)
|
|
||||||
|
|
||||||
for problem_id, time, points in queryset:
|
|
||||||
if self.config["cumtime"]:
|
|
||||||
dt = (time - participation.start).total_seconds()
|
|
||||||
if points:
|
|
||||||
cumtime += dt
|
|
||||||
else:
|
|
||||||
dt = 0
|
|
||||||
format_data[str(problem_id)] = {
|
|
||||||
"time": dt,
|
|
||||||
"points": points,
|
|
||||||
}
|
|
||||||
score += points
|
|
||||||
|
|
||||||
self.handle_frozen_state(participation, format_data)
|
|
||||||
participation.cumtime = max(cumtime, 0)
|
|
||||||
participation.score = round(score, self.contest.points_precision)
|
|
||||||
participation.tiebreaker = 0
|
|
||||||
participation.format_data = format_data
|
|
||||||
participation.save()
|
|
|
@ -1,22 +0,0 @@
|
||||||
from django.utils.translation import gettext_lazy as _, ngettext
|
|
||||||
|
|
||||||
|
|
||||||
def custom_trans():
|
|
||||||
return [
|
|
||||||
# Password reset
|
|
||||||
ngettext(
|
|
||||||
"This password is too short. It must contain at least %(min_length)d character.",
|
|
||||||
"This password is too short. It must contain at least %(min_length)d characters.",
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
ngettext(
|
|
||||||
"Your password must contain at least %(min_length)d character.",
|
|
||||||
"Your password must contain at least %(min_length)d characters.",
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
_("The two password fields didn’t match."),
|
|
||||||
_("Your password can’t be entirely numeric."),
|
|
||||||
# Navbar
|
|
||||||
_("Bug Report"),
|
|
||||||
_("Courses"),
|
|
||||||
]
|
|
|
@ -16,7 +16,7 @@ class EventPoster(object):
|
||||||
|
|
||||||
def _connect(self):
|
def _connect(self):
|
||||||
self._conn = pika.BlockingConnection(
|
self._conn = pika.BlockingConnection(
|
||||||
pika.URLParameters(settings.EVENT_DAEMON_AMQP),
|
pika.URLParameters(settings.EVENT_DAEMON_AMQP)
|
||||||
)
|
)
|
||||||
self._chan = self._conn.channel()
|
self._chan = self._conn.channel()
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ class EventPoster(object):
|
||||||
id = int(time() * 1000000)
|
id = int(time() * 1000000)
|
||||||
self._chan.basic_publish(
|
self._chan.basic_publish(
|
||||||
self._exchange,
|
self._exchange,
|
||||||
"#",
|
"",
|
||||||
json.dumps({"id": id, "channel": channel, "message": message}),
|
json.dumps({"id": id, "channel": channel, "message": message}),
|
||||||
)
|
)
|
||||||
return id
|
return id
|
||||||
|
|
120
judge/feed.py
Normal file
120
judge/feed.py
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
from django.conf import settings
|
||||||
|
from django.contrib.auth.models import AnonymousUser
|
||||||
|
from django.contrib.syndication.views import Feed
|
||||||
|
from django.core.cache import cache
|
||||||
|
from django.utils import timezone
|
||||||
|
from django.utils.feedgenerator import Atom1Feed
|
||||||
|
|
||||||
|
from judge.jinja2.markdown import markdown
|
||||||
|
from judge.models import BlogPost, Comment, Problem
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
# https://lsimons.wordpress.com/2011/03/17/stripping-illegal-characters-out-of-xml-in-python/
|
||||||
|
def escape_xml_illegal_chars(val, replacement="?"):
|
||||||
|
_illegal_xml_chars_RE = re.compile(
|
||||||
|
"[\x00-\x08\x0b\x0c\x0e-\x1F\uD800-\uDFFF\uFFFE\uFFFF]"
|
||||||
|
)
|
||||||
|
return _illegal_xml_chars_RE.sub(replacement, val)
|
||||||
|
|
||||||
|
|
||||||
|
class ProblemFeed(Feed):
|
||||||
|
title = "Recently Added %s Problems" % settings.SITE_NAME
|
||||||
|
link = "/"
|
||||||
|
description = (
|
||||||
|
"The latest problems added on the %s website" % settings.SITE_LONG_NAME
|
||||||
|
)
|
||||||
|
|
||||||
|
def items(self):
|
||||||
|
return (
|
||||||
|
Problem.objects.filter(is_public=True, is_organization_private=False)
|
||||||
|
.defer("description")
|
||||||
|
.order_by("-date", "-id")[:25]
|
||||||
|
)
|
||||||
|
|
||||||
|
def item_title(self, problem):
|
||||||
|
return problem.name
|
||||||
|
|
||||||
|
def item_description(self, problem):
|
||||||
|
key = "problem_feed:%d" % problem.id
|
||||||
|
desc = cache.get(key)
|
||||||
|
if desc is None:
|
||||||
|
desc = str(markdown(problem.description))[:500] + "..."
|
||||||
|
desc = escape_xml_illegal_chars(desc)
|
||||||
|
cache.set(key, desc, 86400)
|
||||||
|
return desc
|
||||||
|
|
||||||
|
def item_pubdate(self, problem):
|
||||||
|
return problem.date
|
||||||
|
|
||||||
|
item_updateddate = item_pubdate
|
||||||
|
|
||||||
|
|
||||||
|
class AtomProblemFeed(ProblemFeed):
|
||||||
|
feed_type = Atom1Feed
|
||||||
|
subtitle = ProblemFeed.description
|
||||||
|
|
||||||
|
|
||||||
|
class CommentFeed(Feed):
|
||||||
|
title = "Latest %s Comments" % settings.SITE_NAME
|
||||||
|
link = "/"
|
||||||
|
description = "The latest comments on the %s website" % settings.SITE_LONG_NAME
|
||||||
|
|
||||||
|
def items(self):
|
||||||
|
return Comment.most_recent(AnonymousUser(), 25)
|
||||||
|
|
||||||
|
def item_title(self, comment):
|
||||||
|
return "%s -> %s" % (comment.author.user.username, comment.page_title)
|
||||||
|
|
||||||
|
def item_description(self, comment):
|
||||||
|
key = "comment_feed:%d" % comment.id
|
||||||
|
desc = cache.get(key)
|
||||||
|
if desc is None:
|
||||||
|
desc = str(markdown(comment.body))
|
||||||
|
desc = escape_xml_illegal_chars(desc)
|
||||||
|
cache.set(key, desc, 86400)
|
||||||
|
return desc
|
||||||
|
|
||||||
|
def item_pubdate(self, comment):
|
||||||
|
return comment.time
|
||||||
|
|
||||||
|
item_updateddate = item_pubdate
|
||||||
|
|
||||||
|
|
||||||
|
class AtomCommentFeed(CommentFeed):
|
||||||
|
feed_type = Atom1Feed
|
||||||
|
subtitle = CommentFeed.description
|
||||||
|
|
||||||
|
|
||||||
|
class BlogFeed(Feed):
|
||||||
|
title = "Latest %s Blog Posts" % settings.SITE_NAME
|
||||||
|
link = "/"
|
||||||
|
description = "The latest blog posts from the %s" % settings.SITE_LONG_NAME
|
||||||
|
|
||||||
|
def items(self):
|
||||||
|
return BlogPost.objects.filter(
|
||||||
|
visible=True, publish_on__lte=timezone.now()
|
||||||
|
).order_by("-sticky", "-publish_on")
|
||||||
|
|
||||||
|
def item_title(self, post):
|
||||||
|
return post.title
|
||||||
|
|
||||||
|
def item_description(self, post):
|
||||||
|
key = "blog_feed:%d" % post.id
|
||||||
|
summary = cache.get(key)
|
||||||
|
if summary is None:
|
||||||
|
summary = str(markdown(post.summary or post.content))
|
||||||
|
summary = escape_xml_illegal_chars(summary)
|
||||||
|
cache.set(key, summary, 86400)
|
||||||
|
return summary
|
||||||
|
|
||||||
|
def item_pubdate(self, post):
|
||||||
|
return post.publish_on
|
||||||
|
|
||||||
|
item_updateddate = item_pubdate
|
||||||
|
|
||||||
|
|
||||||
|
class AtomBlogFeed(BlogFeed):
|
||||||
|
feed_type = Atom1Feed
|
||||||
|
subtitle = BlogFeed.description
|
|
@ -8,6 +8,7 @@
|
||||||
"ip": "10.0.2.2",
|
"ip": "10.0.2.2",
|
||||||
"language": 1,
|
"language": 1,
|
||||||
"last_access": "2017-12-02T08:57:10.093Z",
|
"last_access": "2017-12-02T08:57:10.093Z",
|
||||||
|
"math_engine": "auto",
|
||||||
"mute": false,
|
"mute": false,
|
||||||
"organizations": [
|
"organizations": [
|
||||||
1
|
1
|
||||||
|
@ -17,7 +18,8 @@
|
||||||
"problem_count": 0,
|
"problem_count": 0,
|
||||||
"rating": null,
|
"rating": null,
|
||||||
"timezone": "America/Toronto",
|
"timezone": "America/Toronto",
|
||||||
"user": 1
|
"user": 1,
|
||||||
|
"user_script": ""
|
||||||
},
|
},
|
||||||
"model": "judge.profile",
|
"model": "judge.profile",
|
||||||
"pk": 1
|
"pk": 1
|
||||||
|
@ -145,8 +147,25 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fields": {
|
"fields": {
|
||||||
"domain": "localhost:8000",
|
"author": 1,
|
||||||
"name": "LQDOJ"
|
"body": "This is your first comment!",
|
||||||
|
"hidden": false,
|
||||||
|
"level": 0,
|
||||||
|
"lft": 1,
|
||||||
|
"page": "b:1",
|
||||||
|
"parent": null,
|
||||||
|
"rght": 2,
|
||||||
|
"score": 0,
|
||||||
|
"time": "2017-12-02T08:46:54.007Z",
|
||||||
|
"tree_id": 1
|
||||||
|
},
|
||||||
|
"model": "judge.comment",
|
||||||
|
"pk": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fields": {
|
||||||
|
"domain": "localhost:8081",
|
||||||
|
"name": "DMOJ: Modern Online Judge"
|
||||||
},
|
},
|
||||||
"model": "sites.site",
|
"model": "sites.site",
|
||||||
"pk": 1
|
"pk": 1
|
||||||
|
|
213
judge/forms.py
213
judge/forms.py
|
@ -1,16 +1,13 @@
|
||||||
import os
|
|
||||||
import secrets
|
|
||||||
from operator import attrgetter
|
from operator import attrgetter
|
||||||
import pyotp
|
|
||||||
import time
|
|
||||||
import datetime
|
|
||||||
|
|
||||||
|
import pyotp
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.auth.forms import AuthenticationForm
|
from django.contrib.auth.forms import AuthenticationForm
|
||||||
from django.core.exceptions import ValidationError, ObjectDoesNotExist
|
from django.core.exceptions import ValidationError, ObjectDoesNotExist
|
||||||
from django.core.validators import RegexValidator
|
from django.core.validators import RegexValidator
|
||||||
|
from django.db import transaction
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.forms import (
|
from django.forms import (
|
||||||
CharField,
|
CharField,
|
||||||
|
@ -19,9 +16,8 @@ from django.forms import (
|
||||||
ModelForm,
|
ModelForm,
|
||||||
formset_factory,
|
formset_factory,
|
||||||
BaseModelFormSet,
|
BaseModelFormSet,
|
||||||
FileField,
|
|
||||||
)
|
)
|
||||||
from django.urls import reverse_lazy, reverse
|
from django.urls import reverse_lazy
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
|
@ -29,7 +25,6 @@ from django_ace import AceWidget
|
||||||
from judge.models import (
|
from judge.models import (
|
||||||
Contest,
|
Contest,
|
||||||
Language,
|
Language,
|
||||||
TestFormatterModel,
|
|
||||||
Organization,
|
Organization,
|
||||||
PrivateMessage,
|
PrivateMessage,
|
||||||
Problem,
|
Problem,
|
||||||
|
@ -38,12 +33,11 @@ from judge.models import (
|
||||||
Submission,
|
Submission,
|
||||||
BlogPost,
|
BlogPost,
|
||||||
ContestProblem,
|
ContestProblem,
|
||||||
TestFormatterModel,
|
|
||||||
ProfileInfo,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from judge.widgets import (
|
from judge.widgets import (
|
||||||
HeavyPreviewPageDownWidget,
|
HeavyPreviewPageDownWidget,
|
||||||
|
MathJaxPagedownWidget,
|
||||||
PagedownWidget,
|
PagedownWidget,
|
||||||
Select2MultipleWidget,
|
Select2MultipleWidget,
|
||||||
Select2Widget,
|
Select2Widget,
|
||||||
|
@ -51,9 +45,8 @@ from judge.widgets import (
|
||||||
HeavySelect2Widget,
|
HeavySelect2Widget,
|
||||||
Select2MultipleWidget,
|
Select2MultipleWidget,
|
||||||
DateTimePickerWidget,
|
DateTimePickerWidget,
|
||||||
ImageWidget,
|
|
||||||
DatePickerWidget,
|
|
||||||
)
|
)
|
||||||
|
from judge.tasks import rescore_contest
|
||||||
|
|
||||||
|
|
||||||
def fix_unicode(string, unsafe=tuple("\u202a\u202b\u202d\u202e")):
|
def fix_unicode(string, unsafe=tuple("\u202a\u202b\u202d\u202e")):
|
||||||
|
@ -71,61 +64,55 @@ class UserForm(ModelForm):
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class ProfileInfoForm(ModelForm):
|
|
||||||
class Meta:
|
|
||||||
model = ProfileInfo
|
|
||||||
fields = ["tshirt_size", "date_of_birth", "address"]
|
|
||||||
widgets = {
|
|
||||||
"tshirt_size": Select2Widget(attrs={"style": "width:100%"}),
|
|
||||||
"date_of_birth": DatePickerWidget,
|
|
||||||
"address": forms.TextInput(attrs={"style": "width:100%"}),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class ProfileForm(ModelForm):
|
class ProfileForm(ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Profile
|
model = Profile
|
||||||
fields = [
|
fields = [
|
||||||
"about",
|
"about",
|
||||||
|
"organizations",
|
||||||
"timezone",
|
"timezone",
|
||||||
"language",
|
"language",
|
||||||
"ace_theme",
|
"ace_theme",
|
||||||
"profile_image",
|
"user_script",
|
||||||
"css_background",
|
|
||||||
]
|
]
|
||||||
widgets = {
|
widgets = {
|
||||||
|
"user_script": AceWidget(theme="github"),
|
||||||
"timezone": Select2Widget(attrs={"style": "width:200px"}),
|
"timezone": Select2Widget(attrs={"style": "width:200px"}),
|
||||||
"language": Select2Widget(attrs={"style": "width:200px"}),
|
"language": Select2Widget(attrs={"style": "width:200px"}),
|
||||||
"ace_theme": Select2Widget(attrs={"style": "width:200px"}),
|
"ace_theme": Select2Widget(attrs={"style": "width:200px"}),
|
||||||
"profile_image": ImageWidget,
|
|
||||||
"css_background": forms.TextInput(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
has_math_config = bool(settings.MATHOID_URL)
|
||||||
|
if has_math_config:
|
||||||
|
fields.append("math_engine")
|
||||||
|
widgets["math_engine"] = Select2Widget(attrs={"style": "width:200px"})
|
||||||
|
|
||||||
if HeavyPreviewPageDownWidget is not None:
|
if HeavyPreviewPageDownWidget is not None:
|
||||||
widgets["about"] = HeavyPreviewPageDownWidget(
|
widgets["about"] = HeavyPreviewPageDownWidget(
|
||||||
preview=reverse_lazy("profile_preview"),
|
preview=reverse_lazy("profile_preview"),
|
||||||
attrs={"style": "max-width:700px;min-width:700px;width:700px"},
|
attrs={"style": "max-width:700px;min-width:700px;width:700px"},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
organizations = self.cleaned_data.get("organizations") or []
|
||||||
|
max_orgs = settings.DMOJ_USER_MAX_ORGANIZATION_COUNT
|
||||||
|
|
||||||
|
if sum(org.is_open for org in organizations) > max_orgs:
|
||||||
|
raise ValidationError(
|
||||||
|
_("You may not be part of more than {count} public groups.").format(
|
||||||
|
count=max_orgs
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return self.cleaned_data
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
user = kwargs.pop("user", None)
|
user = kwargs.pop("user", None)
|
||||||
super(ProfileForm, self).__init__(*args, **kwargs)
|
super(ProfileForm, self).__init__(*args, **kwargs)
|
||||||
self.fields["profile_image"].required = False
|
if not user.has_perm("judge.edit_all_organization"):
|
||||||
|
self.fields["organizations"].queryset = Organization.objects.filter(
|
||||||
def clean_profile_image(self):
|
Q(is_open=True) | Q(id__in=user.profile.organizations.all()),
|
||||||
profile_image = self.cleaned_data.get("profile_image")
|
|
||||||
if profile_image:
|
|
||||||
if profile_image.size > 5 * 1024 * 1024:
|
|
||||||
raise ValidationError(
|
|
||||||
_("File size exceeds the maximum allowed limit of 5MB.")
|
|
||||||
)
|
)
|
||||||
return profile_image
|
|
||||||
|
|
||||||
|
|
||||||
def file_size_validator(file):
|
|
||||||
limit = 10 * 1024 * 1024
|
|
||||||
if file.size > limit:
|
|
||||||
raise ValidationError("File too large. Size should not exceed 10MB.")
|
|
||||||
|
|
||||||
|
|
||||||
class ProblemSubmitForm(ModelForm):
|
class ProblemSubmitForm(ModelForm):
|
||||||
|
@ -133,13 +120,9 @@ class ProblemSubmitForm(ModelForm):
|
||||||
max_length=65536, widget=AceWidget(theme="twilight", no_ace_media=True)
|
max_length=65536, widget=AceWidget(theme="twilight", no_ace_media=True)
|
||||||
)
|
)
|
||||||
judge = ChoiceField(choices=(), widget=forms.HiddenInput(), required=False)
|
judge = ChoiceField(choices=(), widget=forms.HiddenInput(), required=False)
|
||||||
source_file = FileField(required=False, validators=[file_size_validator])
|
|
||||||
|
|
||||||
def __init__(self, *args, judge_choices=(), request=None, problem=None, **kwargs):
|
def __init__(self, *args, judge_choices=(), **kwargs):
|
||||||
super(ProblemSubmitForm, self).__init__(*args, **kwargs)
|
super(ProblemSubmitForm, self).__init__(*args, **kwargs)
|
||||||
self.source_file_name = None
|
|
||||||
self.request = request
|
|
||||||
self.problem = problem
|
|
||||||
self.fields["language"].empty_label = None
|
self.fields["language"].empty_label = None
|
||||||
self.fields["language"].label_from_instance = attrgetter("display_name")
|
self.fields["language"].label_from_instance = attrgetter("display_name")
|
||||||
self.fields["language"].queryset = Language.objects.filter(
|
self.fields["language"].queryset = Language.objects.filter(
|
||||||
|
@ -152,36 +135,6 @@ class ProblemSubmitForm(ModelForm):
|
||||||
)
|
)
|
||||||
self.fields["judge"].choices = judge_choices
|
self.fields["judge"].choices = judge_choices
|
||||||
|
|
||||||
def allow_url_as_source(self):
|
|
||||||
key = self.cleaned_data["language"].key
|
|
||||||
filename = self.files["source_file"].name
|
|
||||||
if key == "OUTPUT" and self.problem.data_files.output_only:
|
|
||||||
return filename.endswith(".zip")
|
|
||||||
if key == "SCAT":
|
|
||||||
return filename.endswith(".sb3")
|
|
||||||
return False
|
|
||||||
|
|
||||||
def clean(self):
|
|
||||||
if "source_file" in self.files:
|
|
||||||
if self.allow_url_as_source():
|
|
||||||
filename = self.files["source_file"].name
|
|
||||||
now = datetime.datetime.now()
|
|
||||||
timestamp = str(int(time.mktime(now.timetuple())))
|
|
||||||
self.source_file_name = (
|
|
||||||
timestamp + secrets.token_hex(5) + "." + filename.split(".")[-1]
|
|
||||||
)
|
|
||||||
filepath = os.path.join(
|
|
||||||
settings.DMOJ_SUBMISSION_ROOT, self.source_file_name
|
|
||||||
)
|
|
||||||
with open(filepath, "wb+") as destination:
|
|
||||||
for chunk in self.files["source_file"].chunks():
|
|
||||||
destination.write(chunk)
|
|
||||||
self.cleaned_data["source"] = self.request.build_absolute_uri(
|
|
||||||
reverse("submission_source_file", args=(self.source_file_name,))
|
|
||||||
)
|
|
||||||
del self.files["source_file"]
|
|
||||||
return self.cleaned_data
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Submission
|
model = Submission
|
||||||
fields = ["language"]
|
fields = ["language"]
|
||||||
|
@ -195,32 +148,16 @@ class EditOrganizationForm(ModelForm):
|
||||||
"slug",
|
"slug",
|
||||||
"short_name",
|
"short_name",
|
||||||
"about",
|
"about",
|
||||||
"organization_image",
|
"logo_override_image",
|
||||||
"admins",
|
"admins",
|
||||||
"is_open",
|
"is_open",
|
||||||
]
|
]
|
||||||
widgets = {
|
widgets = {"admins": Select2MultipleWidget()}
|
||||||
"admins": Select2MultipleWidget(),
|
|
||||||
"organization_image": ImageWidget,
|
|
||||||
}
|
|
||||||
if HeavyPreviewPageDownWidget is not None:
|
if HeavyPreviewPageDownWidget is not None:
|
||||||
widgets["about"] = HeavyPreviewPageDownWidget(
|
widgets["about"] = HeavyPreviewPageDownWidget(
|
||||||
preview=reverse_lazy("organization_preview")
|
preview=reverse_lazy("organization_preview")
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
super(EditOrganizationForm, self).__init__(*args, **kwargs)
|
|
||||||
self.fields["organization_image"].required = False
|
|
||||||
|
|
||||||
def clean_organization_image(self):
|
|
||||||
organization_image = self.cleaned_data.get("organization_image")
|
|
||||||
if organization_image:
|
|
||||||
if organization_image.size > 5 * 1024 * 1024:
|
|
||||||
raise ValidationError(
|
|
||||||
_("File size exceeds the maximum allowed limit of 5MB.")
|
|
||||||
)
|
|
||||||
return organization_image
|
|
||||||
|
|
||||||
|
|
||||||
class AddOrganizationForm(ModelForm):
|
class AddOrganizationForm(ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -230,7 +167,7 @@ class AddOrganizationForm(ModelForm):
|
||||||
"slug",
|
"slug",
|
||||||
"short_name",
|
"short_name",
|
||||||
"about",
|
"about",
|
||||||
"organization_image",
|
"logo_override_image",
|
||||||
"is_open",
|
"is_open",
|
||||||
]
|
]
|
||||||
widgets = {}
|
widgets = {}
|
||||||
|
@ -242,7 +179,6 @@ class AddOrganizationForm(ModelForm):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.request = kwargs.pop("request", None)
|
self.request = kwargs.pop("request", None)
|
||||||
super(AddOrganizationForm, self).__init__(*args, **kwargs)
|
super(AddOrganizationForm, self).__init__(*args, **kwargs)
|
||||||
self.fields["organization_image"].required = False
|
|
||||||
|
|
||||||
def save(self, commit=True):
|
def save(self, commit=True):
|
||||||
res = super(AddOrganizationForm, self).save(commit=False)
|
res = super(AddOrganizationForm, self).save(commit=False)
|
||||||
|
@ -304,9 +240,16 @@ class EditOrganizationContestForm(ModelForm):
|
||||||
"view_contest_scoreboard",
|
"view_contest_scoreboard",
|
||||||
]:
|
]:
|
||||||
self.fields[field].widget.data_url = (
|
self.fields[field].widget.data_url = (
|
||||||
self.fields[field].widget.get_url() + f"?org_id={self.org_id}"
|
self.fields[field].widget.get_url() + "?org_id=1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def save(self, commit=True):
|
||||||
|
res = super(EditOrganizationContestForm, self).save(commit=False)
|
||||||
|
if commit:
|
||||||
|
res.save()
|
||||||
|
transaction.on_commit(rescore_contest.s(res.key).delay)
|
||||||
|
return res
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Contest
|
model = Contest
|
||||||
fields = (
|
fields = (
|
||||||
|
@ -320,13 +263,11 @@ class EditOrganizationContestForm(ModelForm):
|
||||||
"curators",
|
"curators",
|
||||||
"testers",
|
"testers",
|
||||||
"time_limit",
|
"time_limit",
|
||||||
"freeze_after",
|
|
||||||
"use_clarifications",
|
"use_clarifications",
|
||||||
"hide_problem_tags",
|
"hide_problem_tags",
|
||||||
"public_scoreboard",
|
|
||||||
"scoreboard_visibility",
|
"scoreboard_visibility",
|
||||||
|
"run_pretests_only",
|
||||||
"points_precision",
|
"points_precision",
|
||||||
"rate_limit",
|
|
||||||
"description",
|
"description",
|
||||||
"og_image",
|
"og_image",
|
||||||
"logo_override_image",
|
"logo_override_image",
|
||||||
|
@ -369,7 +310,7 @@ class AddOrganizationMemberForm(ModelForm):
|
||||||
label=_("New users"),
|
label=_("New users"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def clean_new_users(self):
|
def clean(self):
|
||||||
new_users = self.cleaned_data.get("new_users") or ""
|
new_users = self.cleaned_data.get("new_users") or ""
|
||||||
usernames = new_users.split()
|
usernames = new_users.split()
|
||||||
invalid_usernames = []
|
invalid_usernames = []
|
||||||
|
@ -387,7 +328,8 @@ class AddOrganizationMemberForm(ModelForm):
|
||||||
usernames=str(invalid_usernames)
|
usernames=str(invalid_usernames)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return valid_usernames
|
self.cleaned_data["new_users"] = valid_usernames
|
||||||
|
return self.cleaned_data
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Organization
|
model = Organization
|
||||||
|
@ -435,15 +377,13 @@ class NewMessageForm(ModelForm):
|
||||||
fields = ["title", "content"]
|
fields = ["title", "content"]
|
||||||
widgets = {}
|
widgets = {}
|
||||||
if PagedownWidget is not None:
|
if PagedownWidget is not None:
|
||||||
widgets["content"] = PagedownWidget()
|
widgets["content"] = MathJaxPagedownWidget()
|
||||||
|
|
||||||
|
|
||||||
class CustomAuthenticationForm(AuthenticationForm):
|
class CustomAuthenticationForm(AuthenticationForm):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(CustomAuthenticationForm, self).__init__(*args, **kwargs)
|
super(CustomAuthenticationForm, self).__init__(*args, **kwargs)
|
||||||
self.fields["username"].widget.attrs.update(
|
self.fields["username"].widget.attrs.update({"placeholder": _("Username")})
|
||||||
{"placeholder": _("Username/Email")}
|
|
||||||
)
|
|
||||||
self.fields["password"].widget.attrs.update({"placeholder": _("Password")})
|
self.fields["password"].widget.attrs.update({"placeholder": _("Password")})
|
||||||
|
|
||||||
self.has_google_auth = self._has_social_auth("GOOGLE_OAUTH2")
|
self.has_google_auth = self._has_social_auth("GOOGLE_OAUTH2")
|
||||||
|
@ -506,15 +446,6 @@ class ContestCloneForm(Form):
|
||||||
max_length=20,
|
max_length=20,
|
||||||
validators=[RegexValidator("^[a-z0-9]+$", _("Contest id must be ^[a-z0-9]+$"))],
|
validators=[RegexValidator("^[a-z0-9]+$", _("Contest id must be ^[a-z0-9]+$"))],
|
||||||
)
|
)
|
||||||
organization = ChoiceField(choices=(), required=True)
|
|
||||||
|
|
||||||
def __init__(self, *args, org_choices=(), profile=None, **kwargs):
|
|
||||||
super(ContestCloneForm, self).__init__(*args, **kwargs)
|
|
||||||
self.fields["organization"].widget = Select2Widget(
|
|
||||||
attrs={"style": "width: 100%", "data-placeholder": _("Group")},
|
|
||||||
)
|
|
||||||
self.fields["organization"].choices = org_choices
|
|
||||||
self.profile = profile
|
|
||||||
|
|
||||||
def clean_key(self):
|
def clean_key(self):
|
||||||
key = self.cleaned_data["key"]
|
key = self.cleaned_data["key"]
|
||||||
|
@ -522,16 +453,6 @@ class ContestCloneForm(Form):
|
||||||
raise ValidationError(_("Contest with key already exists."))
|
raise ValidationError(_("Contest with key already exists."))
|
||||||
return key
|
return key
|
||||||
|
|
||||||
def clean_organization(self):
|
|
||||||
organization_id = self.cleaned_data["organization"]
|
|
||||||
try:
|
|
||||||
organization = Organization.objects.get(id=organization_id)
|
|
||||||
except Exception:
|
|
||||||
raise ValidationError(_("Group doesn't exist."))
|
|
||||||
if not organization.admins.filter(id=self.profile.id).exists():
|
|
||||||
raise ValidationError(_("You don't have permission in this group."))
|
|
||||||
return organization
|
|
||||||
|
|
||||||
|
|
||||||
class ProblemPointsVoteForm(ModelForm):
|
class ProblemPointsVoteForm(ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -547,53 +468,19 @@ class ContestProblemForm(ModelForm):
|
||||||
"problem",
|
"problem",
|
||||||
"points",
|
"points",
|
||||||
"partial",
|
"partial",
|
||||||
"show_testcases",
|
"output_prefix_override",
|
||||||
"max_submissions",
|
"max_submissions",
|
||||||
)
|
)
|
||||||
widgets = {
|
widgets = {
|
||||||
"problem": HeavySelect2Widget(
|
"problem": HeavySelect2Widget(
|
||||||
data_view="problem_select2", attrs={"style": "width: 100%"}
|
data_view="problem_select2", attrs={"style": "width:100%"}
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class ContestProblemModelFormSet(BaseModelFormSet):
|
|
||||||
def is_valid(self):
|
|
||||||
valid = super().is_valid()
|
|
||||||
|
|
||||||
if not valid:
|
|
||||||
return valid
|
|
||||||
|
|
||||||
problems = set()
|
|
||||||
duplicates = []
|
|
||||||
|
|
||||||
for form in self.forms:
|
|
||||||
if form.cleaned_data and not form.cleaned_data.get("DELETE", False):
|
|
||||||
problem = form.cleaned_data.get("problem")
|
|
||||||
if problem in problems:
|
|
||||||
duplicates.append(problem)
|
|
||||||
else:
|
|
||||||
problems.add(problem)
|
|
||||||
|
|
||||||
if duplicates:
|
|
||||||
for form in self.forms:
|
|
||||||
problem = form.cleaned_data.get("problem")
|
|
||||||
if problem in duplicates:
|
|
||||||
form.add_error("problem", _("This problem is duplicated."))
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class ContestProblemFormSet(
|
class ContestProblemFormSet(
|
||||||
formset_factory(
|
formset_factory(
|
||||||
ContestProblemForm, formset=ContestProblemModelFormSet, extra=6, can_delete=True
|
ContestProblemForm, formset=BaseModelFormSet, extra=6, can_delete=True
|
||||||
)
|
)
|
||||||
):
|
):
|
||||||
model = ContestProblem
|
model = ContestProblem
|
||||||
|
|
||||||
|
|
||||||
class TestFormatterForm(ModelForm):
|
|
||||||
class Meta:
|
|
||||||
model = TestFormatterModel
|
|
||||||
fields = ["file"]
|
|
||||||
|
|
|
@ -1,13 +1,44 @@
|
||||||
from django.utils.html import escape, mark_safe
|
from django.utils.html import escape, mark_safe
|
||||||
from judge.markdown import markdown
|
|
||||||
|
|
||||||
__all__ = ["highlight_code"]
|
__all__ = ["highlight_code"]
|
||||||
|
|
||||||
|
|
||||||
def highlight_code(code, language, linenos=True, title=None):
|
def _make_pre_code(code):
|
||||||
linenos_option = 'linenums="1"' if linenos else ""
|
return mark_safe("<pre>" + escape(code) + "</pre>")
|
||||||
title_option = f'title="{title}"' if title else ""
|
|
||||||
options = f"{{.{language} {linenos_option} {title_option}}}"
|
|
||||||
|
|
||||||
value = f"```{options}\n{code}\n```\n"
|
|
||||||
return mark_safe(markdown(value))
|
try:
|
||||||
|
import pygments
|
||||||
|
import pygments.lexers
|
||||||
|
import pygments.formatters
|
||||||
|
import pygments.util
|
||||||
|
except ImportError:
|
||||||
|
|
||||||
|
def highlight_code(code, language, cssclass=None):
|
||||||
|
return _make_pre_code(code)
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
def highlight_code(code, language, cssclass="codehilite", linenos=True):
|
||||||
|
try:
|
||||||
|
lexer = pygments.lexers.get_lexer_by_name(language)
|
||||||
|
except pygments.util.ClassNotFound:
|
||||||
|
return _make_pre_code(code)
|
||||||
|
|
||||||
|
if linenos:
|
||||||
|
return mark_safe(
|
||||||
|
pygments.highlight(
|
||||||
|
code,
|
||||||
|
lexer,
|
||||||
|
pygments.formatters.HtmlFormatter(
|
||||||
|
cssclass=cssclass, linenos="table", wrapcode=True
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return mark_safe(
|
||||||
|
pygments.highlight(
|
||||||
|
code,
|
||||||
|
lexer,
|
||||||
|
pygments.formatters.HtmlFormatter(cssclass=cssclass, wrapcode=True),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
|
@ -21,8 +21,8 @@ from . import (
|
||||||
render,
|
render,
|
||||||
social,
|
social,
|
||||||
spaceless,
|
spaceless,
|
||||||
|
submission,
|
||||||
timedelta,
|
timedelta,
|
||||||
comment,
|
|
||||||
)
|
)
|
||||||
from . import registry
|
from . import registry
|
||||||
|
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
from . import registry
|
|
||||||
|
|
||||||
from django.contrib.contenttypes.models import ContentType
|
|
||||||
|
|
||||||
from judge.models.comment import get_visible_comment_count
|
|
||||||
from judge.caching import cache_wrapper
|
|
||||||
|
|
||||||
|
|
||||||
@registry.function
|
|
||||||
def comment_count(obj):
|
|
||||||
content_type = ContentType.objects.get_for_model(obj)
|
|
||||||
return get_visible_comment_count(content_type, obj.pk)
|
|
|
@ -23,5 +23,5 @@ registry.filter(localtime_wrapper(time))
|
||||||
|
|
||||||
@registry.function
|
@registry.function
|
||||||
@registry.render_with("widgets/relative-time.html")
|
@registry.render_with("widgets/relative-time.html")
|
||||||
def relative_time(time, format=_("N j, Y, g:i a"), rel=_("{time}"), abs=_("{time}")):
|
def relative_time(time, format=_("N j, Y, g:i a"), rel=_("{time}"), abs=_("on {time}")):
|
||||||
return {"time": time, "format": format, "rel_format": rel, "abs_format": abs}
|
return {"time": time, "format": format, "rel_format": rel, "abs_format": abs}
|
||||||
|
|
|
@ -9,16 +9,14 @@ from . import registry
|
||||||
|
|
||||||
|
|
||||||
@registry.function
|
@registry.function
|
||||||
def gravatar(profile, size=80, default=None, profile_image=None, email=None):
|
def gravatar(email, size=80, default=None):
|
||||||
if profile and not profile.is_muted:
|
if isinstance(email, Profile):
|
||||||
if profile_image:
|
|
||||||
return profile_image
|
|
||||||
if profile and profile.profile_image_url:
|
|
||||||
return profile.profile_image_url
|
|
||||||
if profile:
|
|
||||||
email = email or profile.email
|
|
||||||
if default is None:
|
if default is None:
|
||||||
default = profile.is_muted
|
default = email.mute
|
||||||
|
email = email.user.email
|
||||||
|
elif isinstance(email, AbstractUser):
|
||||||
|
email = email.email
|
||||||
|
|
||||||
gravatar_url = (
|
gravatar_url = (
|
||||||
"//www.gravatar.com/avatar/"
|
"//www.gravatar.com/avatar/"
|
||||||
+ hashlib.md5(utf8bytes(email.strip().lower())).hexdigest()
|
+ hashlib.md5(utf8bytes(email.strip().lower())).hexdigest()
|
||||||
|
|
|
@ -1,7 +1,112 @@
|
||||||
from .. import registry
|
from .. import registry
|
||||||
from judge.markdown import markdown as _markdown
|
import markdown as _markdown
|
||||||
|
import bleach
|
||||||
|
from django.utils.html import escape
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
from pymdownx import superfences
|
||||||
|
|
||||||
|
|
||||||
|
EXTENSIONS = [
|
||||||
|
"pymdownx.arithmatex",
|
||||||
|
"pymdownx.magiclink",
|
||||||
|
"pymdownx.betterem",
|
||||||
|
"pymdownx.details",
|
||||||
|
"pymdownx.emoji",
|
||||||
|
"pymdownx.inlinehilite",
|
||||||
|
"pymdownx.superfences",
|
||||||
|
"pymdownx.tasklist",
|
||||||
|
"markdown.extensions.footnotes",
|
||||||
|
"markdown.extensions.attr_list",
|
||||||
|
"markdown.extensions.def_list",
|
||||||
|
"markdown.extensions.tables",
|
||||||
|
"markdown.extensions.admonition",
|
||||||
|
"nl2br",
|
||||||
|
"mdx_breakless_lists",
|
||||||
|
]
|
||||||
|
|
||||||
|
EXTENSION_CONFIGS = {
|
||||||
|
"pymdownx.superfences": {
|
||||||
|
"custom_fences": [
|
||||||
|
{
|
||||||
|
"name": "sample",
|
||||||
|
"class": "no-border",
|
||||||
|
"format": superfences.fence_code_format,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
ALLOWED_TAGS = bleach.sanitizer.ALLOWED_TAGS + [
|
||||||
|
"img",
|
||||||
|
"center",
|
||||||
|
"iframe",
|
||||||
|
"div",
|
||||||
|
"span",
|
||||||
|
"table",
|
||||||
|
"tr",
|
||||||
|
"td",
|
||||||
|
"th",
|
||||||
|
"tr",
|
||||||
|
"pre",
|
||||||
|
"code",
|
||||||
|
"p",
|
||||||
|
"hr",
|
||||||
|
"h1",
|
||||||
|
"h2",
|
||||||
|
"h3",
|
||||||
|
"h4",
|
||||||
|
"h5",
|
||||||
|
"h6",
|
||||||
|
"thead",
|
||||||
|
"tbody",
|
||||||
|
"sup",
|
||||||
|
"dl",
|
||||||
|
"dt",
|
||||||
|
"dd",
|
||||||
|
"br",
|
||||||
|
"details",
|
||||||
|
"summary",
|
||||||
|
]
|
||||||
|
|
||||||
|
ALLOWED_ATTRS = ["src", "width", "height", "href", "class", "open"]
|
||||||
|
|
||||||
|
|
||||||
@registry.filter
|
@registry.filter
|
||||||
def markdown(value, lazy_load=False):
|
def markdown(value, lazy_load=False):
|
||||||
return _markdown(value, lazy_load)
|
extensions = EXTENSIONS
|
||||||
|
html = _markdown.markdown(
|
||||||
|
value, extensions=extensions, extension_configs=EXTENSION_CONFIGS
|
||||||
|
)
|
||||||
|
|
||||||
|
# Don't clean mathjax
|
||||||
|
hash_script_tag = {}
|
||||||
|
soup = BeautifulSoup(html, "html.parser")
|
||||||
|
for script_tag in soup.find_all("script"):
|
||||||
|
allow_math_types = ["math/tex", "math/tex; mode=display"]
|
||||||
|
if script_tag.attrs.get("type", False) in allow_math_types:
|
||||||
|
hash_script_tag[str(hash(str(script_tag)))] = str(script_tag)
|
||||||
|
|
||||||
|
for hashed_tag in hash_script_tag:
|
||||||
|
tag = hash_script_tag[hashed_tag]
|
||||||
|
html = html.replace(tag, hashed_tag)
|
||||||
|
|
||||||
|
html = bleach.clean(html, tags=ALLOWED_TAGS, attributes=ALLOWED_ATTRS)
|
||||||
|
|
||||||
|
for hashed_tag in hash_script_tag:
|
||||||
|
tag = hash_script_tag[hashed_tag]
|
||||||
|
html = html.replace(hashed_tag, tag)
|
||||||
|
|
||||||
|
if not html:
|
||||||
|
html = escape(value)
|
||||||
|
if lazy_load or True:
|
||||||
|
soup = BeautifulSoup(html, features="html.parser")
|
||||||
|
for img in soup.findAll("img"):
|
||||||
|
if img.get("src"):
|
||||||
|
img["data-src"] = img["src"]
|
||||||
|
img["src"] = ""
|
||||||
|
for img in soup.findAll("iframe"):
|
||||||
|
if img.get("src"):
|
||||||
|
img["data-src"] = img["src"]
|
||||||
|
img["src"] = ""
|
||||||
|
html = str(soup)
|
||||||
|
return '<div class="md-typeset">%s</div>' % html
|
||||||
|
|
|
@ -155,16 +155,16 @@ def item_title(item):
|
||||||
|
|
||||||
@registry.function
|
@registry.function
|
||||||
@registry.render_with("user/link.html")
|
@registry.render_with("user/link.html")
|
||||||
def link_user(user, show_image=False):
|
def link_user(user):
|
||||||
if isinstance(user, Profile):
|
if isinstance(user, Profile):
|
||||||
profile = user
|
user, profile = user.user, user
|
||||||
elif isinstance(user, AbstractUser):
|
elif isinstance(user, AbstractUser):
|
||||||
profile = user.profile
|
profile = user.profile
|
||||||
elif isinstance(user, int):
|
elif type(user).__name__ == "ContestRankingProfile":
|
||||||
profile = Profile(id=user)
|
user, profile = user.user, user
|
||||||
else:
|
else:
|
||||||
raise ValueError("Expected profile or user, got %s" % (type(user),))
|
raise ValueError("Expected profile or user, got %s" % (type(user),))
|
||||||
return {"profile": profile, "show_image": show_image}
|
return {"user": user, "profile": profile}
|
||||||
|
|
||||||
|
|
||||||
@registry.function
|
@registry.function
|
||||||
|
|
|
@ -48,9 +48,5 @@ for name, template, url_func in SHARES:
|
||||||
@registry.function
|
@registry.function
|
||||||
def recaptcha_init(language=None):
|
def recaptcha_init(language=None):
|
||||||
return get_template("snowpenguin/recaptcha/recaptcha_init.html").render(
|
return get_template("snowpenguin/recaptcha/recaptcha_init.html").render(
|
||||||
{
|
{"explicit": False, "language": language}
|
||||||
"explicit": False,
|
|
||||||
"language": language,
|
|
||||||
"recaptcha_host": "https://google.com",
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
36
judge/jinja2/submission.py
Normal file
36
judge/jinja2/submission.py
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
from . import registry
|
||||||
|
|
||||||
|
|
||||||
|
@registry.function
|
||||||
|
def submission_layout(
|
||||||
|
submission, profile_id, user, editable_problem_ids, completed_problem_ids
|
||||||
|
):
|
||||||
|
problem_id = submission.problem_id
|
||||||
|
can_view = False
|
||||||
|
|
||||||
|
if problem_id in editable_problem_ids:
|
||||||
|
can_view = True
|
||||||
|
|
||||||
|
if profile_id == submission.user_id:
|
||||||
|
can_view = True
|
||||||
|
|
||||||
|
if user.has_perm("judge.change_submission"):
|
||||||
|
can_view = True
|
||||||
|
|
||||||
|
if user.has_perm("judge.view_all_submission"):
|
||||||
|
can_view = True
|
||||||
|
|
||||||
|
if submission.problem.is_public and user.has_perm("judge.view_public_submission"):
|
||||||
|
can_view = True
|
||||||
|
|
||||||
|
if submission.problem_id in completed_problem_ids:
|
||||||
|
can_view |= (
|
||||||
|
submission.problem.is_public or profile_id in submission.problem.tester_ids
|
||||||
|
)
|
||||||
|
|
||||||
|
if not can_view and hasattr(submission, "contest"):
|
||||||
|
contest = submission.contest.participation.contest
|
||||||
|
if contest.is_editable_by(user):
|
||||||
|
can_view = True
|
||||||
|
|
||||||
|
return can_view
|
|
@ -1,12 +0,0 @@
|
||||||
import logging
|
|
||||||
|
|
||||||
error_log = logging.getLogger("judge.errors")
|
|
||||||
debug_log = logging.getLogger("judge.debug")
|
|
||||||
|
|
||||||
|
|
||||||
def log_exception(msg):
|
|
||||||
error_log.exception(msg)
|
|
||||||
|
|
||||||
|
|
||||||
def log_debug(category, data):
|
|
||||||
debug_log.info(f"{category}: {data}")
|
|
|
@ -1,5 +1,6 @@
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from judge.models import *
|
from judge.models import *
|
||||||
|
from collections import defaultdict
|
||||||
import csv
|
import csv
|
||||||
import os
|
import os
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
|
@ -89,13 +89,14 @@ class Command(BaseCommand):
|
||||||
if trans is None
|
if trans is None
|
||||||
else trans.description,
|
else trans.description,
|
||||||
"url": "",
|
"url": "",
|
||||||
|
"math_engine": maker.math_engine,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.replace('"//', '"https://')
|
.replace('"//', '"https://')
|
||||||
.replace("'//", "'https://")
|
.replace("'//", "'https://")
|
||||||
)
|
)
|
||||||
maker.title = problem_name
|
maker.title = problem_name
|
||||||
for file in "style.css":
|
for file in ("style.css", "pygment-github.css", "mathjax3_config.js"):
|
||||||
maker.load(file, os.path.join(settings.DMOJ_RESOURCES, file))
|
maker.load(file, os.path.join(settings.DMOJ_RESOURCES, file))
|
||||||
maker.make(debug=True)
|
maker.make(debug=True)
|
||||||
if not maker.success:
|
if not maker.success:
|
||||||
|
|
|
@ -1,149 +0,0 @@
|
||||||
import markdown as _markdown
|
|
||||||
import bleach
|
|
||||||
from django.utils.html import escape
|
|
||||||
from bs4 import BeautifulSoup
|
|
||||||
from pymdownx import superfences
|
|
||||||
from django.conf import settings
|
|
||||||
from urllib.parse import urlparse
|
|
||||||
|
|
||||||
from judge.markdown_extensions import YouTubeExtension, EmoticonExtension
|
|
||||||
|
|
||||||
|
|
||||||
EXTENSIONS = [
|
|
||||||
"pymdownx.arithmatex",
|
|
||||||
"pymdownx.magiclink",
|
|
||||||
"pymdownx.betterem",
|
|
||||||
"pymdownx.details",
|
|
||||||
"pymdownx.emoji",
|
|
||||||
"pymdownx.inlinehilite",
|
|
||||||
"pymdownx.superfences",
|
|
||||||
"pymdownx.highlight",
|
|
||||||
"pymdownx.tasklist",
|
|
||||||
"markdown.extensions.footnotes",
|
|
||||||
"markdown.extensions.attr_list",
|
|
||||||
"markdown.extensions.def_list",
|
|
||||||
"markdown.extensions.tables",
|
|
||||||
"markdown.extensions.admonition",
|
|
||||||
"nl2br",
|
|
||||||
"mdx_breakless_lists",
|
|
||||||
YouTubeExtension(),
|
|
||||||
EmoticonExtension(),
|
|
||||||
]
|
|
||||||
|
|
||||||
EXTENSION_CONFIGS = {
|
|
||||||
"pymdownx.arithmatex": {
|
|
||||||
"generic": True,
|
|
||||||
},
|
|
||||||
"pymdownx.superfences": {
|
|
||||||
"custom_fences": [
|
|
||||||
{
|
|
||||||
"name": "sample",
|
|
||||||
"class": "no-border",
|
|
||||||
"format": superfences.fence_code_format,
|
|
||||||
}
|
|
||||||
],
|
|
||||||
},
|
|
||||||
"pymdownx.highlight": {
|
|
||||||
"auto_title": True,
|
|
||||||
"auto_title_map": {
|
|
||||||
"Text Only": "",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
ALLOWED_TAGS = list(bleach.sanitizer.ALLOWED_TAGS) + [
|
|
||||||
"img",
|
|
||||||
"center",
|
|
||||||
"iframe",
|
|
||||||
"div",
|
|
||||||
"span",
|
|
||||||
"table",
|
|
||||||
"tr",
|
|
||||||
"td",
|
|
||||||
"th",
|
|
||||||
"tr",
|
|
||||||
"pre",
|
|
||||||
"code",
|
|
||||||
"p",
|
|
||||||
"hr",
|
|
||||||
"h1",
|
|
||||||
"h2",
|
|
||||||
"h3",
|
|
||||||
"h4",
|
|
||||||
"h5",
|
|
||||||
"h6",
|
|
||||||
"thead",
|
|
||||||
"tbody",
|
|
||||||
"sup",
|
|
||||||
"dl",
|
|
||||||
"dt",
|
|
||||||
"dd",
|
|
||||||
"br",
|
|
||||||
"details",
|
|
||||||
"summary",
|
|
||||||
]
|
|
||||||
|
|
||||||
ALLOWED_ATTRS = [
|
|
||||||
"src",
|
|
||||||
"width",
|
|
||||||
"height",
|
|
||||||
"href",
|
|
||||||
"class",
|
|
||||||
"open",
|
|
||||||
"title",
|
|
||||||
"frameborder",
|
|
||||||
"allow",
|
|
||||||
"allowfullscreen",
|
|
||||||
"loading",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def _wrap_img_iframe_with_lazy_load(soup):
|
|
||||||
for img in soup.findAll("img"):
|
|
||||||
if img.get("src"):
|
|
||||||
img["loading"] = "lazy"
|
|
||||||
for img in soup.findAll("iframe"):
|
|
||||||
if img.get("src"):
|
|
||||||
img["loading"] = "lazy"
|
|
||||||
return soup
|
|
||||||
|
|
||||||
|
|
||||||
def _wrap_images_with_featherlight(soup):
|
|
||||||
for img in soup.findAll("img"):
|
|
||||||
if img.get("src"):
|
|
||||||
link = soup.new_tag("a", href=img["src"], **{"data-featherlight": "image"})
|
|
||||||
img.wrap(link)
|
|
||||||
return soup
|
|
||||||
|
|
||||||
|
|
||||||
def _open_external_links_in_new_tab(soup):
|
|
||||||
domain = settings.SITE_DOMAIN.lower()
|
|
||||||
for a in soup.findAll("a", href=True):
|
|
||||||
href = a["href"]
|
|
||||||
if href.startswith("http://") or href.startswith("https://"):
|
|
||||||
link_domain = urlparse(href).netloc.lower()
|
|
||||||
if link_domain != domain:
|
|
||||||
a["target"] = "_blank"
|
|
||||||
return soup
|
|
||||||
|
|
||||||
|
|
||||||
def markdown(value, lazy_load=False):
|
|
||||||
extensions = EXTENSIONS
|
|
||||||
html = _markdown.markdown(
|
|
||||||
value, extensions=extensions, extension_configs=EXTENSION_CONFIGS
|
|
||||||
)
|
|
||||||
|
|
||||||
html = bleach.clean(html, tags=ALLOWED_TAGS, attributes=ALLOWED_ATTRS)
|
|
||||||
|
|
||||||
if not html:
|
|
||||||
html = escape(value)
|
|
||||||
|
|
||||||
soup = BeautifulSoup(html, features="html.parser")
|
|
||||||
if lazy_load:
|
|
||||||
soup = _wrap_img_iframe_with_lazy_load(soup)
|
|
||||||
|
|
||||||
soup = _wrap_images_with_featherlight(soup)
|
|
||||||
soup = _open_external_links_in_new_tab(soup)
|
|
||||||
html = str(soup)
|
|
||||||
|
|
||||||
return '<div class="md-typeset content-description">%s</div>' % html
|
|
|
@ -1,2 +0,0 @@
|
||||||
from .youtube import YouTubeExtension
|
|
||||||
from .emoticon import EmoticonExtension
|
|
|
@ -1,112 +0,0 @@
|
||||||
import markdown
|
|
||||||
from markdown.extensions import Extension
|
|
||||||
from markdown.inlinepatterns import InlineProcessor
|
|
||||||
import xml.etree.ElementTree as etree
|
|
||||||
import re
|
|
||||||
|
|
||||||
EMOTICON_EMOJI_MAP = {
|
|
||||||
":D": "\U0001F603", # Smiling Face with Open Mouth
|
|
||||||
":)": "\U0001F642", # Slightly Smiling Face
|
|
||||||
":-)": "\U0001F642", # Slightly Smiling Face with Nose
|
|
||||||
":(": "\U0001F641", # Slightly Frowning Face
|
|
||||||
":-(": "\U0001F641", # Slightly Frowning Face with Nose
|
|
||||||
";)": "\U0001F609", # Winking Face
|
|
||||||
";-)": "\U0001F609", # Winking Face with Nose
|
|
||||||
":P": "\U0001F61B", # Face with Tongue
|
|
||||||
":-P": "\U0001F61B", # Face with Tongue and Nose
|
|
||||||
":p": "\U0001F61B", # Face with Tongue
|
|
||||||
":-p": "\U0001F61B", # Face with Tongue and Nose
|
|
||||||
";P": "\U0001F61C", # Winking Face with Tongue
|
|
||||||
";-P": "\U0001F61C", # Winking Face with Tongue and Nose
|
|
||||||
";p": "\U0001F61C", # Winking Face with Tongue
|
|
||||||
";-p": "\U0001F61C", # Winking Face with Tongue and Nose
|
|
||||||
":'(": "\U0001F622", # Crying Face
|
|
||||||
":o": "\U0001F62E", # Face with Open Mouth
|
|
||||||
":-o": "\U0001F62E", # Face with Open Mouth and Nose
|
|
||||||
":O": "\U0001F62E", # Face with Open Mouth
|
|
||||||
":-O": "\U0001F62E", # Face with Open Mouth and Nose
|
|
||||||
":-0": "\U0001F62E", # Face with Open Mouth and Nose
|
|
||||||
">:(": "\U0001F620", # Angry Face
|
|
||||||
">:-(": "\U0001F620", # Angry Face with Nose
|
|
||||||
">:)": "\U0001F608", # Smiling Face with Horns
|
|
||||||
">:-)": "\U0001F608", # Smiling Face with Horns and Nose
|
|
||||||
"XD": "\U0001F606", # Grinning Squinting Face
|
|
||||||
"xD": "\U0001F606", # Grinning Squinting Face
|
|
||||||
"B)": "\U0001F60E", # Smiling Face with Sunglasses
|
|
||||||
"B-)": "\U0001F60E", # Smiling Face with Sunglasses and Nose
|
|
||||||
"O:)": "\U0001F607", # Smiling Face with Halo
|
|
||||||
"O:-)": "\U0001F607", # Smiling Face with Halo and Nose
|
|
||||||
"0:)": "\U0001F607", # Smiling Face with Halo
|
|
||||||
"0:-)": "\U0001F607", # Smiling Face with Halo and Nose
|
|
||||||
">:P": "\U0001F92A", # Zany Face (sticking out tongue and winking)
|
|
||||||
">:-P": "\U0001F92A", # Zany Face with Nose
|
|
||||||
">:p": "\U0001F92A", # Zany Face (sticking out tongue and winking)
|
|
||||||
">:-p": "\U0001F92A", # Zany Face with Nose
|
|
||||||
":/": "\U0001F615", # Confused Face
|
|
||||||
":-/": "\U0001F615", # Confused Face with Nose
|
|
||||||
":\\": "\U0001F615", # Confused Face
|
|
||||||
":-\\": "\U0001F615", # Confused Face with Nose
|
|
||||||
"3:)": "\U0001F608", # Smiling Face with Horns
|
|
||||||
"3:-)": "\U0001F608", # Smiling Face with Horns and Nose
|
|
||||||
"<3": "\u2764\uFE0F", # Red Heart
|
|
||||||
"</3": "\U0001F494", # Broken Heart
|
|
||||||
":*": "\U0001F618", # Face Blowing a Kiss
|
|
||||||
":-*": "\U0001F618", # Face Blowing a Kiss with Nose
|
|
||||||
";P": "\U0001F61C", # Winking Face with Tongue
|
|
||||||
";-P": "\U0001F61C",
|
|
||||||
">:P": "\U0001F61D", # Face with Stuck-Out Tongue and Tightly-Closed Eyes
|
|
||||||
":-/": "\U0001F615", # Confused Face
|
|
||||||
":/": "\U0001F615",
|
|
||||||
":\\": "\U0001F615",
|
|
||||||
":-\\": "\U0001F615",
|
|
||||||
":|": "\U0001F610", # Neutral Face
|
|
||||||
":-|": "\U0001F610",
|
|
||||||
"8)": "\U0001F60E", # Smiling Face with Sunglasses
|
|
||||||
"8-)": "\U0001F60E",
|
|
||||||
"O:)": "\U0001F607", # Smiling Face with Halo
|
|
||||||
"O:-)": "\U0001F607",
|
|
||||||
":3": "\U0001F60A", # Smiling Face with Smiling Eyes
|
|
||||||
"^.^": "\U0001F60A",
|
|
||||||
"-_-": "\U0001F611", # Expressionless Face
|
|
||||||
"T_T": "\U0001F62D", # Loudly Crying Face
|
|
||||||
"T.T": "\U0001F62D",
|
|
||||||
">.<": "\U0001F623", # Persevering Face
|
|
||||||
"x_x": "\U0001F635", # Dizzy Face
|
|
||||||
"X_X": "\U0001F635",
|
|
||||||
":]": "\U0001F600", # Grinning Face
|
|
||||||
":[": "\U0001F641", # Slightly Frowning Face
|
|
||||||
"=]": "\U0001F600",
|
|
||||||
"=[": "\U0001F641",
|
|
||||||
"D:<": "\U0001F621", # Pouting Face
|
|
||||||
"D:": "\U0001F629", # Weary Face
|
|
||||||
"D=": "\U0001F6AB", # No Entry Sign (sometimes used to denote dismay or frustration)
|
|
||||||
":'D": "\U0001F602", # Face with Tears of Joy
|
|
||||||
"D':": "\U0001F625", # Disappointed but Relieved Face
|
|
||||||
"D8": "\U0001F631", # Face Screaming in Fear
|
|
||||||
"-.-": "\U0001F644", # Face with Rolling Eyes
|
|
||||||
"-_-;": "\U0001F612", # Unamused
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class EmoticonEmojiInlineProcessor(InlineProcessor):
|
|
||||||
def handleMatch(self, m, data):
|
|
||||||
emoticon = m.group(1)
|
|
||||||
emoji = EMOTICON_EMOJI_MAP.get(emoticon, "")
|
|
||||||
if emoji:
|
|
||||||
el = etree.Element("span")
|
|
||||||
el.text = markdown.util.AtomicString(emoji)
|
|
||||||
el.set("class", "big-emoji")
|
|
||||||
return el, m.start(0), m.end(0)
|
|
||||||
else:
|
|
||||||
return None, m.start(0), m.end(0)
|
|
||||||
|
|
||||||
|
|
||||||
class EmoticonExtension(Extension):
|
|
||||||
def extendMarkdown(self, md):
|
|
||||||
emoticon_pattern = (
|
|
||||||
r"(?:(?<=\s)|^)" # Lookbehind for a whitespace character or the start of the string
|
|
||||||
r"(" + "|".join(map(re.escape, EMOTICON_EMOJI_MAP.keys())) + r")"
|
|
||||||
r"(?=\s|$)" # Lookahead for a whitespace character or the end of the string
|
|
||||||
)
|
|
||||||
emoticon_processor = EmoticonEmojiInlineProcessor(emoticon_pattern, md)
|
|
||||||
md.inlinePatterns.register(emoticon_processor, "emoticon_to_emoji", 1)
|
|
|
@ -1,36 +0,0 @@
|
||||||
import markdown
|
|
||||||
from markdown.inlinepatterns import InlineProcessor
|
|
||||||
from markdown.extensions import Extension
|
|
||||||
import xml.etree.ElementTree as etree
|
|
||||||
|
|
||||||
YOUTUBE_REGEX = (
|
|
||||||
r"(https?://)?(www\.)?" "(youtube\.com/watch\?v=|youtu\.be/)" "([\w-]+)(&[\w=]*)?"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class YouTubeEmbedProcessor(InlineProcessor):
|
|
||||||
def handleMatch(self, m, data):
|
|
||||||
youtube_id = m.group(4)
|
|
||||||
if not youtube_id:
|
|
||||||
return None, None, None
|
|
||||||
|
|
||||||
# Create an iframe element with the YouTube embed URL
|
|
||||||
iframe = etree.Element("iframe")
|
|
||||||
iframe.set("width", "100%")
|
|
||||||
iframe.set("height", "360")
|
|
||||||
iframe.set("src", f"https://www.youtube.com/embed/{youtube_id}")
|
|
||||||
iframe.set("frameborder", "0")
|
|
||||||
iframe.set("allowfullscreen", "true")
|
|
||||||
center = etree.Element("center")
|
|
||||||
center.append(iframe)
|
|
||||||
|
|
||||||
# Return the iframe as the element to replace the match, along with the start and end indices
|
|
||||||
return center, m.start(0), m.end(0)
|
|
||||||
|
|
||||||
|
|
||||||
class YouTubeExtension(Extension):
|
|
||||||
def extendMarkdown(self, md):
|
|
||||||
# Create the YouTube link pattern
|
|
||||||
YOUTUBE_PATTERN = YouTubeEmbedProcessor(YOUTUBE_REGEX, md)
|
|
||||||
# Register the pattern to apply the YouTubeEmbedProcessor
|
|
||||||
md.inlinePatterns.register(YOUTUBE_PATTERN, "youtube", 175)
|
|
|
@ -1,9 +1,3 @@
|
||||||
import time
|
|
||||||
import logging
|
|
||||||
import random
|
|
||||||
import json
|
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.http import HttpResponseRedirect, Http404
|
from django.http import HttpResponseRedirect, Http404
|
||||||
from django.urls import Resolver404, resolve, reverse
|
from django.urls import Resolver404, resolve, reverse
|
||||||
|
@ -17,7 +11,6 @@ from judge.utils.views import generic_message
|
||||||
|
|
||||||
|
|
||||||
USED_DOMAINS = ["www"]
|
USED_DOMAINS = ["www"]
|
||||||
URL_NAMES_BYPASS_SUBDOMAIN = ["submission_source_file"]
|
|
||||||
|
|
||||||
|
|
||||||
class ShortCircuitMiddleware:
|
class ShortCircuitMiddleware:
|
||||||
|
@ -118,10 +111,7 @@ class SubdomainMiddleware(object):
|
||||||
|
|
||||||
subdomain = subdomain[:-1]
|
subdomain = subdomain[:-1]
|
||||||
|
|
||||||
if (
|
if subdomain in USED_DOMAINS:
|
||||||
subdomain in USED_DOMAINS
|
|
||||||
or resolve(request.path).url_name in URL_NAMES_BYPASS_SUBDOMAIN
|
|
||||||
):
|
|
||||||
return self.get_response(request)
|
return self.get_response(request)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -148,33 +138,3 @@ class SubdomainMiddleware(object):
|
||||||
status=404,
|
status=404,
|
||||||
)
|
)
|
||||||
return self.get_response(request)
|
return self.get_response(request)
|
||||||
|
|
||||||
|
|
||||||
class SlowRequestMiddleware(object):
|
|
||||||
def __init__(self, get_response):
|
|
||||||
self.get_response = get_response
|
|
||||||
|
|
||||||
def __call__(self, request):
|
|
||||||
logger = logging.getLogger("judge.request_time")
|
|
||||||
logger_slow = logging.getLogger("judge.slow_request")
|
|
||||||
start_time = time.time()
|
|
||||||
response = self.get_response(request)
|
|
||||||
if response.status_code == 200:
|
|
||||||
try:
|
|
||||||
response_time = time.time() - start_time
|
|
||||||
url_name = resolve(request.path).url_name
|
|
||||||
message = {
|
|
||||||
"url_name": url_name,
|
|
||||||
"response_time": response_time * 1000,
|
|
||||||
"profile": request.user.username,
|
|
||||||
"date": datetime.now().strftime("%Y/%m/%d"),
|
|
||||||
"url": request.build_absolute_uri(),
|
|
||||||
"method": request.method,
|
|
||||||
}
|
|
||||||
if response_time > 9:
|
|
||||||
logger_slow.info(json.dumps(message))
|
|
||||||
if random.random() < 0.1:
|
|
||||||
logger.info(json.dumps(message))
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
return response
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import lxml.html as lh
|
import lxml.html as lh
|
||||||
from django.db import migrations
|
from django.db import migrations
|
||||||
from lxml_html_clean import clean_html
|
from lxml.html.clean import clean_html
|
||||||
|
|
||||||
|
|
||||||
def strip_error_html(apps, schema_editor):
|
def strip_error_html(apps, schema_editor):
|
||||||
|
|
File diff suppressed because one or more lines are too long
19
judge/migrations/0151_alter_courseassignment_course.py
Normal file
19
judge/migrations/0151_alter_courseassignment_course.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# Generated by Django 3.2.17 on 2023-02-15 04:28
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('judge', '0150_alter_profile_timezone'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='courseassignment',
|
||||||
|
name='course',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='judge.course', verbose_name='course'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,50 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2023-02-20 21:26
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("contenttypes", "0002_remove_content_type_name"),
|
|
||||||
("judge", "0150_alter_profile_timezone"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="comment",
|
|
||||||
name="content_type",
|
|
||||||
field=models.ForeignKey(
|
|
||||||
null=True,
|
|
||||||
on_delete=django.db.models.deletion.CASCADE,
|
|
||||||
to="contenttypes.contenttype",
|
|
||||||
),
|
|
||||||
preserve_default=False,
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="comment",
|
|
||||||
name="object_id",
|
|
||||||
field=models.PositiveIntegerField(null=True),
|
|
||||||
preserve_default=False,
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name="solution",
|
|
||||||
name="problem",
|
|
||||||
field=models.OneToOneField(
|
|
||||||
blank=True,
|
|
||||||
null=True,
|
|
||||||
on_delete=django.db.models.deletion.CASCADE,
|
|
||||||
related_name="solution",
|
|
||||||
to="judge.problem",
|
|
||||||
verbose_name="associated problem",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
migrations.AddIndex(
|
|
||||||
model_name="comment",
|
|
||||||
index=models.Index(
|
|
||||||
fields=["content_type", "object_id"],
|
|
||||||
name="judge_comme_content_2dce05_idx",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]
|
|
19
judge/migrations/0152_alter_courserole_course.py
Normal file
19
judge/migrations/0152_alter_courserole_course.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# Generated by Django 3.2.17 on 2023-02-22 08:08
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('judge', '0151_alter_courseassignment_course'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='courserole',
|
||||||
|
name='course',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='judge.course', verbose_name='course'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,54 +0,0 @@
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
|
||||||
|
|
||||||
|
|
||||||
def migrate_comments(apps, schema_editor):
|
|
||||||
Comment = apps.get_model("judge", "Comment")
|
|
||||||
Problem = apps.get_model("judge", "Problem")
|
|
||||||
Solution = apps.get_model("judge", "Solution")
|
|
||||||
BlogPost = apps.get_model("judge", "BlogPost")
|
|
||||||
Contest = apps.get_model("judge", "Contest")
|
|
||||||
|
|
||||||
for comment in Comment.objects.all():
|
|
||||||
page = comment.page
|
|
||||||
try:
|
|
||||||
if page.startswith("p:"):
|
|
||||||
code = page[2:]
|
|
||||||
comment.linked_object = Problem.objects.get(code=code)
|
|
||||||
elif page.startswith("s:"):
|
|
||||||
code = page[2:]
|
|
||||||
comment.linked_object = Solution.objects.get(problem__code=code)
|
|
||||||
elif page.startswith("c:"):
|
|
||||||
key = page[2:]
|
|
||||||
comment.linked_object = Contest.objects.get(key=key)
|
|
||||||
elif page.startswith("b:"):
|
|
||||||
blog_id = page[2:]
|
|
||||||
comment.linked_object = BlogPost.objects.get(id=blog_id)
|
|
||||||
comment.save()
|
|
||||||
except ObjectDoesNotExist:
|
|
||||||
comment.delete()
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
dependencies = [
|
|
||||||
("contenttypes", "0002_remove_content_type_name"),
|
|
||||||
("judge", "0151_comment_content_type"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.RunPython(migrate_comments, migrations.RunPython.noop, atomic=True),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name="comment",
|
|
||||||
name="content_type",
|
|
||||||
field=models.ForeignKey(
|
|
||||||
on_delete=django.db.models.deletion.CASCADE,
|
|
||||||
to="contenttypes.contenttype",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name="comment",
|
|
||||||
name="object_id",
|
|
||||||
field=models.PositiveIntegerField(),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,24 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2023-02-20 23:46
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0152_migrate_comments"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.RemoveField(
|
|
||||||
model_name="comment",
|
|
||||||
name="page",
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name="commentlock",
|
|
||||||
name="page",
|
|
||||||
field=models.CharField(
|
|
||||||
db_index=True, max_length=30, verbose_name="associated page"
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,27 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2023-03-08 01:55
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0153_drop_comment_page"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddIndex(
|
|
||||||
model_name="submission",
|
|
||||||
index=models.Index(
|
|
||||||
fields=["problem", "user", "-points"],
|
|
||||||
name="judge_submi_problem_5687ea_idx",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
migrations.AddIndex(
|
|
||||||
model_name="submission",
|
|
||||||
index=models.Index(
|
|
||||||
fields=["contest_object", "problem", "user", "-points"],
|
|
||||||
name="judge_submi_contest_31cdbb_idx",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,22 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2023-03-10 04:24
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0154_add_submission_indexes"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="problemdata",
|
|
||||||
name="output_only",
|
|
||||||
field=models.BooleanField(
|
|
||||||
help_text="Support output-only problem",
|
|
||||||
null=True,
|
|
||||||
verbose_name="is output only",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,48 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2023-07-31 18:07
|
|
||||||
|
|
||||||
import django.core.validators
|
|
||||||
from django.db import migrations, models
|
|
||||||
import judge.models.problem_data
|
|
||||||
import judge.utils.problem_data
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0155_output_only"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="problemdata",
|
|
||||||
name="signature_handler",
|
|
||||||
field=models.FileField(
|
|
||||||
blank=True,
|
|
||||||
null=True,
|
|
||||||
storage=judge.utils.problem_data.ProblemDataStorage(),
|
|
||||||
upload_to=judge.models.problem_data.problem_directory_file,
|
|
||||||
validators=[
|
|
||||||
django.core.validators.FileExtensionValidator(
|
|
||||||
allowed_extensions=["cpp"]
|
|
||||||
)
|
|
||||||
],
|
|
||||||
verbose_name="signature handler",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="problemdata",
|
|
||||||
name="signature_header",
|
|
||||||
field=models.FileField(
|
|
||||||
blank=True,
|
|
||||||
null=True,
|
|
||||||
storage=judge.utils.problem_data.ProblemDataStorage(),
|
|
||||||
upload_to=judge.models.problem_data.problem_directory_file,
|
|
||||||
validators=[
|
|
||||||
django.core.validators.FileExtensionValidator(
|
|
||||||
allowed_extensions=["h"]
|
|
||||||
)
|
|
||||||
],
|
|
||||||
verbose_name="signature header",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,22 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2023-08-01 04:45
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0156_auto_20230801_0107"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="problemdata",
|
|
||||||
name="use_ioi_signature",
|
|
||||||
field=models.BooleanField(
|
|
||||||
help_text="Use IOI Signature",
|
|
||||||
null=True,
|
|
||||||
verbose_name="is IOI signature",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,70 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2023-08-03 07:40
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
|
||||||
|
|
||||||
|
|
||||||
def migrate_pagevote(apps, schema_editor):
|
|
||||||
PageVote = apps.get_model("judge", "PageVote")
|
|
||||||
Problem = apps.get_model("judge", "Problem")
|
|
||||||
Solution = apps.get_model("judge", "Solution")
|
|
||||||
BlogPost = apps.get_model("judge", "BlogPost")
|
|
||||||
Contest = apps.get_model("judge", "Contest")
|
|
||||||
|
|
||||||
for vote in PageVote.objects.all():
|
|
||||||
page = vote.page
|
|
||||||
try:
|
|
||||||
if page.startswith("p:"):
|
|
||||||
code = page[2:]
|
|
||||||
vote.linked_object = Problem.objects.get(code=code)
|
|
||||||
elif page.startswith("s:"):
|
|
||||||
code = page[2:]
|
|
||||||
vote.linked_object = Solution.objects.get(problem__code=code)
|
|
||||||
elif page.startswith("c:"):
|
|
||||||
key = page[2:]
|
|
||||||
vote.linked_object = Contest.objects.get(key=key)
|
|
||||||
elif page.startswith("b:"):
|
|
||||||
blog_id = page[2:]
|
|
||||||
vote.linked_object = BlogPost.objects.get(id=blog_id)
|
|
||||||
vote.save()
|
|
||||||
except ObjectDoesNotExist:
|
|
||||||
vote.delete()
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("contenttypes", "0002_remove_content_type_name"),
|
|
||||||
("judge", "0157_auto_20230801_1145"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="pagevote",
|
|
||||||
name="content_type",
|
|
||||||
field=models.ForeignKey(
|
|
||||||
null=True,
|
|
||||||
on_delete=django.db.models.deletion.CASCADE,
|
|
||||||
to="contenttypes.contenttype",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="pagevote",
|
|
||||||
name="object_id",
|
|
||||||
field=models.PositiveIntegerField(default=None),
|
|
||||||
preserve_default=False,
|
|
||||||
),
|
|
||||||
migrations.AlterUniqueTogether(
|
|
||||||
name="pagevote",
|
|
||||||
unique_together={("content_type", "object_id")},
|
|
||||||
),
|
|
||||||
migrations.AddIndex(
|
|
||||||
model_name="pagevote",
|
|
||||||
index=models.Index(
|
|
||||||
fields=["content_type", "object_id"],
|
|
||||||
name="judge_pagev_content_ed8899_idx",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
migrations.RunPython(migrate_pagevote, migrations.RunPython.noop, atomic=True),
|
|
||||||
]
|
|
|
@ -1,23 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2023-08-03 08:18
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("contenttypes", "0002_remove_content_type_name"),
|
|
||||||
("judge", "0158_migrate_pagevote"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name="pagevote",
|
|
||||||
name="content_type",
|
|
||||||
field=models.ForeignKey(
|
|
||||||
on_delete=django.db.models.deletion.CASCADE,
|
|
||||||
to="contenttypes.contenttype",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,80 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2023-08-03 08:32
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
|
||||||
|
|
||||||
|
|
||||||
def migrate_bookmark(apps, schema_editor):
|
|
||||||
BookMark = apps.get_model("judge", "BookMark")
|
|
||||||
Problem = apps.get_model("judge", "Problem")
|
|
||||||
Solution = apps.get_model("judge", "Solution")
|
|
||||||
BlogPost = apps.get_model("judge", "BlogPost")
|
|
||||||
Contest = apps.get_model("judge", "Contest")
|
|
||||||
|
|
||||||
for bookmark in BookMark.objects.all():
|
|
||||||
page = bookmark.page
|
|
||||||
try:
|
|
||||||
if page.startswith("p:"):
|
|
||||||
code = page[2:]
|
|
||||||
bookmark.linked_object = Problem.objects.get(code=code)
|
|
||||||
elif page.startswith("s:"):
|
|
||||||
code = page[2:]
|
|
||||||
bookmark.linked_object = Solution.objects.get(problem__code=code)
|
|
||||||
elif page.startswith("c:"):
|
|
||||||
key = page[2:]
|
|
||||||
bookmark.linked_object = Contest.objects.get(key=key)
|
|
||||||
elif page.startswith("b:"):
|
|
||||||
blog_id = page[2:]
|
|
||||||
bookmark.linked_object = BlogPost.objects.get(id=blog_id)
|
|
||||||
bookmark.save()
|
|
||||||
except ObjectDoesNotExist:
|
|
||||||
bookmark.delete()
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("contenttypes", "0002_remove_content_type_name"),
|
|
||||||
("judge", "0159_auto_20230803_1518"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="bookmark",
|
|
||||||
name="content_type",
|
|
||||||
field=models.ForeignKey(
|
|
||||||
null=True,
|
|
||||||
on_delete=django.db.models.deletion.CASCADE,
|
|
||||||
to="contenttypes.contenttype",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="bookmark",
|
|
||||||
name="object_id",
|
|
||||||
field=models.PositiveIntegerField(default=1),
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="bookmark",
|
|
||||||
name="score",
|
|
||||||
field=models.IntegerField(default=0, verbose_name="votes"),
|
|
||||||
),
|
|
||||||
migrations.AlterUniqueTogether(
|
|
||||||
name="bookmark",
|
|
||||||
unique_together={("content_type", "object_id")},
|
|
||||||
),
|
|
||||||
migrations.AddIndex(
|
|
||||||
model_name="bookmark",
|
|
||||||
index=models.Index(
|
|
||||||
fields=["content_type", "object_id"],
|
|
||||||
name="judge_bookm_content_964329_idx",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
migrations.AddIndex(
|
|
||||||
model_name="makebookmark",
|
|
||||||
index=models.Index(
|
|
||||||
fields=["user", "bookmark"], name="judge_makeb_user_id_f0e226_idx"
|
|
||||||
),
|
|
||||||
),
|
|
||||||
migrations.RunPython(migrate_bookmark, migrations.RunPython.noop, atomic=True),
|
|
||||||
]
|
|
|
@ -1,28 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2023-08-03 08:36
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("contenttypes", "0002_remove_content_type_name"),
|
|
||||||
("judge", "0160_migrate_bookmark"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name="bookmark",
|
|
||||||
name="content_type",
|
|
||||||
field=models.ForeignKey(
|
|
||||||
on_delete=django.db.models.deletion.CASCADE,
|
|
||||||
to="contenttypes.contenttype",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name="bookmark",
|
|
||||||
name="object_id",
|
|
||||||
field=models.PositiveIntegerField(),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,21 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2023-08-24 00:50
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import judge.models.profile
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0161_auto_20230803_1536"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="profile",
|
|
||||||
name="profile_image",
|
|
||||||
field=models.ImageField(
|
|
||||||
null=True, upload_to=judge.models.profile.profile_image_path
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,18 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2023-08-25 00:19
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0162_profile_image"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="profile",
|
|
||||||
name="email_change_pending",
|
|
||||||
field=models.EmailField(blank=True, max_length=254, null=True),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,30 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2023-08-25 23:03
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
def migrate_show_testcases(apps, schema_editor):
|
|
||||||
ContestProblem = apps.get_model("judge", "ContestProblem")
|
|
||||||
|
|
||||||
for c in ContestProblem.objects.all():
|
|
||||||
if c.output_prefix_override == 1:
|
|
||||||
c.show_testcases = True
|
|
||||||
c.save()
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0163_email_change"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="contestproblem",
|
|
||||||
name="show_testcases",
|
|
||||||
field=models.BooleanField(default=False, verbose_name="visible testcases"),
|
|
||||||
),
|
|
||||||
migrations.RunPython(
|
|
||||||
migrate_show_testcases, migrations.RunPython.noop, atomic=True
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,17 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2023-08-25 23:11
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0164_show_testcase"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.RemoveField(
|
|
||||||
model_name="contestproblem",
|
|
||||||
name="output_prefix_override",
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,28 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2023-08-28 01:13
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0165_drop_output_prefix_override"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name="profile",
|
|
||||||
name="display_rank",
|
|
||||||
field=models.CharField(
|
|
||||||
choices=[
|
|
||||||
("user", "Normal User"),
|
|
||||||
("setter", "Problem Setter"),
|
|
||||||
("admin", "Admin"),
|
|
||||||
],
|
|
||||||
db_index=True,
|
|
||||||
default="user",
|
|
||||||
max_length=10,
|
|
||||||
verbose_name="display rank",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,32 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2023-09-01 00:09
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0166_display_rank_index"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name="contest",
|
|
||||||
name="format_name",
|
|
||||||
field=models.CharField(
|
|
||||||
choices=[
|
|
||||||
("atcoder", "AtCoder"),
|
|
||||||
("default", "Default"),
|
|
||||||
("ecoo", "ECOO"),
|
|
||||||
("icpc", "ICPC"),
|
|
||||||
("ioi", "IOI"),
|
|
||||||
("ioi16", "New IOI"),
|
|
||||||
("ultimate", "Ultimate"),
|
|
||||||
],
|
|
||||||
default="default",
|
|
||||||
help_text="The contest format module to use.",
|
|
||||||
max_length=32,
|
|
||||||
verbose_name="contest format",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,24 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2023-09-02 00:30
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0167_ultimate_contest_format"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="profile",
|
|
||||||
name="css_background",
|
|
||||||
field=models.TextField(
|
|
||||||
blank=True,
|
|
||||||
help_text='CSS custom background properties: url("image_url"), color, etc',
|
|
||||||
max_length=300,
|
|
||||||
null=True,
|
|
||||||
verbose_name="Custom background",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,22 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2023-09-17 01:55
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0168_css_background"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="contest",
|
|
||||||
name="public_scoreboard",
|
|
||||||
field=models.BooleanField(
|
|
||||||
default=False,
|
|
||||||
help_text="Ranking page is public even for private contests.",
|
|
||||||
verbose_name="public scoreboard",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,30 +0,0 @@
|
||||||
# Generated by Django 3.2.21 on 2023-10-02 03:25
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0169_public_scoreboard"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.CreateModel(
|
|
||||||
name="ContestsSummary",
|
|
||||||
fields=[
|
|
||||||
(
|
|
||||||
"id",
|
|
||||||
models.AutoField(
|
|
||||||
auto_created=True,
|
|
||||||
primary_key=True,
|
|
||||||
serialize=False,
|
|
||||||
verbose_name="ID",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
("scores", models.JSONField(blank=True, null=True)),
|
|
||||||
("key", models.CharField(max_length=20, unique=True)),
|
|
||||||
("contests", models.ManyToManyField(to="judge.Contest")),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,68 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2023-10-10 21:17
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
|
||||||
from django.urls import reverse
|
|
||||||
|
|
||||||
from collections import defaultdict
|
|
||||||
|
|
||||||
|
|
||||||
# Run this in shell
|
|
||||||
def migrate_notif(apps, schema_editor):
|
|
||||||
Notification = apps.get_model("judge", "Notification")
|
|
||||||
Profile = apps.get_model("judge", "Profile")
|
|
||||||
NotificationProfile = apps.get_model("judge", "NotificationProfile")
|
|
||||||
|
|
||||||
unread_count = defaultdict(int)
|
|
||||||
for c in Notification.objects.all():
|
|
||||||
if c.comment:
|
|
||||||
c.html_link = (
|
|
||||||
f'<a href="{c.comment.get_absolute_url()}">{c.comment.page_title}</a>'
|
|
||||||
)
|
|
||||||
c.author = c.comment.author
|
|
||||||
c.save()
|
|
||||||
if c.read is False:
|
|
||||||
unread_count[c.author] += 1
|
|
||||||
|
|
||||||
for user in unread_count:
|
|
||||||
np = NotificationProfile(user=user)
|
|
||||||
np.unread_count = unread_count[user]
|
|
||||||
np.save()
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0170_contests_summary"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterModelOptions(
|
|
||||||
name="contestssummary",
|
|
||||||
options={
|
|
||||||
"verbose_name": "contests summary",
|
|
||||||
"verbose_name_plural": "contests summaries",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
migrations.CreateModel(
|
|
||||||
name="NotificationProfile",
|
|
||||||
fields=[
|
|
||||||
(
|
|
||||||
"id",
|
|
||||||
models.AutoField(
|
|
||||||
auto_created=True,
|
|
||||||
primary_key=True,
|
|
||||||
serialize=False,
|
|
||||||
verbose_name="ID",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
("unread_count", models.IntegerField(default=0)),
|
|
||||||
(
|
|
||||||
"user",
|
|
||||||
models.OneToOneField(
|
|
||||||
on_delete=django.db.models.deletion.CASCADE, to="judge.profile"
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,18 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2023-10-10 23:15
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0171_update_notification"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name="profile",
|
|
||||||
name="rating",
|
|
||||||
field=models.IntegerField(db_index=True, default=None, null=True),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,25 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2023-10-14 00:53
|
|
||||||
|
|
||||||
from django.db import migrations
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0172_index_rating"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.RunSQL(
|
|
||||||
(
|
|
||||||
"CREATE FULLTEXT INDEX IF NOT EXISTS code_name_index ON judge_problem (code, name)",
|
|
||||||
),
|
|
||||||
reverse_sql=migrations.RunSQL.noop,
|
|
||||||
),
|
|
||||||
migrations.RunSQL(
|
|
||||||
(
|
|
||||||
"CREATE FULLTEXT INDEX IF NOT EXISTS key_name_index ON judge_contest (`key`, name)",
|
|
||||||
),
|
|
||||||
reverse_sql=migrations.RunSQL.noop,
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,50 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2023-11-24 05:45
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0173_fulltext"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="contestssummary",
|
|
||||||
name="results",
|
|
||||||
field=models.JSONField(blank=True, null=True),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name="contest",
|
|
||||||
name="authors",
|
|
||||||
field=models.ManyToManyField(
|
|
||||||
help_text="These users will be able to edit the contest.",
|
|
||||||
related_name="_judge_contest_authors_+",
|
|
||||||
to="judge.Profile",
|
|
||||||
verbose_name="authors",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name="contest",
|
|
||||||
name="curators",
|
|
||||||
field=models.ManyToManyField(
|
|
||||||
blank=True,
|
|
||||||
help_text="These users will be able to edit the contest, but will not be listed as authors.",
|
|
||||||
related_name="_judge_contest_curators_+",
|
|
||||||
to="judge.Profile",
|
|
||||||
verbose_name="curators",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name="contest",
|
|
||||||
name="testers",
|
|
||||||
field=models.ManyToManyField(
|
|
||||||
blank=True,
|
|
||||||
help_text="These users will be able to view the contest, but not edit it.",
|
|
||||||
related_name="_judge_contest_testers_+",
|
|
||||||
to="judge.Profile",
|
|
||||||
verbose_name="testers",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,20 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2023-11-29 02:26
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0174_contest_summary_result"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddIndex(
|
|
||||||
model_name="profile",
|
|
||||||
index=models.Index(
|
|
||||||
fields=["is_unlisted", "performance_points"],
|
|
||||||
name="judge_profi_is_unli_d4034c_idx",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,30 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2023-12-06 01:28
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
# Run this in shell
|
|
||||||
def migrate_revision(apps, schema_editor):
|
|
||||||
Comment = apps.get_model("judge", "Comment")
|
|
||||||
|
|
||||||
for c in Comment.objects.all():
|
|
||||||
c.revision_count = c.versions.count()
|
|
||||||
c.save()
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0175_add_profile_index"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="comment",
|
|
||||||
name="revision_count",
|
|
||||||
field=models.PositiveIntegerField(default=1),
|
|
||||||
),
|
|
||||||
# migrations.RunPython(
|
|
||||||
# migrate_revision, migrations.RunPython.noop, atomic=True
|
|
||||||
# ),
|
|
||||||
]
|
|
|
@ -1,35 +0,0 @@
|
||||||
from django.db import migrations, models
|
|
||||||
import judge.models.test_formatter
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0176_comment_revision_count"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.CreateModel(
|
|
||||||
name="TestFormatterModel",
|
|
||||||
fields=[
|
|
||||||
(
|
|
||||||
"id",
|
|
||||||
models.AutoField(
|
|
||||||
auto_created=True,
|
|
||||||
primary_key=True,
|
|
||||||
serialize=False,
|
|
||||||
verbose_name="ID",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
(
|
|
||||||
"file",
|
|
||||||
models.FileField(
|
|
||||||
blank=True,
|
|
||||||
null=True,
|
|
||||||
upload_to=judge.models.test_formatter.test_formatter_path,
|
|
||||||
verbose_name="testcase file",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
]
|
|
|
@ -1,17 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2024-01-14 01:04
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0177_test_formatter"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.RemoveField(
|
|
||||||
model_name="profile",
|
|
||||||
name="user_script",
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,19 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2024-01-23 00:32
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0178_remove_user_script"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddIndex(
|
|
||||||
model_name="submission",
|
|
||||||
index=models.Index(
|
|
||||||
fields=["language", "result"], name="judge_submi_languag_874af4_idx"
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,78 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2024-02-15 02:12
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0179_submission_result_lang_index"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.CreateModel(
|
|
||||||
name="CourseLesson",
|
|
||||||
fields=[
|
|
||||||
(
|
|
||||||
"id",
|
|
||||||
models.AutoField(
|
|
||||||
auto_created=True,
|
|
||||||
primary_key=True,
|
|
||||||
serialize=False,
|
|
||||||
verbose_name="ID",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
("title", models.TextField(verbose_name="course title")),
|
|
||||||
("content", models.TextField(verbose_name="course content")),
|
|
||||||
("order", models.IntegerField(default=0, verbose_name="order")),
|
|
||||||
("points", models.IntegerField(verbose_name="points")),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
migrations.RemoveField(
|
|
||||||
model_name="courseresource",
|
|
||||||
name="course",
|
|
||||||
),
|
|
||||||
migrations.RemoveField(
|
|
||||||
model_name="course",
|
|
||||||
name="ending_time",
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name="courserole",
|
|
||||||
name="course",
|
|
||||||
field=models.ForeignKey(
|
|
||||||
on_delete=django.db.models.deletion.CASCADE,
|
|
||||||
to="judge.course",
|
|
||||||
verbose_name="course",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
migrations.DeleteModel(
|
|
||||||
name="CourseAssignment",
|
|
||||||
),
|
|
||||||
migrations.DeleteModel(
|
|
||||||
name="CourseResource",
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="courselesson",
|
|
||||||
name="course",
|
|
||||||
field=models.ForeignKey(
|
|
||||||
on_delete=django.db.models.deletion.CASCADE,
|
|
||||||
to="judge.course",
|
|
||||||
verbose_name="course",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="courselesson",
|
|
||||||
name="problems",
|
|
||||||
field=models.ManyToManyField(to="judge.Problem"),
|
|
||||||
),
|
|
||||||
migrations.AlterUniqueTogether(
|
|
||||||
name="courserole",
|
|
||||||
unique_together={("course", "user")},
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name="courselesson",
|
|
||||||
name="problems",
|
|
||||||
field=models.ManyToManyField(blank=True, to="judge.Problem"),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,50 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2024-02-26 20:43
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0180_course"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.RemoveField(
|
|
||||||
model_name="profile",
|
|
||||||
name="math_engine",
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name="course",
|
|
||||||
name="about",
|
|
||||||
field=models.TextField(verbose_name="course description"),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name="courselesson",
|
|
||||||
name="course",
|
|
||||||
field=models.ForeignKey(
|
|
||||||
on_delete=django.db.models.deletion.CASCADE,
|
|
||||||
related_name="lessons",
|
|
||||||
to="judge.course",
|
|
||||||
verbose_name="course",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name="courselesson",
|
|
||||||
name="problems",
|
|
||||||
field=models.ManyToManyField(
|
|
||||||
blank=True, to="judge.Problem", verbose_name="problem"
|
|
||||||
),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name="courserole",
|
|
||||||
name="user",
|
|
||||||
field=models.ForeignKey(
|
|
||||||
on_delete=django.db.models.deletion.CASCADE,
|
|
||||||
related_name="course_roles",
|
|
||||||
to="judge.profile",
|
|
||||||
verbose_name="user",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,75 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2024-03-19 04:28
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
def migrate_checker(apps, schema_editor):
|
|
||||||
ProblemData = apps.get_model("judge", "ProblemData")
|
|
||||||
ProblemTestCase = apps.get_model("judge", "ProblemTestCase")
|
|
||||||
|
|
||||||
for p in ProblemData.objects.all():
|
|
||||||
if p.checker == "customval":
|
|
||||||
p.checker = "customcpp"
|
|
||||||
p.save()
|
|
||||||
|
|
||||||
for p in ProblemTestCase.objects.all():
|
|
||||||
if p.checker == "customval":
|
|
||||||
p.checker = "customcpp"
|
|
||||||
p.save()
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0181_remove_math_engine"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.RunPython(migrate_checker, migrations.RunPython.noop, atomic=True),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name="problemdata",
|
|
||||||
name="checker",
|
|
||||||
field=models.CharField(
|
|
||||||
blank=True,
|
|
||||||
choices=[
|
|
||||||
("standard", "Standard"),
|
|
||||||
("floats", "Floats"),
|
|
||||||
("floatsabs", "Floats (absolute)"),
|
|
||||||
("floatsrel", "Floats (relative)"),
|
|
||||||
("rstripped", "Non-trailing spaces"),
|
|
||||||
("sorted", "Unordered"),
|
|
||||||
("identical", "Byte identical"),
|
|
||||||
("linecount", "Line-by-line"),
|
|
||||||
("custom", "Custom checker (PY)"),
|
|
||||||
("customcpp", "Custom checker (CPP)"),
|
|
||||||
("interact", "Interactive"),
|
|
||||||
("testlib", "Testlib"),
|
|
||||||
],
|
|
||||||
max_length=10,
|
|
||||||
verbose_name="checker",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name="problemtestcase",
|
|
||||||
name="checker",
|
|
||||||
field=models.CharField(
|
|
||||||
blank=True,
|
|
||||||
choices=[
|
|
||||||
("standard", "Standard"),
|
|
||||||
("floats", "Floats"),
|
|
||||||
("floatsabs", "Floats (absolute)"),
|
|
||||||
("floatsrel", "Floats (relative)"),
|
|
||||||
("rstripped", "Non-trailing spaces"),
|
|
||||||
("sorted", "Unordered"),
|
|
||||||
("identical", "Byte identical"),
|
|
||||||
("linecount", "Line-by-line"),
|
|
||||||
("custom", "Custom checker (PY)"),
|
|
||||||
("customcpp", "Custom checker (CPP)"),
|
|
||||||
("interact", "Interactive"),
|
|
||||||
("testlib", "Testlib"),
|
|
||||||
],
|
|
||||||
max_length=10,
|
|
||||||
verbose_name="checker",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,45 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2024-03-19 04:45
|
|
||||||
|
|
||||||
import django.core.validators
|
|
||||||
from django.db import migrations, models
|
|
||||||
import judge.models.problem_data
|
|
||||||
import judge.utils.problem_data
|
|
||||||
|
|
||||||
|
|
||||||
def migrate_checker(apps, schema_editor):
|
|
||||||
ProblemData = apps.get_model("judge", "ProblemData")
|
|
||||||
|
|
||||||
for p in ProblemData.objects.all():
|
|
||||||
p.custom_checker_cpp = p.custom_validator
|
|
||||||
p.save()
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0182_rename_customcpp"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="problemdata",
|
|
||||||
name="custom_checker_cpp",
|
|
||||||
field=models.FileField(
|
|
||||||
blank=True,
|
|
||||||
null=True,
|
|
||||||
storage=judge.utils.problem_data.ProblemDataStorage(),
|
|
||||||
upload_to=judge.models.problem_data.problem_directory_file,
|
|
||||||
validators=[
|
|
||||||
django.core.validators.FileExtensionValidator(
|
|
||||||
allowed_extensions=["cpp"]
|
|
||||||
)
|
|
||||||
],
|
|
||||||
verbose_name="custom cpp checker file",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
migrations.RunPython(migrate_checker, migrations.RunPython.noop, atomic=True),
|
|
||||||
migrations.RemoveField(
|
|
||||||
model_name="problemdata",
|
|
||||||
name="custom_validator",
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,28 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2024-03-23 04:07
|
|
||||||
|
|
||||||
import django.core.validators
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0183_rename_custom_checker_cpp"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="contest",
|
|
||||||
name="rate_limit",
|
|
||||||
field=models.PositiveIntegerField(
|
|
||||||
blank=True,
|
|
||||||
help_text="Maximum number of submissions per minute. Leave empty if you don't want rate limit.",
|
|
||||||
null=True,
|
|
||||||
validators=[
|
|
||||||
django.core.validators.MinValueValidator(1),
|
|
||||||
django.core.validators.MaxValueValidator(5),
|
|
||||||
],
|
|
||||||
verbose_name="rate limit",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,18 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2024-04-12 05:50
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0184_contest_rate_limit"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.RenameField(
|
|
||||||
model_name="organizationprofile",
|
|
||||||
old_name="users",
|
|
||||||
new_name="profile",
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,43 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2024-04-12 17:04
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
def truncate_about_text(apps, schema_editor):
|
|
||||||
Organization = apps.get_model("judge", "Organization")
|
|
||||||
Profile = apps.get_model("judge", "Profile")
|
|
||||||
|
|
||||||
for org in Organization.objects.all():
|
|
||||||
if len(org.about) > 10000:
|
|
||||||
org.about = org.about[:10000]
|
|
||||||
org.save()
|
|
||||||
|
|
||||||
for profile in Profile.objects.all():
|
|
||||||
if profile.about and len(profile.about) > 10000:
|
|
||||||
profile.about = profile.about[:10000]
|
|
||||||
profile.save()
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0185_rename_org_profile_colum"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.RunPython(truncate_about_text),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name="organization",
|
|
||||||
name="about",
|
|
||||||
field=models.CharField(
|
|
||||||
max_length=10000, verbose_name="organization description"
|
|
||||||
),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name="profile",
|
|
||||||
name="about",
|
|
||||||
field=models.CharField(
|
|
||||||
blank=True, max_length=10000, null=True, verbose_name="self-description"
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,69 +0,0 @@
|
||||||
# Generated by Django 3.2.18 on 2024-04-27 03:35
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("judge", "0186_change_about_fields_max_len"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.RemoveField(
|
|
||||||
model_name="profile",
|
|
||||||
name="is_banned_problem_voting",
|
|
||||||
),
|
|
||||||
migrations.CreateModel(
|
|
||||||
name="ProfileInfo",
|
|
||||||
fields=[
|
|
||||||
(
|
|
||||||
"id",
|
|
||||||
models.AutoField(
|
|
||||||
auto_created=True,
|
|
||||||
primary_key=True,
|
|
||||||
serialize=False,
|
|
||||||
verbose_name="ID",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
(
|
|
||||||
"tshirt_size",
|
|
||||||
models.CharField(
|
|
||||||
blank=True,
|
|
||||||
choices=[
|
|
||||||
("S", "Small (S)"),
|
|
||||||
("M", "Medium (M)"),
|
|
||||||
("L", "Large (L)"),
|
|
||||||
("XL", "Extra Large (XL)"),
|
|
||||||
("XXL", "2 Extra Large (XXL)"),
|
|
||||||
],
|
|
||||||
max_length=5,
|
|
||||||
null=True,
|
|
||||||
verbose_name="t-shirt size",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
(
|
|
||||||
"date_of_birth",
|
|
||||||
models.DateField(
|
|
||||||
blank=True, null=True, verbose_name="date of birth"
|
|
||||||
),
|
|
||||||
),
|
|
||||||
(
|
|
||||||
"address",
|
|
||||||
models.CharField(
|
|
||||||
blank=True, max_length=255, null=True, verbose_name="address"
|
|
||||||
),
|
|
||||||
),
|
|
||||||
(
|
|
||||||
"profile",
|
|
||||||
models.OneToOneField(
|
|
||||||
on_delete=django.db.models.deletion.CASCADE,
|
|
||||||
related_name="info",
|
|
||||||
to="judge.profile",
|
|
||||||
verbose_name="profile associated",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
]
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue