Fix #8214 (Detect 'senseless' user input)

This commit is contained in:
Kovid Goyal 2011-01-06 12:52:43 -07:00
parent 9cc4d3e0ea
commit db08883480
2 changed files with 7 additions and 3 deletions

View File

@ -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'),
'<p>'+_('The template %s is invalid:')%tmpl + \

View File

@ -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