Example #1
0
    def post(self, request):
        """
        Gets a query and runs it
        """
        from webui.slice.utils import get_cleaned_sliced_data

        query = request.POST.get('query')
        fields = request.POST.get('fields')
        if not query or not fields:
            return HttpResponseBadRequest('Missing query or fields')

        try:
            results = get_cleaned_sliced_data(query, fields, with_header=True)
            header = next(results)
            results = list(results)
        except Exception, e:
            return HttpResponseBadRequest(str(e))
Example #2
0
    def post(self, request):
        """
        Gets a query and runs it
        """
        from webui.slice.utils import get_cleaned_sliced_data

        query = request.POST.get('query')
        fields = request.POST.get('fields')
        if not query or not fields:
            return HttpResponseBadRequest('Missing query or fields')

        try:
            results = get_cleaned_sliced_data(query, fields, with_header=True)
            header = next(results)
            results = list(results)
        except Exception, e:
            return HttpResponseBadRequest(str(e))
Example #3
0
    def render_to_response(self, context):  # pylint: disable=R0201
        """
        Called by GET, returns a streaming response.
        """
        from .utils import dicts2geojson, get_cleaned_sliced_data

        obj = context['object']
        data = get_cleaned_sliced_data(obj.query_string, obj.fields)
        data = ({k: v
                 for k, v in row.iteritems() if v is not None} for row in data)
        response = StreamingHttpResponse(
            dicts2geojson(data),
            content_type='application/x-download',
            # content_type='application/json',
        )
        response['Content-Disposition'] = 'attachment;filename=slice.geojson'

        return response
Example #4
0
    def render_to_response(self, context):  # pylint: disable=R0201
        """
        Called by GET, returns a streaming response.
        """
        from .utils import dicts2geojson, get_cleaned_sliced_data

        obj = context['object']
        data = get_cleaned_sliced_data(obj.query_string, obj.fields)
        data = ({k: v for k, v in row.iteritems() if v is not None}
                for row in data)
        response = StreamingHttpResponse(
            dicts2geojson(data),
            content_type='application/x-download',
            # content_type='application/json',
        )
        response['Content-Disposition'] = 'attachment;filename=slice.geojson'

        return response
Example #5
0
    def test_query_ok(self):
        graph_pref = settings.TRIPLE_DATABASE['PREFIXES']['data_graph_mapped']
        get_virtuoso('master').ingest(self._get_test_file(
            'boardgamegeek-games-mapped.nt', 'scheduler'),
                                      graph=graph_pref + 'test_graph')

        results = get_cleaned_sliced_data(query=THE_QUERY,
                                          fields='acheneID,provenance',
                                          with_header=True)
        header = next(results)
        self.assertIsInstance(header, list)
        self.assertGreater(len(list(results)), 0)

        results = get_sliced_data(query=THE_QUERY,
                                  fields='acheneID,provenance',
                                  with_header=False)
        results = list(results)
        self.assertIsInstance(results[0], dict)
Example #6
0
    def test_query_ok(self):
        graph_pref = settings.TRIPLE_DATABASE['PREFIXES']['data_graph_mapped']
        get_virtuoso('master').ingest(
            self._get_test_file('boardgamegeek-games-mapped.nt', 'scheduler'),
            graph=graph_pref + 'test_graph'
        )

        results = get_cleaned_sliced_data(
            query=THE_QUERY,
            fields='acheneID,provenance',
            with_header=True
        )
        header = next(results)
        self.assertIsInstance(header, list)
        self.assertGreater(len(list(results)), 0)

        results = get_sliced_data(
            query=THE_QUERY,
            fields='acheneID,provenance',
            with_header=False
        )
        results = list(results)
        self.assertIsInstance(results[0], dict)