plone / plone.api

The Plone API
https://6.docs.plone.org/plone.api
Other
86 stars 53 forks source link

plone.content.get_link #206

Open jaroel opened 9 years ago

jaroel commented 9 years ago

Since I'm linking to a lot of objects, I'd like a helper method and view (ie @@view_link and @@view_url) that returns an chameleon.utils.Markup object or plain html (html=True argument).

This call can be used to create an a tag that:

  1. links to the objects view url
  2. checks View permission (no tag if no View permission, just the title)
  3. set the title attribute by default
  4. allow arbitrary tags

Would be nice:

  1. @@view_link and @@view_url also callable as a view on objects and brains, so in templates I can do or Static title
jaroel commented 9 years ago

Different views can be done like:

  1. get_link(view=None) -> absolute_url
  2. get_link(view='my-view-name') -> ${context/absolute_url}/'my-view-name'

A marker object for the view argument signals the default view. This is the default setting.

def get_link(context, view=_marker, html=False): pass

adamcheasley commented 9 years ago

I don't really see that this is adding much. In the second example, you already have the object and the view name. Why would you not just use absolute url?

mattss commented 9 years ago

I may be misunderstanding your use-case here, but this doesn't sound like it fits with the goals of plone.api (in particular: "...to cover 20% of the tasks any Plone developer does 80% of the time.")

jaroel commented 9 years ago

@adamcheasley the second example is just to be feature complete. Don't really care for that except that I can use the same API everywhere.

@mattss I have to generate 'a' tags and check permissions all the time when I make custom views. I don't like to do that :)

adamcheasley commented 9 years ago

Using the catalog will check permissions for you. It's then not too much trouble to use brain.getURL() to get the equivalent to absolute_url.

mattss commented 9 years ago

@jaroel don't get me wrong - it sounds like a good pattern for your use case, but it's not a common use case in my own experience.

jaroel commented 9 years ago

@adamcheasley True, although I don't always have brains :) @mattss Not a problem - neither is .folder.list_content().

Just let this sink for a bit, we'll check again in a few days :)

jaroel commented 9 years ago

If the object is the default content item of its container, this should return the link to the container.

jaroel commented 9 years ago

I think there's a bit more logic than just ${context/absolute_url}. I'll draft an implementation

jaroel commented 9 years ago

This should probably accept an uuid.

plone.api.content.get_link(uuid='ce380ef0f10a85beb864025928e1819b')