コード例 #1
0
def query_editor(request, query_id=None):
    form = QueryForm(request.POST) if request.method == 'POST' else QueryForm()
    query = None
    if query_id is not None:
        try:
            query = Query.objects.get(id=query_id)
        except:
            pass
        if not query:
            return HttpResponseRedirect("/sql_dashboards/query/")
    if request.method == "GET" and query_id is not None:
        form = QueryForm(instance=query)
    elif request.method == "POST" and ("run" in request.POST or "save" in request.POST or "run_save" in request.POST):
        form = QueryForm(request.POST, instance=query) if query else QueryForm(request.POST)
        if form.is_valid():
            query = form.save(commit=("save" in request.POST or "run_save" in request.POST), user=request.user)

        if query and ("run" in request.POST or "run_save" in request.POST):
            query_executed = True
            print(request.POST.keys())
            custom_data = dict([(k, v.initial) for k, v in CustomQueryForm(query).fields.items()]) if query.custom else None
            query.getAll(custom_data=custom_data)
    if request.method == "POST" and "save" in request.POST:
        return HttpResponseRedirect("/sql_dashboards/query/edit/%s" % query.id)
    return render_to_response("django_sql_dashboards/query_editor.html", locals(), RequestContext(request))
コード例 #2
0
def query_new(request):
    if request.method == "POST":
        form = QueryForm(request.POST.copy())
        if form.is_valid():
            query = form.save(commit=False)
            query.user = request.user
            query.save()
            return redirect('pred_list')
    else:
        form = QueryForm()
    return render(request, 'deep_stylo/query_edit.html', {'form': form})
コード例 #3
0
ファイル: views.py プロジェクト: csvenja/coursys
def new_query(request, report):
    report = get_object_or_404(Report, slug=report) 

    if request.method == 'POST':
        form = QueryForm(request.POST)
        if form.is_valid():
            f = form.save(commit=False)
            f.report = report
            f.created_by = request.user.username
            f.save()
            messages.success(request, "Created new report query: %s" % f.query)
            return HttpResponseRedirect(reverse('reports.views.view_report', kwargs={'report':report.slug}))
    else:
        form = QueryForm()

    return render(request, 'reports/new_query.html', {'form': form, 'report': report })
コード例 #4
0
ファイル: views.py プロジェクト: tedkirkpatrick/coursys
def new_query(request, report):
    report = get_object_or_404(Report, slug=report) 

    if request.method == 'POST':
        form = QueryForm(request.POST)
        if form.is_valid():
            f = form.save(commit=False)
            f.report = report
            f.created_by = request.user.username
            f.save()
            messages.success(request, "Created new report query: %s" % f.query)
            return HttpResponseRedirect(reverse('reports.views.view_report', kwargs={'report':report.slug}))
    else:
        form = QueryForm()

    return render(request, 'reports/new_query.html', {'form': form, 'report': report })
コード例 #5
0
ファイル: views.py プロジェクト: csvenja/coursys
def edit_query(request, report, query_id):
    report = get_object_or_404(Report, slug=report)
    query = get_object_or_404(Query, id=int(query_id))

    if request.method == 'POST':
        form = QueryForm(request.POST)
        if form.is_valid():
            f = form.save(commit=False)
            f.report = report
            f.created_by = request.user.username
            f.save()
            query.delete()
            messages.success(request, "Edited query: %s" % f.query)
            return HttpResponseRedirect(reverse('reports.views.view_report', kwargs={'report':report.slug}))
    else:
        form = QueryForm(instance=query)

    return render(request, 'reports/edit_query.html', {'form': form, 'report': report, 'query_id':query_id })
コード例 #6
0
ファイル: views.py プロジェクト: tedkirkpatrick/coursys
def edit_query(request, report, query_id):
    report = get_object_or_404(Report, slug=report)
    query = get_object_or_404(Query, id=int(query_id))

    if request.method == 'POST':
        form = QueryForm(request.POST)
        if form.is_valid():
            f = form.save(commit=False)
            f.report = report
            f.created_by = request.user.username
            f.save()
            query.delete()
            messages.success(request, "Edited query: %s" % f.query)
            return HttpResponseRedirect(reverse('reports.views.view_report', kwargs={'report':report.slug}))
    else:
        form = QueryForm(instance=query)

    return render(request, 'reports/edit_query.html', {'form': form, 'report': report, 'query_id':query_id })
コード例 #7
0
ファイル: views.py プロジェクト: lasarux/PollXpress
def query_edit(request, query_id=False, template='poll/query_form.html'):
    if query_id:
        instance = Query.objects.get(id=query_id)
    else:
        instance = None

    if request.method == 'POST':
        form = QueryForm(request.POST, instance=instance)
        if form.is_valid():
            query = form.save(commit=False)
            if not query_id:
                query.user = request.user
            query.save()
            messages.add_message(request, messages.SUCCESS,
                ugettext("Successfully saved query: %s") % query.name)
            return HttpResponseRedirect(reverse('query-view', args=[query.id]))
        
    form = QueryForm(instance=instance)
    data = {'form': form}
    return render_to_response(template, data, context_instance=RequestContext(request))