Example #1
0
def thumb_url(item, size, qualified=False, exists=False):
    """Get the thumbnail url for the given item and size.

    :param item: A 2-tuple with a subdir name and an ID. If given a
        ORM mapped class with _thumb_dir and id attributes, the info
        can be extracted automatically.
    :type item: ``tuple`` or mapped class instance
    :param size: Size key to display, see ``thumb_sizes`` in
        :mod:`mediacore.config.app_config`
    :type size: str
    :param qualified: If ``True`` return the full URL including the domain.
    :type qualified: bool
    :param exists: If enabled, checks to see if the file actually exists.
        If it doesn't exist, ``None`` is returned.
    :type exists: bool
    :returns: The relative or absolute URL.
    :rtype: str

    """
    if not item:
        return None

    image_dir, item_id = _normalize_thumb_item(item)
    image = '%s/%s%s.jpg' % (image_dir, item_id, size)

    if exists and not os.path.isfile(os.path.join(config['image_dir'], image)):
        return None
    return url_for('/images/%s' % image, qualified=qualified)
Example #2
0
def thumb_url(item, size, qualified=False, exists=False):
    """Get the thumbnail url for the given item and size.

    :param item: A 2-tuple with a subdir name and an ID. If given a
        ORM mapped class with _thumb_dir and id attributes, the info
        can be extracted automatically.
    :type item: ``tuple`` or mapped class instance
    :param size: Size key to display, see ``thumb_sizes`` in
        :mod:`mediacore.config.app_config`
    :type size: str
    :param qualified: If ``True`` return the full URL including the domain.
    :type qualified: bool
    :param exists: If enabled, checks to see if the file actually exists.
        If it doesn't exist, ``None`` is returned.
    :type exists: bool
    :returns: The relative or absolute URL.
    :rtype: str

    """
    if not item:
        return None

    image_dir, item_id = _normalize_thumb_item(item)
    image = '%s/%s%s.jpg' % (image_dir, item_id, size)

    if exists and not os.path.isfile(os.path.join(config['image_dir'], image)):
        return None
    return url_for('/images/%s' % image, qualified=qualified)
Example #3
0
def thumb_url(item, size, qualified=True, exists=False):
    """Get the thumbnail url for the given item and size.

    :param item: A 2-tuple with a subdir name and an ID. If given a
        ORM mapped class with _thumb_dir and id attributes, the info
        can be extracted automatically.
    :type item: ``tuple`` or mapped class instance
    :param size: Size key to display, see ``thumb_sizes`` in
        :mod:`mediadrop.config.app_config`
    :type size: str
    :param qualified: If ``True`` return the full URL including the domain.
    :type qualified: bool
    :param exists: If enabled, checks to see if the file actually exists.
        If it doesn't exist, ``None`` is returned.
    :type exists: bool
    :returns: The relative or absolute URL.
    :rtype: str

    """
    if not item:
        return None

    image_dir, item_id = _normalize_thumb_item(item)
    image = '%s/%s%s.jpg' % (image_dir, item_id, size)
    swift_image = '%s/%s/%s%s.jpg' % (config['swift_container'], image_dir, item_id, size)
    image_path = os.path.join(config['image_dir'], image)

    swift = _connect()
    swift_base_url = swift.get_auth()[0]
    swift_base_url = swift_base_url.replace('http://', '')

    try:
        swift.head_object(config['swift_container'], image)
        return url_for('%s' % swift_image, qualified=True, host=swift_base_url)
    except Exception, e:
        swift.close()
        if exists and not os.path.isfile(image_path):
            return None
Example #4
0
    image_path = os.path.join(config['image_dir'], image)

    swift = _connect()
    swift_base_url = swift.get_auth()[0]
    swift_base_url = swift_base_url.replace('http://', '')

    try:
        swift.head_object(config['swift_container'], image)
        return url_for('%s' % swift_image, qualified=True, host=swift_base_url)
    except Exception, e:
        swift.close()
        if exists and not os.path.isfile(image_path):
            return None

    swift.close()
    return url_for('/images/%s' % image, qualified=qualified)


class ThumbDict(dict):
    """Dict wrapper with convenient attribute access"""

    def __init__(self, url, dimensions):
        dict.__init__(self)
        self['url'] = url
        self['x'], self['y'] = dimensions

    def __getattr__(self, name):
        return self[name]

def thumb(item, size, qualified=False, exists=False):
    """Get the thumbnail url & dimensions for the given item and size.
Example #5
0
def redirect_to(*args, **kwargs):
    return redirect(url_for(*args, **kwargs))
Example #6
0
def redirect_to(*args, **kwargs):
    return redirect(url_for(*args, **kwargs))