Browse Source

Merge pull request #318 from lebouquetin/master

Bastien Sevajol 7 years ago
parent
commit
d68a39c929
1 changed files with 30 additions and 18 deletions
  1. 30 18
      tracim/tracim/controllers/content.py

+ 30 - 18
tracim/tracim/controllers/content.py View File

220
         file_path = content_api.get_one_revision_filepath(revision_id)
220
         file_path = content_api.get_one_revision_filepath(revision_id)
221
 
221
 
222
         nb_page = 0
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__))
223
+        enable_pdf_buttons = False  # type: bool
229
         preview_urls = []
224
         preview_urls = []
230
-        for page in range(int(nb_page)):
231
-            url_str = '/previews/{}/pages/{}?revision_id={}'
232
-            url = url_str.format(file_id,
233
-                                 page,
234
-                                 revision_id)
235
-            preview_urls.append(url)
236
 
225
 
237
-        enable_pdf_buttons = False  # type: bool
238
         try:
226
         try:
227
+            nb_page = preview_manager.get_page_nb(file_path=file_path)
228
+            for page in range(int(nb_page)):
229
+                url_str = '/previews/{}/pages/{}?revision_id={}'
230
+                url = url_str.format(file_id,
231
+                                     page,
232
+                                     revision_id)
233
+                preview_urls.append(url)
234
+
239
             enable_pdf_buttons = \
235
             enable_pdf_buttons = \
240
                 preview_manager.has_pdf_preview(file_path=file_path)
236
                 preview_manager.has_pdf_preview(file_path=file_path)
237
+
241
         except PreviewGeneratorException as e:
238
         except PreviewGeneratorException as e:
242
             # INFO - A.P - Silently intercepts preview exception
239
             # INFO - A.P - Silently intercepts preview exception
243
             # As preview generation isn't mandatory, just register it
240
             # As preview generation isn't mandatory, just register it
244
-            logger.debug(self, 'Exception: {}'.format(e.__str__))
241
+            logger.debug(
242
+                self,
243
+                'Preview Generator Exception: {}'.format(e.__str__)
244
+            )
245
+        except Exception as e:
246
+            # INFO - D.A - 2017-08-11 - Make Tracim robust to pg exceptions
247
+            # Preview generator may potentially raise any type of exception
248
+            # so we prevent user interface crashes by catching all exceptions
249
+            logger.error(
250
+                self,
251
+                'Preview Generator Generic Exception: {}'.format(e.__str__)
252
+            )
253
+
245
         pdf_available = 'true' if enable_pdf_buttons else 'false'  # type: str
254
         pdf_available = 'true' if enable_pdf_buttons else 'false'  # type: str
246
 
255
 
247
         fake_api_breadcrumb = self.get_breadcrumb(file_id)
256
         fake_api_breadcrumb = self.get_breadcrumb(file_id)
248
-        fake_api_content = DictLikeClass(breadcrumb=fake_api_breadcrumb,
249
-                                         current_user=current_user_content)
250
-        fake_api = Context(CTX.FOLDER,
251
-                           current_user=user).toDict(fake_api_content)
257
+        fake_api_content = DictLikeClass(
258
+            breadcrumb=fake_api_breadcrumb,
259
+            current_user=current_user_content
260
+        )
261
+        fake_api = Context(CTX.FOLDER, current_user=user)\
262
+            .toDict(fake_api_content)
263
+
252
         dictified_file = Context(self._get_one_context,
264
         dictified_file = Context(self._get_one_context,
253
                                  current_user=user).toDict(file, 'file')
265
                                  current_user=user).toDict(file, 'file')
254
         result = DictLikeClass(result=dictified_file,
266
         result = DictLikeClass(result=dictified_file,