The PEAK Developers' Center   Diff for "ChandlerSharingModel" UserPreferences
 
HelpContents Search Diffs Info Edit Subscribe XML Print View
Ignore changes in the amount of whitespace

Differences between version dated 2006-09-08 14:06:13 and 2007-08-11 11:02:27 (spanning 2 versions)

Deletions are marked like this.
Additions are marked like this.

    @sharing.recordtype("http://schemas.osafoundation.org/pim/contentitem")
    def itemrecord(itsUUID, title, body, createdOn, description, lastModifiedBy):
        """Record type for content items; note lastModifiedBy is a UUID"""
        
 
The above defines a record type with 6 fields, named by the arguments to the function. The string passed to ``recordtype()`` must be a unique URI, and will be used to allow other programs (such as Cosmo) to identify whether a particular record type is known to or understood by it.
 
(Note that any unique URI is acceptable, including URIs of the form "uuid:...". That is, you need not have control of a domain name in order to create your own unique URI, as you can use a UUID to create one.)

        def import_contentitem(self, record):
            self.loadItemByUUID(
                record.itsUUID, pim.ContentItem,
                title = record.title,
                title = record.title,
                body = record.body,
                createdOn = record.createdOn,
                description = record.description,
                lastModifiedBy = self.loadItemByUUID(record.lastModifiedBy)
            )
                
 
        @tag.importer
        def import_tag(self, record):
            self.loadItemByUUID(record.itsUUID, pim.Tag, tagname=record.tagname)

 
The ``loadItemByUUID()`` method shown in the importer examples above is a utility method provided by the ``sharing.Schema`` base class. It takes a UUID, an optional item or annotation class, and keyword arguments for attributes to set. The return value is an item of the specified class, or a plain ``schema.Item`` if no class was specified and the item didn't already exist.
 
If an item with the given UUID already exists, it's returned. If a class was specified, the item's kind is upgraded if necessary. For example, the importer for the ``tag`` recordtype above invokes it like this::
If an item with the given UUID already exists, it's returned. If a class was specified, the item's kind is upgraded if necessary. For example, the importer for the ``tag`` recordtype above invokes it like this::
 
    self.loadItemByUUID(record.itsUUID, pim.Tag, tagname=record.tagname)
 

PythonPowered
ShowText of this page
EditText of this page
FindPage by browsing, title search , text search or an index
Or try one of these actions: AttachFile, DeletePage, LikePages, LocalSiteMap, SpellCheck