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

[ui] Use concept autocomplete widget for Keyword reference

so one may first/only specify the scheme from which the keyword should come

* add an explicit relation from KeywordReference to ConceptScheme
* fix related constraint accordingly (was erroneous)
* update tests
parent 20ae8e69f142
......@@ -54,6 +54,18 @@ class SEDAContent(generated.SEDAContent):
return seda_title.title or self._cw._('<no title specified>')
class SEDAKeywordReference(generated.SEDAKeywordReference):
@property
def scheme(self):
return (self.seda_keyword_reference_to_scheme[0] if self.seda_keyword_reference_to_scheme
else None)
@property
def concept(self):
return self.seda_keyword_reference_to[0] if self.seda_keyword_reference_to else None
class RuleMixIn(object):
@property
......
......@@ -62,6 +62,13 @@ class scheme_entity_type(RelationDefinition):
cardinality = '*?'
class seda_keyword_reference_to_scheme(RelationDefinition):
subject = 'SEDAKeywordReference'
object = 'ConceptScheme'
cardinality = '?*'
inlined = True
class Agent(EntityType):
"""An agent is something that bears some form of responsibility for an
activity taking place, for the existence of an entity, or for another
......
......@@ -1856,7 +1856,7 @@ class keyword_reference_keyword_reference_to(RelationDefinition):
cardinality = '?*'
composite = fulltext_container = None
inlined = True
constraints = [RQLConstraint('O in_scheme CS, CS scheme_relation_type CR, CR name "seda_keyword_reference_to"')]
constraints = [RQLConstraint('O in_scheme CS, S seda_keyword_reference_to_scheme CS')]
@seda_profile_element(cardinalities=['0..1', '1'], default_cardinality='0..1',
annotable=False)
......
......@@ -251,7 +251,6 @@ class SEDAXSDExportFuncTC(XmlTestMixin, CubicWebTC):
with self.admin_access.client_cnx() as cnx:
create = cnx.create_entity
scheme = create('ConceptScheme', title=u'Keyword Types')
map_cs_to_rtype(scheme, 'seda_keyword_reference_to')
some_concept = scheme.add_concept(label=u'md5')
transfer = create('SEDAArchiveTransfer', title=u'test profile',
......@@ -294,11 +293,9 @@ class SEDAXSDExportFuncTC(XmlTestMixin, CubicWebTC):
# content
content = create('SEDAContent', seda_content=unit_alt_seq)
kw = create('SEDAKeyword', user_cardinality=u'0..n', seda_keyword=content)
# kw_type = cnx.execute('Any C LIMIT 1 WHERE C in_scheme S, S scheme_relation_type RT, '
# 'RT name "seda_keyword_type_to"').one()
create('SEDAKeywordType', seda_keyword_type_from=kw) # , seda_keyword_type_to=kw_type)
create('SEDAKeywordType', seda_keyword_type_from=kw)
create('SEDAKeywordReference', seda_keyword_reference_from=kw,
) # seda_keyword_reference_to=some_concept)
seda_keyword_reference_to_scheme=scheme)
create('SEDAKeywordContent', reverse_seda_keyword_content=kw)
history_item = create('SEDACustodialHistoryItem', seda_custodial_history_item=content)
create('SEDAwhen', seda_when=history_item)
......
......@@ -13,7 +13,6 @@
#
# You should have received a copy of the GNU Lesser General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
"""cubicweb-seda views for content of archive units."""
import itertools
......@@ -21,12 +20,24 @@ import itertools
from cubicweb.predicates import is_instance
from cubicweb.web.views import tabs, uicfg
from cubes.seda.views import rtags_from_rtype_role_targets, viewlib
from cubes.seda.views import rtags_from_rtype_role_targets, viewlib, widgets
_ = unicode
pvs = uicfg.primaryview_section
afs = uicfg.autoform_section
affk = uicfg.autoform_field_kwargs
rec = uicfg.reledit_ctrl
afs.tag_subject_of(('SEDAKeywordReference', 'seda_keyword_reference_to_scheme', '*'),
'main', 'attributes')
affk.set_field_kwargs('SEDAKeywordReference', 'seda_keyword_reference_to',
widget=widgets.ConceptAutoCompleteWidget(
slave_name='seda_keyword_reference_to',
master_name='seda_keyword_reference_to_scheme'))
affk.set_fields_order('SEDAKeywordReference', ['user_cardinality',
'seda_keyword_reference_to_scheme',
'seda_keyword_reference_to'])
pvs.tag_subject_of(('SEDAContent', 'seda_description_level', '*'), 'attributes')
afs.tag_subject_of(('SEDAContent', 'seda_description_level', '*'), 'main', 'attributes')
......
......@@ -102,8 +102,6 @@ RDEF_CONSTRAINTS = {
'O in_scheme CS, CS scheme_relation_type CR, CR name "seda_event_type_to"'),
'seda_keyword_type_to': (
'O in_scheme CS, CS scheme_relation_type CR, CR name "seda_keyword_type_to"'),
'seda_keyword_reference_to': (
'O in_scheme CS, CS scheme_relation_type CR, CR name "seda_keyword_reference_to"'),
'seda_archival_agreement_to': (
'O in_scheme CS, CS scheme_relation_type CR, CR name "seda_archival_agreement_to"'),
# - scheme defined according to the relation type and the subject type
......@@ -168,6 +166,9 @@ RDEF_CONSTRAINTS = {
'O in_scheme CS, CACLV seda_storage_rule_code_list_version_from AT, '
'CACLV seda_storage_rule_code_list_version_to CS,'
'S container AT'),
# others
'seda_keyword_reference_to': (
'O in_scheme CS, S seda_keyword_reference_to_scheme CS'),
}
......
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