Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code refactor for printing UI, API and client #2950

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions submit/submit
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ elif contests:
languages: list = []
problems: list = []
if my_contest and baseurl:
if 'allow_submit' in my_contest and not my_contest['allow_submit']:
if not args.print and 'allow_submit' in my_contest and not my_contest['allow_submit']:
warn_user('Submissions for contest (temporarily) disabled')
exit(1)
languages = read_languages()
Expand Down Expand Up @@ -610,23 +610,25 @@ for problem in problems:
if not my_problem and not args.print:
usage('No known problem specified or detected.')

if not args.print:
# Guess entry point if not already specified.
if not entry_point and my_language['entry_point_required']:
if my_language['name'] == 'Java':
entry_point = filebase
elif my_language['name'] == 'Kotlin':
entry_point = kotlin_base_entry_point(filebase) + "Kt"
elif my_language['name'] == 'Python 3':
entry_point = filebase + "." + ext
if not entry_point and my_language['entry_point_required']:
if my_language['name'] == 'Java':
entry_point = filebase
elif my_language['name'] == 'Kotlin':
entry_point = kotlin_base_entry_point(filebase) + "Kt"
elif my_language['name'] == 'Python 3':
entry_point = filebase + "." + ext

if not entry_point and my_language['entry_point_required']:
error('Entry point required but not specified nor detected.')
if not entry_point and my_language['entry_point_required']:
error('Entry point required but not specified nor detected.')

logging.debug(f"contest is `{my_contest['shortname']}'")
if not args.print:
logging.debug(f"problem is `{my_problem['label']}'")
logging.debug(f"language is `{my_language['name']}'")
logging.debug(f"entry_point is `{entry_point or '<None>'}'")
logging.debug(f"language is `{my_language.get('name', '<None>')}'")
if not args.print:
logging.debug(f"entry_point is `{entry_point or '<None>'}'")
logging.debug(f"url is `{baseurl}'")

if args.print:
Expand Down
4 changes: 0 additions & 4 deletions webapp/src/Controller/API/PrintController.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,10 @@ public function printAsTeam(
->createQueryBuilder()
->from(Language::class, "l")
->select("l.langid")
->andWhere("l.allowSubmit = 1")
->andWhere("l.name = :name")
->setParameter("name", $print->language)
->getQuery()
->getOneOrNullResult(AbstractQuery::HYDRATE_SINGLE_SCALAR);
if ($langid === null) {
throw new BadRequestHttpException("Programming language not found.");
}
}

$decodedFile = base64_decode($print->fileContents, true);
Expand Down
9 changes: 0 additions & 9 deletions webapp/src/Controller/Jury/PrintController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,8 @@ public function showAction(Request $request): Response
]);
}

/** @var Language[] $languages */
$languages = $this->em->createQueryBuilder()
->from(Language::class, 'l')
->select('l')
->andWhere('l.allowSubmit = 1')
->getQuery()
->getResult();

return $this->render('jury/print.html.twig', [
'form' => $form,
'languages' => $languages,
]);
}
}
5 changes: 0 additions & 5 deletions webapp/src/Controller/Team/MiscController.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,8 @@ public function printAction(Request $request): Response
]);
}

$currentContest = $this->dj->getCurrentContest();
/** @var Language[] $languages */
$languages = $this->dj->getAllowedLanguagesForContest($currentContest);

return $this->render('team/print.html.twig', [
'form' => $form,
'languages' => $languages,
]);
}

Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Service/DOMJudgeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ public function printFile(
$replaces = [
'[file]' => escapeshellarg($filename),
'[original]' => escapeshellarg($origname),
'[language]' => escapeshellarg($language),
'[language]' => escapeshellarg($language ?? ''),
'[username]' => escapeshellarg($username),
'[teamname]' => escapeshellarg($teamname ?? ''),
'[teamid]' => escapeshellarg($teamid ?? ''),
Expand Down
Loading