[PATCH 6 of 8 sherpa V2] [eac] Skip unknown-agent-kind value for AuthorityRecord.agent_kind

Sylvain Thenault sylvain.thenault at logilab.fr
Wed Mar 29 12:07:36 CEST 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1490696686 -7200
#      Tue Mar 28 12:24:46 2017 +0200
# Node ID c2d18668ec69234bf5749a9b5c88b6b6f9bb404f
# Parent  fb07744cb84051c22255354c04f85562e3ee87a0
[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

diff --git a/cubicweb_sherpa/views/__init__.py b/cubicweb_sherpa/views/__init__.py
--- a/cubicweb_sherpa/views/__init__.py
+++ b/cubicweb_sherpa/views/__init__.py
@@ -91,10 +91,21 @@ class SherpaReqRewriter(urlrewrite.Simpl
 
 
 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)
 
     from cubicweb.web.views import actions, bookmark, cwuser


More information about the saem-devel mailing list