Ejemplo n.º 1
0
    def clean(self):


        if "received_application" in self.cleaned_data \
           and self.cleaned_data["received_application"]:

            # email required if received
            if not "email" in self.cleaned_data \
               or not self.cleaned_data["email"]:
                self.add_error('email',_('required_attribute') )                

            if not "ldap_user_name" in self.cleaned_data \
               or not self.cleaned_data["ldap_user_name"]:
                self.add_error('ldap_user_name',_('required_attribute') )                

            # email should not exist before if received request
            email = ''
            exists = False
            if "email" in self.cleaned_data and self.cleaned_data["email"]:
                email = self.cleaned_data['email']
                exists = Person.ldap_uid_by_email(email)
            if exists:
                logging.warning(_('the_mail_is_required') % {'email':email})
                logging.warning('The email should not exist before if received request.')
                #self.add_error('email', _('the_mail_is_required') % {'email':email}  )
            
        if "ldap_user_name" in self.cleaned_data and self.cleaned_data["ldap_user_name"] \
        and not self.cleaned_data["received_application"]:
            self.add_error('received_application',_('received_application_required') )

        if self.instance.pk and not self.cleaned_data["group_id"]:
            self.add_error('group_id',_('required_attribute_group') )
            raise ValidationError(_('required_attribute_group'))

        if len(self.cleaned_data['ldap_user_password']) < settings.MIN_LENGTH_LDAP_USER_PASSWORD:
            raise ValidationError(_('ldap_user_password_too_short'))

        if "ldap_user_name" in self.cleaned_data \
           and self.cleaned_data["ldap_user_name"]:
            existing_names_in_ldap = Person.ldap_uid_by_id( self.cleaned_data['document_number'],
                                                            self.cleaned_data['document_type'] )
            if existing_names_in_ldap and (self.cleaned_data["ldap_user_name"] not in existing_names_in_ldap):
                logging.info("User has already exists in Ldap with uid '%s'. it was not updated!" \
                             % ','.join(existing_names_in_ldap))
                self.add_error('document_number',
                               _("user_ID_ldap_already_exists") % {'uid':','.join(existing_names_in_ldap)})