Commit d06edc68 by Hasnain Committed by hasnain-naveed

Added two fields in credit API

parent a26d5764
......@@ -10,6 +10,7 @@ import pytz
from django.db import transaction
from lms.djangoapps.django_comment_client.utils import JsonResponse
from edx_proctoring.api import get_last_exam_completion_date
from openedx.core.djangoapps.credit.exceptions import (
UserIsNotEligible,
CreditProviderNotConfigured,
......@@ -23,8 +24,12 @@ from openedx.core.djangoapps.credit.models import (
CreditRequest,
CreditEligibility,
)
from student.models import (
User,
CourseEnrollment,
)
from openedx.core.djangoapps.credit.signature import signature, get_shared_secret_key
from student.models import User
from util.date_utils import to_timestamp
......@@ -264,12 +269,21 @@ def create_credit_request(course_key, provider_id, username):
log.exception(msg)
raise UserIsNotEligible(msg)
# Getting the students's enrollment date
course_enrollment = CourseEnrollment.get_enrollment(user, course_key)
enrollment_date = course_enrollment.created if course_enrollment else ""
# Getting the student's course completion date
completion_date = get_last_exam_completion_date(course_key, username)
parameters = {
"request_uuid": credit_request.uuid,
"timestamp": to_timestamp(datetime.datetime.now(pytz.UTC)),
"course_org": course_key.org,
"course_num": course_key.course,
"course_run": course_key.run,
"enrollment_timestamp": to_timestamp(enrollment_date) if enrollment_date else "",
"course_completion_timestamp": to_timestamp(completion_date) if completion_date else "",
"final_grade": final_grade,
"user_username": user.username,
"user_email": user.email,
......
......@@ -720,10 +720,12 @@ class CreditProviderIntegrationApiTests(CreditApiTestBase):
# - 2 queries: Get-or-create the credit request.
# - 1 query: Retrieve user account and profile information from the user API.
# - 1 query: Look up the user's final grade from the credit requirements table.
# - 1 query: Look up the user's enrollment date in the course.
# - 2 query: Look up the user's completion date in the course.
# - 1 query: Update the request.
# - 2 queries: Update the history table for the request.
# - 4 Django savepoints
with self.assertNumQueries(13):
with self.assertNumQueries(16):
request = api.create_credit_request(self.course_key, self.PROVIDER_ID, self.USER_INFO['username'])
# - 2 queries: Retrieve and update the request
......
......@@ -91,7 +91,7 @@ git+https://github.com/edx/xblock-utils.git@v1.0.2#egg=xblock-utils==1.0.2
-e git+https://github.com/edx-solutions/xblock-google-drive.git@138e6fa0bf3a2013e904a085b9fed77dab7f3f21#egg=xblock-google-drive
-e git+https://github.com/edx/edx-reverification-block.git@0.0.5#egg=edx-reverification-block==0.0.5
git+https://github.com/edx/edx-user-state-client.git@1.0.1#egg=edx-user-state-client==1.0.1
git+https://github.com/edx/edx-proctoring.git@0.12.8#egg=edx-proctoring==0.12.8
git+https://github.com/edx/edx-proctoring.git@0.12.9#egg=edx-proctoring==0.12.9
git+https://github.com/edx/xblock-lti-consumer.git@v1.0.3#egg=xblock-lti-consumer==1.0.3
# Third Party XBlocks
......
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