terom@14: # DeGAL - A pretty simple web image gallery terom@14: # Copyright (C) 2007 Tero Marttila terom@14: # http://marttila.de/~terom/degal/ terom@14: # terom@14: # This program is free software; you can redistribute it and/or modify terom@14: # it under the terms of the GNU General Public License as published by terom@14: # the Free Software Foundation; either version 2 of the License, or terom@14: # (at your option) any later version. terom@14: # terom@14: # This program is distributed in the hope that it will be useful, terom@14: # but WITHOUT ANY WARRANTY; without even the implied warranty of terom@14: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terom@14: # GNU General Public License for more details. terom@14: # terom@14: # You should have received a copy of the GNU General Public License terom@14: # along with this program; if not, write to the terom@14: # Free Software Foundation, Inc., terom@14: # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. terom@14: # terom@14: terom@12: # template helper functions terom@12: import urllib terom@12: from formatbytes import formatbytes terom@12: from datetime import datetime terom@12: terom@12: def iter_is_first (seq) : terom@12: flag = True terom@12: terom@12: for item in seq : terom@12: yield item, flag terom@12: flag = False terom@12: terom@12: def url_for_page (page) : terom@12: assert page >= 0 terom@12: terom@12: if page > 0 : terom@12: return 'index_%d.html' % page terom@12: else : terom@12: return 'index.html' terom@12: terom@12: def tag_for_img (page, img) : terom@12: return """""" % (page, img) terom@12: terom@12: def format_filesize (size) : terom@12: return formatbytes(size, forcekb=False, largestonly=True, kiloname='KiB', meganame='MiB', bytename='B', nospace=False) terom@12: terom@12: def format_timestamp (ts) : terom@12: return datetime.fromtimestamp(ts).strftime("%Y-%m-%d %H:%M:%S") terom@12: terom@12: def format_imgsize (size) : terom@12: return "%dx%d" % size