mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: homework: 自动转换pids
This commit is contained in:
1 parent
f2a999aacb
commit
25e7e00518
6 files changed
+20
-17
No files matched your search
@@ -140,7 +140,7 @@ class HomeworkDetailProblemHandler extends HomeworkHandler {
|
||||
];
|
||||
this.response.template = 'problem_detail.html';
|
||||
this.response.body = {
|
||||
tdoc: this.tdoc, pdoc: this.pdoc, tsdoc: this.tsdoc, udoc, attended, path,
|
||||
tdoc: this.tdoc, pdoc: this.pdoc, tsdoc: this.tsdoc, udoc, attended, path, page_name: 'homework_detail_problem',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -247,9 +247,9 @@ class HomeworkCreateHandler extends HomeworkHandler {
|
||||
const endAt = penaltySince.clone().add(extensionDays, 'days');
|
||||
if (beginAt.isSameOrAfter(penaltySince)) throw new ValidationError('endAtDate', 'endAtTime');
|
||||
if (penaltySince.isAfter(endAt)) throw new ValidationError('extensionDays');
|
||||
await this.verifyProblems(domainId, pids);
|
||||
const verified = await this.verifyProblems(domainId, pids);
|
||||
const tid = await contest.add(domainId, title, content, this.user._id,
|
||||
'homework', beginAt.toDate(), endAt.toDate(), pids, rated,
|
||||
'homework', beginAt.toDate(), endAt.toDate(), verified, rated,
|
||||
{ penaltySince: penaltySince.toDate(), penaltyRules }, document.TYPE_HOMEWORK);
|
||||
this.response.body = { tid };
|
||||
this.response.redirect = this.url('homework_detail', { tid });
|
||||
@@ -324,17 +324,17 @@ class HomeworkEditHandler extends HomeworkHandler {
|
||||
}
|
||||
let endAt = penaltySince.clone().add(extensionDays, 'days');
|
||||
if (beginAt.isSameOrAfter(penaltySince)) throw new ValidationError('endAtDate', 'endAtTime');
|
||||
await this.verifyProblems(domainId, pids);
|
||||
const verified = await this.verifyProblems(domainId, pids);
|
||||
beginAt = beginAt.toDate();
|
||||
endAt = endAt.toDate();
|
||||
penaltySince = penaltySince.toDate();
|
||||
await contest.edit(domainId, tid, {
|
||||
title, content, beginAt, endAt, pids, penaltySince, penaltyRules, rated,
|
||||
title, content, beginAt, endAt, verified, penaltySince, penaltyRules, rated,
|
||||
}, document.TYPE_HOMEWORK);
|
||||
if (tdoc.beginAt !== beginAt
|
||||
|| tdoc.endAt !== endAt
|
||||
|| tdoc.penaltySince !== penaltySince
|
||||
|| new Set(tdoc.pids) !== new Set(pids)) {
|
||||
|| tdoc.pids.sort().join(' ') !== verified.sort().join(' ')) {
|
||||
await contest.recalcStatus(domainId, tdoc.docId, document.TYPE_HOMEWORK);
|
||||
}
|
||||
this.response.body = { tid };
|
||||
|
||||
@@ -190,7 +190,7 @@ export async function getList(
|
||||
}
|
||||
}
|
||||
}
|
||||
return r;
|
||||
return Object.assign(r, l);
|
||||
}
|
||||
|
||||
export async function getListStatus(domainId: string, uid: number, pids: number[]) {
|
||||
|
||||
@@ -446,7 +446,7 @@ export class Handler extends HandlerCommon {
|
||||
this.getSession(),
|
||||
this.getBdoc(),
|
||||
]);
|
||||
if (inferDomain) {
|
||||
if (inferDomain && !this.request.path.startsWith('/d/')) {
|
||||
this.domainId = inferDomain._id;
|
||||
this.args.domainId = inferDomain._id;
|
||||
this.domain = inferDomain;
|
||||
|
||||
@@ -21,14 +21,15 @@ import * as system from './model/system';
|
||||
const logger = new Logger('upgrade');
|
||||
type UpgradeScript = () => Promise<boolean | void>;
|
||||
|
||||
async function iterateAllDomain(cb: (ddoc: DomainDoc) => Promise<any>) {
|
||||
const domains = await domain.getMulti().project({ _id: 1 }).toArray();
|
||||
for (const d of domains) await cb(d);
|
||||
async function iterateAllDomain(cb: (ddoc: DomainDoc, current?: number, total?: number) => Promise<any>) {
|
||||
const ddocs = await domain.getMulti().project({ _id: 1 }).toArray();
|
||||
for (const i in ddocs) await cb(ddocs[i], +i, ddocs.length);
|
||||
}
|
||||
|
||||
async function iterateAllProblem(cb: (pdoc: problem.Pdoc) => Promise<any>) {
|
||||
async function iterateAllProblem(cb: (pdoc: problem.Pdoc, current?: number, total?: number) => Promise<any>) {
|
||||
await iterateAllDomain(async (d) => {
|
||||
await problem.getMulti(d._id, {}).forEach(cb);
|
||||
const pdocs = await problem.getMulti(d._id, {}).toArray();
|
||||
for (const i in pdocs) await cb(pdocs[i], +i, pdocs.length);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -77,7 +78,7 @@ const scripts: UpgradeScript[] = [
|
||||
if (savedProgress) savedProgress = JSON.parse(savedProgress);
|
||||
else savedProgress = { pdocs: [] };
|
||||
const ddocs = await domain.getMulti().project({ _id: 1 }).toArray();
|
||||
logger.info('Total found %d domains.', ddocs.length);
|
||||
logger.info('Found %d domains.', ddocs.length);
|
||||
for (let i = 0; i < ddocs.length; i++) {
|
||||
const ddoc = ddocs[i];
|
||||
logger.info('Domain %s (%d/%d)', ddoc._id, i + 1, ddocs.length);
|
||||
|
||||
Reference in new issue
Block a user