~doctormo/erato/trunk

« back to all changes in this revision

Viewing changes to art_website/users/management/commands/update-profiles.py

  • Committer: Martin Owens
  • Date: 2010-10-20 15:33:05 UTC
  • Revision ID: doctormo@gmail.com-20101020153305-w5vcu2jclk5a38so
Manual merge in of other inital branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
from django.core.management.base import NoArgsCommand
 
4
 
 
5
from common import launchpad
 
6
from django.contrib.auth.models import User, Group
 
7
from users.models import UserProfile, create_profile
 
8
 
 
9
from datetime import datetime
 
10
import sys
 
11
 
 
12
class Command(NoArgsCommand):
 
13
    help = "Updates user profiles with information from Launchpad."
 
14
 
 
15
    def handle_noargs(self, **options):
 
16
        lp = launchpad.lp_login()
 
17
        if not lp:
 
18
            sys.exit(1)
 
19
        USER_BLACKLIST = (u"root", u"admin")
 
20
        
 
21
        ld_users = User.objects.all()
 
22
 
 
23
        for ld_user in ld_users:
 
24
            if not ld_user.username in USER_BLACKLIST:
 
25
                print "* Updating %s" % ld_user
 
26
                profile, created = UserProfile.objects.get_or_create(user=ld_user)
 
27
                try:
 
28
                    lp_user = lp.people[ld_user.username]
 
29
                    #profile.tz = lp_user.time_zone or "UTC"
 
30
                    profile.realname = lp_user.display_name or user.username
 
31
                    profile.save()
 
32
                except Exception, e:
 
33
                    print "Error updating %s" % ld_user
 
34
                    print e
 
35
                    pass