I have been searching the web, (and StackOverflow), for an answer to what appears to be a REALLY simple problem. I am using django-userena with a custom form.
Inside my form.py is:
class RegistrationForm(SignupFormOnlyEmail):
first_name = forms.CharField(label='First Name', max_length=30, required=True, error_messages={'required':'Please Provide Your First Name'})
last_name = forms.CharField(label='Last Name', max_length=30, required=True)
email2 = forms.EmailField(widget=forms.TextInput(attrs=dict(attrs_dict, maxlength=75)), label=_("Retype Email"), required=True)
parent_type = forms.ChoiceField(label="I am a", choices=ACCOUNT_TYPES, widget=forms.RadioSelect)
child_count = forms.ChoiceField(label="My Kids", choices=KID_CHOICES, widget=forms.Select)
grade = forms.ChoiceField(label="My Classroom", choices=GRADE_CHOICES, widget=forms.Select)
tos = forms.BooleanField(label="I accept the Terms of Use.", required=True)
def __init__(self, *args, **kwargs):
self.initial = kwargs.pop('initial', None)
kidCount = self.initial['child_count']
account_type = self.initial['parent_type']
super(RegistrationForm, self).__init__(*args, **kwargs)
Inside of my urls.py I put:
url(r'^membership/signup/$', signup_view, name='userena_signup'),
My custom view looks like this:
def signup_view(request):
form = RegistrationForm(initial={'parent_type':request.session['parent_type'],'child_count':request.session['child_count']})
response = userena_views.signup(request, signup_form=form, extra_context={'section':'Membership','pagetitle':'Sign Up'})
return response
When I post the form and go to the /membership/signup/, I get a “TypeError” of
‘RegistrationForm’ object is not callable
Here is a dump of the stack trace:
Traceback:
File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/handlers/base.py” in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File “/Users/lawrenceleach/Dropbox/Sites/django/wonderville/membership/views.py” in signup_view
42. response = userena_views.signup(request, signup_form=form, extra_context={‘section’:’Membership’,’pagetitle’:’Sign Up’})
File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/userena/decorators.py” in _wrapped_view
28. return view_func(request, *args, **kwargs)
File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/userena/views.py” in signup
115. form = signup_form()Exception Type: TypeError at /membership/signup/
Exception Value: ‘RegistrationForm’ object is not callable
Like I said, I’m sure the answer is staring me right in the face and I just can’t see it. Any help would be greatly appreciated.
Thank you in advance!
L.
The solution was to pass the initial form values as a dictionary object to the “extra_context” variable of the form call in the view. If had been using Django’s built-in form tool then what I originally had done above would have worked. I posted the issue to the Userena folks. It appears to be a bug within their system.