Skip to content
This repository was archived by the owner on Jul 28, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cms/djangoapps/contentstore/views/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
delete_entrance_exam,
update_entrance_exam,
)
from milestones import api as milestones_api
from course_action_state.managers import CourseActionStateItemNotFoundError
from course_action_state.models import CourseRerunState, CourseRerunUIStateManager
from course_creators.views import get_course_creator_status, add_user_with_status_unrequested
Expand Down Expand Up @@ -83,6 +84,7 @@
is_prerequisite_courses_enabled,
is_valid_course_key,
set_prerequisite_courses,
remove_prerequisite_course,
)
from util.organizations_helpers import (
add_organization_course,
Expand Down Expand Up @@ -1023,6 +1025,11 @@ def settings_handler(request, course_key_string):
if not all(is_valid_course_key(course_key) for course_key in prerequisite_course_keys):
return JsonResponseBadRequest({"error": _("Invalid prerequisite course key")})
set_prerequisite_courses(course_key, prerequisite_course_keys)
else:
# None is chose so remove the course prerequites
course_milestones = milestones_api.get_course_milestones(course_key=course_key, relationship="requires")
for milestone in course_milestones:
remove_prerequisite_course(course_key, milestone)

# If the entrance exams feature has been enabled, we'll need to check for some
# feature-specific settings and handle them accordingly
Expand Down
10 changes: 7 additions & 3 deletions common/djangoapps/util/milestones_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,13 @@ def any_unfulfilled_milestones(course_id, user_id):
""" Returns a boolean if user has any unfulfilled milestones """
if not settings.FEATURES.get('MILESTONES_APP', False):
return False
return bool(
get_course_milestones_fulfillment_paths(course_id, {"id": user_id})
)

from milestones import api as milestones_api
fulfillment_paths = milestones_api.get_course_milestones_fulfillment_paths(course_id, {'id': user_id})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one comment, why not use the function in this file: get_course_milestones_fulfillment_paths ?
I see in some functions the milestones_api.get_course_..... is being used, and only in one function the get_course_milestones_fulfillment_paths in the file is being used. I do not see the difference in the result on one hand, and I do not see why from milestones import api as milestones_api has to be used many times?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other methods are using the API gateway, so I prefer keeping it like this. In the same hand, the get_course_milestones_fulfillment_paths function is rechecking the feature flag again, a reason that tells not call it.

Let's wait for edX's review and see. But we still need to know the status of the changes if we need had to merge this before edX do.

# Returns True if any of the milestones is unfulfilled. False if
# values is empty or all values are.
return any(fulfillment_paths.values())


def get_course_milestones_fulfillment_paths(course_id, user_id):
Expand Down