Exemple #1
0
def pt_base_html(request, project_id, template, params=None, obj=None):
    if request.method == 'POST':
        raise Http404

    params = params if params else {}

    dentries = request.path.split("/")
    verb = dentries[2] if len(dentries) > 3 else "comparison"

    default_params = {
        'projects':
        ProjectModel().pt_get_all(),
        'request':
        request,
        'verb':
        verb,
        'obj':
        obj,
        'pt_version':
        __pt_version__,
        'project':
        ProjectModel.pt_get_by_id(project_id),
        'api_ver':
        API_VER,
        'screens': [('Home', '/%d/home/' % project_id),
                    ('Regressions', '/%d/regression/' % project_id),
                    ('Comparisons', '/%d/comparison/' % project_id),
                    ('Jobs', '/%d/job/' % project_id),
                    ('Hosts', '/%d/hw_farm/' % project_id)]
    }
    params.update(default_params)
    return TemplateResponse(request, template, params)
Exemple #2
0
def pt_comparison_all_json(request, api_ver, project_id):
    class ComparisonJson(BaseDatatableView):
        # The model we're going to show
        model = ComparisonModel

        # define the columns that will be returned
        columns = [
            '', 'id', 'updated', 'project', 'env_node', 'suite_ver', 'title',
            'jobs', 'tests_total', 'tests_completed', 'tests_failed'
        ]

        # define column names that will be used in sorting
        # order is important and should be same as order of columns
        # displayed by datatables. For non sortable columns use empty
        # value like ''
        order_columns = [
            '', 'id', 'updated', 'project', 'env_node', 'suite_ver', 'title',
            'jobs', 'tests_total', 'tests_completed', 'tests_failed'
        ]

        # set max limit of records returned, this is used to protect our site if someone tries to attack our site
        # and make it return huge amount of data
        max_display_length = 5000

        def filter_queryset(self, qs):
            # filter by project & deleted only, search filtering is performed in-mem in prepare_results
            if int(project_id) != 0:
                qs = qs.filter(Q(project_id=project_id))

            qs = qs.filter(Q(deleted=False)).prefetch_related(
                "_jobs", "project")
            return qs

        def paging(self, qs):
            # disable default paging, it has stupid default=10. For client-side DataTables we need to return all
            return qs

        def prepare_results(self, qs):
            return ComparisonSimpleSerializer(qs, many=True).data

    if request.method == "POST":
        body_unicode = request.body.decode('utf-8')
        body = json.loads(body_unicode)

        try:
            ComparisonModel.pt_validate_json(body)
        except SuspiciousOperation as e:
            return HttpResponseBadRequest(e)

        cmp = ComparisonModel(project=ProjectModel.pt_get_by_id(project_id))
        try:
            cmp.pt_update(body)
        except SuspiciousOperation as e:
            return HttpResponseBadRequest(e)

        return JsonResponse({'id': cmp.id}, safe=False)

    return ComparisonJson.as_view()(request)
Exemple #3
0
def pt_comparison_all_json(request, api_ver, project_id):
    class ComparisonJson(BaseDatatableView):
        # The model we're going to show
        model = ComparisonModel

        # define the columns that will be returned
        columns = [
            '', 'id', 'updated', 'env_node', 'suite_ver', 'title', 'jobs',
            'tests_total', 'tests_completed', 'tests_failed'
        ]

        # define column names that will be used in sorting
        # order is important and should be same as order of columns
        # displayed by datatables. For non sortable columns use empty
        # value like ''
        order_columns = [
            '', 'id', 'updated', 'env_node', 'suite_ver', 'title', 'jobs',
            'tests_total', 'tests_completed', 'tests_failed'
        ]

        # set max limit of records returned, this is used to protect our site if someone tries to attack our site
        # and make it return huge amount of data
        max_display_length = 5000

        def render_column(self, row, column):
            # We want to render user as a custom column
            if column == 'tests_total':
                return '{0} {1}'.format(row.tests_total, row.tests_completed)
            else:
                return super(JobJson, self).render_column(row, column)

        def filter_queryset(self, qs):
            # use parameters passed in GET request to filter queryset

            # simple example:
            search = self.request.GET.get(u'search[value]', None)
            if search:
                qs = qs.filter(
                    Q(title__icontains=search)
                    | Q(suite_ver__icontains=search))

            if project_id != 0:
                qs = qs.filter(Q(project_id=project_id))

            qs = qs.filter(Q(deleted=False))

            return qs

        def prepare_results(self, qs):
            return ComparisonSimpleSerializer(qs, many=True).data

    if request.method == "POST":
        body_unicode = request.body.decode('utf-8')
        body = json.loads(body_unicode)

        try:
            ComparisonModel.pt_validate_json(body)
        except SuspiciousOperation as e:
            return HttpResponseBadRequest(e)

        cmp = ComparisonModel(project=ProjectModel.pt_get_by_id(project_id))
        try:
            cmp.pt_update(body)
        except SuspiciousOperation as e:
            return HttpResponseBadRequest(e)

        return JsonResponse({'id': cmp.id}, safe=False)

    return ComparisonJson.as_view()(request)