Exemplo n.º 1
0
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,
        'h1': _(u'Versions for "%s"') % filename,
        'menu_current': 'content_media',
        'settings_var': get_settings_var(),
        'breadcrumbs': get_breadcrumbs(query, path),
        'breadcrumbs_title': _(u'Versions for "%s"') % filename
    }, context_instance=Context(request))
Exemplo n.º 2
0
 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:
         return ""