Exemple #1
0
    def get_mirror(self, attachment=False):
        if attachment:
            host = posixpath.join(user_media_url('addons'), '_attachments')
        else:
            host = user_media_url('addons')

        return posixpath.join(
            *map(force_bytes, [host, self.version.addon.id, self.filename]))
Exemple #2
0
    def get_mirror(self, attachment=False):
        if attachment:
            host = posixpath.join(user_media_url('addons'), '_attachments')
        else:
            host = user_media_url('addons')

        return posixpath.join(
            *map(force_bytes, [host, self.version.addon.id, self.filename]))
Exemple #3
0
    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]))
Exemple #4
0
    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_file_cdn_url(self, attachment=False):
        """Return the URL for the file corresponding to this instance
        on the CDN."""
        if attachment:
            host = posixpath.join(user_media_url('addons'), '_attachments')
        else:
            host = user_media_url('addons')

        return posixpath.join(
            *map(force_bytes, [host, self.version.addon.id, self.filename]))
Exemple #6
0
    def get_file_cdn_url(self, attachment=False):
        """Return the URL for the file corresponding to this instance
        on the CDN."""
        if attachment:
            host = posixpath.join(user_media_url('addons'), '_attachments')
        else:
            host = user_media_url('addons')

        return posixpath.join(
            *map(force_bytes, [host, self.version.addon.id, self.filename]))
Exemple #7
0
    def picture_url(self):
        from olympia.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
Exemple #8
0
 def picture_url(self):
     from olympia.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
Exemple #9
0
 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'
Exemple #10
0
 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'
Exemple #11
0
 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_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')
     assert url == '/mediapath/userpics/'
Exemple #14
0
 def test_without_settings(self):
     del settings.USERPICS_URL
     settings.MEDIA_URL = '/mediapath/'
     url = helpers.user_media_url('userpics')
     eq_(url, '/mediapath/userpics/')
 def assert_served_by_cdn(self, response, file_=None):
     url = settings.SITE_URL + user_media_url('addons')
     self.assert_served_by_host(response, url, file_)
 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_)