author | terom |
Sun, 04 May 2008 18:23:03 +0000 | |
changeset 33 | 4943047bfcb5 |
parent 19 | 8d3ffd87cb0b |
permissions | -rwxr-xr-x |
8 | 1 |
#!/usr/bin/env python2.4 |
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
8
diff
changeset
|
2 |
# |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
8
diff
changeset
|
3 |
# DeGAL - A pretty simple web image gallery |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
8
diff
changeset
|
4 |
# Copyright (C) 2007 Tero Marttila |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
8
diff
changeset
|
5 |
# http://marttila.de/~terom/degal/ |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
8
diff
changeset
|
6 |
# |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
8
diff
changeset
|
7 |
# This program is free software; you can redistribute it and/or modify |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
8
diff
changeset
|
8 |
# it under the terms of the GNU General Public License as published by |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
8
diff
changeset
|
9 |
# the Free Software Foundation; either version 2 of the License, or |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
8
diff
changeset
|
10 |
# (at your option) any later version. |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
8
diff
changeset
|
11 |
# |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
8
diff
changeset
|
12 |
# This program is distributed in the hope that it will be useful, |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
8
diff
changeset
|
13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
8
diff
changeset
|
14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
8
diff
changeset
|
15 |
# GNU General Public License for more details. |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
8
diff
changeset
|
16 |
# |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
8
diff
changeset
|
17 |
# You should have received a copy of the GNU General Public License |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
8
diff
changeset
|
18 |
# along with this program; if not, write to the |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
8
diff
changeset
|
19 |
# Free Software Foundation, Inc., |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
8
diff
changeset
|
20 |
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
8
diff
changeset
|
21 |
# |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
8
diff
changeset
|
22 |
|
8 | 23 |
|
24 |
import cgi |
|
25 |
import shelve |
|
26 |
import os, os.path |
|
27 |
||
28 |
import degal |
|
29 |
||
30 |
images = shelve.open('images', 'c') |
|
31 |
tag_images = shelve.open('tag_images', 'c') |
|
32 |
tag_tags = shelve.open('tag_tags', 'c') |
|
33 |
||
34 |
# request params |
|
35 |
vars = cgi.FieldStorage() |
|
36 |
||
37 |
if 'path' in vars : |
|
38 |
path = vars['path'].value |
|
39 |
else : |
|
40 |
path = '.' |
|
41 |
||
42 |
image_list = [] |
|
43 |
||
44 |
if 'bulk_tag' in vars : |
|
45 |
bulk_tags = vars['bulk_tag'].value.split() |
|
46 |
else : |
|
47 |
bulk_tags = None |
|
48 |
||
49 |
for fname in os.listdir(path) : |
|
50 |
if degal.isImage(fname) : |
|
51 |
image_path = os.path.join(path, fname) |
|
52 |
thumb_path = os.path.join(path, degal.THUMB_DIR, fname) |
|
53 |
html_path = image_path + '.html' |
|
54 |
||
55 |
title, descr, tags = images.get(image_path, (None, None, [])) |
|
56 |
||
57 |
if 'img_%s_title' % fname in vars : |
|
58 |
title = vars['img_%s_title' % fname].value |
|
59 |
||
60 |
if 'img_%s_descr' % fname in vars : |
|
61 |
descr = vars['img_%s_descr' % fname].value |
|
62 |
||
63 |
if 'img_%s_tags' % fname in vars : |
|
64 |
tags = vars['img_%s_tags' % fname].value.split() |
|
65 |
||
66 |
if bulk_tags and 'img_%s_chk' % fname in vars : |
|
67 |
tags.extend(bulk_tags) |
|
68 |
||
69 |
if title or descr or tags : |
|
70 |
images[image_path] = (title, descr, tags) |
|
71 |
||
72 |
html = """ |
|
73 |
<li> |
|
74 |
<span class="inputs"> |
|
75 |
<label for="img_%(fname)s_title">Title</label> <input type="text" name="img_%(fname)s_title" size="60" value="%(title)s" /> <br/> |
|
76 |
<label for="img_%(fname)s_descr">Description</label> <input type="text" name="img_%(fname)s_descr" size="60" value="%(descr)s" /> <br/> |
|
77 |
<label for="img_%(fname)s_tags">Tags</label> <input type="text" name="img_%(fname)s_tags" size="60" value="%(tags)s" /> <br/> |
|
78 |
</span> |
|
79 |
||
80 |
<input type="checkbox" name="img_%(fname)s_chk" class="chk" /> |
|
81 |
||
82 |
<span class="thumb"><a href="%(html_path)s"><img src="%(thumb_path)s" /></a></span> |
|
83 |
</li> |
|
84 |
""" % dict( |
|
85 |
html_path = html_path, |
|
86 |
thumb_path = thumb_path, |
|
87 |
fname = fname, |
|
88 |
title = title and title or '', |
|
89 |
descr = descr and descr or '', |
|
90 |
tags = tags and ' '.join(tags) or '', |
|
91 |
) |
|
92 |
||
93 |
image_list.append((fname, html)) |
|
94 |
||
95 |
image_list.sort() |
|
96 |
||
97 |
print "Content-Type: text/html" |
|
98 |
||
99 |
print degal.Template('taggr').render( |
|
100 |
TITLE = "Taggr - %s" % path, |
|
101 |
BREADCRUMB = "TODO", |
|
102 |
CONTENT = "<ul>" + ''.join([h for fname, h in image_list]) + "</ul>", |
|
103 |
PATH = path, |
|
104 |
) |
|
105 |