def validate(self, attrs): """ Validate the fields in combination. """ if not any(field in attrs for field in self.fields): raise ValidationError('Bad request') settings_to_change = {} divided_course_wide_discussions, divided_inline_discussions = get_divided_discussions( self.course, self.discussion_settings ) if any(item in attrs for item in ('divided_course_wide_discussions', 'divided_inline_discussions')): divided_course_wide_discussions = attrs.get( 'divided_course_wide_discussions', divided_course_wide_discussions ) divided_inline_discussions = attrs.get('divided_inline_discussions', divided_inline_discussions) settings_to_change['divided_discussions'] = divided_course_wide_discussions + divided_inline_discussions for item in ('always_divide_inline_discussions', 'division_scheme'): if item in attrs: settings_to_change[item] = attrs[item] attrs['settings_to_change'] = settings_to_change return attrs
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) })