# HG changeset patch # User Thierry Florac # Date 1512729225 -3600 # Node ID d07ddd028cd049fadc70200c16f79b8d2d782504 # Parent 8969b8950fed22caf3484147a39c26f92c4e98bf Added "SEO-enabled" text-line input to display SEO quality based on text length (used for titles) diff -r 8969b8950fed -r d07ddd028cd0 src/pyams_form/interfaces/form.py --- a/src/pyams_form/interfaces/form.py Wed Nov 29 10:31:38 2017 +0100 +++ b/src/pyams_form/interfaces/form.py Fri Dec 08 11:33:45 2017 +0100 @@ -511,9 +511,16 @@ """New select2 based widget""" +class ISEOTextLineWidget(ITextWidget): + """Text line widget with SEO length indicator""" + + class ITextLineListWidget(ITextWidget): """Text line list widget""" + length = Attribute("Input length") + status = Attribute("SEO input status related to text length") + # # Form events diff -r 8969b8950fed -r d07ddd028cd0 src/pyams_form/widget/__init__.py --- a/src/pyams_form/widget/__init__.py Wed Nov 29 10:31:38 2017 +0100 +++ b/src/pyams_form/widget/__init__.py Fri Dec 08 11:33:45 2017 +0100 @@ -20,8 +20,9 @@ import venusian # import interfaces -from pyams_form.interfaces.form import IFormLayer, IResetWidget, ICloseWidget, IDateWidget, IDatetimeWidget, ITimeWidget, \ - IColorWidget, IHTMLWidget, ISelect2Widget, ITextLineListWidget +from pyams_form.interfaces.form import IFormLayer, IResetWidget, ICloseWidget, IDateWidget, IDatetimeWidget, \ + ITimeWidget, \ + IColorWidget, IHTMLWidget, ISelect2Widget, ITextLineListWidget, ISEOTextLineWidget from pyams_form.schema import IResetButton, ICloseButton from pyams_skin.interfaces.tinymce import ITinyMCEConfiguration from pyams_utils.schema import IColorField, IHTMLField, ITextLineListField @@ -380,3 +381,31 @@ @adapter_config(context=(ITextLineListField, IFormLayer), provides=IFieldWidget) def TextLineListFieldWidget(field, request): return FieldWidget(field, TextLineListWidget(request)) + + +# +# TextLine widget with SEO length status +# + +@widgettemplate_config(mode=INPUT_MODE, template='templates/seo-textline-input.pt', layer=IFormLayer) +@implementer_only(ISEOTextLineWidget) +class SEOTextLineWidget(TextWidget): + """SEO textline widget""" + + @property + def length(self): + return len(self.value or '') + + @property + def status(self): + status = 'success' + length = self.length + if length < 20 or length > 80: + status = 'danger' + elif length < 40 or length > 66: + status = 'warning' + return status + + +def SEOTextLineFieldWidget(field, request): + return FieldWidget(field, SEOTextLineWidget(request)) diff -r 8969b8950fed -r d07ddd028cd0 src/pyams_form/widget/templates/seo-textline-input.pt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_form/widget/templates/seo-textline-input.pt Fri Dec 08 11:33:45 2017 +0100 @@ -0,0 +1,44 @@ + + +
+
+
+