[PATCH saem] [eac] Fix UnicodeEncodeError when unconfigured user attempt to create an authority record

Sylvain Thenault sylvain.thenault at logilab.fr
Thu Oct 5 11:01:13 CEST 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1507124215 -7200
#      Wed Oct 04 15:36:55 2017 +0200
# Node ID 9d703c668cfdc6d99dcf425cf85542d2e2a6a809
# Parent  976da31e4753197f8821706f065b2b145f90a822
# Available At http://hg.logilab.org/review/cubes/saem_ref
#              hg pull http://hg.logilab.org/review/cubes/saem_ref -r 9d703c668cfd
[eac] Fix UnicodeEncodeError when unconfigured user attempt to create an authority record

and test regression by adding a non-ascii unicode character to the translated
string.

Closes extranet #36759603

diff --git a/cubicweb_saem_ref/views/eac.py b/cubicweb_saem_ref/views/eac.py
--- a/cubicweb_saem_ref/views/eac.py
+++ b/cubicweb_saem_ref/views/eac.py
@@ -53,19 +53,19 @@ class EACImportViewNoNaa(eac.EACImportVi
 
     def call(self):
         self.w(tags.h1(self._cw.__('Importing an AuthorityRecord from a EAC-CPF file')))
         if not self._cw.user.authority:
             msg = self._cw._("You must be in an organization to access this functionnality.")
-            msg += " <a href='{}'>{}</a>".format(self._cw.user.absolute_url(vid='edition'),
-                                                 self._cw._('Edit your settings'))
+            msg += u" <a href='{}'>{}</a>".format(self._cw.user.absolute_url(vid='edition'),
+                                                  self._cw._('Edit your settings'))
         else:
             msg = self._cw._("Your organization must have an NAA configured to "
                              "access this functionnality.")
             authority = self._cw.user.authority[0]
             if authority.cw_has_perm('update'):
-                msg += " <a href='{}'>{}</a>".format(authority.absolute_url(vid='edition'),
-                                                     self._cw._('Edit authority settings'))
+                msg += u" <a href='{}'>{}</a>".format(authority.absolute_url(vid='edition'),
+                                                      self._cw._('Edit authority settings'))
         self.w(tags.div(msg))
 
 
 class EACCreationFormViewNoNaa(editforms.CreationFormView):
     __select__ = (editforms.CreationFormView.__select__
@@ -73,12 +73,12 @@ class EACCreationFormViewNoNaa(editforms
                   & ~user_has_authority())
 
     def render_form(self, entity):
         self.form_title(entity)
         msg = self._cw._("You must be in an organization to access this functionnality.")
-        msg += " <a href='{}'>{}</a>".format(self._cw.user.absolute_url(vid='edition'),
-                                             self._cw._('Edit your settings'))
+        msg += u" <a href='{}'>{}</a>".format(self._cw.user.absolute_url(vid='edition'),
+                                              self._cw._('Edit your settings'))
         self.w(tags.div(msg))
 
 
 def registration_callback(vreg):
     vreg.register_all(globals().values(), __name__, (EACImportForm, EACImportView))
diff --git a/test/test_views.py b/test/test_views.py
--- a/test/test_views.py
+++ b/test/test_views.py
@@ -100,14 +100,16 @@ class FuncViewsTC(CubicWebTC):
             self.assertEqual(without_link_html, u'<i class="truncate">plop</i>')
 
     def test_eac_import_user_has_no_naa(self):
         regid = 'eac.import'
         with self.admin_access.web_request() as req:
+            req._ = lambda x: x + u' \xe9'
             output = self.view(regid, req=req, template=None)
             self.assertIn('be in an organization', output)
             self.assertIn('to access this functionnality', output)
         with self.admin_access.web_request() as req:
+            req._ = lambda x: x + u' \xe9'
             authority = req.cnx.create_entity('Organization', name=u'dummy',
                                               ark=u'123')
             req.user.cw_set(authority=authority)
             req.cnx.commit()
             output = self.view(regid, req=req, template=None)


More information about the saem-devel mailing list