prepopule users
[auf_django_saml.git] / auf / django / saml / management / commands / employes.py
1 # -*- coding: utf-8 -*-
2
3 from django.core.management.base import BaseCommand, CommandError
4 from django.contrib.auth.models import User
5 from auf.django.references import models as ref
6
7
8 class Command(BaseCommand):
9 """
10 Outils concernant les comptes relatifs aux employes
11 """
12 def handle(self, *args, **options):
13 if len(args) == 0:
14 self.stdout.write('Commandes:\n')
15 self.stdout.write('* import (ref_employes => django_user)\n')
16 return
17
18 if args[0] == 'import':
19 nb_employes = 0
20 for e in ref.Employe.objects.filter(actif=True):
21 username = e.courriel.replace('@auf.org', '')
22 django_user, created = \
23 User.objects.get_or_create(username=username)
24 django_user.username = username
25 django_user.first_name = e.prenom
26 django_user.last_name = e.nom
27 django_user.email = e.courriel
28 django_user.save()
29 nb_employes += 1
30 self.stdout.write('%s employés ont été importés.\n' % nb_employes)