Skip to content

Commit

Permalink
Merge pull request openedx#6 from andela-ijubril/certificate
Browse files Browse the repository at this point in the history
Add certificate info to User API endpoint
  • Loading branch information
mmassaki authored Jul 14, 2016
2 parents f364e47 + 3cba886 commit ac6cff3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
32 changes: 31 additions & 1 deletion lms/djangoapps/certificates/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,40 @@
CertificateTemplate,
)
from certificates.queue import XQueueCertInterface

from openedx.core.djangoapps.content.course_overviews.models import CourseOverview

log = logging.getLogger("edx.certificate")

def get_certificates_for_user_basic(username):
"""
Retrieve basic certificate information for a particular user.
Arguments:
username (unicode): The identifier of the user.
Returns: list
Example Usage:
>>> get_certificates_for_user_basic("bob")
[
{
"course_title": "some course",
"download_url": "/certificates/user/3/course/course-v1:APC101:2016_S1",
}
]
"""

return [
{
"course_title": CourseOverview.objects.get(id=cert.course_id).display_name,
"download_url": (
cert.download_url or get_certificate_url(cert.user.id, cert.course_id)
if cert.status == CertificateStatuses.downloadable
else None
),
}
for cert in GeneratedCertificate.objects.filter(user__username=username).order_by("course_id") ]

def get_certificates_for_user(username):
"""
Expand Down
7 changes: 5 additions & 2 deletions openedx/core/djangoapps/user_api/accounts/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from . import (
ACCOUNT_VISIBILITY_PREF_KEY, ALL_USERS_VISIBILITY, PRIVATE_VISIBILITY,
)

from certificates.api import get_certificates_for_user_basic

PROFILE_IMAGE_KEY_PREFIX = 'image_url'

Expand Down Expand Up @@ -98,11 +98,14 @@ def to_representation(self, user):
"account_privacy": self._get_profile_visibility(profile, user),
}

return self._filter_fields(
filtered_data = self._filter_fields(
self._visible_fields(profile, user),
data
)

filtered_data['certificates'] = get_certificates_for_user_basic(user.username)
return filtered_data

def _visible_fields(self, user_profile, user):
"""
Return what fields should be visible based on user settings
Expand Down

0 comments on commit ac6cff3

Please sign in to comment.