Revision 5ce3ce4f snf-astakos-app/astakos/im/management/commands/user_invite.py

b/snf-astakos-app/astakos/im/management/commands/user_invite.py
40 40

  
41 41
from ._common import get_user
42 42

  
43

  
43 44
@transaction.commit_manually
44 45
class Command(BaseCommand):
45 46
    args = "<inviter id or email> <email> <real name>"
46 47
    help = "Invite a user"
47
    
48

  
48 49
    def handle(self, *args, **options):
49 50
        if len(args) != 3:
50 51
            raise CommandError("Invalid number of arguments")
51
        
52

  
52 53
        inviter = get_user(args[0], is_active=True)
53 54
        if not inviter:
54 55
            raise CommandError("Unknown inviter")
55
        if  not inviter.is_active:
56
        if not inviter.is_active:
56 57
            raise CommandError("Inactive inviter")
57
        
58

  
58 59
        if inviter.invitations > 0:
59 60
            email = args[1]
60 61
            realname = args[2]
61
            
62

  
62 63
            try:
63
                invitation = Invitation(username = email, realname=realname, inviter=inviter)
64
                invitation = Invitation(
65
                    username=email, realname=realname, inviter=inviter)
64 66
                invite(invitation, inviter)
65 67
                self.stdout.write("Invitation sent to '%s'\n" % (email,))
66 68
            except SendMailError, e:
......
68 70
                raise CommandError(e.message)
69 71
            except IntegrityError, e:
70 72
                transaction.rollback()
71
                raise CommandError("There is already an invitation for %s" % (email,))
73
                raise CommandError(
74
                    "There is already an invitation for %s" % (email,))
72 75
            else:
73 76
                transaction.commit()
74 77
        else:

Also available in: Unified diff