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 92ac4dc2f7
commit 36db1f4e06
3 changed files with 17 additions and 2 deletions

View File

@@ -76,6 +76,7 @@ Backward incompatible changes
Bugs fixed or issues closed Bugs fixed or issues closed
=========================== ===========================
* `GitLab issue #310 <https://gitlab.com/mayan-edms/mayan-edms/issues/310>`_ Metadata's lookup with chinese messages when new document
* `GitLab issue #348 <https://gitlab.com/mayan-edms/mayan-edms/issues/348>`_ REST API: Document version comments are not getting updated * `GitLab issue #348 <https://gitlab.com/mayan-edms/mayan-edms/issues/348>`_ REST API: Document version comments are not getting updated
* `GitLab issue #349 <https://gitlab.com/mayan-edms/mayan-edms/issues/349>`_ REST API: Document Label, Description are not able to update * `GitLab issue #349 <https://gitlab.com/mayan-edms/mayan-edms/issues/349>`_ REST API: Document Label, Description are not able to update

View File

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

View File

@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.core.files.base import File from django.core.files.base import File
@@ -175,3 +176,15 @@ class MetadataTestCase(TestCase):
self.assertTrue( self.assertTrue(
self.metadata_type.get_required_for(self.document_type) 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')