series.cgi
author terom
Fri, 21 Dec 2007 20:49:04 +0000
changeset 14 4b5478da5850
parent 12 c2d8e9a754a1
permissions -rwxr-xr-x
remove hanging utils.py in root, and add GPL license header to all .py files
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
3
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    23
import shelve
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
import os, os.path
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    27
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    28
import degal
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
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    95
        
3
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    96
    if arg2 :
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    97
        index = int(arg2)
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    98
    else :
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
    99
        index = None
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   100
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   101
    # load DB
3
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
   102
    db = shelve.open('shorturls2', 'r')
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   103
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   104
    # get the Image objects
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   105
    photos = []
3
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
   106
    
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
   107
    #
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
   108
    # Start ugly code-misreuse
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
   109
    #
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   110
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   111
    # monkey-patch the templates
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   112
    rendered_templates = []
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   113
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   114
    def _myRenderTo (self, path, **vars) :
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   115
        rendered_templates.append(self.render(**vars))
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   116
3
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
   117
    # lalalalala... ooh, look;
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
   118
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   119
    degal.Template.renderTo = _myRenderTo
3
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
   120
    #
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
   121
    #         vvvvvvvvvvvvvvvvvvvv
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
   122
    #         vvvvvvvvvvvvvvvvvvvv
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
   123
    #
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
   124
    #    >>>> SHINY PINK ELEPHANT! <<<<
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
   125
    #
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
   126
    #         ^^^^^^^^^^^^^^^^^^^^
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
   127
    #         ^^^^^^^^^^^^^^^^^^^^
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   128
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   129
    # our own version of Folder
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   130
    class Series (degal.Folder) :
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   131
        def __init__ (self) :
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   132
            super(Series, self).__init__()
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   133
            
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   134
            self.alive = True
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   135
            self.filtered = False
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   136
            self.subdirs = {}
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   137
            self.images = {}
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   138
            self.sorted_images = []
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   139
            self.title = "Series"
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   140
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   141
            if my_series :
4
d46ab092d2b2 add rel="nofollow" to ShortURL and series-related links, googlebot doesn't need to follow them
terom
parents: 3
diff changeset
   142
                self.descr = '<a href="../clear/" rel="nofollow">Clear your series</a>'
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   143
            else :
4
d46ab092d2b2 add rel="nofollow" to ShortURL and series-related links, googlebot doesn't need to follow them
terom
parents: 3
diff changeset
   144
                self.descr = '<a href="load" rel="nofollow">Load as your series</a>'
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   145
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   146
            self.shorturl_code = ''
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   147
        
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   148
        def breadcrumb (self) :
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   149
            return [('../..', 'Gallery'), ('.', 'Series')]
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   150
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   151
        def inRoot (self, *fnames) :
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   152
            return os.path.join('../..', *fnames)
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   153
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   154
    class Image (degal.Image) :
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   155
        def __init__ (self, series, key, i) :
3
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
   156
            type, self.dir_name, self.image_name = db[key]
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   157
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   158
            super(Image, self).__init__(series, self.image_name)
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   159
            
3
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
   160
            self.path = self._path()
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   161
            self.shorturl_code = key
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   162
            self.html_path = self.html_name = str(i + 1)
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   163
            self.title = 'Image %d' % (i + 1, )
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   164
            self.descr = '<span style="font-size: x-small">Standalone image: <a href="%s.html">%s</a></span>' % (self._path(), self._path().lstrip('./'))
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   165
            self.img_size = (-1, -1)
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   166
            self.filesize = 0
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   167
            self.timestamp = 0
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   168
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   169
            if my_series :
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   170
                self.series_act = "del"
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   171
                self.series_verb = "Remove from"
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   172
            else :
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   173
                self.series_act = self.series_verb = ""
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   174
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   175
        def breadcrumb (self) :
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   176
            return [('../..', 'Gallery'), ('.', 'Series'), (self.html_name, self.title)]
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   177
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   178
        def _path (self, blaa='') :
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   179
            return os.path.join('../..', self.dir_name, blaa, self.image_name)
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   180
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   181
        def thumbImgTag (self) :
3
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
   182
            return degal.link(self.html_name, "<img src='%s' alt='%s' title='%s'>" % (self._path(degal.THUMB_DIR), '', self.title))
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   183
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   184
        def previewImgTag (self) :
3
9637b8f24005 ...and fix it to redirect to the .html. Series.cgi is also refactored+commented+shorturls2'd
terom
parents: 1
diff changeset
   185
            return degal.link(self._path(), "<img src='%s' alt='%s' title='%s'>" % (self._path(degal.PREVIEW_DIR), '', self.title))
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   186
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   187
    series = Series()
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   188
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   189
    try :
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   190
        prev = None
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   191
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   192
        for i, key in enumerate(keys) :
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   193
            img = Image(series, key, i)
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   194
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   195
            if prev :
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   196
                prev.next = img
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   197
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   198
            img.prev = prev
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   199
            prev = img
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   200
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   201
            series.sorted_images.append(img)
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   202
    finally :
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   203
        db.close()
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   204
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   205
    if index :
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   206
        img = series.sorted_images[index - 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
        img.render()
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   209
    else :
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   210
        series.render()
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   211
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   212
    print "Content-Type: text/html"
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   213
    print
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   214
    print rendered_templates[0]
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
   215