Ejemplo n.º 1
0
def query_viewmodel(request, query, title=None, form=None, message=None, run_query=True, error=None):
    rows = url_get_rows(request)
    res = None
    ql = None
    if run_query:
        try:
            res, ql = query.execute_with_logging(request.user)
        except DatabaseError as e:
            error = str(e)
    has_valid_results = not error and res and run_query
    ret = RequestContext(request, {
            'tasks_enabled': app_settings.ENABLE_TASKS,
            'params': query.available_params(),
            'title': title,
            'shared': query.shared,
            'query': query,
            'form': form,
            'message': message,
            'error': error,
            'rows': rows,
            'data': res.data[:rows] if has_valid_results else None,
            'headers': res.headers if has_valid_results else None,
            'total_rows': len(res.data) if has_valid_results else None,
            'duration': res.duration if has_valid_results else None,
            'has_stats': len([h for h in res.headers if h.summary]) if has_valid_results else False,
            'dataUrl': reverse_lazy('query_csv', kwargs={'query_id': query.id}) if query.id else '',
            'bucket': app_settings.S3_BUCKET,
            'snapshots': query.snapshots if query.snapshot else [],
            'ql_id': ql.id if ql else None})
    return ret
Ejemplo n.º 2
0
def query_viewmodel(request, query, title=None, form=None, message=None, show_results=True):
    rows = url_get_rows(request)
    data = {
        'params': query.available_params(),
        'title': title,
        'shared': query.shared,
        'query': query,
        'form': form,
        'message': message,
        'error': None,
        'data': None,
        'headers': None,
        'total_rows': None,
        'duration': None,
        'rows': rows,
        'has_stats': False,
        'dataUrl': reverse_lazy('query_csv', kwargs={'query_id': query.id}) if query.id else '',
        'snapshots': query.snapshots if query.snapshot else None,
        'bucket': settings.EXPLORER_S3_BUCKET
    }
    if show_results:
        try:
            res = query.execute()
        except DatabaseError as e:
            data['error'] = str(e)
        else:
            data.update({
                'data': res.data[:rows],
                'headers': res.headers,
                'total_rows': len(res.data),
                'duration': res.duration,
                'has_stats': len([header for header in res.headers if header.summary]),
            })

    return RequestContext(request, data)
Ejemplo n.º 3
0
def query_viewmodel(request, query, title=None, form=None, message=None, show_results=True):
    rows = url_get_rows(request)
    res = None
    error = None
    if show_results:
        try:
            res = query.execute()
        except DatabaseError as e:
            error = str(e)
    ret = RequestContext(request, {
            'params': query.available_params(),
            'title': title,
            'shared': query.shared,
            'query': query,
            'form': form,
            'message': message,
            'error': error,
            'data': res.data[:rows] if not error and show_results else None,
            'headers': res.headers if not error and show_results else None,
            'total_rows': len(res.data) if not error and show_results else None,
            'duration': res.duration if not error and show_results else None,
            'rows': rows,
            'has_stats': len([h for h in res.headers if h.summary]) if not error and show_results else False,
            'dataUrl': reverse_lazy('query_csv', kwargs={'query_id': query.id}) if query.id else '',
            'bucket': app_settings.S3_BUCKET,
            'snapshots': query.snapshots if query.snapshot else []})
    return ret
Ejemplo n.º 4
0
def query_viewmodel(request, query, title=None, form=None, message=None, show_results=True, rebuild_cache=False):
    rows = url_get_rows(request)
    res = None
    error = None
    if show_results:
        try:
            if rebuild_cache:
                res = query.execute_cache()
            else:
                res = query.execute()
        except DatabaseError as e:
            error = str(e)
    query.log(request.user)
    return RequestContext(request, {
            'params': query.available_params(),
            'title': title,
            'shared': query.shared,
            'connection': query.database,
            'connections': get_connections_list(),
            'query': query,
            'form': form,
            'message': message,
            'error': error,
            'data': res.data[:rows] if not error and show_results else None,
            'headers': res.headers if not error and show_results else None,
            'total_rows': len(res.data) if not error and show_results else None,
            'duration': res.duration if not error and show_results else None,
            'rows': rows,
            'has_stats': len([h for h in res.headers if h.summary]) if not error and show_results else False,
            'dataUrl': reverse_lazy('query_csv', kwargs={'query_id': query.id}) if query.id else ''})
Ejemplo n.º 5
0
def query_viewmodel(request, query, title=None, form=None, message=None):
    rows = url_get_rows(request)
    res = query.headers_and_data()
    return RequestContext(
        request, {
            'error':
            res.error,
            'params':
            query.available_params(),
            'title':
            title,
            'query':
            query,
            'form':
            form,
            'message':
            message,
            'data':
            res.data[:rows],
            'headers':
            res.headers,
            'duration':
            res.duration,
            'rows':
            rows,
            'total_rows':
            len(res.data),
            'dataUrl':
            reverse_lazy('query_csv', kwargs={'query_id': query.id})
            if query.id else ''
        })
Ejemplo n.º 6
0
 def get(self, request, query_id):
     query, form = QueryView.get_instance_and_form(request, query_id)
     query.save()  # updates the modified date
     show = url_get_show(request)
     rows = url_get_rows(request)
     vm = query_viewmodel(request.user, query, form=form, run_query=show, rows=rows)
     fullscreen = url_get_fullscreen(request)
     template = 'fullscreen' if fullscreen else 'query'
     return self.render_template('explorer/%s.html' % template, vm)
Ejemplo n.º 7
0
 def get(self, request, query_id):
     query, form = QueryView.get_instance_and_form(request, query_id)
     query.save()  # updates the modified date
     show = url_get_show(request)
     rows = url_get_rows(request)
     vm = query_viewmodel(request.user, query, form=form, run_query=show, rows=rows)
     fullscreen = url_get_fullscreen(request)
     template = 'fullscreen' if fullscreen else 'query'
     return self.render_template('explorer/%s.html' % template, vm)
Ejemplo n.º 8
0
 def render_with_sql(self, request, query, run_query=True, error=None):
     rows = url_get_rows(request)
     context = query_viewmodel(request.user,
                               query,
                               title="Playground",
                               run_query=run_query,
                               error=error,
                               rows=rows)
     context.update({'no_jquery': True})
     return self.render_template('reports/playground.html', context)
Ejemplo n.º 9
0
 def render_with_sql(self, request, query, run_query=True, error=None):
     rows = url_get_rows(request)
     fullscreen = url_get_fullscreen(request)
     template = 'fullscreen' if fullscreen else 'play'
     return self.render_template('explorer/%s.html' % template, query_viewmodel(request.user,
                                                                                query,
                                                                                title="Playground",
                                                                                run_query=run_query,
                                                                                error=error,
                                                                                rows=rows))
Ejemplo n.º 10
0
 def render_with_sql(self, request, query, run_query=True, error=None):
     rows = url_get_rows(request)
     fullscreen = url_get_fullscreen(request)
     template = 'fullscreen' if fullscreen else 'play'
     form = QueryForm(request.POST if len(request.POST) else None, instance=query)
     return self.render_template('explorer/%s.html' % template, query_viewmodel(request.user,
                                                                                query,
                                                                                title="Playground",
                                                                                run_query=run_query,
                                                                                error=error,
                                                                                rows=rows,
                                                                                form=form))
Ejemplo n.º 11
0
Archivo: views.py Proyecto: grouwner/sc
 def render_with_sql(self, request, query, run_query=True, error=None):
     rows = url_get_rows(request)
     fullscreen = url_get_fullscreen(request)
     template = 'fullscreen' if fullscreen else 'play'
     return self.render_template(
         'explorer/%s.html' % template,
         query_viewmodel(request.user,
                         query,
                         title="Playground",
                         run_query=run_query,
                         error=error,
                         rows=rows))
Ejemplo n.º 12
0
 def render_with_sql(self, request, query, run_query=True, error=None):
     rows = url_get_rows(request)
     fullscreen = url_get_fullscreen(request)
     template = 'fullscreen' if fullscreen else 'play'
     form = QueryForm(request.POST if len(request.POST) else None, instance=query)
     return self.render_template('explorer/%s.html' % template, query_viewmodel(request.user,
                                                                                query,
                                                                                title="Playground",
                                                                                run_query=run_query,
                                                                                error=error,
                                                                                rows=rows,
                                                                                form=form))
Ejemplo n.º 13
0
def query_viewmodel(request,
                    query,
                    title=None,
                    form=None,
                    message=None,
                    show_results=True):
    rows = url_get_rows(request)
    res = None
    error = None
    if show_results:
        try:
            res = query.execute()
        except DatabaseError as e:
            error = str(e)
    ret = RequestContext(
        request, {
            'params':
            query.available_params(),
            'title':
            title,
            'shared':
            query.shared,
            'query':
            query,
            'form':
            form,
            'message':
            message,
            'error':
            error,
            'data':
            res.data[:rows] if not error and show_results else None,
            'headers':
            res.headers if not error and show_results else None,
            'total_rows':
            len(res.data) if not error and show_results else None,
            'duration':
            res.duration if not error and show_results else None,
            'rows':
            rows,
            'has_stats':
            len([h for h in res.headers
                 if h.summary]) if not error and show_results else False,
            'dataUrl':
            reverse_lazy('query_csv', kwargs={'query_id': query.id})
            if query.id else '',
            'bucket':
            app_settings.S3_BUCKET,
            'snapshots':
            query.snapshots if query.snapshot else []
        })
    return ret
Ejemplo n.º 14
0
 def post(self, request, query_id):
     if not app_settings.EXPLORER_PERMISSION_CHANGE(request.user):
         return HttpResponseRedirect(
             reverse_lazy('query_detail', kwargs={'query_id': query_id}))
     show = url_get_show(request)
     query, form = QueryView.get_instance_and_form(request, query_id)
     success = form.is_valid() and form.save()
     vm = query_viewmodel(request.user,
                          query,
                          form=form,
                          run_query=show,
                          rows=url_get_rows(request),
                          message="Query saved." if success else None)
     return self.render_template('explorer/query.html', vm)
Ejemplo n.º 15
0
def query_viewmodel(request, query, title=None, form=None, message=None):
    rows = url_get_rows(request)
    headers, data, duration, error = query.headers_and_data()
    return RequestContext(request, {
            'error': error,
            'params': query.available_params(),
            'title': title,
            'query': query,
            'form': form,
            'message': message,
            'data': data[:rows],
            'headers': headers,
            'duration': duration,
            'rows': rows,
            'total_rows': len(data)})
Ejemplo n.º 16
0
 def post(self, request, query_id):
     if not app_settings.EXPLORER_PERMISSION_CHANGE(request.user):
         return HttpResponseRedirect(
             reverse_lazy('query_detail', kwargs={'query_id': query_id})
         )
     show = url_get_show(request)
     query, form = QueryView.get_instance_and_form(request, query_id)
     success = form.is_valid() and form.save()
     vm = query_viewmodel(request.user,
                          query,
                          form=form,
                          run_query=show,
                          rows=url_get_rows(request),
                          message="Query saved." if success else None)
     return self.render_template('explorer/query.html', vm)
Ejemplo n.º 17
0
def query_viewmodel(request, query, title=None, form=None, message=None):
    rows = url_get_rows(request)
    res = query.headers_and_data()
    return RequestContext(request, {
            'error': res.error,
            'params': query.available_params(),
            'title': title,
            'query': query,
            'form': form,
            'message': message,
            'data': res.data[:rows],
            'headers': res.headers,
            'duration': res.duration,
            'rows': rows,
            'total_rows': len(res.data),
            'dataUrl': reverse_lazy('query_csv', kwargs={'query_id': query.id}) if query.id else ''})
Ejemplo n.º 18
0
def query_viewmodel(request, query, title=None, form=None, message=None):
    rows = url_get_rows(request)
    headers, data, duration, error = query.headers_and_data()
    return RequestContext(
        request, {
            'error': error,
            'params': query.available_params(),
            'title': title,
            'query': query,
            'form': form,
            'message': message,
            'data': data[:rows],
            'headers': headers,
            'duration': duration,
            'rows': rows,
            'total_rows': len(data)
        })
Ejemplo n.º 19
0
def query_viewmodel(request, query, title=None, form=None, message=None):
    rows = url_get_rows(request)
    params = url_get_params(request)
    headers, data, duration, error = query.headers_and_data(params)
    return RequestContext(
        request,
        {
            "error": error,
            "params": query.available_params(param_values=params),
            "title": title,
            "query": query,
            "form": form,
            "message": message,
            "data": data[:rows],
            "headers": headers,
            "duration": duration,
            "rows": rows,
            "total_rows": len(data),
        },
    )
Ejemplo n.º 20
0
 def post(self, request):
     ret = super().post(request)
     if self.get_form().is_valid():
         show = url_get_show(request)
         query, form = QueryView.get_instance_and_form(request, self.object.id)
         success = form.is_valid() and form.save()
         vm = query_viewmodel(
             request.user,
             query,
             form=form,
             run_query=show,
             rows=url_get_rows(request),
             page=url_get_page(request),
             message="Query created." if success else None,
             log=False,
         )
         if vm['form'].errors:
             self.object.delete()
         return self.render_template('explorer/query.html', vm)
     return ret