From 575589f8a546f4f9334d566603aabfc67bdae3f2 Mon Sep 17 00:00:00 2001 From: uzairr Date: Thu, 27 Jun 2019 13:21:50 +0500 Subject: [PATCH] Python-modernize on edx-platform (369 of 380) --- lms/djangoapps/instructor_task/admin.py | 2 ++ lms/djangoapps/instructor_task/api.py | 9 ++++++--- lms/djangoapps/instructor_task/api_helper.py | 4 +++- lms/djangoapps/instructor_task/models.py | 7 +++++-- lms/djangoapps/instructor_task/tasks.py | 4 +++- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lms/djangoapps/instructor_task/admin.py b/lms/djangoapps/instructor_task/admin.py index 977596ec17..6b4ed131fb 100644 --- a/lms/djangoapps/instructor_task/admin.py +++ b/lms/djangoapps/instructor_task/admin.py @@ -5,6 +5,8 @@ This will mostly involve searching by course_id or task_id and manually failing a task. """ +from __future__ import absolute_import + from config_models.admin import ConfigurationModelAdmin from django.contrib import admin diff --git a/lms/djangoapps/instructor_task/api.py b/lms/djangoapps/instructor_task/api.py index dda5be3c65..b587aa4a1a 100644 --- a/lms/djangoapps/instructor_task/api.py +++ b/lms/djangoapps/instructor_task/api.py @@ -6,16 +6,19 @@ already been submitted, filtered either by running state or input arguments. """ +from __future__ import absolute_import + import hashlib from collections import Counter +import six from celery.states import READY_STATES from bulk_email.models import CourseEmail from lms.djangoapps.certificates.models import CertificateGenerationHistory from lms.djangoapps.instructor_task.api_helper import ( - check_arguments_for_rescoring, check_arguments_for_overriding, + check_arguments_for_rescoring, check_entrance_exam_problems_for_rescoring, encode_entrance_exam_and_student_input, encode_problem_and_student_input, @@ -23,7 +26,6 @@ from lms.djangoapps.instructor_task.api_helper import ( ) from lms.djangoapps.instructor_task.models import InstructorTask from lms.djangoapps.instructor_task.tasks import ( - override_problem_score, calculate_grades_csv, calculate_may_enroll_csv, calculate_problem_grade_report, @@ -36,6 +38,7 @@ from lms.djangoapps.instructor_task.tasks import ( exec_summary_report_csv, export_ora2_data, generate_certificates, + override_problem_score, proctored_exam_results_csv, rescore_problem, reset_problem_attempts, @@ -309,7 +312,7 @@ def submit_bulk_course_email(request, course_key, email_id): targets = [ target if count <= 1 else u"{} {}".format(count, target) - for target, count in targets.iteritems() + for target, count in six.iteritems(targets) ] task_type = 'bulk_course_email' diff --git a/lms/djangoapps/instructor_task/api_helper.py b/lms/djangoapps/instructor_task/api_helper.py index ddd53ddc06..77dba670be 100644 --- a/lms/djangoapps/instructor_task/api_helper.py +++ b/lms/djangoapps/instructor_task/api_helper.py @@ -4,6 +4,8 @@ Helper lib for instructor_tasks API. Includes methods to check args for rescoring task, encoding student input, and task submission logic, including handling the Celery backend. """ +from __future__ import absolute_import + import hashlib import json import logging @@ -364,7 +366,7 @@ def check_entrance_exam_problems_for_rescoring(exam_key): # pylint: disable=inv descriptor doesn't exist for exam_key. NotImplementedError is raised if any of the problem in entrance exam doesn't support re-scoring calls. """ - problems = get_problems_in_section(exam_key).values() + problems = list(get_problems_in_section(exam_key).values()) if any(not _supports_rescore(problem) for problem in problems): msg = _("Not all problems in entrance exam support re-scoring.") raise NotImplementedError(msg) diff --git a/lms/djangoapps/instructor_task/models.py b/lms/djangoapps/instructor_task/models.py index ab7143afd8..aea28c803a 100644 --- a/lms/djangoapps/instructor_task/models.py +++ b/lms/djangoapps/instructor_task/models.py @@ -12,6 +12,8 @@ file and check it in at the same time as your model changes. To do that, ASSUMPTIONS: modules have unique IDs, even across different module_types """ +from __future__ import absolute_import + import codecs import csv import hashlib @@ -20,6 +22,7 @@ import logging import os.path from uuid import uuid4 +import six from boto.exception import BotoServerError from django.conf import settings from django.contrib.auth.models import User @@ -87,7 +90,7 @@ class InstructorTask(models.Model): },) def __unicode__(self): - return unicode(repr(self)) + return six.text_type(repr(self)) @classmethod def create(cls, course_id, task_type, task_key, task_input, requester): @@ -226,7 +229,7 @@ class ReportStore(object): compatibility. """ for row in rows: - yield [unicode(item).encode('utf-8') for item in row] + yield [six.text_type(item).encode('utf-8') for item in row] class DjangoStorageReportStore(ReportStore): diff --git a/lms/djangoapps/instructor_task/tasks.py b/lms/djangoapps/instructor_task/tasks.py index 65e3c1b11e..89dcd6f6b8 100644 --- a/lms/djangoapps/instructor_task/tasks.py +++ b/lms/djangoapps/instructor_task/tasks.py @@ -19,6 +19,8 @@ a problem URL and optionally a student. These are used to set up the initial va of the query for traversing StudentModule objects. """ +from __future__ import absolute_import + import logging from functools import partial @@ -44,8 +46,8 @@ from lms.djangoapps.instructor_task.tasks_helper.misc import ( ) from lms.djangoapps.instructor_task.tasks_helper.module_state import ( delete_problem_module_state, - perform_module_state_update, override_score_module_state, + perform_module_state_update, rescore_problem_module_state, reset_attempts_module_state )