From: Oleg Broytman Date: Wed, 10 Jan 2024 00:16:24 +0000 (+0300) Subject: Feat(web): Catch and report errors on downloading X-Git-Tag: 0.3.0~11 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=d402ab0c3732892674d79c0fbc4b965d925e8029;p=m_librarian.git Feat(web): Catch and report errors on downloading [skip ci] --- diff --git a/m_librarian/web/app.py b/m_librarian/web/app.py index 283ddb7..39a1779 100644 --- a/m_librarian/web/app.py +++ b/m_librarian/web/app.py @@ -66,15 +66,21 @@ def download_books(): books_ids.append(bid) if books_ids: download_path = get_config().getpath('download', 'path') - for bid in books_ids: - book = Book.get(int(bid)) - download(book, download_path) - return { - 'message': u'Книги сохранены.', - } + try: + for bid in books_ids: + book = Book.get(int(bid)) + download(book, download_path) + except Exception as e: + return { + 'error': str(e), + } + else: + return { + 'message': u'Книги сохранены.', + } else: return { - 'message': u'Не выбрано книг для сохранения.', + 'error': u'Не выбрано книг для сохранения.', } diff --git a/m_librarian/web/views/download.py b/m_librarian/web/views/download.py index ef05ca4..c207ccb 100644 --- a/m_librarian/web/views/download.py +++ b/m_librarian/web/views/download.py @@ -33,12 +33,12 @@ VFFSL=valueFromFrameOrSearchList VFSL=valueFromSearchList VFN=valueForName currentTime=time.time -__CHEETAH_version__ = '3.1.0' -__CHEETAH_versionTuple__ = (3, 1, 0, 'final', 1) -__CHEETAH_genTime__ = 1523146500.915016 -__CHEETAH_genTimestamp__ = 'Sun Apr 8 03:15:00 2018' +__CHEETAH_version__ = '3.3.1' +__CHEETAH_versionTuple__ = (3, 3, 1, 'final', 0) +__CHEETAH_genTime__ = 1704845598.39619 +__CHEETAH_genTimestamp__ = 'Wed Jan 10 03:13:18 2024' __CHEETAH_src__ = 'download.tmpl' -__CHEETAH_srcLastModified__ = 'Sun Apr 8 03:14:43 2018' +__CHEETAH_srcLastModified__ = 'Wed Jan 10 03:10:53 2024' __CHEETAH_docstring__ = 'Autogenerated by Cheetah: The Python-Powered Template Engine' if __CHEETAH_versionTuple__ < RequiredCheetahVersionTuple: @@ -91,10 +91,18 @@ class download(layout): if _v is not None: write(_filter(_v, rawExpr=u'$title')) # from line 5, col 5. write(u''' -

''') - _v = VFFSL(SL,"message",True) # u'$message' on line 7, col 4 - if _v is not None: write(_filter(_v, rawExpr=u'$message')) # from line 7, col 4. - write(u'''

+''') + if VFFSL(SL,"getVar",False)('error', None): # generated from line 7, col 1 + write(u'''

''') + _v = VFFSL(SL,"error",True) # u'$error' on line 8, col 23 + if _v is not None: write(_filter(_v, rawExpr=u'$error')) # from line 8, col 23. + write(u'''

+''') + else: # generated from line 9, col 1 + write(u'''

''') + _v = VFFSL(SL,"message",True) # u'$message' on line 10, col 4 + if _v is not None: write(_filter(_v, rawExpr=u'$message')) # from line 10, col 4. + write(u'''

''') ######################################## @@ -161,7 +169,7 @@ if not hasattr(download, '_initCheetahAttributes'): # CHEETAH was developed by Tavis Rudd and Mike Orr # with code, advice and input from many other volunteers. -# For more information visit http://cheetahtemplate.org/ +# For more information visit https://cheetahtemplate.org/ ################################################## ## if run from command line: diff --git a/m_librarian/web/views/download.tmpl b/m_librarian/web/views/download.tmpl index cf7e5bf..f9bf363 100644 --- a/m_librarian/web/views/download.tmpl +++ b/m_librarian/web/views/download.tmpl @@ -4,5 +4,9 @@ #def body

$title

+#if $getVar('error', None) +

$error

+#else

$message

+#end if #end def