Thumbnail and preview image URLs for Persona model.

This commit is contained in:
Fred Wenzel 2010-03-26 18:58:32 +01:00
Родитель f43c09c79f
Коммит 2ef85e7182
3 изменённых файлов: 30 добавлений и 1 удалений

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

@ -367,6 +367,24 @@ class Persona(caching.base.CachingMixin, models.Model):
def __unicode__(self):
return unicode(self.addon.name)
def _image_url(self, filename):
units = self.id % 10
tens = (self.id // 10) % 10
return settings.PERSONAS_IMAGE_URL % {
'units': units, 'tens': tens, 'file': filename,
'id': self.id
}
@amo.cached_property
def thumb_url(self):
"""URL to Persona's thumbnail preview."""
return self._image_url('preview.jpg')
@amo.cached_property
def preview_url(self):
"""URL to Persona's big, 680px, preview."""
return self._image_url('preview_large.jpg')
class AddonCategory(caching.base.CachingMixin, models.Model):
addon = models.ForeignKey(Addon)

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

@ -7,7 +7,7 @@ from nose.tools import eq_, assert_not_equal
import test_utils
import amo
from addons.models import Addon, AddonPledge
from addons.models import Addon, AddonPledge, Persona
from stats.models import Contribution
@ -235,3 +235,12 @@ class TestAddonPledgeModel(test_utils.TestCase):
pledge = AddonPledge.objects.create(addon_id=4, target=230,
deadline=date.today())
eq_(pledge.raised, 0)
class TestPersonaModel(test_utils.TestCase):
def test_image_urls(self):
mypersona = Persona(id=1234)
assert mypersona.thumb_url.endswith('/3/4/1234/preview.jpg')
assert mypersona.preview_url.endswith('/3/4/1234/preview_large.jpg')
pass

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

@ -336,6 +336,8 @@ USER_PIC_URL = STATIC_URL + '/img/uploads/userpics/%s/%s/%s.jpg?modified=%d'
FILES_URL = STATIC_URL + "/downloads/file/%d/%s?src=%s"
COLLECTION_ICON_URL = ('%s/%s/%s/images/collection_icon/%%s/%%s' %
(STATIC_URL, LANGUAGE_CODE, DEFAULT_APP))
PERSONAS_IMAGE_URL = ('https://getpersonas.com/static/'
'%(tens)d/%(units)d/%(id)d/%(file)s')
# Outgoing URL bouncer
REDIRECT_URL = 'https://outgoing.mozilla.org/v1/'