[web/views] extract cube sioc (closes #1916018)
authorSimon Chabot <simon.chabot@logilab.fr>
Wed, 27 Mar 2013 16:36:47 +0100
changeset 8800 8ca1a0da5a29
parent 8799 5fa07fdb6c8f
child 8801 86c1a5afbe4e
[web/views] extract cube sioc (closes #1916018)
doc/3.17.rst
interfaces.py
misc/migration/bootstrapmigration_repository.py
web/views/isioc.py
xy.py
--- a/doc/3.17.rst	Wed Mar 27 15:36:41 2013 +0100
+++ b/doc/3.17.rst	Wed Mar 27 16:36:47 2013 +0100
@@ -1,2 +1,8 @@
 What's new in CubicWeb 3.17?
 ============================
+
+API changes
+-----------
+
+* The SIOC views and adapters have been removed from CubicWeb and moved to the
+  `sioc` cube.
--- a/interfaces.py	Wed Mar 27 15:36:41 2013 +0100
+++ b/interfaces.py	Wed Mar 27 16:36:47 2013 +0100
@@ -148,34 +148,6 @@
     def marker_icon(self):
         """returns the icon that should be used as the marker"""
 
-# XXX deprecates in favor of ISIOCItemAdapter
-class ISiocItem(Interface):
-    """interface for entities which may be represented as an ISIOC item"""
-
-    def isioc_content(self):
-        """return item's content"""
-
-    def isioc_container(self):
-        """return container entity"""
-
-    def isioc_type(self):
-        """return container type (post, BlogPost, MailMessage)"""
-
-    def isioc_replies(self):
-        """return replies items"""
-
-    def isioc_topics(self):
-        """return topics items"""
-
-# XXX deprecates in favor of ISIOCContainerAdapter
-class ISiocContainer(Interface):
-    """interface for entities which may be represented as an ISIOC container"""
-
-    def isioc_type(self):
-        """return container type (forum, Weblog, MailingList)"""
-
-    def isioc_items(self):
-        """return contained items"""
 
 # XXX deprecates in favor of IEmailableAdapter
 class IFeed(Interface):
--- a/misc/migration/bootstrapmigration_repository.py	Wed Mar 27 15:36:41 2013 +0100
+++ b/misc/migration/bootstrapmigration_repository.py	Wed Mar 27 16:36:47 2013 +0100
@@ -34,6 +34,14 @@
     ss.execschemarql(rql, rdef, ss.rdef2rql(rdef, CSTRMAP, groupmap=None))
     commit(ask_confirm=False)
 
+if applcubicwebversion < (3, 17, 0) and cubicwebversion >= (3, 17, 0):
+    try:
+        add_cube('sioc', update_database=False)
+    except ImportError:
+        if not confirm('In cubicweb 3.17 sioc views have been moved to the sioc '
+                       'cube, which is not installed.  Continue anyway?'):
+            raise
+
 if applcubicwebversion <= (3, 13, 0) and cubicwebversion >= (3, 13, 1):
     sql('ALTER TABLE entities ADD asource VARCHAR(64)')
     sql('UPDATE entities SET asource=cw_name  '
--- a/web/views/isioc.py	Wed Mar 27 15:36:41 2013 +0100
+++ b/web/views/isioc.py	Wed Mar 27 16:36:47 2013 +0100
@@ -1,4 +1,4 @@
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -20,144 +20,16 @@
 http://sioc-project.org
 """
 
-__docformat__ = "restructuredtext en"
-_ = unicode
-
-from logilab.mtconverter import xml_escape
-
-from cubicweb.view import EntityView, EntityAdapter, implements_adapter_compat
-from cubicweb.predicates import implements, adaptable
-from cubicweb.interfaces import ISiocItem, ISiocContainer
-
-
-class ISIOCItemAdapter(EntityAdapter):
-    """interface for entities which may be represented as an ISIOC items"""
-    __needs_bw_compat__ = True
-    __regid__ = 'ISIOCItem'
-    __select__ = implements(ISiocItem, warn=False) # XXX for bw compat, should be abstract
-
-    @implements_adapter_compat('ISIOCItem')
-    def isioc_content(self):
-        """return item's content"""
-        raise NotImplementedError
-
-    @implements_adapter_compat('ISIOCItem')
-    def isioc_container(self):
-        """return container entity"""
-        raise NotImplementedError
-
-    @implements_adapter_compat('ISIOCItem')
-    def isioc_type(self):
-        """return container type (post, BlogPost, MailMessage)"""
-        raise NotImplementedError
+from logilab.common.deprecation import class_moved
 
-    @implements_adapter_compat('ISIOCItem')
-    def isioc_replies(self):
-        """return replies items"""
-        raise NotImplementedError
-
-    @implements_adapter_compat('ISIOCItem')
-    def isioc_topics(self):
-        """return topics items"""
-        raise NotImplementedError
-
-
-class ISIOCContainerAdapter(EntityAdapter):
-    """interface for entities which may be represented as an ISIOC container"""
-    __needs_bw_compat__ = True
-    __regid__ = 'ISIOCContainer'
-    __select__ = implements(ISiocContainer, warn=False) # XXX for bw compat, should be abstract
-
-    @implements_adapter_compat('ISIOCContainer')
-    def isioc_type(self):
-        """return container type (forum, Weblog, MailingList)"""
-        raise NotImplementedError
-
-    @implements_adapter_compat('ISIOCContainer')
-    def isioc_items(self):
-        """return contained items"""
-        raise NotImplementedError
-
-
-class SIOCView(EntityView):
-    __regid__ = 'sioc'
-    __select__ = adaptable('ISIOCItem', 'ISIOCContainer')
-    title = _('sioc')
-    templatable = False
-    content_type = 'text/xml'
+try:
+    from cubes.sioc.views import *
 
-    def call(self):
-        self.w(u'<?xml version="1.0" encoding="%s"?>\n' % self._cw.encoding)
-        self.w(u'''<rdf:RDF
-             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
-             xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
-             xmlns:owl="http://www.w3.org/2002/07/owl#"
-             xmlns:foaf="http://xmlns.com/foaf/0.1/"
-             xmlns:sioc="http://rdfs.org/sioc/ns#"
-             xmlns:sioctype="http://rdfs.org/sioc/types#"
-             xmlns:dcterms="http://purl.org/dc/terms/">\n''')
-        for i in xrange(self.cw_rset.rowcount):
-            self.cell_call(i, 0)
-        self.w(u'</rdf:RDF>\n')
-
-    def cell_call(self, row, col):
-        self.wview('sioc_element', self.cw_rset, row=row, col=col)
-
-class SIOCContainerView(EntityView):
-    __regid__ = 'sioc_element'
-    __select__ = adaptable('ISIOCContainer')
-    templatable = False
-    content_type = 'text/xml'
-
-    def cell_call(self, row, col):
-        entity = self.cw_rset.complete_entity(row, col)
-        isioc = entity.cw_adapt_to('ISIOCContainer')
-        isioct = isioc.isioc_type()
-        self.w(u'<sioc:%s rdf:about="%s">\n'
-               % (isioct, xml_escape(entity.absolute_url())))
-        self.w(u'<dcterms:title>%s</dcterms:title>'
-               % xml_escape(entity.dc_title()))
-        self.w(u'<dcterms:created>%s</dcterms:created>'
-               % entity.creation_date) # XXX format
-        self.w(u'<dcterms:modified>%s</dcterms:modified>'
-               % entity.modification_date) # XXX format
-        self.w(u'<!-- FIXME : here be items -->')#entity.isioc_items()
-        self.w(u'</sioc:%s>\n' % isioct)
-
-
-class SIOCItemView(EntityView):
-    __regid__ = 'sioc_element'
-    __select__ = adaptable('ISIOCItem')
-    templatable = False
-    content_type = 'text/xml'
-
-    def cell_call(self, row, col):
-        entity = self.cw_rset.complete_entity(row, col)
-        isioc = entity.cw_adapt_to('ISIOCItem')
-        isioct = isioc.isioc_type()
-        self.w(u'<sioc:%s rdf:about="%s">\n'
-               % (isioct, xml_escape(entity.absolute_url())))
-        self.w(u'<dcterms:title>%s</dcterms:title>'
-               % xml_escape(entity.dc_title()))
-        self.w(u'<dcterms:created>%s</dcterms:created>'
-               % entity.creation_date) # XXX format
-        self.w(u'<dcterms:modified>%s</dcterms:modified>'
-               % entity.modification_date) # XXX format
-        content = isioc.isioc_content()
-        if content:
-            self.w(u'<sioc:content>%s</sioc:content>' % xml_escape(content))
-        container = isioc.isioc_container()
-        if container:
-            self.w(u'<sioc:has_container rdf:resource="%s"/>\n'
-                   % xml_escape(container.absolute_url()))
-        if entity.creator:
-            self.w(u'<sioc:has_creator>\n')
-            self.w(u'<sioc:User rdf:about="%s">\n'
-                   % xml_escape(entity.creator.absolute_url()))
-            self.w(entity.creator.view('foaf'))
-            self.w(u'</sioc:User>\n')
-            self.w(u'</sioc:has_creator>\n')
-        self.w(u'<!-- FIXME : here be topics -->')#entity.isioc_topics()
-        self.w(u'<!-- FIXME : here be replies -->')#entity.isioc_replies()
-        self.w(u' </sioc:%s>\n' % isioct)
-
+    ISIOCItemAdapter = class_moved(ISIOCItemAdapter, message='[3.17] ISIOCItemAdapter moved to cubes.isioc.views')
+    ISIOCContainerAdapter = class_moved(ISIOCContainerAdapter, message='[3.17] ISIOCContainerAdapter moved to cubes.isioc.views')
+    SIOCView = class_moved(SIOCView, message='[3.17] SIOCView moved to cubes.is.view')
+    SIOCContainerView = class_moved(SIOCContainerView, message='[3.17] SIOCContainerView moved to cubes.is.view')
+    SIOCItemView = class_moved(SIOCItemView, message='[3.17] SIOCItemView moved to cubes.is.view')
+except ImportError:
+    from cubicweb.web import LOGGER
+    LOGGER.warning('[3.17] isioc extracted to cube sioc that was not found. try installing it.')
--- a/xy.py	Wed Mar 27 15:36:41 2013 +0100
+++ b/xy.py	Wed Mar 27 16:36:47 2013 +0100
@@ -23,7 +23,6 @@
 xy.register_prefix('dc', 'http://purl.org/dc/elements/1.1/')
 xy.register_prefix('foaf', 'http://xmlns.com/foaf/0.1/')
 xy.register_prefix('doap', 'http://usefulinc.com/ns/doap#')
-xy.register_prefix('sioc', 'http://rdfs.org/sioc/ns#')
 xy.register_prefix('owl', 'http://www.w3.org/2002/07/owl#')
 xy.register_prefix('dcterms', 'http://purl.org/dc/terms/')