#NEWLINE# def update_giving( self , cursor = None ) : #NEWLINE# #INDENT# has_credit_card = ( self . get_credit_card_error ( ) == '' ) #NEWLINE# updated = ( cursor or self . db ) . all ( '\n            UPDATE payment_instructions\n               SET is_funded = %(has_credit_card)s\n             WHERE participant = %(username)s\n               AND is_funded <> %(has_credit_card)s\n         RETURNING *\n        ' , dict ( username = self . username , has_credit_card = has_credit_card ) ) #NEWLINE# r = ( cursor or self . db ) . one ( '\n        WITH pi AS (\n            SELECT amount\n              FROM current_payment_instructions cpi\n              JOIN teams t ON t.slug = cpi.team\n             WHERE participant = %(username)s\n               AND amount > 0\n               AND is_funded\n               AND t.is_approved\n        )\n            UPDATE participants p\n               SET giving = COALESCE((SELECT sum(amount) FROM pi), 0)\n                 , ngiving_to = COALESCE((SELECT count(amount) FROM pi), 0)\n             WHERE p.username=%(username)s\n         RETURNING giving, ngiving_to\n        ' , dict ( username = self . username ) ) #NEWLINE# self . set_attributes ( giving = updated . giving , ngiving_to = r . ngiving_to ) #NEWLINE# return updated