Skip to content

Commit

Permalink
Merge branch 'icpc23' of https://github.com/VNOI-Admin/OJ into icpc23…
Browse files Browse the repository at this point in the history
…-filter-by-uni-group
  • Loading branch information
winprn committed Oct 21, 2023
2 parents acf20a3 + 40791e1 commit 079bed7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
5 changes: 5 additions & 0 deletions judge/management/commands/batch_add_icpc_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,18 @@ def handle(self, *args, **options):
writer = csv.DictWriter(fout, fieldnames=['username', 'teamname', 'password', 'group'])
writer.writeheader()

done_team_ids = set()

for cnt, row in enumerate(reader, start=1):
username = f'{prefix}{cnt}'
teamname = row['name']
org = get_org(row['instName'])
password = generate_password()
internalid = row['id']
org_group = row['group']
if internalid in done_team_ids:
continue
done_team_ids.add(internalid)

add_user(username, teamname, password, org, org_group, internalid)

Expand Down
26 changes: 19 additions & 7 deletions judge/management/commands/send_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
from judge.models import Profile


def send_account(team_uni, team_name, username, password, coach_email):
def send_account(team_uni, team_name, username, password, receiver_emails):
html_message = loader.render_to_string('send_account_mail.html', {
'teamuni': team_uni,
'teamname': team_name,
'teamusername': username,
'teampassword': password,
})
subject = f'{team_name} - Thông tin tài khoản thi ICPC Miền Bắc 2023'
subject = f'{team_name} - Thông tin tài khoản thi ICPC Miền Trung 2023'
plain_message = strip_tags(html_message)

mail.send_mail(subject, plain_message, settings.SERVER_EMAIL, [coach_email], html_message=html_message)
mail.send_mail(subject, plain_message, settings.SERVER_EMAIL, receiver_emails, html_message=html_message)


class Command(BaseCommand):
Expand All @@ -34,12 +34,24 @@ def handle(self, *args, **options):
fin = open(options['input'], 'r', encoding='utf-8')

reader = csv.DictReader(fin)
team_email_map = {}
for row in reader:
email = row['email']
teamname = row['teamname']
username = row['username']
teamname: str = row['teamname']
username: str = row['username']
password: str = row['password']

# create a map from (username) to: (teamname, password, emails)
if username not in team_email_map:
team_email_map[username] = (teamname, password, [email])
else:
team_email_map[username][2].append(email)

for username in team_email_map:
print('Processing', username)
password = row['password']
p = Profile.objects.filter(user__username=username)[0]
send_account(p.organization.name, teamname, username, password, email)
teamname, password, emails = team_email_map[username]

print('Processing', username, 'sending to', emails)
send_account(p.organization.name, teamname, username, password, emails)
time.sleep(2)
18 changes: 14 additions & 4 deletions templates/contest/ranking.html
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,12 @@
$('#apply-organization-filter').click(function () {
$('#org-check-list-wrapper').hide();

let selected_orgs = $('#org-check-list').val().map(x => x.trim());
const selected_orgs = [];
$('#org-check-list').val().forEach(function (el) {
selected_orgs.push(el.trim());
});
let selected_group = $('#tag-check-list').val().map(x => x.trim());
localStorage.setItem(`filter-selected-orgs-${contest_key}`, selected_orgs);
localStorage.setItem(`filter-selected-orgs-${contest_key}`, JSON.stringify(selected_orgs));
localStorage.setItem(`filter-selected-group-${contest_key}`, selected_group);
window.applyRankingFilter();
});
Expand Down Expand Up @@ -382,7 +385,7 @@
window.applyRankingFilter = function () {
let counter = 0;
let previous_abs_rank = -1;
let selected_orgs = localStorage.getItem(`filter-selected-orgs-${contest_key}`);
let selected_orgs = JSON.parse(localStorage.getItem(`filter-selected-orgs-${contest_key}`));
let selected_group = localStorage.getItem(`filter-selected-group-${contest_key}`);

if (!selected_orgs.length && !selected_group.length) {
Expand All @@ -396,7 +399,14 @@
let org_anchor = row.find("div > div > .personal-info > .organization > a")[0];
let org = org_anchor ? org_anchor.text : 'Other';

if (!selected_orgs.includes(org.trim()) && !selected_group.includes(row.data('user-group'))) {
let should_show_org = false;
selected_orgs.forEach(function (selected_org) {
if (selected_org === org.trim()) {
should_show_org = true;
}
});

if (!should_show_org) {
row.hide();
return;
}
Expand Down
4 changes: 2 additions & 2 deletions templates/send_account_mail.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div style="display:block;margin: 0 2px;padding: 1em;border: 3px solid #2980B9;background-color: #f8f8f8;border-radius: 6px;font-size: .95em;color: #444;">

Đây là thông tin về tài khoản thi ICPC vòng miền Bắc 2023 <br>
Đây là thông tin về tài khoản thi ICPC vòng miền Trung 2023 <br>

<b>Hệ thống thi: <a href="https://icpc-mb.vnoi.info/contests/">https://icpc-mb.vnoi.info/contests/</a></b> <br>
<b>Hệ thống thi: <a href="https://icpc-mt.vnoi.info/contests/">https://icpc-mt.vnoi.info/contests/</a></b> <br>


Tên trường: {{teamuni}} <br>
Expand Down

0 comments on commit 079bed7

Please sign in to comment.