misc ui sorting fixes and cleanup

This commit is contained in:
dave 2019-07-05 00:28:57 -07:00
parent 83a0702341
commit 947f06ea08
2 changed files with 7 additions and 12 deletions

View File

@ -8,7 +8,6 @@ from photoapp.thumb import ThumbGenerator
from photoapp.types import Photo, PhotoSet, Tag, TagItem, PhotoStatus, User from photoapp.types import Photo, PhotoSet, Tag, TagItem, PhotoStatus, User
from photoapp.common import pwhash from photoapp.common import pwhash
from photoapp.api import PhotosApi, LibraryManager from photoapp.api import PhotosApi, LibraryManager
from photoapp.storage import FilesystemAdapter
from photoapp.dbutils import SAEnginePlugin, SATool, db, get_db_engine from photoapp.dbutils import SAEnginePlugin, SATool, db, get_db_engine
from photoapp.utils import mime2ext, auth, require_auth, photoset_auth_filter, slugify from photoapp.utils import mime2ext, auth, require_auth, photoset_auth_filter, slugify
from photoapp.storage import uri_to_storage from photoapp.storage import uri_to_storage
@ -134,9 +133,9 @@ class PhotosWeb(object):
dt = datetime.strptime(fromdate, "%Y-%m-%d") dt = datetime.strptime(fromdate, "%Y-%m-%d")
dt_end = dt + timedelta(days=1) dt_end = dt + timedelta(days=1)
photos = db.query(PhotoSet).filter(and_(PhotoSet.date >= dt, photos = db.query(PhotoSet).filter(and_(PhotoSet.date >= dt,
PhotoSet.date < dt_end)).order_by(PhotoSet.date) PhotoSet.date < dt_end)).order_by(PhotoSet.date.desc())
num_photos = db.query(func.count(PhotoSet.id)). \ num_photos = db.query(func.count(PhotoSet.id)). \
filter(and_(PhotoSet.date >= dt, PhotoSet.date < dt_end)).order_by(PhotoSet.date).scalar() filter(and_(PhotoSet.date >= dt, PhotoSet.date < dt_end)).order_by(PhotoSet.date.desc()).scalar()
if uuid: if uuid:
photos = db.query(PhotoSet).filter(PhotoSet.uuid == uuid) photos = db.query(PhotoSet).filter(PhotoSet.uuid == uuid)
@ -211,8 +210,9 @@ class DateView(object):
dt_end = dt + timedelta(days=1) dt_end = dt + timedelta(days=1)
total_sets = photoset_auth_filter(db.query(func.count(PhotoSet.id))). \ total_sets = photoset_auth_filter(db.query(func.count(PhotoSet.id))). \
filter(and_(PhotoSet.date >= dt, PhotoSet.date < dt_end)).first()[0] filter(and_(PhotoSet.date >= dt, PhotoSet.date < dt_end)).first()[0]
images = photoset_auth_filter(db.query(PhotoSet)).filter(and_(PhotoSet.date >= dt, images = photoset_auth_filter(db.query(PhotoSet)). \
PhotoSet.date < dt_end)).order_by(PhotoSet.date). \ filter(and_(PhotoSet.date >= dt, PhotoSet.date < dt_end)). \
order_by(PhotoSet.date.desc()). \
offset(page * pgsize).limit(pgsize).all() offset(page * pgsize).limit(pgsize).all()
yield self.master.render("date.html", page=page, pgsize=pgsize, total_sets=total_sets, yield self.master.render("date.html", page=page, pgsize=pgsize, total_sets=total_sets,
images=[i for i in images], date=dt) images=[i for i in images], date=dt)
@ -354,7 +354,8 @@ class TagView(object):
if uuid == "untagged": if uuid == "untagged":
numphotos = photoset_auth_filter(db.query(func.count(PhotoSet.id))). \ numphotos = photoset_auth_filter(db.query(func.count(PhotoSet.id))). \
filter(~PhotoSet.id.in_(db.query(TagItem.set_id))).scalar() filter(~PhotoSet.id.in_(db.query(TagItem.set_id))).scalar()
photos = photoset_auth_filter(db.query(PhotoSet)).filter(~PhotoSet.id.in_(db.query(TagItem.set_id))).\ photos = photoset_auth_filter(db.query(PhotoSet)).filter(~PhotoSet.id.in_(db.query(TagItem.set_id))). \
order_by(PhotoSet.date.desc()). \
offset(page * pgsize). \ offset(page * pgsize). \
limit(pgsize).all() limit(pgsize).all()
yield self.master.render("untagged.html", images=photos, total_items=numphotos, pgsize=pgsize, page=page) yield self.master.render("untagged.html", images=photos, total_items=numphotos, pgsize=pgsize, page=page)

View File

@ -49,17 +49,13 @@ class FilesystemAdapter(StorageAdapter):
self.root = root # root path self.root = root # root path
def exists(self, path): def exists(self, path):
# TODO return true/false if the file path exists
return os.path.exists(self._abspath(path)) return os.path.exists(self._abspath(path))
def open(self, path, mode): def open(self, path, mode):
# TODO return a handle to the path. this should work as a context manager
os.makedirs(os.path.dirname(self._abspath(path)), exist_ok=True) os.makedirs(os.path.dirname(self._abspath(path)), exist_ok=True)
return open(self._abspath(path), mode) return open(self._abspath(path), mode)
def delete(self, path): def delete(self, path):
# TODO delete the file
# TODO prune empty directories that were components of $path
os.unlink(self._abspath(path)) os.unlink(self._abspath(path))
def getsize(self, path): def getsize(self, path):
@ -166,7 +162,6 @@ class MinioAdapter(StorageAdapter):
raise raise
def open(self, path, mode): def open(self, path, mode):
# TODO return a handle to the path. this should work as a context manager
if "r" in mode: if "r" in mode:
return S3ReadProxy(self.s3.get_object(Bucket=self.bucket, Key=os.path.join(self.prefix, path))["Body"]) return S3ReadProxy(self.s3.get_object(Bucket=self.bucket, Key=os.path.join(self.prefix, path))["Body"])
elif "w" in mode: elif "w" in mode:
@ -175,7 +170,6 @@ class MinioAdapter(StorageAdapter):
raise Exception("unknown file open mode") raise Exception("unknown file open mode")
def delete(self, path): def delete(self, path):
# TODO handle verification of return status
self.s3.delete_object(Bucket=self.bucket, Key=os.path.join(self.prefix, path)) self.s3.delete_object(Bucket=self.bucket, Key=os.path.join(self.prefix, path))
def getsize(self, path): def getsize(self, path):