Skip to content
This repository was archived by the owner on Jun 30, 2024. It is now read-only.

Commit 4ce2b1a

Browse files
committed
Because of the new changes, I cannot get auth.user.course_name anymore in the assignments.py practice action, instead I get base_course from the course object to mathch with the corresponding db.chapters.course_id.
1 parent 9068285 commit 4ce2b1a

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

controllers/assignments.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ def practice():
769769
float(session.timezoneoffset) if 'timezoneoffset' in session else 0)
770770

771771
if message1 != "":
772-
session.flash = message1 + " " + message2
772+
# session.flash = message1 + " " + message2
773773
return redirect(URL('practiceNotStartedYet',
774774
vars=dict(message1=message1,
775775
message2=message2)))
@@ -781,7 +781,7 @@ def practice():
781781
(db.user_topic_practice.user_id == auth.user.id) &
782782
(db.user_topic_practice.chapter_label == db.chapters.chapter_label) &
783783
(db.user_topic_practice.sub_chapter_label == db.sub_chapters.sub_chapter_label) &
784-
(db.chapters.course_id == auth.user.course_name) &
784+
(db.chapters.course_id == course.base_course) &
785785
(db.sub_chapters.chapter_id == db.chapters.id)) \
786786
.select(db.chapters.chapter_name,
787787
db.sub_chapters.sub_chapter_name,
@@ -814,20 +814,31 @@ def practice():
814814
elif f_card["mastery_percent"] >= 25:
815815
f_card["mastery_color"] = "warning"
816816

817-
# If the student has any flashcards to practice and has not practiced enough to get their points for today or they
818-
# have intrinsic motivation to practice beyond what they are expected to do.
819-
if available_flashcards_num > 0 and (practiced_today_count != questions_to_complete_day or
820-
request.vars.willing_to_continue or
821-
spacing == 0):
817+
# If an instructor removes the practice flag from a question in the middle of the semester
818+
# and students are in the middle of practicing it, the following code makes sure the practice tool does not crash.
819+
questions = []
820+
if len(presentable_flashcards) > 0:
822821
# Present the first one.
823822
flashcard = presentable_flashcards[0]
824823
# Get eligible questions.
825824
questions = _get_qualified_questions(course.base_course,
826825
flashcard.chapter_label,
827826
flashcard.sub_chapter_label)
827+
# If the student has any flashcards to practice and has not practiced enough to get their points for today or they
828+
# have intrinsic motivation to practice beyond what they are expected to do.
829+
if (available_flashcards_num > 0 and
830+
len(questions) > 0 and
831+
(practiced_today_count != questions_to_complete_day or
832+
request.vars.willing_to_continue or
833+
spacing == 0)):
828834
# Find index of the last question asked.
829835
question_names = [q.name for q in questions]
830-
qIndex = question_names.index(flashcard.question_name)
836+
837+
try:
838+
qIndex = question_names.index(flashcard.question_name)
839+
except:
840+
qIndex = 0
841+
831842
# present the next one in the list after the last one that was asked
832843
question = questions[(qIndex + 1) % len(questions)]
833844

@@ -868,15 +879,15 @@ def practice():
868879
course_name=auth.user.course_name,
869880
practice_completion_date=now_local.date()
870881
)
882+
practice_completion_count = _get_practice_completion(auth.user.id,
883+
auth.user.course_name,
884+
spacing)
871885
if practice_graded == 1:
872886
# send practice grade via lti, if setup for that
873887
lti_record = _get_lti_record(session.oauth_consumer_key)
874888
practice_grade = _get_student_practice_grade(auth.user.id, auth.user.course_name)
875889
course_settings = _get_course_practice_record(auth.user.course_name)
876890

877-
practice_completion_count = _get_practice_completion(auth.user.id,
878-
auth.user.course_name,
879-
spacing)
880891
if spacing == 1:
881892
total_possible_points = day_points * max_days
882893
points_received = day_points * practice_completion_count

0 commit comments

Comments
 (0)