taggr.cgi
author terom
Fri, 21 Dec 2007 20:36:03 +0000
changeset 12 c2d8e9a754a1
parent 8 4e71e1b670bc
permissions -rwxr-xr-x
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
8
4e71e1b670bc an unfinished taggr.py, prototype/testing code
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: 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
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    23
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    24
import cgi
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    25
import shelve
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    26
import os, os.path
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    27
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    28
import degal
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    29
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    30
images = shelve.open('images', 'c')
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    31
tag_images = shelve.open('tag_images', 'c')
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    32
tag_tags = shelve.open('tag_tags', 'c')
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    33
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    34
# request params
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    35
vars = cgi.FieldStorage()
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    36
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    37
if 'path' in vars :
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    38
    path = vars['path'].value
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    39
else :
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    40
    path = '.'
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    41
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    42
image_list = []
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    43
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    44
if 'bulk_tag' in vars :
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    45
    bulk_tags = vars['bulk_tag'].value.split()
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    46
else :
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    47
    bulk_tags = None
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    48
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    49
for fname in os.listdir(path) :
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    50
    if degal.isImage(fname) :
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    51
        image_path = os.path.join(path, fname)
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    52
        thumb_path = os.path.join(path, degal.THUMB_DIR, fname)
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    53
        html_path = image_path + '.html'
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    54
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    55
        title, descr, tags = images.get(image_path, (None, None, []))
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    56
        
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    57
        if 'img_%s_title' % fname in vars :
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    58
            title = vars['img_%s_title' % fname].value
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    59
        
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    60
        if 'img_%s_descr' % fname in vars :
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    61
            descr = vars['img_%s_descr' % fname].value
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    62
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    63
        if 'img_%s_tags' % fname in vars :
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    64
            tags = vars['img_%s_tags' % fname].value.split()
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    65
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    66
        if bulk_tags and 'img_%s_chk' % fname in vars :
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    67
            tags.extend(bulk_tags)
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    68
        
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    69
        if title or descr or tags :
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    70
           images[image_path] = (title, descr, tags)
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    71
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    72
        html = """
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    73
<li>
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    74
    <span class="inputs">
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    75
        <label for="img_%(fname)s_title">Title</label> <input type="text" name="img_%(fname)s_title" size="60" value="%(title)s" /> <br/>
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    76
        <label for="img_%(fname)s_descr">Description</label> <input type="text" name="img_%(fname)s_descr" size="60" value="%(descr)s" /> <br/>
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    77
        <label for="img_%(fname)s_tags">Tags</label> <input type="text" name="img_%(fname)s_tags" size="60" value="%(tags)s" /> <br/>
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    78
    </span>
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    79
    
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    80
    <input type="checkbox" name="img_%(fname)s_chk" class="chk" />
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    81
    
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    82
    <span class="thumb"><a href="%(html_path)s"><img src="%(thumb_path)s" /></a></span>
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    83
</li>
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    84
        """ % dict(
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    85
            html_path       = html_path,
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    86
            thumb_path      = thumb_path,
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    87
            fname           = fname,
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    88
            title           = title and title or '',
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    89
            descr           = descr and descr or '',
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    90
            tags            = tags and ' '.join(tags) or '',
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    91
        )
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    92
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    93
        image_list.append((fname, html))
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    94
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    95
image_list.sort()
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    96
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    97
print "Content-Type: text/html"
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    98
print
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
    99
print degal.Template('taggr').render(
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
   100
    TITLE       = "Taggr - %s" % path,
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
   101
    BREADCRUMB  = "TODO",
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
   102
    CONTENT     = "<ul>" + ''.join([h for fname, h in image_list]) + "</ul>",
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
   103
    PATH        = path,
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
   104
)
4e71e1b670bc an unfinished taggr.py, prototype/testing code
terom
parents:
diff changeset
   105