Example #1
0
def settings_handler(request, tag=None, course_id=None, branch=None, version_guid=None, block=None):
    """
    Course settings for dates and about pages
    GET
        html: get the page
        json: get the CourseDetails model
    PUT
        json: update the Course and About xblocks through the CourseDetails model
    """
    locator, course_module = _get_locator_and_course(course_id, branch, version_guid, block, request.user)
    if "text/html" in request.META.get("HTTP_ACCEPT", "") and request.method == "GET":
        upload_asset_url = locator.url_reverse("assets/")

        return render_to_response(
            "settings.html",
            {
                "context_course": course_module,
                "course_locator": locator,
                "lms_link_for_about_page": utils.get_lms_link_for_about_page(course_module.location),
                "course_image_url": utils.course_image_url(course_module),
                "details_url": locator.url_reverse("/settings/details/"),
                "about_page_editable": not settings.FEATURES.get("ENABLE_MKTG_SITE", False),
                "upload_asset_url": upload_asset_url,
            },
        )
    elif "application/json" in request.META.get("HTTP_ACCEPT", ""):
        if request.method == "GET":
            return JsonResponse(
                CourseDetails.fetch(locator),
                # encoder serializes dates, old locations, and instances
                encoder=CourseSettingsEncoder,
            )
        else:  # post or put, doesn't matter.
            return JsonResponse(CourseDetails.update_from_json(locator, request.json), encoder=CourseSettingsEncoder)
Example #2
0
def settings_handler(request,
                     tag=None,
                     package_id=None,
                     branch=None,
                     version_guid=None,
                     block=None):
    """
    Course settings for dates and about pages
    GET
        html: get the page
        json: get the CourseDetails model
    PUT
        json: update the Course and About xblocks through the CourseDetails model
    """
    locator, course_module = _get_locator_and_course(package_id, branch,
                                                     version_guid, block,
                                                     request.user)
    if 'text/html' in request.META.get('HTTP_ACCEPT',
                                       '') and request.method == 'GET':
        upload_asset_url = locator.url_reverse('assets/')

        # see if the ORG of this course can be attributed to a 'Microsite'. In that case, the
        # course about page should be editable in Studio
        about_page_editable = not microsite.get_value_for_org(
            course_module.location.org, 'ENABLE_MKTG_SITE',
            settings.FEATURES.get('ENABLE_MKTG_SITE', False))

        short_description_editable = settings.FEATURES.get(
            'EDITABLE_SHORT_DESCRIPTION', True)

        return render_to_response(
            'settings.html', {
                'context_course':
                course_module,
                'course_locator':
                locator,
                'lms_link_for_about_page':
                utils.get_lms_link_for_about_page(course_module.location),
                'course_image_url':
                utils.course_image_url(course_module),
                'details_url':
                locator.url_reverse('/settings/details/'),
                'about_page_editable':
                about_page_editable,
                'short_description_editable':
                short_description_editable,
                'upload_asset_url':
                upload_asset_url
            })
    elif 'application/json' in request.META.get('HTTP_ACCEPT', ''):
        if request.method == 'GET':
            return JsonResponse(
                CourseDetails.fetch(locator),
                # encoder serializes dates, old locations, and instances
                encoder=CourseSettingsEncoder)
        else:  # post or put, doesn't matter.
            return JsonResponse(CourseDetails.update_from_json(
                locator, request.json, request.user),
                                encoder=CourseSettingsEncoder)
Example #3
0
def settings_handler(request,
                     tag=None,
                     course_id=None,
                     branch=None,
                     version_guid=None,
                     block=None):
    """
    Course settings for dates and about pages
    GET
        html: get the page
        json: get the CourseDetails model
    PUT
        json: update the Course and About xblocks through the CourseDetails model
    """
    locator, course_module = _get_locator_and_course(course_id, branch,
                                                     version_guid, block,
                                                     request.user)
    if 'text/html' in request.META.get('HTTP_ACCEPT',
                                       '') and request.method == 'GET':
        upload_asset_url = locator.url_reverse('assets/')

        return render_to_response(
            'settings.html', {
                'context_course':
                course_module,
                'course_locator':
                locator,
                'lms_link_for_about_page':
                utils.get_lms_link_for_about_page(course_module.location),
                'course_image_url':
                utils.course_image_url(course_module),
                'details_url':
                locator.url_reverse('/settings/details/'),
                'about_page_editable':
                not settings.FEATURES.get('ENABLE_MKTG_SITE', False),
                'upload_asset_url':
                upload_asset_url
            })
    elif 'application/json' in request.META.get('HTTP_ACCEPT', ''):
        if request.method == 'GET':
            return JsonResponse(
                CourseDetails.fetch(locator),
                # encoder serializes dates, old locations, and instances
                encoder=CourseSettingsEncoder)
        else:  # post or put, doesn't matter.
            return JsonResponse(CourseDetails.update_from_json(
                locator, request.json),
                                encoder=CourseSettingsEncoder)
Example #4
0
def settings_handler(request, tag=None, package_id=None, branch=None, version_guid=None, block=None):
    """
    Course settings for dates and about pages
    GET
        html: get the page
        json: get the CourseDetails model
    PUT
        json: update the Course and About xblocks through the CourseDetails model
    """
    locator, course_module = _get_locator_and_course(
        package_id, branch, version_guid, block, request.user
    )
    if 'text/html' in request.META.get('HTTP_ACCEPT', '') and request.method == 'GET':
        upload_asset_url = locator.url_reverse('assets/')

        # see if the ORG of this course can be attributed to a 'Microsite'. In that case, the
        # course about page should be editable in Studio
        about_page_editable = not MicrositeConfiguration.get_microsite_configuration_value_for_org(
            course_module.location.org,
            'ENABLE_MKTG_SITE',
            settings.FEATURES.get('ENABLE_MKTG_SITE', False)
        )

        short_description_editable = settings.FEATURES.get('EDITABLE_SHORT_DESCRIPTION', True)

        return render_to_response('settings.html', {
            'context_course': course_module,
            'course_locator': locator,
            'lms_link_for_about_page': utils.get_lms_link_for_about_page(course_module.location),
            'course_image_url': utils.course_image_url(course_module),
            'details_url': locator.url_reverse('/settings/details/'),
            'about_page_editable': about_page_editable,
            'short_description_editable': short_description_editable,
            'upload_asset_url': upload_asset_url
        })
    elif 'application/json' in request.META.get('HTTP_ACCEPT', ''):
        if request.method == 'GET':
            return JsonResponse(
                CourseDetails.fetch(locator),
                # encoder serializes dates, old locations, and instances
                encoder=CourseSettingsEncoder
            )
        else:  # post or put, doesn't matter.
            return JsonResponse(
                CourseDetails.update_from_json(locator, request.json, request.user),
                encoder=CourseSettingsEncoder
            )
Example #5
0
def settings_handler(request, course_key_string):
    """
    Course settings for dates and about pages
    GET
        html: get the page
        json: get the CourseDetails model
    PUT
        json: update the Course and About xblocks through the CourseDetails model
    """
    course_key = CourseKey.from_string(course_key_string)
    course_module = _get_course_module(course_key, request.user)
    if "text/html" in request.META.get("HTTP_ACCEPT", "") and request.method == "GET":
        upload_asset_url = reverse_course_url("assets_handler", course_key)

        # see if the ORG of this course can be attributed to a 'Microsite'. In that case, the
        # course about page should be editable in Studio
        about_page_editable = not microsite.get_value_for_org(
            course_module.location.org, "ENABLE_MKTG_SITE", settings.FEATURES.get("ENABLE_MKTG_SITE", False)
        )

        short_description_editable = settings.FEATURES.get("EDITABLE_SHORT_DESCRIPTION", True)

        return render_to_response(
            "settings.html",
            {
                "context_course": course_module,
                "course_locator": course_key,
                "lms_link_for_about_page": utils.get_lms_link_for_about_page(course_key),
                "course_image_url": utils.course_image_url(course_module),
                "details_url": reverse_course_url("settings_handler", course_key),
                "about_page_editable": about_page_editable,
                "short_description_editable": short_description_editable,
                "upload_asset_url": upload_asset_url,
            },
        )
    elif "application/json" in request.META.get("HTTP_ACCEPT", ""):
        if request.method == "GET":
            return JsonResponse(
                CourseDetails.fetch(course_key),
                # encoder serializes dates, old locations, and instances
                encoder=CourseSettingsEncoder,
            )
        else:  # post or put, doesn't matter.
            return JsonResponse(
                CourseDetails.update_from_json(course_key, request.json, request.user), encoder=CourseSettingsEncoder
            )
Example #6
0
def settings_handler(request, tag=None, course_id=None, branch=None, version_guid=None, block=None):
    """
    Course settings for dates and about pages
    GET
        html: get the page
        json: get the CourseDetails model
    PUT
        json: update the Course and About xblocks through the CourseDetails model
    """
    locator = BlockUsageLocator(course_id=course_id, branch=branch, version_guid=version_guid, usage_id=block)
    if not has_access(request.user, locator):
        raise PermissionDenied()

    if 'text/html' in request.META.get('HTTP_ACCEPT', '') and request.method == 'GET':
        course_old_location = loc_mapper().translate_locator_to_location(locator)
        course_module = modulestore().get_item(course_old_location)

        upload_asset_url = locator.url_reverse('assets/')

        return render_to_response('settings.html', {
            'context_course': course_module,
            'course_locator': locator,
            'lms_link_for_about_page': utils.get_lms_link_for_about_page(course_old_location),
            'course_image_url': utils.course_image_url(course_module),
            'details_url': locator.url_reverse('/settings/details/'),
            'about_page_editable': not settings.FEATURES.get(
                'ENABLE_MKTG_SITE', False
            ),
            'upload_asset_url': upload_asset_url
        })
    elif 'application/json' in request.META.get('HTTP_ACCEPT', ''):
        if request.method == 'GET':
            return JsonResponse(
                CourseDetails.fetch(locator),
                # encoder serializes dates, old locations, and instances
                encoder=CourseSettingsEncoder
            )
        else:  # post or put, doesn't matter.
            return JsonResponse(
                CourseDetails.update_from_json(locator, request.json),
                encoder=CourseSettingsEncoder
            )
Example #7
0
 def get_about_page_link(self):
     """ create mock course and return the about page link """
     location = "i4x", "mitX", "101", "course", "test"
     utils.get_course_id = mock.Mock(return_value="mitX/101/test")
     return utils.get_lms_link_for_about_page(location)
Example #8
0
 def get_about_page_link(self):
     """ create mock course and return the about page link """
     course_key = SlashSeparatedCourseKey('mitX', '101', 'test')
     return utils.get_lms_link_for_about_page(course_key)
Example #9
0
 def get_about_page_link(self):
     """ create mock course and return the about page link """
     course_key = SlashSeparatedCourseKey("mitX", "101", "test")
     return utils.get_lms_link_for_about_page(course_key)
Example #10
0
 def get_about_page_link(self):
     """ create mock course and return the about page link """
     location = 'i4x', 'mitX', '101', 'course', 'test'
     return utils.get_lms_link_for_about_page(location)
Example #11
0
 def get_about_page_link(self):
     """ create mock course and return the about page link """
     location = 'i4x', 'mitX', '101', 'course', 'test'
     utils.get_course_id = mock.Mock(return_value="mitX/101/test")
     return utils.get_lms_link_for_about_page(location)
Example #12
0
 def get_about_page_link(self):
     """ create mock course and return the about page link """
     location = "i4x", "mitX", "101", "course", "test"
     return utils.get_lms_link_for_about_page(location)
Example #13
0
 def get_about_page_link(self):
     """ create mock course and return the about page link """
     location = 'i4x', 'mitX', '101', 'course', 'test'
     utils.get_course_id = mock.Mock(return_value="mitX/101/test")
     return utils.get_lms_link_for_about_page(location)
Example #14
0
 def about_page_test(self):
     """ Get URL for about page. """
     location = 'i4x', 'mitX', '101', 'course', 'test'
     utils.get_course_id = mock.Mock(return_value="mitX/101/test")
     link = utils.get_lms_link_for_about_page(location)
     self.assertEquals(link, "//localhost:8000/courses/mitX/101/test/about")
Example #15
0
 def get_about_page_link(self):
     """ create mock course and return the about page link """
     location = 'i4x', 'mitX', '101', 'course', 'test'
     return utils.get_lms_link_for_about_page(location)