def edit_participants(request, course_id): course = Course.objects.get(id=course_id) if request.user == course.owner: participants = Participation.objects.filter(course=course_id) form = ParticipantsForm(instance=course) if request.method == 'POST': form = ParticipantsForm(instance=course, data=request.POST) if form.is_valid(): Participation.objects.filter(course=course).delete() for participant in form.cleaned_data['participants']: part = Participation(user=participant, course=course) part.save() messages.success(request, 'Participants updated successfully!') return redirect('/courses/' + course_id) return render(request, 'edit_participants.html', {'form': form, 'course': course, 'participants': participants}) return redirect('/courses/')
def edit_participants(request, course_id): course = Course.objects.get(id=course_id) if request.user == course.owner: participants = Participation.objects.filter(course=course_id) form = ParticipantsForm(instance=course) if request.method == 'POST': form = ParticipantsForm(instance=course, data=request.POST) if form.is_valid(): Participation.objects.filter(course=course).delete() for participant in form.cleaned_data['participants']: part = Participation(user=participant, course=course) part.save() messages.success(request, 'Participants updated successfully!') return redirect('/courses/' + course_id) return render(request, 'edit_participants.html', { 'form': form, 'course': course, 'participants': participants }) return redirect('/courses/')
def test_if_not_valid_on_only_participants(self): form_data = {'participants': '1'} form = ParticipantsForm(data=form_data) self.assertFalse(form.is_valid())