Commit d414bf32 authored by OzzieIsaacs's avatar OzzieIsaacs

Massadd of books to shelfs (#203, #404) from advanced search

Code cosmetics
bugfix error message on failed emails
refactored language name generation
parent 34abf95f
...@@ -390,7 +390,7 @@ function rarMakeDecodeTables(BitLength, offset, dec, size) { ...@@ -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; ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -488,7 +490,7 @@ function Unpack20(bstream) { //, Solid) {
continue; continue;
} }
} }
rarUpdateProgress() rarUpdateProgress();
} }
function rarUpdateProgress() { function rarUpdateProgress() {
...@@ -511,20 +513,23 @@ function rarReadTables20(bstream) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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 @@ ...@@ -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 @@ ...@@ -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" ...@@ -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"
......
...@@ -46,9 +46,8 @@ DEFAULT_PASS = "admin123" ...@@ -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): ...@@ -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): ...@@ -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: ...@@ -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 = {}
This diff is collapsed.
...@@ -205,7 +205,7 @@ class WorkerThread(threading.Thread): ...@@ -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): ...@@ -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): ...@@ -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): ...@@ -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): ...@@ -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):
......
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