def _process_statements(self): """Creates problem statement from html or pdf source. """ docdir = os.path.join(self.rootdir, 'doc') if not os.path.isdir(docdir): logger.warning("%s: no docdir", self.filename) return # pylint: disable=maybe-no-member self.problem.statements.all().delete() htmlzipfile = os.path.join(docdir, self.short_name + 'zad.html.zip') if os.path.isfile(htmlzipfile): self._force_index_encoding(htmlzipfile) statement = ProblemStatement(problem=self.problem) statement.content.save(self.short_name + '.html.zip', File(open(htmlzipfile, 'rb'))) pdffile = os.path.join(docdir, self.short_name + 'zad.pdf') if os.path.isfile(pdffile): statement = ProblemStatement(problem=self.problem) statement.content.save(self.short_name + '.pdf', File(open(pdffile, 'rb'))) else: if self.use_make: self._compile_latex_docs(docdir) logger.warning("%s: no problem statement", self.filename)
def _process_statements(self): """Creates problem statement from html or pdf source. """ docdir = os.path.join(self.rootdir, 'doc') if not os.path.isdir(docdir): logger.warning("%s: no docdir", self.filename) return # pylint: disable=maybe-no-member self.problem.statements.all().delete() lang_prefs = [''] + ['-' + l[0] for l in settings.STATEMENT_LANGUAGES] if self.use_make: self._compile_latex_docs(docdir) for lang in lang_prefs: htmlzipfile = os.path.join(docdir, self.short_name + 'zad' + lang + '.html.zip') if os.path.isfile(htmlzipfile): self._force_index_encoding(htmlzipfile) statement = ProblemStatement(problem=self.problem, language=lang[1:]) statement.content.save(self.short_name + lang + '.html.zip', File(open(htmlzipfile, 'rb'))) pdffile = os.path.join(docdir, self.short_name + 'zad' + lang + '.pdf') if os.path.isfile(pdffile): statement = ProblemStatement(problem=self.problem, language=lang[1:]) statement.content.save(self.short_name + lang + '.pdf', File(open(pdffile, 'rb'))) if not self.problem.statements.exists(): logger.warning("%s: no problem statement", self.filename)
def _process_statements(self): docdir = os.path.join(self.rootdir, 'doc') if not os.path.isdir(docdir): logger.warning('%s: no docdir', self.filename) return self.problem.statements.all().delete() htmlzipfile = os.path.join(docdir, self.short_name + 'zad.html.zip') if os.path.exists(htmlzipfile): statement = ProblemStatement(problem=self.problem) statement.content.save(self.short_name + '.html.zip', File(open(htmlzipfile, 'rb'))) pdffile = os.path.join(docdir, self.short_name + 'zad.pdf') if not os.path.isfile(pdffile): self._compile_docs(docdir) if not os.path.isfile(pdffile): logger.warning('%s: no problem statement', self.filename) return statement = ProblemStatement(problem=self.problem) statement.content.save(self.short_name + '.pdf', File(open(pdffile, 'rb')))
def test_make_problem_filename(self): p12 = Problem(pk=12) self.assertEqual(make_problem_filename(p12, 'a/hej.txt'), 'problems/12/hej.txt') ps = ProblemStatement(pk=22, problem=p12) self.assertEqual(make_problem_filename(ps, 'a/hej.txt'), 'problems/12/hej.txt')
def _process_statements(self): """Creates a problem statement from html or pdf source. If `USE_SINOLPACK_MAKEFILES` is set to True in the OIOIOI settings, the pdf file will be compiled from a LaTeX source. """ docdir = os.path.join(self.rootdir, 'doc') if not os.path.isdir(docdir): logger.warning("%s: no docdir", self.filename) return # pylint: disable=maybe-no-member self.problem.statements.all().delete() lang_prefs = [''] + ['-' + l[0] for l in settings.STATEMENT_LANGUAGES] if self.use_make: self._compile_latex_docs(docdir) for lang in lang_prefs: htmlzipfile = os.path.join( docdir, self.short_name + 'zad' + lang + '.html.zip') if os.path.isfile(htmlzipfile): if self._html_disallowed(): raise ProblemPackageError( _("You cannot upload package with " "problem statement in HTML. " "Try again using PDF format.")) self._force_index_encoding(htmlzipfile) statement = ProblemStatement(problem=self.problem, language=lang[1:]) statement.content.save(self.short_name + lang + '.html.zip', File(open(htmlzipfile, 'rb'))) pdffile = os.path.join(docdir, self.short_name + 'zad' + lang + '.pdf') if os.path.isfile(pdffile): statement = ProblemStatement(problem=self.problem, language=lang[1:]) statement.content.save(self.short_name + lang + '.pdf', File(open(pdffile, 'rb'))) if not self.problem.statements.exists(): logger.warning("%s: no problem statement", self.filename)