Exemplo n.º 1
0
def samples_list(request, search_string=None):
    context = {}

    lookup = request.GET.get('lookup', None)

    # for now, look up will just forward to detail view
    if lookup:
        return sample_detail(request, lookup.strip())

    # init bamboo with user's URL
    project = request.user.project
    connection = Connection(get_bamboo_url(project))
    main_dataset = CachedDataset(get_bamboo_dataset_id(project),
                                 connection=connection)

    submissions_list = main_dataset.get_data(cache=True, cache_expiry=60,
                                             order_by='-end')

    paginator = FlynsarmyPaginator(submissions_list, 20, adjacent_pages=2)

    page = request.GET.get('page')
    try:
        submissions = paginator.page(page)
    except PageNotAnInteger:
        submissions = paginator.page(1)
    except EmptyPage:
        submissions = paginator.page(paginator.num_pages)

    context.update({'samples': submissions,
                    'lookup': lookup})

    return render(request, 'samples_list.html', context)
Exemplo n.º 2
0
def list_submissions(request):

    context = {'category': 'submissions'}

    connection = Connection(get_bamboo_url(request.user.project))
    main_dataset = CachedDataset(get_bamboo_dataset_id(request.user.project),
                                 connection=connection)
    submissions_list = main_dataset.get_data(cache=True, cache_expiry=VSHORT)

    for submission in submissions_list:
        submission.update(detailed_id_dict(submission, prefix='teacher_'))

    paginator = FlynsarmyPaginator(submissions_list, 10, adjacent_pages=2)

    page = request.GET.get('page')
    try:
        submissions = paginator.page(page)
    except PageNotAnInteger:
        submissions = paginator.page(1)
    except EmptyPage:
        submissions = paginator.page(paginator.num_pages)

    context.update({'submissions': submissions})

    return render(request, 'list_submissions.html', context)
Exemplo n.º 3
0
def list_teachers(request):

    context = {'category': 'teachers',
               'schoolcat': '%s|%s'
               % (request.user.project.slug, 'school_names')}

    # redirect to a teacher's page if jump_to matches one.
    jump_to = request.GET.get('jump_to', None)

    connection = Connection(get_bamboo_url(request.user.project))
    teacher_dataset = CachedDataset(get_bamboo_dataset_id(request.user.project,
                                                          is_registration=True),
                                 connection=connection)

    teachers_list = teacher_dataset.get_data(cache=True, cache_expiry=MEDIUM)

    ''' Not using the `group` method of bamboo here as it's innefiscient
        for our use case: it would request multiple inner-loops and uglify
        the templates.

        Instead, we grab the raw list of teachers and then group them
        by the school name resulting in a 2-dim list.

        While it works, I believe the pagination is done at school level
        making it useless for cases where there are many teachers per school '''

    # school list container ; each key should contain list of teachers.
    school_list = {}

    for teacher in teachers_list:
        if not teacher.get('barcode', None):
            continue

        teacher.update(detailed_id_dict(teacher))

        # requested teacher exists ; redirect
        if teacher.get('sid_') == jump_to:
            return redirect(detail_teacher, uid=teacher.get('uid_'))

        if teacher.get('school') in school_list:
            school_list.get(teacher.get('school')).append(teacher)
        else:
            school_list[teacher.get('school')] = [teacher, ]

    paginator = FlynsarmyPaginator(school_list.values(), 10, adjacent_pages=2)

    page = request.GET.get('page', 1)
    try:
        schools = paginator.page(page)
    except PageNotAnInteger:
        schools = paginator.page(1)
    except EmptyPage:
        schools = paginator.page(paginator.num_pages)

    # context.update({'teachers': teachers})
    context.update({'schools': schools})

    return render(request, 'list_teachers.html', context)