'Given a db cursor and a :py:class:`Participant`, return a
:py:class:`~gratipay.models.team.Team`.'

def get_or_create_linked_team(self, cursor, owner):

    team = self.load_team(cursor)
    if team:
        return team
    def slug_options():
        (yield self.name)
        for i in range(1, 10):
            (yield u'{}-{}'.format(self.name, i))
        (yield uuid.uuid4().hex)
    for slug in slug_options():
        if (cursor.one(u'SELECT    count(*)    FROM    teams    WHERE    slug=%s', (slug,)) == 0):
            break
    team = _Team.insert(slug=slug, slug_lower=slug.lower(), name=slug, homepage=(u'https://www.npmjs.com/package/' + self.name), product_or_service=self.description, owner=owner, _cursor=cursor)
    cursor.run(u'INSERT    INTO    teams_to_packages    (team_id,    package_id)    VALUES    (%s,    %s)', (team.id, self.id))
    self.app.add_event(cursor, u'package', dict(id=self.id, action=u'link', values=dict(team_id=team.id)))
    return team
