Code Duplication    Length = 30-36 lines in 2 locations

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

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