Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
EvaP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CourseEval
EvaP
Commits
13327f01
Unverified
Commit
13327f01
authored
3 years ago
by
Niklas Mohrin
Browse files
Options
Downloads
Patches
Plain Diff
Update `Evaluation.state` values in log entries too
parent
1e936a76
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
evap/evaluation/migrations/0123_evaluation_state_fsm_int.py
+28
-5
28 additions, 5 deletions
evap/evaluation/migrations/0123_evaluation_state_fsm_int.py
evap/evaluation/migrations/0127_fix_logentry_types.py
+19
-0
19 additions, 0 deletions
evap/evaluation/migrations/0127_fix_logentry_types.py
with
47 additions
and
5 deletions
evap/evaluation/migrations/0123_evaluation_state_fsm_int.py
+
28
−
5
View file @
13327f01
from
django.db
import
migrations
import
django_fsm
# as defined in the Evaluation model
...
...
@@ -24,28 +23,52 @@ CONVERSION = {
"
reviewed
"
:
State
.
REVIEWED
,
"
published
"
:
State
.
PUBLISHED
,
}
REV_CONVERSION
=
{
val
:
key
for
key
,
val
in
CONVERSION
.
items
()}
def
str_to_int
(
apps
,
_schema_editor
):
def
model_
str_to_int
(
apps
,
_schema_editor
):
Evaluation
=
apps
.
get_model
(
"
evaluation
"
,
"
Evaluation
"
)
for
string_type
,
int_type
in
CONVERSION
.
items
():
Evaluation
.
objects
.
filter
(
state
=
string_type
).
update
(
int_state
=
int_type
)
def
int_to_str
(
apps
,
_schema_editor
):
def
model_
int_to_str
(
apps
,
_schema_editor
):
Evaluation
=
apps
.
get_model
(
"
evaluation
"
,
"
Evaluation
"
)
for
string_type
,
int_type
in
CONVERSION
.
items
():
Evaluation
.
objects
.
filter
(
int_state
=
int_type
).
update
(
state
=
string_type
)
def
logentries_str_to_int
(
apps
,
_schema_editor
):
LogEntry
=
apps
.
get_model
(
"
evaluation
"
,
"
LogEntry
"
)
for
entry
in
LogEntry
.
objects
.
filter
(
content_type__app_label
=
"
evaluation
"
,
content_type__model
=
"
evaluation
"
):
if
"
state
"
in
entry
.
data
:
for
key
in
entry
.
data
[
"
state
"
]:
entry
.
data
[
"
state
"
][
key
]
=
[
CONVERSION
[
val
]
if
val
in
CONVERSION
else
val
for
val
in
entry
.
data
[
"
state
"
][
key
]
]
entry
.
save
()
def
logentries_int_to_str
(
apps
,
_schema_editor
):
LogEntry
=
apps
.
get_model
(
"
evaluation
"
,
"
LogEntry
"
)
for
entry
in
LogEntry
.
objects
.
filter
(
content_type__app_label
=
"
evaluation
"
,
content_type__model
=
"
evaluation
"
):
if
"
state
"
in
entry
.
data
:
for
key
in
entry
.
data
[
"
state
"
]:
entry
.
data
[
"
state
"
][
key
]
=
[
REV_CONVERSION
[
val
]
if
val
in
REV_CONVERSION
else
val
for
val
in
entry
.
data
[
"
state
"
][
key
]
]
entry
.
save
()
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'
evaluation
'
,
'
0122_prepare_evaluation_state_fsm_int
'
),
(
"
evaluation
"
,
"
0122_prepare_evaluation_state_fsm_int
"
),
]
operations
=
[
migrations
.
RunPython
(
str_to_int
,
int_to_str
),
migrations
.
RunPython
(
model_str_to_int
,
model_int_to_str
),
migrations
.
RunPython
(
logentries_str_to_int
,
logentries_int_to_str
),
migrations
.
RemoveField
(
model_name
=
"
evaluation
"
,
name
=
"
state
"
,
...
...
This diff is collapsed.
Click to expand it.
evap/evaluation/migrations/0127_fix_logentry_types.py
0 → 100644
+
19
−
0
View file @
13327f01
import
importlib
from
django.db
import
migrations
original_migration_module
=
importlib
.
import_module
(
"
evap.evaluation.migrations.0123_evaluation_state_fsm_int
"
)
class
Migration
(
migrations
.
Migration
):
"""
Initially, we forgot to migrate logentries in 0123, so this migration cleans this up.
Note that 0123 is now modified to also take care of the logentries in the first place.
"""
dependencies
=
[
(
"
evaluation
"
,
"
0126_add_textanswer_review_email_template
"
),
]
operations
=
[
migrations
.
RunPython
(
original_migration_module
.
logentries_str_to_int
,
migrations
.
RunPython
.
noop
),
]
This diff is collapsed.
Click to expand it.
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