[PATCH 5 of 8 seda] [views] Tweak complex keyword form UI

Sylvain Thenault sylvain.thenault at logilab.fr
Thu Mar 16 13:37:42 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1489663043 -3600
#      Thu Mar 16 12:17:23 2017 +0100
# Node ID 382e756b9338a58ff33adcbdb50f2e2b81bb808a
# Parent  7864b0ba1858788cee6580f398d233098bb84b82
[views] Tweak complex keyword form UI

* Display type before term, because its value will modify possible term's
  vocabularies, so it makes sense to display it before

* Force display of type as well as term, it make things (js) simpler and user
  still have the cardinality if he doesn't want to force a type to be set

* Hide the 'add new' link in any cases, else it ends up appearing unwillingly
  while we don't need it at all.

Related to extranet #12351787

diff --git a/cubicweb_seda/views/archiveunit.py b/cubicweb_seda/views/archiveunit.py
--- a/cubicweb_seda/views/archiveunit.py
+++ b/cubicweb_seda/views/archiveunit.py
@@ -20,11 +20,11 @@ from six import text_type
 from logilab.mtconverter import xml_escape
 from logilab.common.registry import objectify_predicate
 from logilab.common.decorators import monkeypatch
 
 from cubicweb import tags, _
-from cubicweb.predicates import is_instance, match_form_params
+from cubicweb.predicates import is_instance, match_form_params, specified_etype_implements
 from cubicweb.view import EntityView
 from cubicweb.web.views import autoform, baseviews, tabs, uicfg
 
 from cubicweb_compound import views as compound
 from cubes.relationwidget import views as rwdg
@@ -94,11 +94,11 @@ def is_simple_keyword(cls, req, rset=Non
     try:
         # first check for unit_type specified in form params
         unit_type = req.form['keyword_type']
         return int(unit_type == 'simple_keyword')
     except KeyError:
-        if not entity.reverse_seda_keyword_reference_from:
+        if entity is not None and not entity.reverse_seda_keyword_reference_from:
             return 1
         return 0
 
 
 @objectify_predicate
@@ -608,24 +608,44 @@ kw_simple_afs = copy_rtag(afs, __name__,
 kw_simple_afs.tag_attribute(('SEDAKeyword', 'keyword_content'), 'main', 'attributes')
 kw_simple_afs.tag_object_of(
     ('*', 'seda_keyword_reference_from', 'SEDAKeyword'),
     'main', 'hidden')
 # but one ordering is enough to rule them all
-affk.set_fields_order('SEDAKeyword', ['keyword_content', ('seda_keyword_reference_from', 'object')])
+affk.set_fields_order('SEDAKeyword', [('seda_keyword_type_from', 'object'),
+                                      'keyword_content',
+                                      ('seda_keyword_reference_from', 'object')])
 
 affk.set_field_kwargs('SEDAKeywordType', 'seda_keyword_type_to',
                       widget=widgets.KeywordTypeMasterWidget(
                           slave_base_name='seda_keyword_reference_to_scheme'))
 
 
 class ComplexKeywordAutomaticEntityForm(autoform.AutomaticEntityForm):
     __select__ = (is_instance('SEDAKeyword') & ~is_simple_keyword())
 
     def should_display_inline_creation_form(self, rschema, existing, card):
-        # 1. force creation of one appraisal/access rule
-        if rschema == 'seda_keyword_reference_from':
+        # force display of type and keyword
+        if not existing and rschema in ('seda_keyword_type_from', 'seda_keyword_reference_from'):
             return True
+        return False
+
+    def should_display_add_new_relation_link(self, rschema, existing, card):
+        return False
+
+
+class ComplexKeywordEditionFormView(autoform.InlineEntityEditionFormView):
+    __select__ = (autoform.InlineEntityEditionFormView.__select__
+                  & is_instance('SEDAKeywordType', 'SEDAKeywordReference')
+                  & ~is_simple_keyword())
+    removejs = None
+
+
+class ComplexKeywordCreationFormView(autoform.InlineEntityCreationFormView):
+    __select__ = (autoform.InlineEntityCreationFormView.__select__
+                  & specified_etype_implements('SEDAKeywordType', 'SEDAKeywordReference')
+                  & ~is_simple_keyword())
+    removejs = None
 
 
 # relations tab ################################################################
 
 class ArchiveUnitRelationsTab(ArchiveUnitContentTab):


More information about the saem-devel mailing list