Allow no value to be selected when some concepts are found
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 20 Oct 2016 00:12:21 +0200
changeset 1894 bd2e39dc44b8
parent 1893 953d38a480d5
child 1895 1d3ccf2d7108
Allow no value to be selected when some concepts are found Before one had to pick a value...
test/test_views.py
views/mgmt_rules.py
--- a/test/test_views.py	Wed Oct 19 23:11:34 2016 +0200
+++ b/test/test_views.py	Thu Oct 20 00:12:21 2016 +0200
@@ -61,9 +61,11 @@
             cnx.commit()
 
             self.assertEqual(_rule_ref_vocabulary(transfer, rule_base.cw_etype),
-                             [(access_concept.label(), text_type(access_concept.eid))])
+                             [('<no value specified>', '__cubicweb_internal_field__'),
+                              (access_concept.label(), text_type(access_concept.eid))])
             self.assertEqual(_rule_ref_vocabulary(transfer, rule_alt.cw_etype),
-                             [(access_concept.label(), text_type(access_concept.eid))])
+                             [('<no value specified>', '__cubicweb_internal_field__'),
+                              (access_concept.label(), text_type(access_concept.eid))])
 
 
 class PermissionsTC(CubicWebTC):
--- a/views/mgmt_rules.py	Wed Oct 19 23:11:34 2016 +0200
+++ b/views/mgmt_rules.py	Thu Oct 20 00:12:21 2016 +0200
@@ -57,8 +57,9 @@
            'CACLV seda_{0}_rule_code_list_version_to CS'.format(rule_type))
     rset = req.execute(rql, {'at': container.eid})
     if rset:
-        return [(concept.label(), text_type(concept.eid))
-                for concept in rset.entities()]
+        return ([(req._('<no value specified>'), INTERNAL_FIELD_VALUE)]
+                + sorted([(concept.label(), text_type(concept.eid))
+                          for concept in rset.entities()]))
     else:
         scheme_relation = 'seda_{0}_rule_code_list_version_from_object'.format(rule_type)
         scheme_relation = req._(scheme_relation)
@@ -67,9 +68,11 @@
 
 
 affk.tag_subject_of(('*', 'seda_ref_non_rule_id_to', '*'),
-                    {'choices': rule_ref_vocabulary})
+                    {'choices': rule_ref_vocabulary,
+                     'sort': False})
 affk.tag_subject_of(('*', 'seda_rule', '*'),
-                    {'choices': rule_ref_vocabulary})
+                    {'choices': rule_ref_vocabulary,
+                     'sort': False})
 
 
 class RuleComplexLinkEntityAttributeView(viewlib.TextEntityAttributeView):