Beispiel #1
0
 def _get_representation(self, course, course_key, discussion_settings):
     """
     Return a serialized representation of the course discussion settings.
     """
     divided_course_wide_discussions, divided_inline_discussions = get_divided_discussions(
         course, discussion_settings
     )
     return JsonResponse({
         'id': discussion_settings.id,
         'divided_inline_discussions': divided_inline_discussions,
         'divided_course_wide_discussions': divided_course_wide_discussions,
         'always_divide_inline_discussions': discussion_settings.always_divide_inline_discussions,
         'division_scheme': discussion_settings.division_scheme,
         'available_division_schemes': available_division_schemes(course_key)
     })
Beispiel #2
0
 def _get_representation(self, course, course_key, discussion_settings):
     """
     Return a serialized representation of the course discussion settings.
     """
     divided_course_wide_discussions, divided_inline_discussions = get_divided_discussions(
         course, discussion_settings
     )
     return JsonResponse({
         'id': discussion_settings.id,
         'divided_inline_discussions': divided_inline_discussions,
         'divided_course_wide_discussions': divided_course_wide_discussions,
         'always_divide_inline_discussions': discussion_settings.always_divide_inline_discussions,
         'division_scheme': discussion_settings.division_scheme,
         'available_division_schemes': available_division_schemes(course_key)
     })
def _section_discussions_management(course, access):
    """ Provide data for the corresponding discussion management section """
    course_key = course.id
    enrollment_track_schemes = available_division_schemes(course_key)
    section_data = {
        'section_key': 'discussions_management',
        'section_display_name': _('Discussions'),
        'is_hidden': (not is_course_cohorted(course_key) and
                      CourseDiscussionSettings.ENROLLMENT_TRACK not in enrollment_track_schemes),
        'discussion_topics_url': reverse('discussion_topics', kwargs={'course_key_string': six.text_type(course_key)}),
        'course_discussion_settings': reverse(
            'course_discussions_settings',
            kwargs={'course_key_string': six.text_type(course_key)}
        ),
    }
    return section_data
def _section_discussions_management(course, access):
    """ Provide data for the corresponding discussion management section """
    course_key = course.id
    enrollment_track_schemes = available_division_schemes(course_key)
    section_data = {
        'section_key': 'discussions_management',
        'section_display_name': _('Discussions'),
        'is_hidden': (not is_course_cohorted(course_key) and
                      CourseDiscussionSettings.ENROLLMENT_TRACK not in enrollment_track_schemes),
        'discussion_topics_url': reverse('discussion_topics', kwargs={'course_key_string': unicode(course_key)}),
        'course_discussion_settings': reverse(
            'course_discussions_settings',
            kwargs={'course_key_string': unicode(course_key)}
        ),
    }
    return section_data
Beispiel #5
0
 def to_representation(self, instance: CourseDiscussionSettings) -> dict:
     """
     Return a serialized representation of the course discussion settings.
     """
     payload = super().to_representation(instance)
     course = self.context['course']
     instance = self.context['settings']
     course_key = course.id
     divided_course_wide_discussions, divided_inline_discussions = get_divided_discussions(
         course, instance)
     payload = {
         'id': instance.id,
         'divided_inline_discussions': divided_inline_discussions,
         'divided_course_wide_discussions': divided_course_wide_discussions,
         'always_divide_inline_discussions':
         instance.always_divide_inline_discussions,
         'division_scheme': instance.division_scheme,
         'available_division_schemes':
         available_division_schemes(course_key)
     }
     return payload
Beispiel #6
0
def course_discussions_settings_handler(request, course_key_string):
    """
    The restful handler for divided discussion setting requests. Requires JSON.
    This will raise 404 if user is not staff.
    GET
        Returns the JSON representation of divided discussion settings for the course.
    PATCH
        Updates the divided discussion settings for the course. Returns the JSON representation of updated settings.
    """
    course_key = CourseKey.from_string(course_key_string)
    course = get_course_with_access(request.user, 'staff', course_key)
    discussion_settings = get_course_discussion_settings(course_key)

    if request.method == 'PATCH':
        divided_course_wide_discussions, divided_inline_discussions = get_divided_discussions(
            course, discussion_settings)

        settings_to_change = {}

        if 'divided_course_wide_discussions' in request.json or 'divided_inline_discussions' in request.json:
            divided_course_wide_discussions = request.json.get(
                'divided_course_wide_discussions',
                divided_course_wide_discussions)
            divided_inline_discussions = request.json.get(
                'divided_inline_discussions', divided_inline_discussions)
            settings_to_change[
                'divided_discussions'] = divided_course_wide_discussions + divided_inline_discussions

        if 'always_divide_inline_discussions' in request.json:
            settings_to_change[
                'always_divide_inline_discussions'] = request.json.get(
                    'always_divide_inline_discussions')
        if 'division_scheme' in request.json:
            settings_to_change['division_scheme'] = request.json.get(
                'division_scheme')

        if not settings_to_change:
            return JsonResponse({"error": six.text_type("Bad Request")}, 400)

        try:
            if settings_to_change:
                discussion_settings = set_course_discussion_settings(
                    course_key, **settings_to_change)

        except ValueError as err:
            # Note: error message not translated because it is not exposed to the user (UI prevents this state).
            return JsonResponse({"error": six.text_type(err)}, 400)

    divided_course_wide_discussions, divided_inline_discussions = get_divided_discussions(
        course, discussion_settings)

    return JsonResponse({
        'id':
        discussion_settings.id,
        'divided_inline_discussions':
        divided_inline_discussions,
        'divided_course_wide_discussions':
        divided_course_wide_discussions,
        'always_divide_inline_discussions':
        discussion_settings.always_divide_inline_discussions,
        'division_scheme':
        discussion_settings.division_scheme,
        'available_division_schemes':
        available_division_schemes(course_key)
    })
Beispiel #7
0
def course_discussions_settings_handler(request, course_key_string):
    """
    The restful handler for divided discussion setting requests. Requires JSON.
    This will raise 404 if user is not staff.
    GET
        Returns the JSON representation of divided discussion settings for the course.
    PATCH
        Updates the divided discussion settings for the course. Returns the JSON representation of updated settings.
    """
    course_key = CourseKey.from_string(course_key_string)
    course = get_course_with_access(request.user, 'staff', course_key)
    discussion_settings = get_course_discussion_settings(course_key)

    if request.method == 'PATCH':
        divided_course_wide_discussions, divided_inline_discussions = get_divided_discussions(
            course, discussion_settings
        )

        settings_to_change = {}

        if 'divided_course_wide_discussions' in request.json or 'divided_inline_discussions' in request.json:
            divided_course_wide_discussions = request.json.get(
                'divided_course_wide_discussions', divided_course_wide_discussions
            )
            divided_inline_discussions = request.json.get(
                'divided_inline_discussions', divided_inline_discussions
            )
            settings_to_change['divided_discussions'] = divided_course_wide_discussions + divided_inline_discussions

        if 'always_divide_inline_discussions' in request.json:
            settings_to_change['always_divide_inline_discussions'] = request.json.get(
                'always_divide_inline_discussions'
            )
        if 'division_scheme' in request.json:
            settings_to_change['division_scheme'] = request.json.get(
                'division_scheme'
            )

        if not settings_to_change:
            return JsonResponse({"error": unicode("Bad Request")}, 400)

        try:
            if settings_to_change:
                discussion_settings = set_course_discussion_settings(course_key, **settings_to_change)

        except ValueError as err:
            # Note: error message not translated because it is not exposed to the user (UI prevents this state).
            return JsonResponse({"error": unicode(err)}, 400)

    divided_course_wide_discussions, divided_inline_discussions = get_divided_discussions(
        course, discussion_settings
    )

    return JsonResponse({
        'id': discussion_settings.id,
        'divided_inline_discussions': divided_inline_discussions,
        'divided_course_wide_discussions': divided_course_wide_discussions,
        'always_divide_inline_discussions': discussion_settings.always_divide_inline_discussions,
        'division_scheme': discussion_settings.division_scheme,
        'available_division_schemes': available_division_schemes(course_key)
    })