示例#1
0
    def test_retrieve_last_sitewide_block_completed(self):
        """
        Test that the method returns a URL for the "last completed" block
        when sending a user object
        """
        block_url = retrieve_last_sitewide_block_completed(self.engaged_user)
        empty_block_url = retrieve_last_sitewide_block_completed(
            self.cruft_user)
        assert block_url ==\
               'test_url:9999/courses/{org}/{course}/{run}/jump_to/i4x://{org}/{course}/vertical/{vertical_id}'.format(
                   org=self.course.location.course_key.org,
                   course=self.course.location.course_key.course,
                   run=self.course.location.course_key.run,
                   vertical_id=self.vertical2.location.block_id
               )

        assert empty_block_url is None
示例#2
0
 def test_retrieve_last_sitewide_block_completed(self, use_username):
     """
     Test that the method returns a URL for the "last completed" block
     when sending a user object
     """
     block_url = retrieve_last_sitewide_block_completed(
         self.engaged_user.username if use_username else self.engaged_user
     )
     empty_block_url = retrieve_last_sitewide_block_completed(
         self.cruft_user.username if use_username else self.cruft_user
     )
     self.assertEqual(
         block_url,
         u'test_url:9999/courses/{org}/{course}/{run}/jump_to/i4x://{org}/{course}/vertical/{vertical_id}'.format(
             org=self.course.location.course_key.org,
             course=self.course.location.course_key.course,
             run=self.course.location.course_key.run,
             vertical_id=self.vertical2.location.block_id,
         )
     )
     self.assertEqual(empty_block_url, None)
示例#3
0
 def test_retrieve_last_sitewide_block_completed(self, use_username, get_patched_current_site):  # pylint: disable=unused-argument
     """
     Test that the method returns a URL for the "last completed" block
     when sending a user object
     """
     block_url = retrieve_last_sitewide_block_completed(
         self.engaged_user.username if use_username else self.engaged_user
     )
     empty_block_url = retrieve_last_sitewide_block_completed(
         self.cruft_user.username if use_username else self.cruft_user
     )
     self.assertEqual(
         block_url,
         u'test_url:9999/courses/{org}/{course}/{run}/jump_to/i4x://{org}/{course}/vertical/{vertical_id}'.format(
             org=self.course.location.course_key.org,
             course=self.course.location.course_key.course,
             run=self.course.location.course_key.run,
             vertical_id=self.vertical2.location.block_id,
         )
     )
     self.assertEqual(empty_block_url, None)
示例#4
0
    def _get_expected_header_urls(self):
        expected_header_urls = {
            'logout': reverse('logout'),
            'resume_block': retrieve_last_sitewide_block_completed(self.user),
            'account_settings': reverse('account_settings'),
            'learner_profile': reverse('learner_profile', kwargs={'username': self.user.username}),
        }

        # Convert relative URL paths to absolute URIs
        for url_name, url_path in six.iteritems(expected_header_urls):
            expected_header_urls[url_name] = self.request.build_absolute_uri(url_path)

        return expected_header_urls
示例#5
0
def _get_user_info_cookie_data(request, user):
    """ Returns information that will populate the user info cookie. """

    # Set a cookie with user info.  This can be used by external sites
    # to customize content based on user information.  Currently,
    # we include information that's used to customize the "account"
    # links in the header of subdomain sites (such as the marketing site).
    header_urls = {'logout': reverse('logout')}

    # Unfortunately, this app is currently used by both the LMS and Studio login pages.
    # If we're in Studio, we won't be able to reverse the account/profile URLs.
    # To handle this, we don't add the URLs if we can't reverse them.
    # External sites will need to have fallback mechanisms to handle this case
    # (most likely just hiding the links).
    try:
        header_urls['account_settings'] = reverse('account_settings')
        header_urls['learner_profile'] = reverse(
            'learner_profile', kwargs={'username': user.username})
    except NoReverseMatch:
        pass

    # Add 'resume course' last completed block
    try:
        header_urls['resume_block'] = retrieve_last_sitewide_block_completed(
            user)
    except User.DoesNotExist:
        pass

    # Convert relative URL paths to absolute URIs
    for url_name, url_path in six.iteritems(header_urls):
        header_urls[url_name] = request.build_absolute_uri(url_path)

    profile_image_url = get_profile_image_urls_for_user(user)['medium']

    user_info = {
        'version':
        settings.EDXMKTG_USER_INFO_COOKIE_VERSION,
        'username':
        user.username,
        'header_urls':
        header_urls,
        'enrollmentStatusHash':
        CourseEnrollment.generate_enrollment_status_hash(user),
        'profile_image_url':
        profile_image_url
    }

    return user_info
示例#6
0
def _get_user_info_cookie_data(request, user):
    """ Returns information that will populate the user info cookie. """

    # Set a cookie with user info.  This can be used by external sites
    # to customize content based on user information.  Currently,
    # we include information that's used to customize the "account"
    # links in the header of subdomain sites (such as the marketing site).
    header_urls = {'logout': reverse('logout')}

    # Unfortunately, this app is currently used by both the LMS and Studio login pages.
    # If we're in Studio, we won't be able to reverse the account/profile URLs.
    # To handle this, we don't add the URLs if we can't reverse them.
    # External sites will need to have fallback mechanisms to handle this case
    # (most likely just hiding the links).
    try:
        header_urls['account_settings'] = reverse('account_settings')
        header_urls['learner_profile'] = reverse(
            'learner_profile', kwargs={'username': user.username})
    except NoReverseMatch:
        pass

    # Add 'resume course' last completed block
    try:
        header_urls['resume_block'] = retrieve_last_sitewide_block_completed(
            user)
    except User.DoesNotExist:
        pass

    header_urls = _convert_to_absolute_uris(request, header_urls)

    image_urls = {}
    try:
        image_urls = get_profile_image_urls_for_user(user)
    except UserProfile.DoesNotExist:
        pass

    image_urls = _convert_to_absolute_uris(request, image_urls)

    user_info = {
        'version': settings.EDXMKTG_USER_INFO_COOKIE_VERSION,
        'username': user.username,
        'email': user.email,
        'header_urls': header_urls,
        'user_image_urls': image_urls,
    }

    return user_info
示例#7
0
    def _get_expected_header_urls(self):
        expected_header_urls = {
            'logout':
            reverse('logout'),
            'resume_block':
            retrieve_last_sitewide_block_completed(self.user),
            'account_settings':
            reverse('account_settings'),
            'learner_profile':
            reverse('learner_profile', kwargs={'username':
                                               self.user.username}),
        }

        expected_header_urls = self._convert_to_absolute_uris(
            self.request, expected_header_urls)

        return expected_header_urls
示例#8
0
    def _get_expected_header_urls(self):
        expected_header_urls = {
            'logout': reverse('logout'),
            'resume_block': retrieve_last_sitewide_block_completed(self.user)
        }

        # Studio (CMS) does not have the URLs below
        if settings.ROOT_URLCONF == 'lms.urls':
            expected_header_urls.update({
                'account_settings': reverse('account_settings'),
                'learner_profile': reverse('learner_profile', kwargs={'username': self.user.username}),
            })

        # Convert relative URL paths to absolute URIs
        for url_name, url_path in six.iteritems(expected_header_urls):
            expected_header_urls[url_name] = self.request.build_absolute_uri(url_path)

        return expected_header_urls
示例#9
0
    def _get_expected_header_urls(self, request):
        expected_header_urls = {
            'logout': reverse('logout'),
            'resume_block': retrieve_last_sitewide_block_completed(self.user)
        }

        # Studio (CMS) does not have the URLs below
        if settings.ROOT_URLCONF == 'lms.urls':
            expected_header_urls.update({
                'account_settings': reverse('account_settings'),
                'learner_profile': reverse('learner_profile', kwargs={'username': self.user.username}),
            })

        # Convert relative URL paths to absolute URIs
        for url_name, url_path in six.iteritems(expected_header_urls):
            expected_header_urls[url_name] = request.build_absolute_uri(url_path)

        return expected_header_urls
示例#10
0
def get_user_info_cookie_data(request):
    """ Returns information that wil populate the user info cookie. """
    user = request.user

    # Set a cookie with user info.  This can be used by external sites
    # to customize content based on user information.  Currently,
    # we include information that's used to customize the "account"
    # links in the header of subdomain sites (such as the marketing site).
    header_urls = {'logout': reverse('logout')}

    # Unfortunately, this app is currently used by both the LMS and Studio login pages.
    # If we're in Studio, we won't be able to reverse the account/profile URLs.
    # To handle this, we don't add the URLs if we can't reverse them.
    # External sites will need to have fallback mechanisms to handle this case
    # (most likely just hiding the links).
    try:
        header_urls['account_settings'] = reverse('account_settings')
        header_urls['learner_profile'] = reverse('learner_profile', kwargs={'username': user.username})
    except NoReverseMatch:
        pass

    # Add 'resume course' last completed block
    try:
        header_urls['resume_block'] = retrieve_last_sitewide_block_completed(user)
    except User.DoesNotExist:
        pass

    # Convert relative URL paths to absolute URIs
    for url_name, url_path in six.iteritems(header_urls):
        header_urls[url_name] = request.build_absolute_uri(url_path)

    user_info = {
        'version': settings.EDXMKTG_USER_INFO_COOKIE_VERSION,
        'username': user.username,
        'header_urls': header_urls,
        'enrollmentStatusHash': CourseEnrollment.generate_enrollment_status_hash(user)
    }

    return user_info
示例#11
0
def render_body(context,**pageargs):
    __M_caller = context.caller_stack._push_frame()
    try:
        __M_locals = __M_dict_builtin(pageargs=pageargs)
        getattr = context.get('getattr', UNDEFINED)
        request = context.get('request', UNDEFINED)
        user = context.get('user', UNDEFINED)
        self = context.get('self', UNDEFINED)
        __M_writer = context.writer()
        __M_writer(u'\n')
        __M_writer(u'\n\n')
        __M_writer(u'\n\n')

## This template should not use the target student's details when masquerading, see TNL-4895
        self.real_user = getattr(user, 'real_user', user)
        profile_image_url = get_profile_image_urls_for_user(self.real_user)['medium']
        username = self.real_user.username
        resume_block = retrieve_last_sitewide_block_completed(username)
        displayname = get_enterprise_learner_generic_name(request) or username
        
        
        __M_locals_builtin_stored = __M_locals_builtin()
        __M_locals.update(__M_dict_builtin([(__M_key, __M_locals_builtin_stored[__M_key]) for __M_key in ['username','resume_block','displayname','profile_image_url'] if __M_key in __M_locals_builtin_stored]))
        __M_writer(u'\n\n<div class="nav-item hidden-mobile nav-item-dashboard">\n    <a href="')
        __M_writer(filters.html_escape(filters.decode.utf8(reverse('dashboard'))))
        __M_writer(u'" class="menu-title">\n        <img class="user-image-frame" src="')
        __M_writer(filters.html_escape(filters.decode.utf8(profile_image_url)))
        __M_writer(u'" alt="">\n        <span class="sr-only">')
        __M_writer(filters.html_escape(filters.decode.utf8(_("Dashboard for:"))))
        __M_writer(u'</span>\n        <span class="username">')
        __M_writer(filters.html_escape(filters.decode.utf8(displayname)))
        __M_writer(u'</span>\n    </a>\n</div>\n<div class="nav-item hidden-mobile nav-item-dropdown" tabindex="-1">\n    <div class="toggle-user-dropdown" role="button" aria-label=')
        __M_writer(filters.html_escape(filters.decode.utf8(_("Options Menu"))))
        __M_writer(u' aria-expanded="false" tabindex="0" aria-controls="user-menu">\n        <span class="fa fa-caret-down" aria-hidden="true"></span>\n    </div>\n    <div class="dropdown-user-menu hidden" aria-label=')
        __M_writer(filters.html_escape(filters.decode.utf8(_("More Options"))))
        __M_writer(u' role="menu" id="user-menu" tabindex="-1">\n')
        if resume_block:
            __M_writer(u'            <div class="mobile-nav-item dropdown-item dropdown-nav-item"><a href="')
            __M_writer(filters.html_escape(filters.decode.utf8(resume_block)))
            __M_writer(u'" role="menuitem">')
            __M_writer(filters.html_escape(filters.decode.utf8(_("Resume your last course"))))
            __M_writer(u'</a></div>\n')
        __M_writer(u'        <div class="mobile-nav-item dropdown-item dropdown-nav-item"><a href="')
        __M_writer(filters.html_escape(filters.decode.utf8(reverse('dashboard'))))
        __M_writer(u'" role="menuitem">')
        __M_writer(filters.html_escape(filters.decode.utf8(_("Dashboard"))))
        __M_writer(u'</a></div>\n        <div class="mobile-nav-item dropdown-item dropdown-nav-item"><a href="')
        __M_writer(filters.html_escape(filters.decode.utf8(reverse('learner_profile', kwargs={'username': username}))))
        __M_writer(u'" role="menuitem">')
        __M_writer(filters.html_escape(filters.decode.utf8(_("Profile"))))
        __M_writer(u'</a></div>\n        <div class="mobile-nav-item dropdown-item dropdown-nav-item"><a href="')
        __M_writer(filters.html_escape(filters.decode.utf8(reverse('account_settings'))))
        __M_writer(u'" role="menuitem">')
        __M_writer(filters.html_escape(filters.decode.utf8(_("Account"))))
        __M_writer(u'</a></div>\n        <div class="mobile-nav-item dropdown-item dropdown-nav-item"><a href="')
        __M_writer(filters.html_escape(filters.decode.utf8(reverse('logout'))))
        __M_writer(u'" role="menuitem">')
        __M_writer(filters.html_escape(filters.decode.utf8(_("Sign Out"))))
        __M_writer(u'</a></div>\n    </div>\n</div>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()