Esempio n. 1
0
def filter_detail(request, username, name):
    qfilter = get_object_or_404(TestRunFilter, owner__username=username, name=name)
    if not request.user.is_superuser:
        if not qfilter.public and qfilter.owner != request.user:
            raise PermissionDenied()

    if not qfilter.is_accessible_by(request.user):
        raise PermissionDenied()

    if not request.user.is_authenticated():
        subscription = None
    else:
        try:
            subscription = TestRunFilterSubscription.objects.get(
                user=request.user, filter=qfilter)
        except TestRunFilterSubscription.DoesNotExist:
            subscription = None
    view = FilterDetailView(request, qfilter, model=TestRun)
    if view.is_pass_table():
        table = FilterPassTable(view.get_table_data(), match_maker=view.match_maker)
    else:
        table = FilterSummaryTable(view.get_table_data(), match_maker=view.match_maker)
    RequestConfig(request, paginate={"per_page": table.length}).configure(table)
    return render_to_response(
        'dashboard_app/filter_detail.html', {
            'filter': qfilter,
            'subscription': subscription,
            'filter_table': table,
            "terms_data": table.prepare_terms_data(view),
            "search_data": table.prepare_search_data(view),
            "discrete_data": table.prepare_discrete_data(view),
            'bread_crumb_trail': BreadCrumbTrail.leading_to(
                filter_detail, name=name, username=username),
        }, RequestContext(request)
    )
Esempio n. 2
0
def filter_form(request, bread_crumb_trail, instance=None, is_copy=False):
    if request.method == 'POST':
        if instance:
            owner = instance.owner
        else:
            owner = request.user
        form = TestRunFilterForm(owner,
                                 request.POST,
                                 instance=instance,
                                 is_copy=is_copy)

        if form.is_valid():
            if 'save' in request.POST:
                qfilter = form.save()
                return HttpResponseRedirect(qfilter.get_absolute_url())
            else:
                c = request.POST.copy()
                c.pop('csrfmiddlewaretoken', None)
                view = FilterDetailView(request, form, model=TestRun)
                if view.is_pass_table():
                    table = FilterPassTable(view.get_table_data(),
                                            match_maker=view.match_maker)
                else:
                    table = FilterSummaryTable(view.get_table_data(),
                                               match_maker=view.match_maker)
                RequestConfig(request, paginate={
                    "per_page": table.length
                }).configure(table)
                template = loader.get_template(
                    'dashboard_app/filter_preview.html')
                return HttpResponse(
                    template.render(
                        {
                            'bread_crumb_trail': bread_crumb_trail,
                            'form': form,
                            'table': table,
                        },
                        request=request))
    else:
        form = TestRunFilterForm(request.user,
                                 instance=instance,
                                 is_copy=is_copy)

    filter_name = None
    if is_copy:
        filter_name = instance.name
        instance.name = None
    template = loader.get_template('dashboard_app/filter_add.html')
    return HttpResponse(
        template.render(
            {
                'bread_crumb_trail': bread_crumb_trail,
                'form': form,
                'is_copy': is_copy,
                'filter_name': filter_name,
            },
            request=request))
Esempio n. 3
0
def filter_detail(request, username, name):
    qfilter = get_object_or_404(TestRunFilter,
                                owner__username=username,
                                name=name)
    if not request.user.is_superuser:
        if not qfilter.public and qfilter.owner != request.user:
            raise PermissionDenied()

    if not qfilter.is_accessible_by(request.user):
        raise PermissionDenied()

    if not request.user.is_authenticated():
        subscription = None
    else:
        try:
            subscription = TestRunFilterSubscription.objects.get(
                user=request.user, filter=qfilter)
        except TestRunFilterSubscription.DoesNotExist:
            subscription = None
    view = FilterDetailView(request, qfilter, model=TestRun)
    if view.is_pass_table():
        table = FilterPassTable(view.get_table_data(),
                                match_maker=view.match_maker)
    else:
        table = FilterSummaryTable(view.get_table_data(),
                                   match_maker=view.match_maker)
    RequestConfig(request, paginate={
        "per_page": table.length
    }).configure(table)
    template = loader.get_template('dashboard_app/filter_detail.html')
    return HttpResponse(
        template.render(
            {
                'filter':
                qfilter,
                'subscription':
                subscription,
                'filter_table':
                table,
                "terms_data":
                table.prepare_terms_data(view),
                "search_data":
                table.prepare_search_data(view),
                "discrete_data":
                table.prepare_discrete_data(view),
                'bread_crumb_trail':
                BreadCrumbTrail.leading_to(
                    filter_detail, name=name, username=username),
            },
            request=request))