Skip to content

Commit

Permalink
Add use_last_activity_as_completion_time to grading rules
Browse files Browse the repository at this point in the history
  • Loading branch information
inducer committed Sep 13, 2015
1 parent 882803a commit 7317cfb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
13 changes: 12 additions & 1 deletion course/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ def grade_page_visits(fctx, flow_session, answer_visits, force_regrade=False):
@transaction.atomic
def finish_flow_session(fctx, flow_session, grading_rule,
force_regrade=False, now_datetime=None):

if not flow_session.in_progress:
raise RuntimeError(_("Can't end a session that's already ended"))

Expand All @@ -482,11 +483,21 @@ def finish_flow_session(fctx, flow_session, grading_rule,

# ORDERING RESTRICTION: Must grade pages before gathering grade info

# {{{ determine completion time

if now_datetime is None:
from django.utils.timezone import now
now_datetime = now()

flow_session.completion_time = now_datetime
completion_time = now_datetime
if grading_rule.use_last_activity_as_completion_time:
last_activity = flow_session.last_activity()
if last_activity is not None:
completion_time = last_activity

flow_session.completion_time = completion_time

# }}}

flow_session.in_progress = False
flow_session.save()
Expand Down
6 changes: 5 additions & 1 deletion course/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class FlowSessionGradingRule(FlowSessionRuleBase):
"generates_grade",
"description",
"credit_percent",
"use_last_activity_as_completion_time",
]


Expand Down Expand Up @@ -332,7 +333,10 @@ def get_session_grading_rule(session, role, flow_desc, now_datetime):
due=due,
generates_grade=generates_grade,
description=getattr(rule, "description", None),
credit_percent=getattr(rule, "credit_percent", 100))
credit_percent=getattr(rule, "credit_percent", 100),
use_last_activity_as_completion_time=getattr(
rule, "use_last_activity_as_completion_time", False),
)

raise RuntimeError(_("grading rule determination was unable to find "
"a grading rule"))
Expand Down
1 change: 1 addition & 0 deletions course/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ def validate_session_grading_rule(ctx, location, grule, tags, grade_identifier):
("if_completed_before", datespec_types),

("credit_percent", (int, float)),
("use_last_activity_as_completion_time", bool),
("due", datespec_types),
("generates_grade", bool),
("description", str),
Expand Down
8 changes: 8 additions & 0 deletions doc/flow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,14 @@ Here's a commented example:
*may* have been set to generate a grade must *always* be set to generate
a grade. Defaults to ``true``.

.. attribute:: use_last_activity_as_completion_time

(Optional) A Boolean indicating whether the last time a participant made
a change to their flow should be used as the completion time.

Defaults to ``false`` to match past behavior. ``true`` is probably the more
sensible value for this.

.. attribute:: description

(Optional) A description of this set of grading rules being applied to the flow.
Expand Down

0 comments on commit 7317cfb

Please sign in to comment.