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
009
field as mandatory - Set the subfield
t
of the099
field as mandatory - Set the subfields
a
andf
of the200
field as mandatory - Set the whole
700
field 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 valueART
to the subfieldt
of the099
field - 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 as0
and the second as2
for the field710
- Use
_
to specify an empty indicator (ex :2000_
will set the first indicator of the200
field as0
and 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
hidden
value to8
(= none of the visibility options are checked) - Collapse fields : for each subfield in the field, set the
hidden
value to-1
(= OPAC, Staff Interface, Editor and Collapsed are checked, Flagged is not) - If a field is neither hidden or collapased, its
hidden
value stays the same as in the original framework - Mandatory fields : set the field
mandatory
value to1
- Mandatory subfields : set the subfield
mandatory
value to1
- Note : as the script create a
dict
for mandatory fields, writing"200", "200a"
will not set both the200
field and its subfielda
as mandatory. The script sets a field as mandatory if its subfieldlist
is empty