mirror of
https://github.com/janeczku/calibre-web
synced 2024-12-25 01:20:32 +00:00
Partial fix to #617. Local status messages now work.
This commit is contained in:
parent
0bb148e6e3
commit
b4122e9858
@ -567,3 +567,24 @@ def get_current_version_info():
|
||||
if is_sha1(content[0]) and len(content[1]) > 0:
|
||||
return {'hash': content[0], 'datetime': content[1]}
|
||||
return False
|
||||
|
||||
def render_task_status(tasklist):
|
||||
#helper function to apply localize status information in tasklist entries
|
||||
renderedtasklist=list()
|
||||
|
||||
for task in tasklist:
|
||||
if isinstance( task['status'], int ):
|
||||
if task['status'] == worker.STAT_WAITING:
|
||||
task['status'] = _('Waiting')
|
||||
elif task['status'] == worker.STAT_FAIL:
|
||||
task['status'] = _('Failed')
|
||||
elif task['status'] == worker.STAT_STARTED:
|
||||
task['status'] = _('Started')
|
||||
elif task['status'] == worker.STAT_FINISH_SUCCESS:
|
||||
task['status'] = _('Finished')
|
||||
else:
|
||||
task['status'] = _('Unknown Status')
|
||||
renderedtasklist.append(task)
|
||||
|
||||
return renderedtasklist
|
||||
|
13
cps/web.py
13
cps/web.py
@ -85,6 +85,7 @@ import hashlib
|
||||
from redirect import redirect_back
|
||||
import time
|
||||
import server
|
||||
import copy
|
||||
try:
|
||||
import cPickle
|
||||
except ImportError:
|
||||
@ -873,6 +874,7 @@ def get_metadata_calibre_companion(uuid):
|
||||
@login_required
|
||||
def get_email_status_json():
|
||||
answer=list()
|
||||
UIanswer = list()
|
||||
tasks=helper.global_WorkerThread.get_taskstatus()
|
||||
if not current_user.role_admin():
|
||||
for task in tasks:
|
||||
@ -893,7 +895,11 @@ def get_email_status_json():
|
||||
if 'starttime' not in task:
|
||||
task['starttime'] = ""
|
||||
answer = tasks
|
||||
js=json.dumps(answer)
|
||||
|
||||
UIanswer = copy.deepcopy(answer)
|
||||
UIanswer = helper.render_task_status(UIanswer)
|
||||
|
||||
js=json.dumps(UIanswer)
|
||||
response = make_response(js)
|
||||
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
||||
return response
|
||||
@ -1626,6 +1632,7 @@ def bookmark(book_id, book_format):
|
||||
def get_tasks_status():
|
||||
# if current user admin, show all email, otherwise only own emails
|
||||
answer=list()
|
||||
UIanswer=list()
|
||||
tasks=helper.global_WorkerThread.get_taskstatus()
|
||||
if not current_user.role_admin():
|
||||
for task in tasks:
|
||||
@ -1647,8 +1654,10 @@ def get_tasks_status():
|
||||
task['starttime'] = ""
|
||||
answer = tasks
|
||||
|
||||
UIanswer = copy.deepcopy(answer)
|
||||
UIanswer = helper.render_task_status(UIanswer)
|
||||
# foreach row format row
|
||||
return render_title_template('tasks.html', entries=answer, title=_(u"Tasks"))
|
||||
return render_title_template('tasks.html', entries=UIanswer, title=_(u"Tasks"))
|
||||
|
||||
|
||||
@app.route("/admin")
|
||||
|
@ -212,7 +212,7 @@ class WorkerThread(threading.Thread):
|
||||
def convert_any_format(self):
|
||||
# convert book, and upload in case of google drive
|
||||
self.queue[self.current]['status'] = STAT_STARTED
|
||||
self.UIqueue[self.current]['status'] = _('Started')
|
||||
self.UIqueue[self.current]['status'] = STAT_STARTED
|
||||
self.queue[self.current]['starttime'] = datetime.now()
|
||||
self.UIqueue[self.current]['formStarttime'] = self.queue[self.current]['starttime']
|
||||
curr_task = self.queue[self.current]['typ']
|
||||
@ -352,7 +352,7 @@ class WorkerThread(threading.Thread):
|
||||
self.queue.append({'file_path':file_path, 'bookid':bookid, 'starttime': 0, 'kindle': kindle_mail,
|
||||
'status': STAT_WAITING, 'typ': task, 'settings':settings})
|
||||
self.UIqueue.append({'user': user_name, 'formStarttime': '', 'progress': " 0 %", 'type': typ,
|
||||
'runtime': '0 s', 'status': _('Waiting'),'id': self.id } )
|
||||
'runtime': '0 s', 'status': STAT_WAITING,'id': self.id } )
|
||||
|
||||
self.last=len(self.queue)
|
||||
addLock.release()
|
||||
@ -371,7 +371,7 @@ class WorkerThread(threading.Thread):
|
||||
'settings':settings, 'recipent':recipient, 'starttime': 0,
|
||||
'status': STAT_WAITING, 'typ': TASK_EMAIL, 'text':text})
|
||||
self.UIqueue.append({'user': user_name, 'formStarttime': '', 'progress': " 0 %", 'type': typ,
|
||||
'runtime': '0 s', 'status': _('Waiting'),'id': self.id })
|
||||
'runtime': '0 s', 'status': STAT_WAITING,'id': self.id })
|
||||
self.last=len(self.queue)
|
||||
addLock.release()
|
||||
|
||||
@ -395,7 +395,7 @@ class WorkerThread(threading.Thread):
|
||||
self.queue[self.current]['starttime'] = datetime.now()
|
||||
self.UIqueue[self.current]['formStarttime'] = self.queue[self.current]['starttime']
|
||||
self.queue[self.current]['status'] = STAT_STARTED
|
||||
self.UIqueue[self.current]['status'] = _('Started')
|
||||
self.UIqueue[self.current]['status'] = STAT_STARTED
|
||||
obj=self.queue[self.current]
|
||||
# create MIME message
|
||||
msg = MIMEMultipart()
|
||||
@ -473,7 +473,7 @@ class WorkerThread(threading.Thread):
|
||||
def _handleError(self, error_message):
|
||||
web.app.logger.error(error_message)
|
||||
self.queue[self.current]['status'] = STAT_FAIL
|
||||
self.UIqueue[self.current]['status'] = _('Failed')
|
||||
self.UIqueue[self.current]['status'] = STAT_FAIL
|
||||
self.UIqueue[self.current]['progress'] = "100 %"
|
||||
self.UIqueue[self.current]['runtime'] = self._formatRuntime(
|
||||
datetime.now() - self.queue[self.current]['starttime'])
|
||||
@ -481,7 +481,7 @@ class WorkerThread(threading.Thread):
|
||||
|
||||
def _handleSuccess(self):
|
||||
self.queue[self.current]['status'] = STAT_FINISH_SUCCESS
|
||||
self.UIqueue[self.current]['status'] = _('Finished')
|
||||
self.UIqueue[self.current]['status'] = STAT_FINISH_SUCCESS
|
||||
self.UIqueue[self.current]['progress'] = "100 %"
|
||||
self.UIqueue[self.current]['runtime'] = self._formatRuntime(
|
||||
datetime.now() - self.queue[self.current]['starttime'])
|
||||
|
Loading…
Reference in New Issue
Block a user