Export template not working as shown in preview

Bug #2096841 reported by Jörg Nissen
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
calibre
Fix Released
Undecided
Unassigned

Bug Description

I'm using calibre 7.24 on Windows 10 and created this export template: "{author_sort}/{series:||/{series_index:0>4s} - }{title}"

The book "The Tower" by "Stephen King" from the series "The Dark Tower" is shown in the template preview as
"King, Stephen/The Dark Tower/0007 - The Tower" which is exactly what I expect from the export template.

When exporting the book to a folder on my hard disk the path is "King, Stephen/Dark Tower, The/0007 - Tower, The".

Looks like the title is exported as "{title_sort}" and there is an internal conversion to something like "{series_sort}". This happens to all books whose titles and series names fullfil the rules of automatic sort name conversion.

Revision history for this message
Kovid Goyal (kovid) wrote :

Preferences->Tweaks->Control formatting of title and series when used in templates

Changed in calibre:
status: New → Invalid
Revision history for this message
Jörg Nissen (jogobo) wrote :

Should the template editor consider the setting in "Preferences->Tweaks->Control" when displaying the template value?
It's a little bit confusing when the result of saving books is different from the preview in the editor.

Revision history for this message
Kovid Goyal (kovid) wrote :

Changing the component for this bug.

 assignee
 status

Changed in calibre:
assignee: nobody → Charles Haley (cbhaley)
status: Invalid → Triaged
Revision history for this message
Kovid Goyal (kovid) wrote :

@charles: Maybe specialize the template editor when launched from the
save to disk/send to device panels?

Revision history for this message
Charles Haley (cbhaley-deactivatedaccount) wrote (last edit ):

@kovid: Save/Send set up a specialized Metadata object with title and series values that follow the tweak, modifying the return of db.get_metadata(). The preference dialog uses get_metadata() directly, which has no visability to the tweaks in the long call chain (proxy_metadata and ebooks.metadata.book.formatter).

A fix could be to separate out the construction of the metadata object done in save/send so they could be constructed by the preference. This would require creating a separate method from save_to_disk.py, which isn't hard. The problem: it is very hard to test for all the possible fallout from such a change. If there is any fallout it will be in obscure cases.

I'll do the change if you are willing to take the risk.

Revision history for this message
Kovid Goyal (kovid) wrote :

@charles: Not sure I follow. Looking at the code, the Metadata object
isnt modified, instead, the get_components() function modifies the
format_args dict with the appropriate values based on the tweak.

Presumably the template editor would need to get a flag in its __init__
method to tell it to use save_to_disk/send_to_device
get_path_components() when evaluating the template for display to the
user. This would even allow it to reflect the result of platform path
length limitations.

Revision history for this message
Charles Haley (cbhaley-deactivatedaccount) wrote :

@Kovid: I explained very badly. Sorry. Save/Send use a customized formatter (save_to_disk.py line 142) that uses a "metadata" dict created from a metadata object (format_args). That formatter is effectively an EvalFormatter. The changes I made last week to support icon rules in the content server permit passing customized formatters to TemplateDialog. The proposed change would use that new facility, which could expose problems in it. Probably obscure ones.

Rather than discuss this further I will do a PR with the changes. You can decide then based on real code.

Changed in calibre:
status: Triaged → Fix Committed
Revision history for this message
Kovid Goyal (kovid) wrote :

Fixed in branch master. The fix will be in the next release. calibre is usually released every alternate Friday.

Changed in calibre:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.