Added thumbnails
Merge remote-tracking branch 'cover/thumbnails' into development # Conflicts: # cps/admin.py # cps/templates/layout.html # cps/ub.py # cps/web.py Update join for sqlalchemy 1.4
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import division, print_function, unicode_literals
|
||||
import atexit
|
||||
import os
|
||||
import sys
|
||||
import datetime
|
||||
@@ -441,6 +442,27 @@ class RemoteAuthToken(Base):
|
||||
return '<Token %r>' % self.id
|
||||
|
||||
|
||||
def filename(context):
|
||||
file_format = context.get_current_parameters()['format']
|
||||
if file_format == 'jpeg':
|
||||
return context.get_current_parameters()['uuid'] + '.jpg'
|
||||
else:
|
||||
return context.get_current_parameters()['uuid'] + '.' + file_format
|
||||
|
||||
|
||||
class Thumbnail(Base):
|
||||
__tablename__ = 'thumbnail'
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
book_id = Column(Integer)
|
||||
uuid = Column(String, default=lambda: str(uuid.uuid4()), unique=True)
|
||||
format = Column(String, default='jpeg')
|
||||
resolution = Column(SmallInteger, default=1)
|
||||
filename = Column(String, default=filename)
|
||||
generated_at = Column(DateTime, default=lambda: datetime.datetime.utcnow())
|
||||
expiration = Column(DateTime, default=lambda: datetime.datetime.utcnow() + datetime.timedelta(days=30))
|
||||
|
||||
|
||||
# Add missing tables during migration of database
|
||||
def add_missing_tables(engine, session):
|
||||
if not engine.dialect.has_table(engine.connect(), "book_read_link"):
|
||||
@@ -455,6 +477,8 @@ def add_missing_tables(engine, session):
|
||||
KoboStatistics.__table__.create(bind=engine)
|
||||
if not engine.dialect.has_table(engine.connect(), "archived_book"):
|
||||
ArchivedBook.__table__.create(bind=engine)
|
||||
if not engine.dialect.has_table(engine.connect(), "thumbnail"):
|
||||
Thumbnail.__table__.create(bind=engine)
|
||||
if not engine.dialect.has_table(engine.connect(), "registration"):
|
||||
Registration.__table__.create(bind=engine)
|
||||
with engine.connect() as conn:
|
||||
@@ -725,6 +749,16 @@ def init_db(app_db_path):
|
||||
sys.exit(3)
|
||||
|
||||
|
||||
def get_new_session_instance():
|
||||
new_engine = create_engine(u'sqlite:///{0}'.format(cli.settingspath), echo=False)
|
||||
new_session = scoped_session(sessionmaker())
|
||||
new_session.configure(bind=new_engine)
|
||||
|
||||
atexit.register(lambda: new_session.remove() if new_session else True)
|
||||
|
||||
return new_session
|
||||
|
||||
|
||||
def dispose():
|
||||
global session
|
||||
|
||||
|
||||
Reference in New Issue
Block a user