From af46e5f222896305a10a366fe783001dcc0073ab Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Thu, 7 Sep 2017 22:22:38 -0500 Subject: [PATCH 1/2] Define interaction between use_last_activity_as_completion_time and if_completed_before (See also #358 on Github) --- course/utils.py | 18 +++++++++++++++--- doc/flow.rst | 6 ++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/course/utils.py b/course/utils.py index 2ff1f3f5..acb1bc7a 100644 --- a/course/utils.py +++ b/course/utils.py @@ -493,9 +493,21 @@ def get_session_grading_rule( if hasattr(rule, "if_completed_before"): ds = parse_date_spec(session.course, rule.if_completed_before) - if session.in_progress and now_datetime > ds: - continue - if not session.in_progress and session.completion_time > ds: + + use_last_activity_as_completion_time = False + if hasattr(rule, "use_last_activity_as_completion_time"): + use_last_activity_as_completion_time = \ + rule.use_last_activity_as_completion_time + + if use_last_activity_as_completion_time: + completion_time = session.last_activity() + else: + if session.in_progress: + completion_time = now_datetime + else: + completion_time = session.completion_time + + if completion_time > ds: continue due = parse_date_spec(session.course, getattr(rule, "due", None)) diff --git a/doc/flow.rst b/doc/flow.rst index b1cf6ba3..a9886a90 100644 --- a/doc/flow.rst +++ b/doc/flow.rst @@ -510,6 +510,12 @@ Determining how final (overall) grades of flows are computed (Optional) A :ref:`datespec `. Rule applies if the session was completed before this time. + When evaluating this condition for in-progress sessions, the current time, + or, if :attr:`use_last_activity_as_completion_time` is set, the time of the + last activity is used. + + Since September 2017, this respects :attr:`use_last_activity_as_completion_time`. + .. rubric:: Rules specified .. attribute:: credit_percent -- GitLab From 8e70efd3cfe4efc49cafe6614a40e9d53d5a2594 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Fri, 8 Sep 2017 00:10:40 -0500 Subject: [PATCH 2/2] Get if_completed_before check to be mypy-clean --- course/models.py | 2 ++ course/utils.py | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/course/models.py b/course/models.py index f1f2fc87..0a3dfe54 100644 --- a/course/models.py +++ b/course/models.py @@ -63,6 +63,7 @@ from course.page.base import AnswerFeedback if False: from typing import List, Dict, Any, Optional, Text, Iterable, Tuple, FrozenSet # noqa from course.content import FlowDesc # noqa + import datetime # noqa # }}} @@ -819,6 +820,7 @@ class FlowSession(models.Model): return assemble_answer_visits(self) def last_activity(self): + # type: () -> Optional[datetime.datetime] for visit in (FlowPageVisit.objects .filter( flow_session=self, diff --git a/course/utils.py b/course/utils.py index 373f29ad..ffbee615 100644 --- a/course/utils.py +++ b/course/utils.py @@ -500,7 +500,11 @@ def get_session_grading_rule( rule.use_last_activity_as_completion_time if use_last_activity_as_completion_time: - completion_time = session.last_activity() + last_activity = session.last_activity() + if last_activity is not None: + completion_time = last_activity + else: + completion_time = now_datetime else: if session.in_progress: completion_time = now_datetime -- GitLab