[web/views] extract cube sioc (closes #1916018)

authorSimon Chabot <simon.chabot@logilab.fr>
changesetf404f3e4ccea
branchdefault
phasedraft
hiddenyes
parent revision#cf63671fcf2b [web/views] extract cube embed (closes #1916015)
child revision#87d24907ca99 Drop iprogress code (closes #2777628)
files modified by this revision
doc/3.17.rst
interfaces.py
misc/migration/bootstrapmigration_repository.py
web/views/isioc.py
xy.py
# HG changeset patch
# User Simon Chabot <simon.chabot@logilab.fr>
# Date 1364398607 -3600
# Wed Mar 27 16:36:47 2013 +0100
# Node ID f404f3e4ccea032f85639904c644293e1b19749c
# Parent cf63671fcf2b8db0eee208a6bb16244187e1fac6
[web/views] extract cube sioc (closes #1916018)

diff --git a/doc/3.17.rst b/doc/3.17.rst
@@ -4,5 +4,8 @@
1  API changes
2  -----------
3 
4  * The web page embedding views and adapters have been removed from CubicWeb and
5    moved to the `embed` cube.
6 +
7 +* The SIOC views and adapters have been removed from CubicWeb and moved to the
8 +  `sioc` cube.
diff --git a/interfaces.py b/interfaces.py
@@ -146,38 +146,10 @@
9          """returns the longitude of the entity"""
10 
11      def marker_icon(self):
12          """returns the icon that should be used as the marker"""
13 
14 -# XXX deprecates in favor of ISIOCItemAdapter
15 -class ISiocItem(Interface):
16 -    """interface for entities which may be represented as an ISIOC item"""
17 -
18 -    def isioc_content(self):
19 -        """return item's content"""
20 -
21 -    def isioc_container(self):
22 -        """return container entity"""
23 -
24 -    def isioc_type(self):
25 -        """return container type (post, BlogPost, MailMessage)"""
26 -
27 -    def isioc_replies(self):
28 -        """return replies items"""
29 -
30 -    def isioc_topics(self):
31 -        """return topics items"""
32 -
33 -# XXX deprecates in favor of ISIOCContainerAdapter
34 -class ISiocContainer(Interface):
35 -    """interface for entities which may be represented as an ISIOC container"""
36 -
37 -    def isioc_type(self):
38 -        """return container type (forum, Weblog, MailingList)"""
39 -
40 -    def isioc_items(self):
41 -        """return contained items"""
42 
43  # XXX deprecates in favor of IEmailableAdapter
44  class IFeed(Interface):
45      """interface for entities with rss flux"""
46 
diff --git a/misc/migration/bootstrapmigration_repository.py b/misc/migration/bootstrapmigration_repository.py
@@ -39,10 +39,16 @@
47          add_cube('embed', update_database=False)
48      except ImportError:
49          if not confirm('In cubicweb 3.17 embedding views have been moved to the embed '
50                         'cube, which is not installed.  Continue anyway?'):
51              raise
52 +    try:
53 +        add_cube('sioc', update_database=False)
54 +    except ImportError:
55 +        if not confirm('In cubicweb 3.17 sioc views have been moved to the sioc '
56 +                       'cube, which is not installed.  Continue anyway?'):
57 +            raise
58 
59  if applcubicwebversion <= (3, 13, 0) and cubicwebversion >= (3, 13, 1):
60      sql('ALTER TABLE entities ADD asource VARCHAR(64)')
61      sql('UPDATE entities SET asource=cw_name  '
62          'FROM cw_CWSource, cw_source_relation '
diff --git a/web/views/isioc.py b/web/views/isioc.py
@@ -1,6 +1,6 @@
63 -# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
64 +# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
65  # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
66  #
67  # This file is part of CubicWeb.
68  #
69  # CubicWeb is free software: you can redistribute it and/or modify it under the
@@ -18,146 +18,18 @@
70  """Specific views for SIOC (Semantically-Interlinked Online Communities)
71 
72  http://sioc-project.org
73  """
74 
75 -__docformat__ = "restructuredtext en"
76 -_ = unicode
77 -
78 -from logilab.mtconverter import xml_escape
79 -
80 -from cubicweb.view import EntityView, EntityAdapter, implements_adapter_compat
81 -from cubicweb.predicates import implements, adaptable
82 -from cubicweb.interfaces import ISiocItem, ISiocContainer
83 -
84 -
85 -class ISIOCItemAdapter(EntityAdapter):
86 -    """interface for entities which may be represented as an ISIOC items"""
87 -    __needs_bw_compat__ = True
88 -    __regid__ = 'ISIOCItem'
89 -    __select__ = implements(ISiocItem, warn=False) # XXX for bw compat, should be abstract
90 -
91 -    @implements_adapter_compat('ISIOCItem')
92 -    def isioc_content(self):
93 -        """return item's content"""
94 -        raise NotImplementedError
95 -
96 -    @implements_adapter_compat('ISIOCItem')
97 -    def isioc_container(self):
98 -        """return container entity"""
99 -        raise NotImplementedError
100 -
101 -    @implements_adapter_compat('ISIOCItem')
102 -    def isioc_type(self):
103 -        """return container type (post, BlogPost, MailMessage)"""
104 -        raise NotImplementedError
105 +from logilab.common.deprecation import class_moved
106 
107 -    @implements_adapter_compat('ISIOCItem')
108 -    def isioc_replies(self):
109 -        """return replies items"""
110 -        raise NotImplementedError
111 -
112 -    @implements_adapter_compat('ISIOCItem')
113 -    def isioc_topics(self):
114 -        """return topics items"""
115 -        raise NotImplementedError
116 -
117 -
118 -class ISIOCContainerAdapter(EntityAdapter):
119 -    """interface for entities which may be represented as an ISIOC container"""
120 -    __needs_bw_compat__ = True
121 -    __regid__ = 'ISIOCContainer'
122 -    __select__ = implements(ISiocContainer, warn=False) # XXX for bw compat, should be abstract
123 -
124 -    @implements_adapter_compat('ISIOCContainer')
125 -    def isioc_type(self):
126 -        """return container type (forum, Weblog, MailingList)"""
127 -        raise NotImplementedError
128 -
129 -    @implements_adapter_compat('ISIOCContainer')
130 -    def isioc_items(self):
131 -        """return contained items"""
132 -        raise NotImplementedError
133 -
134 -
135 -class SIOCView(EntityView):
136 -    __regid__ = 'sioc'
137 -    __select__ = adaptable('ISIOCItem', 'ISIOCContainer')
138 -    title = _('sioc')
139 -    templatable = False
140 -    content_type = 'text/xml'
141 +try:
142 +    from cubes.sioc.views import *
143 
144 -    def call(self):
145 -        self.w(u'<?xml version="1.0" encoding="%s"?>\n' % self._cw.encoding)
146 -        self.w(u'''<rdf:RDF
147 -             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
148 -             xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
149 -             xmlns:owl="http://www.w3.org/2002/07/owl#"
150 -             xmlns:foaf="http://xmlns.com/foaf/0.1/"
151 -             xmlns:sioc="http://rdfs.org/sioc/ns#"
152 -             xmlns:sioctype="http://rdfs.org/sioc/types#"
153 -             xmlns:dcterms="http://purl.org/dc/terms/">\n''')
154 -        for i in xrange(self.cw_rset.rowcount):
155 -            self.cell_call(i, 0)
156 -        self.w(u'</rdf:RDF>\n')
157 -
158 -    def cell_call(self, row, col):
159 -        self.wview('sioc_element', self.cw_rset, row=row, col=col)
160 -
161 -class SIOCContainerView(EntityView):
162 -    __regid__ = 'sioc_element'
163 -    __select__ = adaptable('ISIOCContainer')
164 -    templatable = False
165 -    content_type = 'text/xml'
166 -
167 -    def cell_call(self, row, col):
168 -        entity = self.cw_rset.complete_entity(row, col)
169 -        isioc = entity.cw_adapt_to('ISIOCContainer')
170 -        isioct = isioc.isioc_type()
171 -        self.w(u'<sioc:%s rdf:about="%s">\n'
172 -               % (isioct, xml_escape(entity.absolute_url())))
173 -        self.w(u'<dcterms:title>%s</dcterms:title>'
174 -               % xml_escape(entity.dc_title()))
175 -        self.w(u'<dcterms:created>%s</dcterms:created>'
176 -               % entity.creation_date) # XXX format
177 -        self.w(u'<dcterms:modified>%s</dcterms:modified>'
178 -               % entity.modification_date) # XXX format
179 -        self.w(u'<!-- FIXME : here be items -->')#entity.isioc_items()
180 -        self.w(u'</sioc:%s>\n' % isioct)
181 -
182 -
183 -class SIOCItemView(EntityView):
184 -    __regid__ = 'sioc_element'
185 -    __select__ = adaptable('ISIOCItem')
186 -    templatable = False
187 -    content_type = 'text/xml'
188 -
189 -    def cell_call(self, row, col):
190 -        entity = self.cw_rset.complete_entity(row, col)
191 -        isioc = entity.cw_adapt_to('ISIOCItem')
192 -        isioct = isioc.isioc_type()
193 -        self.w(u'<sioc:%s rdf:about="%s">\n'
194 -               % (isioct, xml_escape(entity.absolute_url())))
195 -        self.w(u'<dcterms:title>%s</dcterms:title>'
196 -               % xml_escape(entity.dc_title()))
197 -        self.w(u'<dcterms:created>%s</dcterms:created>'
198 -               % entity.creation_date) # XXX format
199 -        self.w(u'<dcterms:modified>%s</dcterms:modified>'
200 -               % entity.modification_date) # XXX format
201 -        content = isioc.isioc_content()
202 -        if content:
203 -            self.w(u'<sioc:content>%s</sioc:content>' % xml_escape(content))
204 -        container = isioc.isioc_container()
205 -        if container:
206 -            self.w(u'<sioc:has_container rdf:resource="%s"/>\n'
207 -                   % xml_escape(container.absolute_url()))
208 -        if entity.creator:
209 -            self.w(u'<sioc:has_creator>\n')
210 -            self.w(u'<sioc:User rdf:about="%s">\n'
211 -                   % xml_escape(entity.creator.absolute_url()))
212 -            self.w(entity.creator.view('foaf'))
213 -            self.w(u'</sioc:User>\n')
214 -            self.w(u'</sioc:has_creator>\n')
215 -        self.w(u'<!-- FIXME : here be topics -->')#entity.isioc_topics()
216 -        self.w(u'<!-- FIXME : here be replies -->')#entity.isioc_replies()
217 -        self.w(u' </sioc:%s>\n' % isioct)
218 -
219 +    ISIOCItemAdapter = class_moved(ISIOCItemAdapter, message='[3.17] ISIOCItemAdapter moved to cubes.isioc.views')
220 +    ISIOCContainerAdapter = class_moved(ISIOCContainerAdapter, message='[3.17] ISIOCContainerAdapter moved to cubes.isioc.views')
221 +    SIOCView = class_moved(SIOCView, message='[3.17] SIOCView moved to cubes.is.view')
222 +    SIOCContainerView = class_moved(SIOCContainerView, message='[3.17] SIOCContainerView moved to cubes.is.view')
223 +    SIOCItemView = class_moved(SIOCItemView, message='[3.17] SIOCItemView moved to cubes.is.view')
224 +except ImportError:
225 +    from cubicweb.web import LOGGER
226 +    LOGGER.warning('[3.17] isioc extracted to cube sioc that was not found. try installing it.')
diff --git a/xy.py b/xy.py
@@ -21,11 +21,10 @@
227 
228  xy.register_prefix('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#')
229  xy.register_prefix('dc', 'http://purl.org/dc/elements/1.1/')
230  xy.register_prefix('foaf', 'http://xmlns.com/foaf/0.1/')
231  xy.register_prefix('doap', 'http://usefulinc.com/ns/doap#')
232 -xy.register_prefix('sioc', 'http://rdfs.org/sioc/ns#')
233  xy.register_prefix('owl', 'http://www.w3.org/2002/07/owl#')
234  xy.register_prefix('dcterms', 'http://purl.org/dc/terms/')
235 
236  xy.add_equivalence('creation_date', 'dc:date')
237  xy.add_equivalence('created_by', 'dc:creator')