terom@20: #!/usr/bin/env python2.4 terom@20: # terom@20: # DeGAL - A pretty simple web image gallery terom@20: # Copyright (C) 2007 Tero Marttila terom@20: # http://marttila.de/~terom/degal/ terom@20: # terom@20: # This program is free software; you can redistribute it and/or modify terom@20: # it under the terms of the GNU General Public License as published by terom@20: # the Free Software Foundation; either version 2 of the License, or terom@20: # (at your option) any later version. terom@20: # terom@20: # This program is distributed in the hope that it will be useful, terom@20: # but WITHOUT ANY WARRANTY; without even the implied warranty of terom@20: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terom@20: # GNU General Public License for more details. terom@20: # terom@20: # You should have received a copy of the GNU General Public License terom@20: # along with this program; if not, write to the terom@20: # Free Software Foundation, Inc., terom@20: # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. terom@20: # terom@20: terom@20: import cgi terom@20: terom@20: import inc terom@20: from lib import tags, template, req, shorturl, utils, settings terom@20: terom@20: tag_list = [tag for tag in req.get_str("tags", "").split("/") if tag] terom@20: terom@20: tag_db = tags.TagDB() terom@20: shorturl_db = shorturl.DB() terom@20: terom@20: root = len(tag_list) + 1 terom@20: terom@20: class Tag (object) : terom@20: def __init__ (self, name, count) : terom@20: self.title = "%s (%d)" % (name, count) terom@20: self.name = utils.url(name, trailing=True) terom@20: terom@20: class TagView (object) : terom@20: def __init__ (self, tag_list) : terom@20: img_codes = tag_db.imgs(tag_list) terom@20: more_tags = tag_db.tags(tag_list) terom@20: terom@20: self.images = [] terom@20: terom@20: for index, key in enumerate(img_codes) : terom@20: dir, fname = shorturl_db.image_info(key) terom@20: terom@20: img = Image(key, dir, fname, index) terom@20: self.images.append(img) terom@20: terom@20: self.tags = [Tag(name, count) for (name, count) in more_tags] terom@20: terom@20: def render (self) : terom@20: descr = "" terom@20: return template.gallery.render( terom@20: stylesheet_url = utils.url("style.css", up=root), terom@20: terom@20: breadcrumb = [(utils.url(up=root), "Index"), (utils.url(up=root-1), "Tags")] + [(utils.url(up=root-(n+1), trailing=True), tag) for n, tag in enumerate(tag_list)], terom@20: terom@20: title = "Tags :: %s" % (" » ".join(tag_list) or "All"), terom@20: terom@20: num_pages = 1, terom@20: cur_page = 0, terom@20: terom@20: dirs = self.tags, terom@20: images = self.images, terom@20: terom@20: description = descr, terom@20: terom@20: shorturl = None, terom@20: shorturl_code = None, terom@20: ) terom@20: terom@20: class Image (object) : terom@20: def __init__ (self, key, dir, fname, index) : terom@20: self.fname = fname terom@20: self.name = utils.url_join(dir, fname, abs=True) terom@20: self.html_name = utils.url_join(dir, fname + ".html", abs=True) terom@20: self.thumb_name = utils.url_join(dir, settings.THUMB_DIR, fname, abs=True) terom@20: self.preview_name = utils.url_join(dir, settings.PREVIEW_DIR, fname, abs=True) terom@20: terom@20: self.shorturl = key terom@20: terom@20: self.prev = self.next = None terom@20: terom@20: tagview = TagView(tag_list) terom@20: terom@20: print "Content-Type: text/html" terom@20: print terom@20: print tagview.render() terom@20: