Skip to content

Package attributes refactor #18

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

Merged
merged 4 commits into from
Mar 17, 2025
Merged
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
6 changes: 3 additions & 3 deletions src/sio3pack/django/common/handler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Type
from typing import Any, Type

from django.core.files import File
from django.db import transaction
Expand Down Expand Up @@ -82,8 +82,8 @@ def lang_titles(self) -> dict[str, str]:
return {t.language: t.name for t in self.db_package.name_translations.all()}

@property
def model_solutions(self) -> list[RemoteFile]:
return [RemoteFile(s.source_file.path) for s in self.db_package.model_solutions.all()]
def model_solutions(self) -> list[dict[str, Any]]:
return [{"file": RemoteFile(s.source_file.path)} for s in self.db_package.model_solutions.all()]

@property
def lang_statements(self) -> dict[str, RemoteFile]:
Expand Down
4 changes: 2 additions & 2 deletions src/sio3pack/django/sinolpack/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def config(self) -> dict[str, Any]:
return self.db_package.config.parsed_config

@property
def model_solutions(self) -> list[tuple[ModelSolutionKind, RemoteFile]]:
def model_solutions(self) -> list[dict[str, Any]]:
solutions = SinolpackModelSolution.objects.filter(package=self.db_package)
return [(s.kind, RemoteFile(s.source_file.path)) for s in solutions]
return [{"file": RemoteFile(s.source_file.path), "kind": s.kind} for s in solutions]

@property
def additional_files(self) -> list[RemoteFile]:
Expand Down
25 changes: 21 additions & 4 deletions src/sio3pack/packages/package/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
from typing import Any

from sio3pack import LocalFile
from sio3pack.exceptions import SIO3PackException
from sio3pack.files import File
from sio3pack.graph import Graph, GraphOperation
from sio3pack.graph import GraphOperation
from sio3pack.packages.exceptions import UnknownPackageType
from sio3pack.packages.package.handler import NoDjangoHandler
from sio3pack.test import Test
from sio3pack.utils.archive import Archive
from sio3pack.utils.classinit import RegisteredSubclassesBase

from sio3pack.exceptions import SIO3PackException


def wrap_exceptions(func):
"""Decorator to catch exceptions and re-raise them as SIO3PackException."""
Expand All @@ -20,7 +19,7 @@ def decorator(*args, **kwargs):
try:
return func(*args, **kwargs)
except SIO3PackException:
raise # Do not wrap SIO3PackExceptions again
raise # Do not wrap SIO3PackExceptions again
except Exception as e:
raise SIO3PackException(f"SIO3Pack raised an exception in {func.__name__} function.", e)

Expand All @@ -34,6 +33,24 @@ class Package(RegisteredSubclassesBase):

abstract = True

"""
Attributes:
short_name (str): Short name of the problem.
full_name (str): Full name of the problem.
lang_titles (dict[str, str]): A dictionary of problem titles,
where keys are language codes and values are titles.
lang_statements (dict[str, File]): A dictionary of problem
statements, where keys are language codes and values are
files.
config (dict[str, Any]): Configuration of the problem.
model_solutions (list[dict[str, Any]]): A list
of model solutions, where each element is a tuple of model
solution kind and filename.
additional_files (list[File]): A list of additional files of
the problem.
attachments (list[File]): A list of attachments of the problem.
"""

def __init__(self):
super().__init__()

Expand Down