From 714801060695189a2cecdfe5d8d00cb8b0434355 Mon Sep 17 00:00:00 2001 From: dzhuang Date: Wed, 31 May 2017 18:04:06 +0800 Subject: [PATCH] Apply if_has_participation_tags_{all,any} to grading rules. --- course/utils.py | 59 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/course/utils.py b/course/utils.py index efb26c95..0349d806 100644 --- a/course/utils.py +++ b/course/utils.py @@ -172,26 +172,6 @@ def _eval_generic_conditions( if all(role not in rule.if_has_role for role in roles): return False - participation_tags_any_set = ( - set(getattr(rule, "if_has_participation_tags_any", []))) - participation_tags_all_set = ( - set(getattr(rule, "if_has_participation_tags_all", []))) - - if participation_tags_any_set or participation_tags_all_set: - if not participation: - return False - ptag_set = set(participation.tags.all().values_list("name", flat=True)) - if not ptag_set: - return False - if (participation_tags_any_set - and - not participation_tags_any_set & ptag_set): - return False - if (participation_tags_all_set - and - not participation_tags_all_set <= ptag_set): - return False - if (hasattr(rule, "if_signed_in_with_matching_exam_ticket") and rule.if_signed_in_with_matching_exam_ticket): if login_exam_ticket is None: @@ -223,6 +203,36 @@ def _eval_generic_session_conditions( return True +def _eval_participation_tags_conditions( + rule, # type: Any + participation, # type: Optional[Participation] + ): + # type: (...) -> bool + + if not participation: + return False + + participation_tags_any_set = ( + set(getattr(rule, "if_has_participation_tags_any", []))) + participation_tags_all_set = ( + set(getattr(rule, "if_has_participation_tags_all", []))) + + if participation_tags_any_set or participation_tags_all_set: + ptag_set = set(participation.tags.all().values_list("name", flat=True)) + if not ptag_set: + return False + if (participation_tags_any_set + and + not participation_tags_any_set & ptag_set): + return False + if (participation_tags_all_set + and + not participation_tags_all_set <= ptag_set): + return False + + return True + + def get_flow_rules( flow_desc, # type: FlowDesc kind, # type: Text @@ -295,6 +305,9 @@ def get_session_start_rule( login_exam_ticket=login_exam_ticket): continue + if not _eval_participation_tags_conditions(rule, participation): + continue + if not for_rollover and hasattr(rule, "if_in_facility"): if rule.if_in_facility not in facilities: continue @@ -383,6 +396,9 @@ def get_session_access_rule( login_exam_ticket=login_exam_ticket): continue + if not _eval_participation_tags_conditions(rule, session.participation): + continue + if not _eval_generic_session_conditions(rule, session, now_datetime): continue @@ -469,6 +485,9 @@ def get_session_grading_rule( if not _eval_generic_session_conditions(rule, session, now_datetime): continue + if not _eval_participation_tags_conditions(rule, session.participation): + continue + if hasattr(rule, "if_completed_before"): ds = parse_date_spec(session.course, rule.if_completed_before) if session.in_progress and now_datetime > ds: -- GitLab