=======================
 Exporting person data
=======================

The addressbook can export the data of persons using its export
plug-ins.

Setup
=====

At first we have to create an addressbook, some keywords and some persons:

>>> from icemac.addressbook.testing import (
...     create_addressbook, create_person, create_postal_address, 
...     create_phone_number, create_email_address, create_home_page_address,
...     create_keyword)
>>> import zope.app.component.hooks
>>> import gocept.country.db
>>> import datetime 
>>> addressbook = create_addressbook()

>>> church = create_keyword(addressbook, u'church')
>>> family = create_keyword(addressbook, u'family')

>>> liebig = create_person(
...     addressbook, addressbook, u'Liebig', first_name=u'B.', sex=u'male', birth_date=datetime.date(1980, 4, 21))
>>> zope.app.component.hooks.setSite(addressbook)
>>> liebig.keywords = set([church, family])
>>> create_postal_address(
...     addressbook, liebig, zip=u'06333', city=u'Testhausen', 
...     street=u'A-Street 1a', state=gocept.country.db.Subdivision('DE-ST'))
<icemac.addressbook.address.PostalAddress object at 0x...>
>>> create_email_address(
...     addressbook, liebig, kind=u'private', email=u'b.liebig@example.com')
<icemac.addressbook.address.EMailAddress object at 0x...>
>>> create_phone_number(
...     addressbook, liebig, kind=u'private phone', number=u'01234-5678-90')
<icemac.addressbook.address.PhoneNumber object at 0x...>
>>> create_home_page_address(
...     addressbook, liebig, kind=u'work', url='http://www.example.org')
<icemac.addressbook.address.HomePageAddress object at 0x...>

>>> howitz = create_person(
...     addressbook, addressbook, u'Howitz', first_name=u'Michael', sex=u'male')
>>> create_postal_address(
...     addressbook, howitz, zip=u'06333', city=u'Hettstedt', 
...     street=u'Eine-Straße 99x')
<icemac.addressbook.address.PostalAddress object at 0x...>

XLS defaults export
===================

This exporter exports personal data, and the defaults values of the
person contents as an XLS file:

>>> from icemac.addressbook.export.xls.simple import DefaultsExport
>>> import xlrd
>>> exporter = DefaultsExport()
>>> export = exporter.export(liebig, howitz)
>>> xls_workbook = xlrd.open_workbook(file_contents=export)
>>> xls_workbook.sheet_names()
[u'Address book - Export']
>>> work_sheet_0 = xls_workbook.sheet_by_index(0)
>>> (work_sheet_0.nrows, work_sheet_0.ncols)
(4, 21)
>>> for rx in range(work_sheet_0.nrows):
...     print work_sheet_0.row(rx)
[text:u'Person', empty:'', empty:'', empty:'', empty:'', empty:'', text:u'Postal address', empty:'', empty:'', empty:'', empty:'', empty:'', text:u'E-Mail address', empty:'', empty:'', text:u'Home page address', empty:'', empty:'', text:u'Phone number', empty:'', empty:'']
[text:u'first name', text:u'last name', text:u'birth date', text:u'sex', text:u'keywords', text:u'notes', text:u'street', text:u'city', text:u'zip', text:u'country', text:u'state', text:u'notes', text:u'kind', text:u'e-mail address', text:u'notes', text:u'kind', text:u'URL', text:u'notes', text:u'kind', text:u'number', text:u'notes']
[text:u'B.', text:u'Liebig', xldate:29332.0, text:u'male', text:u'church, family', empty:'', text:u'A-Street 1a', text:u'Testhausen', text:u'06333', text:u'Germany', text:u'Sachsen-Anhalt', empty:'', text:u'private', text:u'b.liebig@example.com', empty:'', text:u'work', text:u'http://www.example.org', empty:'', text:u'private phone', text:u'01234-5678-90', empty:'']
[text:u'Michael', text:u'Howitz', empty:'', text:u'male', empty:'', empty:'', text:u'Eine-Stra\xc3\x9fe 99x', text:u'Hettstedt', text:u'06333', text:u'Germany', empty:'', empty:'', empty:'', empty:'', empty:'', empty:'', empty:'', empty:'', empty:'', empty:'', empty:'']
