[eac] Skip unknown-agent-kind value for AuthorityRecord.agent_kind
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 28 Mar 2017 12:24:46 +0200
changeset 229 c2d18668ec69
parent 228 fb07744cb840
child 230 b00c8f906a29
[eac] Skip unknown-agent-kind value for AuthorityRecord.agent_kind This value is useful during eac import but should not be displayed when creating/editing from the web UI. Related to #17066617
cubicweb_sherpa/views/__init__.py
--- a/cubicweb_sherpa/views/__init__.py	Tue Mar 28 12:23:49 2017 +0200
+++ b/cubicweb_sherpa/views/__init__.py	Tue Mar 28 12:24:46 2017 +0200
@@ -93,6 +93,17 @@
 uicfg.autoform_section.tag_subject_of(('CWUser', 'primary_email', '*'), 'main', 'hidden')
 
 
+def authority_record_kind_vocabulary(form, field):
+    """Vocabulary function for AuthorityRecord.kind skipping "unknown" value."""
+    rset = form._cw.execute('Any X, XN WHERE X name XN, X is AgentKind, '
+                            'X name != "unknown-agent-kind"')
+    return [(entity.dc_title(), str(entity.eid)) for entity in rset.entities()]
+
+
+uicfg.autoform_field_kwargs.tag_attribute(('AuthorityRecord', 'agent_kind'),
+                                          {'choices': authority_record_kind_vocabulary})
+
+
 def registration_callback(vreg):
     vreg.register_all(globals().values(), __name__, (IndexView,))
     vreg.register_and_replace(IndexView, startup.IndexView)