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

Commit

Permalink
Revert "use addonuser for personas (bug 734531)"
Browse files Browse the repository at this point in the history
This reverts commit fd3ad4b.
  • Loading branch information
cvan committed Mar 15, 2012
1 parent 3444453 commit d4caef5
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 56 deletions.
29 changes: 8 additions & 21 deletions apps/addons/models.py
Expand Up @@ -38,7 +38,7 @@
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
Expand Down Expand Up @@ -725,6 +725,7 @@ def transformer(addons):
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)
Expand Down Expand Up @@ -783,20 +784,14 @@ def current_beta_version(self):
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,
Expand Down Expand Up @@ -1390,14 +1385,6 @@ def json_data(self):
'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)
Expand Down
38 changes: 14 additions & 24 deletions apps/addons/tests/test_views.py
Expand Up @@ -1543,20 +1543,11 @@ def test_categories(self):
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()

Expand All @@ -1571,19 +1562,15 @@ def test_persona_images(self):

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)
Expand All @@ -1596,7 +1583,9 @@ def test_other_personas(self):
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)

Expand Down Expand Up @@ -1971,15 +1960,14 @@ def test_addons(self):
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):
Expand All @@ -1997,13 +1985,15 @@ def test_persona(self):

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)
Expand Down
20 changes: 17 additions & 3 deletions apps/addons/views.py
Expand Up @@ -46,7 +46,7 @@
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')
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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():
Expand Down
16 changes: 16 additions & 0 deletions apps/users/models.py
Expand Up @@ -516,6 +516,22 @@ def blocked(cls, domain):
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)
Expand Down
8 changes: 0 additions & 8 deletions mkt/webapps/models.py
Expand Up @@ -186,14 +186,6 @@ def mark_done(self):
"""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
Expand Down

0 comments on commit d4caef5

Please sign in to comment.