Changed some instances of error strings from ascii to unicode in order to avoid problems with unicode error messages, such as the file size indications generated by django.template.defaultfilters.filesizeformat().

- Legacy-Id: 11220
This commit is contained in:
Henrik Levkowetz 2016-05-22 14:40:37 +00:00
parent a15d0ecbd6
commit a32b121efb
2 changed files with 10 additions and 6 deletions

View file

@ -62,21 +62,25 @@ class FileParser(object):
regexp = re.compile(r'&|\|\/|;|\*|\s|\$')
chars = regexp.findall(name)
if chars:
self.parsed_info.add_error('Invalid characters were found in the name of the file which was just submitted: %s' % ', '.join(set(chars)))
self.parsed_info.add_error(u'Invalid characters were found in the name of the file which was just submitted: %s' % ', '.join(set(chars)))
def parse_max_size(self):
max_size = settings.IDSUBMIT_MAX_DRAFT_SIZE[self.ext]
if self.fd.size > max_size:
self.parsed_info.add_error('File size is larger than the permitted maximum of %s' % filesizeformat(max_size))
s = filesizeformat(max_size)
debug.traceback()
debug.type('s')
debug.show('s')
self.parsed_info.add_error(u'File size is larger than the permitted maximum of %s' % filesizeformat(max_size))
self.parsed_info.metadata.file_size = self.fd.size
def parse_filename_extension(self):
if not self.fd.name.lower().endswith('.'+self.ext):
self.parsed_info.add_error('Expected the %s file to have extension ".%s", found the name "%s"' % (self.ext.upper(), self.ext, self.fd.name))
self.parsed_info.add_error(u'Expected the %s file to have extension ".%s", found the name "%s"' % (self.ext.upper(), self.ext, self.fd.name))
def parse_file_type(self):
self.fd.file.seek(0)
content = self.fd.file.read(4096)
mimetype = magic.from_buffer(content, mime=True)
if not mimetype == self.mimetype:
self.parsed_info.add_error('Expected an %s file of type "%s", found one of type "%s"' % (self.ext.upper(), self.mimetype, mimetype))
self.parsed_info.add_error(u'Expected an %s file of type "%s", found one of type "%s"' % (self.ext.upper(), self.mimetype, mimetype))

View file

@ -3,7 +3,7 @@ import bootstrap3.renderers
class SeparateErrorsFromHelpTextFieldRenderer(bootstrap3.renderers.FieldRenderer):
def append_to_field(self, html):
if self.field_help:
html += '<div class="help-block">{}</div>'.format(self.field_help)
html += u'<div class="help-block">{}</div>'.format(self.field_help)
for e in self.field_errors:
html += '<div class="alert alert-danger">{}</div>'.format(e)
html += u'<div class="alert alert-danger">{}</div>'.format(e)
return html