equal
deleted
inserted
replaced
33 from cubicweb.spa2rql import Sparql2rqlTranslator, UnsupportedQuery |
33 from cubicweb.spa2rql import Sparql2rqlTranslator, UnsupportedQuery |
34 except ImportError: |
34 except ImportError: |
35 # fyzz not available (only a recommends) |
35 # fyzz not available (only a recommends) |
36 Sparql2rqlTranslator = None |
36 Sparql2rqlTranslator = None |
37 |
37 |
|
38 |
38 class SparqlForm(forms.FieldsForm): |
39 class SparqlForm(forms.FieldsForm): |
39 __regid__ = 'sparql' |
40 __regid__ = 'sparql' |
40 sparql = formfields.StringField(help=_('type here a sparql query')) |
41 sparql = formfields.StringField(help=_('type here a sparql query')) |
41 resultvid = formfields.StringField(choices=((_('table'), 'table'), |
42 resultvid = formfields.StringField(choices=((_('table'), 'table'), |
42 (_('sparql xml'), 'sparqlxml')), |
43 (_('sparql xml'), 'sparqlxml')), |
48 return self._cw.url() |
49 return self._cw.url() |
49 |
50 |
50 |
51 |
51 class SparqlFormView(form.FormViewMixIn, StartupView): |
52 class SparqlFormView(form.FormViewMixIn, StartupView): |
52 __regid__ = 'sparql' |
53 __regid__ = 'sparql' |
|
54 |
53 def call(self): |
55 def call(self): |
54 form = self._cw.vreg['forms'].select('sparql', self._cw) |
56 form = self._cw.vreg['forms'].select('sparql', self._cw) |
55 form.render(w=self.w) |
57 form.render(w=self.w) |
56 sparql = self._cw.form.get('sparql') |
58 sparql = self._cw.form.get('sparql') |
57 vid = self._cw.form.get('resultvid', 'table') |
59 vid = self._cw.form.get('resultvid', 'table') |
92 # XXX the following types don't have direct mapping |
94 # XXX the following types don't have direct mapping |
93 'Decimal': 'string', |
95 'Decimal': 'string', |
94 'Interval': 'duration', |
96 'Interval': 'duration', |
95 'Bytes': 'base64Binary', |
97 'Bytes': 'base64Binary', |
96 'Password': 'string', |
98 'Password': 'string', |
97 } |
99 } |
|
100 |
98 |
101 |
99 def xmlschema(yamstype): |
102 def xmlschema(yamstype): |
100 return 'http://www.w3.org/2001/XMLSchema#%s' % YAMS_XMLSCHEMA_MAPPING[yamstype] |
103 return 'http://www.w3.org/2001/XMLSchema#%s' % YAMS_XMLSCHEMA_MAPPING[yamstype] |
|
104 |
101 |
105 |
102 class SparqlResultXmlView(AnyRsetView): |
106 class SparqlResultXmlView(AnyRsetView): |
103 """The spec can be found here: http://www.w3.org/TR/rdf-sparql-XMLres/ |
107 """The spec can be found here: http://www.w3.org/TR/rdf-sparql-XMLres/ |
104 """ |
108 """ |
105 __regid__ = 'sparqlxml' |
109 __regid__ = 'sparqlxml' |
136 """overriden to set the correct filetype and filename""" |
140 """overriden to set the correct filetype and filename""" |
137 self._cw.set_content_type(self.content_type, |
141 self._cw.set_content_type(self.content_type, |
138 filename='sparql.xml', |
142 filename='sparql.xml', |
139 encoding=self._cw.encoding) |
143 encoding=self._cw.encoding) |
140 |
144 |
|
145 |
141 def registration_callback(vreg): |
146 def registration_callback(vreg): |
142 if Sparql2rqlTranslator is not None: |
147 if Sparql2rqlTranslator is not None: |
143 vreg.register_all(globals().values(), __name__) |
148 vreg.register_all(globals().values(), __name__) |