new persona images should not link to getpersonas.com (bug 684069)

This commit is contained in:
Chris Van 2011-11-04 15:51:00 -07:00
Родитель 70fb8bbc06
Коммит 3bc6fdfcef
6 изменённых файлов: 112 добавлений и 52 удалений

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

@ -535,8 +535,8 @@ class NewPersonaForm(AddonFormBase):
p = Persona()
p.persona_id = 0
p.addon = addon
p.header = 'header.jpg'
p.footer = 'footer.jpg'
p.header = 'header'
p.footer = 'footer'
if data['accentcolor']:
p.accentcolor = data['accentcolor'].lstrip('#')
if data['textcolor']:

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

@ -1182,6 +1182,9 @@ class Persona(caching.CachingMixin, models.Model):
def __unicode__(self):
return unicode(self.addon.name)
def is_new(self):
return self.persona_id == 0
def flush_urls(self):
urls = ['*/addon/%d/' % self.addon_id,
'*/api/*/addon/%d' % self.addon_id,
@ -1190,34 +1193,47 @@ class Persona(caching.CachingMixin, models.Model):
self.preview_url,
self.header_url,
self.footer_url,
self.update_url, ]
self.update_url,]
return urls
def _image_url(self, filename, ssl=True):
base_url = (settings.PERSONAS_IMAGE_URL_SSL if ssl else
settings.PERSONAS_IMAGE_URL)
units = self.persona_id % 10
tens = (self.persona_id // 10) % 10
return base_url % {
'units': units, 'tens': tens, 'file': filename,
'id': self.persona_id,
}
if self.is_new():
return settings.NEW_PERSONAS_IMAGE_URL % {'id': self.addon.id,
'file': filename}
else:
# TODO(cvan): Remove when getpersonas.com images go bye-bye.
base_url = (settings.PERSONAS_IMAGE_URL_SSL if ssl else
settings.PERSONAS_IMAGE_URL)
return base_url % {
'units': self.persona_id % 10,
'tens': (self.persona_id // 10) % 10,
'id': self.persona_id,
'file': filename,
}
@amo.cached_property
def thumb_url(self):
"""URL to Persona's thumbnail preview."""
return self._image_url('preview.jpg')
if self.is_new():
return self._image_url('thumb.jpg')
else:
return self._image_url('preview.jpg')
@amo.cached_property
def icon_url(self):
"""URL to personas square preview."""
return self._image_url('preview_small.jpg')
if self.is_new():
return self._image_url('icon.jpg')
else:
return self._image_url('preview_small.jpg')
@amo.cached_property
def preview_url(self):
"""URL to Persona's big, 680px, preview."""
return self._image_url('preview_large.jpg')
if self.is_new():
return self._image_url('preview.jpg')
else:
return self._image_url('preview_large.jpg')
@amo.cached_property
def header_url(self):

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

@ -1242,15 +1242,45 @@ class TestCategoryModel(amo.tests.TestCase):
class TestPersonaModel(amo.tests.TestCase):
fixtures = ['addons/persona', 'base/apps']
def setUp(self):
self.addon = Addon.objects.get(id=15663)
self.persona = self.addon.persona
self.persona.header = 'header.jpg'
self.persona.footer = 'footer.jpg'
self.persona.save()
def test_image_urls(self):
mypersona = Persona(id=1234, persona_id=9876)
assert mypersona.thumb_url.endswith('/7/6/9876/preview.jpg')
assert mypersona.preview_url.endswith('/7/6/9876/preview_large.jpg')
self.persona.persona_id = 0
self.persona.save()
p = lambda x: '/15663/' + x
assert self.persona.thumb_url.endswith(p('thumb.jpg')), (
self.persona.thumb_url)
assert self.persona.icon_url.endswith(p('icon.jpg')), (
self.persona.icon_url)
assert self.persona.preview_url.endswith(p('preview.jpg')), (
self.persona.preview_url)
assert self.persona.header_url.endswith(p('header.jpg')), (
self.persona.header_url)
assert self.persona.footer_url.endswith(p('footer.jpg')), (
self.persona.footer_url)
def test_old_image_urls(self):
p = lambda x: '/1/3/813/' + x
assert self.persona.thumb_url.endswith(p('preview.jpg')), (
self.persona.thumb_url)
assert self.persona.icon_url.endswith(p('preview_small.jpg')), (
self.persona.icon_url)
assert self.persona.preview_url.endswith(p('preview_large.jpg')), (
self.persona.preview_url)
assert self.persona.header_url.endswith(p('header.jpg')), (
self.persona.header_url)
assert self.persona.footer_url.endswith(p('footer.jpg')), (
self.persona.footer_url)
def test_update_url(self):
p = Persona(id=1234, persona_id=9876)
assert p.update_url.endswith('9876')
assert self.persona.update_url.endswith(str(self.persona.persona_id))
class TestPreviewModel(amo.tests.TestCase):

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

@ -1029,17 +1029,13 @@ class TestDetailPage(amo.tests.TestCase):
class TestImpalaDetailPage(amo.tests.TestCase):
fixtures = ['addons/persona', 'base/apps', 'base/addon_3615',
'base/addon_592', 'base/users']
fixtures = ['base/apps', 'base/addon_3615', 'base/addon_592', 'base/users']
def setUp(self):
self.addon = Addon.objects.get(id=3615)
self.url = self.addon.get_url_path()
self.more_url = self.addon.get_url_path(more=True)
self.persona = Addon.objects.get(id=15663)
self.persona_url = self.persona.get_url_path()
def test_adu(self):
doc = pq(self.client.get(self.url).content)
eq_(doc('#daily-users').text().split()[0],
@ -1143,29 +1139,6 @@ class TestImpalaDetailPage(amo.tests.TestCase):
doc = self.get_more_pq()('#author-addons')
test_hovercards(self, doc, [other], src='dp-dl-othersby')
def test_other_personas(self):
"""Ensure listed personas by the same author show up."""
addon_factory(type=amo.ADDON_PERSONA, status=amo.STATUS_NULL)
addon_factory(type=amo.ADDON_PERSONA, status=amo.STATUS_LITE)
addon_factory(type=amo.ADDON_PERSONA, disabled_by_user=True)
other = addon_factory(type=amo.ADDON_PERSONA)
other.persona.author = self.persona.persona.author
other.persona.save()
eq_(other.persona.author, self.persona.persona.author)
eq_(other.status, amo.STATUS_PUBLIC)
eq_(other.disabled_by_user, False)
# TODO(cvan): Uncomment this once Personas detail page is impalacized.
#doc = self.get_more_pq()('#author-addons')
#test_hovercards(self, doc, [other], src='dp-dl-othersby')
r = self.client.get(self.persona_url)
eq_(list(r.context['author_personas']), [other])
a = pq(r.content)('#more-artist a[data-browsertheme]')
eq_(a.length, 1)
eq_(a.attr('href'), other.get_url_path())
def test_other_addons_no_webapps(self):
"""An app by the same author should not show up."""
other = Addon.objects.get(id=592)
@ -1214,6 +1187,47 @@ class TestImpalaDetailPage(amo.tests.TestCase):
eq_(len(pq(res.content)('.prominent')), 1)
class TestPersonaDetailPage(amo.tests.TestCase):
fixtures = ['addons/persona', 'base/apps', 'base/users']
def setUp(self):
self.addon = Addon.objects.get(id=15663)
self.persona = self.addon.persona
self.url = self.addon.get_url_path()
def test_persona_images(self):
r = self.client.get(self.url)
doc = pq(r.content)
eq_(doc('h2.addon img').attr('src'), self.persona.icon_url)
style = doc('#persona div[data-browsertheme]').attr('style')
assert self.persona.preview_url in style, (
'style attribute %s does not link to %s' % (
style, self.persona.preview_url))
def test_other_personas(self):
"""Ensure listed personas by the same author show up."""
addon_factory(type=amo.ADDON_PERSONA, status=amo.STATUS_NULL)
addon_factory(type=amo.ADDON_PERSONA, status=amo.STATUS_LITE)
addon_factory(type=amo.ADDON_PERSONA, disabled_by_user=True)
other = addon_factory(type=amo.ADDON_PERSONA)
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)
# TODO(cvan): Uncomment this once Personas detail page is impalacized.
#doc = self.get_more_pq()('#author-addons')
#test_hovercards(self, doc, [other], src='dp-dl-othersby')
r = self.client.get(self.url)
eq_(list(r.context['author_personas']), [other])
a = pq(r.content)('#more-artist a[data-browsertheme]')
eq_(a.length, 1)
eq_(a.attr('href'), other.get_url_path())
class TestStatus(amo.tests.TestCase):
fixtures = ['base/apps', 'base/addon_3615', 'addons/persona']

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

@ -179,7 +179,7 @@ class TestSubmitPersona(amo.tests.TestCase):
data.update(footer_hash=json.loads(r_ajax.content)['upload_hash'])
r = self.client.post(self.url, data)
addon = Addon.objects.exclude(id=5579)[0]
addon = Addon.objects.order_by('-id')[0]
persona = addon.persona
done_url = reverse('devhub.personas.submit.done', args=[addon.slug])
@ -212,13 +212,13 @@ class TestSubmitPersona(amo.tests.TestCase):
dst = os.path.join(settings.PERSONAS_PATH, str(addon.id))
img = os.path.join(dst, 'header.jpg')
eq_(persona.header, 'header.jpg')
eq_(persona.header, 'header')
eq_(os.path.exists(img), True)
eq_(Image.open(img).size, (3000, 200))
eq_(amo.PERSONA_IMAGE_SIZES['header'][1], (3000, 200))
img = os.path.join(dst, 'footer.jpg')
eq_(persona.footer, 'footer.jpg')
eq_(persona.footer, 'footer')
eq_(os.path.exists(img), True)
eq_(Image.open(img).size, (3000, 100))
eq_(amo.PERSONA_IMAGE_SIZES['footer'][1], (3000, 100))

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

@ -866,7 +866,7 @@ USERPICS_URL = STATIC_URL + '/img/uploads/userpics/%s/%s/%s.png?modified=%d'
COLLECTION_ICON_URL = ('%s/images/collection_icon/%%s.png?modified=%%s' %
STATIC_URL)
NEW_PERSONAS_IMAGE_URL = (STATIC_URL +
'/img/uploads/personas/%(id)d/%(file)s.jpg')
'/img/uploads/personas/%(id)d/%(file)s')
PERSONAS_IMAGE_URL = ('http://www.getpersonas.com/static/'
'%(tens)d/%(units)d/%(id)d/%(file)s')
PERSONAS_IMAGE_URL_SSL = ('https://www.getpersonas.com/static/'