backport 3.5
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 02 Sep 2009 16:42:07 +0200
changeset 3090 8184bec7414d
parent 3087 dbbaa628f0f9 (current diff)
parent 3089 72c23fc7fe20 (diff)
child 3163 edfe43ceaa35
backport 3.5
server/hook.py
server/hooksmanager.py
web/views/ibreadcrumbs.py
--- a/server/hook.py	Wed Sep 02 10:54:04 2009 +0200
+++ b/server/hook.py	Wed Sep 02 16:42:07 2009 +0200
@@ -202,10 +202,10 @@
         else:
             assert rtype in self.object_relations
             meid, seid = toeid, fromeid
-        rql = 'SET E %s P WHERE X %s P, X eid %%(x)s, E eid %%(e)s, NOT E %s P'\
-              % (self.rtype, self.rtype, self.rtype)
-        rqls = [(rql, {'x': meid, 'e': seid}, ('x', 'e'))]
-        RQLPrecommitOperation(session, rqls=rqls)
+        session.unsafe_execute(
+            'SET E %s P WHERE X %s P, X eid %%(x)s, E eid %%(e)s, NOT E %s P'\
+            % (self.rtype, self.rtype, self.rtype),
+            {'x': meid, 'e': seid}, ('x', 'e'))
 
 
 class PropagateSubjectRelationAddHook(Hook):
@@ -219,19 +219,17 @@
 
     def call(self, session, fromeid, rtype, toeid):
         eschema = self.schema.eschema(session.describe(fromeid)[0])
-        rqls = []
+        execute = session.unsafe_execute
         for rel in self.subject_relations:
             if eschema.has_subject_relation(rel):
-                rqls.append(('SET R %s P WHERE X eid %%(x)s, P eid %%(p)s, '
-                             'X %s R, NOT R %s P' % (rtype, rel, rtype),
-                             {'x': fromeid, 'p': toeid}, 'x'))
+                execute('SET R %s P WHERE X eid %%(x)s, P eid %%(p)s, '
+                        'X %s R, NOT R %s P' % (rtype, rel, rtype),
+                        {'x': fromeid, 'p': toeid}, 'x')
         for rel in self.object_relations:
             if eschema.has_object_relation(rel):
-                rqls.append(('SET R %s P WHERE X eid %%(x)s, P eid %%(p)s, '
-                             'R %s X, NOT R %s P' % (rtype, rel, rtype),
-                             {'x': fromeid, 'p': toeid}, 'x'))
-        if rqls:
-            RQLPrecommitOperation(session, rqls=rqls)
+                execute('SET R %s P WHERE X eid %%(x)s, P eid %%(p)s, '
+                        'R %s X, NOT R %s P' % (rtype, rel, rtype),
+                        {'x': fromeid, 'p': toeid}, 'x')
 
 
 class PropagateSubjectRelationDelHook(Hook):
@@ -245,19 +243,17 @@
 
     def call(self, session, fromeid, rtype, toeid):
         eschema = self.schema.eschema(session.describe(fromeid)[0])
-        rqls = []
+        execute = session.unsafe_execute
         for rel in self.subject_relations:
             if eschema.has_subject_relation(rel):
-                rqls.append(('DELETE R %s P WHERE X eid %%(x)s, P eid %%(p)s, '
-                             'X %s R' % (rtype, rel),
-                             {'x': fromeid, 'p': toeid}, 'x'))
+                execute('DELETE R %s P WHERE X eid %%(x)s, P eid %%(p)s, '
+                        'X %s R' % (rtype, rel),
+                        {'x': fromeid, 'p': toeid}, 'x')
         for rel in self.object_relations:
             if eschema.has_object_relation(rel):
-                rqls.append(('DELETE R %s P WHERE X eid %%(x)s, P eid %%(p)s, '
-                             'R %s X' % (rtype, rel),
-                             {'x': fromeid, 'p': toeid}, 'x'))
-        if rqls:
-            RQLPrecommitOperation(session, rqls=rqls)
+                execute('DELETE R %s P WHERE X eid %%(x)s, P eid %%(p)s, '
+                        'R %s X' % (rtype, rel),
+                        {'x': fromeid, 'p': toeid}, 'x')
 
 
 # abstract classes for operation ###############################################
--- a/server/hooksmanager.py	Wed Sep 02 10:54:04 2009 +0200
+++ b/server/hooksmanager.py	Wed Sep 02 16:42:07 2009 +0200
@@ -5,3 +5,4 @@
 PropagateSubjectRelationAddHook = class_renamed('PropagateSubjectRelationAddHook', Hook)
 PropagateSubjectRelationDelHook = class_renamed('PropagateSubjectRelationDelHook', Hook)
 Hook = class_moved(Hook)
+
--- a/web/views/ibreadcrumbs.py	Wed Sep 02 10:54:04 2009 +0200
+++ b/web/views/ibreadcrumbs.py	Wed Sep 02 16:42:07 2009 +0200
@@ -16,14 +16,8 @@
 from cubicweb.view import EntityView, Component
 # don't use AnyEntity since this may cause bug with isinstance() due to reloading
 from cubicweb.entity import Entity
-from cubicweb.common.uilib import cut
-
+from cubicweb.common import tags, uilib
 
-def bc_title(entity):
-    textsize = entity.req.property_value('navigation.short-line-size')
-    return xml_escape(cut(entity.dc_title(), textsize))
-
-# XXX only provides the component version
 
 class BreadCrumbEntityVComponent(Component):
     id = 'breadcrumbs'
@@ -38,7 +32,7 @@
     separator = u'&#160;&gt;&#160;'
 
     def call(self, view=None, first_separator=True):
-        entity = self.rset.get_entity(0,0)
+        entity = self.rset.get_entity(0, 0)
         path = entity.breadcrumbs(view)
         if path:
             self.w(u'<span id="breadcrumbs" class="pathbar">')
@@ -62,17 +56,17 @@
     def wpath_part(self, part, contextentity, last=False):
         if isinstance(part, Entity):
             if last and part.eid == contextentity.eid:
-                self.w(bc_title(part))
+                part.view('breadcrumbtext', w=self.w)
             else:
                 part.view('breadcrumbs', w=self.w)
         elif isinstance(part, tuple):
             url, title = part
             textsize = self.req.property_value('navigation.short-line-size')
             self.w(u'<a href="%s">%s</a>' % (
-                xml_escape(url), xml_escape(cut(title, textsize))))
+                xml_escape(url), xml_escape(uilib.cut(title, textsize))))
         else:
             textsize = self.req.property_value('navigation.short-line-size')
-            self.w(cut(unicode(part), textsize))
+            self.w(uilib.cut(unicode(part), textsize))
 
 
 class BreadCrumbETypeVComponent(BreadCrumbEntityVComponent):
@@ -104,6 +98,15 @@
 
     def cell_call(self, row, col):
         entity = self.rset.get_entity(row, col)
-        desc = xml_escape(cut(entity.dc_description(), 50))
-        self.w(u'<a href="%s" title="%s">%s</a>' % (
-            xml_escape(entity.absolute_url()), desc, bc_title(entity)))
+        desc = xml_escape(uilib.cut(entity.dc_description(), 50))
+        self.w(tags.a(entity.view('breadcrumbtext'), href=entity.absolute_url(),
+                      title=desc))
+
+
+class BreadCrumbTextView(EntityView):
+    id = 'breadcrumbtext'
+
+    def cell_call(self, row, col):
+        entity = self.rset.get_entity(row, col)
+        textsize = self.req.property_value('navigation.short-line-size')
+        self.w(uilib.cut(entity.dc_title(), textsize))