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

authorSimon Chabot <simon.chabot@logilab.fr>
changeset165a27dfc427
branchdefault
phasedraft
hiddenyes
parent revision#662b6671d3d6 [web/views] extract cube embed (closes #1916015)
child revision<not specified>
files modified by this revision
__pkginfo__.py
debian/control
interfaces.py
misc/migration/bootstrapmigration_repository.py
web/views/isioc.py
xy.py
# HG changeset patch
# User Simon Chabot <simon.chabot@logilab.fr>
# Date 1355750035 -3600
# Mon Dec 17 14:13:55 2012 +0100
# Node ID 165a27dfc427c1e12c1106c700f13e3283c9ef98
# Parent 662b6671d3d649275fc750fdedb060989e1f02fe
[web/views] extract cube sioc (closes #1916018)

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