[ZIZope] Re: [Plone-Users] how to interate ARFilePreview into RichDocument?

Yuri <[email protected]> Wed, 12 Dec 2007 13:52:39 +0100
Newsgroups gmane.comp.web.zope.italian,gmane.comp.web.zope.plone.user
Message-ID <[email protected]>
adam tang wrote:
> Hi Yuri,
>           The  method is very clever that you provided .But I still 
> have trouble when apply it .
> The following is error information:
> ZopeXMLConfigurationError: File 
> "/opt/Plone-2.5.3/zeocluster/client1/Products/ARFilePreview/configure.zcml", 
> line 8.2-10.81
>     ConfigurationError: ('Invalid value for', 'interface', 
> 'ImportError: Module Products.ARFilePreview.interfaces has no global 
> IPreviewAware in .interfaces.IPreviewAware                          
> zope.app.annotation.interfaces.IAttributeAnnotatable')
>
> I am using ARFilePreview 2.1.2 ,plone 2.5.3 and Five 1.4.2.
This error is because you didn't tell to Five that the object has the 
interface and you didn't implemented it, see below.


But unrelated, I had to to it for work, so here a 99% solution :)

Basically, for simple File derived types, you've to do nothing after 
you've installed ARFilepreview.

 Just append @@preview_provider/getPreview to the url, so if your file is

http://mysite.com/files/myfile.pdf

the preview is:

http://mysite.com/files/myfile.pdf/@@preview_provider/getPreview

Maybe there are better ways to deal with it.

Note: appending don't preserve images so the right code to use in the 
file template is:

<div style="position: relative;"
              tal:content="structure here/@@preview_provider/getPreview" />

Back to RD:
By default, arfilepreviews already does it, so in richdocument you've 
just to change the simpleattacchment widget (if using RD 3.0) to use the 
arfilepreview macro instead of the file one the simpleattachmentfield one.

But before you've to tell five to give the preview to the 
attachmentfield (I'm using RD 2):

in the product (i.e. RD) put a configure.zcml (or add the include and 
implements part to the existing one, for example here EEPArticleNG is my 
product):

<configure xmlns="http://namespaces.zope.org/zope"
           xmlns:browser="http://namespaces.zope.org/browser"
           xmlns:five="http://namespaces.zope.org/five">

  <include package="zope.app.annotation" />


  <five:implements 
class="Products.EEPArticleNG.content.attachments.FileAttachment"
              interface=".interfaces.eeparticleng.IPreviewAware
                         
zope.app.annotation.interfaces.IAttributeAnnotatable" /
 >

</configure>

But you've to implement the interface in the product, so add to 
Products/EEPArticleNG/interfaces/eeparticleng.py (where I store my 
interfaces in a very similar way to RD):

from zope.interface import Interface
from zope.app.event.interfaces import IObjectModifiedEvent


class IPreviewAware( Interface ):
    """ marker interface """

class IPreviewable( Interface ):
   
    def hasPreview( ):
        """
        Has the preview
        """
   
    def setPreview( preview):
        """
        Sets the preview
        """
   
    def getPreview( ):
        """
        Get the preview
        """
  
class IPreviewProvider( Interface ):
   
    def hasPreview( ):
        """
        Has the preview
        """
   
    def getPreview( ):
        """
        Get the preview
        """
       
    def updatePreview( ):
        """
        update the preview by retransforming original file and store it
        """
   
    def updateAllPreviews( ):
        """
        update all the previews reachable from the catalog
        """

=======
Note :Maybe adding the interface in the container of the attachments is 
wrong, but works!

 Can someone explain why? (otherwise Five gives this error :


    ZopeXMLConfigurationError: File 
"/path/to//Products/EEPArticleNG/configure.zcml", line 8.2-10.81
    ConfigurationError: ('Invalid value for', 'interface', 'ImportError: 
Module Products.EEPArticleNG.interfaces has no global IPreviewAware in 
.interfaces.IPreviewAware                          
zope.app.annotation.interfaces.IAttributeAnnotatable')

)

=======

then, in my widget, I had just to do:

            <tal:related tal:repeat="item attachments">
                <li tal:define="
                        desc      item/Description;
                        item_type item/portal_type;
                        item_type_class python: 'contenttype-' + 
putils.normalizeString(item_type);
                        item_wf_state       item/review_state|python: 
getInfoFor(item, 'review_state', '');
                        item_wf_state_class python: 'state-' + 
putils.normalizeString(item_wf_state);
                                item_url           item/getURL;">
                    <span tal:attributes="class item_type_class">
                    <a href="" target="_new" class="visualIconPadding"
                        tal:attributes="href  string:${item_url};
                                        title desc;"
                        tal:content="item/pretty_title_or_id">
                        Related Item
                    </a>

<!-- this is the real important part -->
 | <a style="background-image: url(html_converted.gif); 
background-repeat: no-repeat; background-position: left; "  href="" 
class="visualIconPadding"
                        tal:attributes="href  
string:${item_url}/@@preview_provider/getPreview;
                                        title desc;"
                        tal:content="string:${item/pretty_title_or_id} 
as html">
                        Related Item
                    </a>
<!-- end -->
                    </span>
                </li>
            </tal:related>

then clicking on  "myfile.pdf as html" it shows the preview.

====
Note 2: The only problem is the the preview don't give back the images 
generated from the preview, as instead ATFile does, so I'm ccing atreal :)

the broken image url is:

http://mysite.com/bla-bla/myfile.pdf/@@preview_provider/myfile.pdf/@@preview_provider/myfile001.png.

In a ATFile is:
http://mysite.com/myfile.pdf/@@preview_provider/myfile001.png

so if I try:
http://mysite.com/bla-bla/myfile.pdf/@@preview_provider/myfile001.png

I can retrieve the image correctly from the preview of my custom RD.

Is my fault?
====

This shows how interfaces, annotation and other z3 technologies are cool 
and how easy is to put the pieces toghether (mostly). :)

>  
> Thanks a lot.
>  
> 2007/12/11, Yuri <[email protected] <mailto:[email protected]>>:
>
>     adam tang wrote:
>     > Hi all,
>     >              The ARFilePreview is a great product for plone and the
>     > RichDocument also is a great product .We very thank contributors of
>     > the two products.
>     >              Now ,I want to interate ARFilePreview into
>     RichDocument.
>     > In the other word,use the ARFilePreview content type taking
>     place of
>     > Fileattachment of RD. But I have trouble with it.
>     >             I can upload the " ARFilePreview" docs into RD,and also
>     > rename,move ,delete "ARFilePreview" attachment.But the index
>     function
>     > of  " ARFilePreview" is invalid. I don't understand the index
>     > mechanism of " ARFilePreview".So I need some help.
>     >
>     >              Anyone any suggestions will be wellcome!
>
>     well, ARFilePreview 2.2 "extend" the File portal type.
>
>     <configure xmlns="http://namespaces.zope.org/zope"
>               xmlns:browser=" http://namespaces.zope.org/browser"
>               xmlns:five="http://namespaces.zope.org/five">
>
>     <include package=" zope.annotation" />
>
>
>     <five:implements class="Products.ATContentTypes.content.file.ATFile"
>                  interface=".interfaces.IPreviewAware
>
>     zope.annotation.interfaces.IAttributeAnnotatable " />
>
>
>     RD uses AttachmentField, and:
>
>
>     class FileAttachment(ATFile):
>        """A file attachment"""
>        portal_type = meta_type = 'FileAttachment'
>
>     registerType(FileAttachment)
>
>     so all should be there, just use the "pieces" from arpreviewfile
>     templates to display the preview in RD.
>
>     >
>     > --
>     > 三人行必有我师!
>     > There are three men walking together.(Triplicity means
>     > collaboration,innovation,comity THREE AS ONE.)
>     > WebSite buiding Expert: http://315ok.org/
>     >
>     ------------------------------------------------------------------------
>     >
>     >
>     -------------------------------------------------------------------------
>     > SF.Net email is sponsored by:
>     > Check out the new SourceForge.net Marketplace.
>     > It's the best place to buy or sell services for
>     > just about anything Open Source.
>     > http://sourceforge.net/services/buy/index.php
>     >
>     ------------------------------------------------------------------------
>
>     >
>     > _______________________________________________
>     > Plone-Users mailing list
>     > [email protected]
>     <mailto:[email protected]>
>     > https://lists.sourceforge.net/lists/listinfo/plone-users
>     >
>
>
>     -------------------------------------------------------------------------
>     SF.Net email is sponsored by:
>     Check out the new SourceForge.net Marketplace.
>     It's the best place to buy or sell services for
>     just about anything Open Source.
>     http://sourceforge.net/services/buy/index.php
>     _______________________________________________
>     Plone-Users mailing list
>     [email protected]
>     <mailto:[email protected]>
>     https://lists.sourceforge.net/lists/listinfo/plone-users
>     <https://lists.sourceforge.net/lists/listinfo/plone-users>
>
>
>
>
> -- 
> 三人行必有我师!
> There are three men walking together.(Triplicity means 
> collaboration,innovation,comity THREE AS ONE.)
> WebSite building Expert: http://315ok.org/

_______________________________________________
Zope mailing list
[email protected]
http://lists.zope.it/cgi-bin/mailman/listinfo/zope