Exemple #1
0
    def render(self, context):
        try:
            request = context['request']
            session = request.session
        except KeyError:
            session = None

        image_field = self.image_field.resolve(context)
        try:
            parameters = self.parameters.resolve(context)
        except template.VariableDoesNotExist:
            parameters = self.parameters

        if isinstance(image_field, VideoFieldFile):
            parameters += "&video=true"

        if isinstance(image_field, ImageFieldFile) or isinstance(
                image_field, VideoFieldFile):
            try:
                parameters = parameters + "&center=" + image_field.__image_center_instance__.__unicode__(
                )
            except AttributeError:
                pass

        if "autogen=true" in parameters:
            # We want the image to be generated immediately
            image_views.image(None, str(image_field), parameters, True)

        return IMAGE_CACHE_STORAGE.url(
            os.path.join(unicode(image_field),
                         image_tokenize(session, parameters)))
Exemple #2
0
    def render(self, context):
        try:
            request = context['request']
            session = request.session
        except KeyError:
            session = None

        image_field = self.image_field.resolve(context)
        try:
            parameters = self.parameters.resolve(context)
        except template.VariableDoesNotExist:
            parameters = self.parameters

        if isinstance(image_field, VideoFieldFile):
            parameters += "&video=true"

        if isinstance(image_field, ImageFieldFile) or isinstance(image_field, VideoFieldFile):
            try:
                parameters = parameters + "&center=" + image_field.__image_center_instance__.__unicode__()
            except AttributeError:
                pass

        if "autogen=true" in parameters:
            # We want the image to be generated immediately
            image_views.image(None, str(image_field), parameters, True)

        return IMAGE_CACHE_STORAGE.url(os.path.join(unicode(image_field), image_tokenize(session, parameters)))
Exemple #3
0
    def render(self, context):
        try:
            request = context['request']
            session = request.session
        except KeyError:
            request = HttpRequest()
            session = None

        image_field = self.image_field.resolve(context)
        try:
            parameters = self.parameters.resolve(context)
        except template.VariableDoesNotExist:
            parameters = self.parameters

        if isinstance(image_field, VideoFieldFile):
            parameters += "&video=true"

        if isinstance(image_field, ImageFieldFile) or isinstance(
                image_field, VideoFieldFile):
            try:
                parameters = parameters + "&center=" + image_field.__image_center_instance__.__str__(
                )
            except AttributeError:
                pass

        if "autogen=true" in parameters or getattr(IMAGE_CACHE_STORAGE,
                                                   "autogen_required", False):
            # We want the image to be generated immediately
            image_views.image(request, six.text_type(image_field), parameters,
                              True)

        # image_path = os.path.join(image_tokenize(session, parameters), six.text_type(image_field))
        # return IMAGE_CACHE_STORAGE.url(image_path)
        return image_url(session, parameters, image_field)
Exemple #4
0
    def render(self, context):
        try:
            request = context['request']
            session = request.session
        except KeyError:
            request = HttpRequest()
            session = None

        image_field = self.image_field.resolve(context)
        try:
            parameters = self.parameters.resolve(context)
        except template.VariableDoesNotExist:
            parameters = self.parameters

        if isinstance(image_field, VideoFieldFile):
            parameters += "&video=true"

        if isinstance(image_field, ImageFieldFile) or isinstance(image_field, VideoFieldFile):
            try:
                parameters = parameters + "&center=" + image_field.__image_center_instance__.__str__()
            except AttributeError:
                pass

        if "autogen=true" in parameters or getattr(IMAGE_CACHE_STORAGE, "autogen_required", False):
            # We want the image to be generated immediately
            image_views.image(request, six.text_type(image_field), parameters, True)

        # image_path = os.path.join(image_tokenize(session, parameters), six.text_type(image_field))
        # return IMAGE_CACHE_STORAGE.url(image_path)
        return image_url(session, parameters, image_field)
Exemple #5
0
def image_url(session, parameters, image_field, generate=False):
    if generate:
        from image import views as image_views

        autogen = 'autogen=true' in parameters
        image_views.image(session, str(image_field), parameters, autogen)

    image_path = os.path.join(image_tokenize(session, parameters), six.text_type(image_field))
    return IMAGE_CACHE_STORAGE.url(image_path)
Exemple #6
0
def image_url(session, parameters, image_field, generate=False):
    if generate:
        from image import views as image_views

        autogen = 'autogen=true' in parameters
        image_views.image(session, str(image_field), parameters, autogen)

    image_path = os.path.join(image_tokenize(session, parameters),
                              six.text_type(image_field))
    return IMAGE_CACHE_STORAGE.url(image_path)