13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
14 # details. |
14 # details. |
15 # |
15 # |
16 # You should have received a copy of the GNU Lesser General Public License along |
16 # You should have received a copy of the GNU Lesser General Public License along |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 """Specific views for SIOC interfaces |
18 """Specific views for SIOC (Semantically-Interlinked Online Communities) |
19 |
19 |
|
20 http://sioc-project.org |
20 """ |
21 """ |
|
22 |
21 __docformat__ = "restructuredtext en" |
23 __docformat__ = "restructuredtext en" |
22 |
24 |
23 from logilab.mtconverter import xml_escape |
25 from logilab.mtconverter import xml_escape |
24 |
26 |
25 from cubicweb.view import EntityView |
27 from cubicweb.view import EntityView, EntityAdapter, implements_adapter_compat |
26 from cubicweb.selectors import implements |
28 from cubicweb.selectors import implements, adaptable |
27 from cubicweb.interfaces import ISiocItem, ISiocContainer |
29 from cubicweb.interfaces import ISiocItem, ISiocContainer |
|
30 |
|
31 |
|
32 class ISIOCItemAdapter(EntityAdapter): |
|
33 """interface for entities which may be represented as an ISIOC items""" |
|
34 __regid__ = 'ISIOCItem' |
|
35 __select__ = implements(ISiocItem) # XXX for bw compat, should be abstract |
|
36 |
|
37 @implements_adapter_compat('ISIOCItem') |
|
38 def isioc_content(self): |
|
39 """return item's content""" |
|
40 raise NotImplementedError |
|
41 |
|
42 @implements_adapter_compat('ISIOCItem') |
|
43 def isioc_container(self): |
|
44 """return container entity""" |
|
45 raise NotImplementedError |
|
46 |
|
47 @implements_adapter_compat('ISIOCItem') |
|
48 def isioc_type(self): |
|
49 """return container type (post, BlogPost, MailMessage)""" |
|
50 raise NotImplementedError |
|
51 |
|
52 @implements_adapter_compat('ISIOCItem') |
|
53 def isioc_replies(self): |
|
54 """return replies items""" |
|
55 raise NotImplementedError |
|
56 |
|
57 @implements_adapter_compat('ISIOCItem') |
|
58 def isioc_topics(self): |
|
59 """return topics items""" |
|
60 raise NotImplementedError |
|
61 |
|
62 |
|
63 class ISIOCContainerAdapter(EntityAdapter): |
|
64 """interface for entities which may be represented as an ISIOC container""" |
|
65 __regid__ = 'ISIOCContainer' |
|
66 __select__ = implements(ISiocContainer) # XXX for bw compat, should be abstract |
|
67 |
|
68 @implements_adapter_compat('ISIOCContainer') |
|
69 def isioc_type(self): |
|
70 """return container type (forum, Weblog, MailingList)""" |
|
71 raise NotImplementedError |
|
72 |
|
73 @implements_adapter_compat('ISIOCContainer') |
|
74 def isioc_items(self): |
|
75 """return contained items""" |
|
76 raise NotImplementedError |
|
77 |
28 |
78 |
29 class SIOCView(EntityView): |
79 class SIOCView(EntityView): |
30 __regid__ = 'sioc' |
80 __regid__ = 'sioc' |
31 __select__ = EntityView.__select__ & implements(ISiocItem, ISiocContainer) |
81 __select__ = adaptable('ISIOCItem', 'ISIOCContainer') |
32 title = _('sioc') |
82 title = _('sioc') |
33 templatable = False |
83 templatable = False |
34 content_type = 'text/xml' |
84 content_type = 'text/xml' |
35 |
85 |
36 def call(self): |
86 def call(self): |
50 def cell_call(self, row, col): |
100 def cell_call(self, row, col): |
51 self.wview('sioc_element', self.cw_rset, row=row, col=col) |
101 self.wview('sioc_element', self.cw_rset, row=row, col=col) |
52 |
102 |
53 class SIOCContainerView(EntityView): |
103 class SIOCContainerView(EntityView): |
54 __regid__ = 'sioc_element' |
104 __regid__ = 'sioc_element' |
55 __select__ = EntityView.__select__ & implements(ISiocContainer) |
105 __select__ = adaptable('ISIOCContainer') |
56 templatable = False |
106 templatable = False |
57 content_type = 'text/xml' |
107 content_type = 'text/xml' |
58 |
108 |
59 def cell_call(self, row, col): |
109 def cell_call(self, row, col): |
60 entity = self.cw_rset.complete_entity(row, col) |
110 entity = self.cw_rset.complete_entity(row, col) |
61 sioct = xml_escape(entity.isioc_type()) |
111 isioc = entity.cw_adapt_to('ISIOCContainer') |
|
112 isioct = isioc.isioc_type() |
62 self.w(u'<sioc:%s rdf:about="%s">\n' |
113 self.w(u'<sioc:%s rdf:about="%s">\n' |
63 % (sioct, xml_escape(entity.absolute_url()))) |
114 % (isioct, xml_escape(entity.absolute_url()))) |
64 self.w(u'<dcterms:title>%s</dcterms:title>' |
115 self.w(u'<dcterms:title>%s</dcterms:title>' |
65 % xml_escape(entity.dc_title())) |
116 % xml_escape(entity.dc_title())) |
66 self.w(u'<dcterms:created>%s</dcterms:created>' |
117 self.w(u'<dcterms:created>%s</dcterms:created>' |
67 % entity.creation_date) |
118 % entity.creation_date) # XXX format |
68 self.w(u'<dcterms:modified>%s</dcterms:modified>' |
119 self.w(u'<dcterms:modified>%s</dcterms:modified>' |
69 % entity.modification_date) |
120 % entity.modification_date) # XXX format |
70 self.w(u'<!-- FIXME : here be items -->')#entity.isioc_items() |
121 self.w(u'<!-- FIXME : here be items -->')#entity.isioc_items() |
71 self.w(u'</sioc:%s>\n' % sioct) |
122 self.w(u'</sioc:%s>\n' % sioct) |
72 |
123 |
73 |
124 |
74 class SIOCItemView(EntityView): |
125 class SIOCItemView(EntityView): |
75 __regid__ = 'sioc_element' |
126 __regid__ = 'sioc_element' |
76 __select__ = EntityView.__select__ & implements(ISiocItem) |
127 __select__ = adaptable('ISIOCItem') |
77 templatable = False |
128 templatable = False |
78 content_type = 'text/xml' |
129 content_type = 'text/xml' |
79 |
130 |
80 def cell_call(self, row, col): |
131 def cell_call(self, row, col): |
81 entity = self.cw_rset.complete_entity(row, col) |
132 entity = self.cw_rset.complete_entity(row, col) |
82 sioct = xml_escape(entity.isioc_type()) |
133 isioc = entity.cw_adapt_to('ISIOCItem') |
|
134 isioct = isioc.isioc_type() |
83 self.w(u'<sioc:%s rdf:about="%s">\n' |
135 self.w(u'<sioc:%s rdf:about="%s">\n' |
84 % (sioct, xml_escape(entity.absolute_url()))) |
136 % (isioct, xml_escape(entity.absolute_url()))) |
85 self.w(u'<dcterms:title>%s</dcterms:title>' |
137 self.w(u'<dcterms:title>%s</dcterms:title>' |
86 % xml_escape(entity.dc_title())) |
138 % xml_escape(entity.dc_title())) |
87 self.w(u'<dcterms:created>%s</dcterms:created>' |
139 self.w(u'<dcterms:created>%s</dcterms:created>' |
88 % entity.creation_date) |
140 % entity.creation_date) # XXX format |
89 self.w(u'<dcterms:modified>%s</dcterms:modified>' |
141 self.w(u'<dcterms:modified>%s</dcterms:modified>' |
90 % entity.modification_date) |
142 % entity.modification_date) # XXX format |
91 if entity.content: |
143 content = isioc.isioc_content() |
92 self.w(u'<sioc:content>%s</sioc:content>''' |
144 if content: |
93 % xml_escape(entity.isioc_content())) |
145 self.w(u'<sioc:content>%s</sioc:content>' % xml_escape(content)) |
94 if entity.related('entry_of'): |
146 container = isioc.isioc_container() |
|
147 if container: |
95 self.w(u'<sioc:has_container rdf:resource="%s"/>\n' |
148 self.w(u'<sioc:has_container rdf:resource="%s"/>\n' |
96 % xml_escape(entity.isioc_container().absolute_url())) |
149 % xml_escape(container.absolute_url())) |
97 if entity.creator: |
150 if entity.creator: |
98 self.w(u'<sioc:has_creator>\n') |
151 self.w(u'<sioc:has_creator>\n') |
99 self.w(u'<sioc:User rdf:about="%s">\n' |
152 self.w(u'<sioc:User rdf:about="%s">\n' |
100 % xml_escape(entity.creator.absolute_url())) |
153 % xml_escape(entity.creator.absolute_url())) |
101 self.w(entity.creator.view('foaf')) |
154 self.w(entity.creator.view('foaf')) |