Browse Source

Elimina ou corrige Prints

pull/159/head
Sesostris Vieira 3 years ago
parent
commit
935b27db95
  1. 1
      sigi/apps/convenios/admin.py
  2. 2
      sigi/apps/servidores/management/commands/migra.py
  3. 29
      sigi/apps/servidores/management/commands/sync_ldap.py

1
sigi/apps/convenios/admin.py

@ -97,7 +97,6 @@ class ConvenioAdmin(CartExportReportMixin, admin.ModelAdmin):
def get_queryset(self, request): def get_queryset(self, request):
queryset = super(ConvenioAdmin, self).get_queryset(request) queryset = super(ConvenioAdmin, self).get_queryset(request)
print (queryset)
return queryset return queryset
def get_uf(self, obj): def get_uf(self, obj):

2
sigi/apps/servidores/management/commands/migra.py

@ -104,7 +104,7 @@ class Command(BaseCommand):
nome_completo="%s %s" % (user.first_name, user.last_name) nome_completo="%s %s" % (user.first_name, user.last_name)
) )
except MigrationError as e: except MigrationError as e:
print ", ".join(row) print (", ".join(row))
continue continue
# mapeando dados simples # mapeando dados simples

29
sigi/apps/servidores/management/commands/sync_ldap.py

@ -104,9 +104,9 @@ class Command(BaseCommand):
return result return result
def sync_groups(self): def sync_groups(self):
print "Syncing groups..." print ("Syncing groups...")
ldap_groups = self.get_ldap_groups() ldap_groups = self.get_ldap_groups()
print "\tFetched groups: %s" % len(ldap_groups) print (f"\tFetched groups: {ldap_groups}")
for ldap_group in ldap_groups: for ldap_group in ldap_groups:
try: try:
group_name = ldap_group[1]['cn'][0] group_name = ldap_group[1]['cn'][0]
@ -118,13 +118,13 @@ class Command(BaseCommand):
except Group.DoesNotExist: except Group.DoesNotExist:
group = Group(name=group_name) group = Group(name=group_name)
group.save() group.save()
print "\tGroup '%s' created." % group_name print (f"\tGroup '{group_name}' created.")
print "Groups are synchronized." print ("Groups are synchronized.")
def sync_users(self): def sync_users(self):
print "Syncing users..." print ("Syncing users...")
ldap_users = self.get_ldap_users() ldap_users = self.get_ldap_users()
print "\tFetched users: %s" % len(ldap_users) print (f"\tFetched users: {ldap_users}")
def get_ldap_property(ldap_user, property_name, default_value=None): def get_ldap_property(ldap_user, property_name, default_value=None):
value = ldap_user[1].get(property_name, None) value = ldap_user[1].get(property_name, None)
return value[0].decode('utf8') if value else default_value return value[0].decode('utf8') if value else default_value
@ -142,8 +142,7 @@ class Command(BaseCommand):
user = User.objects.get(email=email) user = User.objects.get(email=email)
old_username = user.username old_username = user.username
user.username = username user.username = username
print "\tUser with email '%s' had his/her username updated from [%s] to [%s]." % ( print (f"\tUser with email {email} had his/her username updated from [{old_username}] to [{username}].")
email, old_username, username)
except User.DoesNotExist: except User.DoesNotExist:
user = User.objects.create_user( user = User.objects.create_user(
username=username, username=username,
@ -151,17 +150,17 @@ class Command(BaseCommand):
last_name=last_name, last_name=last_name,
email=email, email=email,
) )
print "\tUser '%s' created." % username print (f"\tUser '{username}' created.")
if not user.first_name == first_name: if not user.first_name == first_name:
user.first_name = first_name user.first_name = first_name
print "\tUser '%s' first name updated." % username print (f"\tUser '{username}' first name updated.")
if not user.last_name == last_name: if not user.last_name == last_name:
user.last_name = last_name user.last_name = last_name
print "\tUser '%s' last name updated." % username print (f"\tUser '{username}' last name updated.")
if not user.email == email: if not user.email == email:
user.email = email user.email = email
print "\tUser '%s' email updated." % username print (f"\tUser '{username}' email updated.")
nome_completo = get_ldap_property(ldap_user, 'cn', '') nome_completo = get_ldap_property(ldap_user, 'cn', '')
try: try:
@ -171,13 +170,13 @@ class Command(BaseCommand):
servidor = Servidor.objects.get(nome_completo=nome_completo) servidor = Servidor.objects.get(nome_completo=nome_completo)
except Servidor.DoesNotExist: except Servidor.DoesNotExist:
servidor = user.servidor_set.create(nome_completo=nome_completo) servidor = user.servidor_set.create(nome_completo=nome_completo)
print "\tServidor '%s' created." % nome_completo print (f"\tServidor '{nome_completo}' created.")
else: else:
if not servidor.nome_completo == nome_completo: if not servidor.nome_completo == nome_completo:
servidor.nome_completo = nome_completo servidor.nome_completo = nome_completo
print "\tFull name of Servidor '%s' updated." % nome_completo print (f"\tFull name of Servidor '{nome_completo}' updated.")
servidor.user = user servidor.user = user
servidor.save() servidor.save()
user.save() user.save()
print "Users are synchronized." print ("Users are synchronized.")

Loading…
Cancel
Save