Exemple #1
0
    def get_naa_record(self, cleaned_data):
        barcode = cleaned_data['numeric_identifier']
        rs = RSItemClient()
        rsseries = RSSeriesClient()
        item_details = rs.get_summary(barcode)
        dates = item_details['contents_dates']
        citation = '{}, {}'.format(
                                item_details['series'],
                                item_details['control_symbol']
                            )
        series_details = rsseries.get_summary(item_details['series'])
        repository = Repository.objects.get(display_name='National Archives of Australia')

        series_type, created = RecordType.objects.get_or_create(label='series')
        series, created = Record.objects.get_or_create(
                identifier=item_details['series'],
                record_type=series_type,
                repository=repository,
                defaults={
                    'title': series_details['title']
                }

            )
        item_type, created = RecordType.objects.get_or_create(label='item')

        cleaned_data['is_part_of'] = series
        cleaned_data['record_type'] = item_type
        cleaned_data['identifier'] = item_details['control_symbol']
        cleaned_data['title'] = item_details['title']
        cleaned_data['date_string'] = dates['date_str']
        cleaned_data['start_date'] = dates['start_date']['date']
        cleaned_data['start_month_known'] = dates['start_date']['month']
        cleaned_data['start_day_known'] = dates['start_date']['day']
        cleaned_data['end_date'] = dates['end_date']['date']
        cleaned_data['end_month_known'] = dates['end_date']['month']
        cleaned_data['end_day_known'] = dates['end_date']['day']
        cleaned_data['access_status'] = item_details['access_status']
        cleaned_data['short_citation'] = citation
        cleaned_data['repository'] = repository
        cleaned_data['number_of_items'] = int(item_details['digitised_pages'])

        del self._errors['title']
        del self._errors['record_type']
        del self._errors['identifier']
        return cleaned_data
Exemple #2
0
    def save_model(self, request, obj, form, change):
        if not change and obj.numeric_identifier and not obj.title:
            barcode = obj.numeric_identifier
            print barcode
            rs = RSItemClient()
            rsseries = RSSeriesClient()
            item_details = rs.get_summary(barcode)
            dates = item_details['contents_dates']
            citation = '{}, {}'.format(
                item_details['series'],
                item_details['control_symbol']
            )
            series_details = rsseries.get_summary(item_details['series'])
            repository = Repository.objects.get(display_name='National Archives of Australia')
            series_type, created = RecordType.objects.get_or_create(label='series')
            series, created = Record.objects.get_or_create(
                identifier=item_details['series'],
                record_type=series_type,
                repository=repository,
                defaults={
                    'title': series_details['title']
                }

            )
            item_type, created = RecordType.objects.get_or_create(label='item')
            obj.is_part_of = series
            obj.record_type = item_type
            obj.identifier = item_details['control_symbol']
            obj.title = item_details['title']
            obj.date_string = dates['date_str']
            obj.start_date = dates['start_date']['date']
            obj.start_month_known = dates['start_date']['month']
            obj.start_day_known = dates['start_date']['day']
            obj.end_date = dates['end_date']['date']
            obj.end_month_known = dates['end_date']['month']
            obj.end_day_known = dates['end_date']['day']
            obj.access_status = item_details['access_status']
            obj.short_citation = citation
            obj.repository = repository
            obj.number_of_items = int(item_details['digitised_pages'])
            obj.save()