def pg_update_or_create(self, context, values): pg_ref = db.pg_get_by_pgid(context, values['pgid']) if pg_ref: pg = db.pg_update(context, pg_ref['id'], values) else: pg = db.pg_create(context, values) return pg