getImage method inside ATFile

classic Classic list List threaded Threaded
5 messages Options
hvelarde hvelarde
Reply | Threaded
Open this post in threaded view
|

getImage method inside ATFile

can somebody explain me why there is a getImage method on the File
content type?

(Pdb) item
<ATFile at /Plone/my_file.pdf>
(Pdb) item.image
*** AttributeError: image
(Pdb) item.getImage
<bound method ATBlob.getImage of <ATFile at /Plone/my_file.pdf>>
(Pdb) item.getImage()
<plone.app.blob.field.BlobWrapper object at 0x7f9ae0e1c1b8>

is this a bug on plone.app.blob? I don't see were do we get it:

https://github.com/plone/plone.app.blob/blob/master/src/plone/app/blob/field.py

best regards
--
Héctor Velarde



------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
Plone-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-developers

smime.p7s (5K) Download Attachment
David Glick (Plone) David Glick (Plone)
Reply | Threaded
Open this post in threaded view
|

Re: getImage method inside ATFile

On 8/12/13 6:09 PM, Héctor Velarde wrote:

> can somebody explain me why there is a getImage method on the File
> content type?
>
> (Pdb) item
> <ATFile at /Plone/my_file.pdf>
> (Pdb) item.image
> *** AttributeError: image
> (Pdb) item.getImage
> <bound method ATBlob.getImage of <ATFile at /Plone/my_file.pdf>>
> (Pdb) item.getImage()
> <plone.app.blob.field.BlobWrapper object at 0x7f9ae0e1c1b8>
>
> is this a bug on plone.app.blob? I don't see were do we get it:
>
> https://github.com/plone/plone.app.blob/blob/master/src/plone/app/blob/field.py 
>
>
It comes from ImageMixin which is mixed into ATBlob in content.py for
backwards compatibility with ATImage. The blob-based File and Image
types are both actually instances of ATBlob.

If you're looking for a generic way to see if an Archetypes item has an
image, it's probably best to check if there's a field called 'image' in
item.Schema()

David

------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
Plone-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-developers
hvelarde hvelarde
Reply | Threaded
Open this post in threaded view
|

Re: getImage method inside ATFile

On 12/08/13 22:16, David Glick (Plone) wrote:
> If you're looking for a generic way to see if an Archetypes item has an
> image, it's probably best to check if there's a field called 'image' in
> item.Schema()

thanks, David; my use case is the following:

if the object has an image field or a getImage method, do something:

def image_tag(self, item):
     """Return an image tag based on the tile configuration.
     """
     # we look here for an image field or a getImage method in the object
     # if none available, we just return an empty tag
     if not hasattr(item, 'image') and not hasattr(item, 'getImage'):
         return u''
     ...

https://github.com/collective/collective.cover/commit/8afac58653616344442c530fa0894ec89af49f4d#L0R210

but this is obviously wrong, it's late and I'm tired.

(this is your same use case, aclark, in case you're reading this)

thanks!


------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
Plone-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-developers

smime.p7s (5K) Download Attachment
David Glick (Plone) David Glick (Plone)
Reply | Threaded
Open this post in threaded view
|

Re: getImage method inside ATFile

On 8/12/13 6:40 PM, Héctor Velarde wrote:

> On 12/08/13 22:16, David Glick (Plone) wrote:
>> If you're looking for a generic way to see if an Archetypes item has an
>> image, it's probably best to check if there's a field called 'image' in
>> item.Schema()
>
> thanks, David; my use case is the following:
>
> if the object has an image field or a getImage method, do something:
>
> def image_tag(self, item):
>     """Return an image tag based on the tile configuration.
>     """
>     # we look here for an image field or a getImage method in the object
>     # if none available, we just return an empty tag
>     if not hasattr(item, 'image') and not hasattr(item, 'getImage'):
>         return u''
>     ...
>
> https://github.com/collective/collective.cover/commit/8afac58653616344442c530fa0894ec89af49f4d#L0R210 
>
>
> but this is obviously wrong, it's late and I'm tired.
>
> (this is your same use case, aclark, in case you're reading this)
>
Well maybe you can try my suggestion after some sleep. :)

------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
Plone-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-developers
hvelarde hvelarde
Reply | Threaded
Open this post in threaded view
|

Re: getImage method inside ATFile

On 12-08-2013 22:42, David Glick (Plone) wrote:
> Well maybe you can try my suggestion after some sleep. :)

I had some sleep and this is what I finally got:

         if hasattr(obj, 'image'):  # Dexterity
             return True
         elif hasattr(obj, 'Schema'):  # Archetypes
             return 'image' in obj.Schema().keys()
         else:
             return False

it seems to be working, thanks! :-)


------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk
_______________________________________________
Plone-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-developers

smime.p7s (5K) Download Attachment