benschaf / gipfel-tutor

Welcome to our online tutoring platform.
0 stars 1 forks source link

how do I do proper form validation in a func based view? #40

Open benschaf opened 2 months ago

benschaf commented 2 months ago
    if request.method == 'POST':
        review_form = RatingForm(request.POST)

        # how do I do proper form validation in a func based view?
        # If I do it witha CBV the invalid form will reload the page and add
        # a specific error message on the invalid fields.
        if not review_form.is_valid():
            messages.error(request, 'Form was not valid. Please try again.')

        if existing_rating:
            existing_rating.score = review_form.cleaned_data['score']
            existing_rating.comment = review_form.cleaned_data['comment']
            existing_rating.save()
            return redirect('tutor_detail', pk=pk)

        review = review_form.save(commit=False)
        review.tutor = tutor
        review.user = request.user
        review.save()
        messages.success(request, 'Review added successfully.')
        return redirect('tutor_detail', pk=pk)
benschaf commented 1 week ago

out of scope and only a very high level quality of life issue