def test_wrap_xblock(self, course_id, data_usage_id):
     """
     Verify that new content is added and the resources are the same.
     """
     fragment = self.create_fragment(u"<h1>Test!</h1>")
     fragment.initialize_js(
         'BlockMain'
     )  # wrap_block() sets some attributes only if there is JS.
     course = getattr(self, course_id)
     test_wrap_output = wrap_xblock(
         runtime_class='TestRuntime',
         block=course,
         view='baseview',
         frag=fragment,
         context={"wrap_xblock_data": {
             "custom-attribute": "custom-value"
         }},
         usage_id_serializer=lambda usage_id: quote_slashes(
             six.text_type(usage_id)),
         request_token=uuid.uuid1().hex)
     assert isinstance(test_wrap_output, Fragment)
     assert 'xblock-baseview' in test_wrap_output.content
     assert 'data-runtime-class="TestRuntime"' in test_wrap_output.content
     assert data_usage_id in test_wrap_output.content
     assert '<h1>Test!</h1>' in test_wrap_output.content
     assert 'data-custom-attribute="custom-value"' in test_wrap_output.content
     assert test_wrap_output.resources[
         0].data == u'body {background-color:red;}'
     assert test_wrap_output.resources[1].data == 'alert("Hi!");'
Exemple #2
0
 def test_wrap_xblock(self, course_id, data_usage_id):
     """
     Verify that new content is added and the resources are the same.
     """
     fragment = self.create_fragment(u"<h1>Test!</h1>")
     course = getattr(self, course_id)
     test_wrap_output = wrap_xblock(
         runtime_class='TestRuntime',
         block=course,
         view='baseview',
         frag=fragment,
         context={"wrap_xblock_data": {
             "custom-attribute": "custom-value"
         }},
         usage_id_serializer=lambda usage_id: quote_slashes(
             unicode(usage_id)),
         request_token=uuid.uuid1().get_hex())
     self.assertIsInstance(test_wrap_output, Fragment)
     self.assertIn('xblock-baseview', test_wrap_output.content)
     self.assertIn('data-runtime-class="TestRuntime"',
                   test_wrap_output.content)
     self.assertIn(data_usage_id, test_wrap_output.content)
     self.assertIn('<h1>Test!</h1>', test_wrap_output.content)
     self.assertIn('data-custom-attribute="custom-value"',
                   test_wrap_output.content)
     self.assertEqual(test_wrap_output.resources[0].data,
                      u'body {background-color:red;}')
     self.assertEqual(test_wrap_output.resources[1].data, 'alert("Hi!");')
def _section_send_email(course, access):
    """ Provide data for the corresponding bulk email section """
    course_key = course.id

    # Monkey-patch applicable_aside_types to return no asides for the duration of this render
    with patch.object(course.runtime, 'applicable_aside_types',
                      null_applicable_aside_types):
        # This HtmlDescriptor is only being used to generate a nice text editor.
        html_module = HtmlDescriptor(
            course.system, DictFieldData({'data': ''}),
            ScopeIds(None, None, None,
                     course_key.make_usage_key('html', 'fake')))
        fragment = course.system.render(html_module, 'studio_view')
    fragment = wrap_xblock(
        'LmsRuntime',
        html_module,
        'studio_view',
        fragment,
        None,
        extra_data={"course-id": unicode(course_key)},
        usage_id_serializer=lambda usage_id: quote_slashes(unicode(usage_id)),
        # Generate a new request_token here at random, because this module isn't connected to any other
        # xblock rendering.
        request_token=uuid.uuid1().get_hex())
    cohorts = []
    if is_course_cohorted(course_key):
        cohorts = get_course_cohorts(course)
    email_editor = fragment.content
    section_data = {
        'section_key':
        'send_email',
        'section_display_name':
        _('Email'),
        'access':
        access,
        'send_email':
        reverse('send_email', kwargs={'course_id': unicode(course_key)}),
        'editor':
        email_editor,
        'cohorts':
        cohorts,
        'default_cohort_name':
        DEFAULT_COHORT_NAME,
        'list_instructor_tasks_url':
        reverse('list_instructor_tasks',
                kwargs={'course_id': unicode(course_key)}),
        'email_background_tasks_url':
        reverse('list_background_email_tasks',
                kwargs={'course_id': unicode(course_key)}),
        'email_content_history_url':
        reverse('list_email_content',
                kwargs={'course_id': unicode(course_key)}),
    }
    return section_data
def _section_send_email(course, access):
    """ Provide data for the corresponding bulk email section """
    course_key = course.id

    # Monkey-patch applicable_aside_types to return no asides for the duration of this render
    with patch.object(course.runtime, 'applicable_aside_types', null_applicable_aside_types):
        # This HtmlBlock is only being used to generate a nice text editor.
        html_module = HtmlBlock(
            course.system,
            DictFieldData({'data': ''}),
            ScopeIds(None, None, None, course_key.make_usage_key('html', 'fake'))
        )
        fragment = course.system.render(html_module, 'studio_view')
    fragment = wrap_xblock(
        'LmsRuntime', html_module, 'studio_view', fragment, None,
        extra_data={"course-id": str(course_key)},
        usage_id_serializer=lambda usage_id: quote_slashes(str(usage_id)),
        # Generate a new request_token here at random, because this module isn't connected to any other
        # xblock rendering.
        request_token=uuid.uuid1().hex
    )
    cohorts = []
    if is_course_cohorted(course_key):
        cohorts = get_course_cohorts(course)
    course_modes = []
    if not VerifiedTrackCohortedCourse.is_verified_track_cohort_enabled(course_key):
        course_modes = CourseMode.modes_for_course(course_key, include_expired=True, only_selectable=False)
    email_editor = fragment.content
    section_data = {
        'section_key': 'send_email',
        'section_display_name': _('Email'),
        'access': access,
        'send_email': reverse('send_email', kwargs={'course_id': str(course_key)}),
        'editor': email_editor,
        'cohorts': cohorts,
        'course_modes': course_modes,
        'default_cohort_name': DEFAULT_COHORT_NAME,
        'list_instructor_tasks_url': reverse(
            'list_instructor_tasks', kwargs={'course_id': str(course_key)}
        ),
        'email_background_tasks_url': reverse(
            'list_background_email_tasks', kwargs={'course_id': str(course_key)}
        ),
        'email_content_history_url': reverse(
            'list_email_content', kwargs={'course_id': str(course_key)}
        ),
    }
    if settings.FEATURES.get("ENABLE_NEW_BULK_EMAIL_EXPERIENCE", False) is not False:
        section_data[
            "communications_mfe_url"
        ] = f"{settings.COMMUNICATIONS_MICROFRONTEND_URL}/courses/{str(course_key)}/bulk_email"
    return section_data
def _section_send_email(course, access):
    """ Provide data for the corresponding bulk email section """
    course_key = course.id

    # Monkey-patch applicable_aside_types to return no asides for the duration of this render
    with patch.object(course.runtime, 'applicable_aside_types', null_applicable_aside_types):
        # This HtmlDescriptor is only being used to generate a nice text editor.
        html_module = HtmlDescriptor(
            course.system,
            DictFieldData({'data': ''}),
            ScopeIds(None, None, None, course_key.make_usage_key('html', 'fake'))
        )
        fragment = course.system.render(html_module, 'studio_view')
    fragment = wrap_xblock(
        'LmsRuntime', html_module, 'studio_view', fragment, None,
        extra_data={"course-id": unicode(course_key)},
        usage_id_serializer=lambda usage_id: quote_slashes(unicode(usage_id)),
        # Generate a new request_token here at random, because this module isn't connected to any other
        # xblock rendering.
        request_token=uuid.uuid1().get_hex()
    )
    cohorts = []
    if is_course_cohorted(course_key):
        cohorts = get_course_cohorts(course)
    course_modes = []
    if not VerifiedTrackCohortedCourse.is_verified_track_cohort_enabled(course_key):
        course_modes = CourseMode.modes_for_course(course_key, include_expired=True, only_selectable=False)
    email_editor = fragment.content
    section_data = {
        'section_key': 'send_email',
        'section_display_name': _('Email'),
        'access': access,
        'send_email': reverse('send_email', kwargs={'course_id': unicode(course_key)}),
        'editor': email_editor,
        'cohorts': cohorts,
        'course_modes': course_modes,
        'default_cohort_name': DEFAULT_COHORT_NAME,
        'list_instructor_tasks_url': reverse(
            'list_instructor_tasks', kwargs={'course_id': unicode(course_key)}
        ),
        'email_background_tasks_url': reverse(
            'list_background_email_tasks', kwargs={'course_id': unicode(course_key)}
        ),
        'email_content_history_url': reverse(
            'list_email_content', kwargs={'course_id': unicode(course_key)}
        ),
    }
    from openedx.stanford.lms.djangoapps.instructor.views.instructor_dashboard import send_email_section_data
    section_data.update(send_email_section_data())
    return section_data
def _section_send_email(course, access):
    """ Provide data for the corresponding bulk email section """
    course_key = course.id
    queries = GroupedQuery.objects.filter(course_id=course_key)
    query_options = tuple(
        (query.id, query.title or u'Query saved at ' + query.created.strftime("%m-%d-%y %H:%M"))
        for query in queries
    )

    # Monkey-patch applicable_aside_types to return no asides for the duration of this render
    with patch.object(course.runtime, 'applicable_aside_types', null_applicable_aside_types):
        # This HtmlDescriptor is only being used to generate a nice text editor.
        html_module = HtmlDescriptor(
            course.system,
            DictFieldData({'data': ''}),
            ScopeIds(None, None, None, course_key.make_usage_key('html', 'fake'))
        )
        fragment = course.system.render(html_module, 'studio_view')
    fragment = wrap_xblock(
        'LmsRuntime', html_module, 'studio_view', fragment, None,
        extra_data={"course-id": unicode(course_key)},
        usage_id_serializer=lambda usage_id: quote_slashes(unicode(usage_id)),
        # Generate a new request_token here at random, because this module isn't connected to any other
        # xblock rendering.
        request_token=uuid.uuid1().get_hex()
    )
    email_editor = fragment.content
    section_data = {
        'section_key': 'send_email',
        'section_display_name': _('Email'),
        'keywords_supported': get_keywords_supported(),
        'access': access,
        'to_options': query_options,
        'send_email': reverse('send_email', kwargs={'course_id': unicode(course_key)}),
        'editor': email_editor,
        'list_instructor_tasks_url': reverse(
            'list_instructor_tasks', kwargs={'course_id': unicode(course_key)}
        ),
        'email_background_tasks_url': reverse(
            'list_background_email_tasks', kwargs={'course_id': unicode(course_key)}
        ),
        'email_content_history_url': reverse(
            'list_email_content', kwargs={'course_id': unicode(course_key)}
        ),
    }
    return section_data
 def test_wrap_xblock(self, course_id, data_usage_id):
     """
     Verify that new content is added and the resources are the same.
     """
     fragment = self.create_fragment(u"<h1>Test!</h1>")
     course = getattr(self, course_id)
     test_wrap_output = wrap_xblock(
         runtime_class='TestRuntime',
         block=course,
         view='baseview',
         frag=fragment,
         context=None,
         usage_id_serializer=lambda usage_id: quote_slashes(unicode(usage_id)),
         request_token=uuid.uuid1().get_hex()
     )
     self.assertIsInstance(test_wrap_output, Fragment)
     self.assertIn('xblock-baseview', test_wrap_output.content)
     self.assertIn('data-runtime-class="TestRuntime"', test_wrap_output.content)
     self.assertIn(data_usage_id, test_wrap_output.content)
     self.assertIn('<h1>Test!</h1>', test_wrap_output.content)
     self.assertEqual(test_wrap_output.resources[0].data, u'body {background-color:red;}')
     self.assertEqual(test_wrap_output.resources[1].data, 'alert("Hi!");')
def _section_send_email(course, access):
    """ Provide data for the corresponding bulk email section """
    course_key = course.id

    # Monkey-patch applicable_aside_types to return no asides for the duration of this render
    with patch.object(course.runtime, "applicable_aside_types", null_applicable_aside_types):
        # This HtmlDescriptor is only being used to generate a nice text editor.
        html_module = HtmlDescriptor(
            course.system,
            DictFieldData({"data": ""}),
            ScopeIds(None, None, None, course_key.make_usage_key("html", "fake")),
        )
        fragment = course.system.render(html_module, "studio_view")
    fragment = wrap_xblock(
        "LmsRuntime",
        html_module,
        "studio_view",
        fragment,
        None,
        extra_data={"course-id": unicode(course_key)},
        usage_id_serializer=lambda usage_id: quote_slashes(unicode(usage_id)),
        # Generate a new request_token here at random, because this module isn't connected to any other
        # xblock rendering.
        request_token=uuid.uuid1().get_hex(),
    )
    email_editor = fragment.content
    section_data = {
        "section_key": "send_email",
        "section_display_name": _("Email"),
        "access": access,
        "send_email": reverse("send_email", kwargs={"course_id": unicode(course_key)}),
        "editor": email_editor,
        "list_instructor_tasks_url": reverse("list_instructor_tasks", kwargs={"course_id": unicode(course_key)}),
        "email_background_tasks_url": reverse("list_background_email_tasks", kwargs={"course_id": unicode(course_key)}),
        "email_content_history_url": reverse("list_email_content", kwargs={"course_id": unicode(course_key)}),
    }
    return section_data
def _section_recap(request, course, recap_blocks, access):
    """Provide data for the Recap dashboard section """

    course_key = course.id
    recap_items = []
    recap_fragments = []

    # Get list of enrolled students for this course

    user_list = User.objects.filter(
        courseenrollment__course_id=course_key,
        courseenrollment__is_active=1,
    ).order_by('username').select_related('profile')

    for block in recap_blocks:
        recap_items.append({
            'name':
            block.display_name,
            'block_list':
            block.xblock_list,
            'url_base':
            reverse(
                'xblock_view',
                args=[course.id, block.location, 'recap_blocks_listing_view']),
            'make_pdf_json':
            reverse('xblock_handler',
                    args=[course.id, block.location, 'make_pdf_json']),
        })

    recap_block = recap_blocks[0]
    block, __ = get_module_by_usage_id(request,
                                       unicode(course_key),
                                       unicode(recap_block.location),
                                       disable_staff_debug_info=True,
                                       course=course)
    # Set up recap instructor dashboard fragment, pass data to the context
    fragment = block.render('recap_blocks_listing_view',
                            context={
                                'recap_items': recap_items,
                                'users': user_list,
                            })
    # Wrap the fragment and get all resources associated with this XBlock view
    fragment = wrap_xblock(
        'LmsRuntime',
        recap_block,
        'recap_blocks_listing_view',
        fragment,
        None,
        extra_data={"course-id": unicode(course_key)},
        usage_id_serializer=lambda usage_id: quote_slashes(unicode(usage_id)),
        # Generate a new request_token here at random, because this module isn't connected to any other
        # xblock rendering.
        request_token=uuid.uuid1().get_hex())

    section_data = {
        'fragment': fragment,
        'users': user_list,
        'section_key': 'recap',
        'section_display_name': _('Recap'),
        'access': access,
        'course_id': unicode(course_key)
    }

    return section_data