libreqda 1.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- CHANGELOG.md +481 -0
- libreqda-1.2.0.dist-info/LICENSE.txt +28 -0
- libreqda-1.2.0.dist-info/METADATA +131 -0
- libreqda-1.2.0.dist-info/RECORD +255 -0
- libreqda-1.2.0.dist-info/WHEEL +4 -0
- libreqda-1.2.0.dist-info/entry_points.txt +4 -0
- scripts/babelrc +8 -0
- scripts/dist/LICENSE.txt +33 -0
- scripts/dist/RELEASE.txt +23 -0
- scripts/dist/macos/libreqda.icns +0 -0
- scripts/dist/macos/macos.spec +43 -0
- scripts/dist/macos/plist.patch +10 -0
- scripts/dist/macos/taguette.icns +0 -0
- scripts/dist/macos/taguette_console_wrapper +4 -0
- scripts/dist/macos.sh +32 -0
- scripts/dist/pyinstaller_entrypoint.py +19 -0
- scripts/dist/windows/windows-installer.iss +51 -0
- scripts/dist/windows/windows.spec +39 -0
- scripts/edugain/worker_update_edugain_idps.py +89 -0
- scripts/edugain/worker_update_edugain_idps.sh +9 -0
- scripts/make_password_reset_link.py +56 -0
- scripts/make_theme.py +99 -0
- scripts/new_db_revision.sh +8 -0
- scripts/register_user.py +76 -0
- scripts/update_pot.sh +33 -0
- scripts/update_translations.sh +17 -0
- scripts/validate.py +140 -0
- scripts/wipe_and_disable_user.py +90 -0
- taguette/__init__.py +13 -0
- taguette/access_control.py +145 -0
- taguette/convert.py +623 -0
- taguette/database/__init__.py +177 -0
- taguette/database/base.py +9 -0
- taguette/database/copy.py +433 -0
- taguette/database/models.py +920 -0
- taguette/demodata.py +688 -0
- taguette/export.py +500 -0
- taguette/extract.py +287 -0
- taguette/import_codebook.py +110 -0
- taguette/l10n/de_DE/LC_MESSAGES/taguette_javascript.mo +0 -0
- taguette/l10n/de_DE/LC_MESSAGES/taguette_main.mo +0 -0
- taguette/l10n/el_EL/LC_MESSAGES/taguette_javascript.mo +0 -0
- taguette/l10n/el_GR/LC_MESSAGES/taguette_javascript.mo +0 -0
- taguette/l10n/el_GR/LC_MESSAGES/taguette_main.mo +0 -0
- taguette/l10n/en_US/LC_MESSAGES/taguette_javascript.mo +0 -0
- taguette/l10n/en_US/LC_MESSAGES/taguette_main.mo +0 -0
- taguette/l10n/es_ES/LC_MESSAGES/taguette_javascript.mo +0 -0
- taguette/l10n/es_ES/LC_MESSAGES/taguette_main.mo +0 -0
- taguette/l10n/fr_FR/LC_MESSAGES/taguette_javascript.mo +0 -0
- taguette/l10n/fr_FR/LC_MESSAGES/taguette_main.mo +0 -0
- taguette/l10n/id_ID/LC_MESSAGES/taguette_javascript.mo +0 -0
- taguette/l10n/id_ID/LC_MESSAGES/taguette_main.mo +0 -0
- taguette/l10n/it_IT/LC_MESSAGES/taguette_javascript.mo +0 -0
- taguette/l10n/it_IT/LC_MESSAGES/taguette_main.mo +0 -0
- taguette/l10n/nl_NL/LC_MESSAGES/taguette_javascript.mo +0 -0
- taguette/l10n/nl_NL/LC_MESSAGES/taguette_main.mo +0 -0
- taguette/l10n/pt_PT/LC_MESSAGES/taguette_javascript.mo +0 -0
- taguette/l10n/pt_PT/LC_MESSAGES/taguette_main.mo +0 -0
- taguette/l10n/sv_SE/LC_MESSAGES/taguette_javascript.mo +0 -0
- taguette/l10n/sv_SE/LC_MESSAGES/taguette_main.mo +0 -0
- taguette/loki_handler.py +107 -0
- taguette/main.py +649 -0
- taguette/migrations/env.py +72 -0
- taguette/migrations/script.py.mako +24 -0
- taguette/migrations/versions/09c662cd9483_make_documents_filename_not_null.py +39 -0
- taguette/migrations/versions/1b29e68900c1_add_user_roles.py +55 -0
- taguette/migrations/versions/1b96a606551d_update_user_to_have_a_display_name.py +34 -0
- taguette/migrations/versions/2467bab602b7_add_color_column_to_tags_table.py +33 -0
- taguette/migrations/versions/382db36f20f4_add_user_disabled.py +66 -0
- taguette/migrations/versions/43d6c240309d_remove_document_groups.py +81 -0
- taguette/migrations/versions/447d636f72c5_cascades.py +40 -0
- taguette/migrations/versions/491de2dc7cd7_add_indexes.py +51 -0
- taguette/migrations/versions/4c55b3b3ff30_user_login_length.py +58 -0
- taguette/migrations/versions/61a4abcc8769_user_with_parent_for_permissions.py +40 -0
- taguette/migrations/versions/6489b5f9cfb5_increase_password_hash_size.py +34 -0
- taguette/migrations/versions/679f625e6e6a_fix_unique_tags.py +59 -0
- taguette/migrations/versions/77c4543a5b9b_add_parent_id_column_to_collection_table.py +41 -0
- taguette/migrations/versions/7c94b7a31e69_add_is_archived_column_to_projets.py +39 -0
- taguette/migrations/versions/7f56de97e3c8_change_edugain_displayname_length.py +42 -0
- taguette/migrations/versions/807c0cc0ecf6_remove_invalid_hltags.py +43 -0
- taguette/migrations/versions/80b1cc9d4c22_add_user_email.py +35 -0
- taguette/migrations/versions/91ade71ccf4d_add_user_language.py +28 -0
- taguette/migrations/versions/955db2e523d1_add_collections_tables_and_associations_.py +60 -0
- taguette/migrations/versions/a1b2c3d4e5f6_add_user_hide_code_counts.py +28 -0
- taguette/migrations/versions/b23f3b7a638e_add_user_password_change_date.py +36 -0
- taguette/migrations/versions/b7c1e2d3f4a5_add_project_compact_layout.py +28 -0
- taguette/migrations/versions/bc8e0e0677e9_rename_command_fields.py +126 -0
- taguette/migrations/versions/bce44849c2f2_lowercase_logins.py +96 -0
- taguette/migrations/versions/ca076140922f_update_user_for_external_logins.py +32 -0
- taguette/migrations/versions/d86c45d7aa8a_add_document_direction.py +127 -0
- taguette/migrations/versions/db5e31a0233d_remove_blank_highlights.py +88 -0
- taguette/migrations/versions/dd37d9027a24_unique_tags.py +68 -0
- taguette/migrations/versions/de678cef2a94_add_project_id_to_collections_and_.py +41 -0
- taguette/migrations/versions/e459991d960e_add_table_edugainidps.py +39 -0
- taguette/migrations/versions/e4cf92942271_add_index.py +29 -0
- taguette/migrations/versions/e4e090a5b511_remove_commands_document_id_fk.py +38 -0
- taguette/migrations/versions/e9a9f1c77971_add_favorite_column_to_document.py +32 -0
- taguette/migrations/versions/ecb4065de575_don_t_use_server_default_now_timezone_.py +44 -0
- taguette/migrations/versions/fbdc29566f62_edugain_fix_field_type.py +42 -0
- taguette/migrations/versions/fdc6eb54b034_add_parent_id_column_to_tags_table.py +31 -0
- taguette/static/README.md +34 -0
- taguette/static/alt_templates/.gitkeep +0 -0
- taguette/static/assets/test/logos/monsters-university-logo.png +0 -0
- taguette/static/css/custom.css +1696 -0
- taguette/static/css/fa-all.min.css +5 -0
- taguette/static/css/themed.css +3 -0
- taguette/static/css/themed.css.map +25 -0
- taguette/static/css/vendor/bootstrap-treeview.min.css +1 -0
- taguette/static/css/vendor/bootstrap.min.css +6 -0
- taguette/static/css/vendor/font/context-menu-icons.eot +0 -0
- taguette/static/css/vendor/font/context-menu-icons.ttf +0 -0
- taguette/static/css/vendor/font/context-menu-icons.woff +0 -0
- taguette/static/css/vendor/font/context-menu-icons.woff2 +0 -0
- taguette/static/css/vendor/hierarchy-select.min.css +1 -0
- taguette/static/css/vendor/introjs.min.css +2 -0
- taguette/static/css/vendor/jquery.contextMenu.min.css +16 -0
- taguette/static/favicon.ico +0 -0
- taguette/static/js/codebook-viz.js +428 -0
- taguette/static/js/collection/context-menu.js +180 -0
- taguette/static/js/collection/hierarchy-select.js +71 -0
- taguette/static/js/collection/manager.js +217 -0
- taguette/static/js/document/context-menu.js +92 -0
- taguette/static/js/document/custom-select.js +82 -0
- taguette/static/js/document/manager.js +943 -0
- taguette/static/js/document/treeview.js +593 -0
- taguette/static/js/highlight/README.md +18 -0
- taguette/static/js/highlight/crud.js +119 -0
- taguette/static/js/highlight/extracts.js +497 -0
- taguette/static/js/highlight/loader.js +109 -0
- taguette/static/js/highlight/renderer.js +405 -0
- taguette/static/js/login.js +15 -0
- taguette/static/js/permissions.js +153 -0
- taguette/static/js/polling-event.js +145 -0
- taguette/static/js/project/intro.js +524 -0
- taguette/static/js/project/manager.js +0 -0
- taguette/static/js/project/search.js +124 -0
- taguette/static/js/tag/context-menu.js +133 -0
- taguette/static/js/tag/explore-codes.js +400 -0
- taguette/static/js/tag/hierarchy-select.js +69 -0
- taguette/static/js/tag/manager.js +545 -0
- taguette/static/js/tag/treeview.js +613 -0
- taguette/static/js/taguette.js +1790 -0
- taguette/static/js/utilities.js +714 -0
- taguette/static/js/vendor/bootstrap-treeview-custum.js +421 -0
- taguette/static/js/vendor/bootstrap-treeview-custum.min.js +1 -0
- taguette/static/js/vendor/bootstrap-treeview-default.min.js +1 -0
- taguette/static/js/vendor/bootstrap.bundle.min.js +7 -0
- taguette/static/js/vendor/bootstrap.bundle.min.js.map +1 -0
- taguette/static/js/vendor/hierarchy-select.min.js +1 -0
- taguette/static/js/vendor/introjs.min.js +17 -0
- taguette/static/js/vendor/jquery-3.7.1.js +2 -0
- taguette/static/js/vendor/jquery.contextMenu.min.js +2 -0
- taguette/static/libreqda.ico +0 -0
- taguette/static/logo-h.png +0 -0
- taguette/static/logo.png +0 -0
- taguette/static/logo_blanc.png +0 -0
- taguette/static/missing.png +0 -0
- taguette/static/robots.txt +2 -0
- taguette/static/scss/components/_badge.scss +42 -0
- taguette/static/scss/components/_button.scss +169 -0
- taguette/static/scss/components/_checkbox.scss +40 -0
- taguette/static/scss/components/_context_menu.scss +28 -0
- taguette/static/scss/components/_custom_select.scss +150 -0
- taguette/static/scss/components/_dropdown.scss +43 -0
- taguette/static/scss/components/_form.scss +54 -0
- taguette/static/scss/components/_modal.scss +57 -0
- taguette/static/scss/components/_project_card.scss +163 -0
- taguette/static/scss/components/_tag.scss +308 -0
- taguette/static/scss/components/_treeview.scss +76 -0
- taguette/static/scss/custom.scss +809 -0
- taguette/static/scss/layout/_credits.scss +62 -0
- taguette/static/scss/layout/_footer.scss +6 -0
- taguette/static/scss/layout/_navigation.scss +165 -0
- taguette/static/scss/layout/_sidebar.scss +37 -0
- taguette/static/scss/themes/default/_variables.scss +103 -0
- taguette/static/scss/themes/default/theme.css +3 -0
- taguette/static/scss/themes/default/theme.css.map +26 -0
- taguette/static/scss/themes/default/theme.scss +4 -0
- taguette/static/webfonts/BadScript-OFL.txt +94 -0
- taguette/static/webfonts/BadScript.ttf +0 -0
- taguette/static/webfonts/Montserrat-Light.ttf +0 -0
- taguette/static/webfonts/Montserrat-OFL.txt +93 -0
- taguette/static/webfonts/fa-brands-400.eot +0 -0
- taguette/static/webfonts/fa-brands-400.svg +1184 -0
- taguette/static/webfonts/fa-brands-400.ttf +0 -0
- taguette/static/webfonts/fa-brands-400.woff +0 -0
- taguette/static/webfonts/fa-brands-400.woff2 +0 -0
- taguette/static/webfonts/fa-regular-400.eot +0 -0
- taguette/static/webfonts/fa-regular-400.svg +467 -0
- taguette/static/webfonts/fa-regular-400.ttf +0 -0
- taguette/static/webfonts/fa-regular-400.woff +0 -0
- taguette/static/webfonts/fa-regular-400.woff2 +0 -0
- taguette/static/webfonts/fa-solid-900.eot +0 -0
- taguette/static/webfonts/fa-solid-900.svg +2618 -0
- taguette/static/webfonts/fa-solid-900.ttf +0 -0
- taguette/static/webfonts/fa-solid-900.woff +0 -0
- taguette/static/webfonts/fa-solid-900.woff2 +0 -0
- taguette/templates/alt_templates/.gitkeep +0 -0
- taguette/templates/archived_projects.html +50 -0
- taguette/templates/auth/account.html +74 -0
- taguette/templates/auth/cilogon.login.html +89 -0
- taguette/templates/auth/email_reset_password.html +5 -0
- taguette/templates/auth/external_account.html +60 -0
- taguette/templates/auth/login.html +144 -0
- taguette/templates/auth/reset_password.html +27 -0
- taguette/templates/auth/token_needed.html +7 -0
- taguette/templates/base.html +209 -0
- taguette/templates/bug_report.html +158 -0
- taguette/templates/cookies_prompt.html +15 -0
- taguette/templates/downloads.html +127 -0
- taguette/templates/email_bug_report.txt +9 -0
- taguette/templates/email_reset_password.txt +5 -0
- taguette/templates/error.html +8 -0
- taguette/templates/export_codebook.html +20 -0
- taguette/templates/export_document.html +20 -0
- taguette/templates/export_highlights.html +47 -0
- taguette/templates/index.html +347 -0
- taguette/templates/maintenance.html +8 -0
- taguette/templates/messages.js +74 -0
- taguette/templates/modal/change_document.html +68 -0
- taguette/templates/modal/create_collection.html +100 -0
- taguette/templates/modal/create_document.html +84 -0
- taguette/templates/modal/create_highlight.html +38 -0
- taguette/templates/modal/create_tag.html +73 -0
- taguette/templates/modal/explore_codes.html +58 -0
- taguette/templates/modal/manage_collaborators.html +44 -0
- taguette/templates/modal/merge_tag.html +49 -0
- taguette/templates/new_password.html +32 -0
- taguette/templates/partials/alert.html +16 -0
- taguette/templates/partials/codebook_viz_modal.html +34 -0
- taguette/templates/partials/confirm.html +17 -0
- taguette/templates/partials/document_toolbar.html +37 -0
- taguette/templates/partials/hlinfo.html +13 -0
- taguette/templates/partials/project_card.html +44 -0
- taguette/templates/partials/project_card_archived.html +41 -0
- taguette/templates/partials/project_sidebar.html +99 -0
- taguette/templates/partials/spinner.html +11 -0
- taguette/templates/permissions.html +54 -0
- taguette/templates/project.html +288 -0
- taguette/templates/project_delete.html +17 -0
- taguette/templates/project_import.html +122 -0
- taguette/templates/project_import_codebook.html +34 -0
- taguette/templates/project_import_codebook_confirm.html +49 -0
- taguette/templates/project_new.html +31 -0
- taguette/templates/tos.html +8 -0
- taguette/templates/trans.js +7 -0
- taguette/templates/welcome.html +15 -0
- taguette/utils.py +177 -0
- taguette/validate.py +141 -0
- taguette/version_check.py +102 -0
- taguette/web/__init__.py +252 -0
- taguette/web/api.py +1835 -0
- taguette/web/base.py +864 -0
- taguette/web/export.py +338 -0
- taguette/web/views.py +1618 -0
taguette/web/export.py
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
import logging
|
|
3
|
+
import os
|
|
4
|
+
import prometheus_client
|
|
5
|
+
import shutil
|
|
6
|
+
import string
|
|
7
|
+
import tempfile
|
|
8
|
+
from urllib.parse import quote
|
|
9
|
+
from tornado.web import authenticated
|
|
10
|
+
|
|
11
|
+
from .. import convert
|
|
12
|
+
from .. import database
|
|
13
|
+
from .. import export
|
|
14
|
+
from .base import BaseHandler
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
logger = logging.getLogger(__name__)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _content_disposition(filename):
|
|
21
|
+
# RFC 5987 encoding for non-ASCII filenames in HTTP headers
|
|
22
|
+
ascii_fallback = filename.encode('ascii', 'replace').decode('ascii')
|
|
23
|
+
encoded = quote(filename, safe='')
|
|
24
|
+
return (
|
|
25
|
+
'attachment; filename="%s"; filename*=UTF-8\'\'%s'
|
|
26
|
+
% (ascii_fallback, encoded)
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class WriteAdapter(object):
|
|
31
|
+
def __init__(self, write_func):
|
|
32
|
+
self.write = write_func
|
|
33
|
+
|
|
34
|
+
def flush(self):
|
|
35
|
+
pass
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
PROM_EXPORT = prometheus_client.Counter(
|
|
39
|
+
'export_total',
|
|
40
|
+
"Export",
|
|
41
|
+
['what', 'extension'],
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def init_PROM_EXPORT(w):
|
|
46
|
+
for e in convert.html_to_extensions:
|
|
47
|
+
PROM_EXPORT.labels(w, e).inc(0)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def return_doc(wrapped):
|
|
51
|
+
"""Decorator for returning a file, or a conversion error.
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
async def wrapper(self, *args):
|
|
55
|
+
ext = args[-1].lower()
|
|
56
|
+
try:
|
|
57
|
+
name, mimetype, contents = await wrapped(self, *args)
|
|
58
|
+
except convert.UnsupportedFormat:
|
|
59
|
+
self.set_status(404)
|
|
60
|
+
self.set_header('Content-Type', 'text/plain')
|
|
61
|
+
return await self.finish("Unsupported format: %s" % ext)
|
|
62
|
+
except convert.ConversionError as e:
|
|
63
|
+
self.set_status(500)
|
|
64
|
+
self.set_header('Content-Type', 'text/plain')
|
|
65
|
+
return await self.finish("Conversion error: %s" % e)
|
|
66
|
+
|
|
67
|
+
# Return document
|
|
68
|
+
self.set_header('Content-Type', mimetype)
|
|
69
|
+
if name:
|
|
70
|
+
self.set_header('Content-Disposition',
|
|
71
|
+
_content_disposition('%s.%s' % (name, ext)))
|
|
72
|
+
else:
|
|
73
|
+
self.set_header('Content-Disposition', 'attachment')
|
|
74
|
+
|
|
75
|
+
for chunk in contents:
|
|
76
|
+
self.write(chunk)
|
|
77
|
+
return await self.finish()
|
|
78
|
+
|
|
79
|
+
return wrapper
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class ExportHighlightsCsv(BaseHandler):
|
|
83
|
+
PROM_EXPORT.labels('highlights_doc', 'csv').inc(0)
|
|
84
|
+
|
|
85
|
+
@authenticated
|
|
86
|
+
def get(self, project_id, path):
|
|
87
|
+
PROM_EXPORT.labels('highlights_doc', 'csv').inc()
|
|
88
|
+
|
|
89
|
+
project, _ = self.get_project(project_id)
|
|
90
|
+
|
|
91
|
+
name = export.get_filename_for_highlights_export(path)
|
|
92
|
+
self.set_header('Content-Type', 'text/csv; charset=utf-8')
|
|
93
|
+
if name:
|
|
94
|
+
self.set_header('Content-Disposition',
|
|
95
|
+
_content_disposition('%s.csv' % name))
|
|
96
|
+
else:
|
|
97
|
+
self.set_header('Content-Disposition', 'attachment')
|
|
98
|
+
|
|
99
|
+
export.highlights_csv(
|
|
100
|
+
self.db,
|
|
101
|
+
project.id,
|
|
102
|
+
path,
|
|
103
|
+
WriteAdapter(self.write),
|
|
104
|
+
)
|
|
105
|
+
return self.finish()
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
class ExportHighlightsXlsx(BaseHandler):
|
|
109
|
+
PROM_EXPORT.labels('highlights_doc', 'xls').inc(0)
|
|
110
|
+
|
|
111
|
+
@authenticated
|
|
112
|
+
def get(self, project_id, path):
|
|
113
|
+
PROM_EXPORT.labels('highlights_doc', 'xls').inc()
|
|
114
|
+
|
|
115
|
+
project, _ = self.get_project(project_id)
|
|
116
|
+
|
|
117
|
+
name = export.get_filename_for_highlights_export(path)
|
|
118
|
+
self.set_header('Content-Type',
|
|
119
|
+
('application/vnd.openxmlformats-officedocument.'
|
|
120
|
+
'spreadsheetml.sheet'))
|
|
121
|
+
if name:
|
|
122
|
+
self.set_header('Content-Disposition',
|
|
123
|
+
_content_disposition('%s.xlsx' % name))
|
|
124
|
+
else:
|
|
125
|
+
self.set_header('Content-Disposition', 'attachment')
|
|
126
|
+
|
|
127
|
+
tmp = tempfile.mkdtemp(prefix='libreqda_xlsx_')
|
|
128
|
+
try:
|
|
129
|
+
filename = os.path.join(tmp, 'highlights.xlsx')
|
|
130
|
+
export.highlights_xslx(self.db, project.id, path, filename)
|
|
131
|
+
with open(filename, 'rb') as fp:
|
|
132
|
+
chunk = fp.read(4096)
|
|
133
|
+
self.write(chunk)
|
|
134
|
+
while len(chunk) == 4096:
|
|
135
|
+
chunk = fp.read(4096)
|
|
136
|
+
if chunk:
|
|
137
|
+
self.write(chunk)
|
|
138
|
+
return self.finish()
|
|
139
|
+
finally:
|
|
140
|
+
shutil.rmtree(tmp)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
class ExportHighlightsDoc(BaseHandler):
|
|
144
|
+
init_PROM_EXPORT('highlights_doc')
|
|
145
|
+
|
|
146
|
+
@authenticated
|
|
147
|
+
@return_doc
|
|
148
|
+
async def get(self, project_id, path, ext):
|
|
149
|
+
ext = ext.lower()
|
|
150
|
+
PROM_EXPORT.labels('highlights_doc', ext).inc()
|
|
151
|
+
|
|
152
|
+
project, _ = self.get_project(project_id)
|
|
153
|
+
|
|
154
|
+
# Close DB connection to not overflow the connection pool
|
|
155
|
+
self.close_db_connection()
|
|
156
|
+
|
|
157
|
+
name = export.get_filename_for_highlights_export(path)
|
|
158
|
+
mimetype, contents = export.highlights_doc(
|
|
159
|
+
self.db,
|
|
160
|
+
project.id,
|
|
161
|
+
path,
|
|
162
|
+
ext,
|
|
163
|
+
config=self.application.config,
|
|
164
|
+
locale=self.locale,
|
|
165
|
+
)
|
|
166
|
+
contents = await contents
|
|
167
|
+
return name, mimetype, contents
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
_safe_filename_chars = set(
|
|
171
|
+
string.ascii_letters
|
|
172
|
+
+ string.digits
|
|
173
|
+
+ ' ()+,-.=@[]_{}~'
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def safe_filename(name):
|
|
178
|
+
return ''.join(c for c in name if c in _safe_filename_chars)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
class ExportDocument(BaseHandler):
|
|
182
|
+
init_PROM_EXPORT('document')
|
|
183
|
+
|
|
184
|
+
@authenticated
|
|
185
|
+
@return_doc
|
|
186
|
+
async def get(self, project_id, document_id, ext):
|
|
187
|
+
PROM_EXPORT.labels('document', ext.lower()).inc()
|
|
188
|
+
doc, _ = self.get_document(project_id, document_id, True)
|
|
189
|
+
|
|
190
|
+
# Close DB connection to not overflow the connection pool
|
|
191
|
+
self.close_db_connection()
|
|
192
|
+
|
|
193
|
+
name = safe_filename(doc.name)
|
|
194
|
+
|
|
195
|
+
mimetype, contents = await export.highlighted_document(
|
|
196
|
+
self.db,
|
|
197
|
+
doc,
|
|
198
|
+
ext,
|
|
199
|
+
config=self.application.config,
|
|
200
|
+
locale=self.locale,
|
|
201
|
+
)
|
|
202
|
+
return name, mimetype, contents
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
class ExportCodebookXml(BaseHandler):
|
|
206
|
+
PROM_EXPORT.labels('codebook', 'qdc').inc(0)
|
|
207
|
+
|
|
208
|
+
@authenticated
|
|
209
|
+
def get(self, project_id):
|
|
210
|
+
PROM_EXPORT.labels('codebook', 'qdc').inc()
|
|
211
|
+
project, _ = self.get_project(project_id)
|
|
212
|
+
tags = list(project.tags)
|
|
213
|
+
self.set_header('Content-Type', 'text/xml; charset=utf-8')
|
|
214
|
+
self.set_header('Content-Disposition',
|
|
215
|
+
'attachment; filename="codebook.qdc"')
|
|
216
|
+
|
|
217
|
+
export.codebook_xml(tags, WriteAdapter(self.write))
|
|
218
|
+
return self.finish()
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
class ExportCodebookCsv(BaseHandler):
|
|
222
|
+
PROM_EXPORT.labels('codebook', 'csv').inc(0)
|
|
223
|
+
|
|
224
|
+
@authenticated
|
|
225
|
+
def get(self, project_id):
|
|
226
|
+
PROM_EXPORT.labels('codebook', 'csv').inc()
|
|
227
|
+
project, _ = self.get_project(project_id)
|
|
228
|
+
tags = list(project.tags)
|
|
229
|
+
self.set_header('Content-Type', 'text/csv; charset=utf-8')
|
|
230
|
+
self.set_header('Content-Disposition',
|
|
231
|
+
'attachment; filename="codebook.csv"')
|
|
232
|
+
export.codebook_csv(tags, WriteAdapter(self.write))
|
|
233
|
+
return self.finish()
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
class ExportCodebookXlsx(BaseHandler):
|
|
237
|
+
PROM_EXPORT.labels('codebook', 'xls').inc(0)
|
|
238
|
+
|
|
239
|
+
@authenticated
|
|
240
|
+
def get(self, project_id):
|
|
241
|
+
PROM_EXPORT.labels('codebook', 'xls').inc()
|
|
242
|
+
project, _ = self.get_project(project_id)
|
|
243
|
+
tags = list(project.tags)
|
|
244
|
+
self.set_header('Content-Type',
|
|
245
|
+
('application/vnd.openxmlformats-officedocument.'
|
|
246
|
+
'spreadsheetml.sheet'))
|
|
247
|
+
self.set_header('Content-Disposition',
|
|
248
|
+
'attachment; filename="codebook.xlsx"')
|
|
249
|
+
tmp = tempfile.mkdtemp(prefix='libreqda_xlsx_')
|
|
250
|
+
try:
|
|
251
|
+
filename = os.path.join(tmp, 'codebook.xlsx')
|
|
252
|
+
|
|
253
|
+
export.codebook_xlsx(tags, filename)
|
|
254
|
+
|
|
255
|
+
with open(filename, 'rb') as fp:
|
|
256
|
+
chunk = fp.read(4096)
|
|
257
|
+
self.write(chunk)
|
|
258
|
+
while len(chunk) == 4096:
|
|
259
|
+
chunk = fp.read(4096)
|
|
260
|
+
if chunk:
|
|
261
|
+
self.write(chunk)
|
|
262
|
+
return self.finish()
|
|
263
|
+
finally:
|
|
264
|
+
shutil.rmtree(tmp)
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
class ExportCodebookDoc(BaseHandler):
|
|
268
|
+
init_PROM_EXPORT('codebook')
|
|
269
|
+
|
|
270
|
+
@authenticated
|
|
271
|
+
@return_doc
|
|
272
|
+
async def get(self, project_id, ext):
|
|
273
|
+
ext = ext.lower()
|
|
274
|
+
PROM_EXPORT.labels('codebook', ext).inc()
|
|
275
|
+
project, _ = self.get_project(project_id)
|
|
276
|
+
tags = list(project.tags)
|
|
277
|
+
|
|
278
|
+
# Close DB connection to not overflow the connection pool
|
|
279
|
+
self.close_db_connection()
|
|
280
|
+
|
|
281
|
+
mimetype, contents = await export.codebook_document(
|
|
282
|
+
tags,
|
|
283
|
+
ext,
|
|
284
|
+
config=self.application.config,
|
|
285
|
+
locale=self.locale,
|
|
286
|
+
)
|
|
287
|
+
return 'codebook', mimetype, contents
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
class ExportSqlite(BaseHandler):
|
|
291
|
+
PROM_EXPORT.labels('project', 'sqlite3').inc(0)
|
|
292
|
+
|
|
293
|
+
@authenticated
|
|
294
|
+
async def get(self, project_id):
|
|
295
|
+
PROM_EXPORT.labels('project', 'sqlite3').inc()
|
|
296
|
+
project, _ = self.get_project(project_id)
|
|
297
|
+
|
|
298
|
+
# Result filename
|
|
299
|
+
export_name = '%s_%s.sqlite3' % (
|
|
300
|
+
datetime.utcnow().strftime('%Y-%m-%d'),
|
|
301
|
+
safe_filename(project.name),
|
|
302
|
+
)
|
|
303
|
+
|
|
304
|
+
with tempfile.TemporaryDirectory(
|
|
305
|
+
prefix='taguette_export_',
|
|
306
|
+
) as tmp_dir:
|
|
307
|
+
filename = os.path.join(tmp_dir, 'db.sqlite3')
|
|
308
|
+
|
|
309
|
+
# Connect to database
|
|
310
|
+
dest_db = database.connect('sqlite:///%s' % filename)()
|
|
311
|
+
|
|
312
|
+
# Create user
|
|
313
|
+
admin = database.User(login='admin')
|
|
314
|
+
dest_db.add(admin)
|
|
315
|
+
dest_db.commit()
|
|
316
|
+
|
|
317
|
+
# Copy data
|
|
318
|
+
database.copy_project(
|
|
319
|
+
self.db, dest_db,
|
|
320
|
+
project.id, 'admin',
|
|
321
|
+
)
|
|
322
|
+
dest_db.commit()
|
|
323
|
+
|
|
324
|
+
# Close DB connection to not overflow the connection pool
|
|
325
|
+
self.close_db_connection()
|
|
326
|
+
|
|
327
|
+
# Send the file
|
|
328
|
+
self.set_header('Content-Type', 'application/vnd.sqlite3')
|
|
329
|
+
self.set_header('Content-Disposition',
|
|
330
|
+
_content_disposition(export_name))
|
|
331
|
+
with open(filename, 'rb') as fp:
|
|
332
|
+
while True:
|
|
333
|
+
chunk = fp.read(4096)
|
|
334
|
+
self.write(chunk)
|
|
335
|
+
if len(chunk) != 4096:
|
|
336
|
+
break
|
|
337
|
+
await self.flush()
|
|
338
|
+
return await self.finish()
|