# Path: standup/status/models.py
# class StandupUser(models.Model):
#     """A standup participant--tied to Django's User model."""
#     # Note: User provides "username", "is_superuser", "is_staff" and "email"
#     user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='profile')
#     name = models.CharField(max_length=100, blank=True, null=True)
#     slug = models.SlugField(max_length=100, blank=True, null=True, unique=True)
#     irc_nick = models.CharField(
#         max_length=100, blank=True, null=True, unique=True,
#         help_text='IRC nick for this particular user'
#     )
# 
#     class Meta:
#         # ordering = ('user__username',)
#         db_table = 'user'
# 
#     def __str__(self):
#         akas = [aka for aka in [self.slug, self.irc_nick] if aka]
#         return '%s (%s)' % (
#             self.name,
#             ', '.join([':%s' % aka for aka in akas])
#         )
# 
#     def __repr__(self):
#         return '<StandupUser: [{}]>'.format(self.slug)
# 
#     def get_absolute_url(self):
#         try:
#             return reverse('status.user', kwargs={'slug': self.slug})
#         except NoReverseMatch:
#             return ''
# 
#     @property
#     def email(self):
#         return self.user.email
# 
#     def dictify(self):
#         """Returns an OrderedDict of model attributes"""
#         data = OrderedDict()
#         data['id'] = self.id
#         data['name'] = self.name
#         data['slug'] = self.slug
#         data['irc_nick'] = self.irc_nick
#         # FIXME: Should we be providing email addresses publicly via the api?
#         # data['email'] = self.user.email
#         data['is_staff'] = self.user.is_staff
#         return data


import tabulate
from django.contrib.auth import get_user_model
from django.core.management.base import BaseCommand
from django.db.models import Q
from standup.status.models import StandupUser
        # FIXME(willkg): Redo this so that it's easier to keep the row headers in lockstep with row
        # contents without doing it by hand.
        rows = [
            ['user_id', 'username', 'email', 'name', 'slug', 'irc', '# statuses', 'last login', 'created']
        ]

        id_to_data = {}

        # Search through Users
        users = (
            get_user_model().objects.filter(
                Q(username__icontains=text) |
                Q(email__icontains=text)
            )
            .order_by('id')
        )

        for user in users:
            if hasattr(user, 'profile'):
                id_to_data[user.id] = [
                    user.username,
                    user.email,
                    user.profile.name,
                    user.profile.slug,
                    user.profile.irc_nick,
                    user.profile.statuses.count(),
                    user.last_login,
                    user.date_joined
                ]
            else:

# Path: standup/status/models.py
# class StandupUser(models.Model):
#     """A standup participant--tied to Django's User model."""
#     # Note: User provides "username", "is_superuser", "is_staff" and "email"
#     user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='profile')
#     name = models.CharField(max_length=100, blank=True, null=True)
#     slug = models.SlugField(max_length=100, blank=True, null=True, unique=True)
#     irc_nick = models.CharField(
#         max_length=100, blank=True, null=True, unique=True,
#         help_text='IRC nick for this particular user'
#     )
# 
#     class Meta:
#         # ordering = ('user__username',)
#         db_table = 'user'
# 
#     def __str__(self):
#         akas = [aka for aka in [self.slug, self.irc_nick] if aka]
#         return '%s (%s)' % (
#             self.name,
#             ', '.join([':%s' % aka for aka in akas])
#         )
# 
#     def __repr__(self):
#         return '<StandupUser: [{}]>'.format(self.slug)
# 
#     def get_absolute_url(self):
#         try:
#             return reverse('status.user', kwargs={'slug': self.slug})
#         except NoReverseMatch:
#             return ''
# 
#     @property
#     def email(self):
#         return self.user.email
# 
#     def dictify(self):
#         """Returns an OrderedDict of model attributes"""
#         data = OrderedDict()
#         data['id'] = self.id
#         data['name'] = self.name
#         data['slug'] = self.slug
#         data['irc_nick'] = self.irc_nick
#         # FIXME: Should we be providing email addresses publicly via the api?
#         # data['email'] = self.user.email
#         data['is_staff'] = self.user.is_staff
#         return data


# Path: standup/status/management/commands/finduser.py
import tabulate
from django.contrib.auth import get_user_model
from django.core.management.base import BaseCommand
from django.db.models import Q
from standup.status.models import StandupUser

        # FIXME(willkg): Redo this so that it's easier to keep the row headers in lockstep with row
        # contents without doing it by hand.
        rows = [
            ['user_id', 'username', 'email', 'name', 'slug', 'irc', '# statuses', 'last login', 'created']
        ]

        id_to_data = {}

        # Search through Users
        users = (
            get_user_model().objects.filter(
                Q(username__icontains=text) |
                Q(email__icontains=text)
            )
            .order_by('id')
        )

        for user in users:
            if hasattr(user, 'profile'):
                id_to_data[user.id] = [
                    user.username,
                    user.email,
                    user.profile.name,
                    user.profile.slug,
                    user.profile.irc_nick,
                    user.profile.statuses.count(),
                    user.last_login,
                    user.date_joined
                ]
            else:

                id_to_data[user.id] = [