Beispiel #1
0
def execute(request, visualization_id):
    visualization = get_object_or_404(Visualization,
                                      pk=visualization_id,
                                      account=request.user.account)
    err = None
    try:
        job = Job.objects.filter(
            completed_at__isnull=False,
            query__visualization=visualization,
            cached_until__gte=timezone.now()).order_by('-start_at')[:1].get()
        if job.query_checksum != job.query.checksum:
            err, job = execute_query(request.user, visualization)
    except Job.DoesNotExist:
        err, job = execute_query(request.user, visualization)
    if err:
        return HttpResponse(err, 'application/json', status=404)
    job_request = JobRequest(created_by=request.user, job=job)
    if request.GET.get('dashboard'):
        dashboard = get_object_or_404(Dashboard,
                                      pk=request.GET.get('dashboard'),
                                      account=request.user.account)
        job_request.dashboard = dashboard
    job_request.save()
    return HttpResponse(
        json.dumps(
            dict(url=job.cache_url,
                 export_url=request.build_absolute_uri(
                     reverse('jobs_export', kwargs=dict(job_id=job.id))))),
        'application/json')
Beispiel #2
0
def execute(request, visualization_id):
    visualization = get_object_or_404(Visualization, pk=visualization_id, account=request.user.account)
    err = None
    try:
        job = Job.objects.filter(completed_at__isnull=False, query__visualization=visualization, cached_until__gte=timezone.now()).order_by('-start_at')[:1].get()
        if job.query_checksum != job.query.checksum:
            err, job = execute_query(request.user, visualization)
    except Job.DoesNotExist:
        err, job = execute_query(request.user, visualization)
    if err:
        return HttpResponse(err, 'application/json', status=404)
    job_request = JobRequest(created_by=request.user, job=job)
    if request.GET.get('dashboard'):
        dashboard = get_object_or_404(Dashboard, pk=request.GET.get('dashboard'), account=request.user.account)
        job_request.dashboard = dashboard
    job_request.save()
    return HttpResponse(json.dumps(dict(url=job.cache_url, export_url=request.build_absolute_uri(reverse('jobs_export', kwargs=dict(job_id=job.id))))), 'application/json')
Beispiel #3
0
def execute_anonymous(request, visualization_id, token):
    visualization = get_object_or_404(
        Visualization, Q(pk=visualization_id),
        Q(sharedvisualization__token=token)
        | Q(dashboardentity__dashboard__shareddashboard__token=token))
    try:
        shared_entity = SharedVisualization.objects.get(
            visualization__id=visualization_id, token=token)
    except SharedVisualization.DoesNotExist:
        try:
            shared_entity = SharedDashboard.objects.get(
                dashboard__dashboardentity__visualization__id=visualization_id,
                token=token)
        except SharedDashboard.DoesNotExist:
            return render(request, 'errors/403.html', status=403)
    err = None
    try:
        job = Job.objects.filter(
            completed_at__isnull=False,
            query__visualization=visualization,
            cached_until__gte=timezone.now()).order_by('-start_at')[:1].get()
        if job.query_checksum != job.query.checksum:
            err, job = execute_query(shared_entity.created_by, visualization)
    except Job.DoesNotExist:
        err, job = execute_query(shared_entity.created_by, visualization)
    if err:
        return HttpResponse(err, 'application/json', status=404)
    job_request = JobRequest(created_by=shared_entity.created_by, job=job)
    #    if request.GET.get('dashboard'):
    #        dashboard = get_object_or_404(Dashboard, pk=request.GET.get('dashboard'), account=request.user.account)
    #        job_request.dashboard = dashboard
    job_request.save()
    return HttpResponse(
        json.dumps(
            dict(url=job.cache_url,
                 export_url=request.build_absolute_uri(
                     reverse('jobs_export', kwargs=dict(job_id=job.id))))),
        'application/json')
Beispiel #4
0
def execute_anonymous(request, visualization_id, token):
    visualization = get_object_or_404(Visualization, Q(pk=visualization_id), Q(sharedvisualization__token=token) | Q(dashboardentity__dashboard__shareddashboard__token=token))
    try:
        shared_entity = SharedVisualization.objects.get(visualization__id=visualization_id, token=token)
    except SharedVisualization.DoesNotExist:
        try:
            shared_entity = SharedDashboard.objects.get(dashboard__dashboardentity__visualization__id=visualization_id, token=token)
        except SharedDashboard.DoesNotExist:
            return render(request, 'errors/403.html', status=403)
    err = None
    try:
        job = Job.objects.filter(completed_at__isnull=False, query__visualization=visualization, cached_until__gte=timezone.now()).order_by('-start_at')[:1].get()
        if job.query_checksum != job.query.checksum:
            err, job = execute_query(shared_entity.created_by, visualization)
    except Job.DoesNotExist:
        err, job = execute_query(shared_entity.created_by, visualization)
    if err:
        return HttpResponse(err, 'application/json', status=404)
    job_request = JobRequest(created_by=shared_entity.created_by, job=job)
#    if request.GET.get('dashboard'):
#        dashboard = get_object_or_404(Dashboard, pk=request.GET.get('dashboard'), account=request.user.account)
#        job_request.dashboard = dashboard
    job_request.save()
    return HttpResponse(json.dumps(dict(url=job.cache_url, export_url=request.build_absolute_uri(reverse('jobs_export', kwargs=dict(job_id=job.id))))), 'application/json')