:py:mod:`oioioi.problems.problem_sources` ========================================= .. py:module:: oioioi.problems.problem_sources Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: oioioi.problems.problem_sources.ProblemSource oioioi.problems.problem_sources.PackageSource oioioi.problems.problem_sources.UploadedPackageSource oioioi.problems.problem_sources.ProblemsetSource Functions ~~~~~~~~~ .. autoapisummary:: oioioi.problems.problem_sources.problem_sources Attributes ~~~~~~~~~~ .. autoapisummary:: oioioi.problems.problem_sources.logger .. py:data:: logger .. py:function:: problem_sources(request, existing_problem=False) .. py:class:: ProblemSource Bases: :py:obj:`object` .. py:attribute:: key :annotation: = __override_in_a_subclass__ .. py:attribute:: short_description :annotation: = __override_in_a_subclass__ .. py:method:: view(request, contest, existing_problem=None) :abstractmethod: Renders the view where the user can upload the file or point out where to get the problem from. If the request method is ``GET``, it should return rendered HTML, which will be injected in an appropriate div element. :class:`~django.template.response.TemplateResponse` is fine, too. If the request method is ``POST``, it should start the unpacking process. If no errors occur, it should return :class:`~django.http.HttpResponseRedirect` (e.g. to a view with problem packages queued for processing). :param request: Django request :param contest: :class:`~oioioi.contests.models.Contest` where the problem is going to be attached (or is already attached); may be ``None``. :param existing_problem: :class:`~oioioi.problems.models.Problem` to update (if problem update was requested) .. py:method:: is_available(request) Returns ``True`` if the source is available for the given request. .. py:class:: PackageSource Bases: :py:obj:`ProblemSource` .. py:attribute:: key :annotation: = upload .. py:attribute:: short_description .. py:attribute:: template_name :annotation: = problems/package-source.html .. py:method:: make_form(request, contest, existing_problem=None) :abstractmethod: Creates a form, which can be later filled in by the user with information necessary for obtaining the problem package. If the request method is ``POST``, then the form should be filled with its data. .. py:method:: get_package_file(request, contest, form, existing_problem=None) :abstractmethod: Extracts the information from the validated form and returns the package file provided by the user. Should return a pair ``(filename, file_manager)``, where ``filename`` is the original name of the file specified by the user and ``file_manager`` is a context manager. This ``file_manager`` will be later used like this: .. python:: with file_manager as path: process the file pointed to by ``path`` Moreover, ``file_manager`` should take care of unlinking the file if this is necessary. The ``filename`` may be ``None`` if the name of the file returned by the ``file_manager`` ends with an appropriate extension (so that it is possible to choose the right backend for it). .. py:method:: choose_backend(path, original_filename=None) Returns the dotted name of a :class:`~oioioi.package.ProblemPackageBackend` suitable for processing a given package. This function is called when an unpacking environment is created, i.e. from :meth:`~oioioi.problems.problem_sources.ProblemSource.create_env`. .. py:method:: create_package_instance(user, contest, path, existing_problem=None, original_filename=None) Creates a :class:`~oioioi.problems.models.ProblemPackage` instance from a given package file. .. py:method:: create_env(user, contest, path, package, form, round_id=None, visibility=Problem.VISIBILITY_FRIENDS, existing_problem=None, original_filename=None) Creates an environment which will be later passed to :func:`~oioioi.problems.unpackmgr.unpackmgr_job`. .. py:method:: _redirect_response(request) .. py:method:: handle_form(form, request, contest, existing_problem=None) .. py:method:: process_package(request, file_manager, user, contest, original_filename=None, existing_problem=None, round_id=None, visibility=Problem.VISIBILITY_FRIENDS, form=None) .. py:method:: view(request, contest, existing_problem=None) Renders the view where the user can upload the file or point out where to get the problem from. If the request method is ``GET``, it should return rendered HTML, which will be injected in an appropriate div element. :class:`~django.template.response.TemplateResponse` is fine, too. If the request method is ``POST``, it should start the unpacking process. If no errors occur, it should return :class:`~django.http.HttpResponseRedirect` (e.g. to a view with problem packages queued for processing). :param request: Django request :param contest: :class:`~oioioi.contests.models.Contest` where the problem is going to be attached (or is already attached); may be ``None``. :param existing_problem: :class:`~oioioi.problems.models.Problem` to update (if problem update was requested) .. py:class:: UploadedPackageSource Bases: :py:obj:`PackageSource` .. py:method:: make_form(request, contest, existing_problem=None) Creates a form, which can be later filled in by the user with information necessary for obtaining the problem package. If the request method is ``POST``, then the form should be filled with its data. .. py:method:: get_package_file(request, contest, form, existing_problem=None) Extracts the information from the validated form and returns the package file provided by the user. Should return a pair ``(filename, file_manager)``, where ``filename`` is the original name of the file specified by the user and ``file_manager`` is a context manager. This ``file_manager`` will be later used like this: .. python:: with file_manager as path: process the file pointed to by ``path`` Moreover, ``file_manager`` should take care of unlinking the file if this is necessary. The ``filename`` may be ``None`` if the name of the file returned by the ``file_manager`` ends with an appropriate extension (so that it is possible to choose the right backend for it). .. py:method:: is_available(request) Returns ``True`` if the source is available for the given request. .. py:class:: ProblemsetSource Bases: :py:obj:`ProblemSource` .. py:attribute:: key :annotation: = problemset_source .. py:attribute:: short_description .. py:method:: view(request, contest, existing_problem=None) Renders the view where the user can upload the file or point out where to get the problem from. If the request method is ``GET``, it should return rendered HTML, which will be injected in an appropriate div element. :class:`~django.template.response.TemplateResponse` is fine, too. If the request method is ``POST``, it should start the unpacking process. If no errors occur, it should return :class:`~django.http.HttpResponseRedirect` (e.g. to a view with problem packages queued for processing). :param request: Django request :param contest: :class:`~oioioi.contests.models.Contest` where the problem is going to be attached (or is already attached); may be ``None``. :param existing_problem: :class:`~oioioi.problems.models.Problem` to update (if problem update was requested)