Skip to content

Commit 050e85b

Browse files
authored
Merge pull request learningequality#5731 from rtibbles/you_complete_me
Add additional completion to exercises that have already had their completion criteria fixed but their complete value is still wrong
2 parents 1824744 + b2984a0 commit 050e85b

3 files changed

Lines changed: 46 additions & 2 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ migrate:
3838
# 4) Remove the management command from this `deploy-migrate` recipe
3939
# 5) Repeat!
4040
deploy-migrate:
41-
echo "Nothing to do here!"
41+
python contentcuration/manage.py fix_exercise_extra_fields
4242

4343
contentnodegc:
4444
python contentcuration/manage.py garbage_collect

contentcuration/contentcuration/management/commands/fix_exercise_extra_fields.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def handle(self, *args, **options):
6565
migrated_complete = 0
6666
old_style_fixed = 0
6767
old_style_complete = 0
68+
incomplete_fixed = 0
6869
exercises_checked = 0
6970

7071
for node in queryset.iterator(chunk_size=CHUNKSIZE):
@@ -77,6 +78,8 @@ def handle(self, *args, **options):
7778
migrated_fixed += 1
7879
if complete:
7980
migrated_complete += 1
81+
elif fix_type == "incomplete" and complete:
82+
incomplete_fixed += 1
8083
exercises_checked += 1
8184
if exercises_checked % CHUNKSIZE == 0:
8285
logging.info(
@@ -92,6 +95,11 @@ def handle(self, *args, **options):
9295
migrated_complete, migrated_fixed
9396
)
9497
)
98+
logging.info(
99+
"{} marked complete that were previously incomplete".format(
100+
incomplete_fixed
101+
)
102+
)
95103

96104
logging.info("{} / {} exercises checked".format(exercises_checked, total))
97105
logging.info(
@@ -104,18 +112,26 @@ def handle(self, *args, **options):
104112
migrated_complete, migrated_fixed
105113
)
106114
)
115+
logging.info(
116+
"{} marked complete that were previously incomplete".format(
117+
incomplete_fixed
118+
)
119+
)
107120
logging.info(
108121
"Done in {:.1f}s. Fixed {} migrated exercises, "
109-
"migrated {} old-style exercises.{}".format(
122+
"migrated {} old-style exercises."
123+
"marked {} previously incomplete exercises complete. {}".format(
110124
time.time() - start,
111125
migrated_fixed,
112126
old_style_fixed,
127+
incomplete_fixed,
113128
" (dry run)" if dry_run else "",
114129
)
115130
)
116131

117132
def _process_node(self, node, dry_run):
118133
ef = node.extra_fields
134+
was_complete = node.complete
119135
if isinstance(ef, str):
120136
try:
121137
ef = json.loads(ef)
@@ -131,6 +147,8 @@ def _process_node(self, node, dry_run):
131147
ef["options"]["completion_criteria"]["threshold"]["m"] = None
132148
ef["options"]["completion_criteria"]["threshold"]["n"] = None
133149
fix_type = "m_n_fix"
150+
elif not was_complete:
151+
fix_type = "incomplete"
134152
else:
135153
return None, None
136154
node.extra_fields = ef

contentcuration/contentcuration/tests/test_contentnodes.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,6 +1817,32 @@ def test_dry_run_does_not_modify(self):
18171817
self.assertEqual(threshold["m"], 0)
18181818
self.assertEqual(threshold["n"], 0)
18191819

1820+
def test_incomplete_node_with_valid_fields_gets_marked_complete(self):
1821+
"""An incomplete exercise with valid extra_fields should be marked complete."""
1822+
node = self._create_exercise(
1823+
{
1824+
"options": {
1825+
"completion_criteria": {
1826+
"threshold": {
1827+
"mastery_model": exercises.DO_ALL,
1828+
"m": None,
1829+
"n": None,
1830+
},
1831+
"model": completion_criteria.MASTERY,
1832+
}
1833+
},
1834+
}
1835+
)
1836+
# Force incomplete status even though fields are valid
1837+
node.complete = False
1838+
node.save()
1839+
1840+
command = FixExerciseExtraFieldsCommand()
1841+
command.handle()
1842+
1843+
node.refresh_from_db()
1844+
self.assertTrue(node.complete)
1845+
18201846
def test_migrates_string_extra_fields(self):
18211847
"""Command should parse and migrate extra_fields stored as a JSON string."""
18221848
node = self._create_exercise(

0 commit comments

Comments
 (0)