Added content check on title length
authorThierry Florac <thierry.florac@onf.fr>
Fri, 08 Dec 2017 10:42:11 +0100
changeset 305 b5967aacf4c1
parent 304 14b2ae98f78c
child 306 7e7925d13e13
Added content check on title length
src/pyams_content/shared/common/__init__.py
--- a/src/pyams_content/shared/common/__init__.py	Fri Dec 08 10:41:32 2017 +0100
+++ b/src/pyams_content/shared/common/__init__.py	Fri Dec 08 10:42:11 2017 +0100
@@ -18,7 +18,7 @@
 # import interfaces
 from hypatia.interfaces import ICatalog
 from pyams_content.interfaces import IBaseContentInfo
-from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE
+from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE, ERROR_VALUE
 from pyams_content.features.review.interfaces import IReviewComments
 from pyams_content.shared.common.interfaces import IWfSharedContent, IWfSharedContentRoles, ISharedContent, \
     IBaseSharedTool, ISharedSite
@@ -245,6 +245,14 @@
                     else:
                         output.append(missing_lang_value.format(field=translate(IWfSharedContent[attr].title),
                                                                 lang=lang))
+                else:
+                    length = len(value)
+                    if (attr == 'title') and (length < 40 or length > 66):
+                        output.append(translate(ERROR_VALUE).format(
+                            field=translate(IWfSharedContent[attr].title),
+                            message=translate(_("title length should be between 40 and 66 characters ({length} "
+                                                "actually)")).format(length=length)
+                        ))
         if not self.context.keywords:
             output.append(missing_value.format(field=translate(IWfSharedContent['keywords'].title)))
         return output