Re: automatisches zuweisen eines adapters

Raphael Ritz <[email protected]>
Newsgroups gmane.comp.web.zope.german
Message-ID <[email protected]>
On 2/4/11 8:26 AM, robert rottermann wrote:
> Guete Morge mitenand,
>
> ist es möglich einen Adapter so zu definieren, dass er automatisch mit 
> bestehenden Instanzen der adaptierten Klasse genutzt wird.
>
> Mein Ziel ist es fatsyndication für eine bestehende Site zu nutzen. 
> Nun solten alle bestehenden Folder mit den darin vorhanden Objekten 
> als fedd-sourcen bzw. feed-entries dienen.

Salut Robert,

Kommt drauf an, was Du mit "automatisch" meinst.

Hier ein Beispiel von einer meiner Sites:

<configure
     xmlns="http://namespaces.zope.org/zope"
     xmlns:five="http://namespaces.zope.org/five"
     xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
     i18n_domain="incf.inventory">

<adapter
     for="incf.inventory.content.event.ATEvent"
     provides="Products.basesyndication.interfaces.IFeedEntry"
     factory="incf.inventory.content.feed_entry_adapters.EventFeedEntry"
     />

<adapter
     for="incf.inventory.content.deadline.Deadline"
     provides="Products.basesyndication.interfaces.IFeedEntry"
     factory="incf.inventory.content.feed_entry_adapters.DeadlineFeedEntry"
     />

...

Mit dieser Konfiguration in zcml werden Adapter für content typen
definiert (hier eigene, aber das ist egal), die diese als 'FeedEntry'
passend machen. Die Adapter - das worauf 'factory' zeigt - musst
Du natürlich selber schreiben, und dafür musst Du Dir das IFeedEntry
Interface anschauen, damit du weisst, was das adaptierte Object
anbieten muss. fatsyndication bringt ein paar Adapter mit. Die kannst
Du natürlich als Ausgangspunkt nehmen.

Hier als Beispiel die oben registrierten Adapter (speziefisch für
unsere custom Typen):

## Support base/fatsyndication-based content sharing

from Products.fatsyndication.adapters import DocumentFeedEntry

class EventFeedEntry(DocumentFeedEntry):
     """Event as seen in syndication feeds"""

     def getDescription(self, length=250, ellipsis='...'):
         """City, Country; Start, End; and the first  'length' characters
         from the plain text body"""
         address = self.context.getAddress()
         start = self.context.start()
         end = self.context.end()
         lead_in = "%s, %s; Start: %s, End: %s;\n\n" % 
(address.get('city', ''),
                                                       
address.get('country', ''),
                                                       start,
                                                       end,
                                                       )
         text = self.context.getText(mimetype="text/plain")
         return lead_in + text[:length] + ellipsis

     def getBody(self):
         """The comprehensive event description"""
         return self.context.getText()

     def getTags(self):
         """Compile a list containing event type(s) and research topic(s)"""
         types = self.context.getEventType()
         topics = self.context.getPrimary_topics()
         result = []
         for t in types:
             result.append("Type: %s" % t)
         for t in topics:
             result.append("Topic: %s" % t)
         return result

class DeadlineFeedEntry(DocumentFeedEntry):
     """Deadline as seen in syndication feeds"""

     def getDescription(self):
         """As defined on the content type itself already"""
         return self.context.Description()

     def getBody(self):
         """The comprehensive event description"""
         return self.context.parent().getText()

     def getTags(self):
         """Compile a list containing the event type(s) and research 
topic(s)"""
         types = self.context.parent().getEventType()
         topics = self.context.parent().getPrimary_topic()
         result = []
         for t in types:
             result.append("Type: %s" % t)
         for t in topics:
             result.append("Topic: %s" % t)
         return result


Sobald die Registrierung erfolgt ist, sind die Adapter für alle neuen
und existierenden Instanzen der jeweiligen content typen verfügbar.

Ist es das, was Du meinst?

Gruß aus Stockholm,

     Raphael


>
> wie mach ich das?
>
> danke
> robert
>
>
> _______________________________________________
> zope mailing list
> [email protected]
> https://mail.dzug.org/mailman/listinfo/zope



_______________________________________________
zope mailing list
[email protected]
https://mail.dzug.org/mailman/listinfo/zope
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.