Commit 476f6821 by Giovanni Di Milia

Fixed pylint violation for files in lms/djangoapps/certificates

parent 6fb89fee
...@@ -25,6 +25,10 @@ def get_user_from_identifier(identifier): ...@@ -25,6 +25,10 @@ def get_user_from_identifier(identifier):
class Command(BaseCommand): class Command(BaseCommand):
"""
Management command to set or get the certificate whitelist
for a given user(s)/course
"""
help = """ help = """
Sets or gets the certificate whitelist for a given Sets or gets the certificate whitelist for a given
...@@ -88,7 +92,8 @@ class Command(BaseCommand): ...@@ -88,7 +92,8 @@ class Command(BaseCommand):
try: try:
course = CourseKey.from_string(course_id) course = CourseKey.from_string(course_id)
except InvalidKeyError: except InvalidKeyError:
print("Course id {} could not be parsed as a CourseKey; falling back to SSCK.from_dep_str".format(course_id)) print(("Course id {} could not be parsed as a CourseKey; "
"falling back to SSCK.from_dep_str").format(course_id))
course = SlashSeparatedCourseKey.from_deprecated_string(course_id) course = SlashSeparatedCourseKey.from_deprecated_string(course_id)
if options['add'] and options['del']: if options['add'] and options['del']:
......
"""
Management command which fixes ungraded certificates for students
"""
from certificates.models import GeneratedCertificate from certificates.models import GeneratedCertificate
from courseware import grades, courses from courseware import grades, courses
from django.test.client import RequestFactory from django.test.client import RequestFactory
...@@ -6,6 +11,9 @@ from optparse import make_option ...@@ -6,6 +11,9 @@ from optparse import make_option
class Command(BaseCommand): class Command(BaseCommand):
"""
Management command to find and grade all students that need to be graded.
"""
help = """ help = """
Find all students that need to be graded Find all students that need to be graded
......
...@@ -13,6 +13,10 @@ from django.db.models import Count ...@@ -13,6 +13,10 @@ from django.db.models import Count
class Command(BaseCommand): class Command(BaseCommand):
"""
Management command to generate a certificate status
report for a given course.
"""
help = """ help = """
...@@ -48,7 +52,8 @@ class Command(BaseCommand): ...@@ -48,7 +52,8 @@ class Command(BaseCommand):
try: try:
course_id = CourseKey.from_string(options['course']) course_id = CourseKey.from_string(options['course'])
except InvalidKeyError: except InvalidKeyError:
print("Course id {} could not be parsed as a CourseKey; falling back to SSCK.from_dep_str".format(options['course'])) print ("Course id {} could not be parsed as a CourseKey; "
"falling back to SSCK.from_dep_str").format(options['course'])
course_id = SlashSeparatedCourseKey.from_deprecated_string(options['course']) course_id = SlashSeparatedCourseKey.from_deprecated_string(options['course'])
else: else:
raise CommandError("You must specify a course") raise CommandError("You must specify a course")
...@@ -90,8 +95,10 @@ class Command(BaseCommand): ...@@ -90,8 +95,10 @@ class Command(BaseCommand):
) )
cert_data[course_id].update( cert_data[course_id].update(
{status['status']: status['dcount'] {
for status in status_tally}) status['status']: status['dcount'] for status in status_tally
}
)
mode_tally = GeneratedCertificate.objects.filter( mode_tally = GeneratedCertificate.objects.filter(
course_id__exact=course_id, course_id__exact=course_id,
...@@ -100,21 +107,17 @@ class Command(BaseCommand): ...@@ -100,21 +107,17 @@ class Command(BaseCommand):
dcount=Count('mode') dcount=Count('mode')
) )
cert_data[course_id].update( cert_data[course_id].update(
{mode['mode']: mode['dcount'] {mode['mode']: mode['dcount'] for mode in mode_tally}
for mode in mode_tally}
) )
# all states we have seen far all courses # all states we have seen far all courses
status_headings = sorted(set( status_headings = sorted(
[status for course in cert_data set([status for course in cert_data for status in cert_data[course]])
for status in cert_data[course]])
) )
# print the heading for the report # print the heading for the report
print "{:>26}".format("course ID"), print "{:>26}".format("course ID"),
print ' '.join(["{:>16}".format(heading) print ' '.join(["{:>16}".format(heading) for heading in status_headings])
for heading in status_headings]
)
# print the report # print the report
print "{0:>26}".format(course_id.to_deprecated_string()), print "{0:>26}".format(course_id.to_deprecated_string()),
......
...@@ -16,6 +16,11 @@ LOGGER = logging.getLogger(__name__) ...@@ -16,6 +16,11 @@ LOGGER = logging.getLogger(__name__)
class Command(BaseCommand): class Command(BaseCommand):
"""
Management command to recreate the certificate for
a given user in a given course.
"""
help = """Put a request on the queue to recreate the certificate for a particular user in a particular course.""" help = """Put a request on the queue to recreate the certificate for a particular user in a particular course."""
option_list = BaseCommand.option_list + ( option_list = BaseCommand.option_list + (
......
...@@ -21,6 +21,10 @@ LOGGER = logging.getLogger(__name__) ...@@ -21,6 +21,10 @@ LOGGER = logging.getLogger(__name__)
class Command(BaseCommand): class Command(BaseCommand):
"""
Management command to find all students that need certificates
for courses that have finished and put their cert requests on the queue.
"""
help = """ help = """
Find all students that need certificates for courses that have finished and Find all students that need certificates for courses that have finished and
......
...@@ -71,6 +71,9 @@ LOGGER = logging.getLogger(__name__) ...@@ -71,6 +71,9 @@ LOGGER = logging.getLogger(__name__)
class CertificateStatuses(object): class CertificateStatuses(object):
"""
Enum for certificate statuses
"""
deleted = 'deleted' deleted = 'deleted'
deleting = 'deleting' deleting = 'deleting'
downloadable = 'downloadable' downloadable = 'downloadable'
...@@ -108,6 +111,9 @@ class CertificateWhitelist(models.Model): ...@@ -108,6 +111,9 @@ class CertificateWhitelist(models.Model):
class GeneratedCertificate(models.Model): class GeneratedCertificate(models.Model):
"""
Base model for generated certificates
"""
MODES = Choices('verified', 'honor', 'audit', 'professional', 'no-id-professional') MODES = Choices('verified', 'honor', 'audit', 'professional', 'no-id-professional')
...@@ -191,14 +197,16 @@ def certificate_status_for_student(student, course_id): ...@@ -191,14 +197,16 @@ def certificate_status_for_student(student, course_id):
try: try:
generated_certificate = GeneratedCertificate.objects.get( generated_certificate = GeneratedCertificate.objects.get(
user=student, course_id=course_id) user=student, course_id=course_id)
d = {'status': generated_certificate.status, cert_status = {
'mode': generated_certificate.mode} 'status': generated_certificate.status,
'mode': generated_certificate.mode
}
if generated_certificate.grade: if generated_certificate.grade:
d['grade'] = generated_certificate.grade cert_status['grade'] = generated_certificate.grade
if generated_certificate.status == CertificateStatuses.downloadable: if generated_certificate.status == CertificateStatuses.downloadable:
d['download_url'] = generated_certificate.download_url cert_status['download_url'] = generated_certificate.download_url
return d return cert_status
except GeneratedCertificate.DoesNotExist: except GeneratedCertificate.DoesNotExist:
pass pass
return {'status': CertificateStatuses.unavailable, 'mode': GeneratedCertificate.MODES.honor} return {'status': CertificateStatuses.unavailable, 'mode': GeneratedCertificate.MODES.honor}
......
...@@ -118,7 +118,7 @@ class GenerateUserCertificatesTest(EventTestMixin, ModuleStoreTestCase): ...@@ -118,7 +118,7 @@ class GenerateUserCertificatesTest(EventTestMixin, ModuleStoreTestCase):
ERROR_REASON = "Kaboom!" ERROR_REASON = "Kaboom!"
def setUp(self): def setUp(self): # pylint: disable=arguments-differ
super(GenerateUserCertificatesTest, self).setUp('certificates.api.tracker') super(GenerateUserCertificatesTest, self).setUp('certificates.api.tracker')
self.student = UserFactory.create( self.student = UserFactory.create(
...@@ -233,7 +233,7 @@ class CertificateGenerationEnabledTest(EventTestMixin, TestCase): ...@@ -233,7 +233,7 @@ class CertificateGenerationEnabledTest(EventTestMixin, TestCase):
COURSE_KEY = CourseLocator(org='test', course='test', run='test') COURSE_KEY = CourseLocator(org='test', course='test', run='test')
def setUp(self): def setUp(self): # pylint: disable=arguments-differ
super(CertificateGenerationEnabledTest, self).setUp('certificates.api.tracker') super(CertificateGenerationEnabledTest, self).setUp('certificates.api.tracker')
# Since model-based configuration is cached, we need # Since model-based configuration is cached, we need
......
...@@ -15,7 +15,7 @@ from django.test.utils import override_settings ...@@ -15,7 +15,7 @@ from django.test.utils import override_settings
from opaque_keys.edx.locator import CourseLocator from opaque_keys.edx.locator import CourseLocator
from openedx.core.lib.tests.assertions.events import assert_event_matches from openedx.core.lib.tests.assertions.events import assert_event_matches
from student.tests.factories import UserFactory, CourseEnrollmentFactory from student.tests.factories import UserFactory
from track.tests import EventTrackingTestCase from track.tests import EventTrackingTestCase
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
...@@ -26,21 +26,12 @@ from certificates.models import ( ...@@ -26,21 +26,12 @@ from certificates.models import (
ExampleCertificateSet, ExampleCertificateSet,
ExampleCertificate, ExampleCertificate,
GeneratedCertificate, GeneratedCertificate,
BadgeAssertion,
CertificateStatuses,
CertificateHtmlViewConfiguration, CertificateHtmlViewConfiguration,
CertificateSocialNetworks,
CertificateTemplate,
) )
from certificates.tests.factories import ( from certificates.tests.factories import (
CertificateHtmlViewConfigurationFactory,
LinkedInAddToProfileConfigurationFactory,
BadgeAssertionFactory, BadgeAssertionFactory,
) )
from util import organizations_helpers as organizations_api
from django.test.client import RequestFactory
import urllib
FEATURES_WITH_CERTS_ENABLED = settings.FEATURES.copy() FEATURES_WITH_CERTS_ENABLED = settings.FEATURES.copy()
FEATURES_WITH_CERTS_ENABLED['CERTIFICATES_HTML_VIEW'] = True FEATURES_WITH_CERTS_ENABLED['CERTIFICATES_HTML_VIEW'] = True
......
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