Subclassing ImageWidget

2 messages Options
Embed this post
Permalink
Neil Stokes () Subclassing ImageWidget
Reply Threaded More More options
Print post
Permalink
Hi folks,

First of all, I'm new to Plone so please forgive me if I don't express this too well.

I need to do the following:

Display an image on a page along with the supporting information (I have subclassed ATImage to add additional fields/widgets and this works fine).

When the user clicks on the 'Current Image - ...' link below the image, I want to display the image at a different size, depending upon the user's defined role.  Privileged users will see a full size image while others will see a scaled down image.  I have the sizes defined in the ImageField.

One way to do this would be to create a method in my subclassed ATImage class that returns a different-sized image using a test based on user.hasRole() - image_large, image_mini etc.  However, I notice that the image.pt file (in Archetypes/skins/archetypes/widgets) includes a link to the image file's absolute URL so I need to modify this.

A brute force approach would be simply to modify image.pt to call my method but that's a bad idea since it will affect all images.

I can subclass ImageWidget, which is a more elegant approach, and simply specify the new widget for my existing ImageField.  However, I can't see where to define the link between the widget and the page template.  Any pointers would be greatly appreciated.

On the other hand, I may be approaching this from completely the wrong direction, so suggestions on alternative approaches would also be welcome.

Many thanks in advance,

Neil Stokes
Nathan Van Gheem () Re: Subclassing ImageWidget
Reply Threaded More More options
Print post
Permalink
The easiest way to accomplish this I think would be to just create a new view for the Image.  This way you don't need to subclass ATImage or the ImageWidget. 

On Mon, Oct 13, 2008 at 6:17 PM, Neil Stokes <[hidden email]> wrote:

Hi folks,

First of all, I'm new to Plone so please forgive me if I don't express this
too well.

I need to do the following:

Display an image on a page along with the supporting information (I have
subclassed ATImage to add additional fields/widgets and this works fine).

When the user clicks on the 'Current Image - ...' link below the image, I
want to display the image at a different size, depending upon the user's
defined role.  Privileged users will see a full size image while others will
see a scaled down image.  I have the sizes defined in the ImageField.

One way to do this would be to create a method in my subclassed ATImage
class that returns a different-sized image using a test based on
user.hasRole() - image_large, image_mini etc.  However, I notice that the
image.pt file (in Archetypes/skins/archetypes/widgets) includes a link to
the image file's absolute URL so I need to modify this.

A brute force approach would be simply to modify image.pt to call my method
but that's a bad idea since it will affect all images.

I can subclass ImageWidget, which is a more elegant approach, and simply
specify the new widget for my existing ImageField.  However, I can't see
where to define the link between the widget and the page template.  Any
pointers would be greatly appreciated.

On the other hand, I may be approaching this from completely the wrong
direction, so suggestions on alternative approaches would also be welcome.

Many thanks in advance,

Neil Stokes
--
View this message in context: http://n2.nabble.com/Subclassing-ImageWidget-tp1330776p1330776.html
Sent from the Archetypes mailing list archive at Nabble.com.


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Archetypes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/archetypes-users


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Archetypes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/archetypes-users