Python3 update

INCR-471
This commit is contained in:
adeelehsan
2019-06-25 15:47:00 +05:00
parent 94c3b4ee5a
commit 1b227232c5
6 changed files with 38 additions and 26 deletions

View File

@@ -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 {}

View File

@@ -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

View File

@@ -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__)

View File

@@ -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

View File

@@ -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

View File

@@ -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):