def users(self): """ Importação Arquivo.csv ==> User """ last_nam = '' user = User.objects.all() for i in self.list: if len(i[0].split()) > 1: last_nam = i[0].split()[1].upper() if user.filter(username__iexact=i[1].strip()).exists(): print 'Já casdastrado' else: print 'Será cadastrado' print i[1].strip(), i[5].strip().upper() users = User(username=i[1].strip(), first_name=i[0].split()[0].strip().upper(), last_name=last_nam.strip(), email=i[1].strip(),) users.set_password(123465) users.save() print i[5].strip().upper() setor = Setor.objects.get(nome__icontains=i[5].strip().upper()) print setor usuario = Usuario(setor=setor, user=users) usuario.save()
class UsuarioTest(TestCase): def setUp(self): self.obj = Usuario( nome='Welington Carlos', setor='T.I', ) def test_create(self): 'Usuario deve ter nome, setor' self.obj.save() self.assertEqual(1, self.obj.id)
def save(self): newUser = User( username=self.cleaned_data["username"], first_name=self.cleaned_data["first_name"], last_name=self.cleaned_data["last_name"], email=self.cleaned_data["email"], ) newUser.save() newUsuario = Usuario(user=newUser, setor=self.cleaned_data["setor"], cargo=self.cleaned_data["cargo"]) newUsuario.save() newUsuario.colaboradores = self.cleaned_data["colaboradores"] return newUser