# HG changeset patch # User Thierry Florac # Date 1333732199 -7200 # Node ID d5e916191cf461b445b867761934e4ac516cc090 # Parent 6478aac3b2bd083c390091c7dbd77c7bf680afe0 Added "Color" field and widget diff -r 6478aac3b2bd -r d5e916191cf4 setup.py --- a/setup.py Mon Apr 02 09:08:09 2012 +0200 +++ b/setup.py Fri Apr 06 19:09:59 2012 +0200 @@ -85,6 +85,7 @@ 'zope.session', 'zope.tales', 'zopyx.txng3.core', + 'ztfy.jqueryui >= 0.5.6', ], entry_points=""" # -*- Entry points: -*- diff -r 6478aac3b2bd -r d5e916191cf4 ztfy.utils.egg-info/PKG-INFO --- a/ztfy.utils.egg-info/PKG-INFO Mon Apr 02 09:08:09 2012 +0200 +++ b/ztfy.utils.egg-info/PKG-INFO Fri Apr 06 19:09:59 2012 +0200 @@ -1,6 +1,6 @@ Metadata-Version: 1.0 Name: ztfy.utils -Version: 0.3.9 +Version: 0.3.10 Summary: ZTFY utility functions and classes for Zope3 Home-page: http://www.ztfy.org Author: Thierry Florac @@ -41,6 +41,10 @@ Changelog ========= + 0.3.10 + ------ + - added StringLine schema field + 0.3.9 ----- - added HTTP client based on httplib2, handling authentication and proxies diff -r 6478aac3b2bd -r d5e916191cf4 ztfy.utils.egg-info/SOURCES.txt --- a/ztfy.utils.egg-info/SOURCES.txt Mon Apr 02 09:08:09 2012 +0200 +++ b/ztfy.utils.egg-info/SOURCES.txt Fri Apr 06 19:09:59 2012 +0200 @@ -27,7 +27,9 @@ ztfy/utils/interfaces.py ztfy/utils/overrides.zcml ztfy/utils/profilehooks.py +ztfy/utils/property.py ztfy/utils/request.py +ztfy/utils/schema.py ztfy/utils/security.py ztfy/utils/session.py ztfy/utils/site.py diff -r 6478aac3b2bd -r d5e916191cf4 ztfy/utils/browser/color.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ztfy/utils/browser/color.py Fri Apr 06 19:09:59 2012 +0200 @@ -0,0 +1,53 @@ +### -*- coding: utf-8 -*- #################################################### +############################################################################## +# +# Copyright (c) 2012 Thierry Florac +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# +############################################################################## + + +# import standard packages + +# import Zope3 interfaces +from z3c.form.interfaces import ITextWidget, IFieldWidget, IFormLayer + +# import local interfaces +from ztfy.utils.schema import IColorField + +# import Zope3 packages +from z3c.form.browser.text import TextWidget +from z3c.form.widget import FieldWidget +from zope.component import adapter +from zope.interface import implementer, implementsOnly + +# import local packages +from ztfy.jqueryui.browser import jquery_colorpicker + + +class IColorWidget(ITextWidget): + """Color widget interface""" + + +class ColorWidget(TextWidget): + """Color widget""" + + implementsOnly(IColorWidget) + + def update(self): + TextWidget.update(self) + jquery_colorpicker.need() + + +@adapter(IColorField, IFormLayer) +@implementer(IFieldWidget) +def ColorFieldWidgetFactory(field, request): + """IColorField widget factory""" + return FieldWidget(field, ColorWidget(request)) diff -r 6478aac3b2bd -r d5e916191cf4 ztfy/utils/browser/configure.zcml --- a/ztfy/utils/browser/configure.zcml Mon Apr 02 09:08:09 2012 +0200 +++ b/ztfy/utils/browser/configure.zcml Fri Apr 06 19:09:59 2012 +0200 @@ -1,5 +1,6 @@ @@ -12,4 +13,26 @@ permission="zope.Public" /> + + + + + + + + + + + \ No newline at end of file diff -r 6478aac3b2bd -r d5e916191cf4 ztfy/utils/browser/templates/color_display.pt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ztfy/utils/browser/templates/color_display.pt Fri Apr 06 19:09:59 2012 +0200 @@ -0,0 +1,14 @@ +
+ +
+ +
\ No newline at end of file diff -r 6478aac3b2bd -r d5e916191cf4 ztfy/utils/browser/templates/color_input.pt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ztfy/utils/browser/templates/color_input.pt Fri Apr 06 19:09:59 2012 +0200 @@ -0,0 +1,32 @@ +
+ +
+ +
\ No newline at end of file diff -r 6478aac3b2bd -r d5e916191cf4 ztfy/utils/schema.py --- a/ztfy/utils/schema.py Mon Apr 02 09:08:09 2012 +0200 +++ b/ztfy/utils/schema.py Fri Apr 06 19:09:59 2012 +0200 @@ -15,16 +15,22 @@ # import standard packages +import string # import Zope3 interfaces +from zope.schema.interfaces import ITextLine # import local interfaces # import Zope3 packages +from zope.interface import implements from zope.schema import TextLine +from zope.schema._bootstrapfields import InvalidValue # import local packages +from ztfy.utils import _ + class StringLine(TextLine): """String line field""" @@ -33,3 +39,24 @@ def fromUnicode(self, value): return str(value) + + +class IColorField(ITextLine): + """Marker interface for color fields""" + + +class ColorField(TextLine): + """Color field""" + + implements(IColorField) + + def __init__(self, *args, **kw): + super(ColorField, self).__init__(max_length=6, *args, **kw) + + def _validate(self, value): + if len(value) not in (3, 6): + raise InvalidValue, _("Color length must be 3 or 6 characters") + for v in value: + if v not in string.hexdigits: + raise InvalidValue, _("Color value must contain only valid color codes (numbers or letters between 'A' end 'F')") + super(ColorField, self)._validate(value)