From 1b227232c55490a0f684ff33f2d2ca0743c99f95 Mon Sep 17 00:00:00 2001 From: adeelehsan Date: Tue, 25 Jun 2019 15:47:00 +0500 Subject: [PATCH] Python3 update INCR-471 --- lms/djangoapps/certificates/api.py | 25 +++++++++++-------- lms/djangoapps/certificates/apps.py | 2 ++ lms/djangoapps/certificates/services.py | 5 +++- lms/djangoapps/certificates/signals.py | 24 ++++++++++-------- .../migrations/0001_initial.py | 4 +-- .../migrations/0002_gradereportsetting.py | 4 +-- 6 files changed, 38 insertions(+), 26 deletions(-) diff --git a/lms/djangoapps/certificates/api.py b/lms/djangoapps/certificates/api.py index da8fa484c7..c1414afdb4 100644 --- a/lms/djangoapps/certificates/api.py +++ b/lms/djangoapps/certificates/api.py @@ -4,11 +4,15 @@ This is a Python API for generating certificates asynchronously. Other Django apps should use the API functions defined in this module rather than importing Django models directly. """ +from __future__ import absolute_import + import logging +import six from django.conf import settings -from django.urls import reverse from django.db.models import Q +from django.urls import reverse +from eventtracking import tracker from opaque_keys.edx.django.models import CourseKeyField from opaque_keys.edx.keys import CourseKey @@ -25,7 +29,6 @@ from lms.djangoapps.certificates.models import ( certificate_status_for_student ) from lms.djangoapps.certificates.queue import XQueueCertInterface -from eventtracking import tracker from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from util.organizations_helpers import get_course_organization_id from xmodule.modulestore.django import modulestore @@ -193,7 +196,7 @@ def generate_user_certificates(student, course_key, course=None, insecure=False, if CertificateStatuses.is_passing_status(cert.status): emit_certificate_event('created', student, course_key, course, { 'user_id': student.id, - 'course_id': unicode(course_key), + 'course_id': six.text_type(course_key), 'certificate_id': cert.verify_uuid, 'enrollment_mode': cert.mode, 'generation_mode': generation_mode @@ -231,7 +234,7 @@ def regenerate_user_certificates(student, course_key, course=None, generate_pdf = not has_html_certificates_enabled(course) log.info( u"Started regenerating certificates for user %s in course %s with generate_pdf status: %s", - student.username, unicode(course_key), generate_pdf + student.username, six.text_type(course_key), generate_pdf ) return xqueue.regen_cert( @@ -306,12 +309,12 @@ def set_cert_generation_enabled(course_key, is_enabled): cert_event_type = 'enabled' if is_enabled else 'disabled' event_name = '.'.join(['edx', 'certificate', 'generation', cert_event_type]) tracker.emit(event_name, { - 'course_id': unicode(course_key), + 'course_id': six.text_type(course_key), }) if is_enabled: - log.info(u"Enabled self-generated certificates for course '%s'.", unicode(course_key)) + log.info(u"Enabled self-generated certificates for course '%s'.", six.text_type(course_key)) else: - log.info(u"Disabled self-generated certificates for course '%s'.", unicode(course_key)) + log.info(u"Disabled self-generated certificates for course '%s'.", six.text_type(course_key)) def is_certificate_invalid(student, course_key): @@ -436,7 +439,7 @@ def _certificate_html_url(user_id, course_id, uuid): if uuid: return reverse('certificates:render_cert_by_uuid', kwargs={'certificate_uuid': uuid}) elif user_id and course_id: - kwargs = {"user_id": str(user_id), "course_id": unicode(course_id)} + kwargs = {"user_id": str(user_id), "course_id": six.text_type(course_id)} return reverse('certificates:html_view', kwargs=kwargs) return '' @@ -452,7 +455,7 @@ def _certificate_download_url(user_id, course_id, user_certificate=None): log.critical( u'Unable to lookup certificate\n' u'user id: %d\n' - u'course: %s', user_id, unicode(course_id) + u'course: %s', user_id, six.text_type(course_id) ) if user_certificate: @@ -589,11 +592,11 @@ def emit_certificate_event(event_name, user, course_id, course=None, event_data= course = modulestore().get_course(course_id, depth=0) context = { 'org_id': course.org, - 'course_id': unicode(course_id) + 'course_id': six.text_type(course_id) } data = { 'user_id': user.id, - 'course_id': unicode(course_id), + 'course_id': six.text_type(course_id), 'certificate_url': get_certificate_url(user.id, course_id) } event_data = event_data or {} diff --git a/lms/djangoapps/certificates/apps.py b/lms/djangoapps/certificates/apps.py index 19f7f23b31..a941f1121e 100644 --- a/lms/djangoapps/certificates/apps.py +++ b/lms/djangoapps/certificates/apps.py @@ -4,6 +4,8 @@ Certificates Application Configuration Signal handlers are connected here. """ +from __future__ import absolute_import + from django.apps import AppConfig from django.conf import settings from edx_proctoring.runtime import set_runtime_service diff --git a/lms/djangoapps/certificates/services.py b/lms/djangoapps/certificates/services.py index 5356c42d7f..a2212dcc25 100644 --- a/lms/djangoapps/certificates/services.py +++ b/lms/djangoapps/certificates/services.py @@ -1,12 +1,15 @@ """ Certificate service """ +from __future__ import absolute_import + import logging from django.core.exceptions import ObjectDoesNotExist -from lms.djangoapps.utils import _get_key from opaque_keys.edx.keys import CourseKey +from lms.djangoapps.utils import _get_key + from .models import GeneratedCertificate log = logging.getLogger(__name__) diff --git a/lms/djangoapps/certificates/signals.py b/lms/djangoapps/certificates/signals.py index d11e7f09e4..ff8ea3586a 100644 --- a/lms/djangoapps/certificates/signals.py +++ b/lms/djangoapps/certificates/signals.py @@ -1,16 +1,20 @@ """ Signal handler for enabling/disabling self-generated certificates based on the course-pacing. """ +from __future__ import absolute_import + import logging +import six from django.db.models.signals import post_save from django.dispatch import receiver +from course_modes.models import CourseMode from lms.djangoapps.certificates.models import ( CertificateGenerationCourseSetting, + CertificateStatuses, CertificateWhitelist, - GeneratedCertificate, - CertificateStatuses + GeneratedCertificate ) from lms.djangoapps.certificates.tasks import generate_certificate from lms.djangoapps.grades.api import CourseGradeFactory @@ -18,13 +22,13 @@ from lms.djangoapps.verify_student.services import IDVerificationService from openedx.core.djangoapps.certificates.api import auto_certificate_generation_enabled from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.content.course_overviews.signals import COURSE_PACING_CHANGED -from openedx.core.djangoapps.signals.signals import (COURSE_GRADE_NOW_PASSED, - LEARNER_NOW_VERIFIED, - COURSE_GRADE_NOW_FAILED) -from course_modes.models import CourseMode +from openedx.core.djangoapps.signals.signals import ( + COURSE_GRADE_NOW_FAILED, + COURSE_GRADE_NOW_PASSED, + LEARNER_NOW_VERIFIED +) from student.models import CourseEnrollment - log = logging.getLogger(__name__) CERTIFICATE_DELAY_SECONDS = 2 @@ -158,10 +162,10 @@ def fire_ungenerated_certificate_task(user, course_key, expected_verification_st if generate_learner_certificate: kwargs = { - 'student': unicode(user.id), - 'course_key': unicode(course_key) + 'student': six.text_type(user.id), + 'course_key': six.text_type(course_key) } if expected_verification_status: - kwargs['expected_verification_status'] = unicode(expected_verification_status) + kwargs['expected_verification_status'] = six.text_type(expected_verification_status) generate_certificate.apply_async(countdown=CERTIFICATE_DELAY_SECONDS, kwargs=kwargs) return True diff --git a/lms/djangoapps/instructor_task/migrations/0001_initial.py b/lms/djangoapps/instructor_task/migrations/0001_initial.py index 14970627f1..316c6c18f8 100644 --- a/lms/djangoapps/instructor_task/migrations/0001_initial.py +++ b/lms/djangoapps/instructor_task/migrations/0001_initial.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import absolute_import, unicode_literals -from django.db import migrations, models from django.conf import settings +from django.db import migrations, models from opaque_keys.edx.django.models import CourseKeyField diff --git a/lms/djangoapps/instructor_task/migrations/0002_gradereportsetting.py b/lms/djangoapps/instructor_task/migrations/0002_gradereportsetting.py index 70838e1260..2ba86491ce 100644 --- a/lms/djangoapps/instructor_task/migrations/0002_gradereportsetting.py +++ b/lms/djangoapps/instructor_task/migrations/0002_gradereportsetting.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import absolute_import, unicode_literals -from django.db import migrations, models import django.db.models.deletion from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration):