I have created TTW two types of dexterity content and would like to be able to multi select elements of one type in the elements of the other type.
For instance:
1.- My first dexterity is Room and my second dexterity is Book.
2.- I have created several rooms and several books.
3.- In each room I would like to be able to select one or more of the existing books.
I understand that this option requires exporting the content type dexterity Room and adding the codes manually, in its file system. Correct? (so far I have always worked with dexterity TTW).
The above code is OK for Managers and Site Administrators.
But not for other users: if one related book is not published, they can't view the room (login request for not logged users and insufficient privileges error for logged users).
I can "solve" this problem with a huge block of code:
Are you using a TTW page template? I think the template registered via a ZCML declaration (optionally together with a Python class) shouldn't hit this problem. Basically Browser Views. Views โ Plone Documentation v5.2
Achieved, although I have to specify the .pt template name in configure.zcml (if I don't, I just get <Products.Five.metaclass.ActividadView object at 0x7ffad195b510> results).
displays all related items to all visitors, even if there are private related items.
It is an improvement, but I think I will continue to use the long code that does not show the private related items to those who do not have permission to see them.
Now I will study how to add the fields programmatically and how to automatically set the views to the content types ...
If a book has been selected as a related item in multiple rooms, how could I automatically show this on book page? (that the book page shows, linked, the rooms in which it has been selected)
The following doesn't work for me (the search shows all rooms, not just those related to the particular book): tal:define="rooms python:context.portal_catalog.searchResults(portal_type='my_room', related_books=('book1'))"
And also I have not been able to set a condition based on the Relation List (see ?????????):
<tal:roomsitem tal:repeat="roomsitem rooms">
<p>
<a tal:define="book_id context/id;room_related_books ?????????" tal:condition="python:book_id in room_related_books"
href=""
tal:attributes="href roomsitem/getURL; title roomsitem/Description"
tal:content="roomsitem/Title">Room</a>
</p>
</tal:roomsitem>
Let's assume that you have the Room which defines that it can relate to multiple Books. This would be the "forward relationship". The Book automatically gets a "backward relationship" to the Room that links it. I think it would be backrelations(obj, attribute=None, as_dict=False)
from the collective.relationhelpers ยท PyPI and it would probably be called like rooms = backrelations(my_context_book, 'books_or_whatever_the_relation_name_is')
I have been searching for "Plone backrelation" for several days and I had not found anything that could serve as a reference on what the code to include in the template of my books should be like.
About your code:
1.- Would I need to create a add-on with plonecli or could it be TTW in some way (creating some kind of file in the ZMI and calling it from the books template)?
2.- If I need to create a add-on with plonecli:
2.1.- In which file should the get_relateditems code be added?
2.2.- Could it be customized so that it only shows the related items of my RelationList?
2.3.- Would the Room and Book content types also have to be created with plonecli in the plugin or could be created TTW? And the templates?