|
1 #!/usr/bin/env python2.4 |
|
2 # |
|
3 # DeGAL - A pretty simple web image gallery |
|
4 # Copyright (C) 2007 Tero Marttila |
|
5 # http://marttila.de/~terom/degal/ |
|
6 # |
|
7 # This program is free software; you can redistribute it and/or modify |
|
8 # it under the terms of the GNU General Public License as published by |
|
9 # the Free Software Foundation; either version 2 of the License, or |
|
10 # (at your option) any later version. |
|
11 # |
|
12 # This program is distributed in the hope that it will be useful, |
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 # GNU General Public License for more details. |
|
16 # |
|
17 # You should have received a copy of the GNU General Public License |
|
18 # along with this program; if not, write to the |
|
19 # Free Software Foundation, Inc., |
|
20 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
21 # |
|
22 |
|
23 import cgi |
|
24 |
|
25 import inc |
|
26 from lib import tags, template, req, shorturl, utils, settings |
|
27 |
|
28 tag_list = [tag for tag in req.get_str("tags", "").split("/") if tag] |
|
29 |
|
30 tag_db = tags.TagDB() |
|
31 shorturl_db = shorturl.DB() |
|
32 |
|
33 root = len(tag_list) + 1 |
|
34 |
|
35 class Tag (object) : |
|
36 def __init__ (self, name, count) : |
|
37 self.title = "%s (%d)" % (name, count) |
|
38 self.name = utils.url(name, trailing=True) |
|
39 |
|
40 class TagView (object) : |
|
41 def __init__ (self, tag_list) : |
|
42 img_codes = tag_db.imgs(tag_list) |
|
43 more_tags = tag_db.tags(tag_list) |
|
44 |
|
45 self.images = [] |
|
46 |
|
47 for index, key in enumerate(img_codes) : |
|
48 dir, fname = shorturl_db.image_info(key) |
|
49 |
|
50 img = Image(key, dir, fname, index) |
|
51 self.images.append(img) |
|
52 |
|
53 self.tags = [Tag(name, count) for (name, count) in more_tags] |
|
54 |
|
55 def render (self) : |
|
56 descr = "" |
|
57 return template.gallery.render( |
|
58 stylesheet_url = utils.url("style.css", up=root), |
|
59 |
|
60 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)], |
|
61 |
|
62 title = "Tags :: %s" % (" » ".join(tag_list) or "All"), |
|
63 |
|
64 num_pages = 1, |
|
65 cur_page = 0, |
|
66 |
|
67 dirs = self.tags, |
|
68 images = self.images, |
|
69 |
|
70 description = descr, |
|
71 |
|
72 shorturl = None, |
|
73 shorturl_code = None, |
|
74 ) |
|
75 |
|
76 class Image (object) : |
|
77 def __init__ (self, key, dir, fname, index) : |
|
78 self.fname = fname |
|
79 self.name = utils.url_join(dir, fname, abs=True) |
|
80 self.html_name = utils.url_join(dir, fname + ".html", abs=True) |
|
81 self.thumb_name = utils.url_join(dir, settings.THUMB_DIR, fname, abs=True) |
|
82 self.preview_name = utils.url_join(dir, settings.PREVIEW_DIR, fname, abs=True) |
|
83 |
|
84 self.shorturl = key |
|
85 |
|
86 self.prev = self.next = None |
|
87 |
|
88 tagview = TagView(tag_list) |
|
89 |
|
90 print "Content-Type: text/html" |
|
91 print |
|
92 print tagview.render() |
|
93 |