Python django.views.generic.FormView() Examples

The following are 3 code examples of django.views.generic.FormView(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.views.generic , or try the search function .
Example #1
Source File: winter_school.py    From mitoc-trips with GNU General Public License v3.0 6 votes vote down vote up
def form_invalid(self, form):
        """ Provide custom behavior on invalidation to compensate for lack of template.

        The default behavior from FormView is to try rendering a template with
        errors for the user. However, since the attended lectures form is
        tremendously simple (a hidden input with participant ID, and a submit
        button), there really isn't any errors we can give to the user.

        We can expect an invalid form submission when:
        1. A participant loads the attendance form (while self-submission is allowed)
        2. The Winter School chairs disable lecture sign-in
        3. The participant then tries to submit the form, but is not allowed
        """
        participant = form.cleaned_data['participant']

        # Notifications aren't shown when viewing other participants
        if participant == self.request.participant:
            messages.error(
                self.request, "Unable to record your attendance at this time."
            )

        # (note that some participants may not have access to this route!)
        return redirect(reverse('view_participant', args=(participant.pk,))) 
Example #2
Source File: views.py    From eoj3 with MIT License 6 votes vote down vote up
def form_valid(self, form):
    codeforces.create_task(form.cleaned_data["answer"], self.request.user)
    return super().form_valid(form)


# class PackageUpload(PolygonBaseMixin, FormView):
#   class UploadForm(forms.Form):
#     file = forms.FileField()
#
#   form_class = UploadForm
#
#   def get_success_url(self):
#     return reverse("polygon:packages")
#
#   def form_valid(self, form):
#     codeforces.create_task(0, self.request.user, init_file=form.cleaned_data["file"])
#     return super().form_valid(form) 
Example #3
Source File: views.py    From django-u2f with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def form_invalid(self, form):
        # Should this go in Django's FormView?!
        # <https://code.djangoproject.com/ticket/25548>
        return self.render_to_response(self.get_context_data(form=form))