From ae759ebd109d1d4040a54ee676bd203070bc8f1f Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Thu, 6 Jan 2011 19:35:04 +0000 Subject: [PATCH] Fix ticket #8214 (Detect 'senseless' user input) --- src/calibre/gui2/preferences/save_template.py | 8 ++++++-- src/calibre/utils/formatter.py | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/preferences/save_template.py b/src/calibre/gui2/preferences/save_template.py index a7f57536d5..4c00a14c0f 100644 --- a/src/calibre/gui2/preferences/save_template.py +++ b/src/calibre/gui2/preferences/save_template.py @@ -8,7 +8,7 @@ __docformat__ = 'restructuredtext en' from PyQt4.Qt import QWidget, pyqtSignal -from calibre.gui2 import error_dialog +from calibre.gui2 import error_dialog, question_dialog from calibre.gui2.preferences.save_template_ui import Ui_Form from calibre.library.save_to_disk import FORMAT_ARG_DESCS, preprocess_template from calibre.utils.formatter import validation_formatter @@ -52,7 +52,11 @@ class SaveTemplate(QWidget, Ui_Form): ''' tmpl = preprocess_template(self.opt_template.text()) try: - validation_formatter.validate(tmpl) + t = validation_formatter.validate(tmpl) + if t.find(validation_formatter._validation_string) < 0: + return question_dialog(self, _('Constant template'), + _('The template contains no {fields}, so all ' + 'books will have the same name. Is this OK?')) except Exception, err: error_dialog(self, _('Invalid template'), '
'+_('The template %s is invalid:')%tmpl + \ diff --git a/src/calibre/utils/formatter.py b/src/calibre/utils/formatter.py index f4e687b419..23763a25bf 100644 --- a/src/calibre/utils/formatter.py +++ b/src/calibre/utils/formatter.py @@ -453,7 +453,7 @@ class TemplateFormatter(string.Formatter): class ValidateFormatter(TemplateFormatter): ''' - Provides a format function that substitutes '' for any missing value + Provides a formatter that substitutes the validation string for every value ''' def get_value(self, key, args, kwargs): return self._validation_string