author | terom |
Fri, 21 Dec 2007 20:49:04 +0000 | |
changeset 14 | 4b5478da5850 |
parent 12 | c2d8e9a754a1 |
permissions | -rwxr-xr-x |
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:
9
diff
changeset
|
1 |
#!/usr/bin/env python2.4 |
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:
9
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:
9
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:
9
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:
9
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:
9
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:
9
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:
9
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:
9
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:
9
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:
9
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:
9
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:
9
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:
9
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:
9
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:
9
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:
9
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:
9
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:
9
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:
9
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:
9
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:
9
diff
changeset
|
22 |
|
1 | 23 |
|
2 | 24 |
import shelve |
1 | 25 |
import cgi |
26 |
import os, os.path |
|
27 |
||
28 |
vars = cgi.FieldStorage() |
|
29 |
||
30 |
key = vars['key'].value |
|
6
d9d1f8e5f384
fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents:
5
diff
changeset
|
31 |
|
d9d1f8e5f384
fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents:
5
diff
changeset
|
32 |
if 'index' in vars : |
d9d1f8e5f384
fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents:
5
diff
changeset
|
33 |
index = int(vars['index'].value.lstrip('/')) |
d9d1f8e5f384
fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents:
5
diff
changeset
|
34 |
else : |
d9d1f8e5f384
fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents:
5
diff
changeset
|
35 |
index = None |
d9d1f8e5f384
fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents:
5
diff
changeset
|
36 |
|
2 | 37 |
db = shelve.open('shorturls2', 'r') |
1 | 38 |
|
39 |
try : |
|
2 | 40 |
type, dirpath, fname = db[key] |
41 |
||
9
a0a13d5e406c
ShortURLs for dirs without page numbers were broken, as fname was 'index'
terom
parents:
6
diff
changeset
|
42 |
if type == 'img' : |
a0a13d5e406c
ShortURLs for dirs without page numbers were broken, as fname was 'index'
terom
parents:
6
diff
changeset
|
43 |
fname += '.html' |
a0a13d5e406c
ShortURLs for dirs without page numbers were broken, as fname was 'index'
terom
parents:
6
diff
changeset
|
44 |
elif type == 'dir' : |
a0a13d5e406c
ShortURLs for dirs without page numbers were broken, as fname was 'index'
terom
parents:
6
diff
changeset
|
45 |
fname = '' |
a0a13d5e406c
ShortURLs for dirs without page numbers were broken, as fname was 'index'
terom
parents:
6
diff
changeset
|
46 |
|
6
d9d1f8e5f384
fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents:
5
diff
changeset
|
47 |
if index : |
d9d1f8e5f384
fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents:
5
diff
changeset
|
48 |
if index > 1 : |
9
a0a13d5e406c
ShortURLs for dirs without page numbers were broken, as fname was 'index'
terom
parents:
6
diff
changeset
|
49 |
fname = 'index_%s.html' % (index - 1) |
5
156cdfffef8e
fix shorturls to dirs, and a new feature: pagination for index pages
terom
parents:
3
diff
changeset
|
50 |
|
6
d9d1f8e5f384
fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents:
5
diff
changeset
|
51 |
dirpath = '../%s' % dirpath |
d9d1f8e5f384
fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents:
5
diff
changeset
|
52 |
|
d9d1f8e5f384
fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents:
5
diff
changeset
|
53 |
path = os.path.join(dirpath, fname) |
1 | 54 |
finally : |
55 |
db.close() |
|
56 |
||
57 |
print "Status: 302" |
|
58 |
print "Location: ../%s" % path |
|
59 |
||
60 |
print "../%s" % path |
|
61 |