From 1700c393b1de3c32b3b572efd0cf935255813e2b Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Mon, 7 Dec 2020 17:03:40 +0100 Subject: [PATCH] Bug 27164: Fix item search CSV export In item search CSV export, data cells are exported with double quotes. There should also be double quotes in header cells. Also some spaces can be removed. Delimiter must be from system preference 'delimiter'. TT filter must be $raw not html, only double quotes must be espaped by duplication of it. This may help to open the CSV with any table/calc software. Test plan : 1.0) Create a record with title : Laurel & "Hardy" 1.2) Create an item on this record 2.0) Without patch 2.1) Perform an item search on title 'Laurel' 2.2) Export as a CSV file and save the file locally 2.3) Open the file with a table/calc software 3.0) Apply patch 3.1) Perform same item search 3.2) Export as a CSV file and save the file locally 3.3) Open the file with a table/calc software 4.0) Compare files with diff/meld => you see double quotes arround header cells and removal of space after coma 4.1) Check that delimiter is from system preference 'delimiter' 4.2) In table/calc software they should look the same Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Victor Grousset/tuxayo Signed-off-by: Jonathan Druart --- .../catalogue/itemsearch_item.csv.inc | 32 ++++++++++++++++- .../csv_headers/catalogue/itemsearch.tt | 35 ++++++++++++++++++- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.csv.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.csv.inc index bb625bae23..57602e0ac2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.csv.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.csv.inc @@ -1,7 +1,37 @@ +[%- USE raw -%] [%- USE Branches -%] [%- USE Koha -%] [%- USE ItemTypes -%] [%- USE AuthorisedValues -%] [%- SET biblio = item.biblio -%] [%- SET biblioitem = item.biblioitem -%] -"[% biblio.title | html %] [% IF ( Koha.Preference( 'marcflavour' ) == 'UNIMARC' && biblio.author ) %]by [% END %][% biblio.author | html %]", "[% (biblioitem.publicationyear || biblio.copyrightdate) | html %]", "[% biblioitem.publishercode | html %]", "[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.ccode', authorised_value => item.ccode ) | html %]", "[% item.barcode | html %]", "[% item.itemcallnumber | html %]", "[% Branches.GetName(item.homebranch) | html %]", "[% Branches.GetName(item.holdingbranch) | html %]", "[% AuthorisedValues.GetDescriptionByKohaField(frameworkcode => biblio.frameworkcode, kohafield => 'items.location', authorised_value => item.location) | html %]", "[% ItemTypes.GetDescription(item.itype) | html %]", "[% item.stocknumber | html %]", "[% AuthorisedValues.GetDescriptionByKohaField(frameworkcode => biblio.frameworkcode, kohafield => 'items.notforloan', authorised_value => item.notforloan) | html %]","[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.itemlost', authorised_value => item.itemlost ) || "" | html %]","[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.withdrawn', authorised_value => item.withdrawn ) || "" | html %]", "[% (item.issues || 0) | html %]" +[%- SET delimiter = Koha.Preference( 'delimiter' ) || ',' -%] +"[% biblio.title | replace('"', '""') | $raw %] [% IF ( Koha.Preference( 'marcflavour' ) == 'UNIMARC' && biblio.author ) %]by [% END %][% biblio.author | replace('"', '""') | $raw %]" +[%- delimiter | $raw -%] +"[% (biblioitem.publicationyear || biblio.copyrightdate) | replace('"', '""') | $raw %]" +[%- delimiter | $raw -%] +"[% biblioitem.publishercode | replace('"', '""') | $raw %]" +[%- delimiter | $raw -%] +"[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.ccode', authorised_value => item.ccode ) | replace('"', '""') | $raw %]" +[%- delimiter | $raw -%] +"[% item.barcode | replace('"', '""') | $raw %]" +[%- delimiter | $raw -%] +"[% item.itemcallnumber | replace('"', '""') | $raw %]" +[%- delimiter | $raw -%] +"[% Branches.GetName(item.homebranch) | replace('"', '""') | $raw %]" +[%- delimiter | $raw -%] +"[% Branches.GetName(item.holdingbranch) | replace('"', '""') | $raw %]" +[%- delimiter | $raw -%] +"[% AuthorisedValues.GetDescriptionByKohaField(frameworkcode => biblio.frameworkcode, kohafield => 'items.location', authorised_value => item.location) | replace('"', '""') | $raw %]" +[%- delimiter | $raw -%] +"[% ItemTypes.GetDescription(item.itype) | replace('"', '""') | $raw %]" +[%- delimiter | $raw -%] +"[% item.stocknumber | replace('"', '""') | $raw %]" +[%- delimiter | $raw -%] +"[% AuthorisedValues.GetDescriptionByKohaField(frameworkcode => biblio.frameworkcode, kohafield => 'items.notforloan', authorised_value => item.notforloan) | replace('"', '""') | $raw %]" +[%- delimiter | $raw -%] +"[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.itemlost', authorised_value => item.itemlost ) || "" | replace('"', '""') | $raw %]" +[%- delimiter | $raw -%] +"[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.withdrawn', authorised_value => item.withdrawn ) || "" | replace('"', '""') | $raw %]" +[%- delimiter | $raw -%] +"[% (item.issues || 0) | $raw %]" diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/csv_headers/catalogue/itemsearch.tt b/koha-tmpl/intranet-tmpl/prog/en/includes/csv_headers/catalogue/itemsearch.tt index aa1ce57f5f..c36cfa6005 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/csv_headers/catalogue/itemsearch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/csv_headers/catalogue/itemsearch.tt @@ -1 +1,34 @@ -[%- BLOCK -%]Title, Publication date, Publisher, Collection, Barcode, Call number, Home library, Current library, Shelving location, Item type, Inventory number, Not for loan status, Lost status, Withdrawn status, Checkouts[%- END -%] +[%- USE raw -%] +[%- USE Koha -%] +[%- SET delimiter = Koha.Preference( 'delimiter' ) || ',' -%] +[%- BLOCK -%] +"Title" +[%- delimiter | $raw -%] +"Publication date" +[%- delimiter | $raw -%] +"Publisher" +[%- delimiter | $raw -%] +"Collection" +[%- delimiter | $raw -%] +"Barcode" +[%- delimiter | $raw -%] +"Call number" +[%- delimiter | $raw -%] +"Home library" +[%- delimiter | $raw -%] +"Current library" +[%- delimiter | $raw -%] +"Shelving location" +[%- delimiter | $raw -%] +"Item type" +[%- delimiter | $raw -%] +"Inventory number" +[%- delimiter | $raw -%] +"Not for loan status" +[%- delimiter | $raw -%] +"Lost status" +[%- delimiter | $raw -%] +"Withdrawn status" +[%- delimiter | $raw -%] +"Checkouts" +[%- END -%] -- 2.39.5