'Factory for :py:class:`~gratipay.models.participant.Participant`.'

def make_participant(self, username, **kw):

    participant = self.db.one(u'\n                                                INSERT    INTO    participants\n                                                                                                (username,    username_lower)\n                                                                    VALUES    (%s,    %s)\n                                                        RETURNING    participants.*::participants\n                                ', (username, username.lower()))
    if (u'id' in kw):
        new_id = kw.pop(u'id')
        self.db.run(u'UPDATE    participants    SET    id=%s    WHERE    id=%s', (new_id, participant.id))
        participant.set_attributes(id=new_id)
    if ((u'elsewhere' in kw) or (u'claimed_time' in kw)):
        platform = kw.pop(u'elsewhere', u'github')
        self.db.run(u'\n                                                                INSERT    INTO    elsewhere\n                                                                                                                (platform,    user_id,    user_name,    participant)\n                                                                                    VALUES    (%s,%s,%s,%s)\n                                                ', (platform, participant.id, username, username))
    if (u'last_bill_result' in kw):
        route = ExchangeRoute.insert(participant, u'braintree-cc', u'/cards/foo')
        route.update_error(kw.pop(u'last_bill_result'))
    if (u'last_paypal_result' in kw):
        route = ExchangeRoute.insert(participant, u'paypal', u'abcd@gmail.com')
        route.update_error(kw.pop(u'last_paypal_result'))
    if (u'email_address' in kw):
        address = kw.pop(u'email_address')
        if address:
            self.add_and_verify_email(participant, address)
            self.app.email_queue.purge()
    verified_in = kw.pop(u'verified_in', [])
    if kw:
        if (kw.get(u'claimed_time') == u'now'):
            kw[u'claimed_time'] = utcnow()
        (cols, vals) = zip(*kw.items())
        cols = u',    '.join(cols)
        placeholders = u',    '.join(([u'%s'] * len(vals)))
        participant = self.db.one(u'\n                                                                UPDATE    participants\n                                                                            SET    ({0})    =    ({1})\n                                                                    WHERE    username=%s\n                                                    RETURNING    participants.*::participants\n                                                '.format(cols, placeholders), (vals + (username,)))
    countries = ([verified_in] if (type(verified_in) in (str, unicode)) else verified_in)
    for code in countries:
        country = self.db.one(u'SELECT    id    FROM    countries    WHERE    code=%s', (code,))
        participant.store_identity_info(country, u'nothing-enforced', {u'name': username})
        participant.set_identity_verification(country, True)
    return participant
