18 """Specific views for SIOC (Semantically-Interlinked Online Communities) |
18 """Specific views for SIOC (Semantically-Interlinked Online Communities) |
19 |
19 |
20 http://sioc-project.org |
20 http://sioc-project.org |
21 """ |
21 """ |
22 |
22 |
23 __docformat__ = "restructuredtext en" |
23 from logilab.common.deprecation import class_moved |
24 _ = unicode |
|
25 |
24 |
26 from logilab.mtconverter import xml_escape |
25 try: |
|
26 from cubes.sioc.views import * |
27 |
27 |
28 from cubicweb.view import EntityView, EntityAdapter, implements_adapter_compat |
28 ISIOCItemAdapter = class_moved(ISIOCItemAdapter, message='[3.17] ISIOCItemAdapter moved to cubes.isioc.views') |
29 from cubicweb.predicates import implements, adaptable |
29 ISIOCContainerAdapter = class_moved(ISIOCContainerAdapter, message='[3.17] ISIOCContainerAdapter moved to cubes.isioc.views') |
30 from cubicweb.interfaces import ISiocItem, ISiocContainer |
30 SIOCView = class_moved(SIOCView, message='[3.17] SIOCView moved to cubes.is.view') |
31 |
31 SIOCContainerView = class_moved(SIOCContainerView, message='[3.17] SIOCContainerView moved to cubes.is.view') |
32 |
32 SIOCItemView = class_moved(SIOCItemView, message='[3.17] SIOCItemView moved to cubes.is.view') |
33 class ISIOCItemAdapter(EntityAdapter): |
33 except ImportError: |
34 """interface for entities which may be represented as an ISIOC items""" |
34 from cubicweb.web import LOGGER |
35 __needs_bw_compat__ = True |
35 LOGGER.warning('[3.17] isioc extracted to cube sioc that was not found. try installing it.') |
36 __regid__ = 'ISIOCItem' |
|
37 __select__ = implements(ISiocItem, warn=False) # XXX for bw compat, should be abstract |
|
38 |
|
39 @implements_adapter_compat('ISIOCItem') |
|
40 def isioc_content(self): |
|
41 """return item's content""" |
|
42 raise NotImplementedError |
|
43 |
|
44 @implements_adapter_compat('ISIOCItem') |
|
45 def isioc_container(self): |
|
46 """return container entity""" |
|
47 raise NotImplementedError |
|
48 |
|
49 @implements_adapter_compat('ISIOCItem') |
|
50 def isioc_type(self): |
|
51 """return container type (post, BlogPost, MailMessage)""" |
|
52 raise NotImplementedError |
|
53 |
|
54 @implements_adapter_compat('ISIOCItem') |
|
55 def isioc_replies(self): |
|
56 """return replies items""" |
|
57 raise NotImplementedError |
|
58 |
|
59 @implements_adapter_compat('ISIOCItem') |
|
60 def isioc_topics(self): |
|
61 """return topics items""" |
|
62 raise NotImplementedError |
|
63 |
|
64 |
|
65 class ISIOCContainerAdapter(EntityAdapter): |
|
66 """interface for entities which may be represented as an ISIOC container""" |
|
67 __needs_bw_compat__ = True |
|
68 __regid__ = 'ISIOCContainer' |
|
69 __select__ = implements(ISiocContainer, warn=False) # XXX for bw compat, should be abstract |
|
70 |
|
71 @implements_adapter_compat('ISIOCContainer') |
|
72 def isioc_type(self): |
|
73 """return container type (forum, Weblog, MailingList)""" |
|
74 raise NotImplementedError |
|
75 |
|
76 @implements_adapter_compat('ISIOCContainer') |
|
77 def isioc_items(self): |
|
78 """return contained items""" |
|
79 raise NotImplementedError |
|
80 |
|
81 |
|
82 class SIOCView(EntityView): |
|
83 __regid__ = 'sioc' |
|
84 __select__ = adaptable('ISIOCItem', 'ISIOCContainer') |
|
85 title = _('sioc') |
|
86 templatable = False |
|
87 content_type = 'text/xml' |
|
88 |
|
89 def call(self): |
|
90 self.w(u'<?xml version="1.0" encoding="%s"?>\n' % self._cw.encoding) |
|
91 self.w(u'''<rdf:RDF |
|
92 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" |
|
93 xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" |
|
94 xmlns:owl="http://www.w3.org/2002/07/owl#" |
|
95 xmlns:foaf="http://xmlns.com/foaf/0.1/" |
|
96 xmlns:sioc="http://rdfs.org/sioc/ns#" |
|
97 xmlns:sioctype="http://rdfs.org/sioc/types#" |
|
98 xmlns:dcterms="http://purl.org/dc/terms/">\n''') |
|
99 for i in xrange(self.cw_rset.rowcount): |
|
100 self.cell_call(i, 0) |
|
101 self.w(u'</rdf:RDF>\n') |
|
102 |
|
103 def cell_call(self, row, col): |
|
104 self.wview('sioc_element', self.cw_rset, row=row, col=col) |
|
105 |
|
106 class SIOCContainerView(EntityView): |
|
107 __regid__ = 'sioc_element' |
|
108 __select__ = adaptable('ISIOCContainer') |
|
109 templatable = False |
|
110 content_type = 'text/xml' |
|
111 |
|
112 def cell_call(self, row, col): |
|
113 entity = self.cw_rset.complete_entity(row, col) |
|
114 isioc = entity.cw_adapt_to('ISIOCContainer') |
|
115 isioct = isioc.isioc_type() |
|
116 self.w(u'<sioc:%s rdf:about="%s">\n' |
|
117 % (isioct, xml_escape(entity.absolute_url()))) |
|
118 self.w(u'<dcterms:title>%s</dcterms:title>' |
|
119 % xml_escape(entity.dc_title())) |
|
120 self.w(u'<dcterms:created>%s</dcterms:created>' |
|
121 % entity.creation_date) # XXX format |
|
122 self.w(u'<dcterms:modified>%s</dcterms:modified>' |
|
123 % entity.modification_date) # XXX format |
|
124 self.w(u'<!-- FIXME : here be items -->')#entity.isioc_items() |
|
125 self.w(u'</sioc:%s>\n' % isioct) |
|
126 |
|
127 |
|
128 class SIOCItemView(EntityView): |
|
129 __regid__ = 'sioc_element' |
|
130 __select__ = adaptable('ISIOCItem') |
|
131 templatable = False |
|
132 content_type = 'text/xml' |
|
133 |
|
134 def cell_call(self, row, col): |
|
135 entity = self.cw_rset.complete_entity(row, col) |
|
136 isioc = entity.cw_adapt_to('ISIOCItem') |
|
137 isioct = isioc.isioc_type() |
|
138 self.w(u'<sioc:%s rdf:about="%s">\n' |
|
139 % (isioct, xml_escape(entity.absolute_url()))) |
|
140 self.w(u'<dcterms:title>%s</dcterms:title>' |
|
141 % xml_escape(entity.dc_title())) |
|
142 self.w(u'<dcterms:created>%s</dcterms:created>' |
|
143 % entity.creation_date) # XXX format |
|
144 self.w(u'<dcterms:modified>%s</dcterms:modified>' |
|
145 % entity.modification_date) # XXX format |
|
146 content = isioc.isioc_content() |
|
147 if content: |
|
148 self.w(u'<sioc:content>%s</sioc:content>' % xml_escape(content)) |
|
149 container = isioc.isioc_container() |
|
150 if container: |
|
151 self.w(u'<sioc:has_container rdf:resource="%s"/>\n' |
|
152 % xml_escape(container.absolute_url())) |
|
153 if entity.creator: |
|
154 self.w(u'<sioc:has_creator>\n') |
|
155 self.w(u'<sioc:User rdf:about="%s">\n' |
|
156 % xml_escape(entity.creator.absolute_url())) |
|
157 self.w(entity.creator.view('foaf')) |
|
158 self.w(u'</sioc:User>\n') |
|
159 self.w(u'</sioc:has_creator>\n') |
|
160 self.w(u'<!-- FIXME : here be topics -->')#entity.isioc_topics() |
|
161 self.w(u'<!-- FIXME : here be replies -->')#entity.isioc_replies() |
|
162 self.w(u' </sioc:%s>\n' % isioct) |
|
163 |
|