Skip to content

Commit

Permalink
Merge pull request #63 from edly-io/fix/discovery-bugs
Browse files Browse the repository at this point in the history
Fix: refresh_course cmd will set Unpublish status to courses and instructor image will update
  • Loading branch information
hinakhadim authored Sep 20, 2023
2 parents 28b5955 + eff8ae3 commit f6105c8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
23 changes: 13 additions & 10 deletions course_discovery/apps/course_metadata/data_loaders/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ def _update_instance(self, instance, validated_data, **kwargs):

for attr, value in validated_data.items():
if getattr(instance, attr) != value:
if attr == 'status':
continue
setattr(instance, attr, value)
updated = True

Expand All @@ -270,7 +272,7 @@ def format_course_run_data(self, body, course=None):
defaults.update({
'short_description_override': body['short_description'],
'video': self.get_courserun_video(body),
'status': CourseRunStatus.Published,
'status': CourseRunStatus.Unpublished,
'mobile_available': body.get('mobile_available') or False,
})

Expand Down Expand Up @@ -973,21 +975,25 @@ def _add_course_instructors(self, course_instructors, course_run):
course_run.staff.clear()
for course_instructor in course_instructors:
course_instructor['partner'] = course_run.course.partner
course_instructor['major_works'] = json.dumps({
'profile_image_url': course_instructor['profile_image_url'],
'marketing_url': course_instructor['marketing_url']
})
instructor, created = Person.objects.get_or_create(
id=course_instructor['marketing_id'],
partner=course_instructor['partner'],
defaults={
'given_name': course_instructor['given_name'],
'bio': course_instructor['bio'],
'email': course_instructor['email'],
'major_works': json.dumps({
'profile_image_url': course_instructor['profile_image_url'],
'marketing_url': course_instructor['marketing_url']
})
'major_works': course_instructor['major_works']
}
)
if not created:
for key, value in course_instructor.items():
if key == 'profile_image_url' or key == 'marketing_url':
continue

setattr(instructor, key, value)

instructor.given_name = instructor.given_name.title()
Expand Down Expand Up @@ -1063,15 +1069,12 @@ def _process_response(self, response):

course_run.save()
self._add_course_subjects(body['categories'], course_run)
self._add_course_instructors(
body['course_instructors'], course_run)
self._add_course_instructors(body['course_instructors'], course_run)
except CourseRun.DoesNotExist:
logger.exception(
'Could not find course run [%s]', course_run_key)
logger.exception('Could not find course run [%s]', course_run_key)
except Exception: # pylint: disable=broad-except
msg = 'An error occurred while updating {course_run} from {api_url}'.format(
course_run=course_run_key,
api_url=self.partner.marketing_site_api_url
)
logger.exception(msg)

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging

from discovery_dataloader_app import serializers
from django_elasticsearch_dsl_drf.filter_backends import FilteringFilterBackend, DefaultOrderingFilterBackend
from opaque_keys.edx.keys import CourseKey
from rest_framework import status
from rest_framework.permissions import IsAuthenticated
Expand Down Expand Up @@ -79,3 +80,12 @@ class DataLoaderCourseRunViewSet(CourseRunViewSet):
class DataLoaderCourseRunSearchViewSet(CourseRunSearchViewSet):
detail_serializer_class = serializers.DataLoaderCourseRunSearchModelSerializer
serializer_class = serializers.DataLoaderCourseRunSearchDocumentSerializer

filter_backends = [
FilteringFilterBackend,
DefaultOrderingFilterBackend,
]

filter_fields = {
'published': 'published',
}

0 comments on commit f6105c8

Please sign in to comment.