Generate new Koha MARC frameworks based on an existing framework. This script allows :
- To keep fields as defined in the existing framework, hide them or collapse them
- To set fields or subfields as mandatory
- To define default values to subfields or indicators
Note : "hide" fields and not "ignore" them, as Koha 22.11 documenation states : "When importing records, subfields that are managed in tab 'ignore' will be deleted. If you still wish to keep the subfields, but hide them, use the 'Visibility' options below."
Developped for Koha 22.11
The python-dotenv library is used in the script (pip install python-dotenv).
The JSON setting file (example) is an object containing objects with 5 arrays.
The keys of the first object are the new framework codes (ex : ART for an article framework, THE for a thesis one, etc.).
Each framework is an object with 5 array elements :
keep_fields: add each field tag as a string, those fields will be kept as they are defined in the original framework (ex :"009", "200")collapsed_fields: add each field tag as a string, those fields will be collapsed by default (ex :"009", "200")mandatory_fields_mapping: fields or subfields can be set as mandatory (not both) :- To set a field as mandatory, write the field tag as a string (
"{field tag}") - To set subfield(s) as mandatory, write the field tag followed by all wanted subfields as a string (
"{field tag}{subfield code 1}{subfield code n}") - For example, setting
["009", "099t", "200af", "700"]will :- Set the whole
009field as mandatory - Set the subfield
tof the099field as mandatory - Set the subfields
aandfof the200field as mandatory - Set the whole
700field as mandatory
- Set the whole
- To set a field as mandatory, write the field tag as a string (
default_values_fields_mapping: add each field tag followed by the subfield followed by the value as a string ("{field tag}{subfield code}{value}") :- For example, setting
"099tART"will set the valueARTto the subfieldtof the099field - Multiple subfields for the same field can be set, just add seperate entries (ex :
"099tART", "099x0") - Controlfields use
@as a subfield
- For example, setting
default_fields_inds_mapping: add each field tag followed by the two indicators values as a string ("{field tag}{indicator 1 value}{indicator 2 value}") :- For example, setting
"71002"will set the first indicator as0and the second as2for the field710 - Use
_to specify an empty indicator (ex :2000_will set the first indicator of the200field as0and will keep the second one empty)
- For example, setting
- Export Koha default framework in a CSV file
- Configure environment variables :
FRAMEWORK_INPUT_FILE: full path to the default framework CSV fileFRAMEWORK_OUTPUT_FOLDER: full path to the folder for the new frameworksFRAMEWORK_MAPPING_FILE: full path to the JSON setting file
- Run the script
- The output folder will contain all new frameworks as
{CODE}_framework.csv
- Hide fields : for each subfield in the field, set the
hiddenvalue to8(= none of the visibility options are checked) - Collapse fields : for each subfield in the field, set the
hiddenvalue to-1(= OPAC, Staff Interface, Editor and Collapsed are checked, Flagged is not) - If a field is neither hidden or collapased, its
hiddenvalue stays the same as in the original framework - Mandatory fields : set the field
mandatoryvalue to1 - Mandatory subfields : set the subfield
mandatoryvalue to1 - Note : as the script create a
dictfor mandatory fields, writing"200", "200a"will not set both the200field and its subfieldaas mandatory. The script sets a field as mandatory if its subfieldlistis empty