Skip to content

Commit

Permalink
fix: always display course title for vc course cards
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrylo-kh committed Jan 17, 2025
1 parent 48069df commit 7350c69
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 3 additions & 3 deletions credentials/apps/verifiable_credentials/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def test_get_user_course_credentials_data_one_course(self):
assert result[0]["download_url"] == self.course_user_credentials[0].download_url
assert result[0]["credential_id"] == self.course_user_credentials[0].credential_id
assert result[0]["credential_uuid"] == self.course_user_credentials[0].credential.course_id
assert result[0]["credential_title"] == self.course_user_credentials[0].credential.title
assert result[0]["credential_title"] == self.course.title

def test_get_user_course_credentials_data_multiple_courses(self):
result = get_user_credentials_data(self.user.username, "coursecertificate")
Expand All @@ -156,15 +156,15 @@ def test_get_user_course_credentials_data_multiple_courses(self):
assert result[0]["download_url"] == self.course_user_credentials[0].download_url
assert result[0]["credential_id"] == self.course_user_credentials[0].credential_id
assert result[0]["credential_uuid"] == self.course_user_credentials[0].credential.course_id
assert result[0]["credential_title"] == self.course_user_credentials[0].credential.title
assert result[0]["credential_title"] == self.course.title

assert result[1]["uuid"] == str(self.course_user_credentials[1].uuid).replace("-", "")
assert result[1]["status"] == self.course_user_credentials[1].status
assert result[1]["username"] == self.course_user_credentials[1].username
assert result[1]["download_url"] == self.course_user_credentials[1].download_url
assert result[1]["credential_id"] == self.course_user_credentials[1].credential_id
assert result[1]["credential_uuid"] == self.course_user_credentials[1].credential.course_id
assert result[1]["credential_title"] == self.course_user_credentials[1].credential.title
assert result[1]["credential_title"] == self.course.title

def test_non_existing_content_type(self):
result = get_user_credentials_data(self.user.username, "non_existing_content_type")
Expand Down
5 changes: 4 additions & 1 deletion credentials/apps/verifiable_credentials/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import qrcode
from django.contrib.contenttypes.models import ContentType

from credentials.apps.catalog.models import CourseRun
from credentials.apps.credentials.api import get_user_credentials_by_content_type
from credentials.apps.credentials.data import UserCredentialStatus

Expand Down Expand Up @@ -39,8 +40,10 @@ def get_user_credentials_data(username, model):
credential.credential.program.authoring_organizations.values_list("name", flat=True)
)
elif model == "coursecertificate":
course_run = CourseRun.objects.filter(key=credential.credential.course_id).first()
course = getattr(course_run, "course", None)
credential_uuid = credential.credential.course_id
credential_title = credential.credential.title
credential_title = credential.credential.title or getattr(course, "title", "")
credential_org = credential.credential.course_key.org

data.append(
Expand Down

0 comments on commit 7350c69

Please sign in to comment.