de-cgi-bin/tags.py
author Tero Marttila <terom@fixme.fi>
Wed, 03 Jun 2009 18:37:12 +0300
branchold-taggr
changeset 37 5df1a18df815
parent 20 6c774496bb00
permissions -rwxr-xr-x
Old taggr code, never finished
#!/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 inc
from lib import tags, template, req, shorturl, utils, settings

tag_list = [tag for tag in req.get_str("tags", "").split("/") if tag]

tag_db = tags.TagDB()
shorturl_db = shorturl.DB()

root = len(tag_list) + 1

class Tag (object) :
    def __init__ (self, name, count) :
        self.title = "%s (%d)" % (name, count)
        self.name = utils.url(name, trailing=True)

class TagView (object) :
    def __init__ (self, tag_list) :
        img_codes = tag_db.imgs(tag_list)
        more_tags = tag_db.tags(tag_list)

        self.images = []

        for index, key in enumerate(img_codes) :
            dir, fname = shorturl_db.image_info(key)

            img = Image(key, dir, fname, index)
            self.images.append(img)

        self.tags = [Tag(name, count) for (name, count) in more_tags]

    def render (self) :
        descr = ""
        return template.gallery.render(
            stylesheet_url      = utils.url("style.css", up=root),
            
            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)],

            title               = "Tags :: %s" % (" &raquo; ".join(tag_list) or "All"),

            num_pages           = 1,
            cur_page            = 0,

            dirs                = self.tags,
            images              = self.images,

            description         = descr,

            shorturl            = None,
            shorturl_code       = None,
        )
    
class Image (object) :
    def __init__ (self, key, dir, fname, index) :
        self.fname = fname
        self.name = utils.url_join(dir, fname, abs=True)
        self.html_name = utils.url_join(dir, fname + ".html", abs=True)
        self.thumb_name = utils.url_join(dir, settings.THUMB_DIR, fname, abs=True)
        self.preview_name = utils.url_join(dir, settings.PREVIEW_DIR, fname, abs=True)

        self.shorturl = key

        self.prev = self.next = None

tagview = TagView(tag_list)

print "Content-Type: text/html"
print
print tagview.render()