示例#1
0
def customize_settings(request, course_key_string):

    course_key = SlashSeparatedCourseKey.from_deprecated_string(
        course_key_string)
    with modulestore().bulk_operations(course_key):
        course_module = get_course_and_check_access(course_key, request.user)
        additional_info = {
            'is_new': request.POST.get('is_new', False),
            'invitation_only': request.POST.get('invitation_only', False),
            'manager_only': request.POST.get('manager_only', False)
        }
        CourseMetadata.update_from_dict(additional_info, course_module,
                                        request.user)
        return JsonResponse({'data': 'data'})
示例#2
0
    def _get_and_validate_course_access(user, course_id):
        """
        Check if course_id exists and is accessible by the user.

        Returns a course_module object
        """
        course_key = CourseKey.from_string(course_id)
        course_module = get_course_and_check_access(course_key, user)

        if not course_module:
            raise NotFound(
                'Course with course_id {} does not exist.'.format(course_id))

        return course_module
示例#3
0
    def get_object(self):
        lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field

        assert lookup_url_kwarg in self.kwargs, (
            u'Expected view %s to be called with a URL keyword argument '
            u'named "%s". Fix your URL conf, or set the `.lookup_field` '
            'attribute on the view correctly.' %
            (self.__class__.__name__, lookup_url_kwarg)
        )

        course_run_key = CourseKey.from_string(self.kwargs[lookup_url_kwarg])
        course_run = get_course_and_check_access(course_run_key, self.request.user)
        if course_run:
            return course_run

        raise Http404
示例#4
0
    def get_object(self):
        lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field

        assert lookup_url_kwarg in self.kwargs, (
            'Expected view %s to be called with a URL keyword argument '
            'named "%s". Fix your URL conf, or set the `.lookup_field` '
            'attribute on the view correctly.' %
            (self.__class__.__name__, lookup_url_kwarg)
        )

        course_run_key = CourseKey.from_string(self.kwargs[lookup_url_kwarg])
        course_run = get_course_and_check_access(course_run_key, self.request.user)
        if course_run:
            return course_run

        raise Http404
示例#5
0
def captions_index(request, course_key):
    """
    Display a list of course videos as well as their status (up to date, or out of date)

    org, course, name: Attributes of the Location for the item to edit
    """
    course = get_course_and_check_access(
        course_key,
        request.user,
        depth=2,
    )

    return render_to_response(
        'captions.html',
        {
            'videos': get_videos(course),
            'context_course': course,
        }
    )
示例#6
0
def proctored_exam_settings(request, course_id):
    """
    A view for retrieving information about proctored exam settings for a course.

    Path: ``/api/contentstore/v1/proctored_exam_settings/{course_id}``

    Accepts: [GET]

    ------------------------------------------------------------------------------------
    GET
    ------------------------------------------------------------------------------------

    **Returns**

        * 200: OK - Contains a set of course proctored exam settings.
        * 401: The requesting user is not authenticated.
        * 403: The requesting user lacks access to the course.
        * 404: The requested course does not exist.

    **Response**

        In the case of a 200 response code, the response will proctored exam settings data
        as well as other metadata about the course or the requesting user that are necessary
        for rendering the settings page.

    **Example**

        {
            "proctored_exam_settings": {
                "enable_proctored_exams": true,
                "allow_proctoring_opt_out": true,
                "proctoring_provider": "mockprock",
                "proctoring_escalation_email": null,
                "create_zendesk_tickets": true
            },
            "available_proctoring_providers": [
                "mockprock",
                "proctortrack"
            ],
            "course_start_date": "2013-02-05T05:00:00Z",
            "is_staff": true
        }
    """
    course_key = CourseKey.from_string(course_id)
    with modulestore().bulk_operations(course_key):
        if request.method == 'GET':
            course_module = get_course_and_check_access(
                course_key, request.user)

            if not course_module:
                return Response(
                    'Course with course_id {} does not exist.'.format(
                        course_id),
                    status=status.HTTP_404_NOT_FOUND)

            course_metadata = CourseMetadata().fetch_all(course_module)
            data = {}

            # specify only the advanced settings we want to return
            proctored_exam_settings_advanced_settings_keys = [
                'enable_proctored_exams', 'allow_proctoring_opt_out',
                'proctoring_provider', 'proctoring_escalation_email',
                'create_zendesk_tickets', 'start'
            ]
            proctored_exam_settings_data = {
                setting_key: setting_value.get('value')
                for (setting_key, setting_value) in course_metadata.items() if
                setting_key in proctored_exam_settings_advanced_settings_keys
            }

            data['proctored_exam_settings'] = proctored_exam_settings_data
            data['available_proctoring_providers'] = get_available_providers()

            # move start key:value out of proctored_exam_settings dictionary and change key
            data['course_start_date'] = proctored_exam_settings_data['start']
            del data['proctored_exam_settings']['start']

            data['is_staff'] = request.user.is_staff

            serializer = ProctoredExamConfigurationSerializer(data)

            return Response(serializer.data)
示例#7
0
def custom_settings_handler(request, course_key_string):
    """
    Course settings configuration
    GET
        html: get the page
        json: get the model
    PUT, POST
        json: update the Course's settings. The payload is a json rep of the
            metadata dicts.
    """
    course_key = CourseKey.from_string(course_key_string)
    with modulestore().bulk_operations(course_key):
        course_module = get_course_and_check_access(course_key, request.user)
        if 'text/html' in request.META.get('HTTP_ACCEPT',
                                           '') and request.method == 'GET':

            return render_to_response(
                'custom_settings.html', {
                    'context_course':
                    course_module,
                    'is_new':
                    course_module.is_new,
                    'invitation_only':
                    course_module.invitation_only,
                    'visible_to_manager_only':
                    course_module.visible_to_manager_only,
                })
        elif 'application/json' in request.META.get('HTTP_ACCEPT', ''):
            if request.method == 'GET':
                return JsonResponse(CourseMetadata.fetch(course_module))
            else:
                try:
                    # validate data formats and update the course module.
                    # Note: don't update mongo yet, but wait until after any tabs are changed
                    is_valid, errors, updated_data = CourseMetadata.validate_and_update_from_json(
                        course_module,
                        request.json,
                        user=request.user,
                    )

                    if is_valid:
                        try:
                            additional_info = {
                                'is_new':
                                request.POST.get('is_new', False),
                                'invitation_only':
                                request.POST.get('invitation_only', False),
                                'visible_to_manager_only':
                                request.POST.get('visible_to_manager_only',
                                                 False)
                            }
                            CourseMetadata.update_from_dict(
                                additional_info, course_module, request.user)
                            course_search_index_handler(
                                request, course_key_string)
                        except InvalidTabsException as err:
                            log.exception(err.message)
                            response_message = [{
                                'message':
                                _('An error occurred while trying to save your tabs'
                                  ),
                                'model': {
                                    'display_name': _('Tabs Exception')
                                }
                            }]
                            return JsonResponseBadRequest(response_message)

                        return JsonResponse(updated_data)
                    else:
                        return JsonResponseBadRequest(errors)

                # Handle all errors that validation doesn't catch
                except (TypeError, ValueError, InvalidTabsException) as err:
                    return HttpResponseBadRequest(django.utils.html.escape(
                        err.message),
                                                  content_type="text/plain")