diff --git a/organize/README.txt b/organize/README.txt new file mode 100644 index 0000000..e41506f --- /dev/null +++ b/organize/README.txt @@ -0,0 +1,41 @@ +Organizations: Persons, Institutions, Addresses... +================================================== + +Let's start with a Person: + + >>> from cybertools.organize.party import Person + >>> john = Person(u'Smith') + >>> john.lastName + u'Smith' + >>> john.firstName + u'' + >>> john.birthDate is None + True + >>> john.addresses + {} + +A Person object knows the age of the person: + + >>> john.age + + >>> from datetime import date + >>> john.birthDate = date(1980, 3, 25) + >>> john.age + 26 + + >>> john.firstName = u'John' + >>> john.firstName + u'John' + +Addresses +--------- + +Let's create an address and assign it to a person: + + >>> from contact.address import Address + >>> addr = Address('München'.decode('UTF-8'), + ... 'Bayerstraße 1'.decode('UTF-8')) + >>> john.addresses['standard'] = addr + >>> john.addresses['standard'].street + u'Bayerstra\xdfe 1' + diff --git a/contact/browser/__init__.py b/organize/__init__.py similarity index 100% rename from contact/browser/__init__.py rename to organize/__init__.py diff --git a/organize/browser/__init__.py b/organize/browser/__init__.py new file mode 100644 index 0000000..4bc90fb --- /dev/null +++ b/organize/browser/__init__.py @@ -0,0 +1,4 @@ +""" +$Id$ +""" + diff --git a/contact/interfaces.py b/organize/interfaces.py similarity index 100% rename from contact/interfaces.py rename to organize/interfaces.py diff --git a/contact/__init__.py b/organize/party.py similarity index 84% rename from contact/__init__.py rename to organize/party.py index 33c188a..a17f5c2 100644 --- a/contact/__init__.py +++ b/organize/party.py @@ -23,21 +23,20 @@ as an example for some of the cybertools packages. $Id$ """ -from zope.component import adapts from zope.interface import implements -from cybertools.contact.interfaces import IPerson from datetime import date +from cybertools.organize.interfaces import IPerson class Person(object): implements(IPerson) - def __init__(self, firstName, lastName, birthDate): - self.firstName = firstName + def __init__(self, lastName, firstName=u'', birthDate=None): self.lastName = lastName + self.firstName = firstName self.birthDate = birthDate - self.moreFirstNames = [] + self.moreFirstNames = None self.personalAddress = 'mrs' # or 'mr', 'ms', None (unknown) self.academicTitle = None self.communicationInfos = [] @@ -46,12 +45,15 @@ class Person(object): @property def age(self): - return (date.today() - self.birthDate).days/365.25 + if self.birthDate is None: + return None + return int((date.today() - self.birthDate).days/365.25) class Address(object): - def __init__(self, title, lines, street, zipcode, city, country): + def __init__(self, title, city, lines=[], street=u'', + zipcode=None, country=None): self.title = title self.lines = lines # a sequence of address lines self.street = street diff --git a/organize/task.py b/organize/task.py new file mode 100644 index 0000000..51e21cd --- /dev/null +++ b/organize/task.py @@ -0,0 +1,31 @@ +# +# 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 to be used +as an example for some of the cybertools packages. + +$Id$ +""" + +from zope.component import adapts +from zope.interface import implements + + +class Task(object): + diff --git a/organize/tests.py b/organize/tests.py new file mode 100755 index 0000000..11cceb1 --- /dev/null +++ b/organize/tests.py @@ -0,0 +1,30 @@ +#! /usr/bin/python + +""" +Tests for the 'cybertools.organize' package. + +$Id$ +""" + +import unittest, doctest +from zope.testing.doctestunit import DocFileSuite +from cybertools.organize.party import Person + +class TestParty(unittest.TestCase): + "Basic tests for the party module." + + def testBasicStuff(self): + p = Person('Meier', 'Hans') + self.assertEqual('Hans', p.firstName) + self.assertEqual('Meier', p.lastName) + + +def test_suite(): + flags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS + return unittest.TestSuite(( + unittest.makeSuite(TestParty), + DocFileSuite('README.txt', optionflags=flags), + )) + +if __name__ == '__main__': + unittest.main(defaultTest='test_suite') diff --git a/reporter/README.txt b/reporter/README.txt index ec3a18a..4ded08c 100644 --- a/reporter/README.txt +++ b/reporter/README.txt @@ -18,7 +18,7 @@ A Basic API for Reports and Listings Let's start with the Person class from the example package - we will then provide a listing of persons... - >>> from cybertools.contact import Person + >>> from cybertools.organize.party import Person >>> from cybertools.reporter.example.interfaces import IContactsDataSource >>> from cybertools.reporter.example.contact import Contacts diff --git a/typology/README.txt b/typology/README.txt index dc855fe..53f55a6 100644 --- a/typology/README.txt +++ b/typology/README.txt @@ -16,8 +16,8 @@ object data. Let's start with the Person class from the cybertools.contact package - we will then apply dynamic typing to Person objects: - >>> from cybertools.contact.interfaces import IPerson - >>> from cybertools.contact import Person + >>> from cybertools.organize.interfaces import IPerson + >>> from cybertools.organize.party import Person >>> from datetime import date >>> pdata = ((u'John', u'Smith', '1956-08-01'), diff --git a/typology/example/person.py b/typology/example/person.py index bcf14b9..d882cbb 100644 --- a/typology/example/person.py +++ b/typology/example/person.py @@ -25,7 +25,7 @@ $Id$ from zope.component import adapts from zope.interface import implements -from cybertools.contact.interfaces import IPerson +from cybertools.organize.interfaces import IPerson from cybertools.typology.interfaces import IType, ITypeManager from cybertools.typology.type import BaseType, TypeManager