Beispiel #1
0
    def get_frbr_uri(self, country, row):
        frbr_uri = FrbrUri(country=row['country'],
                           locality=row['locality'],
                           doctype='act',
                           subtype=row['subtype'],
                           date=row['year'],
                           number=row['number'],
                           actor=None)

        # check country matches (and that it's all one country)
        if country.code != row['country'].lower():
            raise ValueError(
                'The country in the spreadsheet (%s) doesn\'t match the country selected previously (%s)'
                % (row['country'], country))

        # check all frbr uri fields have been filled in and that no spaces were accidentally included
        if ' ' in frbr_uri.work_uri():
            raise ValueError(
                'Check for spaces in country, locality, subtype, year, number – none allowed'
            )
        elif not frbr_uri.country:
            raise ValueError('A country must be given')
        elif not frbr_uri.date:
            raise ValueError('A year must be given')
        elif not frbr_uri.number:
            raise ValueError('A number must be given')

        # check that necessary work fields have been filled in
        elif not row['title']:
            raise ValueError('A title must be given')
        elif not row['publication_date']:
            raise ValueError('A publication date must be given')

        return frbr_uri.work_uri().lower()
Beispiel #2
0
    def get_frbr_uri(self, country, locality, row):
        row_country = row.get('country')
        row_locality = row.get('locality')
        row_subtype = row.get('subtype')
        row_year = row.get('year')
        row_number = row.get('number')
        frbr_uri = FrbrUri(country=row_country,
                           locality=row_locality,
                           doctype='act',
                           subtype=row_subtype,
                           date=row_year,
                           number=row_number,
                           actor=None)

        # if the country doesn't match
        # (but ignore if no country given – dealt with separately)
        if row_country and country.code != row_country.lower():
            raise ValueError(
                'The country code given in the spreadsheet ("%s") '
                'doesn\'t match the code for the country you\'re working in ("%s")'
                % (row.get('country'), country.code.upper()))

        # if you're working on the country level but the spreadsheet gives a locality
        if not locality and row_locality:
            raise ValueError(
                'You are working in a country (%s), '
                'but the spreadsheet gives a locality code ("%s")' %
                (country, row_locality))

        # if you're working in a locality but the spreadsheet doesn't give one
        if locality and not row_locality:
            raise ValueError(
                'There\'s no locality code given in the spreadsheet, '
                'but you\'re working in %s ("%s")' %
                (locality, locality.code.upper()))

        # if the locality doesn't match
        # (only if you're in a locality)
        if locality and locality.code != row_locality.lower():
            raise ValueError(
                'The locality code given in the spreadsheet ("%s") '
                'doesn\'t match the code for the locality you\'re working in ("%s")'
                % (row_locality, locality.code.upper()))

        # check all frbr uri fields have been filled in and that no spaces were accidentally included
        if ' ' in frbr_uri.work_uri():
            raise ValueError(
                'Check for spaces in country, locality, subtype, year, number – none allowed'
            )
        elif not frbr_uri.country:
            raise ValueError('A country must be given')
        elif not frbr_uri.date:
            raise ValueError('A year must be given')
        elif not frbr_uri.number:
            raise ValueError('A number must be given')

        # check that necessary work fields have been filled in
        elif not row.get('title'):
            raise ValueError('A title must be given')
        elif not row.get('publication_date'):
            raise ValueError('A publication date must be given')

        return frbr_uri.work_uri().lower()