From 4ec2371b44e028743a0712fe262fd4d1cfd35252 Mon Sep 17 00:00:00 2001 From: Alexander Watzinger Date: Wed, 29 Nov 2023 16:54:48 +0100 Subject: [PATCH 1/2] Refactored import view --- openatlas/templates/import/project_view.html | 20 ----------- .../templates/{import => }/import_data.html | 0 openatlas/views/imports.py | 34 ++++++++++++++++--- 3 files changed, 30 insertions(+), 24 deletions(-) delete mode 100644 openatlas/templates/import/project_view.html rename openatlas/templates/{import => }/import_data.html (100%) diff --git a/openatlas/templates/import/project_view.html b/openatlas/templates/import/project_view.html deleted file mode 100644 index 885589594..000000000 --- a/openatlas/templates/import/project_view.html +++ /dev/null @@ -1,20 +0,0 @@ -{% if 'manager'|is_authorized %} -
- {{ 'admin/import'|manual|safe }} - {{ _('edit')|button(url_for('import_project_update', id_=project.id))|safe }} - {{ _('delete')|button( - url_for('import_project_delete', id_=project.id), - onclick="return confirm('" + _('delete %(name)s?', name=project.name)|replace("'", "")|uc_first + "')")|safe }} -
-

{{ _('new import')|uc_first }}:

-
- {{ _('source')|button(url_for('import_data', project_id=project.id, class_='source'))|safe }} - {% for class_ in g.view_class_mapping.event + g.view_class_mapping.actor %} - {{ _(class_)|button(url_for('import_data', project_id=project.id, class_=class_))|safe }} - {% endfor %} - {{ _('place')|button(url_for('import_data', project_id=project.id, class_='place'))|safe }} - {{ _('bibliography')|button(url_for('import_data', project_id=project.id, class_='bibliography'))|safe }} - {{ _('edition')|button(url_for('import_data', project_id=project.id, class_='edition'))|safe }} -
-{% endif %} -{{ project.description|description|safe }} diff --git a/openatlas/templates/import/import_data.html b/openatlas/templates/import_data.html similarity index 100% rename from openatlas/templates/import/import_data.html rename to openatlas/templates/import_data.html diff --git a/openatlas/views/imports.py b/openatlas/views/imports.py index 133edccbc..0128c6bcd 100644 --- a/openatlas/views/imports.py +++ b/openatlas/views/imports.py @@ -18,7 +18,8 @@ from openatlas.display.table import Table from openatlas.display.util import ( button, datetime64_to_timestamp, display_form, format_date, - get_backup_file_data, is_authorized, link, manual, required_group) + get_backup_file_data, is_authorized, link, manual, required_group, + button_bar, uc_first, description) from openatlas.forms.field import SubmitField from openatlas.models.entity import Entity from openatlas.models.imports import Import, is_float @@ -88,10 +89,35 @@ def import_project_insert() -> Union[str, Response]: @required_group('contributor') def import_project_view(id_: int) -> str: project = Import.get_project_by_id(id_) + content = '' + if is_authorized('manager'): + content = button_bar([ + manual('admin/import'), + button( + _('edit'), + url_for('import_project_update', id_=project.id)), + button( + _('delete'), + url_for('import_project_delete', id_=project.id), + onclick="return confirm('" + + _('delete %(name)s?', name=project.name.replace("'", "")) + + "')")]) + content += '

' + uc_first(_('new import')) + ':

' + buttons = [] + for class_ in \ + ['source'] \ + + g.view_class_mapping['event'] \ + + g.view_class_mapping['actor'] \ + + ['place', 'bibliography', 'edition']: + buttons.append(button( + _(class_), + url_for('import_data', project_id=project.id, class_=class_))) + content += button_bar(buttons) + content += description(project.description) tabs = { 'info': Tab( 'info', - render_template('import/project_view.html', project=project)), + content=content), 'entities': Tab( 'entities', table=Table( @@ -282,7 +308,7 @@ def import_data(project_id: int, class_: str) -> str: g.logger.log('error', 'import', 'import check failed', e) flash(_('error at import'), 'error') return render_template( - 'import/import_data.html', + 'import_data.html', form=form, messages=messages, file_data=file_data, @@ -307,7 +333,7 @@ def import_data(project_id: int, class_: str) -> str: g.logger.log('error', 'import', 'import failed', e) flash(_('error transaction'), 'error') return render_template( - 'import/import_data.html', + 'import_data.html', form=form, file_data=file_data, table=table, From 80448186a96e93f2e2391d8e13a3771f0ceaaf5e Mon Sep 17 00:00:00 2001 From: Alexander Watzinger Date: Fri, 1 Dec 2023 14:28:52 +0100 Subject: [PATCH 2/2] Pylint and Mypy checks --- openatlas/api/endpoints/content.py | 3 ++- openatlas/models/export.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/openatlas/api/endpoints/content.py b/openatlas/api/endpoints/content.py index 56d7e146d..3b408c1d6 100644 --- a/openatlas/api/endpoints/content.py +++ b/openatlas/api/endpoints/content.py @@ -56,7 +56,8 @@ class ClassMapping(Resource): def get() -> Union[tuple[Resource, int], Response]: return marshal([{ "systemClass": class_.name, - "crmClass": class_.cidoc_class.code if class_.cidoc_class else None, + "crmClass": + class_.cidoc_class.code if class_.cidoc_class else None, "view": class_.view, "standardTypeId": class_.standard_type_id, "icon": class_.icon, diff --git a/openatlas/models/export.py b/openatlas/models/export.py index 3ed330e2c..37e4d1f51 100644 --- a/openatlas/models/export.py +++ b/openatlas/models/export.py @@ -3,7 +3,7 @@ import subprocess from datetime import datetime from pathlib import Path -from typing import Optional +from typing import Any, Optional from openatlas import app @@ -18,8 +18,8 @@ def current_date_for_filename() -> str: def sql_export(format_: str, postfix: Optional[str] = '') -> bool: file = app.config['EXPORT_PATH'] \ / f'{current_date_for_filename()}_export{postfix}.{format_}' - command = ["pg_dump" if os.name == 'posix' - else Path(shutil.which("pg_dump.exe"))] + command: Any = [ + "pg_dump" if os.name == 'posix' else Path(shutil.which("pg_dump.exe"))] if format_ == 'dump': command.append('-Fc') command.extend([