Hi everybody,

I have several components and now I want to add ImportExport
funcionality to some of them.

So I created a simple interface called IImportExport:

class IImportExport(Interface):

  def importFromFile(filename):
    pass

  def exportToFile(filename):
    pass

Now, all I have to do is write an adapter for each component I want to
make importable/exportable. Piece of cake:

class ImportExportAdapter1(object):
  implements(IImportExport)
  __used_for__ = IMyComponent

 def importFromFile(self, filename):
   pass

 def exportToFile(self, filename):
   pass

and in the zcml:

<adapter
  for=".interfaces.IMyComponent"
  provides=".interfaces.IImportExport"
  factory=".adapters.ImportExportAdapter1"
  />

So far so good.

Now the problem: I have a view for IImportExport objects. It just lets
the user choose a name for the file and execute the import or export
method. I want this view to appears in the ZMI tabs for every object
that has an adapter to IImportExport.

If I use implements(IImportExport) in MyComponent class even when it
does not implements IImportExport directly but trough an adapter I can
see the view for objects of type IMyComponent *but* instead of doing

IImportExport(object).exportFromFile(filename)

I have to write

adapter = zope.component.getAdapter(object, IImportExport)
adapter.exportFromFile(filename)

This is not so bad. The real problem is that I have to modify the
original IMyCompoment component to tell zope it implements IImportExport
even when this is false. The adapter does it, not the compoment. But I
don't know other way to make my view work with my components.

I hope I made myself clear. Best regards.

Lorenzo

_______________________________________________
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users

Reply via email to