Commit 8bbc11cb by Adam Palay

rename stripping function, make it more explicit

parent bc424173
...@@ -32,7 +32,7 @@ import instructor_task.api ...@@ -32,7 +32,7 @@ import instructor_task.api
from instructor_task.api_helper import AlreadyRunningError from instructor_task.api_helper import AlreadyRunningError
import instructor.enrollment as enrollment import instructor.enrollment as enrollment
from instructor.enrollment import enroll_email, unenroll_email from instructor.enrollment import enroll_email, unenroll_email
from instructor.views.tools import _clean_field from instructor.views.tools import strip_if_string
import instructor.access as access import instructor.access as access
import analytics.basic import analytics.basic
import analytics.distributions import analytics.distributions
...@@ -234,7 +234,7 @@ def modify_access(request, course_id): ...@@ -234,7 +234,7 @@ def modify_access(request, course_id):
request.user, course_id, 'instructor', depth=None request.user, course_id, 'instructor', depth=None
) )
email = _clean_field(request.GET.get('email')) email = strip_if_string(request.GET.get('email'))
rolename = request.GET.get('rolename') rolename = request.GET.get('rolename')
action = request.GET.get('action') action = request.GET.get('action')
...@@ -434,7 +434,7 @@ def get_student_progress_url(request, course_id): ...@@ -434,7 +434,7 @@ def get_student_progress_url(request, course_id):
'progress_url': '/../...' 'progress_url': '/../...'
} }
""" """
student_email = _clean_field(request.GET.get('student_email')) student_email = strip_if_string(request.GET.get('student_email'))
user = User.objects.get(email=student_email) user = User.objects.get(email=student_email)
progress_url = reverse('student_progress', kwargs={'course_id': course_id, 'student_id': user.id}) progress_url = reverse('student_progress', kwargs={'course_id': course_id, 'student_id': user.id})
...@@ -475,8 +475,8 @@ def reset_student_attempts(request, course_id): ...@@ -475,8 +475,8 @@ def reset_student_attempts(request, course_id):
request.user, course_id, 'staff', depth=None request.user, course_id, 'staff', depth=None
) )
problem_to_reset = _clean_field(request.GET.get('problem_to_reset')) problem_to_reset = strip_if_string(request.GET.get('problem_to_reset'))
student_email = _clean_field(request.GET.get('student_email')) student_email = strip_if_string(request.GET.get('student_email'))
all_students = request.GET.get('all_students', False) in ['true', 'True', True] all_students = request.GET.get('all_students', False) in ['true', 'True', True]
delete_module = request.GET.get('delete_module', False) in ['true', 'True', True] delete_module = request.GET.get('delete_module', False) in ['true', 'True', True]
...@@ -532,8 +532,8 @@ def rescore_problem(request, course_id): ...@@ -532,8 +532,8 @@ def rescore_problem(request, course_id):
all_students and student_email cannot both be present. all_students and student_email cannot both be present.
""" """
problem_to_reset = _clean_field(request.GET.get('problem_to_reset')) problem_to_reset = strip_if_string(request.GET.get('problem_to_reset'))
student_email = _clean_field(request.GET.get('student_email', False)) student_email = strip_if_string(request.GET.get('student_email', False))
all_students = request.GET.get('all_students') in ['true', 'True', True] all_students = request.GET.get('all_students') in ['true', 'True', True]
if not (problem_to_reset and (all_students or student_email)): if not (problem_to_reset and (all_students or student_email)):
...@@ -577,8 +577,8 @@ def list_instructor_tasks(request, course_id): ...@@ -577,8 +577,8 @@ def list_instructor_tasks(request, course_id):
- `problem_urlname` and `student_email` lists task - `problem_urlname` and `student_email` lists task
history for problem AND student (intersection) history for problem AND student (intersection)
""" """
problem_urlname = _clean_field(request.GET.get('problem_urlname', False)) problem_urlname = strip_if_string(request.GET.get('problem_urlname', False))
student_email = _clean_field(request.GET.get('student_email', False)) student_email = strip_if_string(request.GET.get('student_email', False))
if student_email and not problem_urlname: if student_email and not problem_urlname:
return HttpResponseBadRequest( return HttpResponseBadRequest(
...@@ -694,7 +694,7 @@ def update_forum_role_membership(request, course_id): ...@@ -694,7 +694,7 @@ def update_forum_role_membership(request, course_id):
request.user, course_id, FORUM_ROLE_ADMINISTRATOR request.user, course_id, FORUM_ROLE_ADMINISTRATOR
) )
email = _clean_field(request.GET.get('email')) email = strip_if_string(request.GET.get('email'))
rolename = request.GET.get('rolename') rolename = request.GET.get('rolename')
action = request.GET.get('action') action = request.GET.get('action')
......
...@@ -41,7 +41,7 @@ from django_comment_common.models import (Role, ...@@ -41,7 +41,7 @@ from django_comment_common.models import (Role,
FORUM_ROLE_COMMUNITY_TA) FORUM_ROLE_COMMUNITY_TA)
from django_comment_client.utils import has_forum_access from django_comment_client.utils import has_forum_access
from instructor.offline_gradecalc import student_grades, offline_grades_available from instructor.offline_gradecalc import student_grades, offline_grades_available
from instructor.views.tools import _clean_field from instructor.views.tools import strip_if_string
from instructor_task.api import (get_running_instructor_tasks, from instructor_task.api import (get_running_instructor_tasks,
get_instructor_task_history, get_instructor_task_history,
submit_rescore_problem_for_all_students, submit_rescore_problem_for_all_students,
...@@ -173,7 +173,7 @@ def instructor_dashboard(request, course_id): ...@@ -173,7 +173,7 @@ def instructor_dashboard(request, course_id):
is provided, "problem" is assumed. is provided, "problem" is assumed.
""" """
# remove whitespace # remove whitespace
urlname = _clean_field(urlname) urlname = strip_if_string(urlname)
# tolerate an XML suffix in the urlname # tolerate an XML suffix in the urlname
if urlname[-4:] == ".xml": if urlname[-4:] == ".xml":
...@@ -189,7 +189,7 @@ def instructor_dashboard(request, course_id): ...@@ -189,7 +189,7 @@ def instructor_dashboard(request, course_id):
def get_student_from_identifier(unique_student_identifier): def get_student_from_identifier(unique_student_identifier):
"""Gets a student object using either an email address or username""" """Gets a student object using either an email address or username"""
unique_student_identifier = _clean_field(unique_student_identifier) unique_student_identifier = strip_if_string(unique_student_identifier)
msg = "" msg = ""
try: try:
if "@" in unique_student_identifier: if "@" in unique_student_identifier:
...@@ -1001,7 +1001,7 @@ def _add_or_remove_user_group(request, username_or_email, group, group_title, ev ...@@ -1001,7 +1001,7 @@ def _add_or_remove_user_group(request, username_or_email, group, group_title, ev
to do. to do.
""" """
user = None user = None
username_or_email = _clean_field(username_or_email) username_or_email = strip_if_string(username_or_email)
try: try:
if '@' in username_or_email: if '@' in username_or_email:
user = User.objects.get(email=username_or_email) user = User.objects.get(email=username_or_email)
......
""" """
Tools for the instructor dashboard Tools for the instructor dashboard
""" """
def _clean_field(field): def strip_if_string(value):
if field: if isinstance(value, basestring):
return field.strip() return value.strip()
return field return value
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment