attach favorite add-ons to request.amo_user
This commit is contained in:
Родитель
bbdd2cf60e
Коммит
26937318d1
|
@ -49,14 +49,15 @@ class UserProfile(amo.models.ModelBase):
|
||||||
|
|
||||||
nickname = models.CharField(max_length=255, default='', null=True,
|
nickname = models.CharField(max_length=255, default='', null=True,
|
||||||
blank=True)
|
blank=True)
|
||||||
firstname = models.CharField(max_length=255, default='', null=True, blank=True)
|
firstname = models.CharField(max_length=255, default='', null=True,
|
||||||
lastname = models.CharField(max_length=255, default='', null=True, blank=True)
|
blank=True)
|
||||||
|
lastname = models.CharField(max_length=255, default='', null=True,
|
||||||
|
blank=True)
|
||||||
|
|
||||||
username = models.CharField(max_length=255, default='', unique=True)
|
username = models.CharField(max_length=255, default='', unique=True)
|
||||||
display_name = models.CharField(max_length=255, default='', null=True,
|
display_name = models.CharField(max_length=255, default='', null=True,
|
||||||
blank=True)
|
blank=True)
|
||||||
|
|
||||||
|
|
||||||
password = models.CharField(max_length=255, default='')
|
password = models.CharField(max_length=255, default='')
|
||||||
email = models.EmailField(unique=True)
|
email = models.EmailField(unique=True)
|
||||||
|
|
||||||
|
@ -218,10 +219,15 @@ class UserProfile(amo.models.ModelBase):
|
||||||
# We don't want to cache these things on every UserProfile; they're
|
# We don't want to cache these things on every UserProfile; they're
|
||||||
# only used by a user attached to a request.
|
# only used by a user attached to a request.
|
||||||
from bandwagon.models import CollectionAddon
|
from bandwagon.models import CollectionAddon
|
||||||
|
SPECIAL = amo.COLLECTION_SPECIAL_SLUGS.keys()
|
||||||
user = users[0]
|
user = users[0]
|
||||||
qs = CollectionAddon.objects.filter(
|
qs = CollectionAddon.objects.filter(
|
||||||
collection__author=user, collection__type=amo.COLLECTION_MOBILE)
|
collection__author=user, collection__type__in=SPECIAL)
|
||||||
user.mobile_addons = qs.values_list('addon', flat=True)
|
addons = dict((type_, []) for type_ in SPECIAL)
|
||||||
|
for addon, ctype in qs.values_list('addon', 'collection__type'):
|
||||||
|
addons[ctype].append(addon)
|
||||||
|
user.mobile_addons = addons[amo.COLLECTION_MOBILE]
|
||||||
|
user.favorite_addons = addons[amo.COLLECTION_FAVORITES]
|
||||||
|
|
||||||
|
|
||||||
class BlacklistedUsername(amo.models.ModelBase):
|
class BlacklistedUsername(amo.models.ModelBase):
|
||||||
|
|
|
@ -218,3 +218,5 @@ class TestProfile(UserViewBase):
|
||||||
request = response.context['request']
|
request = response.context['request']
|
||||||
assert hasattr(request.amo_user, 'mobile_addons')
|
assert hasattr(request.amo_user, 'mobile_addons')
|
||||||
assert hasattr(request.user.get_profile(), 'mobile_addons')
|
assert hasattr(request.user.get_profile(), 'mobile_addons')
|
||||||
|
assert hasattr(request.amo_user, 'favorite_addons')
|
||||||
|
assert hasattr(request.user.get_profile(), 'favorite_addons')
|
||||||
|
|
Загрузка…
Ссылка в новой задаче