Revert "use addonuser for personas (bug 734531)"

This reverts commit fd3ad4b1a5.
This commit is contained in:
Chris Van 2012-03-15 13:29:18 -07:00
Родитель 34444536a2
Коммит d4caef58b2
5 изменённых файлов: 55 добавлений и 56 удалений

Просмотреть файл

@ -38,7 +38,7 @@ from stats.models import AddonShareCountTotal
from translations.fields import (TranslatedField, PurifiedField,
LinkifiedField, Translation)
from translations.query import order_by_translation
from users.models import UserProfile, UserForeignKey
from users.models import UserProfile, PersonaAuthor, UserForeignKey
from users.utils import find_users
from versions.compare import version_int, version_re
from versions.models import Version
@ -725,6 +725,7 @@ class Addon(amo.models.OnChangeMixin, amo.models.ModelBase):
for persona in Persona.objects.no_cache().filter(addon__in=personas):
addon = addon_dict[persona.addon_id]
addon.persona = persona
addon.listed_authors = [PersonaAuthor(persona.display_username)]
addon.weekly_downloads = persona.popularity
# TODO: This shouldn't be necessary when we import theme users.
author = UserProfile(display_name=persona.display_username)
@ -783,20 +784,14 @@ class Addon(amo.models.OnChangeMixin, amo.models.ModelBase):
def icon_url(self):
return self.get_icon_url(32)
def authors_other_addons(self, app=None):
@property
def authors_other_addons(self):
"""
Return other addons by the author(s) of this addon,
optionally takes an app.
Return other addons by the author(s) of this addon
"""
if app:
qs = Addon.objects.listed(app)
else:
qs = Addon.objects.valid()
return (qs.exclude(id=self.id)
.exclude(type=amo.ADDON_WEBAPP)
.filter(addonuser__listed=True,
authors__in=self.listed_authors)
.distinct())
return (Addon.objects.valid().exclude(id=self.id)
.filter(addonuser__listed=True,
authors__in=self.listed_authors).distinct())
@property
def contribution_url(self, lang=settings.LANGUAGE_CODE,
@ -1390,14 +1385,6 @@ class Persona(caching.CachingMixin, models.Model):
'updateURL': self.update_url,
}, separators=(',', ':'), cls=JSONEncoder)
def authors_other_addons(self, app=None):
return (Addon.objects.listed(app)
.exclude(id=self.id)
.filter(addonuser__listed=True,
authors__in=self.addon.listed_authors,
type=amo.ADDON_PERSONA)
.distinct())
class AddonCategory(caching.CachingMixin, models.Model):
addon = models.ForeignKey(Addon)

Просмотреть файл

@ -1543,20 +1543,11 @@ class TestImpalaDetailPage(amo.tests.TestCase):
amo.tests.check_links(expected, links)
class TestPersonas(object):
def create_addon_user(self, addon, user=None):
if user is None:
user = UserProfile.objects.get(pk=999)
AddonUser.objects.create(addon=addon, user=user)
class TestPersonaDetailPage(TestPersonas, amo.tests.TestCase):
class TestPersonaDetailPage(amo.tests.TestCase):
fixtures = ['addons/persona', 'base/users']
def setUp(self):
self.addon = Addon.objects.get(id=15663)
self.create_addon_user(self.addon)
self.persona = self.addon.persona
self.url = self.addon.get_url_path()
@ -1571,19 +1562,15 @@ class TestPersonaDetailPage(TestPersonas, amo.tests.TestCase):
def test_more_personas(self):
other = addon_factory(type=amo.ADDON_PERSONA)
self.create_addon_user(other)
other.persona.author = self.persona.author
other.persona.save()
r = self.client.get(self.url)
eq_(pq(r.content)('#more-artist .more-link').length, 1)
def test_more_personas_no_addon(self):
other = addon_factory(type=amo.ADDON_EXTENSION)
self.create_addon_user(other)
r = self.client.get(self.url)
eq_(pq(r.content)('#more-artist .more-link').length, 0)
def test_new_more_personas(self):
other = addon_factory(type=amo.ADDON_PERSONA)
self.create_addon_user(other)
other.persona.author = self.persona.author
other.persona.save()
self.persona.persona_id = 0
self.persona.save()
r = self.client.get(self.url)
@ -1596,7 +1583,9 @@ class TestPersonaDetailPage(TestPersonas, amo.tests.TestCase):
addon_factory(type=amo.ADDON_PERSONA, disabled_by_user=True)
other = addon_factory(type=amo.ADDON_PERSONA)
self.create_addon_user(other)
other.persona.author = self.persona.author
other.persona.save()
eq_(other.persona.author, self.persona.author)
eq_(other.status, amo.STATUS_PUBLIC)
eq_(other.disabled_by_user, False)
@ -1971,15 +1960,14 @@ class TestMobileHome(TestMobile):
self._test_addons()
class TestMobileDetails(TestPersonas, TestMobile):
fixtures = TestMobile.fixtures + ['base/featured', 'base/users']
class TestMobileDetails(TestMobile):
fixtures = TestMobile.fixtures + ['base/featured']
def setUp(self):
super(TestMobileDetails, self).setUp()
self.ext = Addon.objects.get(id=3615)
self.url = reverse('addons.detail', args=[self.ext.slug])
self.persona = Addon.objects.get(id=15679)
self.create_addon_user(self.persona)
self.persona_url = self.persona.get_url_path()
def test_extension(self):
@ -1997,13 +1985,15 @@ class TestMobileDetails(TestPersonas, TestMobile):
def test_more_personas(self):
other = addon_factory(type=amo.ADDON_PERSONA)
self.create_addon_user(other)
other.persona.author = self.persona.persona.author
other.persona.save()
r = self.client.get(self.persona_url, follow=True)
eq_(pq(r.content)('#more-artist .more-link').length, 1)
def test_new_more_personas(self):
other = addon_factory(type=amo.ADDON_PERSONA)
self.create_addon_user(other)
other.persona.author = self.persona.persona.author
other.persona.save()
self.persona.persona.persona_id = 0
self.persona.persona.save()
r = self.client.get(self.persona_url, follow=True)

Просмотреть файл

@ -46,7 +46,7 @@ from versions.models import Version
from .models import Addon, Persona, FrozenAddon
from .decorators import (addon_view_factory, can_be_purchased, has_purchased,
has_not_purchased)
from mkt.webapps.models import Installed
from mkt.webapps.models import Webapp, Installed
log = commonware.log.getLogger('z.addons')
paypal_log = commonware.log.getLogger('z.paypal')
@ -145,7 +145,15 @@ def extension_detail(request, addon):
# does a lot more queries we don't want on the initial page load.
if request.is_ajax():
# Other add-ons/apps from the same author(s).
ctx['author_addons'] = addon.authors_other_addons(app=request.APP)[:6]
if addon.is_webapp():
others = Webapp.objects.listed().filter(type=amo.ADDON_WEBAPP)
else:
others = (Addon.objects.listed(request.APP)
.exclude(type=amo.ADDON_WEBAPP))
others = (others.exclude(id=addon.id).distinct()
.filter(addonuser__listed=True,
authors__in=addon.listed_authors))
ctx['author_addons'] = others[:6]
return jingo.render(request, 'addons/impala/details-more.html', ctx)
else:
if addon.is_webapp():
@ -181,11 +189,17 @@ def persona_detail(request, addon, template=None):
else:
category_personas = None
# other personas from the same author(s)
author_personas = Addon.objects.public().filter(
persona__author=persona.author,
type=amo.ADDON_PERSONA).exclude(
pk=addon.pk).select_related('persona')[:3]
data = {
'addon': addon,
'persona': persona,
'categories': categories,
'author_personas': persona.authors_other_addons(request.APP)[:3],
'author_personas': author_personas,
'category_personas': category_personas,
}
if not persona.is_new():

Просмотреть файл

@ -516,6 +516,22 @@ class BlacklistedEmailDomain(amo.models.ModelBase):
return True
class PersonaAuthor(unicode):
"""Stub user until the persona authors get imported."""
@property
def id(self):
"""I don't want to change code depending on PersonaAuthor.id, so I'm
just hardcoding 0. The only code using this is flush_urls."""
return 0
@property
def name(self):
return self
display_name = name
class BlacklistedPassword(amo.models.ModelBase):
"""Blacklisted passwords"""
password = models.CharField(max_length=255, unique=True, blank=False)

Просмотреть файл

@ -186,14 +186,6 @@ class Webapp(Addon):
"""When the submission process is done, update status accordingly."""
self.update(status=amo.WEBAPPS_UNREVIEWED_STATUS)
def authors_other_addons(self, app=None):
"""Return other apps by the same author."""
return (self.__class__.objects.listed()
.filter(type=amo.ADDON_WEBAPP)
.exclude(id=self.id).distinct()
.filter(addonuser__listed=True,
authors__in=self.listed_authors))
# Pull all translated_fields from Addon over to Webapp.
Webapp._meta.translated_fields = Addon._meta.translated_fields