de-cgi-bin/series.py
author terom
Wed, 16 Jan 2008 18:44:03 +0000
changeset 22 72696ca68c34
parent 19 8d3ffd87cb0b
permissions -rwxr-xr-x
use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
     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: 4
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: 4
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: 4
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: 4
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: 4
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: 4
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: 4
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: 4
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: 4
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: 4
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: 4
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: 4
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: 4
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: 4
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: 4
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: 4
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: 4
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: 4
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: 4
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: 4
diff changeset
    21
#
4
d46ab092d2b2 add rel="nofollow" to ShortURL and series-related links, googlebot doesn't need to follow them
terom
parents: 3
diff changeset
    22
19
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
    23
import os
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    24
import cgi
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    25
import Cookie
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    26
19
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
    27
import inc
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
    28
from lib import shorturl, template, utils, settings
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    29
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    30
#
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    31
# load request params
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    32
#
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    33
vars = cgi.FieldStorage()
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    34
3
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    35
# these are interpeted different ways, hence the generic naming
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    36
arg1 = vars["keys"].value
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    37
if 'index' in vars :
3
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    38
    arg2 = vars["index"].value
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    39
else :
3
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    40
    arg2 = None
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    41
3
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    42
# the cookie with the user's current series
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    43
cookie = Cookie.SimpleCookie(os.environ.get('HTTP_COOKIE', None))
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    44
3
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    45
# a special action?
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    46
if arg1 and arg1 in ('add', 'del', 'clear', 'view') or arg2 == 'load' :
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    47
    # load the keys from the cookie
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    48
    if 'series' in cookie :
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    49
        keys = cookie["series"].value.split()
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    50
    else :
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    51
        keys = []
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    52
    
3
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    53
    if arg2 == 'load' :
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    54
        # set the keys in the user's cookie to those in the URL
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    55
        keys = arg1.split()
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    56
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    57
    elif arg1 == 'add' and arg2 not in keys :
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    58
        # add a code to the list of keys
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    59
        keys.append(arg2)
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    60
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    61
    elif arg1 == 'del' and arg2 in keys :
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    62
        # remove a key from the list of keys
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    63
        keys.remove(arg2)
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    64
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    65
    elif arg1 == 'clear' :
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    66
        # clear out the set of keys
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    67
        keys = []
3
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    68
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    69
    elif arg1 == 'view' :
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    70
        # just view them
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    71
        pass
3
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    72
   
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    73
    # set the series cookie value
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    74
    cookie['series'] = ' '.join(keys)
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    75
    cookie['series']['path'] = '/'
3
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    76
    
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    77
    # if we have keys, redirect to them, otherwise, back to index we go
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    78
    if keys :
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    79
        redirect_to = "../%s/" % ('+'.join(keys))
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    80
    else :
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    81
        redirect_to = "../.."
3
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    82
    
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    83
    # do the redirect
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    84
    print "Status: 302"
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    85
    print "Location: %s" % redirect_to
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    86
    print cookie
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    87
    print
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    88
    print "Redirect..."
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    89
else :
3
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    90
    # we're just viewing
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    91
    keys = arg1.split()
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    92
    
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    93
    # is this "My Series"?
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    94
    my_series = 'series' in cookie and cookie['series'].value.split() == keys
19
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
    95
    
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
    96
    index = fname = None
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
    97
3
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    98
    if arg2 :
19
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
    99
        try :
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   100
            index = int(arg2)
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   101
        except ValueError :
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   102
            fname = arg2
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   103
19
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   104
    # our custom Series/Image classes, because they do act slightly differently
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   105
19
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   106
    class Series (object) :
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   107
        def __init__ (self, keys) :
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   108
            self.images = []
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   109
            prev = None
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   110
19
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   111
            self.image_dict = dict()
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   112
22
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents: 19
diff changeset
   113
            images = shorturl.get_images(keys)
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   114
22
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents: 19
diff changeset
   115
            for index, (key, (dir, fname)) in enumerate(zip(keys, images)) :
19
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   116
                img = Image(self, key, dir, fname, index)
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   117
                self.images.append(img)
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   118
                self.image_dict[fname] = img
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   119
19
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   120
                img.prev = prev
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   121
19
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   122
                if prev :
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   123
                    prev.next = img
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   124
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   125
                prev = img
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   126
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   127
        def render (self) :
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   128
            if my_series :
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   129
                descr = '<a href="../clear/" rel="nofollow">Clear your series</a>'
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   130
            else :
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   131
                descr = '<a href="load" rel="nofollow">Load as your series</a>'
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   132
   
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   133
            return template.gallery.render(
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   134
                stylesheet_url      = utils.url("style.css", up=2),
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   135
                
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   136
                breadcrumb          = [(utils.url(up=1), "Index"), (utils.url(), "Series")],
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   137
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   138
                dirs                = None,
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   139
                title               = "Series",
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   140
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   141
                num_pages           = 1,
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   142
                cur_page            = 0,
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   143
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   144
                images              = self.images,
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   145
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   146
                description         = descr,
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   147
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   148
                shorturl            = None,
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   149
                shorturl_code       = None,
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   150
            )
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   151
    
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   152
    class Image (object) :
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   153
        def __init__ (self, series, key, dir, fname, index) :
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   154
            self.fname = fname
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   155
            self.name = utils.url_join(dir, fname, abs=True)
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   156
            self.html_name = utils.url(fname)
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   157
            self.real_html_name = utils.url_join(dir, fname + ".html", abs=True)
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   158
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   159
            self.thumb_name = utils.url_join(dir, settings.THUMB_DIR, fname, abs=True)
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   160
            self.preview_name = utils.url_join(dir, settings.PREVIEW_DIR, fname, abs=True)
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   161
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   162
            self.shorturl = key
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   163
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   164
            self.prev = self.next = None
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   165
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   166
        def render (self) :
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   167
            descr = '<span style="font-size: x-small"><a href="%s.html">Standalone image</a></span>' % self.real_html_name
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   168
            
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   169
            if my_series :
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   170
                series_url = utils.url_join("del", self.shorturl, up=1)
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   171
                series_verb = "Remove from"
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   172
            else :
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   173
                series_url = series_verb = ""
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   174
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   175
            return template.image.render(
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   176
                stylesheet_url      = utils.url("style.css", up=3),
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   177
                
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   178
                breadcrumb          = [(utils.url(up=2), "Index"), (utils.url("."), "Series"), (self.html_name, self.fname)],
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   179
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   180
                title               = self.fname,
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   181
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   182
                prev                = self.prev,
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   183
                img                 = self,
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   184
                next                = self.next,
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   185
                
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   186
                description         = descr,
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   187
    
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   188
                img_size            = None,
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   189
                file_size           = None,
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   190
                timestamp           = None,
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   191
                
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   192
                shorturl            = utils.url_join("s", self.shorturl, abs=True),
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   193
                shorturl_code       = self.shorturl,
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   194
                
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   195
                series_url          = series_url,
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   196
                series_verb         = series_verb,
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   197
            )
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   198
    
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   199
    series = Series(keys)
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   200
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   201
    if fname :
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   202
        html = series.image_dict[fname].render()
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   203
    elif index :
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   204
        html = series.images[index - 1].render()
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   205
    else :
19
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   206
        html = series.render()
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   207
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   208
    print "Content-Type: text/html"
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   209
    print
19
8d3ffd87cb0b * move cgi-bin to de-cgi-bin so it doesn't conflict with my default alias... need to come up with a real solution to this
terom
parents: 18
diff changeset
   210
    print html
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   211