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

[ui] Most of the relation widget configuration code moved as a generic...

[ui] Most of the relation widget configuration code moved as a generic implementation in the skos cube

Closes #14157219
parent a68075226224
......@@ -73,7 +73,8 @@ affk.set_fields_order('SEDAKeywordReference', ['user_cardinality',
affk.tag_subject_of(('SEDALanguage', 'seda_language_to', '*'), {'widget': RelationFacetWidget})
affk.tag_subject_of(('SEDALanguage', 'seda_language_to', '*'),
{'widget': RelationFacetWidget})
affk.tag_subject_of(('SEDADescriptionLanguage', 'seda_description_language_to', '*'),
{'widget': RelationFacetWidget})
......@@ -24,6 +24,7 @@ from cubicweb.predicates import match_form_params, is_instance
from cubicweb.web.views import uicfg, tabs
from cubes.relationwidget import views as rwdg
from cubes.skos.views import widgets as skos
from cubes.seda.xsd2yams import RDEF_CONSTRAINTS
from cubes.seda.views import rtags_from_xsd_element, add_subobject_link, parent_and_container
......@@ -40,6 +41,7 @@ affk = uicfg.autoform_field_kwargs
class ContainedRelationFacetWidget(rwdg.RelationFacetWidget):
def _render_triggers(self, w, domid, form, field, rtype):
parent, container = parent_and_container(form.edited_entity)
req = form._cw
......@@ -78,62 +80,16 @@ class ContainedRelationFacetWidget(rwdg.RelationFacetWidget):
return super(ContainedRelationFacetWidget, self).trigger_search_url(entity, url_params)
class ContainedSearchForRelatedEntitiesView(rwdg.SearchForRelatedEntitiesView):
__select__ = rwdg.SearchForRelatedEntitiesView.__select__ & match_form_params('container')
has_creation_form = False
class ContainedSearchForRelatedEntitiesView(skos.SearchForRelatedConceptsView):
__select__ = skos.SearchForRelatedConceptsView.__select__ & match_form_params('container')
def linkable_rset(self):
"""Return rset of entities to be displayed as possible values for the
edited relation. You may want to override this.
def constrained_rql(self):
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
constraints = self.schema_rdef.constraints
assert len(constraints) == 1 and 'S container AT' in constraints[0].expression, constraints
baserql = constraints[0].expression
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:
if not languages:
return self._cw.empty_rset()
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(
return baserql, {'at': container}
# hide some relation from autoform because of limitation of _container_eid
Supports Markdown
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