def restore_album(d, s): adict = yaml.load(open(os.path.join(d, "info.yaml"))) a = Album() a.id = adict["id"] a.display_name = adict["display_name"] a.created = adict["created"] a.preview_id = adict["preview_id"] a.descr = adict["descr"] a.hidden = adict["hidden"] a.sort_by = adict["sort_by"] s.add(a) s.commit() for pdict in adict["photos"]: pfile = pdict["name"] if pfile in ["previews", "info.yaml"]: continue ppath = os.path.join(d, pfile) if os.path.isdir(ppath): continue p = Photo() p.id = pdict["id"] p.album_id = a.id p.name = pdict["name"] p.display_name = pdict["display_name"] p.created = pdict["created"] p.width = pdict["width"] p.height = pdict["height"] p.hidden = pdict["hidden"] photo_name = os.path.basename(p.get_path()) preview_name = os.path.basename(p.get_preview_path()) shutil.copy(os.path.join(d, photo_name), p.get_path()) shutil.copy(os.path.join(d, "previews", preview_name), p.get_preview_path()) s.add(p) for afile in os.listdir(d): if afile == "previews": continue apath = os.path.join(d, afile) if not os.path.isdir(apath): continue restore_album(apath, s)
def commitedit(album, req): if not req.params.get("commit"): return HTTPFound(location = req.resource_url(album)) s = DBSession() if req.params.get("new_album"): a = Album(parent_id = album.id) s.add(a) s.commit() else: a = album a.display_name = req.params.get("title") a.descr = req.params.get("description") a.hidden = bool(req.params.get("hide_album", 0)) a.sort_by = int(req.params.get("sort_by", 1)) new_thumb = req.params.get('album_thumbnail') print new_thumb, repr(new_thumb) if type(new_thumb) is types.InstanceType: old_preview = a.preview # add preview name = new_thumb.filename.lstrip(os.sep) preview = Photo(name, a.id, new_thumb.file.read()) new_thumb.file.close() preview.hidden = True s.add(preview) s.commit() a.preview_id = preview.id if old_preview: s.delete(old_preview) s.commit() return HTTPFound(location = req.resource_url(a))