Browse Source

fix status

master
dave 1 year ago
parent
commit
bec8013365
2 changed files with 10 additions and 7 deletions
  1. +3
    -6
      photoapp/daemon.py
  2. +7
    -1
      photoapp/dbutils.py

+ 3
- 6
photoapp/daemon.py View File

@@ -9,7 +9,7 @@ from photoapp.types import Photo, PhotoSet, Tag, TagItem, PhotoStatus, User
from photoapp.dbsession import DatabaseSession
from photoapp.common import pwhash
from photoapp.api import PhotosApi, LibraryManager
from photoapp.dbutils import SAEnginePlugin, SATool, db, get_db_engine, driver_statement
from photoapp.dbutils import SAEnginePlugin, SATool, db, get_db_engine, date_format
from photoapp.utils import mime2ext, auth, require_auth, photoset_auth_filter, slugify
from photoapp.storage import uri_to_storage
from jinja2 import Environment, FileSystemLoader, select_autoescape
@@ -97,8 +97,8 @@ class PhotosWeb(object):
/stats - show server statistics
"""
images = photoset_auth_filter(db.query(func.count(PhotoSet.uuid),
func.strftime('%Y', PhotoSet.date).label('year'),
func.strftime('%m', PhotoSet.date).label('month'))). \
date_format('%Y', PhotoSet.date).label('year'),
date_format('%m', PhotoSet.date).label('month'))). \
group_by('year', 'month').order_by(desc('year'), desc('month')).all()
tsize = photoset_auth_filter(db.query(func.sum(Photo.size)).join(PhotoSet)).scalar() # pragma: manual auth
yield self.render("monthly.html", images=images, tsize=tsize)
@@ -219,9 +219,6 @@ class DateView(object):
images=[i for i in images], date=dt)
return

date_format = driver_statement({"sqlite": lambda date_format, value: func.strftime(date_format, value),
"mysql": lambda date_format, value: func.date_format(value, date_format)})

images = photoset_auth_filter(db.query(
func.count(PhotoSet.id),
date_format('%Y', PhotoSet.date).label('year'),


+ 7
- 1
photoapp/dbutils.py View File

@@ -4,7 +4,7 @@ from cherrypy.process import plugins
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.pool import NullPool
from sqlalchemy.orm import sessionmaker
from sqlalchemy import func

Base = declarative_base()

@@ -56,6 +56,12 @@ def driver_statement(statements):
raise Exception(f"Statement not supported for driver {driver}")


def date_format(date_format, value):
stmt = driver_statement({"sqlite": lambda date_format, value: func.strftime(date_format, value),
"mysql": lambda date_format, value: func.date_format(value, date_format)})
return stmt(date_format, value)


class DbAlias(object):
"""
This provides a shorter alias for the cherrypy.request.db object, which is a database session created bound to the


Loading…
Cancel
Save