|
3 | 3 | from django.core.files import File
|
4 | 4 | from django.db import transaction
|
5 | 5 |
|
| 6 | +import sio3pack |
6 | 7 | from sio3pack.django.common.models import SIO3Package, SIO3PackModelSolution, SIO3PackNameTranslation, SIO3PackStatement
|
7 |
| -from sio3pack.files.local_file import LocalFile |
8 |
| -from sio3pack.files.remote_file import RemoteFile |
| 8 | +from sio3pack.files import LocalFile, RemoteFile |
9 | 9 | from sio3pack.packages.exceptions import ImproperlyConfigured, PackageAlreadyExists
|
10 | 10 |
|
11 | 11 |
|
12 | 12 | class DjangoHandler:
|
13 |
| - def __init__(self, package: Type["Package"], problem_id: int): |
| 13 | + """ |
| 14 | + Base class for handling Django models. |
| 15 | + Allows to save the package to the database and retrieve its data. |
| 16 | +
|
| 17 | + :param sio3pack.Package package: The package to handle. |
| 18 | + :param int problem_id: The problem ID. |
| 19 | + """ |
| 20 | + |
| 21 | + def __init__(self, package: "sio3pack.Package", problem_id: int): |
| 22 | + """ |
| 23 | + Initialize the handler with the package and problem ID. |
| 24 | + :param sio3pack.Package package: The package to handle. |
| 25 | + :param int problem_id: The problem ID. |
| 26 | + """ |
14 | 27 | self.package = package
|
15 | 28 | self.problem_id = problem_id
|
16 | 29 | try:
|
@@ -71,20 +84,37 @@ def _add_statement(language: str, statement: LocalFile):
|
71 | 84 |
|
72 | 85 | @property
|
73 | 86 | def short_name(self) -> str:
|
| 87 | + """ |
| 88 | + Short name of the problem. |
| 89 | + """ |
74 | 90 | return self.db_package.short_name
|
75 | 91 |
|
76 | 92 | @property
|
77 | 93 | def full_name(self) -> str:
|
| 94 | + """ |
| 95 | + Full name of the problem. |
| 96 | + """ |
78 | 97 | return self.db_package.full_name
|
79 | 98 |
|
80 | 99 | @property
|
81 | 100 | def lang_titles(self) -> dict[str, str]:
|
| 101 | + """ |
| 102 | + A dictionary of problem titles, |
| 103 | + where keys are language codes and values are titles. |
| 104 | + """ |
82 | 105 | return {t.language: t.name for t in self.db_package.name_translations.all()}
|
83 | 106 |
|
84 | 107 | @property
|
85 | 108 | def model_solutions(self) -> list[dict[str, Any]]:
|
| 109 | + """ |
| 110 | + A list of model solutions, where each element is a dictionary containing |
| 111 | + a :class:`sio3pack.RemoteFile` object. |
| 112 | + """ |
86 | 113 | return [{"file": RemoteFile(s.source_file.path)} for s in self.db_package.model_solutions.all()]
|
87 | 114 |
|
88 | 115 | @property
|
89 | 116 | def lang_statements(self) -> dict[str, RemoteFile]:
|
| 117 | + """ |
| 118 | + A dictionary of problem statements, where keys are language codes and values are files. |
| 119 | + """ |
90 | 120 | return {s.language: RemoteFile(s.content.path) for s in self.db_package.statements.all()}
|
0 commit comments