Skip to content
Snippets Groups Projects
Commit fe458775 authored by Martin Mareš's avatar Martin Mareš
Browse files

Import: Nastane-li varování, vypíšeme potvrzovací stránku

To snad bude pro uživatele přívětivější než chtít provést nový
import navzdory varováním.
parent fe5b030b
No related branches found
No related tags found
No related merge requests found
......@@ -27,6 +27,8 @@ def generic_import_page(form: ImportForm, imp: Optional[Import], redirect_url: s
# Případné další parametry (**kwargs) jsou předávány generování stránky
errs = []
warnings = []
confirm_only = False
if imp:
fmt = form.fmt.data
imp.fmt = fmt
......@@ -35,15 +37,19 @@ def generic_import_page(form: ImportForm, imp: Optional[Import], redirect_url: s
file = form.file.data.stream
import_tmp = mo.util.link_to_dir(file.name, mo.util.data_dir('imports'), suffix='.csv')
if imp.run(import_tmp):
success = imp.run(import_tmp)
errs = imp.errors
warnings = imp.warnings
if success:
if imp.cnt_rows == 0:
flash('Soubor neobsahoval žádné řádky s daty', 'danger')
else:
flash(imp.get_after_import_message(), 'success')
return redirect(redirect_url)
if imp.warnings:
confirm_only = True
else:
errs = imp.errors
warnings = imp.warnings
return redirect(redirect_url)
else:
flash('Vyberte si prosím soubor', 'danger')
elif form.get_template.data:
......@@ -58,6 +64,8 @@ def generic_import_page(form: ImportForm, imp: Optional[Import], redirect_url: s
errs=errs,
warnings=warnings,
form=form,
confirm_only=confirm_only,
redirect_url=redirect_url,
imp=imp,
**kwargs
)
......@@ -6,27 +6,37 @@ Import dat {% if contest or round %}do {% if contest %}soutěže {{ contest.plac
{% endblock %}
{% block body %}
{% block import_errs %}
{% if warnings %}
<h3>Varování při importu</h3>
<div class="alert alert-warning" role="alert" style="white-space: pre-line">{{ "" -}}
{% for e in warnings %}
{{ e }}
{% if confirm_only %}
Varování nebránila dokončení importu.
{% endif %}
{% endfor %}
</div>
{% endif %}
{% if errs %}
<h3>Chyby při importu</h3>
<div class="alert alert-danger" role="alert" style="white-space: pre-line">{{ "" -}}
{% for e in errs %}
{{ e }}
Jelikož došlo k chybám, import nebyl proveden.
{% endfor %}
</div>
{% endif %}
{% endblock %}
{% if confirm_only %}
{# Pokud import proběhl správně, ale vypsal warningy, nezobrazujeme formulář, jen tlačítko na potvrzení. #}
<div class="btn-group">
<a class="btn btn-primary" href='{{ redirect_url }}'>Hotovo</a>
</div>
{% else %}
{% block import_info %}{% endblock %}
......@@ -45,5 +55,6 @@ Import dat {% if contest or round %}do {% if contest %}soutěže {{ contest.plac
</div>
</form>
{% endif %}
{% endblock %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment