Revision 094c0768 snf-astakos-app/astakos/im/management/commands/user-show.py

b/snf-astakos-app/astakos/im/management/commands/user-show.py
38 38

  
39 39
from ._common import format
40 40

  
41
import uuid
41 42

  
42 43
class Command(BaseCommand):
43 44
    args = "<user ID or email>"
......
47 48
        if len(args) != 1:
48 49
            raise CommandError("Please provide a user ID or email")
49 50

  
50
        email_or_id = args[0]
51
        if email_or_id.isdigit():
52
            users = AstakosUser.objects.filter(id=int(email_or_id))
51
        identifier = args[0]
52
        if identifier.isdigit():
53
            users = AstakosUser.objects.filter(id=int(identifier))
53 54
        else:
54
            users = AstakosUser.objects.filter(email__iexact=email_or_id)
55
            try:
56
                uuid.UUID(identifier)
57
            except:
58
                users = AstakosUser.objects.filter(email__iexact=identifier)
59
            else:
60
                users = AstakosUser.objects.filter(uuid=identifier)
55 61
        if users.count() == 0:
56
            field = 'id' if email_or_id.isdigit() else 'email'
57
            msg = "Unknown user with %s '%s'" % (field, email_or_id)
62
            field = 'id' if identifier.isdigit() else 'email'
63
            msg = "Unknown user with %s '%s'" % (field, identifier)
58 64
            raise CommandError(msg)
59 65

  
60 66
        for user in users:

Also available in: Unified diff