@frontend.route('/objects/<int:object_id>/export')
@object_permissions_required(Permissions.READ, on_unauthorized=on_unauthorized)
def export_data(object_id):
    object_ids = [object_id]
    file_extension = flask.request.args.get('format', '.pdf')
    if ((file_extension != '.pdf') and (file_extension not in logic.export.FILE_FORMATS)):
        return flask.abort(400)
    if ('object_ids' in flask.request.args):
        try:
            object_ids = json.loads(flask.request.args['object_ids'])
            object_ids = [int(i) for i in object_ids]
            if any(((Permissions.READ not in get_user_object_permissions(i, flask_login.current_user.id)) for i in object_ids)):
                return flask.abort(400)
        except Exception:
            return flask.abort(400)
        if (not object_ids):
            return flask.abort(400)
    if (file_extension == '.pdf'):
        sections = pdfexport.SECTIONS
        if ('sections' in flask.request.args):
            try:
                sections = sections.intersection(json.loads(flask.request.args['sections']))
            except Exception:
                return flask.abort(400)
        if ('language' in flask.request.args):
            try:
                lang_code = flask.request.args['language']
                if (lang_code not in logic.locale.SUPPORTED_LOCALES):
                    raise ValueError()
                language = logic.languages.get_language_by_lang_code(lang_code)
                if (not language.enabled_for_user_interface):
                    raise ValueError()
            except Exception:
                lang_code = 'en'
        else:
            lang_code = 'en'
        pdf_data = pdfexport.create_pdfexport(object_ids, sections, lang_code)
        file_bytes = io.BytesIO(pdf_data)
    elif (file_extension in logic.export.FILE_FORMATS):
        file_bytes = logic.export.FILE_FORMATS[file_extension][1](flask_login.current_user.id, object_ids=object_ids)
    else:
        file_bytes = None
    if file_bytes:
        return flask.Response(file_bytes, 200, headers={'Content-Disposition': f'attachment; filename=sampledb_export{file_extension}', 'Content-Type': ('application/pdf' if (file_extension == '.pdf') else logic.export.FILE_FORMATS[file_extension][2])})
    return flask.abort(500)
@frontend.route('/objects/<int:object_id>/export')
@object_permissions_required(Permissions.READ, on_unauthorized=on_unauthorized)
def export_data(object_id):
    object_ids = [object_id]
    file_extension = flask.request.args.get('format', '.pdf')
    if ((file_extension != '.pdf') and (file_extension not in logic.export.FILE_FORMATS)):
        return flask.abort(400)
    if ('object_ids' in flask.request.args):
        try:
            object_ids = json.loads(flask.request.args['object_ids'])
            object_ids = [int(i) for i in object_ids]
            if any(((Permissions.READ not in get_user_object_permissions(i, flask_login.current_user.id)) for i in object_ids)):
                return flask.abort(400)
        except Exception:
            return flask.abort(400)
        if (not object_ids):
            return flask.abort(400)
    if (file_extension == '.pdf'):
        sections = pdfexport.SECTIONS
        if ('sections' in flask.request.args):
            try:
                sections = sections.intersection(json.loads(flask.request.args['sections']))
            except Exception:
                return flask.abort(400)
        if ('language' in flask.request.args):
            try:
                lang_code = flask.request.args['language']
                if (lang_code not in logic.locale.SUPPORTED_LOCALES):
                    raise ValueError()
                language = logic.languages.get_language_by_lang_code(lang_code)
                if (not language.enabled_for_user_interface):
                    raise ValueError()
            except Exception:
                lang_code = 'en'
        else:
            lang_code = 'en'
        pdf_data = pdfexport.create_pdfexport(object_ids, sections, lang_code)
        file_bytes = io.BytesIO(pdf_data)
    elif (file_extension in logic.export.FILE_FORMATS):
        file_bytes = logic.export.FILE_FORMATS[file_extension][1](flask_login.current_user.id, object_ids=object_ids)
    else:
        file_bytes = None
    if file_bytes:
        return flask.Response(file_bytes, 200, headers={'Content-Disposition': f'attachment; filename=sampledb_export{file_extension}', 'Content-Type': ('application/pdf' if (file_extension == '.pdf') else logic.export.FILE_FORMATS[file_extension][2])})
    return flask.abort(500)