Exemplo n.º 1
0
    def _load_countries(self):
        """
        Create list of unique countries and reference to these objects in the data
        :return: nothing. Data is replaced in place
        """
        self.stdout.write('\nloading countries')
        self.countries['code'].fillna('', inplace=True)
        failed_countries = {}
        countries_table = {}
        for country_data in self.countries.to_dict(orient='records'):
            if not country_data['code']:
                country_data['code'] = None
            self.stdout.write('.', ending="")
            self.stdout.flush()
            country = Country(**country_data)
            try:
                country.full_clean()
                country.save()
                countries_table[country.name] = country
            except ValidationError as e:
                failed_countries[country.name] = e

        if failed_countries:
            raise CommandError('Countries failed validation:\n{0}'.format(pprint.pformat(failed_countries, indent=4)))
        self.contributors_data['country'] = self.contributors_data['country'].apply(
            lambda x: countries_table[x] if x in countries_table.keys() else None
        )
Exemplo n.º 2
0
 def setUp(self):
     """
     This fixture data set includes:
         contributor1: pays every month and therefor, should not be included in reminders report, although his next
          expected payment is in the near future.
         contributor2: pays every 3 months, and hence should show up in the overdue report.
         contributor3: pays every year and hence should show up in the reminders report.
         contributor4: pays sporadic, and hence should not be included in one of the reports
     """
     print 'installing fixture data'
     self.reference_date = date(2015, 11, 7)
     country = Country(name='Belgium', code=150)
     country.save()
     school = School(name='testschool')
     school.save()
     child = Child(first_name='mary', surname='jones', sex='f', school=school)
     child.save()
     self.contributor1 = Contributor(first_name='john', surname='doe', aard_van_de_schenker='np', street='some street',
                                street_number=4, zip_code=2010, city='city', country=country,
                                payment_frequency='every month', language='nl')
     self.contributor1.save()
     self.contributor2 = Contributor(first_name='marie', surname='evers', aard_van_de_schenker='np',
                                     street='some street', street_number=4, zip_code=2010, city='city',
                                     country=country, payment_frequency='every 3 months', language='nl')
     self.contributor2.save()
     self.contributor3 = Contributor(first_name='harvey', surname='jones', aard_van_de_schenker='np',
                                     street='some street', street_number=4, zip_code=2010, city='city',
                                     country=country, payment_frequency='every year', language='nl')
     self.contributor3.save()
     self.contributor4 = Contributor(first_name='jeff', surname='buckley', aard_van_de_schenker='np',
                                     street='some street', street_number=4, zip_code=2010, city='city',
                                     country=country, payment_frequency='sporadic', language='nl')
     self.contributor4.save()
     payments = [
         {'amount': 45, 'contributor': self.contributor1, 'child': child, 'date': date(2015, 10, 1),
          'entitled': 'entitled', 'ptype': 'recurrent'},
         {'amount': 45, 'contributor': self.contributor1, 'child': child, 'date': date(2015, 12, 4),
          'entitled': 'entitled', 'ptype': 'recurrent'},
         {'amount': 45, 'contributor': self.contributor2, 'child': child, 'date': date(2015, 8, 15),
          'expected_date': date(2015, 8, 1), 'entitled': 'entitled', 'ptype': 'recurrent'},
         {'amount': 42.4, 'contributor': self.contributor3, 'child': child,
          'date': date(2014, 12, 10), 'expected_date': date(2014, 11, 21),
         'entitled': 'entitled', 'ptype': 'recurrent'},
         {'amount': 30, 'contributor': self.contributor4, 'child': child,
          'date': date(2014, 12, 1), 'entitled': 'entitled', 'ptype': 'recurrent'},
     ]
     for p in payments:
         payment = Payment(**p)
         payment.save()
Exemplo n.º 3
0
def create_fixture():
    country = Country(name='Belgium', code=150)
    country.save()
    school = School(name='testschool')
    school.save()
    child = Child(first_name='mary', surname='jones', sex='f', school=school)
    child.save()
    contributor = Contributor(first_name='john', surname='doe', aard_van_de_schenker='np', street='some street',
                               street_number=4, zip_code=2010, city='city', country=country,
                               payment_frequency='every month', language='nl')
    contributor.save()

    payments = [
        {'amount': 48, 'contributor': contributor, 'child': child, 'date': date(2015, 10, 1),
         'entitled': 'entitled', 'ptype': 'recurrent'},
        {'amount': 49, 'contributor': contributor, 'child': child, 'date': date(2015, 12, 4),
         'entitled': 'entitled', 'ptype': 'recurrent'},
        {'amount': 49.5, 'contributor': contributor, 'child': child, 'date': date(2015, 12, 16),
         'entitled': 'entitled', 'ptype': 'single'}
    ]
    for p in payments:
        payment = Payment(**p)
        payment.save()