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
1=== modified file 'loco_directory/teams/models.py'
2--- loco_directory/teams/models.py 2011-06-24 15:25:54 +0000
3+++ loco_directory/teams/models.py 2011-07-12 00:57:31 +0000
4@@ -59,6 +59,13 @@
5 def related_venues(self):
6 return self.venue_set.all()
7
8+ @property
9+ def slug(self):
10+ if self.name is not None:
11+ return self.name.replace(',', '').replace(' ', '_')
12+ else:
13+ return 'no_country'
14+
15 def countries_without_continent():
16 return Country.objects.filter(continents__isnull=True)
17
18
19=== modified file 'loco_directory/templates/venues/venue_detail.html'
20--- loco_directory/templates/venues/venue_detail.html 2011-03-16 18:35:53 +0000
21+++ loco_directory/templates/venues/venue_detail.html 2011-07-12 00:57:31 +0000
22@@ -11,7 +11,11 @@
23
24 {% block sub_nav_links %}
25 <a class="sub-nav-item" href="{% url venue-list %}" >{% trans "Back to Venues List" %}</a>
26-<a class="sub-nav-item" href="{% url venue-update venue_object.country venue_object.id %}">{% trans "Edit Venue Details" %}</a>
27+{% if venue_object.country %}
28+<a class="sub-nav-item" href="{% url venue-update venue_object.country.slug venue_object.id %}">{% trans "Edit Venue Details" %}</a>
29+{% else %}
30+<a class="sub-nav-item" href="{% url venue-update 'no_country' venue_object.id %}">{% trans "Edit Venue Details" %}</a>
31+{% endif %}
32 {% endblock %}
33
34 {% block content %}
35
36=== modified file 'loco_directory/templates/venues/venue_list.html'
37--- loco_directory/templates/venues/venue_list.html 2010-11-27 00:54:13 +0000
38+++ loco_directory/templates/venues/venue_list.html 2011-07-12 00:57:31 +0000
39@@ -57,7 +57,7 @@
40 <ul>
41 {% for venue in venues_without_country %}
42 <li>
43- <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>
44+ <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>
45 </li>
46 {% endfor %}
47 </ul>
48
49=== modified file 'loco_directory/venues/models.py'
50--- loco_directory/venues/models.py 2011-06-17 17:10:41 +0000
51+++ loco_directory/venues/models.py 2011-07-12 00:57:31 +0000
52@@ -45,7 +45,11 @@
53 @models.permalink
54 def get_absolute_url(self):
55 """ get the absolute url for the venue """
56- return ('venue-detail', [self.country or 'no-country', self.id])
57+ if self.country:
58+ country = self.country.slug
59+ else:
60+ country = 'no_country'
61+ return ('venue-detail', [country, self.id])
62
63 def save(self, *args, **kargs):
64 if self.id:
65
66=== modified file 'loco_directory/venues/tests.py'
67--- loco_directory/venues/tests.py 2009-12-21 20:45:43 +0000
68+++ loco_directory/venues/tests.py 2011-07-12 00:57:31 +0000
69@@ -6,18 +6,52 @@
70 """
71
72 from django.test import TestCase
73-
74-class SimpleTest(TestCase):
75- def test_basic_addition(self):
76- """
77- Tests that 1 + 1 always equals 2.
78- """
79- self.failUnlessEqual(1 + 1, 2)
80-
81-__test__ = {"doctest": """
82-Another way to test that 1 + 1 is equal to 2.
83-
84->>> 1 + 1 == 2
85-True
86-"""}
87-
88+from teams.models import Country, Team
89+from venues.models import Venue
90+
91+
92+class ViewTests(TestCase):
93+
94+ def setUp(self):
95+ self.country = Country.objects.create(name='Test Country')
96+ self.team = Team.objects.create(
97+ lp_name='test-team',
98+ name='Test Team',
99+ )
100+ self.team.countries.add(self.country)
101+ self.venue = Venue.objects.create(
102+ name='Test Venue',
103+ country=self.country,
104+ )
105+
106+ def test_venue_list(self):
107+ response = self.client.get('/events/venues/')
108+
109+ # Check that the country group is labeled
110+ self.assertContains(response, 'Test Country', 1)
111+
112+ # Check that the venue name is displayed
113+ self.assertContains(response, 'Test Venue', 1)
114+
115+ # Check that the venue details URL exists using the propert country slug
116+ self.assertContains(response, 'href="/events/venues/Test_Country/%s/detail/"' % self.venue.id, 1)
117+
118+ def test_venue_details_subnav(self):
119+ response = self.client.get('/events/venues/Test_Country/%s/detail/' % self.venue.id)
120+
121+ # Check edit url exists using the proper country slug
122+ self.assertContains(response, 'href="/events/venues/Test_Country/%s/update/"' % self.venue.id)
123+
124+ def test_country_contains_comma(self):
125+ self.country.name='Korea, Republic of'
126+ self.country.save()
127+
128+ # Check list view
129+ response = self.client.get('/events/venues/')
130+ self.assertContains(response, 'Korea, Republic of', 1)
131+ self.assertContains(response, 'href="/events/venues/Korea_Republic_of/%s/detail/"' % self.venue.id, 1)
132+
133+ # Check details view
134+ response = self.client.get('/events/venues/Test_Country/%s/detail/' % self.venue.id)
135+ self.assertContains(response, 'href="/events/venues/Korea_Republic_of/%s/update/"' % self.venue.id)
136+

Subscribers

People subscribed via source and target branches