Opened 13 years ago

Closed 11 years ago

#16977 closed Bug (wontfix)

CommentForm Issue

Reported by: philippe@… Owned by: nobody
Component: contrib.comments Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I'm having some troubles getting a commentform view working on django 1.3. It could be a bug

Here's the deal:

I want to create a class based View that displays a page with a comment form.

So I started to create a view like this

from django.views.generic import FormView
from django.contrib.comments.forms import CommentForm

class MyView(FormView):
    template_name="my_template.html"
    form_class=CommentForm

The problem is I'm getting a 500 Error when the view treats the post data. The error tells me that Commentform takes no 'FILES' as parameter. I didn't understand so I started digging in django code and found this :

 class FormMixin(object):

    ...

    def get_form_kwargs(self):
        """
        Returns the keyword arguments for instanciating the form.
        """
        kwargs = {'initial': self.get_initial()}
        if self.request.method in ('POST', 'PUT'):
            kwargs.update({
                'data': self.request.POST,
                'files': self.request.FILES,
            })
        return kwargs

Then I also found this:

class CommentSecurityForm(forms.Form):
    def __init__(self, target_object, data=None, initial=None):
        self.target_object = target_object
        if initial is None:
            initial = {}
        initial.update(self.generate_security_data())
        super(CommentSecurityForm, self).__init__(data=data, initial=initial)

As you can see, The Formview transmits 'files' to the form but Commentform has no 'files' in the init method...

Is this a bug in the django code or am I using Formview and Commentform in a total wrong way?

Thanks a lot in advance.

Change History (5)

comment:1 by anonymous, 13 years ago

Component: UncategorizedForms

comment:2 by Julien Phalip, 13 years ago

Component: Formscontrib.comments
Triage Stage: UnreviewedAccepted

To me this looks like a bug in CommentSecurityForm, which should accept a files parameter and pass it on to super.

in reply to:  2 comment:3 by anonymous, 13 years ago

Replying to julien:

To me this looks like a bug in CommentSecurityForm, which should accept a files parameter and pass it on to super.

Isn't it a bug is the Formixin?

Because that implies that you should always have a files parameter in every form you want to use...

comment:4 by Julien Phalip, 13 years ago

Well, the base class for forms does have a files attribute, so it would make sense for child classes to have it too, even if they prefer to ignore it by passing None to the super class.

Regardless, I don't see any reason why the comment form should not accept files.

comment:5 by Jacob, 11 years ago

Resolution: wontfix
Status: newclosed

django.contrib.comments has been deprecated and is no longer supported, so I'm closing this ticket. We're encouraging users to transition to a custom solution, or to a hosted solution like Disqus.

The code itself has moved to https://github.com/django/django-contrib-comments; if you want to keep using it, you could move this bug over there.

Note: See TracTickets for help on using tickets.
Back to Top