AA-122 created framework for dates widget on course outline
This commit is contained in:
committed by
Daphne Li-Chen
parent
5c0fd63f13
commit
84b08f366d
@@ -19,6 +19,7 @@ class DateSummarySerializer(serializers.Serializer):
|
||||
description = serializers.CharField()
|
||||
learner_has_access = serializers.SerializerMethodField()
|
||||
link = serializers.SerializerMethodField()
|
||||
link_text = serializers.CharField()
|
||||
title = serializers.CharField()
|
||||
|
||||
def get_learner_has_access(self, block):
|
||||
|
||||
@@ -3,6 +3,7 @@ Outline Tab Serializers.
|
||||
"""
|
||||
|
||||
from rest_framework import serializers
|
||||
from lms.djangoapps.course_home_api.dates.v1.serializers import DateSummarySerializer
|
||||
from rest_framework.reverse import reverse
|
||||
|
||||
|
||||
@@ -44,9 +45,19 @@ class CourseBlockSerializer(serializers.Serializer):
|
||||
}
|
||||
|
||||
|
||||
class DatesWidgetSerializer(serializers.Serializer):
|
||||
"""
|
||||
Serializer for Dates Widget data
|
||||
"""
|
||||
course_date_blocks = DateSummarySerializer(many=True)
|
||||
dates_tab_link = serializers.CharField()
|
||||
user_timezone = serializers.CharField()
|
||||
|
||||
|
||||
class OutlineTabSerializer(serializers.Serializer):
|
||||
"""
|
||||
Serializer for the Outline Tab
|
||||
"""
|
||||
course_tools = CourseToolSerializer(many=True)
|
||||
course_blocks = CourseBlockSerializer()
|
||||
dates_widget = DatesWidgetSerializer()
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
Tests for Outline Tab API in the Course Home API
|
||||
"""
|
||||
|
||||
|
||||
import ddt
|
||||
|
||||
from django.urls import reverse
|
||||
@@ -17,6 +16,7 @@ class OutlineTabTestViews(BaseCourseHomeTests):
|
||||
"""
|
||||
Tests for the Outline Tab API
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
BaseCourseHomeTests.setUpClass()
|
||||
@@ -32,6 +32,12 @@ class OutlineTabTestViews(BaseCourseHomeTests):
|
||||
self.assertTrue(course_tools)
|
||||
self.assertEquals(course_tools[0]['analytics_id'], 'edx.bookmarks')
|
||||
|
||||
dates_widget = response.data.get('dates_widget')
|
||||
self.assertTrue(dates_widget)
|
||||
date_blocks = dates_widget.get('course_date_blocks')
|
||||
self.assertTrue(all((block.get('title') != "") for block in date_blocks))
|
||||
self.assertTrue(all(block.get('date') for block in date_blocks))
|
||||
|
||||
def test_get_authenticated_user_not_enrolled(self):
|
||||
response = self.client.get(self.url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
@@ -40,6 +46,12 @@ class OutlineTabTestViews(BaseCourseHomeTests):
|
||||
course_tools = response.data.get('course_tools')
|
||||
self.assertEqual(len(course_tools), 0)
|
||||
|
||||
dates_widget = response.data.get('dates_widget')
|
||||
self.assertTrue(dates_widget)
|
||||
date_blocks = dates_widget.get('course_date_blocks')
|
||||
self.assertTrue(all((block.get('title') != "") for block in date_blocks))
|
||||
self.assertTrue(all(block.get('date') for block in date_blocks))
|
||||
|
||||
def test_get_unauthenticated_user(self):
|
||||
self.client.logout()
|
||||
response = self.client.get(self.url)
|
||||
|
||||
@@ -2,16 +2,22 @@
|
||||
Outline Tab Views
|
||||
"""
|
||||
|
||||
|
||||
from rest_framework.generics import RetrieveAPIView
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.response import Response
|
||||
|
||||
from edx_django_utils import monitoring as monitoring_utils
|
||||
from django.urls import reverse
|
||||
from opaque_keys.edx.keys import CourseKey, UsageKey
|
||||
|
||||
from lms.djangoapps.course_api.blocks.transformers.blocks_api import BlocksAPITransformer
|
||||
from lms.djangoapps.course_home_api.outline.v1.serializers import OutlineTabSerializer
|
||||
|
||||
from lms.djangoapps.course_home_api.toggles import course_home_mfe_dates_tab_is_active
|
||||
from lms.djangoapps.courseware.courses import get_course_date_blocks, get_course_with_access
|
||||
from lms.djangoapps.courseware.date_summary import TodaysDate
|
||||
from lms.djangoapps.courseware.context_processor import user_timezone_locale_prefs
|
||||
from lms.djangoapps.course_home_api.utils import get_microfrontend_url
|
||||
from openedx.core.djangoapps.content.block_structure.transformers import BlockStructureTransformers
|
||||
from openedx.features.course_experience.course_tools import CourseToolsPluginManager
|
||||
|
||||
@@ -74,6 +80,17 @@ class OutlineTabView(RetrieveAPIView):
|
||||
|
||||
course_tools = CourseToolsPluginManager.get_enabled_course_tools(request, course_key)
|
||||
|
||||
course = get_course_with_access(request.user, 'load', course_key, check_if_enrolled=False)
|
||||
date_blocks = get_course_date_blocks(course, request.user, request, num_assignments=1)
|
||||
|
||||
# User locale settings
|
||||
user_timezone_locale = user_timezone_locale_prefs(request)
|
||||
user_timezone = user_timezone_locale['user_timezone']
|
||||
|
||||
dates_tab_link = request.build_absolute_uri(reverse('dates', args=[course.id]))
|
||||
if course_home_mfe_dates_tab_is_active(course.id):
|
||||
dates_tab_link = get_microfrontend_url(course_key=course.id, view_name='dates')
|
||||
|
||||
transformers = BlockStructureTransformers()
|
||||
transformers += course_blocks_api.get_course_block_access_transformers(request.user)
|
||||
transformers += [
|
||||
@@ -82,9 +99,16 @@ class OutlineTabView(RetrieveAPIView):
|
||||
|
||||
course_blocks = get_course_blocks(request.user, course_usage_key, transformers, include_completion=True)
|
||||
|
||||
dates_widget = {
|
||||
'course_date_blocks': [block for block in date_blocks if not isinstance(block, TodaysDate)],
|
||||
'dates_tab_link': dates_tab_link,
|
||||
'user_timezone': user_timezone,
|
||||
}
|
||||
|
||||
data = {
|
||||
'course_tools': course_tools,
|
||||
'course_blocks': course_blocks,
|
||||
'dates_widget': dates_widget,
|
||||
}
|
||||
context = self.get_serializer_context()
|
||||
context['course_key'] = course_key
|
||||
|
||||
Reference in New Issue
Block a user