Codelist¶
Create or update an OCDS codelist.
from ocdsextensionregistry import Codelist
Create a new codelist:
codelist = Codelist('+partyRole.csv')
Add codes to the codelist (you can provide any iterable, including a csv.DictReader
):
codelist.extend([
{'Code': 'publicAuthority', 'Title': 'Public authority', 'Description': ''},
{'Code': 'bidder', 'Title': 'Bidder', 'Description': ''}
])
Iterate over the codes in the codelist:
[code['Title'] for code in codelist] # ['Public authority', 'Bidder']
Read the codelists’ codes and fieldnames:
codelist.codes # ['publicAuthority', 'bidder']
codelist.fieldnames # ['Code', 'Title', 'Description']
Determine whether the codelist adds or removes codes from another codelist:
codelist.patch # True
codelist.addend # True
codelist.subtrahend # False
Get the name of the codelist it modifies:
codelist.basename # 'partyRole.csv'
- class ocdsextensionregistry.codelist.Codelist(name)[source]¶
-
- add_extension_column(field_name)[source]¶
Add a column for the name of the extension from which codes originate.
- property codes¶
Returns the codes in the codelist.
- property fieldnames¶
Returns all fieldnames used in any rows.
- property basename¶
If the codelist modifies another codelist, returns the latter’s name. Otherwise, returns its own name.
- property patch¶
Returns whether the codelist modifies another codelist.
- property addend¶
Returns whether the codelist adds codes to another codelist.
- property subtrahend¶
Returns whether the codelist removes codes from another codelist.