[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Formulator/Fields/Generic - DateTimeField.py:1.1.4.1 EmailField.py:1.1.4.1 FileField.py:1.1.4.1 FloatField.py:1.1.4.1 IntegerField.py:1.1.4.1 LinkField.py:1.1.4.1 ListField.py:1.1.4.1 MethodField.py:1.1.4.1 PasswordField.py:1.1.4.1 PatternField.py:1.1.4.1 StringField.py:1.1.4.1 TALESField.py:1.1.4.1 __init__.py:1.1.4.1
Stephan Richter
srichter@cbu.edu
Mon, 1 Apr 2002 21:10:22 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Formulator/Fields/Generic
In directory cvs.zope.org:/tmp/cvs-serv6377/Formulator/Fields/Generic
Added Files:
Tag: Zope-3x-branch
DateTimeField.py EmailField.py FileField.py FloatField.py
IntegerField.py LinkField.py ListField.py MethodField.py
PasswordField.py PatternField.py StringField.py TALESField.py
__init__.py
Log Message:
Issue 25: Resolved by janko & srichter
This checkin fixes all the license headers of all the files that needed
fixing it. :) This was made possible by Janko Hauser's script, which is now
available in the ZopeRoot/utilities directory.
Also, cleaned up the Formualtor tag insanity!
=== Added File Zope3/lib/python/Zope/App/Formulator/Fields/Generic/DateTimeField.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""
$Id: DateTimeField.py,v 1.1.4.1 2002/04/02 02:10:16 srichter Exp $
"""
from Zope.App.Formulator.Field import Field
from Zope.App.Formulator.Validators import DateTimeValidator
import time
class DateTimeField(Field):
__implements__ = Field.__implements__
id = None
default = ''
title = 'DateTime Field'
description = 'DateTime Field'
validator = DateTimeValidator.DateTimeValidator()
def on_value_input_style_changed(self, value):
if value == 'text':
self.sub_form = create_datetime_text_sub_form()
elif value == 'list':
self.sub_form = create_datetime_list_sub_form()
year_field = self.sub_form.get_field('year')
year_field.overrides['items'] = BoundMethod(self,
'override_year_items')
else:
assert 0, "Unknown input_style."
def override_year_items(self):
"""The method gets called to get the right amount of years.
"""
start_datetime = self.get_value('start_datetime')
end_datetime = self.get_value('end_datetime')
current_year = time.gmtime(time.time())[0]
if start_datetime:
first_year = start_datetime.year()
else:
first_year = current_year
if end_datetime:
last_year = end_datetime.year() + 1
else:
last_year = first_year + 11
return create_items(first_year, last_year, digits=4)
def create_datetime_text_sub_form():
sub_form = BasicForm()
year = IntegerField('year',
title="Year",
required=0,
display_width=4,
display_maxwidth=4,
max_length=4)
month = IntegerField('month',
title="Month",
required=0,
display_width=2,
display_maxwidth=2,
max_length=2)
day = IntegerField('day',
title="Day",
required=0,
display_width=2,
display_maxwidth=2,
max_length=2)
sub_form.add_group("date")
sub_form.add_fields([year, month, day], "date")
hour = IntegerField('hour',
title="Hour",
required=0,
display_width=2,
display_maxwidth=2,
max_length=2)
minute = IntegerField('minute',
title="Minute",
required=0,
display_width=2,
display_maxwidth=2,
max_length=2)
sub_form.add_group("time")
sub_form.add_fields([hour, minute], "time")
return sub_form
def create_datetime_list_sub_form():
sub_form = BasicForm()
year = ListField('year',
title="Year",
required=0,
default="",
items=create_items(2000, 2010, digits=4),
size=1)
month = ListField('month',
title="Month",
required=0,
default="",
items=create_items(1, 13, digits=2),
size=1)
day = ListField('day',
title="Day",
required=0,
default="",
items=create_items(1, 32, digits=2),
size=1)
sub_form.add_group("date")
sub_form.add_fields([year, month, day], "date")
hour = IntegerField('hour',
title="Hour",
required=0,
display_width=2,
display_maxwidth=2,
max_length=2)
minute = IntegerField('minute',
title="Minute",
required=0,
display_width=2,
display_maxwidth=2,
max_length=2)
sub_form.add_group("time")
sub_form.add_fields([hour, minute], "time")
return sub_form
def create_items(start, end, digits=0):
result = [("-", "")]
if digits:
format_string = "%0" + str(digits) + "d"
else:
format_string = "%s"
for i in range(start, end):
s = format_string % i
result.append((s, s))
return result
=== Added File Zope3/lib/python/Zope/App/Formulator/Fields/Generic/EmailField.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""
$Id: EmailField.py,v 1.1.4.1 2002/04/02 02:10:16 srichter Exp $
"""
from Zope.App.Formulator.Field import Field
from Zope.App.Formulator.Validators import EmailValidator
class EmailField(Field):
__implements__ = Field.__implements__
id = None
default = ''
title = 'Email Field'
description = 'Email Field'
validator = EmailValidator.EmailValidator()
=== Added File Zope3/lib/python/Zope/App/Formulator/Fields/Generic/FileField.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""
$Id: FileField.py,v 1.1.4.1 2002/04/02 02:10:16 srichter Exp $
"""
from Zope.App.Formulator.Field import Field
from Zope.App.Formulator.Validators import FileValidator
class FileField(Field):
__implements__ = Field.__implements__
id = None
default = ''
title = 'File Field'
description = 'File Field'
validator = FileValidator.FileValidator()
=== Added File Zope3/lib/python/Zope/App/Formulator/Fields/Generic/FloatField.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""
$Id: FloatField.py,v 1.1.4.1 2002/04/02 02:10:16 srichter Exp $
"""
from Zope.App.Formulator.Field import Field
from Zope.App.Formulator.Validators import FloatValidator
class FloatField(Field):
__implements__ = Field.__implements__
id = None
default = ''
title = 'Float Field'
description = 'Float Field'
validator = FloatValidator.FloatValidator()
=== Added File Zope3/lib/python/Zope/App/Formulator/Fields/Generic/IntegerField.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""
$Id: IntegerField.py,v 1.1.4.1 2002/04/02 02:10:16 srichter Exp $
"""
from Zope.App.Formulator.Field import Field
from Zope.App.Formulator.Validators import IntegerValidator
class IntegerField(Field):
__implements__ = Field.__implements__
id = None
default = ''
title = 'Integer Field'
description = 'Integer Field'
validator = IntegerValidator.IntegerValidator()
=== Added File Zope3/lib/python/Zope/App/Formulator/Fields/Generic/LinkField.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""
$Id: LinkField.py,v 1.1.4.1 2002/04/02 02:10:16 srichter Exp $
"""
from Zope.App.Formulator.Fields.Field import Field
from Zope.App.Formulator.Validators import LinkValidator
class LinkField(Field):
__implements__ = Field.__implements__
id = None
default = ''
title = 'Link Field'
description = 'Link Field'
validator = LinkValidator.LinkValidator()
=== Added File Zope3/lib/python/Zope/App/Formulator/Fields/Generic/ListField.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""
$Id: ListField.py,v 1.1.4.1 2002/04/02 02:10:16 srichter Exp $
"""
from Zope.App.Formulator.Field import Field
from Zope.App.Formulator.Validators import SelectionValidator
class ListField(Field):
__implements__ = Field.__implements__
id = None
default = ''
title = 'List Field'
description = 'List Field'
validator = SelectionValidator.SelectionValidator()
=== Added File Zope3/lib/python/Zope/App/Formulator/Fields/Generic/MethodField.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
from DummyField import fields
import Widget, Validator
from Globals import Persistent
import Acquisition
from Field import ZMIField
from AccessControl import getSecurityManager
class MethodWidget(Widget.TextWidget):
default = fields.MethodField('default',
title='Default',
default="",
required=0)
def render(self, field, key, value, REQUEST):
if value == None:
method_name = field.get_value('default')
else:
if value != "":
method_name = value.method_name
else:
method_name = ""
return Widget.TextWidget.render(self, field, key, method_name, REQUEST)
MethodWidgetInstance = MethodWidget()
class Method(Persistent, Acquisition.Implicit):
"""A method object; calls method name in acquisition context.
"""
def __init__(self, method_name):
self.method_name = method_name
def __call__(self, *arg, **kw):
# get method from acquisition path
method = getattr(self, self.method_name)
# check if we have 'View' permission for this method
# (raises error if not)
getSecurityManager().checkPermission('View', method)
# okay, execute it with supplied arguments
return apply(method, arg, kw)
class BoundMethod(Method):
"""A bound method calls a method on a particular object.
Should be used internally only.
"""
def __init__(self, object, method_name):
BoundMethod.inheritedAttribute('__init__')(self, method_name)
self.object = object
def __call__(self, *arg, **kw):
method = getattr(self.object, self.method_name)
return apply(method, arg, kw)
class MethodValidator(Validator.StringBaseValidator):
def validate(self, field, key, REQUEST):
value = Validator.StringBaseValidator.validate(self, field, key,
REQUEST)
if value == "" and not field.get_value('required'):
return value
return Method(value)
MethodValidatorInstance = MethodValidator()
class MethodField(ZMIField):
meta_type = 'MethodField'
internal_field = 1
widget = MethodWidgetInstance
validator = MethodValidatorInstance
=== Added File Zope3/lib/python/Zope/App/Formulator/Fields/Generic/PasswordField.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""
$Id: PasswordField.py,v 1.1.4.1 2002/04/02 02:10:16 srichter Exp $
"""
from Zope.App.Formulator.Field import Field
from Zope.App.Formulator.Validators import StringValidator
class PasswordField(Field):
__implements__ = Field.__implements__
id = None
default = ''
title = 'Password Field'
description = 'Password Field'
validator = StringValidator.StringValidator()
=== Added File Zope3/lib/python/Zope/App/Formulator/Fields/Generic/PatternField.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""
$Id: PatternField.py,v 1.1.4.1 2002/04/02 02:10:16 srichter Exp $
"""
from Zope.App.Formulator.Field import Field
from Zope.App.Formulator.Validators import PatternValidator
class PatternField(Field):
__implements__ = Field.__implements__
id = None
default = ''
title = 'Pattern Field'
description = 'Pattern Field'
validator = PatternValidator.PatternValidator()
=== Added File Zope3/lib/python/Zope/App/Formulator/Fields/Generic/StringField.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""
$Id: StringField.py,v 1.1.4.1 2002/04/02 02:10:16 srichter Exp $
"""
from Zope.App.Formulator.Field import Field
from Zope.App.Formulator.Validators import StringValidator
class StringField(Field):
__implements__ = Field.__implements__
id = None
default = ''
title = 'String Field'
description = 'String Field'
validator = StringValidator.StringValidator()
=== Added File Zope3/lib/python/Zope/App/Formulator/Fields/Generic/TALESField.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
from DummyField import fields
import Widget, Validator
from Globals import Persistent
import Acquisition
from Field import ZMIField
from AccessControl import getSecurityManager
class TALESWidget(Widget.TextWidget):
default = fields.MethodField('default',
title='Default',
default="",
required=0)
def render(self, field, key, value, REQUEST):
if value == None:
text = field.get_value('default')
else:
if value != "":
text = value._text
else:
text = ""
return Widget.TextWidget.render(self, field, key, text, REQUEST)
TALESWidgetInstance = TALESWidget()
class TALESNotAvailable(Exception):
pass
try:
# try to import getEngine from TALES
from Products.PageTemplates.EngineConfig import getEngine
class TALESMethod(Persistent, Acquisition.Implicit):
"""A method object; calls method name in acquisition context.
"""
def __init__(self, text):
self._text = text
#self._expr = getEngine().compile(text)
def __call__(self, **kw):
expr = getEngine().compile(self._text)
return getEngine().getContext(kw).evaluate(expr)
# check if we have 'View' permission for this method
# (raises error if not)
# getSecurityManager().checkPermission('View', method)
TALES_AVAILABLE = 1
except ImportError:
# cannot import TALES, so supply dummy TALESMethod
class TALESMethod(Persistent, Acquisition.Implicit):
"""A dummy method in case TALES is not available.
"""
def __init__(self, text):
self._text = text
def __call__(self, **kw):
raise TALESNotAvailable
TALES_AVAILABLE = 0
class TALESValidator(Validator.StringBaseValidator):
def validate(self, field, key, REQUEST):
value = Validator.StringBaseValidator.validate(self, field, key,
REQUEST)
if value == "" and not field.get_value('required'):
return value
return TALESMethod(value)
TALESValidatorInstance = TALESValidator()
class TALESField(ZMIField):
meta_type = 'TALESField'
internal_field = 1
widget = TALESWidgetInstance
validator = TALESValidatorInstance
=== Added File Zope3/lib/python/Zope/App/Formulator/Fields/Generic/__init__.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""
$Id: __init__.py,v 1.1.4.1 2002/04/02 02:10:16 srichter Exp $
"""