Skip to content

Commit

Permalink
SIO-2137 Add button 'rejudge not needed' to problem actions
Browse files Browse the repository at this point in the history
Change-Id: Ib298a8100de2d8b19be057806c76cffc49488ae8
  • Loading branch information
jmolinski committed Dec 15, 2020
1 parent 47a9123 commit 4384861
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 86 deletions.
35 changes: 18 additions & 17 deletions oioioi/contests/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,24 +304,26 @@ def has_delete_permission(self, request, obj=None):

def _problem_change_href(self, instance):
came_from = reverse('oioioiadmin:contests_probleminstance_changelist')
return reverse('oioioiadmin:problems_problem_change',
args=(instance.problem_id,)) + '?' + \
six.moves.urllib.parse.urlencode({'came_from': came_from})
came_from_arg = six.moves.urllib.parse.urlencode({'came_from': came_from})
problem_change_base_href = reverse(
'oioioiadmin:problems_problem_change', args=(instance.problem_id,)
)
return '%s?%s' % (problem_change_base_href, came_from_arg)

def _rejudge_all_submissions_for_problem_href(self, instance):
return reverse('rejudge_all_submissions_for_problem',
args=(instance.id,))
return reverse('rejudge_all_submissions_for_problem', args=(instance.id,))

def _set_needs_rejudge_to_false_href(self, instance):
return reverse('rejudge_not_needed', args=(instance.id,))

def _model_solutions_href(self, instance):
return reverse('model_solutions', args=(instance.id,))

def _problem_site_href(self, instance):
return reverse('problem_site',
args=(instance.problem.problemsite.url_key,))
return reverse('problem_site', args=(instance.problem.problemsite.url_key,))

def _reset_limits_href(self, instance):
return reverse('reset_tests_limits_for_probleminstance',
args=(instance.id,))
return reverse('reset_tests_limits_for_probleminstance', args=(instance.id,))

def _reattach_problem_href(self, instance):
return reverse('reattach_problem_contest_list', args=(instance.id,))
Expand All @@ -336,12 +338,10 @@ def _package_manage_href(self, instance):
six.moves.urllib.parse.urlencode({'key': 'manage_files_problem_package'})

def _edit_quiz_href(self, instance):
return reverse('oioioiadmin:quizzes_quiz_change',
args=[instance.problem.pk])
return reverse('oioioiadmin:quizzes_quiz_change', args=[instance.problem.pk])

def _move_href(self, instance):
return reverse('oioioiadmin:contests_probleminstance_change',
args=(instance.id,))
return reverse('oioioiadmin:contests_probleminstance_change', args=(instance.id,))

def get_list_display(self, request):
items = super(ProblemInstanceAdmin, self).get_list_display(request)
Expand Down Expand Up @@ -377,10 +377,11 @@ def inline_actions(self, instance):
add_or_update_href = self._add_or_update_href(instance)
result.append((add_or_update_href, _("Reupload package")))
if instance.needs_rejudge:
rejudge_all_href = self \
._rejudge_all_submissions_for_problem_href(instance)
result.append((rejudge_all_href,
_("Rejudge all submissions for problem")))
rejudge_all_href = self._rejudge_all_submissions_for_problem_href(instance)
result.append((rejudge_all_href, _("Rejudge all submissions for problem")))
rejudge_not_needed_href = self._set_needs_rejudge_to_false_href(instance)
result.append((rejudge_not_needed_href, _("Rejudge not needed")))

problem_change_href = self._problem_change_href(instance)
package_manage_href = self._package_manage_href(instance)
request = self._request_local.request
Expand Down
32 changes: 32 additions & 0 deletions oioioi/contests/templates/contests/base_confirmation_screen.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{% extends "base-with-menu.html" %}
{% load i18n %}

{% block title %}Put the title here.{% endblock %}

{% block main-content %}
<h1>{% block confirmation_header %}Put the header here.{% endblock %}</h1>

{% block confirmation_form_explanation %}
Put some explanation about what is going to happen here.
{% endblock %}


{% block confirmation_form %}
<p>{% trans "Are you sure?" %}</p>

<div>
<form method="post">
{% csrf_token %}
<input type="hidden" name="post" value="yes"/>
<div class="form-group">
<button type="submit" class="btn btn-danger">
{% trans "Yes, I am sure." %}
</button>
<button type="button" class="btn btn-default" onclick="history.back()">
{% trans "No, go back" %}
</button>
</div>
</form>
</div>
{% endblock %}
{% endblock %}
39 changes: 10 additions & 29 deletions oioioi/contests/templates/contests/confirm_rejudge.html
Original file line number Diff line number Diff line change
@@ -1,33 +1,14 @@
{% extends "base-with-menu.html" %}
{% extends "contests/base_confirmation_screen.html" %}
{% load i18n %}

{% block title %}{% trans "Confirm rejudge" %}{% endblock %}

{% block main-content %}

<h1>{% trans "Confirm rejudge" %}</h1>

<p>
{% trans "Tests for this problem have changed, you should rejudge existing submissions." %}
</p>
<p>
{% blocktrans %}You are going to rejudge {{ count }} submissions. It may take some time.{% endblocktrans %}
</p>

<p>{% trans "Are you sure?" %}</p>

<div>
<form method="post">
{% csrf_token %}
<input type="hidden" name="post" value="yes" />
<div class="form-group">
<button type="submit" class="btn btn-danger">
{% trans "Yes, I am sure." %}
</button>
<button type="button" class="btn btn-default" onclick="history.back()">
{% trans "No, go back" %}
</button>
</div>
</form>
</div>
{% block confirmation_header %}{% trans "Confirm rejudge" %}{% endblock %}
{% block confirmation_form_explanation %}
<p>
{% trans "Something about this problem has changed. If the change was trivial (like a typo) then rejudge is not needed." %}
{% trans "If the tests for the problem have changed then you should proceed with a rejudge." %}
</p>
<p>
{% blocktrans %}You are going to rejudge {{ count }} submissions. It may take some time.{% endblocktrans %}
</p>
{% endblock %}
15 changes: 15 additions & 0 deletions oioioi/contests/templates/contests/confirm_rejudge_not_needed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends "contests/base_confirmation_screen.html" %}
{% load i18n %}

{% block title %}{% trans "Confirm rejudge is not needed" %}{% endblock %}

{% block confirmation_header %}{% trans "Confirm rejudge is not needed" %}{% endblock %}
{% block confirmation_form_explanation %}
<p>
{% trans "Something about this problem has changed. If the change was trivial (like a typo) then rejudge is not needed." %}
{% trans "If the tests for the problem have changed then you should proceed with a rejudge." %}
</p>
<p>
{% blocktrans %}You are going to mark the submissions to this problem as not needing a rejudge.{% endblocktrans %}
</p>
{% endblock %}
46 changes: 15 additions & 31 deletions oioioi/contests/templates/contests/confirm_resetting_limits.html
Original file line number Diff line number Diff line change
@@ -1,37 +1,21 @@
{% extends "base-with-menu.html" %}
{% extends "contests/base_confirmation_screen.html" %}
{% load i18n %}

{% block title %}{% trans "Confirm resetting limits" %}{% endblock %}

{% block main-content %}
{% block confirmation_header %}{% trans "Confirm resetting limits" %}{% endblock %}

<h1>{% trans "Confirm resetting limits" %}</h1>

<p>
{% url 'problem_site' probleminstance.problem.problemsite.url_key as url %}
{% blocktrans %}
You are going to reset time and memory limits and point
scores of all tests for problem {{ probleminstance }}.
<br>
Limits and scores for this problem will be replaced by limits setted on
<a href="{{ url }}">
{{ problem site }}
</a>.
{% endblocktrans %}
</p>

<p>{% trans "Are you sure?" %}</p>

<form method="post">
{% csrf_token %}
<input type="hidden" name="post" value="yes" />
<div class="form-group">
<button type="submit" class="btn btn-danger">
{% trans "Yes, I am sure." %}
</button>
<button type="button" class="btn btn-default" onclick="history.back()">
{% trans "No, go back" %}
</button>
</div>
</form>
{% block confirmation_form_explanation %}
<p>
{% url 'problem_site' probleminstance.problem.problemsite.url_key as url %}
{% blocktrans %}
You are going to reset time and memory limits and point
scores of all tests for problem {{ probleminstance }}.
<br>
Limits and scores for this problem will be replaced by limits set on the
<a href="{{ url }}">
problem site
</a>.
{% endblocktrans %}
</p>
{% endblock %}
19 changes: 18 additions & 1 deletion oioioi/contests/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2220,11 +2220,28 @@ def test_resetting_limits(self):
response = self.client.post(url, data={'submit': True},
follow=True)
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Tests limits resetted successfully")
self.assertContains(response, "Tests limits reset successfully")
self.assertEqual(problem_instance.test_set.count(),
problem_instance.problem.main_problem_instance.test_set.count())
self.assertNotEqual(problem_instance.test_set.count(), 0)

def test_rejudge_not_needed(self):
pi = ProblemInstance.objects.get()
pi.needs_rejudge = True
pi.save()

self.assertTrue(self.client.login(username='test_admin'))
self.client.get('/c/{}/'.format(pi.contest.pk))
response = self.client.post(
reverse('rejudge_not_needed', args=(pi.id,)),
data={'submit': True},
follow=True,
)
self.assertEqual(response.status_code, 200)
pi.refresh_from_db()
self.assertFalse(pi.needs_rejudge)



class TestReattachingProblems(TestCase):
fixtures = ['test_users', 'test_contest', 'test_extra_contests',
Expand Down
5 changes: 5 additions & 0 deletions oioioi/contests/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ def glob_namespaced_patterns(namespace):
url(r'p/(?P<problem_instance_id>[a-z0-9_-]+)/rejudge_all',
views.rejudge_all_submissions_for_problem_view,
name='rejudge_all_submissions_for_problem'),
url(
r'p/(?P<problem_instance_id>[a-z0-9_-]+)/rejudge_not_needed',
views.rejudge_not_needed_view,
name='rejudge_not_needed',
),
url(r'p/(?P<problem_instance_id>[a-z0-9_-]+)/reset_limits',
views.reset_tests_limits_for_probleminstance_view,
name='reset_tests_limits_for_probleminstance'),
Expand Down
29 changes: 22 additions & 7 deletions oioioi/contests/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,24 +457,39 @@ def user_info_redirect_view(request):

@enforce_condition(contest_exists & is_contest_basicadmin)
def rejudge_all_submissions_for_problem_view(request, problem_instance_id):
problem_instance = get_object_or_404(ProblemInstance,
id=problem_instance_id)
problem_instance = get_object_or_404(ProblemInstance, id=problem_instance_id)
count = problem_instance.submission_set.count()
if request.POST:
for submission in problem_instance.submission_set.all():
problem_instance.controller.judge(submission, request.GET.dict(),
is_rejudge=True)
messages.info(request,
ungettext_lazy("%(count)d rejudge request received.",
"%(count)d rejudge requests reveived.",
"%(count)d rejudge requests received.",
count) % {'count': count})
problem_instance.needs_rejudge = False
problem_instance.save()
problem_instance.save(update_fields=["needs_rejudge"])
return safe_redirect(request, reverse(
'oioioiadmin:contests_probleminstance_changelist'))

return TemplateResponse(request, 'contests/confirm_rejudge.html',
{'count': count})
return TemplateResponse(request, 'contests/confirm_rejudge.html', {'count': count})


@enforce_condition(contest_exists & is_contest_basicadmin)
def rejudge_not_needed_view(request, problem_instance_id):
problem_instance = get_object_or_404(ProblemInstance, id=problem_instance_id)

if request.POST:
problem_instance.needs_rejudge = False
problem_instance.save(update_fields=["needs_rejudge"])
messages.success(request, _("Needs rejudge flag turned off."))

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

return TemplateResponse(request, 'contests/confirm_rejudge_not_needed.html')


@enforce_condition(contest_exists & is_contest_basicadmin)
Expand All @@ -483,7 +498,7 @@ def reset_tests_limits_for_probleminstance_view(request, problem_instance_id):
id=problem_instance_id)
if request.POST:
update_tests_from_main_pi(problem_instance)
messages.success(request, _("Tests limits resetted successfully"))
messages.success(request, _("Tests limits reset successfully"))
return safe_redirect(request, reverse(
'oioioiadmin:contests_probleminstance_changelist'))

Expand Down
2 changes: 1 addition & 1 deletion oioioi/problems/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def update_problem_instance(env):


def update_all_probleminstances_after_reupload(problem):
"""Updates test_set for every problem_instance assiged to Problem.
"""Updates test_set for every problem_instance assigned to Problem.
to main_problem_instance.test_set
"""
for pi in problem.probleminstance_set.filter(contest__isnull=False):
Expand Down

0 comments on commit 4384861

Please sign in to comment.