[reledit] do NOT propose to edit composite-related entities (unlinking would destroy the other side) stable
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Thu, 09 Jul 2009 17:16:49 +0200
branchstable
changeset 2361 8f00836580f1
parent 2360 1d43aa551ba9
child 2362 f2409d5f2b75
[reledit] do NOT propose to edit composite-related entities (unlinking would destroy the other side)
utils.py
web/views/editforms.py
web/views/primary.py
--- a/utils.py	Thu Jul 09 16:44:34 2009 +0200
+++ b/utils.py	Thu Jul 09 17:16:49 2009 +0200
@@ -326,6 +326,14 @@
     """
     # XXX deprecated, no more necessary
 
+def get_schema_property(eschema, rschema, role, property):
+    # XXX use entity.e_schema.role_rproperty(role, rschema, property, tschemas[0]) once yams > 0.23.0 is out
+    if role == 'subject':
+        targetschema = rschema.objects(eschema)[0]
+        return rschema.rproperty(eschema, targetschema, property)
+    targetschema = rschema.subjects(eschema)[0]
+    return rschema.rproperty(targetschema, eschema, property)
+
 def compute_cardinality(eschema, rschema, role):
     if role == 'subject':
         targetschema = rschema.objects(eschema)[0]
@@ -333,4 +341,3 @@
     targetschema = rschema.subjects(eschema)[0]
     return rschema.rproperty(targetschema, eschema, 'cardinality')[1]
 
-
--- a/web/views/editforms.py	Thu Jul 09 16:44:34 2009 +0200
+++ b/web/views/editforms.py	Thu Jul 09 17:16:49 2009 +0200
@@ -17,7 +17,7 @@
 
 from cubicweb.selectors import (match_kwargs, one_line_rset, non_final_entity,
                                 specified_etype_implements, yes)
-from cubicweb.utils import make_uid, compute_cardinality
+from cubicweb.utils import make_uid, compute_cardinality, get_schema_property
 from cubicweb.view import EntityView
 from cubicweb.common import tags
 from cubicweb.web import INTERNAL_FIELD_VALUE, stdmsgs, eid_param
@@ -137,6 +137,10 @@
             elif role == 'object' and not rschema.has_perm(self.req, 'add',
                                                            toeid=entity.eid):
                 return self.w(value)
+            elif get_schema_property(entity.e_schema,
+                                   entity.schema.rschema(rtype),
+                                   role, 'composite'):
+                return self.w(value)
             form = self._build_relation_form(entity, value, rtype, role, reload, row, col,
                                              rvid, default, landing_zone)
         renderer = self.vreg.select_object('formrenderers', 'base', self.req,
--- a/web/views/primary.py	Thu Jul 09 16:44:34 2009 +0200
+++ b/web/views/primary.py	Thu Jul 09 17:16:49 2009 +0200
@@ -117,19 +117,7 @@
 
     def render_entity_attributes(self, entity, siderelations=None):
         for rschema, tschemas, role, dispctrl in self._section_def(entity, 'attributes'):
-            # don't use reledit as default vid for composite relation
-            if rschema.is_final():
-                defaultvid = 'reledit'
-            # XXX use entity.e_schema.role_rproperty(role, rschema, 'composite', tschemas[0]) once yams > 0.23.0 is out
-            elif role == 'subject' and \
-                 rschema.rproperty(entity.e_schema, tschemas[0], 'composite'):
-                defaultvid = 'csv'
-            elif role == 'object' and \
-                 rschema.rproperty(tschemas[0], entity.e_schema, 'composite'):
-                defaultvid = 'csv'
-            else:
-                defaultvid = 'reledit'
-            vid =  dispctrl.get('vid', defaultvid)
+            vid = dispctrl.get('vid', 'reledit')
             if rschema.is_final() or vid == 'reledit':
                 value = entity.view(vid, rtype=rschema.type, role=role)
             else: