Преглед изворни кода

Indicates to display, or not, download pdf buttons

Adrien Panay пре 7 година
родитељ
комит
aa7739a9fa
2 измењених фајлова са 16 додато и 2 уклоњено
  1. 15 1
      tracim/tracim/controllers/content.py
  2. 1 1
      tracim/tracim/templates/file/getone.mak

+ 15 - 1
tracim/tracim/controllers/content.py Прегледај датотеку

@@ -10,6 +10,9 @@ from cgi import FieldStorage
10 10
 from depot.manager import DepotManager
11 11
 from preview_generator.exception import PreviewGeneratorException
12 12
 from preview_generator.manager import PreviewManager
13
+from preview_generator.preview.builder.office__libreoffice import OfficePreviewBuilderLibreoffice
14
+from preview_generator.preview.builder.pdf__pypdf2 import PdfPreviewBuilderPyPDF2
15
+from preview_generator.preview.builder.plain_text import PlainTextPreviewBuilder
13 16
 from sqlalchemy.orm.exc import NoResultFound
14 17
 import tg
15 18
 from tg import abort
@@ -18,6 +21,7 @@ from tg import require
18 21
 from tg import predicates
19 22
 from tg.i18n import ugettext as _
20 23
 from tg.predicates import not_anonymous
24
+from typing import List
21 25
 
22 26
 from tracim.controllers import TIMRestController
23 27
 from tracim.controllers import StandardController
@@ -230,6 +234,15 @@ class UserWorkspaceFolderFileRestController(TIMWorkspaceContentRestController):
230 234
                                  revision_id)
231 235
             preview_urls.append(url)
232 236
 
237
+        pdf_ready_mimetypes = []  # type: List[str]
238
+        pdf_ready_mimetypes = \
239
+            OfficePreviewBuilderLibreoffice.get_supported_mimetypes() + \
240
+            PdfPreviewBuilderPyPDF2.get_supported_mimetypes() + \
241
+            PlainTextPreviewBuilder.get_supported_mimetypes()
242
+        enable_pdf_buttons = \
243
+            file.file_mimetype in pdf_ready_mimetypes  # type: bool
244
+        pdf_available = str(enable_pdf_buttons).lower()  # type: str
245
+
233 246
         fake_api_breadcrumb = self.get_breadcrumb(file_id)
234 247
         fake_api_content = DictLikeClass(breadcrumb=fake_api_breadcrumb,
235 248
                                          current_user=current_user_content)
@@ -240,7 +253,8 @@ class UserWorkspaceFolderFileRestController(TIMWorkspaceContentRestController):
240 253
         result = DictLikeClass(result=dictified_file,
241 254
                                fake_api=fake_api,
242 255
                                nb_page=nb_page,
243
-                               url=preview_urls)
256
+                               url=preview_urls,
257
+                               pdf_available=pdf_available)
244 258
         return result
245 259
 
246 260
     @tg.require(current_user_is_reader())

+ 1 - 1
tracim/tracim/templates/file/getone.mak Прегледај датотеку

@@ -127,7 +127,7 @@
127 127
                     modifiedAt: '${h.format_short(created_localized)|n}',
128 128
                     owner: '${result.file.owner.name}',
129 129
                     sourceLink: '${download_url}',
130
-                    pdfAvailable: false // FIXME - Côme - 2017/07/24 - backend should return this information
130
+                    pdfAvailable: ${pdf_available}
131 131
                   }
132 132
                 )
133 133
               })()