From 4ec2371b44e028743a0712fe262fd4d1cfd35252 Mon Sep 17 00:00:00 2001 From: Alexander Watzinger Date: Wed, 29 Nov 2023 16:54:48 +0100 Subject: [PATCH] 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,