Beispiel #1
0
def regenerate_key_view(request, member_type):
    registration_config = get_object_or_404(RegistrationConfig,
            contest=request.contest)

    if member_type == 'teacher':
        registration_config.teacher_key = generate_key()
    elif member_type == 'pupil':
        registration_config.pupil_key = generate_key()
    else:
        raise Http404

    registration_config.save()

    return redirect_to_members(request, member_type)
Beispiel #2
0
def regenerate_key_view(request, member_type):
    registration_config = get_object_or_404(RegistrationConfig,
                                            contest=request.contest)

    if member_type == 'teacher':
        registration_config.teacher_key = generate_key()
    elif member_type == 'pupil':
        registration_config.pupil_key = generate_key()
    else:
        raise Http404

    registration_config.save()

    return redirect_to_members(request, member_type)
def set_default_values(apps, schema_editor):
    """For every :class:`oioioi.problems.models.Problem`.main_problem_instance
       replaces it with copy with contest and round set on None.
       This function assumes that each :class:`oioioi.problems.models.Problem`
       has main_problem_instance.

       Also if there is no ProblemSite for given Problem creates one.

       Field author is set as creator of the problem's problem_package
       (function assumes that there is only one problem_package for problem)
    """
    Problem = apps.get_model('problems', 'Problem')
    ProblemSite = apps.get_model('problems', 'ProblemSite')

    for problem in Problem.objects.all():
        pi = problem.main_problem_instance
        if pi.contest:
            pi.id = pi.pk = None  # there will be a copy created when 'save()'
            pi.contest = pi.round = None
            pi.save()
            for test in problem.main_problem_instance.test_set.all():
                test.id = test.pk = None
                test.problem_instance = pi
                test.save()
            problem.main_problem_instance = pi
            problem.save()

        if not ProblemSite.objects.filter(problem=problem).exists():
            site = ProblemSite(problem=problem, url_key=generate_key())
            site.save()

        if not problem.author:
            problem.author = problem.problempackage_set.get().created_by
            problem.save()
def set_default_values(apps, schema_editor):
    """For every :class:`oioioi.problems.models.Problem`.main_problem_instance
       replaces it with copy with contest and round set on None.
       This function assumes that each :class:`oioioi.problems.models.Problem`
       has main_problem_instance.

       Also if there is no ProblemSite for given Problem creates one.

       Field author is set as creator of the problem's problem_package
       (function assumes that there is only one problem_package for problem)
    """
    Problem = apps.get_model('problems', 'Problem')
    ProblemSite = apps.get_model('problems', 'ProblemSite')

    for problem in Problem.objects.all():
        pi = problem.main_problem_instance
        if pi.contest:
            pi.id = pi.pk = None # there will be a copy created when 'save()'
            pi.contest = pi.round = None
            pi.save()
            for test in problem.main_problem_instance.test_set.all():
                test.id = test.pk = None
                test.problem_instance = pi
                test.save()
            problem.main_problem_instance = pi
            problem.save()

        if not ProblemSite.objects.filter(problem=problem).exists():
            site = ProblemSite(problem=problem, url_key=generate_key())
            site.save()

        if not problem.author:
            problem.author = problem.problempackage_set.get().created_by
            problem.save()
Beispiel #5
0
def regenerate_sharing_key_view(request, usergroup_id):
    if not is_usergroup_owner(request.user, usergroup_id):
        raise PermissionDenied

    group = get_object_or_404(
        UserGroup.objects.select_related('sharing_config'), id=usergroup_id)

    group.sharing_config.key = generate_key()
    group.sharing_config.save()

    return redirect('teacher_usergroup_detail', usergroup_id=usergroup_id)
Beispiel #6
0
 def save(self, *args, **kwargs):
     if not hasattr(self, 'user'):
         self.user = User.objects.create_user(self.login, 'team user', '')
         self.user.first_name = self.name
         self.user.save()
     else:
         self.user.username = self.login
         self.user.first_name = self.name
         self.user.save()
     if not self.join_key:
         self.join_key = generate_key()
     super(Team, self).save(*args, **kwargs)
Beispiel #7
0
 def save(self, *args, **kwargs):
     if not hasattr(self, 'user'):
         self.user = User.objects.create_user(self.login, 'team user', '')
         self.user.first_name = self.name
         self.user.save()
     else:
         self.user.username = self.login
         self.user.first_name = self.name
         self.user.save()
     if not self.join_key:
         self.join_key = generate_key()
     super(Team, self).save(*args, **kwargs)
Beispiel #8
0
    def view(self, request, contest, existing_problem=None):
        is_reupload = existing_problem is not None
        if is_reupload:  # reuploading doesn't make much sense here
            return _("Reuploading quizzes is not supported")

        if request.method == "POST":
            form = EmptyQuizSourceForm(request.POST)
        else:
            form = EmptyQuizSourceForm()

        post_data = {'form': form, 'is_reupload': is_reupload}

        if request.method == "POST" and form.is_valid():
            with transaction.atomic():
                controller = self.problem_controller_class
                quiz = Quiz.objects.create(
                    name=form.cleaned_data['name'],
                    short_name=form.cleaned_data['short_name'],
                    controller_name=controller,
                    author=request.user,
                )

                algorithm_tag, created = AlgorithmTag.objects.get_or_create(
                    name='Quiz')
                if not created:
                    for language_code, _ in LANGUAGES:
                        AlgorithmTagLocalization.objects.create(
                            algorithm_tag=algorithm_tag,
                            language=language_code,
                            name='Quiz',
                        )
                AlgorithmTagThrough.objects.create(problem=quiz,
                                                   tag=algorithm_tag)

                ProblemSite.objects.create(problem=quiz,
                                           url_key=generate_key())
                pi = ProblemInstance.objects.create(problem=quiz,
                                                    short_name=quiz.short_name)
                quiz.main_problem_instance = pi
                quiz.save()
                if contest:
                    quiz.contest = contest
                    get_new_problem_instance(quiz, contest)

                messages.success(request, _("Quiz successfully added"))

                return safe_redirect(
                    request,
                    reverse('oioioiadmin:contests_probleminstance_changelist'))

        return TemplateResponse(request, "quizzes/emptyquiz-source.html",
                                post_data)
Beispiel #9
0
    def _create_problem_or_reuse_if_exists(self, existing_problem):
        if existing_problem:
            self.problem = existing_problem
            self._ensure_short_name_equality_with(existing_problem)
        else:
            self.problem = self._create_problem_instance()
            problem_site = ProblemSite(problem=self.problem,
                                       url_key=generate_key())
            problem_site.save()
            self.problem.problem_site = problem_site

        self.main_problem_instance = self.problem.main_problem_instance
        self.problem.package_backend_name = self.package_backend_name
        self.problem.save()
Beispiel #10
0
    def _create_problem_or_reuse_if_exists(self, existing_problem):
        if existing_problem:
            self.problem = existing_problem
            self._ensure_short_name_equality_with(existing_problem)
        else:
            self.problem = self._create_problem_instance()
            problem_site = ProblemSite(problem=self.problem,
                                       url_key=generate_key())
            problem_site.save()
            self.problem.problem_site = problem_site

        self.main_problem_instance = self.problem.main_problem_instance
        self.problem.package_backend_name = self.package_backend_name
        self.problem.save()
Beispiel #11
0
    def unpack(self, env, package):
        self.short_name = self._find_main_folder()
        self.env = env
        self.package = package
        existing_problem = self.package.problem
        if existing_problem:
            self.problem = existing_problem
            self.main_problem_instance = self.problem.main_problem_instance
            if existing_problem.short_name != self.short_name:
                raise ProblemPackageError(_("Tried to replace problem "
                    "'%(oldname)s' with '%(newname)s'. For safety, changing "
                    "problem short name is not possible.") %
                    dict(oldname=existing_problem.short_name,
                        newname=self.short_name))
        else:
            author_username = env.get('author')
            if author_username:
                author = User.objects.get(username=author_username)
            else:
                author = None

            self.problem = Problem.create(
                    name=self.short_name,
                    short_name=self.short_name,
                    controller_name=self.controller_name,
                    contest=self.package.contest,
                    is_public=(author is None),
                    author=author)
            problem_site = ProblemSite(problem=self.problem,
                                       url_key=generate_key())
            problem_site.save()
            self.problem.problem_site = problem_site
            self.main_problem_instance = self.problem.main_problem_instance

        self.problem.package_backend_name = self.package_backend_name
        self.problem.save()
        tmpdir = tempfile.mkdtemp()
        logger.info("%s: tmpdir is %s", self.filename, tmpdir)
        try:
            self.archive.extract(to_path=tmpdir)
            self.rootdir = os.path.join(tmpdir, self.short_name)
            self.process_package()

            return self.problem
        finally:
            shutil.rmtree(tmpdir)
            if self.prog_archive:
                get_client().delete_file(self.prog_archive)
Beispiel #12
0
    def view(self, request, contest, existing_problem=None):
        is_reupload = existing_problem is not None
        if is_reupload:  # reuploading doesn't make much sense here
            return _("Reuploading quizzes is not supported")

        if request.method == "POST":
            form = EmptyQuizSourceForm(request.POST)
        else:
            form = EmptyQuizSourceForm()
        post_data = {'form': form, 'is_reupload': is_reupload}

        if request.method == "POST" and form.is_valid():
            with transaction.atomic():
                controller = 'oioioi.quizzes.controllers.QuizProblemController'
                quiz = Quiz.objects.create(
                    name=form.cleaned_data['name'],
                    short_name=form.cleaned_data['short_name'],
                    controller_name=controller,
                    author=request.user
                )
                tag = Tag.objects.get_or_create(name='quiz')[0]
                TagThrough.objects.create(
                    problem=quiz,
                    tag=tag
                )
                ProblemSite.objects.create(
                    problem=quiz,
                    url_key=generate_key()
                )
                pi = ProblemInstance.objects.create(
                    problem=quiz,
                    short_name=quiz.short_name
                )
                quiz.main_problem_instance = pi
                quiz.save()
                if contest:
                    quiz.contest = contest
                    get_new_problem_instance(quiz, contest)

                messages.success(request, _("Quiz successfully added"))
                return safe_redirect(request, reverse(
                    'oioioiadmin:contests_probleminstance_changelist'))

        return TemplateResponse(request, "quizzes/emptyquiz-source.html",
                                post_data)
Beispiel #13
0
 def generate_key(self):
     self.access_key = generate_key()[:16]
Beispiel #14
0
def generate_key_view(request):
    return HttpResponse(generate_key())
Beispiel #15
0
    def __init__(self, *args, **kwargs):
        super(ActionConfig, self).__init__(*args, **kwargs)

        if not self.key:
            self.key = generate_key()
Beispiel #16
0
def generate_key_view(request):
    return HttpResponse(generate_key())
Beispiel #17
0
 def __init__(self, *args, **kwargs):
     super(RegistrationConfig, self).__init__(*args, **kwargs)
     if not self.teacher_key:
         self.teacher_key = generate_key()
     if not self.pupil_key:
         self.pupil_key = generate_key()
Beispiel #18
0
 def generate_key(self):
     self.access_key = generate_key()[:16]
Beispiel #19
0
 def __init__(self, *args, **kwargs):
     super(RegistrationConfig, self).__init__(*args, **kwargs)
     if not self.teacher_key:
         self.teacher_key = generate_key()
     if not self.pupil_key:
         self.pupil_key = generate_key()