def prepare_pagination_bench_stacked(project_entry, branch_entry,
                                     bench_def_entry, worker_entry,
                                     page_indices):
    """ Creates pagination object for workers from indices """
    pagination = {}
    pagination['prev'] = ViewUrlGenerator.get_benchmark_execution_stacked_url(
        project_entry, branch_entry, bench_def_entry, worker_entry,
        page_indices['prev'])

    pagination[
        'current'] = ViewUrlGenerator.get_benchmark_execution_stacked_url(
            project_entry, branch_entry, bench_def_entry, worker_entry,
            page_indices['current'])

    pagination['next'] = ViewUrlGenerator.get_benchmark_execution_stacked_url(
        project_entry, branch_entry, bench_def_entry, worker_entry,
        page_indices['next'])

    pagination['pages'] = []
    for index in page_indices['page_indices']:
        pag = {}
        pag['index'] = index
        pag['url'] = ViewUrlGenerator.get_benchmark_execution_stacked_url(
            project_entry, branch_entry, bench_def_entry, worker_entry, index)
        pag['is_current'] = (index == page_indices['current'])
        pagination['pages'].append(pag)
    return pagination
Example #2
0
def get_project_single_branch_links(request, project_id, branch_id):
    """ Display single branch links """
    if request.method != 'GET':
        return res.get_template_data(request, 'presenter/not_found.html', {})

    project_entry = GitProjectEntry.objects.filter(id=project_id).first()
    if project_entry is None:
        return res.get_template_data(request, 'presenter/not_found.html', {})

    branch_entry = GitBranchEntry.objects.filter(
        id=branch_id, project=project_entry).first()
    if branch_entry is None:
        return res.get_template_data(request, 'presenter/not_found.html', {})

    def_entries = BenchmarkDefinitionEntry.objects.all()
    worker_entries = WorkerEntry.objects.all()

    links = []

    for def_entry in def_entries:
        definition = {}
        definition['name'] = def_entry.name
        definition['id'] = def_entry.id
        definition['workers'] = []

        for worker_entry in worker_entries:
            worker = {}
            worker['name'] = worker_entry.name
            worker['uuid'] = worker_entry.uuid
            worker[
                'stacked_benchmarks'] = ViewUrlGenerator.get_benchmark_execution_stacked_url(
                    project_id, branch_id, def_entry.id, worker_entry.id, 1)
            definition['workers'].append(worker)

        links.append(definition)

    branch_names_and_orders = GitController.get_branch_names_and_order_values(
        project_entry)
    update_order_selection = []
    for name_and_order in branch_names_and_orders:
        obj = {}
        obj['name'] = name_and_order['name']
        obj['order'] = name_and_order['order']
        obj['current'] = name_and_order['id'] == branch_entry.id
        obj['url'] = {}
        obj['url']['update'] = ViewUrlGenerator.get_branch_update_order_url(
            branch_id, project_id, obj['order'])
        update_order_selection.append(obj)

    data = {}
    data['branch'] = {}
    data['branch']['name'] = branch_entry.name
    data['branch']['order'] = branch_entry.order
    data['branch']['url'] = {}
    data['branch']['url'][
        'single'] = ViewUrlGenerator.get_project_branch_single_url(
            project_id, branch_id)
    data['branch']['links'] = links
    data['branch']['update_order_selection'] = update_order_selection
    data['menu'] = ViewPrepareObjects.prepare_menu_for_html([])

    return res.get_template_data(request,
                                 'presenter/project_branch_links.html', data)