web/views/sparql.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 26 Mar 2010 08:32:32 +0100
branchstable
changeset 5032 e3fa27fc0d9a
parent 4721 8f63691ccb7f
child 5421 8167de96c523
permissions -rw-r--r--
cleanup
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     1
"""SPARQL integration
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     2
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     3
:organization: Logilab
4721
8f63691ccb7f pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
     4
:copyright: 2009-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     5
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     6
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     7
"""
4716
55b6a3262071 fix some pylint detected errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     8
__docformat__ = "restructuredtext en"
2424
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
     9
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    10
import rql
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    11
from yams import xy
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    12
2424
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    13
from lxml import etree
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    14
from lxml.builder import E
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    15
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    16
from cubicweb.view import StartupView, AnyRsetView
2426
0209d9bc45a8 possibility to choose results format, set a nicer file name on sparqlxml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2424
diff changeset
    17
from cubicweb.web import Redirect, form, formfields, formwidgets as fwdgs
4719
aaed3f813ef8 kill dead/useless code as suggested by pylint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4716
diff changeset
    18
from cubicweb.web.views import forms
2529
736893a990c4 make fyzz/spa2rql a recommends only
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2444
diff changeset
    19
try:
4716
55b6a3262071 fix some pylint detected errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    20
    from cubicweb.spa2rql import Sparql2rqlTranslator, UnsupportedQuery
2529
736893a990c4 make fyzz/spa2rql a recommends only
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2444
diff changeset
    21
except ImportError:
736893a990c4 make fyzz/spa2rql a recommends only
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2444
diff changeset
    22
    # fyzz not available (only a recommends)
736893a990c4 make fyzz/spa2rql a recommends only
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2444
diff changeset
    23
    Sparql2rqlTranslator = None
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    24
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    25
class SparqlForm(forms.FieldsForm):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2789
diff changeset
    26
    __regid__ = 'sparql'
2444
4e61d9e4befb [cleanup] fix typo
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2426
diff changeset
    27
    sparql = formfields.StringField(help=_('type here a sparql query'))
2426
0209d9bc45a8 possibility to choose results format, set a nicer file name on sparqlxml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2424
diff changeset
    28
    resultvid = formfields.StringField(choices=((_('table'), 'table'),
0209d9bc45a8 possibility to choose results format, set a nicer file name on sparqlxml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2424
diff changeset
    29
                                                (_('sparql xml'), 'sparqlxml')),
0209d9bc45a8 possibility to choose results format, set a nicer file name on sparqlxml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2424
diff changeset
    30
                                       widget=fwdgs.Radio,
4159
6b2b20c73d59 refactor form field value handling, to get a nicer api and an easier algorithm to get field's value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4045
diff changeset
    31
                                       value='table')
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    32
    form_buttons = [fwdgs.SubmitButton()]
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    33
    @property
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    34
    def action(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    35
        return self._cw.url()
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    36
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    37
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    38
class SparqlFormView(form.FormViewMixIn, StartupView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2789
diff changeset
    39
    __regid__ = 'sparql'
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    40
    def call(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    41
        form = self._cw.vreg.select('forms', 'sparql', self._cw)
3953
19aefd78f61b [forms] deprecate form_render(**kwargs) in favor of render(formvalues=None, rendervalues=None, renderer=None)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
    42
        self.w(form.render())
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    43
        sparql = self._cw.form.get('sparql')
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    44
        vid = self._cw.form.get('resultvid', 'table')
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    45
        if sparql:
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    46
            try:
4045
f4a52abb6f4f cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 3998
diff changeset
    47
                qinfo = Sparql2rqlTranslator(self._cw.vreg.schema).translate(sparql)
4719
aaed3f813ef8 kill dead/useless code as suggested by pylint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4716
diff changeset
    48
            except rql.TypeResolverException:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    49
                self.w(self._cw._('can not resolve entity types:') + u' ' + unicode('ex'))
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    50
            except UnsupportedQuery:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    51
                self.w(self._cw._('we are not yet ready to handle this query'))
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    52
            except xy.UnsupportedVocabulary, ex:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    53
                self.w(self._cw._('unknown vocabulary:') + u' ' + unicode('ex'))
2426
0209d9bc45a8 possibility to choose results format, set a nicer file name on sparqlxml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2424
diff changeset
    54
            if vid == 'sparqlxml':
3460
e4843535db25 [api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
    55
                url = self._cw.build_url('view', rql=qinfo.finalize(), vid=vid)
2426
0209d9bc45a8 possibility to choose results format, set a nicer file name on sparqlxml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2424
diff changeset
    56
                raise Redirect(url)
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    57
            rset = self._cw.execute(qinfo.finalize())
2426
0209d9bc45a8 possibility to choose results format, set a nicer file name on sparqlxml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2424
diff changeset
    58
            self.wview(vid, rset, 'null')
0209d9bc45a8 possibility to choose results format, set a nicer file name on sparqlxml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2424
diff changeset
    59
2424
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    60
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    61
## sparql resultset views #####################################################
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    62
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    63
YAMS_XMLSCHEMA_MAPPING = {
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    64
    'String': 'string',
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    65
    'Int': 'integer',
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    66
    'Float': 'float',
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    67
    'Boolean': 'boolean',
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    68
    'Datetime': 'dateTime',
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    69
    'Date': 'date',
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    70
    'Time': 'time',
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    71
    # XXX the following types don't have direct mapping
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    72
    'Decimal': 'string',
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    73
    'Interval': 'duration',
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    74
    'Password': 'string',
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    75
    'Bytes': 'base64Binary',
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    76
    }
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    77
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    78
def xmlschema(yamstype):
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    79
    return 'http://www.w3.org/2001/XMLSchema#%s' % YAMS_XMLSCHEMA_MAPPING[yamstype]
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    80
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    81
class SparqlResultXmlView(AnyRsetView):
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    82
    """The spec can be found here: http://www.w3.org/TR/rdf-sparql-XMLres/
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    83
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2789
diff changeset
    84
    __regid__ = 'sparqlxml'
2424
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    85
    content_type = 'application/sparql-results+xml'
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    86
    templatable = False
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    87
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    88
    def call(self):
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    89
        # XXX handle UNION
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    90
        rqlst = self.cw_rset.syntax_tree().children[0]
2424
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    91
        varnames = [var.name for var in rqlst.selection]
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    92
        results = E.results()
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    93
        for rowidx in xrange(len(self.cw_rset)):
2424
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    94
            result = E.result()
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    95
            for colidx, varname in enumerate(varnames):
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    96
                result.append(self.cell_binding(rowidx, colidx, varname))
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    97
            results.append(result)
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    98
        sparql = E.sparql(E.head(*(E.variable(name=name) for name in varnames)),
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
    99
                          results)
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
   100
        self.w(u'<?xml version="1.0"?>\n')
2426
0209d9bc45a8 possibility to choose results format, set a nicer file name on sparqlxml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2424
diff changeset
   101
        self.w(etree.tostring(sparql, encoding=unicode, pretty_print=True))
2424
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
   102
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
   103
    def cell_binding(self, row, col, varname):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   104
        celltype = self.cw_rset.description[row][col]
4045
f4a52abb6f4f cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 3998
diff changeset
   105
        if self._cw.vreg.schema.eschema(celltype).final:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   106
            cellcontent = self.view('cell', self.cw_rset, row=row, col=col)
2424
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
   107
            return E.binding(E.literal(cellcontent,
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
   108
                                       datatype=xmlschema(celltype)),
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
   109
                             name=varname)
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
   110
        else:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   111
            entity = self.cw_rset.get_entity(row, col)
2424
70f85df651a5 simple implementation of sparql XML resultset view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2422
diff changeset
   112
            return E.binding(E.uri(entity.absolute_url()), name=varname)
2426
0209d9bc45a8 possibility to choose results format, set a nicer file name on sparqlxml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2424
diff changeset
   113
0209d9bc45a8 possibility to choose results format, set a nicer file name on sparqlxml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2424
diff changeset
   114
    def set_request_content_type(self):
0209d9bc45a8 possibility to choose results format, set a nicer file name on sparqlxml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2424
diff changeset
   115
        """overriden to set the correct filetype and filename"""
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   116
        self._cw.set_content_type(self.content_type,
2426
0209d9bc45a8 possibility to choose results format, set a nicer file name on sparqlxml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2424
diff changeset
   117
                                  filename='sparql.xml',
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   118
                                  encoding=self._cw.encoding)
2529
736893a990c4 make fyzz/spa2rql a recommends only
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2444
diff changeset
   119
736893a990c4 make fyzz/spa2rql a recommends only
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2444
diff changeset
   120
def registration_callback(vreg):
736893a990c4 make fyzz/spa2rql a recommends only
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2444
diff changeset
   121
    if Sparql2rqlTranslator is not None:
736893a990c4 make fyzz/spa2rql a recommends only
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2444
diff changeset
   122
        vreg.register_all(globals().values(), __name__)