Esempio n. 1
0
 def _build_thumbnail(self, args):
     # Build the DjangoThumbnail kwargs.
     kwargs = {}
     for k, v in args.items():
         kwargs[ALL_ARGS[k]] = v
     # Build the destination filename and return the thumbnail.
     name_kwargs = {}
     for key in ['size', 'options', 'quality', 'basedir', 'subdir',
                 'prefix', 'extension']:
         name_kwargs[key] = args.get(key)
     source = getattr(self.instance, self.field.name)
     rotate = getattr(self,"rotate",None)
     if rotate:
         if name_kwargs.get("options"):
             name_kwargs["options"].update({"rotate":rotate})
         else:
             name_kwargs["options"] = {"rotate":rotate}
             
         if kwargs.get("opts"):
             kwargs["opts"].update({"rotate":rotate})
         else:
             kwargs["opts"] = {"rotate":rotate}
             
     dest = build_thumbnail_name(source.name, **name_kwargs)
     #print source,dest,kwargs
     return DjangoThumbnail(source, relative_dest=dest, **kwargs)
Esempio n. 2
0
 def _get_relative_thumbnail(self, relative_source,
                             basedir=None, subdir=None, prefix=None,
                             extension=None):
     """
     Returns the thumbnail filename including relative path.
     """
     return build_thumbnail_name(relative_source, self.requested_size,
                                 self.opts, self.quality, basedir, subdir,
                                 prefix, extension)
 def _get_relative_thumbnail(self,
                             relative_source,
                             basedir=None,
                             subdir=None,
                             prefix=None,
                             extension=None):
     """
     Returns the thumbnail filename including relative path.
     """
     return build_thumbnail_name(relative_source, self.requested_size,
                                 self.opts, self.quality, basedir, subdir,
                                 prefix, extension)
Esempio n. 4
0
 def _build_thumbnail(self, args):
     # Build the DjangoThumbnail kwargs.
     kwargs = {}
     for k, v in args.items():
         kwargs[ALL_ARGS[k]] = v
     # Build the destination filename and return the thumbnail.
     name_kwargs = {}
     for key in ['size', 'options', 'quality', 'basedir', 'subdir',
                 'prefix', 'extension']:
         name_kwargs[key] = args.get(key)
     source = getattr(self.instance, self.field.name)
     dest = build_thumbnail_name(source.name, **name_kwargs)
     return DjangoThumbnail(source, relative_dest=dest, **kwargs)
Esempio n. 5
0
 def _build_thumbnail(self, args):
     try:
         # Build the DjangoThumbnail kwargs.
         kwargs = {}
         for k, v in args.items():
             kwargs[ALL_ARGS[k]] = v
         # Build the destination filename and return the thumbnail.
         name_kwargs = {}
         for key in ["size", "options", "quality", "basedir", "subdir", "prefix", "extension"]:
             name_kwargs[key] = args.get(key)
         source = self._file
         dest = build_thumbnail_name(source.name, **name_kwargs)
         return DjangoThumbnail(source, relative_dest=dest, **kwargs)
     except:
         return os.path.normpath(u"%s/icons/missingfile_%sx%s.png" % (FILER_STATICMEDIA_PREFIX, 32, 32))
Esempio n. 6
0
 def _build_thumbnail(self, args):
     # Build the DjangoThumbnail kwargs.
     kwargs = {}
     for k, v in args.items():
         kwargs[ALL_ARGS[k]] = v
     # Build the destination filename and return the thumbnail.
     name_kwargs = {}
     for key in [
             'size', 'options', 'quality', 'basedir', 'subdir', 'prefix',
             'extension'
     ]:
         name_kwargs[key] = args.get(key)
     source = getattr(self.instance, self.field.name)
     dest = build_thumbnail_name(source.name, **name_kwargs)
     return DjangoThumbnail(source, relative_dest=dest, **kwargs)
Esempio n. 7
0
 def icons(self):
     if not getattr(self, "_icon_thumbnails_cache", False):
         r = {}
         for size in FILER_ADMIN_ICON_SIZES:
             try:
                 args = {"size": (int(size), int(size)), "options": ["crop", "upscale"]}
                 # Build the DjangoThumbnail kwargs.
                 kwargs = {}
                 for k, v in args.items():
                     kwargs[ALL_ARGS[k]] = v
                 # Build the destination filename and return the thumbnail.
                 name_kwargs = {}
                 for key in ["size", "options", "quality", "basedir", "subdir", "prefix", "extension"]:
                     name_kwargs[key] = args.get(key)
                 source = self._file
                 dest = build_thumbnail_name(source.name, **name_kwargs)
                 r[size] = unicode(DjangoThumbnail(source, relative_dest=dest, **kwargs))
             except Exception, e:
                 pass  # print e
         setattr(self, "_icon_thumbnails_cache", r)
Esempio n. 8
0
 def icons(self):
     if not getattr(self, '_icon_thumbnails_cache', False):
         r = {}
         for size in FILER_ADMIN_ICON_SIZES:
             try:
                 args = {'size': (int(size),int(size)), 'options': ['crop','upscale']}
                 # Build the DjangoThumbnail kwargs.
                 kwargs = {}
                 for k, v in args.items():
                     kwargs[ALL_ARGS[k]] = v
                 # Build the destination filename and return the thumbnail.
                 name_kwargs = {}
                 for key in ['size', 'options', 'quality', 'basedir', 'subdir',
                             'prefix', 'extension']:
                     name_kwargs[key] = args.get(key)
                 source = self._file
                 dest = build_thumbnail_name(source.name, **name_kwargs)
                 r[size] = unicode(DjangoThumbnail(source, relative_dest=dest, **kwargs))
             except Exception, e:
                 pass#print e
         setattr(self, '_icon_thumbnails_cache', r)
Esempio n. 9
0
def download(request, download_id):
    if not request.META.has_key(MXIT_HEADER):
        if not request.user.is_authenticated():
            return HttpResponseRedirect("/account/login/")
        
    download = Download.objects.get(id=download_id)
    filename = os.path.join(MEDIA_ROOT, str(download.download))
    
    if download.type == 'image' and 'HTTP_UA_PIXELS' in request.META:
        size = tuple(int(v) for v in request.META.get('HTTP_UA_PIXELS', '').split("x"))
        outfile = build_thumbnail_name(filename, size)
        thumbnail = Thumbnail(filename, size, dest=outfile)
        wrapper = FileWrapper(file(thumbnail.dest,"rb"))
    else:
        wrapper = FileWrapper(file(filename,"rb"))
    
    response = HttpResponse(wrapper, mimetype='application/force-download')
    filename = str(download.download).split("/")
    filename = filename[len(filename) - 1]

    response['Content-Disposition'] = 'attachment; filename=%s' % filename
    
    return response
Esempio n. 10
0
 def build_thumbnail_name(self, name, size, options=None):
     options = options or self.field.thumb_options
     return build_thumbnail_name(name, size, options)
Esempio n. 11
0
 def build_thumbnail_name(self, name, size, options=None):
     options = options or self.field.thumb_options
     return build_thumbnail_name(name, size, options)