Exemplo n.º 1
0
def tutorial_content(request,
                     template='statistics/templates/statistics_content.html'):
    header = {
        1: SortableHeader('# ', False),
        2: SortableHeader('tutorial_detail__tutorial', True, 'Tutorial'),
        3: SortableHeader('tutorial_detail__foss__foss', True, 'FOSS Course'),
        4: SortableHeader('tutorial_detail__level', True, 'Level'),
        5: SortableHeader('language__name', True, 'Language'),
        6: SortableHeader('publish_at', True, 'Date Published')
    }

    published_tutorials_set = TutorialResource.objects.filter(
        Q(status=1) | Q(status=2))

    raw_get_data = request.GET.get('o', None)
    tutorials = get_sorted_list(request, published_tutorials_set, header,
                                raw_get_data)
    ordering = get_field_index(raw_get_data)

    tutorials_filter = CreationStatisticsFilter(request.GET,
                                                queryset=tutorials)
    # whenever publish date filter is applied there is a table join, resulting a duplicate entry for tutorials
    # because single tutorial might have multiple pushish objects
    qs = tutorials_filter.qs.distinct()
    no_of_foss = qs.filter().values(
        'tutorial_detail__foss_id').distinct().count()
    print('************ no of foss: ', no_of_foss)

    context = {}

    context['form'] = tutorials_filter.form

    # display information table across multiple pages
    paginator = Paginator(qs, 100)
    page = request.GET.get('page')
    try:
        tutorials = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        tutorials = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        tutorials = paginator.page(paginator.num_pages)
    context['tutorials'] = tutorials
    context['tutorial_num'] = tutorials.paginator.count
    context['header'] = header
    context['ordering'] = ordering
    context['no_of_foss'] = no_of_foss

    return render(request, template, context)
Exemplo n.º 2
0
def allocate_tutorial(request, sel_status):
    context = {}
    global global_req
    global_req = request
    print "status : ", sel_status
    user = request.user
    if not (user.is_authenticated() and (is_contributor(user))):
        if not (user.is_authenticated() and (is_language_manager(user))):
            print "AAAAAAAAAAA"
        else:
            print "BBBBBBBBBBBBBBBBBB"
            raise PermissionDenied()

    active = sel_status
    final_query = None
    fosses = []
    lang_qs = None

    if sel_status == 'completed':
        header = {
            1: SortableHeader('# ', False),
            2: SortableHeader('tutorial_detail__foss__foss', True,
                              'FOSS Course'),
            3: SortableHeader('Tutorial', False),
            4: SortableHeader('language__name', False, 'Language'),
            5: SortableHeader('created', False, 'Date Created'),
            6: SortableHeader('script_user_id', False, 'User Details'),
        }

        status = 4
        final_query = TutorialResource.objects.filter(script_status=status)

    elif sel_status == 'available':
        header = {
            1: SortableHeader('Tutorial Level', False),
            2: SortableHeader('Order Id', False),
            3: SortableHeader('Tutorial', False),
            4: SortableHeader('language__name', True, 'Language'),
            5: SortableHeader('Bid', False),
        }

        lang_qs = Language.objects.filter(id__in=RoleRequest.objects.filter(
            user=request.user, status=1, role_type=0).exclude(
                language_id=22).values('language'))
        status = 4
        final_query = TutorialsAvailable.objects.filter(
            language__in=lang_qs).order_by('tutorial_detail__foss__foss',
                                           'tutorial_detail__level',
                                           'language',
                                           'tutorial_detail__order')
        unique_foss = TutorialsAvailable.objects.filter(
            language__in=lang_qs).values('tutorial_detail__foss__foss',
                                         'language',
                                         'tutorial_detail__level').distinct()

    elif sel_status == 'ongoing':
        header = {
            1:
            SortableHeader('# ', False),
            2:
            SortableHeader('tutorial_detail__level', True, 'Tutorial Level'),
            3:
            SortableHeader('tutorial_detail__foss__foss', True, 'FOSS Course'),
            4:
            SortableHeader('Tutorial', False),
            5:
            SortableHeader('language__name', False, 'Language'),
            6:
            SortableHeader('script_user_id', False, 'User ID'),
            7:
            SortableHeader('tutorial_detail_id__tutorialresource__updated',
                           True, 'Bid Date'),
            8:
            SortableHeader('Submission Date', False),
            9:
            SortableHeader('Extension', False),
            10:
            SortableHeader('Revoke ', False)
        }

        status = 4
        final_query = TutorialResource.objects.filter(
            video_user=request.user.id,
            assignment_status=1).exclude(language_id=22)
        stale_tuts = check_stale_tuts(request, final_query)
    else:
        raise PermissionDenied()

    extension = []
    pub_tutorials_set = final_query
    context['datetoday'] = datetime.now()
    raw_get_data = request.GET.get('o', None)
    tutorials = get_sorted_list(request, pub_tutorials_set, header,
                                raw_get_data)
    ordering = get_field_index(raw_get_data)
    tutorials = CreationStatisticsFilter(request.GET, queryset=tutorials)
    bid_count = TutorialResource.objects.filter(
        video_user=request.user,
        assignment_status=1).exclude(language_id=22).count()
    print "Bid Count", bid_count
    context['bid_count'] = bid_count
    context['tutorials_count'] = final_query.count()
    if final_query.count() > 0:
        context['perc'] = float(bid_count * 100) / float(final_query.count())
    form = tutorials.form
    #form.fields['tutorial_detail__foss'].queryset = final_query
    #print "Currect FOSSES : ", unique_foss.tutorial_detail_id
    if lang_qs:
        form.fields['language'].queryset = lang_qs

    context['form'] = form

    # Pagination
    paginator = Paginator(tutorials, 50)
    try:
        page = int(request.GET.get('page', '1'))
    except:
        page = int(request.GET.get('page'))

    try:
        posts = paginator.page(page)

    except (EmptyPage, PageNotAnInteger):
        posts = paginator.page(paginator.num_pages)

    global c_sel_lang
    c_sel_lang = request.GET.get('language')
    print "Language : ", request.GET.get('language')

    context['tutorial_num'] = posts
    context['header'] = header
    context['ordering'] = ordering
    context['status'] = active

    context['counter'] = itertools.count(1)
    if user.groups.filter(Q(name='Language-Manager')):
        return render(request,
                      'statistics/templates/allocate_tutorial_manager.html',
                      context)
    else:
        return render(request, 'statistics/templates/allocate_tutorial.html',
                      context)