Fix ticket #8214 (Detect 'senseless' user input)

This commit is contained in:
Charles Haley 2011-01-06 19:35:04 +00:00
parent 90f973e7ac
commit ae759ebd10
2 changed files with 7 additions and 3 deletions

View file

@ -8,7 +8,7 @@
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 @@ def validate(self):
'''
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 @@ def safe_format(self, fmt, kwargs, error_value, book):
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