def get_mirror(self, addon, attachment=False): if attachment: host = posixpath.join(user_media_url('addons'), '_attachments') elif addon.is_disabled or self.status == amo.STATUS_DISABLED: host = settings.PRIVATE_MIRROR_URL else: host = user_media_url('addons') return posixpath.join(*map(smart_str, [host, addon.id, self.filename]))
def get_mirror(status, id, row): if row['disabled_by_user'] or status == STATUS_DISABLED: host = settings.PRIVATE_MIRROR_URL else: host = user_media_url('addons') return posixpath.join(host, str(id), row['filename'])
def picture_url(self): from amo.helpers import user_media_url if not self.picture_type: return settings.STATIC_URL + '/img/zamboni/anon_user.png' else: split_id = re.match(r'((\d*?)(\d{0,3}?))\d{1,3}$', str(self.id)) modified = int(time.mktime(self.modified.timetuple())) path = "/".join([ split_id.group(2) or '0', split_id.group(1) or '0', "%s.png?modified=%s" % (self.id, modified) ]) return user_media_url('userpics') + path
def icon_url(self): modified = int(time.mktime(self.modified.timetuple())) if self.icontype: # [1] is the whole ID, [2] is the directory split_id = re.match(r'((\d*?)\d{1,3})$', str(self.id)) path = "/".join([ split_id.group(2) or '0', "%s.png?m=%s" % (self.id, modified) ]) return user_media_url('collection_icons') + path elif self.type == amo.COLLECTION_FAVORITES: return settings.STATIC_URL + 'img/icons/heart.png' else: return settings.STATIC_URL + 'img/icons/collection.png'
def test_url_remote_beta(self): file = File.objects.get(pk=67442) file.status = amo.STATUS_BETA file.save() beta_version = '2.0.58 beta' file.version.update(version=beta_version) data = self.good_data.copy() data["version"] = beta_version up = self.get(data) self.addon_one.status = amo.STATUS_PUBLIC self.addon_one.save() up.get_rdf() eq_(up.data['row']['file_id'], file.pk) assert user_media_url('addons') in up.data['row']['url']
def test_url_local_recent(self): a_bit_ago = datetime.now() - timedelta(seconds=60) File.objects.get(pk=67442).update(datestatuschanged=a_bit_ago) up = self.get(self.good_data) up.get_rdf() assert user_media_url('addons') in up.data['row']['url']
def test_image_url(self): up = self.get_update('en-US', 15663) up.get_update() image_url = up.image_url('foo.png') assert user_media_url('addons') in image_url
def test_without_settings(self): del settings.USERPICS_URL settings.MEDIA_URL = '/mediapath/' url = helpers.user_media_url('userpics') eq_(url, '/mediapath/userpics/')
def test_image_url(self): up = self.get_update("en-US", 15663) up.get_update() image_url = up.image_url("foo.png") assert user_media_url("addons") in image_url
def assert_served_locally(self, response, file_=None, attachment=False): host = settings.SITE_URL + user_media_url('addons') if attachment: host += '_attachments/' self.assert_served_by_host(response, host, file_)
def assert_served_by_mirror(self, response, file_=None): url = settings.SITE_URL + user_media_url('addons') self.assert_served_by_host(response, url, file_)
def test_url(self): up = self.get(self.good_data) up.get_rdf() assert user_media_url('addons') in up.data['row']['url']