lambdalisue / django-inspectional-registration

Django registration app with Inspection before activation
http://pypi.python.org/pypi/django-inspectional-registration
42 stars 26 forks source link

Form validation #47

Open danmir opened 9 years ago

danmir commented 9 years ago

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.

lambdalisue commented 9 years ago

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'
danmir commented 9 years ago

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

lambdalisue commented 9 years ago

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 commented 8 years ago

ping @danmir