:py:mod:`oioioi.problems.models` ================================ .. py:module:: oioioi.problems.models Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: oioioi.problems.models.Problem oioioi.problems.models.ProblemName oioioi.problems.models.ProblemStatement oioioi.problems.models.ProblemAttachment oioioi.problems.models.ProblemPackage oioioi.problems.models.ProblemSite oioioi.problems.models.MainProblemInstance oioioi.problems.models.ProblemStatistics oioioi.problems.models.UserStatistics oioioi.problems.models.OriginTag oioioi.problems.models.OriginTagLocalization oioioi.problems.models.OriginInfoCategory oioioi.problems.models.OriginInfoCategoryLocalization oioioi.problems.models.OriginInfoValue oioioi.problems.models.OriginInfoValueLocalization oioioi.problems.models.DifficultyTag oioioi.problems.models.DifficultyTagThrough oioioi.problems.models.DifficultyTagLocalization oioioi.problems.models.DifficultyTagProposal oioioi.problems.models.AlgorithmTag oioioi.problems.models.AlgorithmTagThrough oioioi.problems.models.AlgorithmTagLocalization oioioi.problems.models.AlgorithmTagProposal Functions ~~~~~~~~~ .. autoapisummary:: oioioi.problems.models.make_problem_filename oioioi.problems.models._call_controller_adjust_problem oioioi.problems.models._check_problem_instance_integrity oioioi.problems.models._make_package_filename oioioi.problems.models.truncate_unicode oioioi.problems.models._localized Attributes ~~~~~~~~~~ .. autoapisummary:: oioioi.problems.models.logger oioioi.problems.models.package_statuses oioioi.problems.models.TRACEBACK_STACK_LIMIT .. py:data:: logger .. py:function:: make_problem_filename(instance, filename) .. py:class:: Problem(*args, **kwargs) Bases: :py:obj:`django.db.models.Model` Represents a problem in the problems database. Instances of :class:`Problem` do not represent problems in contests, see :class:`oioioi.contests.models.ProblemInstance` for those. Each :class:`Problem` has associated main :class:`oioioi.contests.models.ProblemInstance`, called main_problem_instance: 1) It is not assigned to any contest. 2) It allows sending submissions aside from contests. 3) It is a base to create another instances. .. py:class:: Meta Bases: :py:obj:`object` .. py:attribute:: verbose_name .. py:attribute:: verbose_name_plural .. py:attribute:: permissions :annotation: = [None, None] .. py:property:: controller .. py:property:: package_backend .. py:attribute:: legacy_name .. py:attribute:: short_name .. py:attribute:: controller_name .. py:attribute:: contest .. py:attribute:: author .. py:attribute:: VISIBILITY_PUBLIC :annotation: = PU .. py:attribute:: VISIBILITY_FRIENDS :annotation: = FR .. py:attribute:: VISIBILITY_PRIVATE :annotation: = PR .. py:attribute:: VISIBILITY_LEVELS_CHOICES :annotation: = [None, None, None] .. py:attribute:: visibility .. py:attribute:: package_backend_name .. py:attribute:: ascii_name .. py:attribute:: main_problem_instance .. py:method:: name() .. py:method:: create(*args, **kwargs) :classmethod: Creates a new :class:`Problem` object, with associated main_problem_instance. After the call, the :class:`Problem` and the :class:`ProblemInstance` objects will be saved in the database. .. py:method:: __str__() Return str(self). .. py:method:: save(*args, **kwargs) Save the current instance. Override this in a subclass if you want to control the saving process. The 'force_insert' and 'force_update' parameters can be used to insist that the "save" must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set. .. py:function:: _call_controller_adjust_problem(sender, instance, raw, **kwargs) .. py:function:: _check_problem_instance_integrity(sender, instance, **kwargs) .. py:class:: ProblemName(*args, **kwargs) Bases: :py:obj:`django.db.models.Model` Represents a problem's name translation in a given language. Problem should have its name translated to all available languages. .. py:class:: Meta Bases: :py:obj:`object` .. py:attribute:: unique_together :annotation: = ['problem', 'language'] .. py:attribute:: verbose_name .. py:attribute:: verbose_name_plural .. py:attribute:: problem .. py:attribute:: name .. py:attribute:: language .. py:method:: __str__() Return str(self). .. py:class:: ProblemStatement(*args, **kwargs) Bases: :py:obj:`django.db.models.Model` Represents a file containing problem statement. Problem may have multiple statements, for example in various languages or formats. Formats should be detected according to filename extension of :attr:`content`. .. py:class:: Meta Bases: :py:obj:`object` .. py:attribute:: verbose_name .. py:attribute:: verbose_name_plural .. py:property:: filename .. py:property:: download_name .. py:property:: extension .. py:attribute:: problem .. py:attribute:: language .. py:attribute:: content .. py:method:: __str__() Return str(self). .. py:class:: ProblemAttachment(*args, **kwargs) Bases: :py:obj:`django.db.models.Model` Represents an additional file visible to the contestant, linked to a problem. This may be used for things like input data for open data tasks, or for giving users additional libraries etc. .. py:class:: Meta Bases: :py:obj:`object` .. py:attribute:: verbose_name .. py:attribute:: verbose_name_plural .. py:property:: filename .. py:property:: download_name .. py:attribute:: problem .. py:attribute:: description .. py:attribute:: content .. py:method:: __str__() Return str(self). .. py:function:: _make_package_filename(instance, filename) .. py:data:: package_statuses .. py:data:: TRACEBACK_STACK_LIMIT :annotation: = 100 .. py:function:: truncate_unicode(string, length, encoding='utf-8') Truncates string to be `length` bytes long. .. py:class:: ProblemPackage(*args, **kwargs) Bases: :py:obj:`django.db.models.Model` Represents a file with data necessary for creating a :class:`~oioioi.problems.models.Problem` instance. .. py:class:: Meta Bases: :py:obj:`object` .. py:attribute:: verbose_name .. py:attribute:: verbose_name_plural .. py:attribute:: ordering :annotation: = ['-creation_date'] .. py:class:: StatusSaver(package) Bases: :py:obj:`object` .. py:method:: __enter__() .. py:method:: __exit__(type, value, traceback) .. py:property:: download_name .. py:attribute:: package_file .. py:attribute:: contest .. py:attribute:: problem .. py:attribute:: created_by .. py:attribute:: problem_name .. py:attribute:: celery_task_id .. py:attribute:: info .. py:attribute:: traceback .. py:attribute:: status .. py:attribute:: creation_date .. py:method:: save_operation_status() Returns a context manager to be used during the unpacking process. The code inside the ``with`` statment is executed in a transaction. If the code inside the ``with`` statement executes successfully, the package ``status`` field is set to ``OK``. If an exception is thrown, it gets logged together with the traceback. Additionally, its value is saved in the package ``info`` field. Lastly, if the package gets deleted from the database before the ``with`` statement ends, a :class:`oioioi.problems.models.ProblemPackage.DoesNotExist` exception is thrown. .. py:class:: ProblemSite(*args, **kwargs) Bases: :py:obj:`django.db.models.Model` Represents a global problem site. Contains configuration necessary to view and submit solutions to a :class:`~oioioi.problems.models.Problem`. .. py:class:: Meta Bases: :py:obj:`object` .. py:attribute:: verbose_name .. py:attribute:: verbose_name_plural .. py:attribute:: problem .. py:attribute:: url_key .. py:method:: __str__() Return str(self). .. py:class:: MainProblemInstance(*args, **kwargs) Bases: :py:obj:`oioioi.contests.models.ProblemInstance` Make subclasses preserve the alters_data attribute on overridden methods. .. py:class:: Meta Bases: :py:obj:`object` .. py:attribute:: proxy :annotation: = True .. py:class:: ProblemStatistics(*args, **kwargs) Bases: :py:obj:`django.db.models.Model` Make subclasses preserve the alters_data attribute on overridden methods. .. py:attribute:: problem .. py:attribute:: user_statistics .. py:attribute:: submitted .. py:attribute:: solved .. py:attribute:: avg_best_score .. py:attribute:: _best_score_sum .. py:class:: UserStatistics(*args, **kwargs) Bases: :py:obj:`django.db.models.Model` Make subclasses preserve the alters_data attribute on overridden methods. .. py:class:: Meta Bases: :py:obj:`object` .. py:attribute:: unique_together :annotation: = ['problem_statistics', 'user'] .. py:attribute:: problem_statistics .. py:attribute:: user .. py:attribute:: has_submitted .. py:attribute:: has_solved .. py:attribute:: best_score .. py:function:: _localized(*localized_fields) Some models may have fields with language-specific data, which cannot be translated through the normal internalization tools, as it is not defined in the source code (e.g. names of dynamically defined items). Decorate a class with this decorator when there exists a class that: - has a ForeignKey to the decorated class with a related_name of `localizations`. - has a `language` field, and all of `localized_fields`. The `localized_fields` can then be accessed directly through the decorated class, and will be matched to the current language. Be sure to use prefetch_related('localizations') if you will be querying multiple localized model instances! Also see: LocalizationForm .. py:class:: OriginTag(*args, **kwargs) Bases: :py:obj:`django.db.models.Model` OriginTags are used along with OriginInfoCategories and OriginInfoValue to give information about the problem's origin. OriginTags themselves represent general information about a problem's origin, whereas OriginInfoValues grouped under OriginInfoCategories represent more specific information. A Problem should probably not have more than one OriginTag, and should probably have one OriginInfoValue for each category. See also: OriginInfoCategory, OriginInfoValue .. py:class:: Meta Bases: :py:obj:`object` .. py:attribute:: verbose_name .. py:attribute:: verbose_name_plural .. py:attribute:: name .. py:attribute:: problems .. py:method:: __str__() Return str(self). .. py:class:: OriginTagLocalization(*args, **kwargs) Bases: :py:obj:`django.db.models.Model` Make subclasses preserve the alters_data attribute on overridden methods. .. py:class:: Meta Bases: :py:obj:`object` .. py:attribute:: unique_together :annotation: = ['origin_tag', 'language'] .. py:attribute:: verbose_name .. py:attribute:: verbose_name_plural .. py:attribute:: origin_tag .. py:attribute:: language .. py:attribute:: full_name .. py:attribute:: short_name .. py:attribute:: description .. py:method:: __str__() Return str(self). .. py:class:: OriginInfoCategory(*args, **kwargs) Bases: :py:obj:`django.db.models.Model` This class represents a category of information, which further specifies what its parent_tag is already telling about the origin. It doesn't do much by itself and is instead used to group OriginInfoValues by category See also: OriginTag, OriginInfoValue .. py:class:: Meta Bases: :py:obj:`object` .. py:attribute:: verbose_name .. py:attribute:: verbose_name_plural .. py:attribute:: unique_together :annotation: = ['name', 'parent_tag'] .. py:attribute:: parent_tag .. py:attribute:: name .. py:attribute:: order .. py:method:: __str__() Return str(self). .. py:class:: OriginInfoCategoryLocalization(*args, **kwargs) Bases: :py:obj:`django.db.models.Model` Make subclasses preserve the alters_data attribute on overridden methods. .. py:class:: Meta Bases: :py:obj:`object` .. py:attribute:: unique_together :annotation: = ['origin_info_category', 'language'] .. py:attribute:: verbose_name .. py:attribute:: verbose_name_plural .. py:attribute:: origin_info_category .. py:attribute:: language .. py:attribute:: full_name .. py:method:: __str__() Return str(self). .. py:class:: OriginInfoValue(*args, **kwargs) Bases: :py:obj:`django.db.models.Model` This class represents additional information, further specifying what its parent_tag is already telling about the origin. Each OriginInfoValue has a category, in which it should be unique, and problems should only have one OriginInfoValue within any category. See alse: OriginTag, OriginInfoCategory .. py:class:: Meta Bases: :py:obj:`object` .. py:attribute:: unique_together :annotation: = ['parent_tag', 'value'] .. py:attribute:: verbose_name .. py:attribute:: verbose_name_plural .. py:property:: name .. py:property:: full_name .. py:attribute:: parent_tag .. py:attribute:: category .. py:attribute:: value .. py:attribute:: order .. py:attribute:: problems .. py:method:: __str__() Return str(self). .. py:class:: OriginInfoValueLocalization(*args, **kwargs) Bases: :py:obj:`django.db.models.Model` Make subclasses preserve the alters_data attribute on overridden methods. .. py:class:: Meta Bases: :py:obj:`object` .. py:attribute:: unique_together :annotation: = ['origin_info_value', 'language'] .. py:attribute:: verbose_name .. py:attribute:: verbose_name_plural .. py:attribute:: origin_info_value .. py:attribute:: language .. py:attribute:: full_value .. py:method:: __str__() Return str(self). .. py:class:: DifficultyTag(*args, **kwargs) Bases: :py:obj:`django.db.models.Model` Make subclasses preserve the alters_data attribute on overridden methods. .. py:class:: Meta Bases: :py:obj:`object` .. py:attribute:: verbose_name .. py:attribute:: verbose_name_plural .. py:attribute:: name .. py:attribute:: problems .. py:method:: __str__() Return str(self). .. py:class:: DifficultyTagThrough(*args, **kwargs) Bases: :py:obj:`django.db.models.Model` Make subclasses preserve the alters_data attribute on overridden methods. .. py:attribute:: problem .. py:attribute:: tag .. py:method:: __str__() Return str(self). .. py:class:: DifficultyTagLocalization(*args, **kwargs) Bases: :py:obj:`django.db.models.Model` Make subclasses preserve the alters_data attribute on overridden methods. .. py:class:: Meta Bases: :py:obj:`object` .. py:attribute:: unique_together :annotation: = ['difficulty_tag', 'language'] .. py:attribute:: verbose_name .. py:attribute:: verbose_name_plural .. py:attribute:: difficulty_tag .. py:attribute:: language .. py:attribute:: full_name .. py:method:: __str__() Return str(self). .. py:class:: DifficultyTagProposal(*args, **kwargs) Bases: :py:obj:`django.db.models.Model` Make subclasses preserve the alters_data attribute on overridden methods. .. py:class:: Meta Bases: :py:obj:`object` .. py:attribute:: verbose_name .. py:attribute:: verbose_name_plural .. py:attribute:: problem .. py:attribute:: tag .. py:attribute:: user .. py:method:: __str__() Return str(self). .. py:class:: AlgorithmTag(*args, **kwargs) Bases: :py:obj:`django.db.models.Model` Make subclasses preserve the alters_data attribute on overridden methods. .. py:class:: Meta Bases: :py:obj:`object` .. py:attribute:: verbose_name .. py:attribute:: verbose_name_plural .. py:attribute:: name .. py:attribute:: problems .. py:method:: __str__() Return str(self). .. py:class:: AlgorithmTagThrough(*args, **kwargs) Bases: :py:obj:`django.db.models.Model` Make subclasses preserve the alters_data attribute on overridden methods. .. py:class:: Meta Bases: :py:obj:`object` .. py:attribute:: unique_together :annotation: = ['problem', 'tag'] .. py:attribute:: problem .. py:attribute:: tag .. py:method:: __str__() Return str(self). .. py:class:: AlgorithmTagLocalization(*args, **kwargs) Bases: :py:obj:`django.db.models.Model` Make subclasses preserve the alters_data attribute on overridden methods. .. py:class:: Meta Bases: :py:obj:`object` .. py:attribute:: unique_together :annotation: = ['algorithm_tag', 'language'] .. py:attribute:: verbose_name .. py:attribute:: verbose_name_plural .. py:attribute:: algorithm_tag .. py:attribute:: language .. py:attribute:: full_name .. py:method:: __str__() Return str(self). .. py:class:: AlgorithmTagProposal(*args, **kwargs) Bases: :py:obj:`django.db.models.Model` Make subclasses preserve the alters_data attribute on overridden methods. .. py:class:: Meta Bases: :py:obj:`object` .. py:attribute:: verbose_name .. py:attribute:: verbose_name_plural .. py:attribute:: problem .. py:attribute:: tag .. py:attribute:: user .. py:method:: __str__() Return str(self).