From c71e23587f584bfe6c07247e7327b1bf9872109e Mon Sep 17 00:00:00 2001 From: dzhuang Date: Sat, 20 May 2017 11:18:16 +0800 Subject: [PATCH] Allow participation query by institutional_id. --- course/enrollment.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/course/enrollment.py b/course/enrollment.py index b7e99e92..839450bf 100644 --- a/course/enrollment.py +++ b/course/enrollment.py @@ -553,6 +553,8 @@ _email = intern("email") _email_contains = intern("email_contains") _user = intern("user") _user_contains = intern("user_contains") +_institutional_id = intern("institutional_id") +_institutional_id_contains = intern("institutional_id__contains") _tagged = intern("tagged") _role = intern("role") _status = intern("status") @@ -583,6 +585,9 @@ _LEX_TABLE = [ (_email_contains, RE(r"email-contains:([^ \t\n\r\f\v)]+)")), (_user, RE(r"username:([^ \t\n\r\f\v)]+)")), (_user_contains, RE(r"username-contains:([^ \t\n\r\f\v)]+)")), + (_institutional_id, RE(r"institutional-id:([^ \t\n\r\f\v)]+)")), + (_institutional_id_contains, + RE(r"institutional-id-contains:([^ \t\n\r\f\v)]+)")), (_tagged, RE(r"tagged:([-\w]+)")), (_role, RE(r"role:(\w+)")), (_status, RE(r"status:(\w+)")), @@ -594,7 +599,9 @@ _LEX_TABLE = [ _TERMINALS = ([ - _id, _email, _email_contains, _user, _user_contains, _tagged, _role, _status]) + _id, _email, _email_contains, _user, _user_contains, _tagged, _role, _status, + _institutional_id, _institutional_id_contains +]) # {{{ operator precedence @@ -637,6 +644,18 @@ def parse_query(course, expr_str): pstate.advance() return result + elif next_tag is _institutional_id: + result = Q( + user__institutional_id__iexact=pstate.next_match_obj().group(1)) + pstate.advance() + return result + + elif next_tag is _institutional_id_contains: + result = Q( + user__institutional_id__icontains=pstate.next_match_obj().group(1)) + pstate.advance() + return result + elif next_tag is _tagged: ptag, created = ParticipationTag.objects.get_or_create( course=course, @@ -753,6 +772,8 @@ class ParticipationQueryForm(StyledForm): "email-contains:abc, " "username:abc, " "username-contains:abc, " + "institutional-id:2015abcd, " + "institutional-id-contains:2015, " "tagged:abc, " "role:instructor|teaching_assistant|" "student|observer|auditor, " -- GitLab