AttachmentField doesn't update preview with external editor

classic Classic list List threaded Threaded
6 messages Options
Luca Olivetti-4 Luca Olivetti-4
Reply | Threaded
Open this post in threaded view
|

AttachmentField doesn't update preview with external editor

As the subject says, if I modify an AttachmentField with the external
editor, the content of the file is updated but the preview isn't (and I
suppose the index neither is).
This indicates that the AttachmentField set method isn't called (since
it would force an update of both the preview and the index).
I've tried to track what happens but it seems that none of the PUT
methods I located (in Archetypes BaseUnit.py and BaseContent.py[*]) gets
called so I don't know where to look

[*]these are called if a PUT on the whole content type, but
AttachmentField uses as the url the name of the field.

Bye
--
Luca Olivetti
Wetron Automatización S.A. http://www.wetron.es/
Tel. +34 93 5883004      Fax +34 93 5883007


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Plone-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users
Luca Olivetti-4 Luca Olivetti-4
Reply | Threaded
Open this post in threaded view
|

Re: AttachmentField doesn't update preview with external editor

En/na Luca Olivetti ha escrit:

> As the subject says, if I modify an AttachmentField with the external
> editor, the content of the file is updated but the preview isn't (and I
> suppose the index neither is).
> This indicates that the AttachmentField set method isn't called (since
> it would force an update of both the preview and the index).
> I've tried to track what happens but it seems that none of the PUT
> methods I located (in Archetypes BaseUnit.py and BaseContent.py[*]) gets
> called so I don't know where to look
>
> [*]these are called if a PUT on the whole content type, but
> AttachmentField uses as the url the name of the field.

Investigating more I found that the PUT method of OFS.Image is called
directly ?!?!.
Well, instead of calling external_edit on the file field, I tried to
call it on the object (that has a PrimaryFieldMarshaller). This time the
reindexing and the preview worked correctly *but* I lose the original
filename.
I tried to yank most of the method in AttachmentField.py (since it seems
to me they just duplicate what archetypes FileField already does),
everything still seems to work fine but I still cannot manage to
preserve the filename using external_edit :-(

Bye
--
Luca Olivetti
Wetron Automatización S.A. http://www.wetron.es/
Tel. +34 93 5883004      Fax +34 93 5883007


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Plone-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users
Luca Olivetti-4 Luca Olivetti-4
Reply | Threaded
Open this post in threaded view
|

Re: AttachmentField doesn't update preview with external editor

En/na Luca Olivetti ha escrit:

> En/na Luca Olivetti ha escrit:
>
>> As the subject says, if I modify an AttachmentField with the external
>> editor, the content of the file is updated but the preview isn't (and
>> I suppose the index neither is).
>> This indicates that the AttachmentField set method isn't called (since
>> it would force an update of both the preview and the index).
>> I've tried to track what happens but it seems that none of the PUT
>> methods I located (in Archetypes BaseUnit.py and BaseContent.py[*])
>> gets called so I don't know where to look
>>
>> [*]these are called if a PUT on the whole content type, but
>> AttachmentField uses as the url the name of the field.
>
>
> Investigating more I found that the PUT method of OFS.Image is called
> directly ?!?!.
> Well, instead of calling external_edit on the file field, I tried to
> call it on the object (that has a PrimaryFieldMarshaller). This time the
> reindexing and the preview worked correctly *but* I lose the original
> filename.
> I tried to yank most of the method in AttachmentField.py (since it seems
> to me they just duplicate what archetypes FileField already does),
> everything still seems to work fine but I still cannot manage to
> preserve the filename using external_edit :-(
I came up with the attached patch, added an external_edit action to my
type and removed the external_edit from the attachmentfield_widget (by
subclassing AttachmentField and overriding checkExternalEditor).
WDYT?

Bye
--
Luca Olivetti
Wetron Automatización S.A. http://www.wetron.es/
Tel. +34 93 5883004      Fax +34 93 5883007

--- AttachmentField.py.orig 2005-10-03 13:27:55.076217540 +0200
+++ AttachmentField.py 2005-10-19 15:58:42.222982187 +0200
@@ -111,8 +111,8 @@
         else:
             return Field.FileField.download(self, instance, REQUEST, RESPONSE)
 
-    def _process_input(self, value, default=None,
-                       mimetype=None, **kwargs):
+    def _process_input(self, value, file=None, default=None,
+                       mimetype=None, instance=None, filename='', **kwargs):
         # We also need to handle the case where there is a baseUnit
         # for this field containing a valid set of data that would
         # not be reuploaded in a subsequent edit, this is basically
@@ -150,10 +150,18 @@
                 filename = value.filename
             if isinstance(value, FileType) or shasattr(value, 'name'):
                 filename = value.name
+            for v in (filename, repr(value)):
+                 # Windows unnamed temporary file has '<fdopen>' in
+                 # repr() and full path in 'file.name'
+                 if '<fdopen>' in v:
+                     filename = ''
             # Get only last part from a 'c:\\folder\\file.ext'
             filename = filename.split('\\')[-1]
             value.seek(0) # rewind
             value = value.read()
+            #keep original filename
+            if filename=='':
+              filename=self.getFilename(instance)
             if mimetype is None:
                 mimetype, enc = guess_content_type(filename, value, mimetype)
             size = len(value)
Luca Olivetti-4 Luca Olivetti-4
Reply | Threaded
Open this post in threaded view
|

Re: AttachmentField doesn't update preview with external editor

En/na Luca Olivetti ha escrit:

>> Well, instead of calling external_edit on the file field, I tried to
>> call it on the object (that has a PrimaryFieldMarshaller). This time
>> the reindexing and the preview worked correctly *but* I lose the
>> original filename.
>> I tried to yank most of the method in AttachmentField.py (since it
>> seems to me they just duplicate what archetypes FileField already
>> does), everything still seems to work fine but I still cannot manage
>> to preserve the filename using external_edit :-(
>
>
> I came up with the attached patch, added an external_edit action to my
> type and removed the external_edit from the attachmentfield_widget (by
> subclassing AttachmentField and overriding checkExternalEditor).

Well, this solves a problem but it opens another one: ExternalEditor
uses manage_FTPget to get the file data on the object and if the file is
big manage_FTPget (inherited from BaseContent) will write directly to
RESPONSE, with the result that the browser gets the original file
*without* the ExternalEditor header.
I wonder if BaseContent.manage_FTPget is broken or is ExternalEditor
that's broken (more probable since most manage_FTPget I could find do
the same as BaseContent.manage_FTPget) or I'm just plain stupid ;-)
Anyway I added another kludge :-( to the mix by overriding manage_FTPget
to return raw file data to ExternalEditor (not very good for big files).

     security.declareProtected(View, 'manage_FTPget')
     def manage_FTPget(self, REQUEST=None, RESPONSE=None):
         "Get the raw content for this object (also used for the WebDAV
SRC)"
         field = self.getPrimaryField()
         data = str(field.get(self).data)
         if RESPONSE is not None:
             RESPONSE.setHeader('Content-Type', field.getContentType(self))
             RESPONSE.setHeader('Content-Length', len(data))
         return data


Bye
--
Luca Olivetti
Wetron Automatización S.A. http://www.wetron.es/
Tel. +34 93 5883004      Fax +34 93 5883007


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Plone-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users
Luca Olivetti-4 Luca Olivetti-4
Reply | Threaded
Open this post in threaded view
|

Re: AttachmentField doesn't update preview with external editor

In reply to this post by Luca Olivetti-4
En/na Luca Olivetti ha escrit:

> En/na Luca Olivetti ha escrit:
>
>> As the subject says, if I modify an AttachmentField with the external
>> editor, the content of the file is updated but the preview isn't (and
>> I suppose the index neither is).
>> This indicates that the AttachmentField set method isn't called (since
>> it would force an update of both the preview and the index).
>> I've tried to track what happens but it seems that none of the PUT
>> methods I located (in Archetypes BaseUnit.py and BaseContent.py[*])
>> gets called so I don't know where to look
>>
>> [*]these are called if a PUT on the whole content type, but
>> AttachmentField uses as the url the name of the field.
>
>
> Investigating more I found that the PUT method of OFS.Image is called
> directly ?!?!.

That's correct, since FileField.set will create a File object stored as
an attribute of the current object, so that's what traversal will return.
This means that AttachmentField is unusable with external_edit since a
PUT won't trigger a reindexing (it goes directly to OFS.Image)
:-(
That's probably not a problem with a standard file since it isn't
indexed, but maybe AttachmentField or Archetypes should wrap File with a
class that correcty triggers reindex after a PUT?

Bye

PS: Am I the only one seeing this problem?
--
Luca Olivetti
Wetron Automatización S.A. http://www.wetron.es/
Tel. +34 93 5883004      Fax +34 93 5883007


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Plone-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users
Luca Olivetti-4 Luca Olivetti-4
Reply | Threaded
Open this post in threaded view
|

Re: AttachmentField doesn't update preview with external editor

En/na Luca Olivetti ha escrit:

> En/na Luca Olivetti ha escrit:
>
>> En/na Luca Olivetti ha escrit:
>>
>>> As the subject says, if I modify an AttachmentField with the external
>>> editor, the content of the file is updated but the preview isn't (and
>>> I suppose the index neither is).
>>> This indicates that the AttachmentField set method isn't called
>>> (since it would force an update of both the preview and the index).
>>> I've tried to track what happens but it seems that none of the PUT
>>> methods I located (in Archetypes BaseUnit.py and BaseContent.py[*])
>>> gets called so I don't know where to look
>>>
>>> [*]these are called if a PUT on the whole content type, but
>>> AttachmentField uses as the url the name of the field.
>>
>>
>>
>> Investigating more I found that the PUT method of OFS.Image is called
>> directly ?!?!.
>
>
> That's correct, since FileField.set will create a File object stored as
> an attribute of the current object, so that's what traversal will return.
> This means that AttachmentField is unusable with external_edit since a
> PUT won't trigger a reindexing (it goes directly to OFS.Image)
> :-(
> That's probably not a problem with a standard file since it isn't
> indexed, but maybe AttachmentField or Archetypes should wrap File with a
> class that correcty triggers reindex after a PUT?
>
> Bye
>
> PS: Am I the only one seeing this problem?

Here again, speaking to myself ;-)

class AttachmentFieldFile(File):
    ClassSecurityInfo().declareProtected(ModifyPortalContent, 'PUT')
    def PUT(self, REQUEST, RESPONSE):
      """Overrides PUT in order to reindex the uploaded file"""
      result=File.PUT(self, REQUEST, RESPONSE)
      parent=self.aq_parent
      parent.Schema().get(self.id())._reset(parent)
      parent.reindexObject()
      return result

and then setting the content_class for the field to AttachmentFieldFile
instead of File.
Too hackish/unclean/whatever?

Bye
--
Luca Olivetti
Wetron Automatización S.A. http://www.wetron.es/
Tel. +34 93 5883004      Fax +34 93 5883007


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Plone-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users