Merge lp:~mhall119/loco-team-portal/fixes-805280 into lp:loco-team-portal

Proposed by Michael Hall
Status: Merged
Approved by: Chris Johnston
Approved revision: 453
Merged at revision: 457
Proposed branch: lp:~mhall119/loco-team-portal/fixes-805280
Merge into: lp:loco-team-portal
Diff against target: 136 lines (+67/-18)
5 files modified
loco_directory/teams/models.py (+7/-0)
loco_directory/templates/venues/venue_detail.html (+5/-1)
loco_directory/templates/venues/venue_list.html (+1/-1)
loco_directory/venues/models.py (+5/-1)
loco_directory/venues/tests.py (+49/-15)
To merge this branch: bzr merge lp:~mhall119/loco-team-portal/fixes-805280
Reviewer Review Type Date Requested Status
Chris Johnston Approve
Review via email: mp+66736@code.launchpad.net

Commit message

Fix various errors with using country name as part of the venue URL

Description of the change

Overview
========
Reverse lookup was failing on a Korean venue

Details
=======
Reverse lookups were failing because the Country object of Korea has the name "Korea, Republic of" and the comma was causing the error. I introduce a "slug" property to the Country model that will give a safer version of the country name, stripping commas and replacing spaces with underscores.

To post a comment you must log in.
Revision history for this message
Chris Johnston (cjohnston) wrote :

Needs test cases.

review: Needs Fixing
Revision history for this message
Chris Johnston (cjohnston) wrote :

Works great.

450. By Michael Hall

[r=chrisjohnston][] Reduces the number of DB hits and code process for the teams list.

452. By Michael Hall

Replace hyphen with underscore in Country.slug fallback

453. By Michael Hall

Add tests

Revision history for this message
Chris Johnston (cjohnston) wrote :

When running ./manage.py test I got:

http://paste.ubuntu.com/645081/

review: Needs Information
Revision history for this message
Michael Hall (mhall119) wrote :

The Teams tests are old, I'll look into fixing them up later. For now, just run "python manage.py test venes" to run just the tests I added in this branch.

Revision history for this message
Chris Johnston (cjohnston) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'loco_directory/teams/models.py'
--- loco_directory/teams/models.py 2011-06-24 15:25:54 +0000
+++ loco_directory/teams/models.py 2011-07-12 00:57:31 +0000
@@ -59,6 +59,13 @@
59 def related_venues(self):59 def related_venues(self):
60 return self.venue_set.all()60 return self.venue_set.all()
6161
62 @property
63 def slug(self):
64 if self.name is not None:
65 return self.name.replace(',', '').replace(' ', '_')
66 else:
67 return 'no_country'
68
62def countries_without_continent():69def countries_without_continent():
63 return Country.objects.filter(continents__isnull=True)70 return Country.objects.filter(continents__isnull=True)
6471
6572
=== modified file 'loco_directory/templates/venues/venue_detail.html'
--- loco_directory/templates/venues/venue_detail.html 2011-03-16 18:35:53 +0000
+++ loco_directory/templates/venues/venue_detail.html 2011-07-12 00:57:31 +0000
@@ -11,7 +11,11 @@
1111
12{% block sub_nav_links %}12{% block sub_nav_links %}
13<a class="sub-nav-item" href="{% url venue-list %}" >{% trans "Back to Venues List" %}</a>13<a class="sub-nav-item" href="{% url venue-list %}" >{% trans "Back to Venues List" %}</a>
14<a class="sub-nav-item" href="{% url venue-update venue_object.country venue_object.id %}">{% trans "Edit Venue Details" %}</a>14{% if venue_object.country %}
15<a class="sub-nav-item" href="{% url venue-update venue_object.country.slug venue_object.id %}">{% trans "Edit Venue Details" %}</a>
16{% else %}
17<a class="sub-nav-item" href="{% url venue-update 'no_country' venue_object.id %}">{% trans "Edit Venue Details" %}</a>
18{% endif %}
15{% endblock %}19{% endblock %}
1620
17{% block content %}21{% block content %}
1822
=== modified file 'loco_directory/templates/venues/venue_list.html'
--- loco_directory/templates/venues/venue_list.html 2010-11-27 00:54:13 +0000
+++ loco_directory/templates/venues/venue_list.html 2011-07-12 00:57:31 +0000
@@ -57,7 +57,7 @@
57 <ul>57 <ul>
58 {% for venue in venues_without_country %}58 {% for venue in venues_without_country %}
59 <li>59 <li>
60 <p><a title="{% trans "show venue details" %}" href="{{ venue.get_absolute_url }}">{{ venue.name }}{% if venue.city %}, {{ venue.city }}{% endif %}{% if venue.spr %}, {{ venue.spr }}{% endif %}</a></p>60 <p><a title="{% trans "show venue details" %}" href="{{ venue.get_absolute_url }}">{% if venue %}{{ venue.name }}{% else %}{% trans 'No Name' %}{% endif %}{% if venue.city %}, {{ venue.city }}{% endif %}{% if venue.spr %}, {{ venue.spr }}{% endif %}</a></p>
61 </li>61 </li>
62 {% endfor %}62 {% endfor %}
63 </ul>63 </ul>
6464
=== modified file 'loco_directory/venues/models.py'
--- loco_directory/venues/models.py 2011-06-17 17:10:41 +0000
+++ loco_directory/venues/models.py 2011-07-12 00:57:31 +0000
@@ -45,7 +45,11 @@
45 @models.permalink45 @models.permalink
46 def get_absolute_url(self):46 def get_absolute_url(self):
47 """ get the absolute url for the venue """47 """ get the absolute url for the venue """
48 return ('venue-detail', [self.country or 'no-country', self.id])48 if self.country:
49 country = self.country.slug
50 else:
51 country = 'no_country'
52 return ('venue-detail', [country, self.id])
4953
50 def save(self, *args, **kargs):54 def save(self, *args, **kargs):
51 if self.id:55 if self.id:
5256
=== modified file 'loco_directory/venues/tests.py'
--- loco_directory/venues/tests.py 2009-12-21 20:45:43 +0000
+++ loco_directory/venues/tests.py 2011-07-12 00:57:31 +0000
@@ -6,18 +6,52 @@
6"""6"""
77
8from django.test import TestCase8from django.test import TestCase
99from teams.models import Country, Team
10class SimpleTest(TestCase):10from venues.models import Venue
11 def test_basic_addition(self):11
12 """12
13 Tests that 1 + 1 always equals 2.13class ViewTests(TestCase):
14 """14
15 self.failUnlessEqual(1 + 1, 2)15 def setUp(self):
1616 self.country = Country.objects.create(name='Test Country')
17__test__ = {"doctest": """17 self.team = Team.objects.create(
18Another way to test that 1 + 1 is equal to 2.18 lp_name='test-team',
1919 name='Test Team',
20>>> 1 + 1 == 220 )
21True21 self.team.countries.add(self.country)
22"""}22 self.venue = Venue.objects.create(
2323 name='Test Venue',
24 country=self.country,
25 )
26
27 def test_venue_list(self):
28 response = self.client.get('/events/venues/')
29
30 # Check that the country group is labeled
31 self.assertContains(response, 'Test Country', 1)
32
33 # Check that the venue name is displayed
34 self.assertContains(response, 'Test Venue', 1)
35
36 # Check that the venue details URL exists using the propert country slug
37 self.assertContains(response, 'href="/events/venues/Test_Country/%s/detail/"' % self.venue.id, 1)
38
39 def test_venue_details_subnav(self):
40 response = self.client.get('/events/venues/Test_Country/%s/detail/' % self.venue.id)
41
42 # Check edit url exists using the proper country slug
43 self.assertContains(response, 'href="/events/venues/Test_Country/%s/update/"' % self.venue.id)
44
45 def test_country_contains_comma(self):
46 self.country.name='Korea, Republic of'
47 self.country.save()
48
49 # Check list view
50 response = self.client.get('/events/venues/')
51 self.assertContains(response, 'Korea, Republic of', 1)
52 self.assertContains(response, 'href="/events/venues/Korea_Republic_of/%s/detail/"' % self.venue.id, 1)
53
54 # Check details view
55 response = self.client.get('/events/venues/Test_Country/%s/detail/' % self.venue.id)
56 self.assertContains(response, 'href="/events/venues/Korea_Republic_of/%s/update/"' % self.venue.id)
57

Subscribers

People subscribed via source and target branches