Skip to content

Commit

Permalink
(no-ticket) Quote contest's id in admin url
Browse files Browse the repository at this point in the history
Django admin uses some kind of escaping special characters with
underscores.
This caused 404 with primary key containing something like '_21'.

Change-Id: I76f8b2e0358f7504c851648b18bfd04a78cd9dca
  • Loading branch information
matrach committed Sep 12, 2013
1 parent 40a688d commit 5e5ec66
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions oioioi/contests/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import urllib

from django.contrib.admin import AllValuesFieldListFilter, SimpleListFilter
from django.contrib.admin.util import unquote
from django.contrib.admin.util import unquote, quote
from django.core.urlresolvers import reverse
from django.forms.models import modelform_factory
from django.http import HttpResponseRedirect
Expand Down Expand Up @@ -135,7 +135,7 @@ def _mixins_for_instance(self, request, instance):

contest_admin_menu_registry.register('contest_change', _("Settings"),
lambda request: reverse('oioioiadmin:contests_contest_change',
args=(request.contest.id,)), order=20)
args=(quote(request.contest.id),)), order=20)


class ProblemInstanceAdmin(admin.ModelAdmin):
Expand Down
9 changes: 5 additions & 4 deletions oioioi/contests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from django.core.files.base import ContentFile
from django.utils.timezone import utc, LocalTimezone
from django.contrib.auth.models import User, AnonymousUser
from django.contrib.admin.util import quote

from oioioi.base.tests import check_not_accessible, fake_time
from oioioi.contests.models import Contest, Round, ProblemInstance, \
Expand Down Expand Up @@ -491,8 +492,8 @@ def test_simple_contest_create_and_change(self):
self.assertEqual(round.results_date,
datetime(2012, 2, 5, 6, 7, 8, tzinfo=LocalTimezone()))

url = reverse('oioioiadmin:contests_contest_change', args=('cid',)) \
+ '?simple=true'
url = reverse('oioioiadmin:contests_contest_change',
args=(quote('cid'),)) + '?simple=true'
response = self.client.get(url)
self.assertIn('2012-02-05', response.content)
self.assertIn('06:07:08', response.content)
Expand Down Expand Up @@ -521,8 +522,8 @@ def test_simple_contest_create_and_change(self):
self.assertEqual(round.results_date,
datetime(2013, 2, 5, 16, 7, 8, tzinfo=LocalTimezone()))

url = reverse('oioioiadmin:contests_contest_change', args=('cid',)) \
+ '?simple=true'
url = reverse('oioioiadmin:contests_contest_change',
args=(quote('cid'),)) + '?simple=true'
response = self.client.get(url)
post_data = {
'name': 'cname1',
Expand Down

0 comments on commit 5e5ec66

Please sign in to comment.