Templating activated (but dysfunctional)

Sun, 23 Nov 2008 20:25:31 +0000

author
andy
date
Sun, 23 Nov 2008 20:25:31 +0000
changeset 8
209609a6c525
parent 7
3c6914b3cfae
child 9
38012d2998c1

Templating activated (but dysfunctional)

emin file | annotate | diff | comparison | revisions
emin-default.html.templ file | annotate | diff | comparison | revisions
     1.1 --- a/emin	Mon Nov 17 04:33:42 2008 +0000
     1.2 +++ b/emin	Sun Nov 23 20:25:31 2008 +0000
     1.3 @@ -92,7 +92,7 @@
     1.4  ## Try to import Cheetah templating
     1.5  ## TODO Should be closer to where it's used? Does default need Cheetah?
     1.6  try:
     1.7 -    from Cheetah import Template
     1.8 +    from Cheetah.Template import Template
     1.9  except Exception, e:
    1.10      logging.error("Couldn't import required Python Cheetah package")
    1.11      sys.exit(1)
    1.12 @@ -176,7 +176,6 @@
    1.13      logging.error("Problem when making thumbnails dir... exiting")
    1.14      #traceback.print_exc()
    1.15      sys.exit(1)
    1.16 -
    1.17  try:
    1.18      for pic in pics:
    1.19          ## TODO: Un-hard-code PNG thumb format
    1.20 @@ -211,7 +210,7 @@
    1.21  ## Calculate how many pages will be needed
    1.22  ## TODO: allow all on one page
    1.23  NUM_PER_PAGE = opts.NUM_ROWS * opts.NUM_COLS
    1.24 -NUM_PAGES = math.ceil( len(pics)/float(NUM_PER_PAGE) )
    1.25 +NUM_PAGES = int(math.ceil( len(pics)/float(NUM_PER_PAGE) ))
    1.26  
    1.27  
    1.28  ## TODO: Move HTML extension-setting to option parser 
    1.29 @@ -224,6 +223,7 @@
    1.30          pagefile = "index.%s" % opts.EXTN
    1.31      else:
    1.32          pagefile = "index%02d.%s" % (pagenum, opts.EXTN)
    1.33 +    return pagefile
    1.34  
    1.35  
    1.36  def mkPageLinkStr(pagenum):
    1.37 @@ -261,31 +261,37 @@
    1.38          ZIPFILE = opts.ZIPFILE
    1.39      elif opts.TITLE is not None or len(opts.TITLE) > 0:
    1.40          ZIPFILE = safeencode(opts.TITLE)
    1.41 -        ZIPFILE = safename(opts.OUTDIR)
    1.42 +        #ZIPFILE = safename(opts.OUTDIR)
    1.43      if ZIPFILE.split(".")[-1] != "zip":
    1.44          ZIPFILE += ".zip"
    1.45 -    import zipfiles
    1.46 +    ## TODO: Do the zipping
    1.47 +    #import zipfiles
    1.48      #rm -f *.zip
    1.49 -    ## TODO: Do the zipping
    1.50      ##zip $ZIPFILE $pics &> /dev/null
    1.51  
    1.52  
    1.53 +## Use template file
    1.54 +TMPLFILE = "emin-default.html.templ"
    1.55 +logging.info("Using index template file %s" % TMPLFILE)
    1.56 +tf = open(TMPLFILE, "r")
    1.57 +tmplstr = tf.read()
    1.58 +tf.close()
    1.59 +
    1.60 +
    1.61  ## Make each index page
    1.62  for n in range(NUM_PAGES):
    1.63      PAGENUM = n + 1
    1.64  
    1.65      ## Choose and open page file
    1.66      PAGEFILE = getPageFilename(PAGENUM)
    1.67 -    logging.info("Writing to index file %s" % PAGEFILE)
    1.68 -    f = open(PAGEFILE, "w")
    1.69 -    
    1.70 +
    1.71      ## Write the title
    1.72      PAGETITLE = opts.TITLE
    1.73      if PAGENUM > 0:
    1.74 -        PAGETITLE += " (page %s)" % pagenum
    1.75 +        PAGETITLE += " (page %s)" % PAGENUM
    1.76      
    1.77      ## Write the linked page list
    1.78 -    LINKSTR = mkPageLinkStr(pagenum)
    1.79 +    LINKSTR = mkPageLinkStr(PAGENUM)
    1.80      
    1.81      ## Make thumbnails if needed and write the image HTML
    1.82      ## Display in table
    1.83 @@ -294,16 +300,28 @@
    1.84      if pics_end >= len(pics):
    1.85          pics_end = len(pics) - 1
    1.86  
    1.87 -    PAGEPICS = pics[pics_start, pics_end]
    1.88 +    PAGEPICS = pics[pics_start: pics_end]
    1.89      PAGEPICNUMS = range(len(pics))
    1.90 -    PAGETHUMBS = [os.path/join(THUMBDIR, t) for t in thumbs[pics_start, pics_end]]
    1.91 -    ## TODO: Build a list of thumb dims during the minimisation process, using ImageInfo
    1.92 -    PAGETHUMBDIMS = [(t), getHeight(t)) ) for t in PAGETHUMBS]
    1.93 +    PAGETHUMBS = [t.path for t in thumbsinfo.keys()[pics_start : pics_end]]
    1.94 +    PAGETHUMBDIMS = [t.size for t in thumbsinfo.keys()[pics_start : pics_end]]
    1.95  
    1.96 -    ## Use template file
    1.97 -    ## TODO
    1.98 -
    1.99 -    ## Close page file
   1.100 +    logging.info("Writing to index file %s" % PAGEFILE)
   1.101 +    f = open(PAGEFILE, "w")
   1.102 +    tdict = {}
   1.103 +    tdict["NUM_PAGES"] = NUM_PAGES
   1.104 +    tdict["PAGEPICS"] = PAGEPICS
   1.105 +    tdict["PAGENUM"] = PAGENUM
   1.106 +    tdict["PAGENUM"] = PAGENUM
   1.107 +    tdict["PAGETITLE"] = PAGETITLE
   1.108 +    tdict["LINKSTR"] = LINKSTR
   1.109 +    tdict["PAGEPICS"] = PAGEPICS
   1.110 +    tdict["PAGEPICNUMS"] = PAGEPICNUMS
   1.111 +    tdict["PAGETHUMBS"] = PAGETHUMBS
   1.112 +    tdict["PAGETHUMBDIMS"] = PAGETHUMBDIMS
   1.113 +    tdict["ZIPFILE"] = ZIPFILE
   1.114 +    tdict["OPTS"] = opts
   1.115 +    indexstr = Template(tmplstr, searchList=[tdict])
   1.116 +    f.write(str(indexstr))
   1.117      f.close()
   1.118  
   1.119  ## It's over. Nothing to see here.
     2.1 --- a/emin-default.html.templ	Mon Nov 17 04:33:42 2008 +0000
     2.2 +++ b/emin-default.html.templ	Sun Nov 23 20:25:31 2008 +0000
     2.3 @@ -6,18 +6,18 @@
     2.4        body { padding:1em; background:white; font-family:sans-serif; }
     2.5        h1 { font-family:sans-serif; }
     2.6      </style>
     2.7 -#if $opts.USE_JS:
     2.8 +#if $OPTS.USE_JS:
     2.9      <script type="text/javascript" src="/lightbox/js/prototype.js"></script>
    2.10      <script type="text/javascript" src="/lightbox/js/scriptaculous.js?load=effects"></script>
    2.11      <script type="text/javascript" src="/lightbox/js/lightbox.js"></script>
    2.12      <link rel="stylesheet" href="/lightbox/css/lightbox.css" type="text/css" media="screen" />
    2.13 -#endif
    2.14 +#end if
    2.15    </head>
    2.16    <body>
    2.17      <h1>$PAGETITLE</h1>
    2.18  #if $NUM_PAGES > 0
    2.19      <div class="pagelinks">Pages: $LINKSTR</div>
    2.20 -#endif
    2.21 +#end if
    2.22  
    2.23      <p>
    2.24  #for npic in $PAGETHUMBS
    2.25 @@ -25,15 +25,15 @@
    2.26        <a href="$PAGEPICS[$npic]"><img alt="$PAGETHUMBS[$npic]" src="$PAGETHUMBS[$npic]" 
    2.27                                        style="border:0;" width="$PAGETHUMBDIMS[$npic][0]" 
    2.28                                        height="$PAGETHUMBDIMS[$npic][1]" /></a>
    2.29 -#endfor
    2.30 +#end for
    2.31      </p>
    2.32  
    2.33  #if $NUM_PAGES > 0
    2.34      <div class="pagelinks">Pages: $LINKSTR</div>
    2.35 -#endif
    2.36 +#end if
    2.37  
    2.38 -#if $opts.WRITE_ZIPFILE:
    2.39 +#if $OPTS.WRITE_ZIPFILE:
    2.40      <p>All photos zipped up: <a href="$ZIPFILE">$ZIPFILE</a></p>
    2.41 -#endif
    2.42 +#end if
    2.43    </body>
    2.44  </html>

mercurial