Commit 2722d0a9 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

[ui] Nicer display of concept within relation widget

* the best language is selected
* concepts are properly ordered
* should more performant (one query fetch all the data)
parent 0dba3e2c3a85
......@@ -87,13 +87,52 @@ class ContainedSearchForRelatedEntitiesView(rwdg.SearchForRelatedEntitiesView):
"""Return rset of entities to be displayed as possible values for the
edited relation. You may want to override this.
container = int(self._cw.form['container'])
entity = self.compute_entity()
rtype, tetype, role = self.rdef
rdef = entity.e_schema.rdef(rtype, role, tetype)
assert len(rdef.constraints) == 1 and 'S container AT' in rdef.constraints[0].expression
baserql = rdef.constraints[0].expression
rql = 'Any O WHERE ' + baserql.replace('S container AT', 'AT eid %(at)s')
return self._cw.execute(rql, {'at': int(self._cw.form['container'])})
baserql = baserql.replace('S container AT', 'AT eid %(at)s')
# detect language first
languages = set(lang for lang, in self._cw.execute(
'DISTINCT Any OLC WHERE ' + baserql + ', O preferred_label OL, '
'OL language_code OLC', {'at': container}))
for lang in (self._cw.lang, 'en', 'sed-2'):
if lang in languages:
assert languages, 'no preferred label'
lang = languages.pop()
# now build the query to prefetch/sort on the preferred label in the proper language
return self._cw.execute(
'DISTINCT Any O,OL,OLL ORDERBY OLL WHERE ' + baserql + ', O preferred_label OL, '
'OL label OLL, OL language_code %(lang)s',
{'at': container, 'lang': lang})
def pref_label_label(concept):
return concept.cw_rset[concept.cw_row][2]
def pref_label_column(w, concept):
class SelectConceptEntitiesTableView(rwdg.SelectEntitiesTableView):
"""Table view of the selectable entities in the relation widget
Selection of columns (and respective renderer) can be overridden by
updating `columns` and `column_renderers` class attributes.
__select__ = rwdg.SelectEntitiesTableView.__select__ & is_instance('Concept')
column_renderers = rwdg.SelectEntitiesTableView.column_renderers.copy()
# speed-up things by considering rset shape from ContainedSearchForRelatedEntitiesView
column_renderers['entity'] = rwdg.SelectMainEntityColRenderer(
# hide some relation from autoform because of limitation of _container_eid
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment