def get_athlete(athlete): """ Get athlete from database or strava. """ try: return Athlete.get(strava_id=athlete) except Athlete.DoesNotExist: return fetch_athlete(athlete)
def handle_member(m): name,athlete_id = (m['name'].encode('utf-8', 'ignore'), m['id']) athlete = Athlete.get_or_create(strava_id=athlete_id) if not athlete.matches_dict({'name': name}): athlete.values_from_dict({'name': name}) athlete.save() club_athlete = ClubAthlete.get_or_create(club=get_club(club), athlete=athlete) club_athlete.save() return athlete