fix commands.main to render HTML for folders that only have subfolders, and no direct images
authorTero Marttila <terom@fixme.fi>
Wed, 17 Jun 2009 17:02:24 +0300
changeset 131 7021d949222c
parent 130 94888270dae0
child 132 c2b2f4b6fe6d
fix commands.main to render HTML for folders that only have subfolders, and no direct images
degal/commands/main.py
degal/folder.py
--- a/degal/commands/main.py	Wed Jun 17 16:45:01 2009 +0300
+++ b/degal/commands/main.py	Wed Jun 17 17:02:24 2009 +0300
@@ -80,7 +80,15 @@
 def render_folder (ctx, folder) :
     """
         Render the HTML/images for this folder if needed, and recrurse into subfolders.
+
+        Returns True if any sub-images were found, False if this folder and all subfolders were completely empty and no
+        HTML was generated.
+        
+        XXX: this logic is too complicated for one function. For one module?
     """
+
+    # flag to track if we've rendered any contents.
+    empty = True
     
     if ctx.config.force_html or ctx.config.force_thumb :
         # index all
@@ -96,21 +104,32 @@
     # index selected images
     new_images = list(folder.index_images(for_update=for_update))
 
-    if new_images or ctx.config.force_html :
+    # index subfolders
+    for subfolder in folder.subfolders :
+        if render_folder(ctx, subfolder) :
+            # positive assertion
+            empty = False
+    
+    if folder.images :
+        empty = False
+
+    # only render HTML if needed
+    if not empty  :
         # update folder index
         render_folder_html(ctx, folder)
-        
+    
+    # only render new images if needed   
+    if new_images or ctx.config.force_html :
         ctx.log_info("%s - render %d/%d images", folder, len(new_images), image_count)
 
         # update images
         render_folder_images(ctx, new_images, for_update)
-    
+
     else :
         ctx.log_info("%s - up to date", folder)
-
-    # index subfolders
-    for subfolder in folder.subfolders :
-        render_folder(ctx, subfolder)
+    
+    # return flag
+    return empty
 
 @command
 def main (ctx) :
--- a/degal/folder.py	Wed Jun 17 16:45:01 2009 +0300
+++ b/degal/folder.py	Wed Jun 17 17:02:24 2009 +0300
@@ -135,10 +135,19 @@
     @property
     def page_count (self) :
         """
-            Returns the number of pages needed to show this folder's images
+            Returns the number of pages needed to show this folder's images or subfolders. May be zero, one or more.
         """
+        
+        if self.images :
+            return int(math.ceil(len(self.images) / float(self.config.images_per_page)))
+        
+        elif self.subfolders :
+            # paginate these?
+            return 1
 
-        return int(math.ceil(len(self.images) / float(self.config.images_per_page)))
+        else :
+            # nothing to render, really
+            return 0
 
     def images_for_page (self, page) :
         """