'Fetch or create a braintree account for this participant.'

def get_braintree_account(self):

    if (not self.braintree_customer_id):
        customer = braintree.Customer.create({u'custom_fields': {u'participant_id': self.id}}).customer
        r = self.db.one(u'\n                                                                UPDATE    participants\n                                                                            SET    braintree_customer_id=%s\n                                                                    WHERE    id=%s\n                                                                            AND    braintree_customer_id    IS    NULL\n                                                    RETURNING    id\n                                                ', (customer.id, self.id))
        if (not r):
            return self.get_braintree_account()
    else:
        customer = braintree.Customer.find(self.braintree_customer_id)
    return customer
