Working again (basically)
parent
561d40f8ff
commit
a00d93a2d9
@ -1,2 +1,85 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# import logging
|
||||
# from logging.handlers import SMTPHandler, RotatingFileHandler
|
||||
# import os
|
||||
|
||||
from flask import Flask# , request, current_app
|
||||
from flask_login import LoginManager
|
||||
from flask_babel import Babel # , lazy_gettext as _l
|
||||
import cache_buster
|
||||
from reverseproxy import ReverseProxied
|
||||
import logging
|
||||
from logging.handlers import RotatingFileHandler
|
||||
from flask_principal import Principal
|
||||
# from flask_sqlalchemy import SQLAlchemy
|
||||
import os
|
||||
import ub
|
||||
from ub import Config, Settings
|
||||
import cPickle
|
||||
|
||||
|
||||
# Normal
|
||||
babel = Babel()
|
||||
lm = LoginManager()
|
||||
lm.login_view = 'web.login'
|
||||
lm.anonymous_user = ub.Anonymous
|
||||
|
||||
|
||||
|
||||
ub_session = ub.session
|
||||
# ub_session.start()
|
||||
config = Config()
|
||||
|
||||
|
||||
import db
|
||||
|
||||
with open(os.path.join(config.get_main_dir, 'cps/translations/iso639.pickle'), 'rb') as f:
|
||||
language_table = cPickle.load(f)
|
||||
|
||||
searched_ids = {}
|
||||
|
||||
|
||||
from worker import WorkerThread
|
||||
|
||||
global_WorkerThread = WorkerThread()
|
||||
|
||||
from server import server
|
||||
Server = server()
|
||||
|
||||
|
||||
def create_app():
|
||||
app = Flask(__name__)
|
||||
app.wsgi_app = ReverseProxied(app.wsgi_app)
|
||||
cache_buster.init_cache_busting(app)
|
||||
|
||||
formatter = logging.Formatter(
|
||||
"[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s")
|
||||
try:
|
||||
file_handler = RotatingFileHandler(config.get_config_logfile(), maxBytes=50000, backupCount=2)
|
||||
except IOError:
|
||||
file_handler = RotatingFileHandler(os.path.join(config.get_main_dir, "calibre-web.log"),
|
||||
maxBytes=50000, backupCount=2)
|
||||
# ToDo: reset logfile value in config class
|
||||
file_handler.setFormatter(formatter)
|
||||
app.logger.addHandler(file_handler)
|
||||
app.logger.setLevel(config.config_log_level)
|
||||
|
||||
app.logger.info('Starting Calibre Web...')
|
||||
logging.getLogger("book_formats").addHandler(file_handler)
|
||||
logging.getLogger("book_formats").setLevel(config.config_log_level)
|
||||
Principal(app)
|
||||
lm.init_app(app)
|
||||
babel.init_app(app)
|
||||
app.secret_key = os.getenv('SECRET_KEY', 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT')
|
||||
Server.init_app(app)
|
||||
db.setup_db()
|
||||
global_WorkerThread.start()
|
||||
|
||||
# app.config.from_object(config_class)
|
||||
# db.init_app(app)
|
||||
# login.init_app(app)
|
||||
|
||||
|
||||
return app
|
||||
|
@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web)
|
||||
# Copyright (C) 2018-2019 OzzieIsaacs, cervinko, jkrehm, bodybybuddha, ok11,
|
||||
# andy29485, idalin, Kyosfonica, wuqi, Kennyl, lemmsh,
|
||||
# falgh1, grunjol, csitko, ytils, xybydy, trasba, vrabe,
|
||||
# ruben-herold, marblepebble, JackED42, SiphonSquirrel,
|
||||
# apetresc, nanu-c, mutschler
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from math import ceil
|
||||
|
||||
# simple pagination for the feed
|
||||
class Pagination(object):
|
||||
def __init__(self, page, per_page, total_count):
|
||||
self.page = int(page)
|
||||
self.per_page = int(per_page)
|
||||
self.total_count = int(total_count)
|
||||
|
||||
@property
|
||||
def next_offset(self):
|
||||
return int(self.page * self.per_page)
|
||||
|
||||
@property
|
||||
def previous_offset(self):
|
||||
return int((self.page - 2) * self.per_page)
|
||||
|
||||
@property
|
||||
def last_offset(self):
|
||||
last = int(self.total_count) - int(self.per_page)
|
||||
if last < 0:
|
||||
last = 0
|
||||
return int(last)
|
||||
|
||||
@property
|
||||
def pages(self):
|
||||
return int(ceil(self.total_count / float(self.per_page)))
|
||||
|
||||
@property
|
||||
def has_prev(self):
|
||||
return self.page > 1
|
||||
|
||||
@property
|
||||
def has_next(self):
|
||||
return self.page < self.pages
|
||||
|
||||
# right_edge: last right_edges count of all pages are shown as number, means, if 10 pages are paginated -> 9,10 shwn
|
||||
# left_edge: first left_edges count of all pages are shown as number -> 1,2 shwn
|
||||
# left_current: left_current count below current page are shown as number, means if current page 5 -> 3,4 shwn
|
||||
# left_current: right_current count above current page are shown as number, means if current page 5 -> 6,7 shwn
|
||||
def iter_pages(self, left_edge=2, left_current=2,
|
||||
right_current=4, right_edge=2):
|
||||
last = 0
|
||||
left_current = self.page - left_current - 1
|
||||
right_current = self.page + right_current + 1
|
||||
right_edge = self.pages - right_edge
|
||||
for num in range(1, (self.pages + 1)):
|
||||
if num <= left_edge or (left_current < num < right_current) or num > right_edge:
|
||||
if last + 1 != num:
|
||||
yield None
|
||||
yield num
|
||||
last = num
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue