def render(self, context): try: source = self.src.resolve(context) except VariableDoesNotExist: return None if self.version_prefix: version_prefix = self.version_prefix else: try: version_prefix = self.version_prefix_var.resolve(context) except VariableDoesNotExist: return None try: version_path = _get_version_path(_url_to_path(str(source)), version_prefix) if not os.path.isfile(os.path.join(MEDIA_ROOT, version_path)): # create version version_path = _version_generator(_url_to_path(str(source)), version_prefix) elif os.path.getmtime(os.path.join(MEDIA_ROOT, _url_to_path(str(source)))) > os.path.getmtime(os.path.join(MEDIA_ROOT, version_path)): # recreate version if original image was updated version_path = _version_generator(_url_to_path(str(source)), version_prefix, force=True) return _path_to_url(version_path) except Exception: logger.exception("Version error") return u""
def render(self, context): try: source = self.src.resolve(context) except VariableDoesNotExist: return None if self.version_prefix: version_prefix = self.version_prefix else: try: version_prefix = self.version_prefix_var.resolve(context) except VariableDoesNotExist: return None try: version_path = _get_version_path(_url_to_path(source), version_prefix) if not os.path.isfile(os.path.join(MEDIA_ROOT, version_path)): # create version version_path = _version_generator(_url_to_path(source), version_prefix) elif os.path.getmtime(os.path.join(MEDIA_ROOT, _url_to_path(source))) > os.path.getmtime(os.path.join(MEDIA_ROOT, version_path)): # recreate version if original image was updated version_path = _version_generator(_url_to_path(source), version_prefix, force=True) context[self.var_name] = FileObject(version_path) except: context[self.var_name] = "" return ''
def render(self, context): try: source = self.src.resolve(context) except VariableDoesNotExist: return None if self.version_prefix: version_prefix = self.version_prefix else: try: version_prefix = self.version_prefix_var.resolve(context) except VariableDoesNotExist: return None try: version_path = _get_version_path(str(source), version_prefix) if not _exists(version_path): # create version version_path = _version_generator(str(source), version_prefix) elif _last_mod(os.path.join(MEDIA_ROOT, _url_to_path(str(source)))) > _last_mod(os.path.join(MEDIA_ROOT, version_path)): # recreate version if original image was updated version_path = _version_generator(_url_to_path(str(source)), version_prefix, force=True) fo = FileObject(version_path) return fo.url_full except: return ""