def versions(request): """ Show all Versions for an Image according to ADMIN_VERSIONS. """ # QUERY / PATH CHECK query = request.GET path = get_path(query.get('dir', '')) if 'pop' in query: is_popup = True else: is_popup = False filename = get_file(query.get('dir', ''), query.get('filename', '')) if path is None or filename is None: if path is None: msg = _('The requested Folder does not exist.') else: msg = _('The requested File does not exist.') messages.warning(request,message=msg) return HttpResponseRedirect(reverse("fb_browse")) abs_path = _check_access(request, path) return render_to_response(_template() + 'versions.html', { 'original': path_to_url(os.path.join(fb_settings.DIRECTORY, path, filename)), 'query': query, 'title': _(u'Versions for "%s"') % filename, 'settings_var': get_settings_var(), 'breadcrumbs': get_breadcrumbs(query, path), 'breadcrumbs_title': _(u'Versions for "%s"') % filename, 'is_popup': is_popup }, context_instance=Context(request))
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: if isinstance(source, FileObject): source = source.path source = force_unicode(source) version_path = get_version_path(source, version_prefix) if not os.path.isfile(version_path): version_path = version_generator(source, version_prefix) elif os.path.getmtime(source) > os.path.getmtime(version_path): version_path = version_generator(source, version_prefix, force=True) return path_to_url(version_path) except: return ""
def versions(request): """ Show all Versions for an Image according to ADMIN_VERSIONS. """ # QUERY / PATH CHECK query = request.GET path = get_path(query.get('dir', '')) filename = get_file(query.get('dir', ''), query.get('filename', '')) if path is None or filename is None: if path is None: msg = _('The requested Folder does not exist.') else: msg = _('The requested File does not exist.') request.user.message_set.create(message=msg) return HttpResponseRedirect(reverse("fb_browse")) abs_path = os.path.join(MEDIA_ROOT, DIRECTORY, path) return render_to_response('filebrowser/versions.html', { 'original': path_to_url(os.path.join(DIRECTORY, path, filename)), 'query': query, 'title': _(u'Versions for "%s"') % filename, 'settings_var': get_settings_var(), 'breadcrumbs': get_breadcrumbs(query, path), 'breadcrumbs_title': _(u'Versions for "%s"') % filename }, context_instance=Context(request))
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: source = force_unicode(source) version_path = get_version_path(url_to_path(source), version_prefix) if not os.path.isfile( smart_str(os.path.join(MEDIA_ROOT, version_path))): # create version version_path = version_generator(url_to_path(source), version_prefix) elif os.path.getmtime( smart_str(os.path.join( MEDIA_ROOT, url_to_path(source)))) > os.path.getmtime( smart_str(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) return path_to_url(version_path) except: return ""
def versions(request): """ Show all Versions for an Image according to ADMIN_VERSIONS. """ # QUERY / PATH CHECK query = request.GET path = get_path(query.get('dir', '')) filename = get_file(query.get('dir', ''), query.get('filename', '')) if path is None or filename is None: if path is None: msg = _('The requested Folder does not exist.') else: msg = _('The requested File does not exist.') messages.add_message(request, messages.SUCCESS, msg) return HttpResponseRedirect(reverse("fb_browse")) abs_path = os.path.join(MEDIA_ROOT, DIRECTORY, path) return render_to_response( 'filebrowser/versions.html', { 'original': path_to_url(os.path.join(DIRECTORY, path, filename)), 'query': query, 'title': _(u'Versions for "%s"') % filename, 'settings_var': get_settings_var(), 'breadcrumbs': get_breadcrumbs(query, path), 'breadcrumbs_title': _(u'Versions for "%s"') % filename }, context_instance=Context(request))
def versions(request): """ Show all Versions for an Image according to ADMIN_VERSIONS. """ # QUERY / PATH CHECK query = request.GET path = get_path(query.get("dir", "")) filename = get_file(query.get("dir", ""), query.get("filename", "")) if path is None or filename is None: if path is None: msg = _("The requested Folder does not exist.") else: msg = _("The requested File does not exist.") messages.warning(request, message=msg) return HttpResponseRedirect(reverse("fb_browse")) abs_path = os.path.join(fb_settings.MEDIA_ROOT, fb_settings.DIRECTORY, path) return render_to_response( "filebrowser/versions.html", { "original": path_to_url(os.path.join(fb_settings.DIRECTORY, path, filename)), "query": query, "title": _(u'Versions for "%s"') % filename, "settings_var": get_settings_var(), "breadcrumbs": get_breadcrumbs(query, path), "breadcrumbs_title": _(u'Versions for "%s"') % filename, }, context_instance=Context(request), )
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(smart_str(os.path.join(fb_settings.MEDIA_ROOT, version_path))): # create version version_path = version_generator( url_to_path(source), version_prefix ) elif os.path.getmtime(smart_str(os.path.join(fb_settings.MEDIA_ROOT, url_to_path(source)))) > os.path.getmtime(smart_str(os.path.join(fb_settings.MEDIA_ROOT, version_path))): # recreate version if original image was updated version_path = version_generator( url_to_path(source), version_prefix, force=True ) return path_to_url(version_path) except: 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 media_root = context.get('media_root', MEDIA_ROOT) media_url = context.get('media_url', MEDIA_URL) try: if isinstance(source, FileObject): source = source.path source = force_unicode(source) version_path = get_version_path(source, version_prefix) if not os.path.isfile(version_path): version_path = version_generator(source, version_prefix, media_root=media_root) elif os.path.getmtime(source) > os.path.getmtime(version_path): version_path = version_generator(source, version_prefix, force=True, media_root=media_root) return path_to_url(version_path, media_root=media_root, media_url=media_url) except: 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 directory = context.get('directory', DIRECTORY) try: if isinstance(source, FileObject): source = source.path source = force_unicode(source) version_path = get_version_path(source, version_prefix, directory=directory) if not os.path.isfile(version_path): version_path = version_generator(source, version_prefix, directory=directory) elif os.path.getmtime(source) > os.path.getmtime(version_path): version_path = version_generator(source, version_prefix, force=True, directory=directory) return path_to_url(version_path) except: return ""
def versions(request): """ Show all Versions for an Image according to ADMIN_VERSIONS. """ # QUERY / PATH CHECK query = request.GET path = get_path(query.get('dir', '')) if 'pop' in query: is_popup = True else: is_popup = False filename = get_file(query.get('dir', ''), query.get('filename', '')) if path is None or filename is None: if path is None: msg = _('The requested Folder does not exist.') else: msg = _('The requested File does not exist.') messages.warning(request, message=msg) return HttpResponseRedirect(reverse("fb_browse")) abs_path = _check_access(request, path) return render(request, _template() + 'versions.html', { 'original': path_to_url( os.path.join(fb_settings.DIRECTORY, path, filename)), 'query': query, 'title': _(u'Versions for "{0}"').format(filename), 'settings_var': get_settings_var(), 'breadcrumbs': get_breadcrumbs(query, path), 'breadcrumbs_title': _(u'Versions for "{0}"').format(filename), 'is_popup': is_popup })
def get_image_version(source, version_prefix): source = force_unicode(source) version_path = get_version_path(url_to_path(source), version_prefix) if not os.path.isfile(smart_str(os.path.join(MEDIA_ROOT, version_path))): # create version version_path = version_generator(url_to_path(source), version_prefix) elif os.path.getmtime(smart_str(os.path.join(MEDIA_ROOT, url_to_path(source)))) > os.path.getmtime(smart_str(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) return path_to_url(version_path)
def url_of_image_version(self, image_path, version): """ :type image_path: basestring :type version: basestring :return: unicode """ if not image_path or not isinstance(image_path, basestring): raise ValueError('image_path is null or not string') location = fbfunctions.get_version_path(fbfunctions.url_to_path(image_path), '') gallery_path = fbfunctions.version_generator(location, version) if not gallery_path: raise ValueError("invalid image %s" % (image_path,)) return self.full_url(fbfunctions.path_to_url(gallery_path))
def versions(request): """ Show all Versions for an Image according to ADMIN_VERSIONS. """ # QUERY / PATH CHECK query = request.GET path = get_path(query.get("dir", "")) filename = get_file(query.get("dir", ""), query.get("filename", "")) if path is None or filename is None: if path is None: msg = _("The requested Folder does not exist.") else: msg = _("The requested File does not exist.") request.user.message_set.create(message=msg) return HttpResponseRedirect(reverse("fb_browse")) # abs_path = u'%s' % os.path.join(MEDIA_ROOT, DIRECTORY, path) path = os.path.join(DIRECTORY, path, filename) settings_var = get_settings_var() if request.POST: formset = ImageCropDataFormSet(request.POST, queryset=ImageCropData.objects.filter(path=path)) if formset.is_valid(): formset.save() for version in settings_var.get("ADMIN_VERSIONS", {}): # TODO: or at least, only do if needed version_generator(path, version) else: raise Exception("Somehow formset became invalid: %s" % formset.errors) return HttpResponseRedirect("") # We have to create all the versions first, so the crop data form has something to fill with #TODO: this could work better somehow for version in VERSIONS: version_for_image(path, version) formset = ImageCropDataFormSet(queryset=ImageCropData.objects.filter(path=path)) return render_to_response( "filebrowser/versions.html", { "original": path_to_url(path), "query": query, "title": _(u'Versions for "%s"') % filename, "settings_var": settings_var, "breadcrumbs": get_breadcrumbs(query, path), "breadcrumbs_title": _(u'Versions for "%s"') % filename, "formset": formset, }, context_instance=Context(request), )
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: source = force_unicode(source) version_path = get_version_path(source, version_prefix) if not os.path.isfile(version_path): version_path = version_generator(source, version_prefix) elif os.path.getmtime(source) > os.path.getmtime(version_path): version_path = version_generator(source, version_prefix, force=True) return path_to_url(version_path) except: return ""