Code cosmetics bugfix error message on failed emails refactored language name generation
This commit is contained in:
parent
34abf95fb2
commit
d414bf3263
|
@ -390,7 +390,7 @@ function rarMakeDecodeTables(BitLength, offset, dec, size) {
|
||||||
for (I = 1; I < 16; ++I) {
|
for (I = 1; I < 16; ++I) {
|
||||||
N = 2 * (N + LenCount[I]);
|
N = 2 * (N + LenCount[I]);
|
||||||
M = (N << (15 - I));
|
M = (N << (15 - I));
|
||||||
if (M > 0xFFFF){
|
if (M > 0xFFFF) {
|
||||||
M = 0xFFFF;
|
M = 0xFFFF;
|
||||||
}
|
}
|
||||||
DecodeLen[I] = M;
|
DecodeLen[I] = M;
|
||||||
|
@ -419,6 +419,8 @@ var lastLength = 0;
|
||||||
function Unpack20(bstream) { //, Solid) {
|
function Unpack20(bstream) { //, Solid) {
|
||||||
var destUnpSize = rBuffer.data.length;
|
var destUnpSize = rBuffer.data.length;
|
||||||
var oldDistPtr = 0;
|
var oldDistPtr = 0;
|
||||||
|
var Length;
|
||||||
|
var Distance;
|
||||||
rarReadTables20(bstream);
|
rarReadTables20(bstream);
|
||||||
while (destUnpSize > rBuffer.ptr) {
|
while (destUnpSize > rBuffer.ptr) {
|
||||||
var num = rarDecodeNumber(bstream, LD);
|
var num = rarDecodeNumber(bstream, LD);
|
||||||
|
@ -428,12 +430,12 @@ function Unpack20(bstream) { //, Solid) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (num > 269) {
|
if (num > 269) {
|
||||||
var Length = rLDecode[num -= 270] + 3;
|
Length = rLDecode[num -= 270] + 3;
|
||||||
if ((Bits = rLBits[num]) > 0) {
|
if ((Bits = rLBits[num]) > 0) {
|
||||||
Length += bstream.readBits(Bits);
|
Length += bstream.readBits(Bits);
|
||||||
}
|
}
|
||||||
var DistNumber = rarDecodeNumber(bstream, DD);
|
var DistNumber = rarDecodeNumber(bstream, DD);
|
||||||
var Distance = rDDecode[DistNumber] + 1;
|
Distance = rDDecode[DistNumber] + 1;
|
||||||
if ((Bits = rDBits[DistNumber]) > 0) {
|
if ((Bits = rDBits[DistNumber]) > 0) {
|
||||||
Distance += bstream.readBits(Bits);
|
Distance += bstream.readBits(Bits);
|
||||||
}
|
}
|
||||||
|
@ -459,16 +461,16 @@ function Unpack20(bstream) { //, Solid) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (num < 261) {
|
if (num < 261) {
|
||||||
var Distance = rOldDist[(oldDistPtr - (num - 256)) & 3];
|
Distance = rOldDist[(oldDistPtr - (num - 256)) & 3];
|
||||||
var LengthNumber = rarDecodeNumber(bstream, RD);
|
var LengthNumber = rarDecodeNumber(bstream, RD);
|
||||||
var Length = rLDecode[LengthNumber] +2;
|
Length = rLDecode[LengthNumber] + 2;
|
||||||
if ((Bits = rLBits[LengthNumber]) > 0) {
|
if ((Bits = rLBits[LengthNumber]) > 0) {
|
||||||
Length += bstream.readBits(Bits);
|
Length += bstream.readBits(Bits);
|
||||||
}
|
}
|
||||||
if (Distance >= 0x101) {
|
if (Distance >= 0x101) {
|
||||||
Length++;
|
Length++;
|
||||||
if (Distance >= 0x2000) {
|
if (Distance >= 0x2000) {
|
||||||
Length++
|
Length++;
|
||||||
if (Distance >= 0x40000) Length++;
|
if (Distance >= 0x40000) Length++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -488,7 +490,7 @@ function Unpack20(bstream) { //, Solid) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rarUpdateProgress()
|
rarUpdateProgress();
|
||||||
}
|
}
|
||||||
|
|
||||||
function rarUpdateProgress() {
|
function rarUpdateProgress() {
|
||||||
|
@ -511,20 +513,23 @@ function rarReadTables20(bstream) {
|
||||||
var BitLength = new Array(rBC20);
|
var BitLength = new Array(rBC20);
|
||||||
var Table = new Array(rMC20 * 4);
|
var Table = new Array(rMC20 * 4);
|
||||||
var TableSize, N, I;
|
var TableSize, N, I;
|
||||||
var AudioBlock = bstream.readBits(1);
|
bstream.readBits(1);
|
||||||
if (!bstream.readBits(1))
|
if (!bstream.readBits(1)) {
|
||||||
for (var i = UnpOldTable20.length; i--;) UnpOldTable20[i] = 0;
|
var i;
|
||||||
|
for (i = UnpOldTable20.length; i--;) UnpOldTable20[i] = 0;
|
||||||
|
}
|
||||||
TableSize = rNC20 + rDC20 + rRC20;
|
TableSize = rNC20 + rDC20 + rRC20;
|
||||||
for (var I = 0; I < rBC20; I++)
|
for (I = 0; I < rBC20; I++) {
|
||||||
BitLength[I] = bstream.readBits(4);
|
BitLength[I] = bstream.readBits(4);
|
||||||
|
}
|
||||||
rarMakeDecodeTables(BitLength, 0, BD, rBC20);
|
rarMakeDecodeTables(BitLength, 0, BD, rBC20);
|
||||||
I = 0;
|
I = 0;
|
||||||
while (I < TableSize) {
|
while (I < TableSize) {
|
||||||
var num = rarDecodeNumber(bstream, BD);
|
var num = rarDecodeNumber(bstream, BD);
|
||||||
if (num < 16) {
|
if (num < 16) {
|
||||||
Table[I] = num + UnpOldTable20[I] & 0xf;
|
Table[I] = num + UnpOldTable20[I] & 0xf;
|
||||||
I++;
|
I++;
|
||||||
} else if(num === 16) {
|
} else if (num === 16) {
|
||||||
N = bstream.readBits(2) + 3;
|
N = bstream.readBits(2) + 3;
|
||||||
while (N-- > 0 && I < TableSize) {
|
while (N-- > 0 && I < TableSize) {
|
||||||
Table[I] = Table[I - 1];
|
Table[I] = Table[I - 1];
|
||||||
|
@ -544,7 +549,7 @@ function rarReadTables20(bstream) {
|
||||||
rarMakeDecodeTables(Table, 0, LD, rNC20);
|
rarMakeDecodeTables(Table, 0, LD, rNC20);
|
||||||
rarMakeDecodeTables(Table, rNC20, DD, rDC20);
|
rarMakeDecodeTables(Table, rNC20, DD, rDC20);
|
||||||
rarMakeDecodeTables(Table, rNC20 + rDC20, RD, rRC20);
|
rarMakeDecodeTables(Table, rNC20 + rDC20, RD, rRC20);
|
||||||
for (var i = UnpOldTable20.length; i--;) UnpOldTable20[i] = Table[i];
|
for (i = UnpOldTable20.length; i--;) UnpOldTable20[i] = Table[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -554,9 +559,9 @@ function Unpack29(bstream, Solid) {
|
||||||
var DDecode = new Array(rDC);
|
var DDecode = new Array(rDC);
|
||||||
var DBits = new Array(rDC);
|
var DBits = new Array(rDC);
|
||||||
|
|
||||||
var Dist=0,BitLength=0,Slot=0;
|
var Dist = 0, BitLength = 0, Slot = 0;
|
||||||
|
var I;
|
||||||
for (var I = 0; I < rDBitLengthCounts.length; I++,BitLength++) {
|
for (I = 0; I < rDBitLengthCounts.length; I++,BitLength++) {
|
||||||
for (var J = 0; J < rDBitLengthCounts[I]; J++,Slot++,Dist+=(1<<BitLength)) {
|
for (var J = 0; J < rDBitLengthCounts[I]; J++,Slot++,Dist+=(1<<BitLength)) {
|
||||||
DDecode[Slot]=Dist;
|
DDecode[Slot]=Dist;
|
||||||
DBits[Slot]=BitLength;
|
DBits[Slot]=BitLength;
|
||||||
|
@ -570,8 +575,8 @@ function Unpack29(bstream, Solid) {
|
||||||
|
|
||||||
lastDist = 0;
|
lastDist = 0;
|
||||||
lastLength = 0;
|
lastLength = 0;
|
||||||
|
var i;
|
||||||
for (var i = UnpOldTable.length; i--;) UnpOldTable[i] = 0;
|
for (i = UnpOldTable.length; i--;) UnpOldTable[i] = 0;
|
||||||
|
|
||||||
// read in Huffman tables
|
// read in Huffman tables
|
||||||
RarReadTables(bstream);
|
RarReadTables(bstream);
|
||||||
|
@ -693,7 +698,7 @@ function RarReadVMCode(bstream) {
|
||||||
var Length = (FirstByte & 7) + 1;
|
var Length = (FirstByte & 7) + 1;
|
||||||
if (Length === 7) {
|
if (Length === 7) {
|
||||||
Length = bstream.readBits(8) + 7;
|
Length = bstream.readBits(8) + 7;
|
||||||
} else if(Length === 8) {
|
} else if (Length === 8) {
|
||||||
Length = bstream.readBits(16);
|
Length = bstream.readBits(16);
|
||||||
}
|
}
|
||||||
var vmCode = [];
|
var vmCode = [];
|
||||||
|
@ -725,9 +730,9 @@ function RarInsertOldDist(distance) {
|
||||||
//this is the real function, the other one is for debugging
|
//this is the real function, the other one is for debugging
|
||||||
function rarCopyString(length, distance) {
|
function rarCopyString(length, distance) {
|
||||||
var destPtr = rBuffer.ptr - distance;
|
var destPtr = rBuffer.ptr - distance;
|
||||||
if(destPtr < 0){
|
if (destPtr < 0) {
|
||||||
var l = rOldBuffers.length;
|
var l = rOldBuffers.length;
|
||||||
while(destPtr < 0){
|
while (destPtr < 0) {
|
||||||
destPtr = rOldBuffers[--l].data.length + destPtr;
|
destPtr = rOldBuffers[--l].data.length + destPtr;
|
||||||
}
|
}
|
||||||
//TODO: lets hope that it never needs to read beyond file boundaries
|
//TODO: lets hope that it never needs to read beyond file boundaries
|
||||||
|
@ -864,7 +869,7 @@ var unrar = function(arrayBuffer) {
|
||||||
return aname > bname ? 1 : -1;
|
return aname > bname ? 1 : -1;
|
||||||
});
|
});
|
||||||
|
|
||||||
info(localFiles.map(function(a){return a.filename}).join(', '));
|
info(localFiles.map(function(a) {return a.filename}).join(', '));
|
||||||
for (var i = 0; i < localFiles.length; ++i) {
|
for (var i = 0; i < localFiles.length; ++i) {
|
||||||
var localfile = localFiles[i];
|
var localfile = localFiles[i];
|
||||||
|
|
||||||
|
@ -883,8 +888,7 @@ var unrar = function(arrayBuffer) {
|
||||||
|
|
||||||
postProgress();
|
postProgress();
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
err("Invalid RAR file");
|
err("Invalid RAR file");
|
||||||
}
|
}
|
||||||
postMessage(new bitjs.archive.UnarchiveFinishEvent());
|
postMessage(new bitjs.archive.UnarchiveFinishEvent());
|
||||||
|
|
|
@ -8,11 +8,34 @@
|
||||||
{% else %}
|
{% else %}
|
||||||
<h2>{{entries|length}} {{_('Results for:')}} {{searchterm}}</h2>
|
<h2>{{entries|length}} {{_('Results for:')}} {{searchterm}}</h2>
|
||||||
{%endif%}
|
{%endif%}
|
||||||
{% if g.user.is_authenticated %}
|
{% if g.user.is_authenticated %}
|
||||||
<!--a href="{{ url_for('read_books') }}" class="btn btn-primary">{{ _('Search result to shelf') }} </a-->
|
{% if g.user.shelf.all() or g.public_shelfes %}
|
||||||
|
<div id="shelf-actions" class="btn-toolbar" role="toolbar">
|
||||||
|
<div class="btn-group" role="group" aria-label="Add to shelves">
|
||||||
|
<button id="add-to-shelf" type="button" class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||||
|
<span class="glyphicon glyphicon-list"></span> {{_('Add to shelf')}}
|
||||||
|
<span class="caret"></span>
|
||||||
|
</button>
|
||||||
|
<ul id="add-to-shelves" class="dropdown-menu" aria-labelledby="add-to-shelf">
|
||||||
|
{% for shelf in g.user.shelf %}
|
||||||
|
{% if shelf.is_public != 1 %}
|
||||||
|
<li>
|
||||||
|
<a href="{{ url_for('search_to_shelf', shelf_id=shelf.id) }}"> {{shelf.name}}</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% for shelf in g.public_shelfes %}
|
||||||
|
<li>
|
||||||
|
<a href="{{ url_for('search_to_shelf', shelf_id=shelf.id) }}">{{shelf.name}}</a>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
||||||
{% for entry in entries %}
|
{% for entry in entries %}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
{% if g.user.is_authenticated %}
|
{% if g.user.is_authenticated %}
|
||||||
{% if (g.user.role_edit_shelfs() and shelf.is_public ) or not shelf.is_public %}
|
{% if (g.user.role_edit_shelfs() and shelf.is_public ) or not shelf.is_public %}
|
||||||
<div data-toggle="modal" data-target="#DeleteShelfDialog" class="btn btn-danger">{{ _('Delete this Shelf') }} </div>
|
<div data-toggle="modal" data-target="#DeleteShelfDialog" class="btn btn-danger">{{ _('Delete this Shelf') }} </div>
|
||||||
<a href="{{ url_for('edit_shelf', shelf_id=shelf.id) }}" class="btn btn-primary">{{ _('Edit Shelf name') }} </a>
|
<a href="{{ url_for('edit_shelf', shelf_id=shelf.id) }}" class="btn btn-primary">{{ _('Edit Shelf') }} </a>
|
||||||
<a href="{{ url_for('order_shelf', shelf_id=shelf.id) }}" class="btn btn-primary">{{ _('Change order') }} </a>
|
<a href="{{ url_for('order_shelf', shelf_id=shelf.id) }}" class="btn btn-primary">{{ _('Change order') }} </a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -1515,8 +1515,8 @@ msgid "Delete this Shelf"
|
||||||
msgstr "Lösche dieses Bücherregal"
|
msgstr "Lösche dieses Bücherregal"
|
||||||
|
|
||||||
#: cps/templates/shelf.html:8
|
#: cps/templates/shelf.html:8
|
||||||
msgid "Edit Shelf name"
|
msgid "Edit Shelf"
|
||||||
msgstr "Bücherregal umbenennen"
|
msgstr "Bücherregal editieren"
|
||||||
|
|
||||||
#: cps/templates/shelf.html:9 cps/templates/shelf_order.html:11
|
#: cps/templates/shelf.html:9 cps/templates/shelf_order.html:11
|
||||||
msgid "Change order"
|
msgid "Change order"
|
||||||
|
|
10
cps/ub.py
10
cps/ub.py
|
@ -46,9 +46,8 @@ DEFAULT_PASS = "admin123"
|
||||||
DEFAULT_PORT = int(os.environ.get("CALIBRE_PORT", 8083))
|
DEFAULT_PORT = int(os.environ.get("CALIBRE_PORT", 8083))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class UserBase:
|
class UserBase:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_authenticated(self):
|
def is_authenticated(self):
|
||||||
return True
|
return True
|
||||||
|
@ -170,7 +169,7 @@ class User(UserBase, Base):
|
||||||
theme = Column(Integer, default=0)
|
theme = Column(Integer, default=0)
|
||||||
|
|
||||||
|
|
||||||
# Class for anonymous user is derived from User base and complets overrides methods and properties for the
|
# Class for anonymous user is derived from User base and completly overrides methods and properties for the
|
||||||
# anonymous user
|
# anonymous user
|
||||||
class Anonymous(AnonymousUserMixin, UserBase):
|
class Anonymous(AnonymousUserMixin, UserBase):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -204,7 +203,7 @@ class Anonymous(AnonymousUserMixin, UserBase):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
# Baseclass representing Shelfs in calibre-web inapp.db
|
# Baseclass representing Shelfs in calibre-web in app.db
|
||||||
class Shelf(Base):
|
class Shelf(Base):
|
||||||
__tablename__ = 'shelf'
|
__tablename__ = 'shelf'
|
||||||
|
|
||||||
|
@ -774,5 +773,6 @@ else:
|
||||||
migrate_Database()
|
migrate_Database()
|
||||||
clean_database()
|
clean_database()
|
||||||
|
|
||||||
# Generate global Settings Object accecable from every file
|
# Generate global Settings Object accessible from every file
|
||||||
config = Config()
|
config = Config()
|
||||||
|
searched_ids = {}
|
||||||
|
|
157
cps/web.py
157
cps/web.py
|
@ -47,7 +47,7 @@ from flask_principal import Principal
|
||||||
from flask_principal import __version__ as flask_principalVersion
|
from flask_principal import __version__ as flask_principalVersion
|
||||||
from flask_babel import Babel
|
from flask_babel import Babel
|
||||||
from flask_babel import gettext as _
|
from flask_babel import gettext as _
|
||||||
import pytz
|
|
||||||
import requests
|
import requests
|
||||||
from werkzeug.security import generate_password_hash, check_password_hash
|
from werkzeug.security import generate_password_hash, check_password_hash
|
||||||
from werkzeug.datastructures import Headers
|
from werkzeug.datastructures import Headers
|
||||||
|
@ -184,14 +184,6 @@ lm.anonymous_user = ub.Anonymous
|
||||||
app.secret_key = os.getenv('SECRET_KEY', 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT')
|
app.secret_key = os.getenv('SECRET_KEY', 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT')
|
||||||
db.setup_db()
|
db.setup_db()
|
||||||
|
|
||||||
'''if config.config_log_level == logging.DEBUG:
|
|
||||||
logging.getLogger("sqlalchemy.engine").addHandler(file_handler)
|
|
||||||
logging.getLogger("sqlalchemy.engine").setLevel(logging.INFO)
|
|
||||||
logging.getLogger("sqlalchemy.pool").addHandler(file_handler)
|
|
||||||
logging.getLogger("sqlalchemy.pool").setLevel(config.config_log_level)
|
|
||||||
logging.getLogger("sqlalchemy.orm").addHandler(file_handler)
|
|
||||||
logging.getLogger("sqlalchemy.orm").setLevel(config.config_log_level)'''
|
|
||||||
|
|
||||||
|
|
||||||
def is_gdrive_ready():
|
def is_gdrive_ready():
|
||||||
return os.path.exists(os.path.join(config.get_main_dir,'settings.yaml')) and \
|
return os.path.exists(os.path.join(config.get_main_dir,'settings.yaml')) and \
|
||||||
|
@ -462,7 +454,7 @@ def edit_required(f):
|
||||||
return inner
|
return inner
|
||||||
|
|
||||||
|
|
||||||
# Language and content filters
|
# Language and content filters for displaying in the UI
|
||||||
def common_filters():
|
def common_filters():
|
||||||
if current_user.filter_language() != "all":
|
if current_user.filter_language() != "all":
|
||||||
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
||||||
|
@ -473,6 +465,19 @@ def common_filters():
|
||||||
return and_(lang_filter, ~content_rating_filter)
|
return and_(lang_filter, ~content_rating_filter)
|
||||||
|
|
||||||
|
|
||||||
|
# Creates for all stored languages a translated speaking name in the array for the UI
|
||||||
|
def speaking_language(languages = None):
|
||||||
|
if not languages:
|
||||||
|
languages = db.session.query(db.Languages).all()
|
||||||
|
for lang in languages:
|
||||||
|
try:
|
||||||
|
cur_l = LC.parse(lang.lang_code)
|
||||||
|
lang.name = cur_l.get_language_name(get_locale())
|
||||||
|
except Exception:
|
||||||
|
lang.name = _(isoLanguages.get(part3=lang.lang_code).name)
|
||||||
|
return languages
|
||||||
|
|
||||||
|
|
||||||
# Fill indexpage with all requested data from database
|
# Fill indexpage with all requested data from database
|
||||||
def fill_indexpage(page, database, db_filter, order, *join):
|
def fill_indexpage(page, database, db_filter, order, *join):
|
||||||
if current_user.show_detail_random():
|
if current_user.show_detail_random():
|
||||||
|
@ -489,6 +494,8 @@ def fill_indexpage(page, database, db_filter, order, *join):
|
||||||
return entries, random, pagination
|
return entries, random, pagination
|
||||||
|
|
||||||
|
|
||||||
|
# Modifies different Database objects, first check if elements have to be added to database, than check
|
||||||
|
# if elements have to be deleted, because they are no longer used
|
||||||
def modify_database_object(input_elements, db_book_object, db_object, db_session, db_type):
|
def modify_database_object(input_elements, db_book_object, db_object, db_session, db_type):
|
||||||
input_elements = [x for x in input_elements if x != '']
|
input_elements = [x for x in input_elements if x != '']
|
||||||
# we have all input element (authors, series, tags) names now
|
# we have all input element (authors, series, tags) names now
|
||||||
|
@ -557,7 +564,7 @@ def modify_database_object(input_elements, db_book_object, db_object, db_session
|
||||||
db_book_object.append(new_element)
|
db_book_object.append(new_element)
|
||||||
|
|
||||||
|
|
||||||
# read search results from calibre-database and return it
|
# read search results from calibre-database and return it (function is used for feed and simple search
|
||||||
def get_search_results(term):
|
def get_search_results(term):
|
||||||
q = list()
|
q = list()
|
||||||
authorterms = re.split("[, ]+", term)
|
authorterms = re.split("[, ]+", term)
|
||||||
|
@ -581,7 +588,6 @@ def feed_search(term):
|
||||||
entriescount = len(entries) if len(entries) > 0 else 1
|
entriescount = len(entries) if len(entries) > 0 else 1
|
||||||
pagination = Pagination(1, entriescount, entriescount)
|
pagination = Pagination(1, entriescount, entriescount)
|
||||||
return render_xml_template('feed.xml', searchterm=term, entries=entries, pagination=pagination)
|
return render_xml_template('feed.xml', searchterm=term, entries=entries, pagination=pagination)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return render_xml_template('feed.xml', searchterm="")
|
return render_xml_template('feed.xml', searchterm="")
|
||||||
|
|
||||||
|
@ -907,13 +913,7 @@ def get_tags_json():
|
||||||
def get_languages_json():
|
def get_languages_json():
|
||||||
if request.method == "GET":
|
if request.method == "GET":
|
||||||
query = request.args.get('q').lower()
|
query = request.args.get('q').lower()
|
||||||
languages = db.session.query(db.Languages).all()
|
languages = speaking_language()
|
||||||
for lang in languages:
|
|
||||||
try:
|
|
||||||
cur_l = LC.parse(lang.lang_code)
|
|
||||||
lang.name = cur_l.get_language_name(get_locale())
|
|
||||||
except Exception:
|
|
||||||
lang.name = _(isoLanguages.get(part3=lang.lang_code).name)
|
|
||||||
entries = [s for s in languages if query in s.name.lower()]
|
entries = [s for s in languages if query in s.name.lower()]
|
||||||
json_dumps = json.dumps([dict(name=r.name) for r in entries])
|
json_dumps = json.dumps([dict(name=r.name) for r in entries])
|
||||||
return json_dumps
|
return json_dumps
|
||||||
|
@ -1212,13 +1212,7 @@ def series(book_id, page):
|
||||||
def language_overview():
|
def language_overview():
|
||||||
if current_user.show_language():
|
if current_user.show_language():
|
||||||
if current_user.filter_language() == u"all":
|
if current_user.filter_language() == u"all":
|
||||||
languages = db.session.query(db.Languages).all()
|
languages = speaking_language()
|
||||||
for lang in languages:
|
|
||||||
try:
|
|
||||||
cur_l = LC.parse(lang.lang_code)
|
|
||||||
lang.name = cur_l.get_language_name(get_locale())
|
|
||||||
except Exception:
|
|
||||||
lang.name = _(isoLanguages.get(part3=lang.lang_code).name)
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
cur_l = LC.parse(current_user.filter_language())
|
cur_l = LC.parse(current_user.filter_language())
|
||||||
|
@ -1521,8 +1515,7 @@ def google_drive_callback():
|
||||||
f.write(credentials.to_json())
|
f.write(credentials.to_json())
|
||||||
except ValueError as error:
|
except ValueError as error:
|
||||||
app.logger.error(error)
|
app.logger.error(error)
|
||||||
finally:
|
return redirect(url_for('configuration'))
|
||||||
return redirect(url_for('configuration'))
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/gdrive/watch/subscribe")
|
@app.route("/gdrive/watch/subscribe")
|
||||||
|
@ -1730,12 +1723,8 @@ def advanced_search():
|
||||||
serie_names = db.session.query(db.Series).filter(db.Series.id.in_(include_series_inputs)).all()
|
serie_names = db.session.query(db.Series).filter(db.Series.id.in_(include_series_inputs)).all()
|
||||||
searchterm.extend(serie.name for serie in serie_names)
|
searchterm.extend(serie.name for serie in serie_names)
|
||||||
language_names = db.session.query(db.Languages).filter(db.Languages.id.in_(include_languages_inputs)).all()
|
language_names = db.session.query(db.Languages).filter(db.Languages.id.in_(include_languages_inputs)).all()
|
||||||
for lang in language_names:
|
if language_names:
|
||||||
try:
|
language_names = speaking_language(language_names)
|
||||||
cur_l = LC.parse(lang.lang_code)
|
|
||||||
lang.name = cur_l.get_language_name(get_locale())
|
|
||||||
except Exception:
|
|
||||||
lang.name = _(isoLanguages.get(part3=lang.lang_code).name)
|
|
||||||
searchterm.extend(language.name for language in language_names)
|
searchterm.extend(language.name for language in language_names)
|
||||||
if rating_high:
|
if rating_high:
|
||||||
searchterm.extend([_(u"Rating <= %s" % rating_high)])
|
searchterm.extend([_(u"Rating <= %s" % rating_high)])
|
||||||
|
@ -1794,22 +1783,19 @@ def advanced_search():
|
||||||
q = q.filter(getattr(db.Books, 'custom_column_'+str(c.id)).any(
|
q = q.filter(getattr(db.Books, 'custom_column_'+str(c.id)).any(
|
||||||
db.cc_classes[c.id].value.ilike("%" + custom_query + "%")))
|
db.cc_classes[c.id].value.ilike("%" + custom_query + "%")))
|
||||||
q = q.all()
|
q = q.all()
|
||||||
|
ids = list()
|
||||||
|
for element in q:
|
||||||
|
ids.append(element.id)
|
||||||
|
ub.searched_ids[current_user.id] = ids
|
||||||
return render_title_template('search.html', searchterm=searchterm,
|
return render_title_template('search.html', searchterm=searchterm,
|
||||||
entries=q, title=_(u"search"), page="search")
|
entries=q, title=_(u"search"), page="search")
|
||||||
# prepare data for search-form
|
# prepare data for search-form
|
||||||
tags = db.session.query(db.Tags).order_by(db.Tags.name).all()
|
tags = db.session.query(db.Tags).order_by(db.Tags.name).all()
|
||||||
series = db.session.query(db.Series).order_by(db.Series.name).all()
|
series = db.session.query(db.Series).order_by(db.Series.name).all()
|
||||||
if current_user.filter_language() == u"all":
|
if current_user.filter_language() == u"all":
|
||||||
languages = db.session.query(db.Languages).all()
|
languages = speaking_language()
|
||||||
for lang in languages:
|
|
||||||
try:
|
|
||||||
cur_l = LC.parse(lang.lang_code)
|
|
||||||
lang.name = cur_l.get_language_name(get_locale())
|
|
||||||
except Exception:
|
|
||||||
lang.name = _(isoLanguages.get(part3=lang.lang_code).name)
|
|
||||||
else:
|
else:
|
||||||
languages = None
|
languages = None
|
||||||
|
|
||||||
return render_title_template('search_form.html', tags=tags, languages=languages,
|
return render_title_template('search_form.html', tags=tags, languages=languages,
|
||||||
series=series, title=_(u"search"), cc=cc, page="advsearch")
|
series=series, title=_(u"search"), cc=cc, page="advsearch")
|
||||||
|
|
||||||
|
@ -2213,7 +2199,57 @@ def add_to_shelf(shelf_id, book_id):
|
||||||
return redirect(request.environ["HTTP_REFERER"])
|
return redirect(request.environ["HTTP_REFERER"])
|
||||||
return "", 204
|
return "", 204
|
||||||
|
|
||||||
|
@app.route("/shelf/massadd/<int:shelf_id>")
|
||||||
|
@login_required
|
||||||
|
def search_to_shelf(shelf_id):
|
||||||
|
shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.id == shelf_id).first()
|
||||||
|
if shelf is None:
|
||||||
|
app.logger.info("Invalid shelf specified")
|
||||||
|
return "Invalid shelf specified", 400
|
||||||
|
|
||||||
|
if not shelf.is_public and not shelf.user_id == int(current_user.id):
|
||||||
|
app.logger.info("Sorry you are not allowed to add a book to the the shelf: %s" % shelf.name)
|
||||||
|
return "Sorry you are not allowed to add a book to the the shelf: %s" % shelf.name, 403
|
||||||
|
|
||||||
|
if shelf.is_public and not current_user.role_edit_shelfs():
|
||||||
|
app.logger.info("User is not allowed to edit public shelves")
|
||||||
|
return "User is not allowed to edit public shelves", 403
|
||||||
|
|
||||||
|
if current_user.id in ub.searched_ids and ub.searched_ids[current_user.id]:
|
||||||
|
books_for_shelf = list()
|
||||||
|
books_in_shelf = ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == shelf_id).all()
|
||||||
|
if books_in_shelf:
|
||||||
|
book_ids = list()
|
||||||
|
for book_id in books_in_shelf:
|
||||||
|
book_ids.append(book_id.book_id)
|
||||||
|
for id in ub.searched_ids[current_user.id]:
|
||||||
|
if id not in book_ids:
|
||||||
|
books_for_shelf.append(id)
|
||||||
|
else:
|
||||||
|
books_for_shelf = ub.searched_ids[current_user.id]
|
||||||
|
|
||||||
|
if not books_for_shelf:
|
||||||
|
app.logger.info("Books are already part of the shelf: %s" % shelf.name)
|
||||||
|
flash(_(u"Books are already part of the shelf: %s" % shelf.name), category="error")
|
||||||
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
|
maxOrder = ub.session.query(func.max(ub.BookShelf.order)).filter(ub.BookShelf.shelf == shelf_id).first()
|
||||||
|
if maxOrder[0] is None:
|
||||||
|
maxOrder = 0
|
||||||
|
else:
|
||||||
|
maxOrder = maxOrder[0]
|
||||||
|
|
||||||
|
for book in books_for_shelf:
|
||||||
|
maxOrder = maxOrder + 1
|
||||||
|
ins = ub.BookShelf(shelf=shelf.id, book_id=book, order=maxOrder)
|
||||||
|
ub.session.add(ins)
|
||||||
|
ub.session.commit()
|
||||||
|
flash(_(u"Books have been added to shelf: %(sname)s", sname=shelf.name), category="success")
|
||||||
|
else:
|
||||||
|
flash(_(u"Could not add books to shelf: %(sname)s", sname=shelf.name), category="error")
|
||||||
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
|
|
||||||
@app.route("/shelf/remove/<int:shelf_id>/<int:book_id>")
|
@app.route("/shelf/remove/<int:shelf_id>/<int:book_id>")
|
||||||
@login_required
|
@login_required
|
||||||
def remove_from_shelf(shelf_id, book_id):
|
def remove_from_shelf(shelf_id, book_id):
|
||||||
|
@ -2397,13 +2433,7 @@ def order_shelf(shelf_id):
|
||||||
def profile():
|
def profile():
|
||||||
content = ub.session.query(ub.User).filter(ub.User.id == int(current_user.id)).first()
|
content = ub.session.query(ub.User).filter(ub.User.id == int(current_user.id)).first()
|
||||||
downloads = list()
|
downloads = list()
|
||||||
languages = db.session.query(db.Languages).all()
|
languages = speaking_language()
|
||||||
for lang in languages:
|
|
||||||
try:
|
|
||||||
cur_l = LC.parse(lang.lang_code)
|
|
||||||
lang.name = cur_l.get_language_name(get_locale())
|
|
||||||
except Exception:
|
|
||||||
lang.name = _(isoLanguages.get(part3=lang.lang_code).name)
|
|
||||||
translations = babel.list_translations() + [LC('en')]
|
translations = babel.list_translations() + [LC('en')]
|
||||||
for book in content.downloads:
|
for book in content.downloads:
|
||||||
downloadBook = db.session.query(db.Books).filter(db.Books.id == book.book_id).first()
|
downloadBook = db.session.query(db.Books).filter(db.Books.id == book.book_id).first()
|
||||||
|
@ -2769,13 +2799,7 @@ def configuration_helper(origin):
|
||||||
@admin_required
|
@admin_required
|
||||||
def new_user():
|
def new_user():
|
||||||
content = ub.User()
|
content = ub.User()
|
||||||
languages = db.session.query(db.Languages).all()
|
languages = speaking_language()
|
||||||
for lang in languages:
|
|
||||||
try:
|
|
||||||
cur_l = LC.parse(lang.lang_code)
|
|
||||||
lang.name = cur_l.get_language_name(get_locale())
|
|
||||||
except Exception:
|
|
||||||
lang.name = _(isoLanguages.get(part3=lang.lang_code).name)
|
|
||||||
translations = [LC('en')] + babel.list_translations()
|
translations = [LC('en')] + babel.list_translations()
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
to_save = request.form.to_dict()
|
to_save = request.form.to_dict()
|
||||||
|
@ -2880,13 +2904,7 @@ def edit_mailsettings():
|
||||||
def edit_user(user_id):
|
def edit_user(user_id):
|
||||||
content = ub.session.query(ub.User).filter(ub.User.id == int(user_id)).first() # type: ub.User
|
content = ub.session.query(ub.User).filter(ub.User.id == int(user_id)).first() # type: ub.User
|
||||||
downloads = list()
|
downloads = list()
|
||||||
languages = db.session.query(db.Languages).all()
|
languages = speaking_language()
|
||||||
for lang in languages:
|
|
||||||
try:
|
|
||||||
cur_l = LC.parse(lang.lang_code)
|
|
||||||
lang.name = cur_l.get_language_name(get_locale())
|
|
||||||
except Exception:
|
|
||||||
lang.name = _(isoLanguages.get(part3=lang.lang_code).name)
|
|
||||||
translations = babel.list_translations() + [LC('en')]
|
translations = babel.list_translations() + [LC('en')]
|
||||||
for book in content.downloads:
|
for book in content.downloads:
|
||||||
downloadBook = db.session.query(db.Books).filter(db.Books.id == book.book_id).first()
|
downloadBook = db.session.query(db.Books).filter(db.Books.id == book.book_id).first()
|
||||||
|
@ -3099,7 +3117,6 @@ def edit_book(book_id):
|
||||||
uploadText=_(u"File format %s added to %s" % (file_ext.upper(),book.title))
|
uploadText=_(u"File format %s added to %s" % (file_ext.upper(),book.title))
|
||||||
helper.global_WorkerThread.add_upload(current_user.nickname,
|
helper.global_WorkerThread.add_upload(current_user.nickname,
|
||||||
"<a href=\""+ url_for('show_book', book_id=book.id) +"\">"+ uploadText + "</a>")
|
"<a href=\""+ url_for('show_book', book_id=book.id) +"\">"+ uploadText + "</a>")
|
||||||
|
|
||||||
|
|
||||||
to_save = request.form.to_dict()
|
to_save = request.form.to_dict()
|
||||||
|
|
||||||
|
@ -3284,7 +3301,7 @@ def edit_book(book_id):
|
||||||
title=_(u"edit metadata"), page="editbook")
|
title=_(u"edit metadata"), page="editbook")
|
||||||
else:
|
else:
|
||||||
db.session.rollback()
|
db.session.rollback()
|
||||||
flash( error, category="error")
|
flash(error, category="error")
|
||||||
return render_title_template('book_edit.html', book=book, authors=author_names, cc=cc,
|
return render_title_template('book_edit.html', book=book, authors=author_names, cc=cc,
|
||||||
title=_(u"edit metadata"), page="editbook")
|
title=_(u"edit metadata"), page="editbook")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -3394,7 +3411,7 @@ def upload():
|
||||||
db_book.series.append(db_series)
|
db_book.series.append(db_series)
|
||||||
if db_language is not None:
|
if db_language is not None:
|
||||||
db_book.languages.append(db_language)
|
db_book.languages.append(db_language)
|
||||||
file_size = os.path.getsize(saved_filename)
|
file_size = os.path.getsize(saved_filename)
|
||||||
db_data = db.Data(db_book, meta.extension.upper()[1:], file_size, title_dir)
|
db_data = db.Data(db_book, meta.extension.upper()[1:], file_size, title_dir)
|
||||||
|
|
||||||
# handle tags
|
# handle tags
|
||||||
|
@ -3406,7 +3423,7 @@ def upload():
|
||||||
# flush content, get db_book.id available
|
# flush content, get db_book.id available
|
||||||
db_book.data.append(db_data)
|
db_book.data.append(db_data)
|
||||||
db.session.add(db_book)
|
db.session.add(db_book)
|
||||||
db.session.flush()
|
db.session.flush()
|
||||||
|
|
||||||
# add comment
|
# add comment
|
||||||
book_id = db_book.id
|
book_id = db_book.id
|
||||||
|
@ -3429,12 +3446,12 @@ def upload():
|
||||||
gdriveutils.updateGdriveCalibreFromLocal()
|
gdriveutils.updateGdriveCalibreFromLocal()
|
||||||
if error:
|
if error:
|
||||||
flash(error, category="error")
|
flash(error, category="error")
|
||||||
uploadText=_(u"File %s uploaded" % book.title)
|
uploadText=_(u"File %s uploaded" % book.title)
|
||||||
helper.global_WorkerThread.add_upload(current_user.nickname,
|
helper.global_WorkerThread.add_upload(current_user.nickname,
|
||||||
"<a href=\"" + url_for('show_book', book_id=book.id) + "\">" + uploadText + "</a>")
|
"<a href=\"" + url_for('show_book', book_id=book.id) + "\">" + uploadText + "</a>")
|
||||||
|
|
||||||
# create data for displaying display Full language name instead of iso639.part3language
|
# create data for displaying display Full language name instead of iso639.part3language
|
||||||
if db_language is not None:
|
if db_language is not None:
|
||||||
book.languages[0].language_name = _(meta.languages)
|
book.languages[0].language_name = _(meta.languages)
|
||||||
author_names = []
|
author_names = []
|
||||||
for author in db_book.authors:
|
for author in db_book.authors:
|
||||||
|
|
|
@ -205,7 +205,7 @@ class WorkerThread(threading.Thread):
|
||||||
self.UIqueue[self.current]['runtime'] = self._formatRuntime(
|
self.UIqueue[self.current]['runtime'] = self._formatRuntime(
|
||||||
datetime.now() - self.queue[self.current]['starttime'])
|
datetime.now() - self.queue[self.current]['starttime'])
|
||||||
return self.UIqueue
|
return self.UIqueue
|
||||||
|
|
||||||
def convert_mobi(self):
|
def convert_mobi(self):
|
||||||
# convert book, and upload in case of google drive
|
# convert book, and upload in case of google drive
|
||||||
self.queue[self.current]['status'] = STAT_STARTED
|
self.queue[self.current]['status'] = STAT_STARTED
|
||||||
|
@ -275,7 +275,7 @@ class WorkerThread(threading.Thread):
|
||||||
# kindlegen returncodes
|
# kindlegen returncodes
|
||||||
# 0 = Info(prcgen):I1036: Mobi file built successfully
|
# 0 = Info(prcgen):I1036: Mobi file built successfully
|
||||||
# 1 = Info(prcgen):I1037: Mobi file built with WARNINGS!
|
# 1 = Info(prcgen):I1037: Mobi file built with WARNINGS!
|
||||||
# 2 = Info(prcgen):I1038: MOBI file could not be generated because of errors!
|
# 2 = Info(prcgen):I1038: MOBI file could not be generated because of errors!
|
||||||
if ( check < 2 and web.ub.config.config_ebookconverter == 1) or \
|
if ( check < 2 and web.ub.config.config_ebookconverter == 1) or \
|
||||||
(check == 0 and web.ub.config.config_ebookconverter == 2):
|
(check == 0 and web.ub.config.config_ebookconverter == 2):
|
||||||
cur_book = web.db.session.query(web.db.Books).filter(web.db.Books.id == bookid).first()
|
cur_book = web.db.session.query(web.db.Books).filter(web.db.Books.id == bookid).first()
|
||||||
|
@ -292,7 +292,7 @@ class WorkerThread(threading.Thread):
|
||||||
self.UIqueue[self.current]['progress'] = "100 %"
|
self.UIqueue[self.current]['progress'] = "100 %"
|
||||||
self.UIqueue[self.current]['runtime'] = self._formatRuntime(
|
self.UIqueue[self.current]['runtime'] = self._formatRuntime(
|
||||||
datetime.now() - self.queue[self.current]['starttime'])
|
datetime.now() - self.queue[self.current]['starttime'])
|
||||||
return file_path + ".mobi"
|
return file_path + ".mobi"
|
||||||
else:
|
else:
|
||||||
web.app.logger.info("ebook converter failed with error while converting book")
|
web.app.logger.info("ebook converter failed with error while converting book")
|
||||||
if not error_message:
|
if not error_message:
|
||||||
|
@ -352,7 +352,7 @@ class WorkerThread(threading.Thread):
|
||||||
|
|
||||||
def send_raw_email(self):
|
def send_raw_email(self):
|
||||||
self.queue[self.current]['starttime'] = datetime.now()
|
self.queue[self.current]['starttime'] = datetime.now()
|
||||||
self.UIqueue[self.current]['formStarttime'] = self.queue[self.current]['starttime']
|
self.UIqueue[self.current]['formStarttime'] = self.queue[self.current]['starttime']
|
||||||
self.queue[self.current]['status'] = STAT_STARTED
|
self.queue[self.current]['status'] = STAT_STARTED
|
||||||
self.UIqueue[self.current]['status'] = _('Started')
|
self.UIqueue[self.current]['status'] = _('Started')
|
||||||
obj=self.queue[self.current]
|
obj=self.queue[self.current]
|
||||||
|
@ -414,7 +414,7 @@ class WorkerThread(threading.Thread):
|
||||||
sys.stderr = org_stderr
|
sys.stderr = org_stderr
|
||||||
|
|
||||||
except (socket.error, smtplib.SMTPRecipientsRefused, smtplib.SMTPException) as e:
|
except (socket.error, smtplib.SMTPRecipientsRefused, smtplib.SMTPException) as e:
|
||||||
self._handleError(error_message)
|
self._handleError(e)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _formatRuntime(self, runtime):
|
def _formatRuntime(self, runtime):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user