merge
authorNicolas Chauvat <nicolas.chauvat@logilab.fr>
Sat, 21 Nov 2009 20:31:19 +0100
changeset 75 3596652f440e
parent 74 5deaa2e20bb7 (current diff)
parent 69 383dbf5b9430 (diff)
child 87 5170c4644eaa
merge
test/unittest_classification.py
views.py
--- a/test/unittest_classification.py	Fri Oct 23 13:29:00 2009 +0200
+++ b/test/unittest_classification.py	Sat Nov 21 20:31:19 2009 +0100
@@ -13,9 +13,8 @@
         #self.zone = self.add_entity('Zone', name=u"Paris")
 
     def test_application_of_bad_keyword_fails(self):
-        self.skip('AssertionError: ValidationError not raised on applied_to relation. Need review here')
-        self.assertRaises(ValidationError, self.execute,
-                          'SET K applied_to G WHERE G is CWGroup, K name "kwuser"')
+        self.execute('SET K applied_to G WHERE G is CWGroup, K name "kwuser"')
+        self.assertRaises(ValidationError, self.commit)
 
     def test_creating_a_new_subkeyword_sets_included_in(self):
         self.execute('INSERT Keyword SK: SK name "kwgroup2", SK subkeyword_of K '
--- a/views.py	Fri Oct 23 13:29:00 2009 +0200
+++ b/views.py	Sat Nov 21 20:31:19 2009 +0100
@@ -65,6 +65,59 @@
     item_vid = 'text'
     separator = u' > '
 
+# skos views ############################################################
+
+SKOS_OPENING_ROOT=u'''<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE rdfs [
+	<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+	<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#">
+	<!ENTITY dc "http://purl.org/dc/elements/1.1/">
+	<!ENTITY dct "http://purl.org/dc/terms/">
+]>
+<rdf:RDF  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+          xmlns:skos="http://www.w3.org/2004/02/skos/core#">
+'''
+SKOS_CLOSING_ROOT = u'</rdf:RDF>'
+
+class SkosView(EntityView):
+    id = 'skos'
+    content_type = 'application/xml'
+    templatable = False
+    __select__ = implements('Keyword', 'Classification')
+
+    def call(self, **kwargs):
+        self.w(SKOS_OPENING_ROOT)
+        for i in xrange(self.rset.rowcount):
+             self.cell_call(i, 0)
+        self.w(SKOS_CLOSING_ROOT)
+
+    def cell_call(self, row, col):
+        self.wview('skositemview', self.rset, row=row, col=col)
+
+class SkosItemView(EntityView):
+    id = 'skositemview'
+    content_type = 'application/xml'
+    __select__ = implements('Keyword', 'Classification')
+
+    def cell_call(self, row, col, show_parent=True, stop=False):
+        w = self.w
+        entity = self.complete_entity(row, col)
+        eschema = entity.e_schema
+        w(u'<skos:%s>' % eschema)
+        w(u'<skos:prefLabel>%s</skos:prefLabel>' % xml_escape(entity.name))
+        if not stop:
+            if show_parent and not entity.is_root():
+                par = entity.parent()
+                w(u'<skos:broader>')
+                par.view('skositemview', show_parent=False, stop=True, w=self.w)
+                w(u'</skos:broader>')
+            for child in entity.children(entities=True):
+                w(u'<skos:narrower>')
+                self.wview('skositemview', child.as_rset(), show_parent=False)
+                w(u'</skos:narrower>')
+        w(u'</skos:%s>' % eschema)
+
+
 # keyword component ###########################################################
 
 class KeywordBarVComponent(component.EntityVComponent):