Skip to content

Commit

Permalink
SIO-2334 [UI] Change labels in contest administration view
Browse files Browse the repository at this point in the history
A proposition of how the solution might look like.

Change-Id: Ib8fd163bf8a6686ba7062e86ecf5d7970e18ff33
  • Loading branch information
niewysoki committed Mar 31, 2020
1 parent 6acc2e2 commit cf205cf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
30 changes: 14 additions & 16 deletions oioioi/contests/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class ProblemInstanceAdmin(admin.ModelAdmin):
form = ProblemInstanceForm
fields = ('contest', 'round', 'problem', 'short_name', 'submissions_limit')
list_display = ('name_link', 'short_name_link', 'round', 'package',
'actions_field')
'actions_field')
readonly_fields = ('contest', 'problem')
ordering = ('-round__start_date', 'short_name')

Expand All @@ -285,9 +285,6 @@ def _problem_change_href(self, instance):
args=(instance.problem_id,)) + '?' + \
six.moves.urllib.parse.urlencode({'came_from': came_from})

def probleminstance_change_link_name(self):
return _("Edit problem")

def _rejudge_all_submissions_for_problem_href(self, instance):
return reverse('rejudge_all_submissions_for_problem',
args=(instance.id,))
Expand All @@ -314,6 +311,10 @@ def _edit_quiz_href(self, instance):
return reverse('oioioiadmin:quizzes_quiz_change',
args=[instance.problem.pk])

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

def get_list_display(self, request):
items = super(ProblemInstanceAdmin, self).get_list_display(request)
if not is_contest_admin(request):
Expand All @@ -323,24 +324,19 @@ def get_list_display(self, request):

def inline_actions(self, instance):
result = []
assert ProblemSite.objects.filter(problem=instance.problem).exists()
move_href = self._move_href(instance)
result.append((move_href, _("Edit")))
if hasattr(instance.problem, 'quiz') and instance.problem.quiz:
edit_quiz_href = self._edit_quiz_href(instance)
result.append((edit_quiz_href, _("Edit quiz questions")))

move_href = reverse('oioioiadmin:contests_probleminstance_change',
args=(instance.id,))
result.append((move_href, self.probleminstance_change_link_name()))

result.append((edit_quiz_href, _("Quiz questions")))
models_href = self._model_solutions_href(instance)
assert ProblemSite.objects.filter(problem=instance.problem).exists()
site_href = self._problem_site_href(instance)
limits_href = self._reset_limits_href(instance)
reattach_href = self._reattach_problem_href(instance)
result.extend([
(models_href, _("Model solutions")),
(site_href, _("Problem site")),
(limits_href, _("Reset tests limits")),
(reattach_href, _("Attach to another contest"))
(reattach_href, _("Attach to another contest")),
])
problem_count = len(ProblemInstance.objects.filter(
problem=instance.problem_id))
Expand All @@ -354,20 +350,22 @@ def inline_actions(self, instance):
._rejudge_all_submissions_for_problem_href(instance)
result.append((rejudge_all_href,
_("Rejudge all submissions for problem")))
problem_change_href = self._problem_change_href(instance)
result.append((problem_change_href, _("Advanced settings")))
return result

def actions_field(self, instance):
return make_html_links(self.inline_actions(instance))
actions_field.short_description = _("Actions")

def name_link(self, instance):
href = self._problem_change_href(instance)
href = self._problem_site_href(instance)
return make_html_link(href, instance.problem.name)
name_link.short_description = _("Problem")
name_link.admin_order_field = 'problem__name'

def short_name_link(self, instance):
href = self._problem_change_href(instance)
href = self._problem_site_href(instance)
return make_html_link(href, instance.short_name)
short_name_link.short_description = _("Symbol")
short_name_link.admin_order_field = 'short_name'
Expand Down
4 changes: 2 additions & 2 deletions oioioi/contests/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1497,12 +1497,12 @@ def test_menu_problems(self):
pos2 = html.find('</td>', pos)
self.assertNotEqual(pos2, -1)

self.assertIn("Edit problem", html[pos:pos2])
self.assertIn("Edit", html[pos:pos2])
self.assertIn("Model solutions", html[pos:pos2])
self.assertIn("Problem site", html[pos:pos2])
self.assertIn("Reset tests limits", html[pos:pos2])
self.assertIn("Attach to another contest", html[pos:pos2])
self.assertIn("Reupload package", html[pos:pos2])
self.assertIn("Advanced settings", html[pos:pos2])
self.assertIn("Suspend all tests", html[pos:pos2])
self.assertIn("Suspend final tests", html[pos:pos2])
self.assertEqual(html[pos:pos2].count('|'), 7)
Expand Down

0 comments on commit cf205cf

Please sign in to comment.