Create backend for three day streak celebration
This feature uses the first_day_of_streak, last_day_of_streak and last_streak_celebration fields to determine whether the user should see a celebration. AA-304
This commit is contained in:
@@ -40,3 +40,4 @@ class CourseHomeMetadataSerializer(serializers.Serializer):
|
||||
original_user_is_staff = serializers.BooleanField()
|
||||
tabs = CourseTabSerializer(many=True)
|
||||
title = serializers.CharField()
|
||||
celebrations = serializers.DictField()
|
||||
|
||||
@@ -2,17 +2,25 @@
|
||||
Tests for the Course Home Course Metadata API in the Course Home API
|
||||
"""
|
||||
|
||||
|
||||
import ddt
|
||||
from django.urls import reverse
|
||||
|
||||
from edx_toggles.toggles.testutils import override_waffle_flag
|
||||
from common.djangoapps.course_modes.models import CourseMode
|
||||
from lms.djangoapps.courseware.toggles import (
|
||||
COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES,
|
||||
COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES_STREAK_CELEBRATION,
|
||||
REDIRECT_TO_COURSEWARE_MICROFRONTEND
|
||||
)
|
||||
from common.djangoapps.student.models import CourseEnrollment
|
||||
from common.djangoapps.student.tests.factories import UserFactory
|
||||
from lms.djangoapps.course_home_api.tests.utils import BaseCourseHomeTests
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
@override_waffle_flag(REDIRECT_TO_COURSEWARE_MICROFRONTEND, active=True)
|
||||
@override_waffle_flag(COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES, active=True)
|
||||
@override_waffle_flag(COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES_STREAK_CELEBRATION, active=True)
|
||||
class CourseHomeMetadataTests(BaseCourseHomeTests):
|
||||
"""
|
||||
Tests for the Course Home Course Metadata API
|
||||
@@ -49,3 +57,10 @@ class CourseHomeMetadataTests(BaseCourseHomeTests):
|
||||
url = reverse('course-home-course-metadata', args=['course-v1:unknown+course+2T2020'])
|
||||
response = self.client.get(url)
|
||||
assert response.status_code == 404
|
||||
|
||||
def test_streak_data_in_response(self):
|
||||
""" Test that metadata endpoint returns data for the streak celebration """
|
||||
CourseEnrollment.enroll(self.user, self.course.id, 'audit')
|
||||
response = self.client.get(self.url, content_type='application/json')
|
||||
celebrations = response.json()['celebrations']
|
||||
assert 'streak_length_to_celebrate' in celebrations
|
||||
|
||||
@@ -12,7 +12,7 @@ from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthenticat
|
||||
from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser
|
||||
from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser
|
||||
|
||||
from common.djangoapps.student.models import CourseEnrollment
|
||||
from common.djangoapps.student.models import CourseEnrollment, UserCelebration
|
||||
from lms.djangoapps.course_api.api import course_detail
|
||||
from lms.djangoapps.course_home_api.course_metadata.v1.serializers import CourseHomeMetadataSerializer
|
||||
from lms.djangoapps.courseware.access import has_access
|
||||
@@ -48,6 +48,7 @@ class CourseHomeMetadataView(RetrieveAPIView):
|
||||
title: (str) The title of the tab to display
|
||||
url: (str) The url to view the tab
|
||||
title: (str) The Course's display title
|
||||
celebrations: (dict) a dict of celebration data
|
||||
|
||||
**Returns**
|
||||
|
||||
@@ -77,7 +78,12 @@ class CourseHomeMetadataView(RetrieveAPIView):
|
||||
|
||||
course = course_detail(request, request.user.username, course_key)
|
||||
user_is_enrolled = CourseEnrollment.is_enrolled(request.user, course_key_string)
|
||||
|
||||
browser_timezone = request.query_params.get('browser_timezone', None)
|
||||
celebrations = {
|
||||
'streak_length_to_celebrate': UserCelebration.perform_streak_updates(
|
||||
request.user, course_key, browser_timezone
|
||||
)
|
||||
}
|
||||
data = {
|
||||
'course_id': course.id,
|
||||
'is_staff': has_access(request.user, 'staff', course_key).has_access,
|
||||
@@ -88,6 +94,7 @@ class CourseHomeMetadataView(RetrieveAPIView):
|
||||
'title': course.display_name_with_default,
|
||||
'is_self_paced': getattr(course, 'self_paced', False),
|
||||
'is_enrolled': user_is_enrolled,
|
||||
'celebrations': celebrations,
|
||||
}
|
||||
context = self.get_serializer_context()
|
||||
context['course'] = course
|
||||
|
||||
@@ -85,6 +85,22 @@ COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES_FIRST_SECTION_CELEBRATION = CourseW
|
||||
WAFFLE_FLAG_NAMESPACE, 'mfe_progress_milestones_first_section_celebration', __name__
|
||||
)
|
||||
|
||||
# .. toggle_name: courseware.mfe_progress_milestones_streak_celebration
|
||||
# .. toggle_implementation: CourseWaffleFlag
|
||||
# .. toggle_default: False
|
||||
# .. toggle_description: Waffle flag to display a celebration modal when learner completes a configurable streak
|
||||
# Supports staged rollout to students for a new micro-frontend-based implementation of the
|
||||
# courseware page.
|
||||
# .. toggle_use_cases: temporary, open_edx
|
||||
# .. toggle_creation_date: 2021-02-16
|
||||
# .. toggle_target_removal_date: None
|
||||
# .. toggle_warnings: Also set settings.LEARNING_MICROFRONTEND_URL and ENABLE_COURSEWARE_MICROFRONTEND and
|
||||
# COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES.
|
||||
# .. toggle_tickets: AA-304
|
||||
COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES_STREAK_CELEBRATION = CourseWaffleFlag(
|
||||
WAFFLE_FLAG_NAMESPACE, 'mfe_progress_milestones_streak_celebration', __name__
|
||||
)
|
||||
|
||||
# .. toggle_name: courseware.proctoring_improvements
|
||||
# .. toggle_implementation: CourseWaffleFlag
|
||||
# .. toggle_default: False
|
||||
@@ -144,3 +160,11 @@ def courseware_mfe_first_section_celebration_is_active(course_key):
|
||||
COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES.is_enabled(course_key) and
|
||||
COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES_FIRST_SECTION_CELEBRATION.is_enabled(course_key)
|
||||
)
|
||||
|
||||
|
||||
def courseware_mfe_streak_celebration_is_active(course_key):
|
||||
return (
|
||||
REDIRECT_TO_COURSEWARE_MICROFRONTEND.is_enabled(course_key) and
|
||||
COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES.is_enabled(course_key) and
|
||||
COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES_STREAK_CELEBRATION.is_enabled(course_key)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user