mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix ticket #8214 (Detect 'senseless' user input)
This commit is contained in:
parent
90f973e7ac
commit
ae759ebd10
@ -8,7 +8,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
from PyQt4.Qt import QWidget, pyqtSignal
|
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.gui2.preferences.save_template_ui import Ui_Form
|
||||||
from calibre.library.save_to_disk import FORMAT_ARG_DESCS, preprocess_template
|
from calibre.library.save_to_disk import FORMAT_ARG_DESCS, preprocess_template
|
||||||
from calibre.utils.formatter import validation_formatter
|
from calibre.utils.formatter import validation_formatter
|
||||||
@ -52,7 +52,11 @@ class SaveTemplate(QWidget, Ui_Form):
|
|||||||
'''
|
'''
|
||||||
tmpl = preprocess_template(self.opt_template.text())
|
tmpl = preprocess_template(self.opt_template.text())
|
||||||
try:
|
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:
|
except Exception, err:
|
||||||
error_dialog(self, _('Invalid template'),
|
error_dialog(self, _('Invalid template'),
|
||||||
'<p>'+_('The template %s is invalid:')%tmpl + \
|
'<p>'+_('The template %s is invalid:')%tmpl + \
|
||||||
|
@ -453,7 +453,7 @@ class TemplateFormatter(string.Formatter):
|
|||||||
|
|
||||||
class ValidateFormatter(TemplateFormatter):
|
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):
|
def get_value(self, key, args, kwargs):
|
||||||
return self._validation_string
|
return self._validation_string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user