--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/de-cgi-bin/taggr.py Wed Jan 16 14:58:03 2008 +0000
@@ -0,0 +1,105 @@
+#!/usr/bin/env python2.4
+#
+# DeGAL - A pretty simple web image gallery
+# Copyright (C) 2007 Tero Marttila
+# http://marttila.de/~terom/degal/
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the
+# Free Software Foundation, Inc.,
+# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+
+
+import cgi
+import shelve
+import os, os.path
+
+import degal
+
+images = shelve.open('images', 'c')
+tag_images = shelve.open('tag_images', 'c')
+tag_tags = shelve.open('tag_tags', 'c')
+
+# request params
+vars = cgi.FieldStorage()
+
+if 'path' in vars :
+ path = vars['path'].value
+else :
+ path = '.'
+
+image_list = []
+
+if 'bulk_tag' in vars :
+ bulk_tags = vars['bulk_tag'].value.split()
+else :
+ bulk_tags = None
+
+for fname in os.listdir(path) :
+ if degal.isImage(fname) :
+ image_path = os.path.join(path, fname)
+ thumb_path = os.path.join(path, degal.THUMB_DIR, fname)
+ html_path = image_path + '.html'
+
+ title, descr, tags = images.get(image_path, (None, None, []))
+
+ if 'img_%s_title' % fname in vars :
+ title = vars['img_%s_title' % fname].value
+
+ if 'img_%s_descr' % fname in vars :
+ descr = vars['img_%s_descr' % fname].value
+
+ if 'img_%s_tags' % fname in vars :
+ tags = vars['img_%s_tags' % fname].value.split()
+
+ if bulk_tags and 'img_%s_chk' % fname in vars :
+ tags.extend(bulk_tags)
+
+ if title or descr or tags :
+ images[image_path] = (title, descr, tags)
+
+ html = """
+<li>
+ <span class="inputs">
+ <label for="img_%(fname)s_title">Title</label> <input type="text" name="img_%(fname)s_title" size="60" value="%(title)s" /> <br/>
+ <label for="img_%(fname)s_descr">Description</label> <input type="text" name="img_%(fname)s_descr" size="60" value="%(descr)s" /> <br/>
+ <label for="img_%(fname)s_tags">Tags</label> <input type="text" name="img_%(fname)s_tags" size="60" value="%(tags)s" /> <br/>
+ </span>
+
+ <input type="checkbox" name="img_%(fname)s_chk" class="chk" />
+
+ <span class="thumb"><a href="%(html_path)s"><img src="%(thumb_path)s" /></a></span>
+</li>
+ """ % dict(
+ html_path = html_path,
+ thumb_path = thumb_path,
+ fname = fname,
+ title = title and title or '',
+ descr = descr and descr or '',
+ tags = tags and ' '.join(tags) or '',
+ )
+
+ image_list.append((fname, html))
+
+image_list.sort()
+
+print "Content-Type: text/html"
+print
+print degal.Template('taggr').render(
+ TITLE = "Taggr - %s" % path,
+ BREADCRUMB = "TODO",
+ CONTENT = "<ul>" + ''.join([h for fname, h in image_list]) + "</ul>",
+ PATH = path,
+)
+