helpers for getting mobile/favorites collection
This commit is contained in:
Родитель
3a2c8c8eaf
Коммит
f65c1829f5
|
@ -421,7 +421,7 @@ COLLECTION_NORMAL = 0
|
|||
COLLECTION_SYNCHRONIZED = 1
|
||||
COLLECTION_FEATURED = 2
|
||||
COLLECTION_RECOMMENDED = 3
|
||||
COLLECTION_FAVORITE = 4
|
||||
COLLECTION_FAVORITES = 4
|
||||
COLLECTION_MOBILE = 5
|
||||
COLLECTION_ANONYMOUS = 6
|
||||
|
||||
|
@ -430,7 +430,7 @@ COLLECTION_CHOICES = {
|
|||
COLLECTION_SYNCHRONIZED: 'Synchronized',
|
||||
COLLECTION_FEATURED: 'Featured',
|
||||
COLLECTION_RECOMMENDED: 'Generated Recommendations',
|
||||
COLLECTION_FAVORITE: 'Favorites',
|
||||
COLLECTION_FAVORITES: 'Favorites',
|
||||
COLLECTION_MOBILE: 'Mobile',
|
||||
COLLECTION_ANONYMOUS: 'Anonymous',
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ class CollectionManager(amo.models.ManagerBase):
|
|||
def manual(self):
|
||||
"""Only hand-crafted, favorites, and featured collections should appear
|
||||
in this filter."""
|
||||
types = (amo.COLLECTION_NORMAL, amo.COLLECTION_FAVORITE,
|
||||
types = (amo.COLLECTION_NORMAL, amo.COLLECTION_FAVORITES,
|
||||
amo.COLLECTION_FEATURED, )
|
||||
|
||||
return self.filter(type__in=types)
|
||||
|
@ -63,6 +63,7 @@ class Collection(amo.models.ModelBase):
|
|||
|
||||
uuid = models.CharField(max_length=36, blank=True, unique=True)
|
||||
name = TranslatedField()
|
||||
# nickname is deprecated. Use slug.
|
||||
nickname = models.CharField(max_length=30, blank=True, unique=True,
|
||||
null=True)
|
||||
slug = models.CharField(max_length=30, blank=True, null=True)
|
||||
|
|
|
@ -194,6 +194,22 @@ class UserProfile(amo.models.ModelBase):
|
|||
self.save()
|
||||
return self.user
|
||||
|
||||
def mobile_collection(self):
|
||||
return self.special_collection(amo.COLLECTION_MOBILE,
|
||||
defaults={'slug': 'mobile', 'listed': False,
|
||||
'name': _('My Mobile Add-ons')})
|
||||
|
||||
def favorites_collection(self):
|
||||
return self.special_collection(amo.COLLECTION_FAVORITES,
|
||||
defaults={'slug': 'favorites', 'listed': False,
|
||||
'name': _('My Favorite Add-ons')})
|
||||
|
||||
def special_collection(self, type_, defaults):
|
||||
from bandwagon.models import Collection
|
||||
c, _ = Collection.objects.get_or_create(
|
||||
author=self, type=type_, defaults=defaults)
|
||||
return c
|
||||
|
||||
|
||||
class BlacklistedNickname(amo.models.ModelBase):
|
||||
"""Blacklisted user nicknames."""
|
||||
|
|
|
@ -9,6 +9,7 @@ from nose.tools import eq_
|
|||
|
||||
import amo.test_utils
|
||||
from addons.models import Addon, AddonUser
|
||||
from bandwagon.models import Collection
|
||||
from reviews.models import Review
|
||||
from users.models import UserProfile, get_hexdigest, BlacklistedNickname
|
||||
|
||||
|
@ -117,6 +118,22 @@ class TestUserProfile(amo.test_utils.ExtraSetup, test.TestCase):
|
|||
addons = u.addons_listed.values_list('id', flat=True)
|
||||
eq_(sorted(addons), [3615, 4664])
|
||||
|
||||
def test_mobile_collection(self):
|
||||
u = UserProfile.objects.get(id='4043307')
|
||||
assert not Collection.objects.filter(author=u)
|
||||
|
||||
c = u.mobile_collection()
|
||||
eq_(c.type, amo.COLLECTION_MOBILE)
|
||||
eq_(c.slug, 'mobile')
|
||||
|
||||
def test_favorites_collection(self):
|
||||
u = UserProfile.objects.get(id='4043307')
|
||||
assert not Collection.objects.filter(author=u)
|
||||
|
||||
c = u.favorites_collection()
|
||||
eq_(c.type, amo.COLLECTION_FAVORITES)
|
||||
eq_(c.slug, 'favorites')
|
||||
|
||||
|
||||
class TestPasswords(test.TestCase):
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче