'Factory for :py:class:`~gratipay.models.team.Team`.'

def make_team(self, *a, **kw):

    _kw = defaultdict(str)
    _kw.update(kw)
    if a:
        _kw[u'name'] = a[0]
        try:
            _kw[u'owner'] = a[1]
        except IndexError:
            pass
    if (u'name' not in _kw):
        _kw[u'name'] = u'The    Enterprise'
    if (u'owner' not in _kw):
        _kw[u'owner'] = u'picard'
    elif isinstance(_kw[u'owner'], Participant):
        _kw[u'owner'] = _kw[u'owner'].username
    if (u'slug' not in _kw):
        _kw[u'slug'] = _kw[u'name'].replace(u'.', u'').replace(u'    ', u'').replace(u',', u'')
    if (u'slug_lower' not in _kw):
        _kw[u'slug_lower'] = _kw[u'slug'].lower()
    if (u'is_approved' not in _kw):
        _kw[u'is_approved'] = False
    if (u'is_closed' not in _kw):
        _kw[u'is_closed'] = False
    if (u'available' not in _kw):
        _kw[u'available'] = 0
    if (u'ctime' not in _kw):
        _kw[u'ctime'] = utcnow()
    self.make_owner(_kw[u'owner'])
    team = self.db.one(u'\n                                                INSERT    INTO    teams\n                                                                                                (slug,    ctime,    slug_lower,    name,    homepage,    product_or_service,\n                                                                                                    onboarding_url,    owner,    is_approved,    is_closed,    available)\n                                                                    VALUES    (%(slug)s,    %(ctime)s,    %(slug_lower)s,    %(name)s,    %(homepage)s,    %(product_or_service)s,\n                                                                                                    %(onboarding_url)s,    %(owner)s,    %(is_approved)s,    %(is_closed)s,\n                                                                                                    %(available)s)\n                                                        RETURNING    teams.*::teams\n                                ', _kw)
    return team
