[Zope3-Users] Problem with @@absolute_url

Greg Baker gbaker at cs.mun.ca
Mon Apr 30 15:56:25 EDT 2007


I have no idea how to get the absolute url of an adapted object, or even if 
its possible.  If you can, please bear with me and I'll try to explain myself 
clearly.

Consider this example (simple object and adapter):

class IStudent:
    """Simple student object"""
    studentNumber = StudentNumber(
        title = _("Student Number"),
        description = _("""The student's ID number."""),
        required = True)

class IStudentPhoto:
    """Adapts Student to IImage"""


The unit tests for my class and adapter passes fine, so I know that doing 
something like the following works...

    photo = StudentPhoto(Student("123456789"))


My problem is that I want to display the photo in a browser but can't figure 
out how.  I created a browser view helper in python, and it seems to work for 
the most part:

class StudentDetails:
    """Helper to return a student photo."""
    def getPhoto(self):
        student = self.context
        return StudentPhoto(student)

In my page template, I can see that the IImage object is being created 
correctly..

<div tal:define="photo view/getPhoto">
    <span tal:content="photo">#</span>
</div>

gives me <zope.app.file.image.Image object at 0xb75c6c6c>.  But to turn this 
object into a URL so that I can put it in an <img> tag is beyond me.  When I 
try to do an @@absolute_url on the photo object I get the error saying 
there's not enough context.

Am I going about this the wrong way?  Is there some other thing I need to be 
doing in order for there to be enough context?

Thanks for any help,
Greg


More information about the Zope3-users mailing list