def test_format_date(): """Test date formatting.""" # Just year assert format_date('2020') == '2020' # Complete date assert format_date('2020-01-01') == '01.01.2020' # No processing assert format_date('July 31, 2020') == 'July 31, 2020'
def dissertation(record): """Get dissertation text.""" if not record.get('dissertation'): return None dissertation_text = [record['dissertation']['degree']] # Dissertation has grantingInstitution or date if record['dissertation'].get( 'grantingInstitution') or record['dissertation'].get('date'): dissertation_text.append(': ') # Add grantingInstitution if record['dissertation'].get('grantingInstitution'): dissertation_text.append( record['dissertation']['grantingInstitution']) # Add date if record['dissertation'].get('date'): dissertation_text.append(', {date}'.format( date=format_date(record['dissertation']['date']))) # Add jury note if record['dissertation'].get('jury_note'): dissertation_text.append(' ({label}: {note})'.format( label=_('Jury note').lower(), note=record['dissertation']['jury_note'])) return ''.join(dissertation_text)
def publication_statement_text(provision_activity): """Create publication statement from place, agent and date values.""" # Only if provision activity is imported from field 269 (no statement, # but start date) if 'statement' not in provision_activity: return format_date(provision_activity['startDate']) punctuation = {'bf:Place': ' ; ', 'bf:Agent': ', '} statement_with_language = {'default': ''} statement_type = None for statement in provision_activity['statement']: labels = statement['label'] for label in labels: language = label.get('language', 'default') if not statement_with_language.get(language): statement_with_language[language] = '' if statement_with_language[language]: if statement_type == statement['type']: statement_with_language[language] += punctuation[ statement_type] else: if statement['type'] == 'bf:Place': statement_with_language[language] += ' ; ' elif statement['type'] == 'Date': statement_with_language[language] += ', ' else: statement_with_language[language] += ' : ' statement_with_language[language] += label['value'] statement_type = statement['type'] # date field: remove ';' and append for key, value in statement_with_language.items(): value = remove_trailing_punctuation(value) statement_with_language[key] = value return statement_with_language