Commit 75c89c28 authored by OzzieIsaacs's avatar OzzieIsaacs

Bugfix for accessing config database

Title now displaed on every page
Title can be changed from within application
parent 4eee58c2
...@@ -5,13 +5,15 @@ from sqlalchemy import * ...@@ -5,13 +5,15 @@ from sqlalchemy import *
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import * from sqlalchemy.orm import *
import os import os
# import config
import re import re
import ast import ast
from ub import Config
global session # user defined sort function for calibre databases (Series, etc.)
def title_sort(title): def title_sort(title):
# calibre sort stuff
config=Config()
title_pat = re.compile(config.config_title_regex, re.IGNORECASE)
match = title_pat.search(title) match = title_pat.search(title)
if match: if match:
prep = match.group(1) prep = match.group(1)
...@@ -250,20 +252,24 @@ class Custom_Columns(Base): ...@@ -250,20 +252,24 @@ class Custom_Columns(Base):
display_dict = ast.literal_eval(self.display) display_dict = ast.literal_eval(self.display)
return display_dict return display_dict
def setup_db(config): def setup_db(config):
global session global session
# calibre sort stuff global cc_exceptions
title_pat = re.compile(config.config_title_regex, re.IGNORECASE) global cc_classes
global cc_ids
global books_custom_column_links
if config.config_calibre_dir is None: if config.config_calibre_dir is None:
return return
dbpath = os.path.join(config.config_calibre_dir, "metadata.db") dbpath = os.path.join(config.config_calibre_dir, "metadata.db")
engine = create_engine('sqlite:///{0}'.format(dbpath.encode('utf-8')), echo=False) engine = create_engine('sqlite:///{0}'.format(dbpath.encode('utf-8')), echo=False)
conn = engine.connect() conn = engine.connect()
conn.connection.create_function('title_sort', 1, title_sort) conn.connection.create_function('title_sort', 1, title_sort)
cc = conn.execute("SELECT id, datatype FROM custom_columns") cc = conn.execute("SELECT id, datatype FROM custom_columns")
cc_ids = [] cc_ids = []
cc_exceptions = ['datetime', 'int', 'comments', 'float', 'composite', 'series'] cc_exceptions = ['datetime', 'int', 'comments', 'float', 'composite', 'series']
books_custom_column_links = {} books_custom_column_links = {}
......
...@@ -255,7 +255,7 @@ def update_dir_stucture(book_id,calibrepath): ...@@ -255,7 +255,7 @@ def update_dir_stucture(book_id,calibrepath):
book.path = book.path.split(os.sep)[0] + os.sep + new_titledir book.path = book.path.split(os.sep)[0] + os.sep + new_titledir
if authordir != new_authordir: if authordir != new_authordir:
new_author_path = os.path.join(os.path.join(config.DB_ROOT, new_authordir), os.path.basename(path)) new_author_path = os.path.join(os.path.join(calibrepath, new_authordir), os.path.basename(path))
os.renames(path, new_author_path) os.renames(path, new_author_path)
book.path = new_authordir + os.sep + book.path.split(os.sep)[1] book.path = new_authordir + os.sep + book.path.split(os.sep)[1]
db.session.commit() db.session.commit()
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<th>{{_('Passwd')}}</th> <th>{{_('Passwd')}}</th>
</tr> </tr>
{% for user in content %} {% for user in content %}
{% if not user.role_anonymous() or config.ANON_BROWSE %} {% if not user.role_anonymous() or config.config_anonbrowse %}
<tr> <tr>
<td><a href="{{url_for('edit_user', user_id=user.id)}}">{{user.nickname}}</a></td> <td><a href="{{url_for('edit_user', user_id=user.id)}}">{{user.nickname}}</a></td>
<td>{{user.email}}</td> <td>{{user.email}}</td>
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
<h2>{{_('Configuration')}}</h2> <h2>{{_('Configuration')}}</h2>
<table class="table table-striped"> <table class="table table-striped">
<tr> <tr>
<th>{{_('Log File')}}</th> <th>{{_('Calibre DB dir')}}</th>
<th>{{_('Log Level')}}</th> <th>{{_('Log Level')}}</th>
<th>{{_('Port')}}</th> <th>{{_('Port')}}</th>
<th>{{_('Books per page')}}</th> <th>{{_('Books per page')}}</th>
...@@ -65,13 +65,13 @@ ...@@ -65,13 +65,13 @@
<th>{{_('Anonymous browsing')}}</th> <th>{{_('Anonymous browsing')}}</th>
</tr> </tr>
<tr> <tr>
<td>{{config.LOG_DIR}}</td> <td>{{config.config_calibre_dir}}</td>
<td>{{config.LOG_DIR}}</td> <td>{{config.config_log_level}}</td>
<td>{{config.PORT}}</td> <td>{{config.config_port}}</td>
<td>{{config.NEWEST_BOOKS}}</td> <td>{{config.config_books_per_page}}</td>
<td>{% if config.UPLOADING %}<span class="glyphicon glyphicon-ok"></span>{% else %}<span class="glyphicon glyphicon-remove"></span>{% endif %}</td> <td>{% if config.config_uploading %}<span class="glyphicon glyphicon-ok"></span>{% else %}<span class="glyphicon glyphicon-remove"></span>{% endif %}</td>
<td>{% if config.PUBLIC_REG %}<span class="glyphicon glyphicon-ok"></span>{% else %}<span class="glyphicon glyphicon-remove"></span>{% endif %}</td> <td>{% if config.config_public_reg %}<span class="glyphicon glyphicon-ok"></span>{% else %}<span class="glyphicon glyphicon-remove"></span>{% endif %}</td>
<td>{% if config.ANON_BROWSE %}<span class="glyphicon glyphicon-ok"></span>{% else %}<span class="glyphicon glyphicon-remove"></span>{% endif %}</td> <td>{% if config.config_anonbrowse %}<span class="glyphicon glyphicon-ok"></span>{% else %}<span class="glyphicon glyphicon-remove"></span>{% endif %}</td>
</table> </table>
<div class="btn btn-default"><a href="{{url_for('configuration')}}">{{_('Configuration')}}</a></div> <div class="btn btn-default"><a href="{{url_for('configuration')}}">{{_('Configuration')}}</a></div>
<h2>{{_('Administration')}}</h2> <h2>{{_('Administration')}}</h2>
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="config_port">{{_('Server Port')}}</label> <label for="config_port">{{_('Server Port')}}</label>
<input type="text" class="form-control" name="config_port" id="port" value="{% if content.config_port != None %}{{ content.config_port }}{% endif %}" autocomplete="off" required> <input type="text" class="form-control" name="config_port" id="config_port" value="{% if content.config_port != None %}{{ content.config_port }}{% endif %}" autocomplete="off" required>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="config_calibre_web_title">{{_('Title')}}</label> <label for="config_calibre_web_title">{{_('Title')}}</label>
......
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>calibre web | {{title}}</title> <title>{{instance}} | {{title}}</title>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
......
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
<!-- Full Screen --> <!-- Full Screen -->
<!--<script src="js/libs/screenfull.min.js"></script>--> <!--<script src="js/libs/screenfull.min.js"></script>-->
<script src="{{ url_for('static', filename='js/libs/screenfull.min.js') }}"></script> <script src="{{ url_for('static', filename='js/screenfull.min.js') }}"></script>
<!-- Render --> <!-- Render -->
<!--<script src="js/epub.min.js"></script>--> <!--<script src="js/epub.min.js"></script>-->
......
...@@ -7,7 +7,6 @@ from sqlalchemy.ext.declarative import declarative_base ...@@ -7,7 +7,6 @@ from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import * from sqlalchemy.orm import *
from flask_login import AnonymousUserMixin from flask_login import AnonymousUserMixin
import os import os
# import config
import traceback import traceback
from werkzeug.security import generate_password_hash from werkzeug.security import generate_password_hash
from flask_babel import gettext as _ from flask_babel import gettext as _
...@@ -98,6 +97,9 @@ class UserBase(): ...@@ -98,6 +97,9 @@ class UserBase():
class Config(): class Config():
def __init__(self): def __init__(self):
self.config_main_dir=os.path.join(os.path.normpath(os.path.dirname(
os.path.realpath(__file__)) + os.sep + ".." + os.sep))
self.db_configured=None
self.loadSettings() self.loadSettings()
def loadSettings(self): def loadSettings(self):
...@@ -112,6 +114,18 @@ class Config(): ...@@ -112,6 +114,18 @@ class Config():
self.config_uploading = data.config_uploading self.config_uploading = data.config_uploading
self.config_anonbrowse = data.config_anonbrowse self.config_anonbrowse = data.config_anonbrowse
self.config_public_reg = data.config_public_reg self.config_public_reg = data.config_public_reg
if self.config_calibre_dir is not None and (self.db_configured is None or self.db_configured is True):
self.db_configured=True
else:
self.db_configured = False
@property
def get_main_dir(self):
return self.config_main_dir
@property
def is_Calibre_Configured(self):
return self.db_configured
class User(UserBase,Base): class User(UserBase,Base):
...@@ -135,7 +149,7 @@ class User(UserBase,Base): ...@@ -135,7 +149,7 @@ class User(UserBase,Base):
class Anonymous(AnonymousUserMixin,UserBase): class Anonymous(AnonymousUserMixin,UserBase):
anon_browse = None # anon_browse = None
def __init__(self): def __init__(self):
self.loadSettings() self.loadSettings()
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment