Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL
Help

Chapter 4. Extending Faculty/Staff Direc... > Add the fax and publications fields - Pg. 68

Extending Faculty/Staff Directory This line declares that PersonExtender adapts Person to an ISchemaExtender : that is, to something that can return a list of fields to be added to an object. (For the curious, detailed documentation of the ISchemaExtender interface can be found in archetypes.schemaextender 's interfaces.py .) Before adding our fields, we must conform to a convention required of all adapters. When an adapter is instantiated by the underlying framework, its __init__ method (called the constructor) is passed the object being adapted: in our case, a Person. However, we're not really interested in which Person it is; we do exactly the same thing in any case. Thus, we declare a constructor that takes the passed-in Person, stores it away in a member variable, and then forgets about it: 21 22 def __init__(self, context): self.context = context Constructor boilerplate These lines can be left as-is in almost all extenders. (Note that context here is unrelated to the same term used in acquisition--a common point of confusion.) Our claims of functionality made and convention satisfied, we can at last move on to adding fields. Add the fax and publications fields 24 25 def getFields(self): return self._fields Besides the constructor above, a schema extender really requires only one function: getFields , which returns a list of fields to add. The list of fields doesn't live within the getFields method; it comes instead from the _fields attribute of the class. We could have written getFields like this... def getFields(self): return [ _StringExtensionField('mobilePhone', required=False, searchable=True, schemata="Contact Information", widget=StringWidget( label=u"Mobile Phone", description=u"Demo field added by the MobilePhoneExtender product.", ) ) ] [ 68 ]