Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
bug 564341, use request.amo_user to get profile.
Browse files Browse the repository at this point in the history
  • Loading branch information
davedash committed May 7, 2010
1 parent 4211e84 commit 65994b2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
16 changes: 12 additions & 4 deletions apps/addons/tests/test_views.py
Expand Up @@ -279,21 +279,29 @@ def test_details_collections_dropdown(self):

request = Mock()
request.APP.id = 1
request.user.is_authenticated = lambda: True

profile = Mock()
profile.id = 10482
request.amo_user.id = 10482

addon = Mock()
addon.id = 4048

ret = _details_collections_dropdown(request, profile, addon)
ret = _details_collections_dropdown(request, addon)
eq_(len(ret), 2)

# Add-on exists in one of the collections
addon.id = 433
ret = _details_collections_dropdown(request, profile, addon)
ret = _details_collections_dropdown(request, addon)
eq_(len(ret), 1)

request.user.is_authenticated = lambda: False
request.amo_user.id = None

ret = _details_collections_dropdown(request, addon)
eq_(len(ret), 0)



def test_remove_tag_button(self):
self.client.login(username='regular@mozilla.com', password='password')
r = self.client.get(reverse('addons.detail', args=[3615]))
Expand Down
14 changes: 6 additions & 8 deletions apps/addons/views.py
Expand Up @@ -11,7 +11,6 @@
from amo import urlresolvers
from amo.urlresolvers import reverse
from bandwagon.models import Collection, CollectionFeature, CollectionPromo
from users.models import UserProfile
from stats.models import GlobalStat
from tags.models import Tag
from .models import Addon
Expand Down Expand Up @@ -103,12 +102,7 @@ def extension_detail(request, addon):
popular_coll = collections.order_by('-subscribers')[:coll_show_count]

# this user's collections
if request.user.is_authenticated():
profile = UserProfile.objects.get(user=request.user)
user_collections = _details_collections_dropdown(request,
profile, addon)
else:
user_collections = []
user_collections = _details_collections_dropdown(request, addon)

data = {
'addon': addon,
Expand All @@ -129,7 +123,7 @@ def extension_detail(request, addon):
return jingo.render(request, 'addons/details.html', data)


def _details_collections_dropdown(request, profile, addon):
def _details_collections_dropdown(request, addon):
"""Returns the collections which should be shown on an add-on details
page for a logged in user. This is used in the "Add to a collection..."
dropdown. Rules to be in this list:
Expand All @@ -146,6 +140,10 @@ def _details_collections_dropdown(request, profile, addon):
Q(collectionuser__role=amo.COLLECTION_ROLE_PUBLISHER),
application__id=request.APP.id)
"""
if request.user.is_authenticated():
profile = request.amo_user
else:
return []

sql = """
SELECT DISTINCT
Expand Down

0 comments on commit 65994b2

Please sign in to comment.