|
@@ -8,6 +8,7 @@ import traceback
|
8
|
8
|
|
9
|
9
|
from cgi import FieldStorage
|
10
|
10
|
from depot.manager import DepotManager
|
|
11
|
+from preview_generator.exception import PreviewGeneratorException
|
11
|
12
|
from preview_generator.manager import PreviewManager
|
12
|
13
|
from sqlalchemy.orm.exc import NoResultFound
|
13
|
14
|
import tg
|
|
@@ -17,6 +18,7 @@ from tg import require
|
17
|
18
|
from tg import predicates
|
18
|
19
|
from tg.i18n import ugettext as _
|
19
|
20
|
from tg.predicates import not_anonymous
|
|
21
|
+from typing import List
|
20
|
22
|
|
21
|
23
|
from tracim.controllers import TIMRestController
|
22
|
24
|
from tracim.controllers import StandardController
|
|
@@ -216,7 +218,14 @@ class UserWorkspaceFolderFileRestController(TIMWorkspaceContentRestController):
|
216
|
218
|
revision_id = file.revision_id
|
217
|
219
|
|
218
|
220
|
file_path = content_api.get_one_revision_filepath(revision_id)
|
219
|
|
- nb_page = preview_manager.get_nb_page(file_path=file_path)
|
|
221
|
+
|
|
222
|
+ nb_page = 0
|
|
223
|
+ try:
|
|
224
|
+ nb_page = preview_manager.get_page_nb(file_path=file_path)
|
|
225
|
+ except PreviewGeneratorException as e:
|
|
226
|
+ # INFO - A.P - Silently intercepts preview exception
|
|
227
|
+ # As preview generation isn't mandatory, just register it
|
|
228
|
+ logger.debug(self, 'Exception: {}'.format(e.__str__))
|
220
|
229
|
preview_urls = []
|
221
|
230
|
for page in range(int(nb_page)):
|
222
|
231
|
url_str = '/previews/{}/pages/{}?revision_id={}'
|
|
@@ -225,6 +234,16 @@ class UserWorkspaceFolderFileRestController(TIMWorkspaceContentRestController):
|
225
|
234
|
revision_id)
|
226
|
235
|
preview_urls.append(url)
|
227
|
236
|
|
|
237
|
+ enable_pdf_buttons = False # type: bool
|
|
238
|
+ try:
|
|
239
|
+ enable_pdf_buttons = \
|
|
240
|
+ preview_manager.has_pdf_preview(file_path=file_path)
|
|
241
|
+ except PreviewGeneratorException as e:
|
|
242
|
+ # INFO - A.P - Silently intercepts preview exception
|
|
243
|
+ # As preview generation isn't mandatory, just register it
|
|
244
|
+ logger.debug(self, 'Exception: {}'.format(e.__str__))
|
|
245
|
+ pdf_available = 'true' if enable_pdf_buttons else 'false' # type: str
|
|
246
|
+
|
228
|
247
|
fake_api_breadcrumb = self.get_breadcrumb(file_id)
|
229
|
248
|
fake_api_content = DictLikeClass(breadcrumb=fake_api_breadcrumb,
|
230
|
249
|
current_user=current_user_content)
|
|
@@ -235,7 +254,8 @@ class UserWorkspaceFolderFileRestController(TIMWorkspaceContentRestController):
|
235
|
254
|
result = DictLikeClass(result=dictified_file,
|
236
|
255
|
fake_api=fake_api,
|
237
|
256
|
nb_page=nb_page,
|
238
|
|
- url=preview_urls)
|
|
257
|
+ url=preview_urls,
|
|
258
|
+ pdf_available=pdf_available)
|
239
|
259
|
return result
|
240
|
260
|
|
241
|
261
|
@tg.require(current_user_is_reader())
|