Commits

George Notaras committed bb46925

``generate_image_name()`` requires an initial name.

  • Participants
  • Parent commits 2aadf1f

Comments (0)

Files changed (1)

File src/thumbnail_works/images.py

 from thumbnail_works import settings
 
 from thumbnail_works.exceptions import ThumbnailOptionError
+from thumbnail_works.exceptions import ThumbnailWorksError
 from thumbnail_works.utils import get_width_height_from_string
 
 
             return '.jpg'
         return '.%s' % ext
     
-    def generate_image_name(self, name=None, force_ext=None):
+    def generate_image_name(self, name, force_ext=None):
         """Generates a path for the image file taking the format into account.
         
         This method should be used by both the source image and thumbnails
         to get their ``name`` attribute.
         
-        name: images/photo.jpg
-        source: images/photo.<extension>
-        thumbnail: images/<THUMBNAILS_DIRNAME>/photo.<identifier>.<extension>
+        Arguments
+        ---------
+        
+        ``name``
+            A relative path to MEDIA_ROOT. ``name`` cannot be empty or None.
+            In such a case a ``ThumbnailWorksError`` is raised.
+        ``force_ext``
+            Can be used to force a specific extension. By default, the extension
+            is derived from the user-specified image format and is generated by
+            the ``get_image_extension()`` method.
+        
+        Path transformation logic
+        -------------------------
+        
+        Path transformation logic for source image and thumbnails.
+        
+        - Assuming ``name = 'images/photo.jpg'``:
+        
+          - source: images/photo.<extension>
+          - thumbnail: images/<THUMBNAILS_DIRNAME>/photo.<identifier>.<extension>
         
         """
-        if name is None:
-            if self.name is None:
-                raise Exception('A name is needed')
-            name = self.name
+        if not name:
+            raise ThumbnailWorksError('The provided name is not usable: "%s"')
         root_dir = os.path.dirname(name)  # images
         filename = os.path.basename(name)    # photo.jpg
         base_filename, default_ext = os.path.splitext(filename)