# HG changeset patch # User Thierry Florac # Date 1512729328 -3600 # Node ID 5638c9cfb233057a9d188e0683024128510963a5 # Parent a024de987b59085b60977953179fdea4b80cae54 Added "SEO-enabled" text-line input to display SEO quality based on text length (used for titles) diff -r a024de987b59 -r 5638c9cfb233 src/pyams_i18n/interfaces/widget.py --- a/src/pyams_i18n/interfaces/widget.py Fri Nov 10 13:27:53 2017 +0100 +++ b/src/pyams_i18n/interfaces/widget.py Fri Dec 08 11:35:28 2017 +0100 @@ -29,6 +29,10 @@ """I18n text line widget interface""" +class II18nSEOTextLineWidget(II18nTextLineWidget): + """I18n text line widget wit SEO quality marker interface""" + + class II18nTextWidget(II18nWidget): """I18n text widget interface""" diff -r a024de987b59 -r 5638c9cfb233 src/pyams_i18n/widget/__init__.py --- a/src/pyams_i18n/widget/__init__.py Fri Nov 10 13:27:53 2017 +0100 +++ b/src/pyams_i18n/widget/__init__.py Fri Dec 08 11:35:28 2017 +0100 @@ -20,11 +20,11 @@ from pyams_i18n.interfaces import II18nManager, INegotiator from pyams_i18n.interfaces.schema import II18nField, II18nTextLineField, II18nTextField, II18nFileField, II18nHTMLField from pyams_i18n.interfaces.widget import II18nWidget, II18nTextLineWidget, II18nTextWidget, II18nFileWidget, \ - II18nHTMLWidget + II18nHTMLWidget, II18nSEOTextLineWidget from z3c.form.interfaces import IDataConverter, IFieldWidget, NO_VALUE, IFormAware, IValidator, IErrorViewSnippet # import packages -from pyams_form.widget import widgettemplate_config +from pyams_form.widget import widgettemplate_config, SEOTextLineFieldWidget from pyams_utils.adapter import adapter_config from pyams_utils.registry import query_utility from pyams_utils.traversing import get_parent @@ -77,6 +77,8 @@ class I18nWidget(HTMLInputWidget, Widget): """I18n base widget""" + widget_factory = None + @reify def langs(self): langs = [] @@ -96,7 +98,10 @@ registry = self.request.registry self.widgets = {} for lang in self.langs: - widget = registry.queryMultiAdapter((self.field.value_type, self.request), IFieldWidget) + if self.widget_factory is not None: + widget = self.widget_factory(self.field.value_type, self.request) + else: + widget = registry.queryMultiAdapter((self.field.value_type, self.request), IFieldWidget) if widget is not None: prefix = expandPrefix(self.form.prefix) + expandPrefix(self.form.widgets.prefix) + expandPrefix(lang) name = self.field.value_type.__name__ = self.field.__name__ @@ -157,6 +162,18 @@ return FieldWidget(field, I18nTextLineWidget(request)) +@implementer_only(II18nSEOTextLineWidget) +class I18nSEOTextLineWidget(I18nTextLineWidget): + """I18n text line widget with SEO quality marker""" + + +def I18nSEOTextLineFieldWidget(field, request): + """I18n text line field widget with SEO quality marker factory""" + widget = I18nSEOTextLineWidget(request) + widget.widget_factory = SEOTextLineFieldWidget + return FieldWidget(field, widget) + + @implementer_only(II18nTextWidget) class I18nTextWidget(I18nWidget): """I18n text widget"""