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

authorSimon Chabot <simon.chabot@logilab.fr>
changeset8ca1a0da5a29
branchdefault
phasepublic
hiddenno
parent revision#5fa07fdb6c8f [doc] Add 3.17 release notes
child revision#86c1a5afbe4e 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 8ca1a0da5a29cc3050f7c024b681b0a2e49989a3
# Parent 5fa07fdb6c8f3522779a56ff9d2459031638237a
[web/views] extract cube sioc (closes #1916018)

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