[Checkins] SVN: grok/trunk/ - added another demo application that
will be used to demonstrate schema
Christian Theune
ct at gocept.com
Thu Oct 19 17:19:13 EDT 2006
Log message for revision 70822:
- added another demo application that will be used to demonstrate schema
driven development in correspondence with an external data source (LDAP)
Changed:
U grok/trunk/TODO.txt
A grok/trunk/addressbook/
A grok/trunk/addressbook/README.txt
A grok/trunk/addressbook/setup.py
A grok/trunk/addressbook/src/
A grok/trunk/addressbook/src/addressbook/
A grok/trunk/addressbook/src/addressbook/__init__.py
A grok/trunk/addressbook/src/addressbook/addressbook.py
A grok/trunk/addressbook/src/addressbook/configure.zcml
U grok/trunk/buildout.cfg
A grok/trunk/grokwiki/README.txt
-=-
Modified: grok/trunk/TODO.txt
===================================================================
--- grok/trunk/TODO.txt 2006-10-19 21:17:52 UTC (rev 70821)
+++ grok/trunk/TODO.txt 2006-10-19 21:19:12 UTC (rev 70822)
@@ -11,6 +11,8 @@
- reference (theuni)
+- Check demo applications for issues with patterns (grok wiki, ldap address
+ book)
Core
====
@@ -40,6 +42,8 @@
* custom templates for forms (make formlib macros available in some form?)
* support nested class 'fields' directly on a view (do we really want this?)
+- provide custom (better looking) template and styles for formlib
+
- error reporting during grokking (provide file/line-number information
on our extrinsically generated errors) (philikon)
Added: grok/trunk/addressbook/README.txt
===================================================================
--- grok/trunk/addressbook/README.txt 2006-10-19 21:17:52 UTC (rev 70821)
+++ grok/trunk/addressbook/README.txt 2006-10-19 21:19:12 UTC (rev 70822)
@@ -0,0 +1,26 @@
+=================
+LDAP address book
+=================
+
+A grok example application that shows how to load and store objects from
+external data sources.
+
+
+Dependencies
+------------
+
+ - Requires python-ldap (no egg available yet)
+
+
+Issues
+------
+
+ - grok.EditForm gives no chance to perform a single update with the data of
+ all forms
+
+ - Container (AddressBook) has to set __parent__ and __name__ for the
+ dynamically created contacts
+
+ - Mapping outside schemata to inside schema is tedious
+
+ - formlib acquires standard ZMI layout
Property changes on: grok/trunk/addressbook/README.txt
___________________________________________________________________
Name: svn:keywords
+ Id Rev Date
Name: svn:eol-style
+ native
Added: grok/trunk/addressbook/setup.py
===================================================================
--- grok/trunk/addressbook/setup.py 2006-10-19 21:17:52 UTC (rev 70821)
+++ grok/trunk/addressbook/setup.py 2006-10-19 21:19:12 UTC (rev 70822)
@@ -0,0 +1,20 @@
+from setuptools import setup, find_packages
+
+setup(
+ name='addressbook',
+ version='0.1',
+ author='Christian Theune',
+ author_email='ct at gocept.com',
+ url='http://svn.gocept.com/grok-applications/addressbook/trunk',
+ description="""\
+Allows to edit addressbook entries of ~inetOrgPerson in LDAP
+""",
+ packages=find_packages('src'),
+ package_dir = {'': 'src'},
+ include_package_data = True,
+ zip_safe=False,
+ license='ZPL',
+
+ install_requires=['setuptools',
+ ],
+)
Property changes on: grok/trunk/addressbook/setup.py
___________________________________________________________________
Name: svn:keywords
+ Id Rev Date
Name: svn:eol-style
+ native
Added: grok/trunk/addressbook/src/addressbook/__init__.py
===================================================================
--- grok/trunk/addressbook/src/addressbook/__init__.py 2006-10-19 21:17:52 UTC (rev 70821)
+++ grok/trunk/addressbook/src/addressbook/__init__.py 2006-10-19 21:19:12 UTC (rev 70822)
@@ -0,0 +1 @@
+#
Property changes on: grok/trunk/addressbook/src/addressbook/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id Rev Date
Name: svn:eol-style
+ native
Added: grok/trunk/addressbook/src/addressbook/addressbook.py
===================================================================
--- grok/trunk/addressbook/src/addressbook/addressbook.py 2006-10-19 21:17:52 UTC (rev 70821)
+++ grok/trunk/addressbook/src/addressbook/addressbook.py 2006-10-19 21:19:12 UTC (rev 70822)
@@ -0,0 +1,137 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""The grok LDAP address book.
+"""
+
+import ldap
+
+from zope import schema
+
+import grok
+
+
+class AddressBook(grok.Model):
+
+ @grok.traverse
+ def getContact(self, name):
+ contact = Contact(name)
+ contact.__parent__ = self
+ contact.__name__ = name
+ return contact
+
+ def listContacts(self):
+ return get_contact_list()
+
+class AddressBookListing(grok.View):
+ grok.context(AddressBook)
+ grok.name("index")
+
+addressbooklisting = grok.PageTemplate("""\
+<html>
+<body>
+<ul>
+ <li tal:repeat="contact context/listContacts">
+ <a tal:attributes="href string:${context/@@absolute_url}/$contact" tal:content="contact">Peter Kummer</a></li>
+</ul>
+</body>
+</html>""")
+
+class Contact(grok.Model):
+
+ class fields:
+ cn = schema.TextLine(title=u"Display name")
+ #displayName = fileAs
+
+ givenName = schema.TextLine(title=u"First name")
+ sn = schema.TextLine(title=u"Last name")
+ initials = schema.TextLine(title=u"Initials")
+
+ # jpegPhoto
+ description = schema.TextLine(title=u"Description")
+
+ title = schema.TextLine(title=u"Title")
+
+ o = schema.TextLine(title=u"Organisation")
+ ou = schema.TextLine(title=u"Organisational Unit")
+ businessRole = schema.TextLine(title=u"Role")
+
+ category = schema.TextLine(title=u"Category")
+
+ mail = schema.TextLine(title=u"Email")
+
+ telephoneNumber = schema.TextLine(title=u"Phone (business)")
+ mobile = schema.TextLine(title=u"Mobiltelefon")
+ facsimileTelephoneNumber = schema.TextLine(title=u"Telefax (business)")
+ homePhone = schema.TextLine(title=u"Phone (private)")
+ otherPhone = schema.TextLine(title=u"Phone (other)")
+
+ note = schema.TextLine(title=u"Note")
+
+ postalAddress = schema.Text(title=u"Address (business)")
+ postalCode = schema.TextLine(title=u"ZIP")
+ street = schema.TextLine(title=u"Street")
+ l = schema.TextLine(title=u"City")
+ st = schema.TextLine(title=u"State")
+
+ homePostalAddress = schema.Text(title=u"Address (private)")
+ otherPostalAddress = schema.Text(title=u"Address (other)")
+
+ labeledURI = schema.TextLine(title=u"Homepage")
+
+ def __init__(self, cname):
+ # Initialize from LDAP data
+ data = get_contact(cname)
+ if data is not None:
+ for field in grok.schema_fields(Contact):
+ field_data = data.get(field.__name__)
+ if not field_data:
+ continue
+ if isinstance(field, schema.TextLine):
+ setattr(self, field.__name__, field_data[0])
+ elif isinstance(field, schema.Text):
+ setattr(self, field.__name__, '\n'.join(field_data))
+ else:
+ raise TypeError, "Invalid schema field type: %r" % field
+
+
+class EditContact(grok.EditForm):
+ grok.context(Contact)
+ grok.name("index")
+
+
+# LDAP helper functions
+
+def get_contact_list():
+ l = ldap.initialize("ldap://uter.whq.gocept.com:389")
+ l.simple_bind_s("cn=admin,dc=gocept,dc=com","asdf")
+ results = l.search_s("ou=Addresses,dc=gocept,dc=com", ldap.SCOPE_SUBTREE, "(objectclass=inetOrgPerson)")
+ if results is None:
+ return []
+ cnames = [unicode(x[1]['cn'][0], 'utf-8') for x in results]
+ cnames.sort()
+ return cnames
+
+def get_contact(cname):
+ l = ldap.initialize("ldap://ldaphost:389")
+ l.simple_bind_s("cn=admin,dc=example,dc=com", "password")
+ results = l.search_s("ou=Addresses,dc=example,dc=com",
+ ldap.SCOPE_SUBTREE,
+ "(&(objectclass=inetOrgPerson)(cn=%s))" % cname)
+ if results:
+ # Get data dictionary
+ data = results[0][1]
+ for key, value in data.items():
+ value = [unicode(v, 'utf-8') for v in value]
+ data[key] = value
+ return data
Property changes on: grok/trunk/addressbook/src/addressbook/addressbook.py
___________________________________________________________________
Name: svn:keywords
+ Id Rev Date
Name: svn:eol-style
+ native
Added: grok/trunk/addressbook/src/addressbook/configure.zcml
===================================================================
--- grok/trunk/addressbook/src/addressbook/configure.zcml 2006-10-19 21:17:52 UTC (rev 70821)
+++ grok/trunk/addressbook/src/addressbook/configure.zcml 2006-10-19 21:19:12 UTC (rev 70822)
@@ -0,0 +1,15 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ xmlns:browser="http://namespaces.zope.org/browser"
+ xmlns:grok="http://namespaces.zope.org/grok"
+ i18n_domain="grok"
+ >
+ <grok:grok package="."/>
+
+ <browser:addMenuItem
+ class=".addressbook.AddressBook"
+ title="Addressbook"
+ description="LDAP Addressbook"
+ permission="zope.ManageContent"
+ />
+</configure>
Property changes on: grok/trunk/addressbook/src/addressbook/configure.zcml
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: grok/trunk/buildout.cfg
===================================================================
--- grok/trunk/buildout.cfg 2006-10-19 21:17:52 UTC (rev 70821)
+++ grok/trunk/buildout.cfg 2006-10-19 21:19:12 UTC (rev 70822)
@@ -1,5 +1,5 @@
[buildout]
-develop = . grokwiki
+develop = . grokwiki addressbook
parts = zope3 data instance test
# find-links = http://download.zope.org/distribution/
@@ -18,15 +18,18 @@
eggs = setuptools
grok
grokwiki
+ addressbook
zcml = *
grok-meta
grokwiki
+ addressbook
[test]
recipe = zc.recipe.testrunner
eggs = grok
grokwiki
+ addressbook
extra-paths = parts/zope3/src
defaults = ['--tests-pattern', '^f?tests$',
'-v'
Added: grok/trunk/grokwiki/README.txt
===================================================================
--- grok/trunk/grokwiki/README.txt 2006-10-19 21:17:52 UTC (rev 70821)
+++ grok/trunk/grokwiki/README.txt 2006-10-19 21:19:12 UTC (rev 70822)
@@ -0,0 +1,9 @@
+=============
+The grok wiki
+=============
+
+The grok wiki is our first demo application, used to demonstrate how grok can
+be used to efficiently write web applications with Zope 3.
+
+It is not so much intended as a tutorial, but as a test bed for ourselves and
+to provide guidance for new users how we are using grok ourselves.
Property changes on: grok/trunk/grokwiki/README.txt
___________________________________________________________________
Name: svn:keywords
+ Id Rev Date
Name: svn:eol-style
+ native
More information about the Checkins
mailing list