Re: RegistrationForm subclass not showing up
> > Thank you for your help Andre You're welcome! > I've now worked out what the problem > was. I was editing the wrong copy of the source code (it happens to > everyone at some point!) so no wonder the changes were not > happening... Happens to me more often than I'd like to admit... > In the end I just created a completely new url path (i.e. > not 'accounts/register') and called registration.views with a > completely new form class in the dictionary parameter. > This is precisely how you're supposed to use it. > > Here's my final code with the RegistrationForm for reference. In my > project's urls.py I added the following lines: > > import registration.backends.default.urls# > django-registration urls > from registration.views import register# > django-registration view > from myapp.newform import MyNewRegistrationForm # my own > customised form > > urlpatterns = patterns('', >url(r'^accounts/', include(registration.backends.default.urls)), >url(r'^accounts/registration/$', register, {'backend': > 'registration.backends.default.DefaultBackend', 'form_class': > MyNewRegistrationForm }, >name='registration_register'), > > I just copied the code from the original RegistrationForm class to > myapp.newform and added my customised fields, including the > TermsOfService field I originally wanted... > While this approach works, it is harder to maintain because any updates (ie. fixes, new features, etc) that are added to the original RegistrationForm will never make it to MyNewRegistrationForm. So subclassing and adding just the TOS logic would be the best approach. It also improves readability for you, since you'll just have to look to a couple of lines in your MyNewRegistrationForm as opposed to the whole logic. Considering someone else maintains django-registration, you can leave that part of the code for them to worry and just work on your project-specific stuff. (I'm not sure how clear that paragraph is, so feel free to ask questions!) Cheers, André Terra > > On Jul 11, 2:13 pm, Andre Terrawrote: > > My guess is that there's another module somewhere in your PYTHONPATH from > > which django is importing these forms. > > > > Also, don't edit registration.forms, subclass the form instead. > > > > You can also try {{ form.as_p }} to make sure the problem isn't in the > > template. > > > > You can raise an exception somewhere in your code to try to find where in > > the python path the module lives. Try something like > > > > def your_view(request): > > # ... > > # your current code > > # ... > > from registration import forms > > assert False, forms.__file__ > > > > Good luck! > > > > Cheers, > > André > > > > > > > > > > > > > > > > On Mon, Jul 11, 2011 at 8:45 AM, katstevens > wrote: > > > OK I must have missed something fundamental. I installed v0.8 and > > > having started all over again, I only made one change - adding an > > > extra field to the basic RegistrationForm class in registration.forms > > > - this isn't showing up on my template either! > > > > > Looking over my code, I've found it's not just the Registration form > > > class - when I try altering the default label in e.g. > > > PasswordResetForm (from django.contrib.auth.forms) the change doesn't > > > show up in my template either ( {{ form.email.label_tag }} ), it still > > > displays the default. Is there another mysterious source that django > > > is getting the form class declaration from instead, or is it just > > > ignoring my changes for some reason? I'm not getting any errors and > > > the form itself still works correctly. I haven't changed any of the > > > default code for PasswordResetForm (urls, views, forms) except that > > > one label. I can't understand this behaviour at all. > > > > > On Jul 11, 10:46 am, katstevens wrote: > > > > I think that's it! I'm using v0.7 and will upgrade now - thanks for > > > > the heads up. > > > > > > On Jul 8, 6:52 pm, CareerDhaba tech wrote: > > > > > > > I believe you are using an older version of django_registration, > since > > > there > > > > > is no reference to the backend in your code. The backend is an > addition > > > in > > > > > the latest (0.8) version of django_registration. > > > > > > > Did you download the code from here? > > >http://readthedocs.org/docs/django-registration/en/latest/index.html > > > > > -- > > > You received this message because you are subscribed to the Google > Groups > > > "Django users" group. > > > To post to this group, send email to django-users@googlegroups.com. > > > To unsubscribe from this group, send email to > > > django-users+unsubscr...@googlegroups.com. > > > For more options, visit this group at > > >http://groups.google.com/group/django-users?hl=en. > > -- > You received this message because you are subscribed to the Google Groups >
Re: RegistrationForm subclass not showing up
Thank you for your help Andre - I've now worked out what the problem was. I was editing the wrong copy of the source code (it happens to everyone at some point!) so no wonder the changes were not happening... In the end I just created a completely new url path (i.e. not 'accounts/register') and called registration.views with a completely new form class in the dictionary parameter. Here's my final code with the RegistrationForm for reference. In my project's urls.py I added the following lines: import registration.backends.default.urls# django-registration urls from registration.views import register# django-registration view from myapp.newform import MyNewRegistrationForm # my own customised form urlpatterns = patterns('', url(r'^accounts/', include(registration.backends.default.urls)), url(r'^accounts/registration/$', register, {'backend': 'registration.backends.default.DefaultBackend', 'form_class': MyNewRegistrationForm }, name='registration_register'), I just copied the code from the original RegistrationForm class to myapp.newform and added my customised fields, including the TermsOfService field I originally wanted... On Jul 11, 2:13 pm, Andre Terrawrote: > My guess is that there's another module somewhere in your PYTHONPATH from > which django is importing these forms. > > Also, don't edit registration.forms, subclass the form instead. > > You can also try {{ form.as_p }} to make sure the problem isn't in the > template. > > You can raise an exception somewhere in your code to try to find where in > the python path the module lives. Try something like > > def your_view(request): > # ... > # your current code > # ... > from registration import forms > assert False, forms.__file__ > > Good luck! > > Cheers, > André > > > > > > > > On Mon, Jul 11, 2011 at 8:45 AM, katstevens wrote: > > OK I must have missed something fundamental. I installed v0.8 and > > having started all over again, I only made one change - adding an > > extra field to the basic RegistrationForm class in registration.forms > > - this isn't showing up on my template either! > > > Looking over my code, I've found it's not just the Registration form > > class - when I try altering the default label in e.g. > > PasswordResetForm (from django.contrib.auth.forms) the change doesn't > > show up in my template either ( {{ form.email.label_tag }} ), it still > > displays the default. Is there another mysterious source that django > > is getting the form class declaration from instead, or is it just > > ignoring my changes for some reason? I'm not getting any errors and > > the form itself still works correctly. I haven't changed any of the > > default code for PasswordResetForm (urls, views, forms) except that > > one label. I can't understand this behaviour at all. > > > On Jul 11, 10:46 am, katstevens wrote: > > > I think that's it! I'm using v0.7 and will upgrade now - thanks for > > > the heads up. > > > > On Jul 8, 6:52 pm, CareerDhaba tech wrote: > > > > > I believe you are using an older version of django_registration, since > > there > > > > is no reference to the backend in your code. The backend is an addition > > in > > > > the latest (0.8) version of django_registration. > > > > > Did you download the code from here? > >http://readthedocs.org/docs/django-registration/en/latest/index.html > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-users@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group at > >http://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: RegistrationForm subclass not showing up
My guess is that there's another module somewhere in your PYTHONPATH from which django is importing these forms. Also, don't edit registration.forms, subclass the form instead. You can also try {{ form.as_p }} to make sure the problem isn't in the template. You can raise an exception somewhere in your code to try to find where in the python path the module lives. Try something like def your_view(request): # ... # your current code # ... from registration import forms assert False, forms.__file__ Good luck! Cheers, André On Mon, Jul 11, 2011 at 8:45 AM, katstevenswrote: > OK I must have missed something fundamental. I installed v0.8 and > having started all over again, I only made one change - adding an > extra field to the basic RegistrationForm class in registration.forms > - this isn't showing up on my template either! > > Looking over my code, I've found it's not just the Registration form > class - when I try altering the default label in e.g. > PasswordResetForm (from django.contrib.auth.forms) the change doesn't > show up in my template either ( {{ form.email.label_tag }} ), it still > displays the default. Is there another mysterious source that django > is getting the form class declaration from instead, or is it just > ignoring my changes for some reason? I'm not getting any errors and > the form itself still works correctly. I haven't changed any of the > default code for PasswordResetForm (urls, views, forms) except that > one label. I can't understand this behaviour at all. > > On Jul 11, 10:46 am, katstevens wrote: > > I think that's it! I'm using v0.7 and will upgrade now - thanks for > > the heads up. > > > > On Jul 8, 6:52 pm, CareerDhaba tech wrote: > > > > > > > > > > > > > > > > > I believe you are using an older version of django_registration, since > there > > > is no reference to the backend in your code. The backend is an addition > in > > > the latest (0.8) version of django_registration. > > > > > Did you download the code from here? > http://readthedocs.org/docs/django-registration/en/latest/index.html > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: RegistrationForm subclass not showing up
OK I must have missed something fundamental. I installed v0.8 and having started all over again, I only made one change - adding an extra field to the basic RegistrationForm class in registration.forms - this isn't showing up on my template either! Looking over my code, I've found it's not just the Registration form class - when I try altering the default label in e.g. PasswordResetForm (from django.contrib.auth.forms) the change doesn't show up in my template either ( {{ form.email.label_tag }} ), it still displays the default. Is there another mysterious source that django is getting the form class declaration from instead, or is it just ignoring my changes for some reason? I'm not getting any errors and the form itself still works correctly. I haven't changed any of the default code for PasswordResetForm (urls, views, forms) except that one label. I can't understand this behaviour at all. On Jul 11, 10:46 am, katstevenswrote: > I think that's it! I'm using v0.7 and will upgrade now - thanks for > the heads up. > > On Jul 8, 6:52 pm, CareerDhaba tech wrote: > > > > > > > > > I believe you are using an older version of django_registration, since there > > is no reference to the backend in your code. The backend is an addition in > > the latest (0.8) version of django_registration. > > > Did you download the code from > > here?http://readthedocs.org/docs/django-registration/en/latest/index.html -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: RegistrationForm subclass not showing up
I think that's it! I'm using v0.7 and will upgrade now - thanks for the heads up. On Jul 8, 6:52 pm, CareerDhaba techwrote: > I believe you are using an older version of django_registration, since there > is no reference to the backend in your code. The backend is an addition in > the latest (0.8) version of django_registration. > > Did you download the code from > here?http://readthedocs.org/docs/django-registration/en/latest/index.html > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: RegistrationForm subclass not showing up
I believe you are using an older version of django_registration, since there is no reference to the backend in your code. The backend is an addition in the latest (0.8) version of django_registration. Did you download the code from here? http://readthedocs.org/docs/django-registration/en/latest/index.html On Fri, Jul 8, 2011 at 3:39 PM, katstevenswrote: > Thanks for your answer, but unfortunately that hasn't helped - on > further investigation I think the problem is somewhere else, as the > original RegistrationForm class instance (in registration.forms) > doesn't seem to be being called correctly by registration.views (so no > wonder RegistrationFormTermsOfService isn't working!). I tried making > some small changes to the labels in the RegistrationForm class and it > is still displaying the default label values in my template. For > example, the class declaration now looks like: > > class RegistrationForm(forms.Form): > # all the other fields > # ... > password1 = > forms.CharField(widget=forms.PasswordInput(attrs=attrs_dict, > render_value=False), >label=_(u'different password label')) > > In registration.views I've imported the form as follows > > from registration.forms import RegistrationForm > > And used the default view declaration: > > def register(request, success_url=None, > form_class=RegistrationForm, profile_callback=None, > template_name='registration/registration_form.html', > extra_context=None): >if request.method == 'POST': > # do post stuff >else: > # instantiate blank form >form = form_class() > > Finally, on the registration_form.html template I've tried calling the > fields explicitly rather than using the form.as_table tag: > > {{ form.password1.label_tag }} > {{ form.password1 }} > > The page displays these fields fine, yet the label still gives the > default label value of 'password' instead of 'different password > label'. I'm not getting any syntax errors, and I've rebooted my server > for good measure with the same results. Therefore I assume that either > form = form_class() isn't actually instantiating RegistrationForm > properly in the view, or there is some sort of overriding default > being called from a different location (maybe django.contrib.auth?). > > Also - I can't see the form_call field that you mention - does this > refer to the parameter 'form_class=RegistrationForm' I've used above > in my registration view? > > Thanks again! > > On Jul 8, 7:08 am, CareerDhaba tech wrote: > > Hi Kat, > > > > You have to tell the your registration view to use the > > RegistrationFormTermsofService. First, import that class from forms and > > change your form_call from None to to RegistrationFormTermsofService. > > > > Hope this helps. > > > > > > > > > > > > > > > > On Thu, Jul 7, 2011 at 5:34 PM, katstevens > wrote: > > > Hi - I'm new to Django and am using django-registration to set up new > > > users. > > > > > The basic RegistrationForm shows up fine in my template (which just > > > uses {{ form.as_table }} to generate fields inside the form HTML), but > > > I now want to use the RegistrationFormTermsOfService subclass instead. > > > > > I set it as a parameter in urls.py as follows: > > > url(r'^register/$', > > > register, > > > {'form_class': > > > RegistrationFormTermsOfService}, > > > name='registration_register'), > > > > > ... but the original RegistrationForm is still showing instead. Any > > > ideas why this would be? Do I have to remove the default 'form_class' > > > value in the register declaration in views.py (as that still gives > > > RegistrationForm as the default)? Or do I need to alter my template? > > > > > I'm sure I'm missing something really obvious - any help gratefully > > > received. > > > > > Kat > > > > > -- > > > You received this message because you are subscribed to the Google > Groups > > > "Django users" group. > > > To post to this group, send email to django-users@googlegroups.com. > > > To unsubscribe from this group, send email to > > > django-users+unsubscr...@googlegroups.com. > > > For more options, visit this group at > > >http://groups.google.com/group/django-users?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from
Re: RegistrationForm subclass not showing up
If I remember this correctly, there's a variable somewhere in django-registration that defines the form to be used. grep (or ack!) the source for RegistrationForm and see if you can find it Cheers, Andre On 7/8/11, katstevenswrote: > Thanks for your answer, but unfortunately that hasn't helped - on > further investigation I think the problem is somewhere else, as the > original RegistrationForm class instance (in registration.forms) > doesn't seem to be being called correctly by registration.views (so no > wonder RegistrationFormTermsOfService isn't working!). I tried making > some small changes to the labels in the RegistrationForm class and it > is still displaying the default label values in my template. For > example, the class declaration now looks like: > > class RegistrationForm(forms.Form): > # all the other fields > # ... > password1 = > forms.CharField(widget=forms.PasswordInput(attrs=attrs_dict, > render_value=False), > label=_(u'different password label')) > > In registration.views I've imported the form as follows > > from registration.forms import RegistrationForm > > And used the default view declaration: > > def register(request, success_url=None, > form_class=RegistrationForm, profile_callback=None, > template_name='registration/registration_form.html', > extra_context=None): > if request.method == 'POST': ># do post stuff > else: ># instantiate blank form > form = form_class() > > Finally, on the registration_form.html template I've tried calling the > fields explicitly rather than using the form.as_table tag: > > {{ form.password1.label_tag }} > {{ form.password1 }} > > The page displays these fields fine, yet the label still gives the > default label value of 'password' instead of 'different password > label'. I'm not getting any syntax errors, and I've rebooted my server > for good measure with the same results. Therefore I assume that either > form = form_class() isn't actually instantiating RegistrationForm > properly in the view, or there is some sort of overriding default > being called from a different location (maybe django.contrib.auth?). > > Also - I can't see the form_call field that you mention - does this > refer to the parameter 'form_class=RegistrationForm' I've used above > in my registration view? > > Thanks again! > > On Jul 8, 7:08 am, CareerDhaba tech wrote: >> Hi Kat, >> >> You have to tell the your registration view to use the >> RegistrationFormTermsofService. First, import that class from forms and >> change your form_call from None to to RegistrationFormTermsofService. >> >> Hope this helps. >> >> >> >> >> >> >> >> On Thu, Jul 7, 2011 at 5:34 PM, katstevens wrote: >> > Hi - I'm new to Django and am using django-registration to set up new >> > users. >> >> > The basic RegistrationForm shows up fine in my template (which just >> > uses {{ form.as_table }} to generate fields inside the form HTML), but >> > I now want to use the RegistrationFormTermsOfService subclass instead. >> >> > I set it as a parameter in urls.py as follows: >> > url(r'^register/$', >> > register, >> > {'form_class': >> > RegistrationFormTermsOfService}, >> > name='registration_register'), >> >> > ... but the original RegistrationForm is still showing instead. Any >> > ideas why this would be? Do I have to remove the default 'form_class' >> > value in the register declaration in views.py (as that still gives >> > RegistrationForm as the default)? Or do I need to alter my template? >> >> > I'm sure I'm missing something really obvious - any help gratefully >> > received. >> >> > Kat >> >> > -- >> > You received this message because you are subscribed to the Google >> > Groups >> > "Django users" group. >> > To post to this group, send email to django-users@googlegroups.com. >> > To unsubscribe from this group, send email to >> > django-users+unsubscr...@googlegroups.com. >> > For more options, visit this group at >> >http://groups.google.com/group/django-users?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- Sent from my mobile device -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at
Re: RegistrationForm subclass not showing up
Thanks for your answer, but unfortunately that hasn't helped - on further investigation I think the problem is somewhere else, as the original RegistrationForm class instance (in registration.forms) doesn't seem to be being called correctly by registration.views (so no wonder RegistrationFormTermsOfService isn't working!). I tried making some small changes to the labels in the RegistrationForm class and it is still displaying the default label values in my template. For example, the class declaration now looks like: class RegistrationForm(forms.Form): # all the other fields # ... password1 = forms.CharField(widget=forms.PasswordInput(attrs=attrs_dict, render_value=False), label=_(u'different password label')) In registration.views I've imported the form as follows from registration.forms import RegistrationForm And used the default view declaration: def register(request, success_url=None, form_class=RegistrationForm, profile_callback=None, template_name='registration/registration_form.html', extra_context=None): if request.method == 'POST': # do post stuff else: # instantiate blank form form = form_class() Finally, on the registration_form.html template I've tried calling the fields explicitly rather than using the form.as_table tag: {{ form.password1.label_tag }} {{ form.password1 }} The page displays these fields fine, yet the label still gives the default label value of 'password' instead of 'different password label'. I'm not getting any syntax errors, and I've rebooted my server for good measure with the same results. Therefore I assume that either form = form_class() isn't actually instantiating RegistrationForm properly in the view, or there is some sort of overriding default being called from a different location (maybe django.contrib.auth?). Also - I can't see the form_call field that you mention - does this refer to the parameter 'form_class=RegistrationForm' I've used above in my registration view? Thanks again! On Jul 8, 7:08 am, CareerDhaba techwrote: > Hi Kat, > > You have to tell the your registration view to use the > RegistrationFormTermsofService. First, import that class from forms and > change your form_call from None to to RegistrationFormTermsofService. > > Hope this helps. > > > > > > > > On Thu, Jul 7, 2011 at 5:34 PM, katstevens wrote: > > Hi - I'm new to Django and am using django-registration to set up new > > users. > > > The basic RegistrationForm shows up fine in my template (which just > > uses {{ form.as_table }} to generate fields inside the form HTML), but > > I now want to use the RegistrationFormTermsOfService subclass instead. > > > I set it as a parameter in urls.py as follows: > > url(r'^register/$', > > register, > > {'form_class': > > RegistrationFormTermsOfService}, > > name='registration_register'), > > > ... but the original RegistrationForm is still showing instead. Any > > ideas why this would be? Do I have to remove the default 'form_class' > > value in the register declaration in views.py (as that still gives > > RegistrationForm as the default)? Or do I need to alter my template? > > > I'm sure I'm missing something really obvious - any help gratefully > > received. > > > Kat > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-users@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group at > >http://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: RegistrationForm subclass not showing up
Hi Kat, You have to tell the your registration view to use the RegistrationFormTermsofService. First, import that class from forms and change your form_call from None to to RegistrationFormTermsofService. Hope this helps. On Thu, Jul 7, 2011 at 5:34 PM, katstevenswrote: > Hi - I'm new to Django and am using django-registration to set up new > users. > > The basic RegistrationForm shows up fine in my template (which just > uses {{ form.as_table }} to generate fields inside the form HTML), but > I now want to use the RegistrationFormTermsOfService subclass instead. > > I set it as a parameter in urls.py as follows: > url(r'^register/$', > register, > {'form_class': > RegistrationFormTermsOfService}, > name='registration_register'), > > ... but the original RegistrationForm is still showing instead. Any > ideas why this would be? Do I have to remove the default 'form_class' > value in the register declaration in views.py (as that still gives > RegistrationForm as the default)? Or do I need to alter my template? > > I'm sure I'm missing something really obvious - any help gratefully > received. > > Kat > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.