Polishing...

master
Jason A. Donenfeld 2011-05-06 21:12:51 -04:00
parent b7641975a6
commit 2e017d0df3
3 changed files with 33 additions and 6 deletions

View File

@ -87,7 +87,7 @@ class Album(object):
return None return None
class Photo(object): class Photo(object):
thumb_sizes = [ (150, True), (640, False), (800, False), (1024, False) ] thumb_sizes = [ (75, True), (150, True), (640, False), (800, False), (1024, False) ]
def __init__(self, path, thumb_path=None, attributes=None): def __init__(self, path, thumb_path=None, attributes=None):
self._path = trim_base(path) self._path = trim_base(path)
self.is_valid = True self.is_valid = True
@ -192,6 +192,9 @@ class Photo(object):
def __str__(self): def __str__(self):
return self.name return self.name
@property @property
def path(self):
return self._path
@property
def image_caches(self): def image_caches(self):
return [image_cache(self._path, size[0], size[1]) for size in Photo.thumb_sizes] return [image_cache(self._path, size[0], size[1]) for size in Photo.thumb_sizes]
@property @property

View File

@ -1,8 +1,9 @@
import os import os
import os.path import os.path
from datetime import datetime from datetime import datetime
from PhotoAlbum import Photo, Album from PhotoAlbum import Photo, Album, PhotoAlbumEncoder
from CachePath import json_cache, set_cache_path_base, file_mtime from CachePath import json_cache, set_cache_path_base, file_mtime
import json
class TreeWalker: class TreeWalker:
def __init__(self, album_path, cache_path): def __init__(self, album_path, cache_path):
@ -12,6 +13,7 @@ class TreeWalker:
self.all_albums = list() self.all_albums = list()
self.all_photos = list() self.all_photos = list()
self.walk(self.album_path) self.walk(self.album_path)
self.big_lists()
self.remove_stale() self.remove_stale()
def walk(self, path): def walk(self, path):
print "Walking %s" % path print "Walking %s" % path
@ -51,7 +53,23 @@ class TreeWalker:
album.cache(self.cache_path) album.cache(self.cache_path)
self.all_albums.append(album) self.all_albums.append(album)
return album return album
def big_lists(self):
photo_list = []
self.all_photos.sort()
for photo in self.all_photos:
photo_list.append(photo.path)
print "Writing all photos list."
fp = open(os.path.join(self.cache_path, "all_photos.json"), 'w')
json.dump(photo_list, fp, cls=PhotoAlbumEncoder)
fp.close()
photo_list.reverse()
print "Writing latest photos list."
fp = open(os.path.join(self.cache_path, "latest_photos.json"), 'w')
json.dump(photo_list[0:27], fp, cls=PhotoAlbumEncoder)
fp.close()
def remove_stale(self): def remove_stale(self):
print "Removing stale cache entries."
for cache in os.listdir(self.cache_path): for cache in os.listdir(self.cache_path):
match = False match = False
for album in self.all_albums: for album in self.all_albums:

View File

@ -56,6 +56,12 @@ $(document).ready(function() {
showPhoto(); showPhoto();
setTitle(); setTitle();
} }
function trimExtension(title) {
var index = title.lastIndexOf(".");
if (index != -1)
return title.substring(0, index)
return title;
}
function setTitle() { function setTitle() {
var title = ""; var title = "";
var components; var components;
@ -78,14 +84,14 @@ $(document).ready(function() {
} }
} }
if (current_photo_cache != null) if (current_photo_cache != null)
title += current_photo.name; title += trimExtension(current_photo.name);
$("#title").html(title); $("#title").html(title);
} }
function showAlbum() { function showAlbum() {
$("html, body").animate({ scrollTop: 0 }, "slow"); $("html, body").animate({ scrollTop: 0 }, "slow");
var photos = ""; var photos = "";
for (var i = 0; i < current_album.photos.length; ++i) for (var i = 0; i < current_album.photos.length; ++i)
photos += "<a href=\"#" + current_album_cache + "/" + cachePath(current_album.photos[i].name) + "\"><img id=\"thumb-" + cachePath(current_album.photos[i].name) + "\" src=\"" + imagePath(current_album.photos[i].name, current_album.path, 150, true) + "\" height=\"150\" width=\"150\"></a>"; photos += "<a href=\"#" + current_album_cache + "/" + cachePath(current_album.photos[i].name) + "\"><img title=\"" + trimExtension(current_album.photos[i].name) + "\" alt=\"" + trimExtension(current_album.photos[i].name) + "\" id=\"thumb-" + cachePath(current_album.photos[i].name) + "\" src=\"" + imagePath(current_album.photos[i].name, current_album.path, 150, true) + "\" height=\"150\" width=\"150\"></a>";
$("#thumbs").html(photos); $("#thumbs").html(photos);
if (current_album.albums.length) if (current_album.albums.length)
$("#subalbums-title").show(); $("#subalbums-title").show();
@ -96,7 +102,7 @@ $(document).ready(function() {
for (var i = current_album.albums.length - 1; i >= 0; --i) { for (var i = current_album.albums.length - 1; i >= 0; --i) {
var path = cachePath(current_album.path + "/" + current_album.albums[i].path); var path = cachePath(current_album.path + "/" + current_album.albums[i].path);
var id = "album-" + path; var id = "album-" + path;
subalbums += "<a href=\"#" + path + "\"><div id=\"" + id + "\" class=\"album-button\">" + current_album.albums[i].path + "</div></a>"; subalbums += "<a href=\"#" + path + "\"><div title=\"" + current_album.albums[i].date + "\" id=\"" + id + "\" class=\"album-button\">" + current_album.albums[i].path + "</div></a>";
thumbFinderList.push({ path: path, id: escapeId(id) }); thumbFinderList.push({ path: path, id: escapeId(id) });
} }
$("#subalbums").html(subalbums); $("#subalbums").html(subalbums);
@ -131,7 +137,7 @@ $(document).ready(function() {
.attr("width", width).attr("height", height) .attr("width", width).attr("height", height)
.attr("src", imagePath(current_photo.name, current_album.path, maxSize, false)) .attr("src", imagePath(current_photo.name, current_album.path, maxSize, false))
.attr("alt", current_photo.name) .attr("alt", current_photo.name)
.attr("title", current_photo.name) .attr("title", current_photo.date)
.load(function() { $(this).css("width", "auto").css("height", "100%"); }); .load(function() { $(this).css("width", "auto").css("height", "100%"); });
var nextLink = "#" + current_album_cache + "/" + cachePath(current_album.photos[ var nextLink = "#" + current_album_cache + "/" + cachePath(current_album.photos[
(current_photo_index + 1 >= current_album.photos.length) ? 0 : (current_photo_index + 1) (current_photo_index + 1 >= current_album.photos.length) ? 0 : (current_photo_index + 1)