def create_travels(max_items=None): travels = TKApi.get_items(PersoonReis, max_items=max_items) logger.info('{} travels found.'.format(len(travels))) if len(travels) < 1000: logger.error( 'Only {} travels found. This is unexpected. Skip re-creating travels.' .format(len(travels))) Travel.objects.all().delete() TravelPersonPosition.objects.all().delete() for travel in travels: person = Person.find_surname_initials(travel.persoon.achternaam, travel.persoon.initialen) if person is None: logger.warning('No person found for travel: {}'.format(travel.id)) continue if travel.van is None or travel.tot_en_met is None: logger.warning('No date found for travel: {}'.format(travel.id)) continue Travel.objects.create( person=person, destination=travel.bestemming, purpose=travel.doel, paid_by=travel.betaald_door, date_begin=travel.van, date_end=travel.tot_en_met, )
def create_gifts(max_items=None): gifts = TKApi.get_items(PersoonGeschenk, max_items=max_items) logger.info('{} gifts found.'.format(len(gifts))) if len(gifts) < 1000: logger.error('Only {} gifts found. This is unexpected. Skip re-creating gifts.'.format(len(gifts))) Gift.objects.all().delete() PersonPosition.objects.all().delete() for gift in gifts: value = find_gift_value(gift.omschrijving) gift_type = find_gift_type(gift.omschrijving) person = Person.find_surname_initials(gift.persoon.achternaam, gift.persoon.initialen) if person is None: logger.warning('No person found for gift: {}'.format(gift.id)) continue if gift.datum is None: logger.warning('No date found for gift: {}'.format(gift.id)) continue Gift.objects.create( person=person, value_euro=value, description=gift.omschrijving, date=gift.datum, type=gift_type, )