18 """SPARQL integration |
18 """SPARQL integration |
19 |
19 |
20 """ |
20 """ |
21 __docformat__ = "restructuredtext en" |
21 __docformat__ = "restructuredtext en" |
22 |
22 |
23 import rql |
|
24 from yams import xy |
23 from yams import xy |
|
24 from rql import TypeResolverException |
25 |
25 |
26 from lxml import etree |
26 from lxml import etree |
27 from lxml.builder import E |
27 from lxml.builder import E |
28 |
28 |
29 from cubicweb.view import StartupView, AnyRsetView |
29 from cubicweb.view import StartupView, AnyRsetView |
49 |
49 |
50 |
50 |
51 class SparqlFormView(form.FormViewMixIn, StartupView): |
51 class SparqlFormView(form.FormViewMixIn, StartupView): |
52 __regid__ = 'sparql' |
52 __regid__ = 'sparql' |
53 def call(self): |
53 def call(self): |
54 form = self._cw.vreg.select('forms', 'sparql', self._cw) |
54 form = self._cw.vreg['forms'].select('sparql', self._cw) |
55 self.w(form.render()) |
55 self.w(form.render()) |
56 sparql = self._cw.form.get('sparql') |
56 sparql = self._cw.form.get('sparql') |
57 vid = self._cw.form.get('resultvid', 'table') |
57 vid = self._cw.form.get('resultvid', 'table') |
58 if sparql: |
58 if sparql: |
59 try: |
59 try: |
60 qinfo = Sparql2rqlTranslator(self._cw.vreg.schema).translate(sparql) |
60 qinfo = Sparql2rqlTranslator(self._cw.vreg.schema).translate(sparql) |
61 except rql.TypeResolverException: |
61 except TypeResolverException, exc: |
62 self.w(self._cw._('can not resolve entity types:') + u' ' + unicode('ex')) |
62 self.w(self._cw._('can not resolve entity types:') + u' ' + unicode(exc)) |
63 except UnsupportedQuery: |
63 except UnsupportedQuery: |
64 self.w(self._cw._('we are not yet ready to handle this query')) |
64 self.w(self._cw._('we are not yet ready to handle this query')) |
65 except xy.UnsupportedVocabulary, ex: |
65 except xy.UnsupportedVocabulary, exc: |
66 self.w(self._cw._('unknown vocabulary:') + u' ' + unicode('ex')) |
66 self.w(self._cw._('unknown vocabulary:') + u' ' + unicode(exc)) |
67 else: |
67 else: |
|
68 rql, args = qinfo.finalize() |
68 if vid == 'sparqlxml': |
69 if vid == 'sparqlxml': |
69 url = self._cw.build_url('view', rql=qinfo.finalize(), vid=vid) |
70 url = self._cw.build_url('view', rql=(rql,args), vid=vid) |
70 raise Redirect(url) |
71 raise Redirect(url) |
71 print qinfo.finalize() |
72 rset = self._cw.execute(rql, args) |
72 rset = self._cw.execute(*qinfo.finalize()) |
|
73 self.wview(vid, rset, 'null') |
73 self.wview(vid, rset, 'null') |
74 |
74 |
75 |
75 |
76 ## sparql resultset views ##################################################### |
76 ## sparql resultset views ##################################################### |
77 |
77 |