Code Duplication    Length = 30-36 lines in 2 locations

backend/tracim_backend/views/contents_api/file_controller.py 2 locations

@@ 291-326 (lines=36) @@
288
            as_attachment=hapic_data.query.force_download
289
        )
290
291
    @hapic.with_api_doc(tags=[SWAGGER_TAG__FILE_ENDPOINTS])
292
    @require_workspace_role(UserRoleInWorkspace.READER)
293
    @require_content_types([FILE_TYPE])
294
    @hapic.handle_exception(UnavailablePreview, HTTPStatus.BAD_REQUEST)
295
    @hapic.handle_exception(UnavailablePreviewType, HTTPStatus.BAD_REQUEST)
296
    @hapic.input_path(WorkspaceAndContentRevisionIdPathSchema())
297
    @hapic.input_query(FileQuerySchema())
298
    @hapic.output_file([])
299
    def preview_pdf_full_revision(self, context, request: TracimRequest, hapic_data=None):  # nopep8
300
        """
301
        Obtain full pdf preview of a specific revision of content.
302
        """
303
        app_config = request.registry.settings['CFG']
304
        api = ContentApi(
305
            show_archived=True,
306
            show_deleted=True,
307
            current_user=request.current_user,
308
            session=request.dbsession,
309
            config=app_config,
310
        )
311
        content = api.get_one(
312
            hapic_data.path.content_id,
313
            content_type=CONTENT_TYPES.Any_SLUG
314
        )
315
        revision = api.get_one_revision(
316
            revision_id=hapic_data.path.revision_id,
317
            content=content
318
        )
319
        pdf_preview_path = api.get_full_pdf_preview_path(
320
            revision.revision_id,
321
        )
322
        filename = "{label}.pdf".format(label=revision.label)
323
        return HapicFile(
324
            file_path=pdf_preview_path,
325
            filename=filename,
326
            as_attachment=hapic_data.query.force_download
327
        )
328
329
    @hapic.with_api_doc(tags=[SWAGGER_TAG__FILE_ENDPOINTS])
@@ 259-288 (lines=30) @@
256
            as_attachment=hapic_data.query.force_download
257
        )
258
259
    @hapic.with_api_doc(tags=[SWAGGER_TAG__FILE_ENDPOINTS])
260
    @require_workspace_role(UserRoleInWorkspace.READER)
261
    @require_content_types([FILE_TYPE])
262
    @hapic.handle_exception(UnavailablePreview, HTTPStatus.BAD_REQUEST)
263
    @hapic.handle_exception(UnavailablePreviewType, HTTPStatus.BAD_REQUEST)
264
    @hapic.input_query(FileQuerySchema())
265
    @hapic.input_path(WorkspaceAndContentIdPathSchema())
266
    @hapic.output_file([])
267
    def preview_pdf_full(self, context, request: TracimRequest, hapic_data=None):  # nopep8
268
        """
269
        Obtain a full pdf preview (all page) of last revision of content.
270
        """
271
        app_config = request.registry.settings['CFG']
272
        api = ContentApi(
273
            show_archived=True,
274
            show_deleted=True,
275
            current_user=request.current_user,
276
            session=request.dbsession,
277
            config=app_config,
278
        )
279
        content = api.get_one(
280
            hapic_data.path.content_id,
281
            content_type=CONTENT_TYPES.Any_SLUG
282
        )
283
        pdf_preview_path = api.get_full_pdf_preview_path(content.revision_id)
284
        filename = "{label}.pdf".format(label=content.label)
285
        return HapicFile(
286
            file_path=pdf_preview_path,
287
            filename=filename,
288
            as_attachment=hapic_data.query.force_download
289
        )
290
291
    @hapic.with_api_doc(tags=[SWAGGER_TAG__FILE_ENDPOINTS])