an easy way to construct URL to resource

Issue #3 wontfix
Jan-Wijbrand Kolman
created an issue

There should be an easy way to construct a URL to a resource. This is useful for those resources which are not included automatically in a web page, such as images. A method on NeededInclusions should do the trick.

Comments (4)

  1. Jan-Wijbrand Kolman reporter

    I'm not sure I fully understand the use-case. Would it be something like:

    class NeededInclusions(object):
      ...
      def resource_url(self, resource):
        return self.library_url(resource.library) + resource.relpath
    
  2. faassen

    Well, concerning use cases, imagine you want to create a link to a static image. I believe you guys have that in zope.fanstatic, right?

    I'm trying to come up with an example in my own codebases, and I had one, but it seems I don't need it anymore right now.

  3. Jan-Wijbrand Kolman reporter

    Yes we certainly see use cases now. Another we could imagine is when you want to return a URL to, for example, an icon in some json to the client. In these cases you want to be able to compute the resource URL.

    This issue relates to #41

  4. Jan-Wijbrand Kolman reporter

    Uhm, we were wrong in this regard... the use case was mainly for generating URLs to for example images, icons etc. But these images can not actually be defined as Resource() instances anyway (as there's no inclusion renderer registered for, say, ".jpg" extensions, and there shouldn't be).

    So, we for now get rid of this issue, "won't fix". If you want to compute a URL to something you happen to know is contained in a Library, you can easily do:

    needed = fanstatic.get_needed()
    icon_url = needed.library_url(lib_containing_icon) + '/know/path/to/icon.jpg'
    
  5. Log in to comment