Ejemplo n.º 1
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:
         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)
         context[self.var_name] = FileObject(version_path)
     except:
         context[self.var_name] = ""
     return ''
Ejemplo 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:
         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)
         context[self.var_name] = FileObject(version_path)
     except:
         context[self.var_name] = ""
     return ''
Ejemplo n.º 3
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(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 ""
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
 def render(self, name, value, attrs=None):
     if self.site:
         name = self.site.name + ":fb_browse"
         url = urlresolvers.reverse(name)
     else:
         url = urlresolvers.reverse('filebrowser:fb_browse')
     if value is None:
         value = ""
     if value != "" and not isinstance(value, FileObject):
         value = FileObject(url_to_path(value))
     final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
     final_attrs[
         'search_icon'] = URL_FILEBROWSER_MEDIA + 'img/filebrowser_icon_show.gif'
     final_attrs['url'] = url
     final_attrs['directory'] = self.directory
     final_attrs['extensions'] = self.extensions
     final_attrs['format'] = self.format
     final_attrs['ADMIN_THUMBNAIL'] = ADMIN_THUMBNAIL
     if value != "":
         try:
             if value.is_version and VERSIONS_BASEDIR:
                 final_attrs['directory'] = os.path.split(
                     value.original.path_relative)[0]
             else:
                 final_attrs['directory'] = os.path.split(
                     value.path_relative)[0]
         except:
             pass
     return render_to_string("filebrowser/custom_field.html", locals())
Ejemplo n.º 6
0
    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 get_all_filebrowse_values(self):
        versions = getattr(settings, 'FILEBROWSER_VERSIONS', fb_settings.VERSIONS)
        files    = []
        
        for model, fields in self.get_all_models().items():
            for record in model.objects.values(*fields):
                for field, value in record.items():
                    if value:
                        file_obj = FileObject(value.replace(settings.MEDIA_URL, ''))
                        files.append(file_obj.path_full)

                        for version in versions:
                            version_path = get_version_path(url_to_path(file_obj.url_save), version)
                            version_file = os.path.join(settings.MEDIA_ROOT, version_path)
                            if os.path.isfile(version_file):                                
                                files.append(version_file)
                                  
        return files
Ejemplo n.º 8
0
 def to_python(self, value):
     if not value or isinstance(value, FileObject):
         return value
     return FileObject(url_to_path(value))
Ejemplo n.º 9
0
 def from_db_value(self, value, expression, connection, context):
     if not value or isinstance(value, FileObject):
         return value
     return FileObject(url_to_path(value))
 def to_python(self, value):
     if not value or isinstance(value, FileObject):
         return value
     return FileObject(url_to_path(value))
Ejemplo n.º 11
0
 def to_python(self, value):
     if not value or isinstance(value, FileObject):
         return value
     return FileObject(url_to_path(value), directory=self.site.directory)
Ejemplo n.º 12
0
 def from_db_value(self, value, expression, connection, context):
     if not value or isinstance(value, FileObject):
         return value
     return FileObject(url_to_path(value))