work in progress: organize: Python3 fixes

This commit is contained in:
Helmut Merz 2024-09-22 18:10:02 +02:00
parent 8d260908a5
commit 52990d1df6
19 changed files with 112 additions and 394 deletions

View file

@ -1,28 +1,9 @@
# # cybertools.composer.message.base
# Copyright (c) 2007 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
""" """ Basic classes for message management.
Basic classes for message management.
$Id$
""" """
from zope.interface import implements from zope.interface import implementer
from cybertools.composer.base import Component, Element, Compound from cybertools.composer.base import Component, Element, Compound
from cybertools.composer.base import Template from cybertools.composer.base import Template
@ -30,10 +11,9 @@ from cybertools.composer.message.interfaces import IMessageManager, IMessage
from cybertools.util.jeep import Jeep from cybertools.util.jeep import Jeep
@implementer(IMessageManager)
class MessageManager(object): class MessageManager(object):
implements(IMessageManager)
messagesFactory = Jeep messagesFactory = Jeep
messages = None messages = None
@ -50,10 +30,9 @@ class MessageManager(object):
self.messages.append(message) self.messages.append(message)
@implementer(IMessage)
class Message(Template): class Message(Template):
implements(IMessage)
name = u'' name = u''
manager = None manager = None

View file

@ -1,30 +1,11 @@
# # cybertools.composer.rule.base
# Copyright (c) 2007 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
""" """ Basic classes for rules and actions.
Basic classes for rules and actions.
$Id$
""" """
from zope import component from zope import component
from zope.component import adapts from zope.component import adapts
from zope.interface import implements from zope.interface import implementer
from cybertools.composer.base import Component, Element, Compound from cybertools.composer.base import Component, Element, Compound
from cybertools.composer.base import Template from cybertools.composer.base import Template
@ -38,10 +19,9 @@ from cybertools.util.jeep import Jeep
# rules # rules
@implementer(IRuleManager)
class RuleManager(object): class RuleManager(object):
implements(IRuleManager)
rulesFactory = Jeep rulesFactory = Jeep
rules = None rules = None
@ -67,10 +47,9 @@ class RuleManager(object):
return result return result
@implementer(IRule)
class Rule(Template): class Rule(Template):
implements(IRule)
name = title = description = u'' name = title = description = u''
manager = None manager = None
actions = None actions = None
@ -95,10 +74,9 @@ class EventType(object):
self.title = title or name self.title = title or name
@implementer(IEvent)
class Event(object): class Event(object):
implements(IEvent)
def __init__(self, eventType, context=None, request=None): def __init__(self, eventType, context=None, request=None):
self.eventType = eventType self.eventType = eventType
self.name = eventType.name self.name = eventType.name
@ -109,9 +87,9 @@ class Event(object):
# conditions # conditions
@implementer(ICondition)
class Condition(object): class Condition(object):
implements(ICondition)
adapts(IRuleInstance) adapts(IRuleInstance)
def __init__(self, context): def __init__(self, context):
@ -123,10 +101,9 @@ class Condition(object):
# actions # actions
@implementer(IAction)
class Action(Component): class Action(Component):
implements(IAction)
name = u'' name = u''
handlerName = u'' handlerName = u''
parameters = None parameters = None
@ -142,9 +119,9 @@ class Action(Component):
self.handlerName = name self.handlerName = name
@implementer(IActionHandler)
class ActionHandler(object): class ActionHandler(object):
implements(IActionHandler)
adapts(IRuleInstance) adapts(IRuleInstance)
def __init__(self, context): def __init__(self, context):

View file

@ -1,38 +1,19 @@
# # cybertools.rule.instance
# Copyright (c) 2007 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
""" """ Rule instance and related classes.
Rule instance and related classes.
$Id$
""" """
from zope import component from zope import component
from zope.component import adapts from zope.component import adapts
from zope.interface import Interface, implements from zope.interface import Interface, implementer
from cybertools.composer.instance import Instance from cybertools.composer.instance import Instance
from cybertools.composer.rule.interfaces import IRuleInstance, IActionHandler from cybertools.composer.rule.interfaces import IRuleInstance, IActionHandler
@implementer(IRuleInstance)
class RuleInstance(Instance): class RuleInstance(Instance):
implements(IRuleInstance)
adapts(Interface) adapts(Interface)
template = None template = None

View file

@ -1,21 +1,20 @@
import unittest, doctest import unittest, doctest
from email import message_from_string from email import message_from_string
from zope.interface import implements from zope.interface import implementer
from zope.sendmail.interfaces import IMailDelivery from zope.sendmail.interfaces import IMailDelivery
@implementer(IMailDelivery)
class TestMailer(object): class TestMailer(object):
implements(IMailDelivery)
def send(self, sender, recipients, message): def send(self, sender, recipients, message):
print 'sender:', sender print('sender:', sender)
print 'recipients:', recipients print('recipients:', recipients)
msg = message_from_string(message) msg = message_from_string(message)
print 'subject:', msg['Subject'] print('subject:', msg['Subject'])
print 'message:' print('message:')
print msg.get_payload(decode=True) print(msg.get_payload(decode=True))
class Test(unittest.TestCase): class Test(unittest.TestCase):

View file

@ -1,29 +1,9 @@
# # cybertools.composer.rule.web
# Copyright (c) 2009 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
""" """ Action handler for sending emails.
Action handler for sending emails.
$Id$
""" """
from zope import component from zope import component
from zope.interface import implements
from cybertools.composer.rule.interfaces import IRuleManager, IRuleInstance from cybertools.composer.rule.interfaces import IRuleManager, IRuleInstance
from cybertools.composer.rule.interfaces import IActionHandler from cybertools.composer.rule.interfaces import IActionHandler

View file

@ -1,32 +1,13 @@
# # cybertools.composer.schema.browser.common
# Copyright (c) 2010 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
""" """ Common base class(es) for schema and other template views.
Common base class(es) for schema and other template views.
$Id$
""" """
from datetime import datetime from datetime import datetime
import time import time
from zope import component from zope import component
from zope.app.pagetemplate import ViewPageTemplateFile from zope.browserpage import ViewPageTemplateFile
from zope.app.session.interfaces import ISession from zope.session.interfaces import ISession
from zope.cachedescriptors.property import Lazy from zope.cachedescriptors.property import Lazy
from zope.traversing.browser.absoluteurl import absoluteURL from zope.traversing.browser.absoluteurl import absoluteURL

View file

@ -1,25 +1,6 @@
# # cybertools.composer.schema.client
# Copyright (c) 2010 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
""" """ Client implementations.
Client implementations.
$Id$
""" """
from BTrees.OOBTree import OOBTree from BTrees.OOBTree import OOBTree
@ -27,7 +8,7 @@ from persistent import Persistent
from time import time from time import time
from zope.cachedescriptors.property import Lazy from zope.cachedescriptors.property import Lazy
from zope.component import adapts from zope.component import adapts
from zope.interface import implements from zope.interface import implementer
from cybertools.composer.message.base import MessageManager from cybertools.composer.message.base import MessageManager
from cybertools.composer.rule.base import RuleManager, EventType from cybertools.composer.rule.base import RuleManager, EventType
@ -42,10 +23,9 @@ from cybertools.util.jeep import Jeep
from cybertools.util.randomname import generateName from cybertools.util.randomname import generateName
@implementer(IClientManager)
class ClientManager(object): class ClientManager(object):
implements(IClientManager)
clientSchemasFactory = Jeep clientSchemasFactory = Jeep
clientsFactory = OOBTree clientsFactory = OOBTree
@ -85,10 +65,9 @@ class ClientManager(object):
return name not in self.getClients() return name not in self.getClients()
@implementer(IClient)
class Client(Persistent): class Client(Persistent):
implements(IClient)
timeStamp = None timeStamp = None
def __init__(self, manager=None): def __init__(self, manager=None):
@ -96,9 +75,9 @@ class Client(Persistent):
self.timeStamp = int(time()) self.timeStamp = int(time())
@implementer(IClientFactory)
class ClientFactory(object): class ClientFactory(object):
implements(IClientFactory)
adapts(IClientManager) adapts(IClientManager)
def __init__(self, context): def __init__(self, context):

View file

@ -127,7 +127,7 @@ class Field(Component):
if instance is not None: if instance is not None:
context = instance.context context = instance.context
voc = (self.vocabulary or '') voc = (self.vocabulary or '')
if isinstance(voc, basestring): if isinstance(voc, str):
terms = self.getVocabularyTerms(voc, context, request) terms = self.getVocabularyTerms(voc, context, request)
if terms is not None: if terms is not None:
return terms return terms
@ -268,7 +268,7 @@ class DecimalFieldInstance(NumberFieldInstance):
def display(self, value, pattern=u'#,##0.00;-#,##0.00'): def display(self, value, pattern=u'#,##0.00;-#,##0.00'):
if value is None: if value is None:
return '' return ''
if isinstance(value, basestring): if isinstance(value, str):
if not value.isdigit(): if not value.isdigit():
return value return value
value = float(value) value = float(value)
@ -293,7 +293,7 @@ class DateFieldInstance(NumberFieldInstance):
def marshall(self, value): def marshall(self, value):
if not value: if not value:
return '' return ''
if isinstance(value, basestring): if isinstance(value, str):
return value return value
try: try:
return strftime('%Y-%m-%dT%H:%M', value.timetuple()) return strftime('%Y-%m-%dT%H:%M', value.timetuple())
@ -402,7 +402,7 @@ class ListFieldInstance(FieldInstance):
return component.getAdapter(self.valueType, IFieldInstance, name=instanceName) return component.getAdapter(self.valueType, IFieldInstance, name=instanceName)
def marshall(self, value): def marshall(self, value):
if isinstance(value, basestring): if isinstance(value, str):
return value return value
if value is None: if value is None:
return u'' return u''
@ -412,12 +412,12 @@ class ListFieldInstance(FieldInstance):
def display(self, value): def display(self, value):
if not value: if not value:
return u'' return u''
if isinstance(value, basestring): if isinstance(value, str):
return value return value
return u' | '.join(unicode(self.valueFieldInstance.display(v)) for v in value) return u' | '.join(unicode(self.valueFieldInstance.display(v)) for v in value)
def unmarshall(self, value): def unmarshall(self, value):
if isinstance(value, basestring): if isinstance(value, str):
value = value.split('\n') value = value.split('\n')
return [self.valueFieldInstance.unmarshall(v.strip()) return [self.valueFieldInstance.unmarshall(v.strip())
for v in value if v.strip()] for v in value if v.strip()]

View file

@ -1,29 +1,12 @@
# # cybertools.composer.schema.instance
# Copyright (c) 2013 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
""" """ Instance adapter classes for schemas.
Instance adapter classes for schemas.
""" """
from BTrees.OOBTree import OOBTree from BTrees.OOBTree import OOBTree
from zope.cachedescriptors.property import Lazy from zope.cachedescriptors.property import Lazy
from zope.component import adapts from zope.component import adapts
from zope.interface import implements, Interface from zope.interface import implementer, Interface
from cybertools.composer.instance import Instance as BaseInstance from cybertools.composer.instance import Instance as BaseInstance
from cybertools.composer.interfaces import IInstance from cybertools.composer.interfaces import IInstance
@ -32,9 +15,9 @@ from cybertools.composer.schema.schema import FormState
from cybertools.util.jeep import Jeep from cybertools.util.jeep import Jeep
@implementer(IInstance)
class Instance(BaseInstance): class Instance(BaseInstance):
implements(IInstance)
adapts(Interface) adapts(Interface)
aspect = 'schema.editor.default' aspect = 'schema.editor.default'
@ -77,9 +60,9 @@ class Instance(BaseInstance):
return self.getFieldInstances() return self.getFieldInstances()
@implementer(IInstance)
class Editor(BaseInstance): class Editor(BaseInstance):
implements(IInstance)
adapts(Interface) adapts(Interface)
aspect = 'schema.editor.default' aspect = 'schema.editor.default'
@ -134,9 +117,9 @@ class Editor(BaseInstance):
return formState return formState
@implementer(IInstance)
class ClientInstance(object): class ClientInstance(object):
implements(IInstance)
adapts(IClient) adapts(IClient)
attrsName = '__schema_attributes__' attrsName = '__schema_attributes__'

View file

@ -1,29 +1,10 @@
# # cybertools.organize.browser.report
# Copyright (c) 2010 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
""" """ View classes for CSV export.
View classes for CSV export.
$Id$
""" """
import csv import csv
from cStringIO import StringIO from io import StringIO
import itertools import itertools
from zope import component from zope import component
from zope.cachedescriptors.property import Lazy from zope.cachedescriptors.property import Lazy
@ -172,7 +153,7 @@ class RegistrationsExportCsv(BaseView):
return result return result
def encode(self, text): def encode(self, text):
if type(text) is unicode: if isinstance(text, str):
result = [] result = []
for c in text: for c in text:
try: try:
@ -180,5 +161,5 @@ class RegistrationsExportCsv(BaseView):
except UnicodeEncodeError: except UnicodeEncodeError:
c = '?' c = '?'
result.append(c) result.append(c)
text = ''.join(result) text = b''.join(result)
return text return text

View file

@ -1,38 +1,18 @@
# # cybertools.organize.party
# Copyright (c) 2006 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
""" """ A set of simple application classes for contact management; this may be used
A set of simple application classes for contact management; this may be used
as an example for some of the cybertools packages, but may also be the base as an example for some of the cybertools packages, but may also be the base
for some real life stuff. for some real life stuff.
$Id$
""" """
from zope.interface import implements from zope.interface import implementer
from datetime import date from datetime import date
from cybertools.organize.interfaces import IPerson, IAddress from cybertools.organize.interfaces import IPerson, IAddress
@implementer(IPerson)
class Person(object): class Person(object):
implements(IPerson)
def __init__(self, lastName, firstName=u'', birthDate=None): def __init__(self, lastName, firstName=u'', birthDate=None):
self.lastName = lastName self.lastName = lastName
self.firstName = firstName self.firstName = firstName
@ -55,10 +35,9 @@ class Person(object):
return int((dt - date(bd.year, bd.month, bd.day)).days/365.25) return int((dt - date(bd.year, bd.month, bd.day)).days/365.25)
@implementer(IAddress)
class Address(object): class Address(object):
implements(IAddress)
def __init__(self, city, street=u'', lines=[], def __init__(self, city, street=u'', lines=[],
zipcode=None, country=None): zipcode=None, country=None):
self.lines = lines # a sequence of additional address lines self.lines = lines # a sequence of additional address lines

View file

@ -1,25 +1,6 @@
# # cybertools.organize.service
# Copyright (c) 2011 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
""" """ Service management classes.
Service management classes.
$Id$
""" """
from time import time from time import time
@ -28,7 +9,7 @@ from BTrees.OOBTree import OOBTree
from zope.cachedescriptors.property import Lazy from zope.cachedescriptors.property import Lazy
from zope.component import adapts from zope.component import adapts
from zope import component from zope import component
from zope.interface import implements, Interface from zope.interface import implementer, Interface
from cybertools.composer.interfaces import IInstance from cybertools.composer.interfaces import IInstance
from cybertools.composer.message.base import MessageManager from cybertools.composer.message.base import MessageManager
@ -50,10 +31,9 @@ from cybertools.organize.interfaces import IRegistration, IRegistrationTemplate
from cybertools.organize.interfaces import IClientRegistrations from cybertools.organize.interfaces import IClientRegistrations
@implementer(IServiceManager)
class ServiceManager(ClientManager): class ServiceManager(ClientManager):
implements(IServiceManager)
servicesFactory = Jeep servicesFactory = Jeep
services = None services = None
@ -69,10 +49,9 @@ class ServiceManager(ClientManager):
return self.services return self.services
@implementer(IRegistration)
class Registration(object): class Registration(object):
implements(IRegistration)
number = 1 number = 1
numberWaiting = 0 numberWaiting = 0
@ -89,10 +68,9 @@ class PersistentRegistration(Registration, Persistent):
pass pass
@implementer(IService)
class Service(object): class Service(object):
implements(IService)
registrationsFactory = OOBTree registrationsFactory = OOBTree
registrationFactory = PersistentRegistration registrationFactory = PersistentRegistration
subservicesFactory = Jeep subservicesFactory = Jeep
@ -234,10 +212,9 @@ class Service(object):
return getattr(self.getManager(), 'allowDirectRegistration', None) return getattr(self.getManager(), 'allowDirectRegistration', None)
@implementer(IScheduledService)
class ScheduledService(Service): class ScheduledService(Service):
implements(IScheduledService)
start = end = None start = end = None
# default methods # default methods
@ -247,10 +224,9 @@ class ScheduledService(Service):
return getattr(self.getManager(), 'end', None) return getattr(self.getManager(), 'end', None)
@implementer(IServiceCollection)
class ServiceCollection(ScheduledService): class ServiceCollection(ScheduledService):
implements(IServiceCollection)
assignmentsFactory = set assignmentsFactory = set
assignments = None assignments = None
@ -273,10 +249,9 @@ class ServiceCollection(ScheduledService):
# registration stuff # registration stuff
@implementer(IRegistrationTemplate)
class RegistrationTemplate(object): class RegistrationTemplate(object):
implements(IRegistrationTemplate)
def __init__(self, name=None, manager=None): def __init__(self, name=None, manager=None):
self.name = self.__name__ = name self.name = self.__name__ = name
self.manager = self.__parent__ = manager self.manager = self.__parent__ = manager
@ -298,9 +273,9 @@ class RegistrationTemplate(object):
return self.manager return self.manager
@implementer(IClientRegistrations)
class ClientRegistrations(object): class ClientRegistrations(object):
implements(IClientRegistrations)
adapts(IClient) adapts(IClient)
template = None template = None

View file

@ -2,8 +2,6 @@
Service Manager Service Manager
================ ================
($Id$)
This package does not provide functionality on its own but shows only This package does not provide functionality on its own but shows only
how to integrate other packages into an application package. how to integrate other packages into an application package.
@ -111,15 +109,16 @@ Using schema views for displaying and editing data
We need some additional setup for working with schema views - so we have to We need some additional setup for working with schema views - so we have to
supply some session handling stuff in order to work with client names. supply some session handling stuff in order to work with client names.
>>> from zope.interface import implements >>> from zope.interface import implementer
>>> from zope.app.session.interfaces import IClientIdManager, ISessionDataContainer >>> from zope.session.interfaces import IClientIdManager, ISessionDataContainer
>>> from zope.app.session import session >>> from zope.session import session
>>> component.provideAdapter(session.ClientId) >>> component.provideAdapter(session.ClientId)
>>> component.provideAdapter(session.Session) >>> component.provideAdapter(session.Session)
>>> component.provideUtility(session.RAMSessionDataContainer(), ISessionDataContainer) >>> component.provideUtility(session.RAMSessionDataContainer(), ISessionDataContainer)
>>> class ClientIdManager(object): >>> class ClientIdManager(object):
... implements(IClientIdManager) ... implements(IClientIdManager)
... def getClientId(self, request): return 'dummy' ... def getClientId(self, request): return 'dummy'
>>> ClientIdManager = implementer(IClientIdManager)(ClientIdManager)
>>> component.provideUtility(ClientIdManager()) >>> component.provideUtility(ClientIdManager())
>>> from zope.publisher.browser import TestRequest >>> from zope.publisher.browser import TestRequest
@ -329,7 +328,7 @@ registered for them.
>>> for svc in workshop.getServices(): >>> for svc in workshop.getServices():
... for cn, reg in sorted(svc.registrations.items()): ... for cn, reg in sorted(svc.registrations.items()):
... print 'client-%i: ' % (clientNames.index(cn)+1), reg.service.name ... print('client-%i: ' % (clientNames.index(cn)+1), reg.service.name)
client-1: event1 client-1: event1
client-3: event2 client-3: event2
@ -492,7 +491,7 @@ allows a hierarchical presentation.
>>> overview = wsView.overview() >>> overview = wsView.overview()
>>> for line in overview: >>> for line in overview:
... print line['title'], line['isHeadline'], line['level'] ... print(line['title'], line['isHeadline'], line['level'])
Event True 0 Event True 0
Event 1 False 1 Event 1 False 1
Event 2 False 1 Event 2 False 1
@ -516,9 +515,9 @@ and registration data.
>>> regInfo = srvView.getRegistrationInfo(reg) >>> regInfo = srvView.getRegistrationInfo(reg)
>>> clientInfo = srvView.getDataForClient(reg) >>> clientInfo = srvView.getDataForClient(reg)
>>> print srvView.formatClientInfo(clientInfo) >>> print(srvView.formatClientInfo(clientInfo))
Skywalker Skywalker
>>> print regInfo['number'], regInfo['stateTitle'] >>> print(regInfo['number'], regInfo['stateTitle'])
1 temporary 1 temporary
The service view also provides fields that sum up the numbers of all The service view also provides fields that sum up the numbers of all
@ -636,7 +635,7 @@ possible.
False False
>>> for reg in sorted(event1.registrations.values(), key=lambda x: x.number): >>> for reg in sorted(event1.registrations.values(), key=lambda x: x.number):
... print reg.number, reg.numberWaiting ... print(reg.number, reg.numberWaiting)
0 3 0 3
1 0 1 0
@ -659,7 +658,7 @@ What happens if one of the participants cancels her registration?
>>> regView.update() >>> regView.update()
False False
>>> for reg in sorted(event1.registrations.values(), key=lambda x: x.number): >>> for reg in sorted(event1.registrations.values(), key=lambda x: x.number):
... print reg.number, reg.numberWaiting ... print(reg.number, reg.numberWaiting)
0 3 0 3
As the participants on the waiting list get priority over newly registering As the participants on the waiting list get priority over newly registering
@ -674,7 +673,7 @@ people on the waiting list.
>>> regView.update() >>> regView.update()
False False
>>> for reg in sorted(event1.registrations.values(), key=lambda x: x.numberWaiting): >>> for reg in sorted(event1.registrations.values(), key=lambda x: x.numberWaiting):
... print reg.number, reg.numberWaiting ... print(reg.number, reg.numberWaiting)
0 2 0 2
0 3 0 3
@ -686,7 +685,7 @@ free place.
>>> regView.update() >>> regView.update()
False False
>>> for reg in sorted(event1.registrations.values(), key=lambda x: x.number): >>> for reg in sorted(event1.registrations.values(), key=lambda x: x.number):
... print reg.number, reg.numberWaiting ... print(reg.number, reg.numberWaiting)
0 2 0 2
1 2 1 2
@ -705,18 +704,18 @@ Excel Export
>>> from cybertools.organize.browser.report import RegistrationsExportCsv >>> from cybertools.organize.browser.report import RegistrationsExportCsv
>>> input = dict(get_data_method='getData') >>> input = dict(get_data_method='getData')
>>> csv = RegistrationsExportCsv(workshop, TestRequest(form=input)) >>> csv = RegistrationsExportCsv(workshop, TestRequest(form=input))
>>> print csv.render() >>> print(csv.render())
"Service","Client ID","Organization","First Name","Last Name","E-Mail","Number","State" "Service","Client ID","Organization","First Name","Last Name","E-Mail","Number","State"
"Event 1","...","","Walker","","john@walker.tv",1,"submitted" "Event 1","...","","Walker","","john@walker.tv",1,"submitted"
>>> input = dict(get_data_method='getAllDataInColumns') >>> input = dict(get_data_method='getAllDataInColumns')
>>> csv = RegistrationsExportCsv(workshop, TestRequest(form=input)) >>> csv = RegistrationsExportCsv(workshop, TestRequest(form=input))
>>> result = csv.render().splitlines() >>> result = csv.render().splitlines()
>>> print result[0] >>> print(result[0])
"Client ID","Time Stamp","Last Name","First Name","Email Address","Age","Personal Address","Academic Titles","Street","City","Country","Event 1","WL Event 1","Event 2","WL Event 2" "Client ID","Time Stamp","Last Name","First Name","Email Address","Age","Personal Address","Academic Titles","Street","City","Country","Event 1","WL Event 1","Event 2","WL Event 2"
>>> len(result) >>> len(result)
2 2
>>> print [f.strip('"') for f in result[1].split(',')[1:]] >>> print([f.strip('"') for f in result[1].split(',')[1:]])
['...', 'Walker', 'John', 'john@walker.tv', '', 'Mr', '', '', '', '', '1', '2', '0', '0'] ['...', 'Walker', 'John', 'john@walker.tv', '', 'Mr', '', '', '', '', '1', '2', '0', '0']

View file

@ -1,34 +1,16 @@
# # cybertools.organize.task
# Copyright (c) 2008 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
""" """ Task management classes.
Task management classes.
$Id$
""" """
from zope.component import adapts from zope.component import adapts
from zope.interface import implements from zope.interface import implementer
from cybertools.organize.interfaces import ITask from cybertools.organize.interfaces import ITask
@implementer(ITask)
class Task(object): class Task(object):
implements(ITask) pass

View file

@ -1,28 +1,11 @@
# # cybertools.organize.work
# Copyright (c) 2018 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
""" """ Planning and recording activities (work items).
Planning and recording activities (work items).
""" """
from zope import component from zope import component
from zope.component import adapts from zope.component import adapts
from zope.interface import implementer, implements from zope.interface import implementer
from zope.traversing.api import getName, getParent from zope.traversing.api import getName, getParent
from cybertools.organize.interfaces import IWorkItem, IWorkItems from cybertools.organize.interfaces import IWorkItem, IWorkItems
@ -171,12 +154,11 @@ workItemTypes = Jeep((
)) ))
@implementer(IWorkItem)
class WorkItem(Stateful, Track): class WorkItem(Stateful, Track):
""" A work item that may be stored as a track in a tracking storage. """ A work item that may be stored as a track in a tracking storage.
""" """
implements(IWorkItem)
metadata_attributes = Track.metadata_attributes + ('state',) metadata_attributes = Track.metadata_attributes + ('state',)
index_attributes = metadata_attributes index_attributes = metadata_attributes
typeName = 'WorkItem' typeName = 'WorkItem'
@ -423,11 +405,11 @@ class WorkItem(Stateful, Track):
getParent(self).indexTrack(None, self, idx) getParent(self).indexTrack(None, self, idx)
@implementer(IWorkItems)
class WorkItems(object): class WorkItems(object):
""" A tracking storage adapter managing work items. """ A tracking storage adapter managing work items.
""" """
implements(IWorkItems)
adapts(ITrackingStorage) adapts(ITrackingStorage)
def __init__(self, context): def __init__(self, context):

View file

@ -1,23 +1,6 @@
# # cybertools.stateful.base
# Copyright (c) 2020 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
""" """ Basic implementations for stateful objects and adapters.
Basic implementations for stateful objects and adapters.
""" """
from persistent.interfaces import IPersistent from persistent.interfaces import IPersistent
@ -26,17 +9,16 @@ from zope import component
from zope.component import adapts from zope.component import adapts
from zope.interface.interfaces import ObjectEvent from zope.interface.interfaces import ObjectEvent
from zope.event import notify from zope.event import notify
from zope.interface import implements from zope.interface import implementer
from cybertools.stateful.definition import statesDefinitions from cybertools.stateful.definition import statesDefinitions
from cybertools.stateful.interfaces import IStateful, IStatefulIndexInfo from cybertools.stateful.interfaces import IStateful, IStatefulIndexInfo
from cybertools.stateful.interfaces import ITransitionEvent from cybertools.stateful.interfaces import ITransitionEvent
@implementer(IStateful)
class Stateful(object): class Stateful(object):
implements(IStateful)
statesDefinition = 'default' statesDefinition = 'default'
state = None state = None
@ -54,7 +36,7 @@ class Stateful(object):
def doTransition(self, transition, historyInfo=None): def doTransition(self, transition, historyInfo=None):
sd = self.getStatesDefinition() sd = self.getStatesDefinition()
previousState = self.getState() previousState = self.getState()
if isinstance(transition, basestring): if isinstance(transition, str):
sd.doTransitionFor(self, transition) sd.doTransitionFor(self, transition)
self.notify(transition, previousState) self.notify(transition, previousState)
return return
@ -127,10 +109,9 @@ class StatefulAdapter(Stateful):
notify(TransitionEvent(self.context, transObject, previousState, self.request)) notify(TransitionEvent(self.context, transObject, previousState, self.request))
@implementer(IStatefulIndexInfo)
class IndexInfo(object): class IndexInfo(object):
implements(IStatefulIndexInfo)
availableStatesDefinitions = [] # to be overwritten by subclass! availableStatesDefinitions = [] # to be overwritten by subclass!
def __init__(self, context): def __init__(self, context):
@ -145,10 +126,9 @@ class IndexInfo(object):
# event # event
@implementer(ITransitionEvent)
class TransitionEvent(ObjectEvent): class TransitionEvent(ObjectEvent):
implements(ITransitionEvent)
def __init__(self, obj, transition, previousState, request=None): def __init__(self, obj, transition, previousState, request=None):
super(TransitionEvent, self).__init__(obj) super(TransitionEvent, self).__init__(obj)
self.transition = transition self.transition = transition

View file

@ -1,36 +1,18 @@
# # cybertools.stateful.definition
# Copyright (c) 2013 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
""" """ State definition implementation.
State definition implementation.
""" """
from zope.interface import implements from zope.interface import implementer
from cybertools.util.jeep import Jeep from cybertools.util.jeep import Jeep
from cybertools.stateful.interfaces import IState, IAction, ITransition from cybertools.stateful.interfaces import IState, IAction, ITransition
from cybertools.stateful.interfaces import IStatesDefinition from cybertools.stateful.interfaces import IStatesDefinition
@implementer(IState)
class State(object): class State(object):
implements(IState)
setSecurity = lambda self, context: None setSecurity = lambda self, context: None
icon = None icon = None
color = 'blue' color = 'blue'
@ -48,10 +30,9 @@ class State(object):
return 'cybertools.icons/' + (self.icon or 'led%s.png' % self.color) return 'cybertools.icons/' + (self.icon or 'led%s.png' % self.color)
@implementer(IAction)
class Action(object): class Action(object):
implements(IAction)
allowed = True allowed = True
permission = None permission = None
roles = [] roles = []
@ -67,19 +48,17 @@ class Action(object):
setattr(self, k, v) setattr(self, k, v)
@implementer(ITransition)
class Transition(Action): class Transition(Action):
implements(ITransition)
def __init__(self, name, title, targetState, **kw): def __init__(self, name, title, targetState, **kw):
super(Transition, self).__init__(name, title, **kw) super(Transition, self).__init__(name, title, **kw)
self.targetState = targetState self.targetState = targetState
@implementer(IStatesDefinition)
class StatesDefinition(object): class StatesDefinition(object):
implements(IStatesDefinition)
initialState = 'started' initialState = 'started'
msgFactory = None msgFactory = None

View file

@ -60,9 +60,9 @@ def formatNumber(num, type='decimal', lang='de',
def toStr(value, encoding='UTF-8'): def toStr(value, encoding='UTF-8'):
if isinstance(value, unicode): if isinstance(value, str):
return value.encode(encoding) return value.encode(encoding)
return str(value) return bytes(value)
def toUnicode(value, encoding='UTF-8', fallback='ISO8859-15'): def toUnicode(value, encoding='UTF-8', fallback='ISO8859-15'):
# or: fallback='CP852' # or: fallback='CP852'

View file

@ -32,6 +32,8 @@ dependencies = [
"zope.index", "zope.index",
"zope.interface", "zope.interface",
"zope.lifecycleevent", "zope.lifecycleevent",
"zope.sendmail",
"zope.session",
"zope.testing", "zope.testing",
] ]