Getting Title from UUID in batch template

I have a content type, which stores the UUID of another item ( in a text field).
I did not use relations when I made the content type (since some of the items are added from api).

In the view of the item, I just look it up (in the py file), but now we also want to show them in the 'table listing of all items'.

So, in a loop, al:repeat="item python: view.batch()">:
How should I get the title when I have the UUID ( 3f5d75279a754a3db5d3c0229c0fd97b )

Can / should I get it from the template ( TAL ? ) or by looking them up one by one ( ${python: view.find_it(3f5d75279a754a3db5d3c0229c0fd97b) or a helper view). It will be slow (?)

Alternatively, would it be possible to make an indexer ?

catalog query?

Either upgrade your code to store a relation instead of an UUID, or use one of the existing views that will call uuidToObject for you.

Update: I see that there is a way to get the url (in TAL) from the UID (val = UUID in example below):

<a  tal:condition="val" tal:attributes="href string:${portal_url}/@@redirect-to-uuid/${val}"
1 Like

It is possible to 'look up each', but I assume it might be very slow. (something like this, maybe: UUID is 'val')

<span>Title: ${python: view.uid_title(val)}</span>

def uid_title(self, val):
    if val:
        uid_object =  api.content.get(UID=val) 
        return uid_object.Title()

UPDATE: According to Yuri, probably something like this instead:

    def uid_title(context, uuid):
        catalog = getToolByName(context, 'portal_catalog')
        results = catalog(UID=uuid)
        if results:
            return results[0].Title
            return '' # or None or whatever

using portal catalog is very fast. Don't get the object with the api, it is slower. But if you need to create an url using the uid, you can also use /resolveuid/<UID>.

Can't you just overrride this template as needed, or create a custom my_tabular_view based on it for your content type? If I recall correctly, this already uses batched results. UUID is in your portal catalog, add it to metadata if it isn't already.

Thanks, did not think of that. (UPDATED post above)

In fact, there is also

  <a  tal:attributes="href string:${portal_url}/@@redirect-to-uuid/${val}">

(or just <a href="${portal_url}/@@redirect-to-uuid/${val}"