Return metadata type lookup values as list of unicode not list of strings.

Fixed GitLab issue #310, thank for @fordguo for the find and fix suggestion.
This commit is contained in:
Roberto Rosario
2017-02-03 16:18:58 -04:00
parent 5f99b123d7
commit b58fa7e241
3 changed files with 18 additions and 3 deletions

View File

@@ -49,7 +49,7 @@ Other changes
- Make the lock_manager.backends.file_lock.FileLock the new default locking backend.
- Add view to clone a document page transformation to other pages.
- Document page transformation navigation bug fixed.
- Document page transformation navigation bug fixed.
- Move test total to 359.
- Increase test coverage to 81%.
- New transformations added:
@@ -128,6 +128,7 @@ Bugs fixed or issues closed
* `GitLab issue #303 <https://gitlab.com/mayan-edms/mayan-edms/issues/303>`_ Update urlpatterns in urls.py files to be a list of django.conf.urls.url() instances instead.
* `GitLab issue #304 <https://gitlab.com/mayan-edms/mayan-edms/issues/304>`_ Remove string view arguments of url() in urls.py files.
* `GitLab issue #307 <https://gitlab.com/mayan-edms/mayan-edms/issues/307>`_ Enter multiple Tags at once
* `GitLab issue #310 <https://gitlab.com/mayan-edms/mayan-edms/issues/310>`_ Metadata's lookup with chinese messages when new document
* `GitLab issue #311 <https://gitlab.com/mayan-edms/mayan-edms/issues/311>`_ acl page return ContentType:Document
* `GitLab issue #319 <https://gitlab.com/mayan-edms/mayan-edms/issues/319>`_ TransformationResize issue with very "long" image
* `GitLab issue #328 <https://gitlab.com/mayan-edms/mayan-edms/issues/328>`_ Upgrade Warning/Error during performupgrade (v2.1.3 to v2.1.4)

View File

@@ -5,7 +5,7 @@ import shlex
from django.core.exceptions import ValidationError
from django.db import models
from django.template import Context, Template
from django.utils.encoding import python_2_unicode_compatible
from django.utils.encoding import force_text, python_2_unicode_compatible
from django.utils.module_loading import import_string
from django.utils.translation import ugettext_lazy as _
@@ -97,7 +97,7 @@ class MetadataType(models.Model):
splitter.whitespace = ','.encode('utf-8')
splitter.whitespace_split = True
splitter.commenters = ''.encode('utf-8')
return list(splitter)
return [force_text(e) for e in splitter]
def get_default_value(self):
template = Template(self.default)
@@ -126,6 +126,7 @@ class MetadataType(models.Model):
if self.lookup:
lookup_options = self.get_lookup_values()
if value and value not in lookup_options:
raise ValidationError(
_('Value is not one of the provided options.')

View File

@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.core.exceptions import ValidationError
@@ -177,3 +178,15 @@ class MetadataTestCase(BaseTestCase):
self.assertTrue(
self.metadata_type.get_required_for(self.document_type)
)
def test_unicode_lookup(self):
# Should NOT return a ValidationError, otherwise test fails
self.metadata_type.lookup = '测试1,测试2,test1,test2'
self.metadata_type.save()
self.metadata_type.validate_value(document_type=None, value='测试1')
def test_non_unicode_lookup(self):
# Should NOT return a ValidationError, otherwise test fails
self.metadata_type.lookup = 'test1,test2'
self.metadata_type.save()
self.metadata_type.validate_value(document_type=None, value='test1')