Skip to content

Commit

Permalink
Issue mozilla#108: List team memberships on profile page
Browse files Browse the repository at this point in the history
  • Loading branch information
lmorchard committed Feb 28, 2015
1 parent 48a8be3 commit 4caacd5
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
1 change: 1 addition & 0 deletions badgus/base/static/css/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ ul.awardees li.awardee .label {

ul.awardees li.awardee .label:before { content: "\263A\00a0"; font-size: 1.25em; }

ul.teams { margin: 0pt; padding: 0pt; }
ul.teams li { border-radius: 8px 8px 8px 8px; border: 1px solid #EEEEEE;
list-style: none outside none; margin: 0pt 0.75em 0.75em 0pt; padding: 0pt; }
ul.teams li img { border-radius: 8px 8px 8px 8px; display: block; }
Expand Down
27 changes: 27 additions & 0 deletions badgus/profiles/templates/profiles/profile_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,33 @@ <h3>
</section>
{% endif %}

{% if teams %}
<section id="team_membership" class="item_flow">
<header class="page-header">
<h3>
<span>{{ _('Teams') }}</span>
</h3>
</header>
<ul class="teams">
{% for team in teams %}
<li class="team">
{% if team and team.image %}
{% set image_url = team.image.url %}
{% else %}
{# TODO: Put the URL for default team image in settings #}
{% set image_url = static("img/default-badge.png") %}
{% endif %}
<a href="{{ team.get_absolute_url() }}" class="image"><img src="{{ image_url }}"
alt="{{ team.name }}" width="128" height="128" /></a>
<a href="{{ team.get_absolute_url() }}" class="label"><span class="title">{{ team.name }}</span></a>
</li>
{% else %}
<li>{{ _("No teams, yet.") }}</li>
{% endfor %}
</ul>
</section>
{% endif %}

</section>

{% endblock %}
46 changes: 46 additions & 0 deletions badgus/profiles/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import logging

import json
from nose.tools import eq_, ok_
from django.test import TestCase
from django.http import HttpRequest
from django import test

from django.contrib.auth.models import User

from pyquery import PyQuery as pq
from django_browserid.tests import mock_browserid

from tower import activate

from teamwork.models import Role

from badger.models import Badge

from badgus.base.urlresolvers import reverse
from badgus.teams.models import BadgeTeam


class BadgeProfileViewsTest(test.TestCase):

def test_list_team_membership(self):
"""User profile page should list team memberships"""
team = BadgeTeam(name='randoteam23')
team.save()

team.members.through.objects.all().delete()

member = User(username='rando23', email='[email protected]')
member.save()

url = member.get_absolute_url()

r = self.client.get(url, follow=True)
doc = pq(r.content)
eq_(0, doc.find('.teams .team .label .title:contains("randoteam23")').length)

team.add_member(member)

r = self.client.get(url, follow=True)
doc = pq(r.content)
eq_(1, doc.find('.teams .team .label .title:contains("randoteam23")').length)
6 changes: 5 additions & 1 deletion badgus/profiles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from .models import UserProfile
from .forms import UserProfileEditForm, UserEditForm

from badgus.teams.models import BadgeTeam

try:
from commons.urlresolvers import reverse
except ImportError, e:
Expand Down Expand Up @@ -49,8 +51,10 @@ def profile_view(request, username):
user = get_object_or_404(User, username=username)
profile = user.get_profile()

teams = BadgeTeam.objects.filter(members__username=user.username)

return render_to_response('profiles/profile_view.html', dict(
user=user, profile=profile
user=user, profile=profile, teams=teams
), context_instance=RequestContext(request))


Expand Down

0 comments on commit 4caacd5

Please sign in to comment.