Add organization logo field in mobile apis (#36940)
* feat: Add org_logo field in mobile apis * fix: fixed quality checks
This commit is contained in:
@@ -16,6 +16,7 @@ from lms.djangoapps.courseware.access_utils import check_course_open_for_learner
|
||||
from lms.djangoapps.courseware.courses import get_assignments_completions
|
||||
from lms.djangoapps.mobile_api.course_info.utils import get_user_certificate_download_url
|
||||
from lms.djangoapps.mobile_api.users.serializers import ModeSerializer
|
||||
from lms.djangoapps.mobile_api.utils import get_course_organization_logo
|
||||
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
|
||||
from openedx.features.course_duration_limits.access import get_user_course_expiration_date
|
||||
|
||||
@@ -28,6 +29,7 @@ class CourseInfoOverviewSerializer(serializers.ModelSerializer):
|
||||
name = serializers.CharField(source='display_name')
|
||||
number = serializers.CharField(source='display_number_with_default')
|
||||
org = serializers.CharField(source='display_org_with_default')
|
||||
org_logo = serializers.SerializerMethodField()
|
||||
is_self_paced = serializers.BooleanField(source='self_paced')
|
||||
media = serializers.SerializerMethodField()
|
||||
course_sharing_utm_parameters = serializers.SerializerMethodField()
|
||||
@@ -41,6 +43,7 @@ class CourseInfoOverviewSerializer(serializers.ModelSerializer):
|
||||
'name',
|
||||
'number',
|
||||
'org',
|
||||
'org_logo',
|
||||
'start',
|
||||
'start_display',
|
||||
'start_type',
|
||||
@@ -85,6 +88,9 @@ class CourseInfoOverviewSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
return get_assignments_completions(obj.id, self.context.get('user'))
|
||||
|
||||
def get_org_logo(self, course_overview):
|
||||
return get_course_organization_logo(course_overview.id)
|
||||
|
||||
|
||||
class MobileCourseEnrollmentSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
|
||||
@@ -17,7 +17,7 @@ from lms.djangoapps.certificates.api import certificate_downloadable_status
|
||||
from lms.djangoapps.courseware.access import has_access
|
||||
from lms.djangoapps.courseware.courses import get_assignments_completions, get_past_and_future_course_assignments
|
||||
from lms.djangoapps.course_home_api.dates.serializers import DateSummarySerializer
|
||||
from lms.djangoapps.mobile_api.utils import API_V4
|
||||
from lms.djangoapps.mobile_api.utils import API_V4, get_course_organization_logo
|
||||
from openedx.features.course_duration_limits.access import get_user_course_expiration_date
|
||||
from xmodule.modulestore.django import modulestore
|
||||
from xmodule.modulestore.exceptions import ItemNotFoundError, NoPathToItem
|
||||
@@ -39,6 +39,7 @@ class CourseOverviewField(serializers.RelatedField): # lint-amnesty, pylint: di
|
||||
'name': course_overview.display_name,
|
||||
'number': course_overview.display_number_with_default,
|
||||
'org': course_overview.display_org_with_default,
|
||||
'org_logo': get_course_organization_logo(course_id),
|
||||
|
||||
# dates
|
||||
'start': course_overview.start,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""
|
||||
Common utility methods for Mobile APIs.
|
||||
"""
|
||||
from organizations import api as organizations_api
|
||||
|
||||
API_V05 = 'v0.5'
|
||||
API_V1 = 'v1'
|
||||
@@ -12,3 +13,16 @@ API_V4 = 'v4'
|
||||
def parsed_version(version):
|
||||
""" Converts string X.X.X.Y to int tuple (X, X, X) """
|
||||
return tuple(map(int, (version.split(".")[:3])))
|
||||
|
||||
|
||||
def get_course_organization_logo(course_key):
|
||||
"""
|
||||
Get organization logo of given course key.
|
||||
"""
|
||||
organization_logo = None
|
||||
organizations = organizations_api.get_course_organizations(course_key=course_key)
|
||||
if organizations:
|
||||
organization = organizations[0]
|
||||
organization_logo = organization.get('logo', None)
|
||||
|
||||
return str(organization_logo.url) if organization_logo else ''
|
||||
|
||||
Reference in New Issue
Block a user