Commits

Andriy Kornatskyy  committed e9fa0c2

Refactored code to use nested validators

  • Participants
  • Parent commits f55da10

Comments (0)

Files changed (3)

File demos/public/src/membership/service/bridge.py

 
 from membership.models import Credential
 from membership.models import Registration
-from membership.validation import account_validator
 from membership.validation import credential_validator
 from membership.validation import registration_validator
 from membership.service.contract import IMembershipService
 
     def create_account(self, registration):
         assert isinstance(registration, Registration)
-        if (not self.validate(registration, registration_validator)
-                & self.validate(registration.credential, credential_validator)
-                & self.validate(registration.account, account_validator)):
+        if not self.validate(registration, registration_validator):
             return False
         membership = self.repository.membership
         if membership.has_account(registration.credential.username):

File demos/public/src/membership/validation.py

 })
 
 registration_validator = Validator({
+    'credential': credential_validator,
+    'account': account_validator,
     'answer': [required, length(min=1, max=20)],
     'date_of_birth': [required]
 })

File demos/public/src/membership/web/views.py

 from membership.models import Credential
 from membership.models import Registration
 from membership.service.factory import Factory
-from membership.validation import account_validator
 from membership.validation import credential_validator
 from membership.validation import password_match_validator
 from membership.validation import registration_validator
                 & self.try_update_model(registration.credential)
                 or not self.validate(self.model, password_match_validator)
                 & self.validate(registration, registration_validator)
-                & self.validate(registration.account, account_validator)
-                & self.validate(registration.credential, credential_validator)
                 or not self.factory.membership.create_account(registration)):
             registration.credential.password = u('')
             self.model.confirm_password = u('')