else:
new_record.add_field(field)
- # Add the publisher, with relator code
- seven_ten = pymarc.Field(tag = '710',
- indicators = ['2', ' '],
- subfields = [
- 'a', options['publisher'],
- '4', 'pbl'
- ]
- )
- new_record.add_field(seven_ten)
+ add_publisher(record, new_record, options)
if 'note' in options:
note = pymarc.Field(tag = '590',
return new_record
+def add_publisher(record, new_record, options):
+ """
+ This is a convoluted way to avoid creating a new 710 if we already
+ have a matching 710 and just need to add the publisher relator code.
+ """
+
+ munge_publisher = False
+ need_publisher = True
+ need_relator = True
+
+ # Iterate through all of the existing 710 fields
+ for sten in record.get_fields('710'):
+ for pub in sten.get_subfields('a'):
+ if pub == options['publisher']:
+ munge_publisher = True
+ for rel in sten.get_subfields('4'):
+ if rel == 'pbl':
+ need_publisher = False
+ need_relator = False
+
+ if munge_publisher and need_relator:
+ sten.add_subfield('4', 'pbl')
+ need_publisher = False
+
+ if need_publisher:
+ # Add the publisher, with relator code
+ seven_ten = pymarc.Field(tag = '710',
+ indicators = ['2', ' '],
+ subfields = [
+ 'a', options['publisher'],
+ '4', 'pbl'
+ ]
+ )
+ new_record.add_field(seven_ten)
+
+
def add_cat_source(record, options):
"""Add or extend the 040 field to identify the cataloguing source"""