django-inspectional-registration icon indicating copy to clipboard operation
django-inspectional-registration copied to clipboard

Form validation

Open danmir opened this issue 9 years ago • 4 comments

Hello. Could you help me with the form validation and Supplement form validation. How could I do that ? My full question on stackoverflow. Thank you.

danmir avatar Aug 31 '15 14:08 danmir

RegistrationView use get_form_class() method to get the registration form class, not form_class attribute. That's why overriding form_class didn't work.

In the method, self.backend.get_registraion_form_class() is called and the method in a default backend returns RegistrationForm.

So what you need to do is

  1. Inherit registration.backends.DefaultRegistrationBackend to create your backend class (say your_registration.backends.MyRegistrationBackend)
  2. In your backend class, override get_registration_form_class() method to return your form class (say your_registration.forms.MyRegistrationForm).
  3. Set your backend class to REGISTRATION_BACKEND_CLASS in settings.py (See registration.backends to figure out how django-inspectional-registration find backend class)
# your_registration/backends.py
from registration.backends.default import DefaultRegistrationBackend
from your_registration.forms import MyRegistrationForm
class MyRegistrationBackend(DefaultRegistrationBackend):
    def get_registration_form_class(self):
        # do not return an instance, return class
        return MyRegistrationForm

# settings.py
REGISTRATION_BACKEND_CLASS = 'your_registration.backends.MyRegistrationBackend'

lambdalisue avatar Aug 31 '15 15:08 lambdalisue

Thank you so much for your answer. And is it possible to validate supplement class form ?

danmir avatar Aug 31 '15 15:08 danmir

registration.supplements.base.RegistrationSupplementBase, which must be inherited to use supplement feature, have get_form_class class method which return form_class attribute of the class. So

class MyRegistrationSupplement(RegistrationSupplementBase):
    form_class = MyRegistrationSupplementForm

should work.

Hum... RegistrationSupplementBase support attribute assignment but RegistrationView. Basically RegistrationView came from django-registration a long time ago thus some legacy codes are remained. I may allow users to do attribute assignments even in RegistrationView which is possible in django-registration can now days.

lambdalisue avatar Aug 31 '15 15:08 lambdalisue

ping @danmir

lambdalisue avatar Dec 22 '15 11:12 lambdalisue