Permalink
Browse files

[fix bug 763543] Display location on profile.

If location data is in the profile, display it. Works with the same
restriction that you must fill in less-specific data (e.g. country)
before more specific data (e.g. region) (and that you can't skip
levels). This is enforced by the form's validation, so will be fine
here.
  • Loading branch information...
1 parent bb3d0d5 commit 6cdcc67d0f585fc6bb1ad24301770e90db43148f James Socol committed Jun 20, 2012
Showing with 81 additions and 1 deletion.
  1. +23 −0 apps/phonebook/templates/phonebook/profile.html
  2. +40 −1 apps/phonebook/tests/test_views.py
  3. +18 −0 media/css/base.css
View
23 apps/phonebook/templates/phonebook/profile.html
@@ -163,6 +163,29 @@ <h2 class="fn p-name">
</ul>
{% endif %}
+ {% if profile.country %}
+ <div class="location">
+ <div class="country">
+ <h3>{{ _('Country') }}</h3>
+ <p>{{ profile.get_country_display() }}</p>
+ </div>
+
+ {% if profile.region %}
+ <div class="region">
+ <h3>{{ _('Province/State') }}</h3>
+ <p>{{ profile.region }}</p>
+ </div>
+
+ {% if profile.city %}
+ <div class="city">
+ <h3>{{ _('City') }}</h3>
+ <p>{{ profile.city }}</p>
+ </div>
+ {% endif %}{# city #}
+ {% endif %}{# region #}
+ </div>
+ {% endif %}{# country #}
+
{% if shown_user.username == request.user.username %}
<a href="{{ url('profile.edit') }}"
class="btn btn-primary pull-right" id="edit-profile">
View
41 apps/phonebook/tests/test_views.py
@@ -8,7 +8,7 @@
from nose.tools import eq_
from pyquery import PyQuery as pq
-from common.tests import TestCase
+from common.tests import TestCase, user
from funfactory.urlresolvers import set_url_prefix, reverse
@@ -255,6 +255,45 @@ def test_has_website(self):
doc('#profile-info dd a[rel=me]')[0].get('href')), (
'User should have a URL with protocol added.')
+ def test_has_country(self):
+ u = user(username='sam')
+ p = u.get_profile()
+ p.country = 'us'
+ p.save()
+ assert self.client.login(email=u.email)
+ r = self.client.get(reverse('profile', args=[u.username]), follow=True)
+ self.assertContains(r, '<h3>Country</h3>')
+ self.assertNotContains(r, '<h3>Province/State</h3>')
+ self.assertNotContains(r, '<h3>City</h3>')
+
+ def test_has_region(self):
+ u = user(username='sam')
+ p = u.get_profile()
+ p.country = 'us'
+ p.region = 'New York'
+ p.save()
+ assert self.client.login(email=u.email)
+ r = self.client.get(reverse('profile', args=[u.username]), follow=True)
+ self.assertContains(r, '<h3>Country</h3>')
+ self.assertContains(r, '<h3>Province/State</h3>')
+ self.assertContains(r, p.region)
+ self.assertNotContains(r, '<h3>City</h3>')
+
+ def test_has_city(self):
+ u = user(username='sam')
+ p = u.get_profile()
+ p.country = 'us'
+ p.region = 'New York'
+ p.city = 'Brooklyn'
+ p.save()
+ assert self.client.login(email=u.email)
+ r = self.client.get(reverse('profile', args=[u.username]), follow=True)
+ self.assertContains(r, '<h3>Country</h3>')
+ self.assertContains(r, '<h3>Province/State</h3>')
+ self.assertContains(r, p.region)
+ self.assertContains(r, '<h3>City</h3>')
+ self.assertContains(r, p.city)
+
def test_replace_photo(self):
"""Ensure we can replace photos."""
client = self.mozillian_client
View
18 media/css/base.css
@@ -551,3 +551,21 @@ footer div.container {
label, input, button, select, textarea {
font-family:'Open Sans', "Lucida Sans", "Lucida Grande", "Lucida Sans Unicode", Verdana, sans-serif;
}
+
+/* Micro-clearfix */
+.location:before,
+.location:after {
+ content: "";
+ display: table;
+}
+
+.location:after {
+ clear: both;
+}
+
+/* TODO: Add rtl support here. */
+.location div {
+ float: left;
+ width: 33%;
+ margin: 0;
+}

0 comments on commit 6cdcc67

Please sign in to comment.