Beispiel #1
0
def agilethumbs_image(request, **kwargs):
    filename = get_cache_filename(**kwargs)
    # If the file already exists serve it up
    if os.path.exists(filename):
        return serve_file(request, filename)
    # Allow override of id_to_object function in settings
    this_id_to_object = get_callable(getattr(
        settings, 'AGILETHUMBS_ID_TO_OBJECT', id_to_object))
    processor, processor_kwargs, extension = get_image_processor(**kwargs)
    # Create file
    with atomic_create(filename) as outfile:
        fileobj = this_id_to_object(unescape(kwargs['file_id']))
        try:
            processor(fileobj, outfile, extension, **processor_kwargs)
        finally:
            if hasattr(fileobj, 'close') and callable(fileobj.close):
                fileobj.close()
    # Serve it up
    return serve_file(request, filename)
Beispiel #2
0
 def testRoundTripEquivalent(self):
     for s in STRINGS:
         self.assertEqual(s, unescape(escape(s)))