created 'cybertools.organize' package, removed 'cybertools.contact', moved imports (in testing code only) of the latter package to the former one.
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1203 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
		
							parent
							
								
									fa7db29662
								
							
						
					
					
						commit
						32beb7824f
					
				
					 10 changed files with 119 additions and 11 deletions
				
			
		
							
								
								
									
										41
									
								
								organize/README.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								organize/README.txt
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -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'
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										4
									
								
								organize/browser/__init__.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								organize/browser/__init__.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,4 @@
 | 
			
		|||
"""
 | 
			
		||||
$Id$
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
							
								
								
									
										31
									
								
								organize/task.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								organize/task.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -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):
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										30
									
								
								organize/tests.py
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										30
									
								
								organize/tests.py
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -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')
 | 
			
		||||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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'),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue