Fixed code duplication in task listing api on instructor dashboard

This commit is contained in:
Amir Qayyum Khan
2018-06-07 15:52:26 +05:00
parent f93c9a9298
commit 9db5e83032

View File

@@ -5,7 +5,6 @@ import json
import logging
from time import time
from django.contrib.auth.models import User
from django.utils.translation import ugettext_noop
from opaque_keys.edx.keys import UsageKey
@@ -16,6 +15,7 @@ from courseware.model_data import DjangoKeyValueStore, FieldDataCache
from courseware.models import StudentModule
from courseware.module_render import get_module_for_descriptor_internal
from lms.djangoapps.grades.events import GRADES_OVERRIDE_EVENT_TYPE, GRADES_RESCORE_EVENT_TYPE
from student.models import get_user_by_username_or_email
from track.event_transaction_utils import create_new_event_transaction_id, set_event_transaction_type
from track.views import task_track
from util.db import outer_atomic
@@ -409,12 +409,7 @@ def _get_modules_to_update(course_id, usage_keys, student_identifier, filter_fcn
"""
def get_student():
""" Fetches student instance if an identifier is provided, else return None """
if student_identifier is None:
return None
student_identifier_type = 'email' if '@' in student_identifier else 'username'
student_query_params = {student_identifier_type: student_identifier}
return User.objects.get(**student_query_params)
return None if not student_identifier else get_user_by_username_or_email(student_identifier)
module_query_params = {'course_id': course_id, 'module_state_keys': usage_keys}