Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing certificate #456

Open
wants to merge 1 commit into
base: develop-koa
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lms/djangoapps/certificates/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ def listen_for_passing_grade(sender, user, course_id, **kwargs): # pylint: disa
Listen for a learner passing a course, send cert generation task,
downstream signal from COURSE_GRADE_CHANGED
"""
log.info('I am working')
course = CourseOverview.get_from_id(course_id)
if not auto_certificate_generation_enabled():
log.info('I am auto generate working')
return

if fire_ungenerated_certificate_task(user, course_id):
Expand Down Expand Up @@ -159,12 +161,16 @@ def fire_ungenerated_certificate_task(user, course_key, expected_verification_st
CourseMode.EXECUTIVE_EDUCATION,
]
enrollment_mode, __ = CourseEnrollment.enrollment_mode_for_user(user, course_key)
log.info('Enrollment Mode {}'.format(enrollment_mode))
cert = GeneratedCertificate.certificate_for_student(user, course_key)
log.info('Certificate {}'.format(cert))

generate_learner_certificate = (
enrollment_mode in allowed_enrollment_modes_list and (cert is None or cert.status == 'unverified')
)

log.info('Generate Certifcate {}'.format(generate_learner_certificate))

if generate_learner_certificate:
kwargs = {
'student': six.text_type(user.id),
Expand Down
5 changes: 5 additions & 0 deletions lms/djangoapps/grades/rest_api/v1/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@
gradebook_views.SubsectionGradeView.as_view(),
name='course_grade_overrides'
),
url(
r'^courses/gengrade',
views.GenerateCertificateGrade.as_view(),
name='generate_course_grades'
)
]
18 changes: 17 additions & 1 deletion lms/djangoapps/grades/rest_api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@
from edx_rest_framework_extensions import permissions
from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication
from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser
from lms.djangoapps.grades.course_grade import CourseGrade
from opaque_keys import InvalidKeyError
from openedx.core.djangoapps.signals.signals import COURSE_GRADE_NOW_PASSED
from rest_framework import status
from rest_framework.generics import ListAPIView
from rest_framework.views import APIView
from rest_framework.response import Response

from django.contrib.auth.models import User
from lms.djangoapps.courseware.access import has_access
from lms.djangoapps.grades.api import CourseGradeFactory, clear_prefetched_course_grades, prefetch_course_grades
from lms.djangoapps.grades.rest_api.serializers import GradingPolicySerializer
from lms.djangoapps.grades.rest_api.v1.utils import CourseEnrollmentPagination, GradeViewMixin
from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser
from openedx.core.lib.api.view_utils import PaginatedAPIView, get_course_key, verify_course_exists
from xmodule.modulestore.django import modulestore
from opaque_keys.edx.keys import CourseKey

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -207,3 +211,15 @@ def _get_course(self, request, course_id):
def get(self, request, course_id, *args, **kwargs): # pylint: disable=arguments-differ
course = self._get_course(request, course_id)
return Response(GradingPolicySerializer(course.raw_grader, many=True).data)

class GenerateCertificateGrade(APIView):
def post(self, request, *args, **kwargs):
# user = User.objects.get(id=20543)
user = User.objects.get(id=3)
course_key = CourseKey.from_string('course-v1:edly+CS202+2015_TS')
COURSE_GRADE_NOW_PASSED.send(
sender=user,
user=user,
course_id=course_key,
)
return Response('Hi There')