Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Odevzdávací Systém MO
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Mareš
Odevzdávací Systém MO
Commits
d64b1cb2
Commit
d64b1cb2
authored
1 year ago
by
Martin Mareš
Browse files
Options
Downloads
Patches
Plain Diff
Import: Varování jsou fatální, ale jdou overridovat
parent
1bded84c
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
mo/imports.py
+4
-4
4 additions, 4 deletions
mo/imports.py
mo/web/imports.py
+2
-1
2 additions, 1 deletion
mo/web/imports.py
mo/web/templates/org_generic_import.html
+6
-0
6 additions, 0 deletions
mo/web/templates/org_generic_import.html
with
12 additions
and
5 deletions
mo/imports.py
+
4
−
4
View file @
d64b1cb2
...
@@ -383,7 +383,7 @@ class Import:
...
@@ -383,7 +383,7 @@ class Import:
return
row
.
email
# type: ignore
return
row
.
email
# type: ignore
return
None
return
None
def
generic_import
(
self
,
path
:
str
)
->
bool
:
def
generic_import
(
self
,
path
:
str
,
despite_warnings
:
bool
)
->
bool
:
charset
=
self
.
fmt
.
get_charset
()
charset
=
self
.
fmt
.
get_charset
()
if
charset
!=
'
utf-8
'
and
self
.
check_utf8
(
path
):
if
charset
!=
'
utf-8
'
and
self
.
check_utf8
(
path
):
logger
.
info
(
'
Import: Uhodnuto kódování utf-8
'
)
logger
.
info
(
'
Import: Uhodnuto kódování utf-8
'
)
...
@@ -412,7 +412,7 @@ class Import:
...
@@ -412,7 +412,7 @@ class Import:
self
.
line_number
+=
1
self
.
line_number
+=
1
self
.
row_name
=
None
self
.
row_name
=
None
return
len
(
self
.
errors
)
==
0
return
len
(
self
.
errors
)
==
0
and
(
len
(
self
.
warnings
)
==
0
or
despite_warnings
)
def
notify_users
(
self
)
->
None
:
def
notify_users
(
self
)
->
None
:
# Projde všechny uživatele a těm, kteří ještě nemají nastavené heslo,
# Projde všechny uživatele a těm, kteří ještě nemají nastavené heslo,
...
@@ -436,10 +436,10 @@ class Import:
...
@@ -436,10 +436,10 @@ class Import:
mo
.
csv
.
write
(
file
=
out
,
fmt
=
self
.
fmt
,
row_class
=
self
.
row_class
,
rows
=
[
self
.
row_example
])
mo
.
csv
.
write
(
file
=
out
,
fmt
=
self
.
fmt
,
row_class
=
self
.
row_class
,
rows
=
[
self
.
row_example
])
return
out
.
getvalue
()
return
out
.
getvalue
()
def
run
(
self
,
path
:
str
)
->
bool
:
def
run
(
self
,
path
:
str
,
despite_warnings
:
bool
=
False
)
->
bool
:
self
.
log_start
(
path
)
self
.
log_start
(
path
)
if
not
self
.
generic_import
(
path
):
if
not
self
.
generic_import
(
path
,
despite_warnings
):
logger
.
info
(
'
Import: Rollback
'
)
logger
.
info
(
'
Import: Rollback
'
)
db
.
get_session
().
rollback
()
db
.
get_session
().
rollback
()
return
False
return
False
...
...
This diff is collapsed.
Click to expand it.
mo/web/imports.py
+
2
−
1
View file @
d64b1cb2
...
@@ -19,6 +19,7 @@ class ImportForm(FlaskForm):
...
@@ -19,6 +19,7 @@ class ImportForm(FlaskForm):
choices
=
FileFormat
.
choices
(),
coerce
=
FileFormat
.
coerce
,
choices
=
FileFormat
.
choices
(),
coerce
=
FileFormat
.
coerce
,
default
=
FileFormat
.
cs_csv
,
default
=
FileFormat
.
cs_csv
,
)
)
despite_warnings
=
wtforms
.
BooleanField
(
'
Importovat navzdory varováním
'
)
submit
=
wtforms
.
SubmitField
(
'
Importovat
'
)
submit
=
wtforms
.
SubmitField
(
'
Importovat
'
)
get_template
=
wtforms
.
SubmitField
(
'
Stáhnout šablonu
'
)
get_template
=
wtforms
.
SubmitField
(
'
Stáhnout šablonu
'
)
...
@@ -35,7 +36,7 @@ def generic_import_page(form: ImportForm, imp: Optional[Import], redirect_url: s
...
@@ -35,7 +36,7 @@ def generic_import_page(form: ImportForm, imp: Optional[Import], redirect_url: s
file
=
form
.
file
.
data
.
stream
file
=
form
.
file
.
data
.
stream
import_tmp
=
mo
.
util
.
link_to_dir
(
file
.
name
,
mo
.
util
.
data_dir
(
'
imports
'
),
suffix
=
'
.csv
'
)
import_tmp
=
mo
.
util
.
link_to_dir
(
file
.
name
,
mo
.
util
.
data_dir
(
'
imports
'
),
suffix
=
'
.csv
'
)
if
imp
.
run
(
import_tmp
):
if
imp
.
run
(
import_tmp
,
despite_warnings
=
form
.
despite_warnings
.
data
):
if
imp
.
cnt_rows
==
0
:
if
imp
.
cnt_rows
==
0
:
flash
(
'
Soubor neobsahoval žádné řádky s daty
'
,
'
danger
'
)
flash
(
'
Soubor neobsahoval žádné řádky s daty
'
,
'
danger
'
)
else
:
else
:
...
...
This diff is collapsed.
Click to expand it.
mo/web/templates/org_generic_import.html
+
6
−
0
View file @
d64b1cb2
...
@@ -14,7 +14,12 @@ Import dat {% if contest or round %}do {% if contest %}soutěže {{ contest.plac
...
@@ -14,7 +14,12 @@ Import dat {% if contest or round %}do {% if contest %}soutěže {{ contest.plac
{% for e in warnings %}
{% for e in warnings %}
{{ e }}
{{ e }}
{% endfor %}
{% endfor %}
{% if not errs %}
<em>
Aby se import provedl, zopakujte ho znovu se zaškrtnutým „Importovat navzdory varováním“.
</em>
{% endif %}
</div>
</div>
{% endif %}
{% endif %}
{% if errs %}
{% if errs %}
...
@@ -38,6 +43,7 @@ Import dat {% if contest or round %}do {% if contest %}soutěže {{ contest.plac
...
@@ -38,6 +43,7 @@ Import dat {% if contest or round %}do {% if contest %}soutěže {{ contest.plac
{{ form.csrf_token }}
{{ form.csrf_token }}
{{ wtf.form_field(form.file) }}
{{ wtf.form_field(form.file) }}
{{ wtf.form_field(form.fmt) }}
{{ wtf.form_field(form.fmt) }}
{{ wtf.form_field(form.despite_warnings) }}
{% block import_form %}{% endblock %}
{% block import_form %}{% endblock %}
<div
class=
"btn-group"
>
<div
class=
"btn-group"
>
{{ wtf.form_field(form.submit, class='btn btn-primary') }}
{{ wtf.form_field(form.submit, class='btn btn-primary') }}
...
...
This diff is collapsed.
Click to expand it.
Martin Mareš
@mj
mentioned in commit
7ad76c4c
·
1 year ago
mentioned in commit
7ad76c4c
mentioned in commit 7ad76c4c5d14d089fb3ab159c02e3abdb9835e74
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment