Beispiel #1
0
def series_foss(request):
    '''
    Get all the media testimonials which are set to not 
    show on home page and display along the form to display the tutorials.
    '''
    form = SeriesTutorialSearchForm()
    collection = None
    # Get all the video / audio testimonials in series
    foss_list = TutorialResource.objects.filter(
        Q(status=1) | Q(status=2),
        language__name='English',
        tutorial_detail__foss__show_on_homepage=0).values_list(
            'tutorial_detail__foss__id').annotate().distinct()
    collection = MediaTestimonials.objects.filter(
        foss__id__in=foss_list).values("foss__foss", "content", "created",
                                       "foss", "foss_id", "id", "path", "user",
                                       "workshop_details").order_by('-created')

    if collection:
        page = request.GET.get('page')
        collection = get_page(collection, page, limit=6)

    add_button_show = False
    if request.user.has_perm('events.add_testimonials'):
        add_button_show = True
    context = {}
    context['form'] = form
    context['collection'] = collection
    context['media_url'] = settings.MEDIA_URL
    context['add_button_show'] = add_button_show
    return render(request, 'spoken/templates/series_foss_list.html', context)
Beispiel #2
0
def foss_testimonials(request, foss):
    '''
    Responds with `/testimonial` page to display all the 
    text / video / audio template.
    '''
    collection = None
    collection = MediaTestimonials.objects.filter(foss__foss=foss).values(
        "foss__foss", "content", "created", "foss", "foss_id", "id", "path",
        "user").order_by('-created')
    if foss == "General":
        #excludng biogas, koha and health series from the list
        exclude_foss_list = [82, 100, 70]
        collection = MediaTestimonials.objects.all().exclude(
            foss__id__in=exclude_foss_list).values("foss__foss", "content",
                                                   "created", "foss",
                                                   "foss_id", "id", "path",
                                                   "user").order_by('-created')

    if collection:
        page = request.GET.get('page')
        collection = get_page(collection, page, limit=6)

    context = {}
    context['collection'] = collection
    context['media_url'] = settings.MEDIA_URL
    context['foss'] = foss
    context.update(csrf(request))
    return render(request,
                  'spoken/templates/testimonial/mediatestimonials.html',
                  context)
Beispiel #3
0
 def get_context_data(self, **kwargs):
   context = super(StudentListView, self).get_context_data(**kwargs)
   collectionSet = self.queryset = Student.objects.filter(
     id__in = StudentMaster.objects.filter(
       batch_id=self.batch.id,
       moved=False
     ).values_list(
       'student'
     )
   )
   header = {
       1: SortableHeader('#', False),
       2: SortableHeader('', False, 'Department'),
       3: SortableHeader('', False, 'Year'),
       4: SortableHeader('user__first_name', True, 'First Name'),
       5: SortableHeader('user__last_name', True, 'Last Name'),
       6: SortableHeader('user__email', True, 'Email'),
       7: SortableHeader('gender', True, 'Gender'),
       8: SortableHeader('', False, 'Status'),
       9: SortableHeader('', False, ''),
   }
   
   raw_get_data = self.request.GET.get('o', None)
   collection = get_sorted_list(self.request, collectionSet, header, raw_get_data)
   ordering = get_field_index(raw_get_data)
   #collection = TrainingFilter(self.request.GET, user = user, queryset=collection)
   
   page = self.request.GET.get('page')
   collection = get_page(collection, page)
   context['object_list'] = collection
   context['header'] = header
   context['ordering'] = ordering
   context['batch'] = self.batch
   return context
Beispiel #4
0
def news(request, cslug):
    try:
        newstype = NewsType.objects.get(slug = cslug)
        collection = None
        latest = None
        sortAllowedCategory = ['articles-on-university-tie-ups-workshops', 'articles-on-spoken-tutorial-project']
        if request.GET and 'latest' in request.GET and int(request.GET.get('latest')) == 1 and (cslug in sortAllowedCategory):
            collection = newstype.news_set.order_by('weight')
        else:
            collection = newstype.news_set.order_by('-created')
            latest = True
        collection = NewsStateFilter(request.GET, queryset=collection, news_type_slug=cslug)
        form = collection.form
        if collection:
            page = request.GET.get('page')
            collection = get_page(collection, page)
        context = {
            'form' : form,
            'collection' : collection,
            'category' : cslug,
            'newstype' : newstype,
            'latest' : latest,
            'sortAllowedCategory' : sortAllowedCategory
        }
        context.update(csrf(request))
        return render(request, 'spoken/templates/news/index.html', context)
    
    except Exception, e:
        print e
        raise Http404('You are not allowed to view this page')
Beispiel #5
0
def series_tutorial_search(request):
    context = {}
    collection = None
    form = SeriesTutorialSearchForm()
    foss_get = ''
    show_on_homepage = False
    queryset = TutorialResource.objects.filter(Q(status=1) | Q(status=2), tutorial_detail__foss__show_on_homepage=show_on_homepage)

    if request.method == 'GET' and request.GET:
        form = SeriesTutorialSearchForm(request.GET)
        if form.is_valid():
            foss_get = request.GET.get('search_otherfoss', '')
            language_get = request.GET.get('search_otherlanguage', '')
            if foss_get and language_get:
                collection = queryset.filter(tutorial_detail__foss__foss=foss_get, language__name=language_get).order_by('tutorial_detail__level', 'tutorial_detail__order')

            elif foss_get:
                collection = queryset.filter(tutorial_detail__foss__foss=foss_get).order_by('tutorial_detail__level', 'tutorial_detail__order', 'language__name')
            elif language_get:
                collection = queryset.filter(language__name=language_get).order_by('tutorial_detail__foss__foss', 'tutorial_detail__level', 'tutorial_detail__order')
            else:
                collection = queryset.filter(tutorial_detail__foss__id__in=FossCategory.objects.values('id'), language__id__in=Language.objects.values('id')).order_by('tutorial_detail__foss__foss', 'language__name', 'tutorial_detail__level', 'tutorial_detail__order')
    else:
        foss = queryset.filter(language__name='English').values('tutorial_detail__foss__foss').annotate(Count('id')).values_list('tutorial_detail__foss__foss').distinct().order_by('?')[:1].first()
        collection = queryset.filter(tutorial_detail__foss__foss=foss[0], language__name='English')
        foss_get = foss[0]
    if collection:
        page = request.GET.get('page')
        collection = get_page(collection, page)
    context['form'] = form
    context['collection'] = collection
    context['SCRIPT_URL'] = settings.SCRIPT_URL
    context['current_foss'] = foss_get
    return render(request, 'spoken/templates/series_tutorial_search.html', context)
Beispiel #6
0
def news(request, cslug):
    try:
        newstype = NewsType.objects.get(slug=cslug)
        collection = None
        latest = None
        sortAllowedCategory = ['articles-on-university-tie-ups-workshops',
                               'articles-on-spoken-tutorial-project', 'events-from-iitb', 'events-across-india']
        if request.GET and 'latest' in request.GET and int(request.GET.get('latest')) == 1 and (cslug in sortAllowedCategory):
            collection = newstype.news_set.order_by('weight', '-created')
        else:
            collection = newstype.news_set.order_by('-created')
            latest = True
        collection = NewsStateFilter(request.GET, queryset=collection, news_type_slug=cslug)
        form = collection.form
        if collection:
            page = request.GET.get('page')
            collection = get_page(collection, page)
        context = {
            'form': form,
            'collection': collection,
            'category': cslug,
            'newstype': newstype,
            'latest': latest,
            'sortAllowedCategory': sortAllowedCategory
        }
        context.update(csrf(request))
        return render(request, 'spoken/templates/news/index.html', context)

    except Exception as e:
        print e
        raise Http404('You are not allowed to view this page')
Beispiel #7
0
def tutorial_search(request):
    context = {}
    collection = None
    form = TutorialSearchForm()
    foss_get = ''
    if request.method == 'GET' and request.GET:
        form = TutorialSearchForm(request.GET)
        if form.is_valid():
            foss_get = request.GET.get('search_foss', '')
            language_get = request.GET.get('search_language', '')
            if foss_get and language_get:
                collection = TutorialResource.objects.filter(Q(status = 1) | Q(status = 2), tutorial_detail__foss__foss = foss_get, language__name = language_get).order_by('tutorial_detail__level', 'tutorial_detail__order')
            elif foss_get:
                collection = TutorialResource.objects.filter(Q(status = 1) | Q(status = 2), tutorial_detail__foss__foss = foss_get).order_by('tutorial_detail__level', 'tutorial_detail__order', 'language__name')
            elif language_get:
                collection = TutorialResource.objects.filter(Q(status = 1) | Q(status = 2), language__name = language_get).order_by('tutorial_detail__foss__foss', 'tutorial_detail__level', 'tutorial_detail__order')
            else:
                collection = TutorialResource.objects.filter(Q(status = 1) | Q(status = 2), tutorial_detail__foss__id__in = FossCategory.objects.values('id'), language__id__in = Language.objects.values('id')).order_by('tutorial_detail__foss__foss', 'language__name', 'tutorial_detail__level', 'tutorial_detail__order')
    else:
        foss = TutorialResource.objects.filter(Q(status = 1) | Q(status = 2), language__name = 'English').values('tutorial_detail__foss__foss').annotate(Count('id')).values_list('tutorial_detail__foss__foss').distinct().order_by('?')[:1].first()
        collection = TutorialResource.objects.filter(Q(status = 1) | Q(status = 2), tutorial_detail__foss__foss = foss[0], language__name = 'English')
        foss_get = foss[0]
    if collection:
        page = request.GET.get('page')
        collection = get_page(collection, page)
    context['form'] = form
    context['collection'] = collection
    context['SCRIPT_URL'] = settings.SCRIPT_URL
    context['current_foss'] = foss_get
    return render(request, 'spoken/templates/tutorial_search.html', context)
Beispiel #8
0
def keyword_search(request):
    context = {}
    keyword = ''
    collection = None
    correction = None
    conjunction_words = ['a', 'i']
    form = TutorialSearchForm()
    if request.method == 'GET' and 'q' in request.GET and request.GET[
            'q'] != '':
        form = KeywordSearchForm(request.GET)
        if form.is_valid():
            keyword = request.GET['q'].lower()
            collection, correction = search_for_results(keyword)

    if collection:
        page = request.GET.get('page')
        collection = get_page(collection, page)

    context = {}
    context['form'] = KeywordSearchForm()
    context['collection'] = collection
    context['correction'] = correction
    context['keywords'] = keyword
    context.update(csrf(request))
    return render(request, 'spoken/templates/keyword_search.html', context)
Beispiel #9
0
def news(request, cslug):
    try:
        newstype = NewsType.objects.get(slug = cslug)
        collection = None
        latest = None
        if request.GET and 'latest' in request.GET and int(request.GET.get('latest') == 0 and cslug == 'media-articles'):
            collection = newstype.news_set.order_by('weight', '-created')
        else:
            collection = newstype.news_set.order_by('-created')
            latest = True
            
        if collection:
            page = request.GET.get('page')
            collection = get_page(collection, page)
        context = {
            'collection' : collection,
            'category' : cslug,
            'newstype' : newstype,
            'latest' : latest,
        }
        context.update(csrf(request))
        return render(request, 'spoken/templates/news/index.html', context)
    
    except Exception, e:
        print e
        raise Http404('You are not allowed to view this page')
Beispiel #10
0
def news(request, cslug):
    try:
        newstype = NewsType.objects.get(slug=cslug)
        collection = None
        latest = None
        if request.GET and 'latest' in request.GET and int(
                request.GET.get('latest') == 0 and cslug == 'media-articles'):
            collection = newstype.news_set.order_by('weight', '-created')
        else:
            collection = newstype.news_set.order_by('-created')
            latest = True

        if collection:
            page = request.GET.get('page')
            collection = get_page(collection, page)
        context = {
            'collection': collection,
            'category': cslug,
            'newstype': newstype,
            'latest': latest,
        }
        context.update(csrf(request))
        return render(request, 'spoken/templates/news/index.html', context)

    except Exception, e:
        print e
        raise Http404('You are not allowed to view this page')
Beispiel #11
0
def testimonials(request, testimonial_type="text"):
    '''
    Responds with `/testimonial` page to display all the 
    text / video / audio template.
    '''
    collection = None
    if testimonial_type == "text":
        collectionSet = Testimonials.objects.all().order_by('-created')
    else:
        collectionSet = MediaTestimonials.objects.all().order_by('-created')
    collection = MediaTestimonialsFossFilter(request.GET,
                                             queryset=collectionSet)

    if collection:
        page = request.GET.get('page')
        testimonials = get_page(collection.qs, page, limit=6)
        form = collection.form

    context = {}
    context['form'] = form
    context['collection'] = testimonials
    context['media_url'] = settings.MEDIA_URL
    context['testimonial_type'] = testimonial_type
    context.update(csrf(request))
    return render(request, 'spoken/templates/testimonial/testimonials.html',
                  context)
Beispiel #12
0
def keyword_search(request):
    context = {}
    keyword = ''
    collection = None
    conjunction_words = ['a', 'i']
    form = TutorialSearchForm()
    if request.method == 'GET' and 'q' in request.GET and request.GET['q'] != '':
        form = KeywordSearchForm(request.GET)
        if form.is_valid():
            keyword = request.GET['q']
            keywords = keyword.split(' ')
            search_fields = ['keyword']
            remove_words = set(keywords).intersection(set(conjunction_words))
            for key in remove_words:
                keywords.remove(key)
            query = get_or_query(keywords, search_fields)
            if query:
                collection = TutorialResource.objects.filter(Q(status = 1) | Q(status = 2), tutorial_detail__foss__status = 1, common_content = TutorialCommonContent.objects.filter(query), language__name = 'English').order_by('tutorial_detail__foss__foss', 'tutorial_detail__level', 'tutorial_detail__order', 'language__name')
    
    if collection:
        page = request.GET.get('page')
        collection = get_page(collection, page)
    
    context = {}
    context['form'] = KeywordSearchForm()
    context['collection'] = collection
    context['keywords'] = keyword
    context.update(csrf(request))
    return render(request, 'spoken/templates/keyword_search.html', context)
Beispiel #13
0
def online_test(request):
    """ Organiser index page """
    collectionSet = None
    participant_count = 0

    collectionSet = Test.objects.filter(
        status=4, participant_count__gt=0).order_by('-tdate')
    header = {
        1: SortableHeader('#', False),
        2: SortableHeader('academic__state__name', True, 'State'),
        3: SortableHeader('academic__city__name', True, 'City'),
        4: SortableHeader('academic__institution_name', True, 'Institution'),
        5: SortableHeader('foss__foss', True, 'FOSS'),
        6: SortableHeader('organiser__user__first_name', True, 'Organiser'),
        7: SortableHeader('tdate', True, 'Date'),
        8: SortableHeader('participant_count', 'True', 'Participants'),
        9: SortableHeader('Action', False)
    }

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

    # find state id
    state = None
    if 'academic__state' in request.GET and request.GET['academic__state']:
        state = State.objects.get(id=request.GET['academic__state'])

    collection = TestFilter(request.GET, queryset=collection, state=state)
    # find participants count
    participant_count = collection.qs.aggregate(Sum('participant_count'))
    #
    chart_query_set = collection.qs.extra(select={
        'year': "EXTRACT(year FROM tdate)"
    }).values('year').order_by('-year').annotate(
        total_training=Count('tdate'),
        total_participant=Sum('participant_count'))
    chart_data = ''
    for data in chart_query_set:
        chart_data += "['" + str(data['year']) + "', " + str(
            data['total_participant']) + "],"

    no_of_colleges = collection.qs.filter().values(
        'academic_id').distinct().count()
    print(" ********************** no of colleges: ", no_of_colleges)

    context = {}
    context['form'] = collection.form
    context['chart_data'] = chart_data
    page = request.GET.get('page')
    collection = get_page(collection.qs, page)
    context['collection'] = collection
    context['header'] = header
    context['ordering'] = ordering
    context['participant_count'] = participant_count
    context['model'] = 'Online-Test'
    context['no_of_colleges'] = no_of_colleges
    return render(request, 'statistics/templates/online_test.html', context)
Beispiel #14
0
def academic_center(request, slug = None):
    context = {}
    header = {
        1: SortableHeader('#', False),
        2: SortableHeader('State', False),
        3: SortableHeader('institution_name', True, 'Institution Name'),
        4: SortableHeader('num_training', True, 'Training'),
        5: SortableHeader('num_participant', True, 'Participants'),
        6: SortableHeader('Action', False)
    }
    
    collection = None
    training_index = int(request.GET.get('training', 0))
    start_date = request.GET.get('training__tdate_0', 0)
    end_date = request.GET.get('training__tdate_1', 0)
    lookup = None
    if start_date or end_date:
        if start_date and end_date:
            lookup = [start_date, end_date]
        elif start_date:
            lookup = [start_date, now()]
        else:
            lookup = [datetime.strptime('1970-01-01', '%Y-%m-%d'), end_date]
    if slug:
        collection = AcademicCenter.objects.filter(state__slug = slug).order_by('state__name', 'institution_name')
    elif training_index:
        collection = AcademicCenter.objects.filter(training__status=4, training__participant_count__gt=0).annotate(num_training=Count('training'), num_participant=Sum('training__participant_count')).filter(num_training__gte=training_index).order_by('state__name', 'institution_name')
    else:
        if lookup:
            collection = AcademicCenter.objects.filter(training__status=4, training__participant_count__gt=0, training__tdate__range=lookup).annotate(num_training=Count('training'), num_participant=Sum('training__participant_count')).order_by('state__name', 'institution_name')
        else:
            collection = AcademicCenter.objects.filter(training__status=4, training__participant_count__gt=0).annotate(num_training=Count('training'), num_participant=Sum('training__participant_count')).order_by('state__name', 'institution_name')
    
    raw_get_data = request.GET.get('o', None)
    collection = get_sorted_list(request, collection, header, raw_get_data)
    ordering = get_field_index(raw_get_data)
    
    collection = AcademicCenterFilter(request.GET, queryset=collection)
    context['form'] = collection.form
    context['total_training'] = collection.qs.aggregate(Sum('num_training'))
    context['total_participant'] = collection.qs.aggregate(Sum('num_participant'))
    
    page = request.GET.get('page')
    collection = get_page(collection, page)
    options = '<option value="0"> --------- </option><option value="1">at least 1</option>'
    for i in range(5, 105, 5):
        options += '<option value="' + str(i) + '"> at least ' + str(i) + '</option>'
    options += '<option value="101">more than 100</option>'
    options = options.replace('<option value="' + str(training_index) + '">', \
        '<option value="' + str(training_index) + '" selected="selected">')
    context['collection'] = collection
    context['header'] = header
    context['ordering'] = ordering
    context['options'] = options
    
    return render(request, 'statistics/templates/academic-center.html', context)
Beispiel #15
0
def fdp_training(request):
    """ Organiser index page """
    collectionSet = None
    state = None

    collectionSet = TrainingRequest.objects.filter(
        participants__gt=0,
        department=169,
        sem_start_date__lte=datetime.now()
    ).order_by('-sem_start_date')
    header = {
        1: SortableHeader('#', False),
        2: SortableHeader('training_planner__academic__state__name', True, 'State'),
        3: SortableHeader('training_planner__academic__city__name', True, 'City'),
        4: SortableHeader('training_planner__academic__institution_name', True, 'Institution'),
        5: SortableHeader('course__foss__foss', True, 'FOSS'),
        6: SortableHeader('department', True, 'Department'),
        7: SortableHeader('course__category', True, 'Type'),
        8: SortableHeader('training_planner__organiser__user__first_name', True, 'Organiser'),
        9: SortableHeader('sem_start_date', True, 'Date'),
        10: SortableHeader('participants', 'True', 'Participants'),
        11: SortableHeader('Action', False)
    }

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

    # find state id
    if 'training_planner__academic__state' in request.GET and request.GET['training_planner__academic__state']:
        state = State.objects.get(id=request.GET['training_planner__academic__state'])

    collection = TrainingRequestFilter(request.GET, queryset=collection, state=state)
    # find participants count
    participants = collection.qs.aggregate(Sum('participants'))
    #
    chart_query_set = collection.qs.extra(select={'year': "EXTRACT(year FROM sem_start_date)"}).values('year').order_by(
        '-year').annotate(total_training=Count('sem_start_date'), total_participant=Sum('participants'))
    chart_data = ''
    for data in chart_query_set:
        chart_data += "['" + str(data['year']) + "', " + str(data['total_participant']) + "],"
    context = {}
    context['form'] = collection.form
    context['chart_data'] = chart_data
    page = request.GET.get('page')
    collection = get_page(collection, page)
    context['collection'] = collection
    context['header'] = header
    context['ordering'] = ordering
    context['participants'] = participants
    context['model'] = 'Workshop/Training'
    return render(request, 'statistics/templates/pmmm_stats.html', context)
Beispiel #16
0
	def get_context_data(self, **kwargs):
		context = super(ParticipantTransactionsListView, self).get_context_data(**kwargs)
		context['form'] = self.collection.form
		page = self.request.GET.get('page')
		collection = get_page(self.collection.qs, page)
		context['collection'] =  collection
		context['header'] = self.header
		context['ordering'] = get_field_index(self.raw_get_data)
		context['events'] =  self.events
		context['total_amount']=self.total_amount
		if self.request.user:
			context['user'] = self.request.user
		return context
Beispiel #17
0
	def get_context_data(self, **kwargs):
		context = super(TrainingEventsListView, self).get_context_data(**kwargs)
		context['form'] = self.collection.form
		page = self.request.GET.get('page')
		collection = get_page(self.collection.qs, page)
		context['collection'] =  collection
		context['ordering'] = get_field_index(self.raw_get_data)
		context['status'] =  self.status
		context['events'] =  self.events
		context['show_myevents'] = self.show_myevents
		context['ILW_ONLINE_TEST_URL'] = settings.ILW_ONLINE_TEST_URL
		if self.request.user:
			context['user'] = self.request.user
		return context
Beispiel #18
0
def online_test(request):
    """ Organiser index page """
    collectionSet = None
    participant_count = 0

    collectionSet = Test.objects.filter(status=4, participant_count__gt=0).order_by('-tdate')
    header = {
        1: SortableHeader('#', False),
        2: SortableHeader('academic__state__name', True, 'State'),
        3: SortableHeader('academic__city__name', True, 'City'),
        4: SortableHeader('academic__institution_name', True, 'Institution'),
        5: SortableHeader('foss__foss', True, 'FOSS'),
        6: SortableHeader('organiser__user__first_name', True, 'Organiser'),
        7: SortableHeader('tdate', True, 'Date'),
        8: SortableHeader('participant_count', 'True', 'Participants'),
        9: SortableHeader('Action', False)
    }

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

    # find state id
    state = None
    if 'academic__state' in request.GET and request.GET['academic__state']:
        state = State.objects.get(id=request.GET['academic__state'])

    collection = TestFilter(request.GET, queryset=collection, state=state)
    # find participants count
    participant_count = collection.qs.aggregate(Sum('participant_count'))
    #
    chart_query_set = collection.qs.extra(select={'year': "EXTRACT(year FROM tdate)"}).values('year').order_by(
        '-year').annotate(total_training=Count('tdate'), total_participant=Sum('participant_count'))
    chart_data = ''
    for data in chart_query_set:
        chart_data += "['" + str(data['year']) + "', " + str(data['total_participant']) + "],"
    context = {}
    context['form'] = collection.form
    context['chart_data'] = chart_data
    page = request.GET.get('page')
    collection = get_page(collection, page)
    context['collection'] = collection
    context['header'] = header
    context['ordering'] = ordering
    context['participant_count'] = participant_count
    context['model'] = 'Online-Test'
    return render(request, 'statistics/templates/online_test.html', context)
Beispiel #19
0
def testimonials(request, type="text"):
    '''
    Responds with `/testimonial` page to display all the 
    text / video / audio template.
    '''
    collection = None
    if type == "text":
        collection = Testimonials.objects.all().values().order_by('-created')
    else:
        collection = MediaTestimonials.objects.all().values("foss__foss", "content", "created", "foss", "foss_id", "id", "path", "user", "workshop_details").order_by('-created')
    collection = MediaTestimonialsFossFilter(request.GET, queryset=collection)
    form = collection.form
    if collection:
        page = request.GET.get('page')
        collection = get_page(collection, page, limit=6)

    context = {}
    context['form'] = form
    context['collection'] = collection
    context['media_url'] = settings.MEDIA_URL
    context['testimonial_type'] = type
    context.update(csrf(request))
    return render(request, 'spoken/templates/testimonial/testimonials.html', context)
Beispiel #20
0
 def get_context_data(self, **kwargs):
   context = super(StudentBatchListView, self).get_context_data(**kwargs)
   collectionSet = StudentBatch.objects.filter(academic_id=self.request.user.organiser.academic_id)
   header = {
       1: SortableHeader('#', False),
       2: SortableHeader('academic', True, 'Institution'),
       3: SortableHeader('department', True, 'Department'),
       4: SortableHeader('year', True, 'Year'),
       5: SortableHeader('stcount', True, 'Student Count'),
       6: SortableHeader('', False, ''),
   }
   
   raw_get_data = self.request.GET.get('o', None)
   collection = get_sorted_list(self.request, collectionSet, header, raw_get_data)
   ordering = get_field_index(raw_get_data)
   #collection = TrainingFilter(self.request.GET, user = user, queryset=collection)
   
   page = self.request.GET.get('page')
   collection = get_page(collection, page)
   context['object_list'] = collection
   context['header'] = header
   context['ordering'] = ordering
   return context
Beispiel #21
0
def keyword_search(request):
    context = {}
    keyword = ''
    collection = None
    correction = None
    conjunction_words = ['a', 'i']
    form = TutorialSearchForm()
    if request.method == 'GET' and 'q' in request.GET and request.GET['q'] != '':
        form = KeywordSearchForm(request.GET)
        if form.is_valid():
            keyword = request.GET['q'].lower()
            collection, correction = search_for_results(keyword)
    
    if collection:
        page = request.GET.get('page')
        collection = get_page(collection, page)
    
    context = {}
    context['form'] = KeywordSearchForm()
    context['collection'] = collection
    context['correction'] = correction
    context['keywords'] = keyword
    context.update(csrf(request))
    return render(request, 'spoken/templates/keyword_search.html', context)
Beispiel #22
0
def academic_center(request, slug=None):
    context = {}
    header = {
        1: SortableHeader('#', False),
        2: SortableHeader('State', False),
        3: SortableHeader('institution_name', True, 'Institution Name'),
        4: SortableHeader('num_training', True, 'Training'),
        5: SortableHeader('num_participant', True, 'Participants'),
        6: SortableHeader('Action', False)
    }

    collection = None
    training_index = int(request.GET.get('training', 0))
    start_date = request.GET.get('training__tdate_0', 0)
    end_date = request.GET.get('training__tdate_1', 0)
    lookup = None
    if start_date or end_date:
        if start_date and end_date:
            lookup = [start_date, end_date]
        elif start_date:
            lookup = [start_date, now()]
        else:
            lookup = [datetime.strptime('1970-01-01', '%Y-%m-%d'), end_date]
    if slug:
        collection = AcademicCenter.objects.filter(state__slug=slug).order_by(
            'state__name', 'institution_name')
    elif training_index:
        collection = AcademicCenter.objects.filter(
            training__status=4, training__participant_count__gt=0).annotate(
                num_training=Count('training'),
                num_participant=Sum('training__participant_count')).filter(
                    num_training__gte=training_index).order_by(
                        'state__name', 'institution_name')
    else:
        if lookup:
            collection = AcademicCenter.objects.filter(
                training__status=4,
                training__participant_count__gt=0,
                training__tdate__range=lookup).annotate(
                    num_training=Count('training'),
                    num_participant=Sum(
                        'training__participant_count')).order_by(
                            'state__name', 'institution_name')
        else:
            collection = AcademicCenter.objects.filter(
                training__status=4,
                training__participant_count__gt=0).annotate(
                    num_training=Count('training'),
                    num_participant=Sum(
                        'training__participant_count')).order_by(
                            'state__name', 'institution_name')

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

    collection = AcademicCenterFilter(request.GET, queryset=collection)
    context['form'] = collection.form
    context['total_training'] = collection.qs.aggregate(Sum('num_training'))
    context['total_participant'] = collection.qs.aggregate(
        Sum('num_participant'))

    page = request.GET.get('page')
    collection = get_page(collection, page)
    options = '<option value="0"> --------- </option><option value="1">at least 1</option>'
    for i in range(5, 105, 5):
        options += '<option value="' + str(i) + '"> at least ' + str(
            i) + '</option>'
    options += '<option value="101">more than 100</option>'
    options = options.replace('<option value="' + str(training_index) + '">', \
        '<option value="' + str(training_index) + '" selected="selected">')
    context['collection'] = collection
    context['header'] = header
    context['ordering'] = ordering
    context['options'] = options

    return render(request, 'statistics/templates/academic-center.html',
                  context)
Beispiel #23
0
def training(request, slug="training"):
    """ Organiser index page """
    user = request.user
    collectionSet = None
    state = None
    participant_count = 0
    event_type = ["Training", "Test"]
    model_type = {"training": 0, "onlinetest": 1}
    if not (slug in model_type.keys()):
        return HttpResponseRedirect("/statistics/training/")
    model_index = int(request.GET.get("event_type", model_type[slug]))
    model_filter = eval(event_type[model_index] + "Filter")
    model = eval(event_type[model_index])
    collectionSet = model.objects.filter(status=4, participant_count__gt=0).order_by("-tdate")
    header = {
        1: SortableHeader("#", False),
        2: SortableHeader("academic__state__name", True, "State"),
        3: SortableHeader("academic__city__name", True, "City"),
        4: SortableHeader("academic__institution_name", True, "Institution"),
        5: SortableHeader("foss__foss", True, "FOSS"),
        6: SortableHeader("organiser__user__first_name", True, "Organiser"),
        7: SortableHeader("tdate", True, "Date"),
        8: SortableHeader("participant_count", "True", "Participants"),
        9: SortableHeader("Action", False),
    }

    raw_get_data = request.GET.get("o", None)
    collection = get_sorted_list(request, collectionSet, header, raw_get_data)
    ordering = get_field_index(raw_get_data)

    # find state id
    state_id = None
    if "academic__state" in request.GET and request.GET["academic__state"] and slug:
        # todo
        pass
    elif "academic__state" in request.GET and request.GET["academic__state"]:
        state = State.objects.get(id=request.GET["academic__state"])

    collection = model_filter(request.GET, queryset=collection, state=state)
    # find participants count
    participant_count = collection.qs.aggregate(Sum("participant_count"))
    #
    chart_query_set = (
        collection.qs.extra(select={"year": "EXTRACT(year FROM tdate)"})
        .values("year")
        .annotate(total_training=Count("tdate"), total_participant=Sum("participant_count"))
    )
    chart_data = ""
    for data in chart_query_set:
        chart_data += "['" + str(data["year"]) + "', " + str(data["total_participant"]) + "],"
    context = {}
    context["form"] = collection.form
    context["chart_data"] = chart_data
    page = request.GET.get("page")
    collection = get_page(collection, page)
    context["collection"] = collection
    context["header"] = header
    context["ordering"] = ordering
    context["state"] = slug
    context["participant_count"] = participant_count
    context["event_type"] = event_type[model_index].lower
    if model_index:
        context["model"] = "Online-Test"
    else:
        context["model"] = "Workshop/Training"
    return render(request, "statistics/templates/training.html", context)
Beispiel #24
0
def academic_center(request, slug=None):
    context = {}
    header = {
        1: SortableHeader("#", False),
        2: SortableHeader("State", False),
        3: SortableHeader("institution_name", True, "Institution Name"),
        4: SortableHeader("num_training", True, "Training"),
        5: SortableHeader("num_participant", True, "Participants"),
        6: SortableHeader("Action", False),
    }

    collection = None
    training_index = int(request.GET.get("training", 0))
    start_date = request.GET.get("training__tdate_0", 0)
    end_date = request.GET.get("training__tdate_1", 0)
    lookup = None
    if start_date or end_date:
        if start_date and end_date:
            lookup = [start_date, end_date]
        elif start_date:
            lookup = [start_date, now()]
        else:
            lookup = [datetime.strptime("1970-01-01", "%Y-%m-%d"), end_date]
    if slug:
        collection = AcademicCenter.objects.filter(state__slug=slug).order_by("state__name", "institution_name")
    elif training_index:
        collection = (
            AcademicCenter.objects.filter(training__status=4, training__participant_count__gt=0)
            .annotate(num_training=Count("training"), num_participant=Sum("training__participant_count"))
            .filter(num_training__gte=training_index)
            .order_by("state__name", "institution_name")
        )
    else:
        if lookup:
            collection = (
                AcademicCenter.objects.filter(
                    training__status=4, training__participant_count__gt=0, training__tdate__range=lookup
                )
                .annotate(num_training=Count("training"), num_participant=Sum("training__participant_count"))
                .order_by("state__name", "institution_name")
            )
        else:
            collection = (
                AcademicCenter.objects.filter(training__status=4, training__participant_count__gt=0)
                .annotate(num_training=Count("training"), num_participant=Sum("training__participant_count"))
                .order_by("state__name", "institution_name")
            )

    raw_get_data = request.GET.get("o", None)
    collection = get_sorted_list(request, collection, header, raw_get_data)
    ordering = get_field_index(raw_get_data)

    collection = AcademicCenterFilter(request.GET, queryset=collection)
    context["form"] = collection.form
    context["total_training"] = collection.qs.aggregate(Sum("num_training"))
    context["total_participant"] = collection.qs.aggregate(Sum("num_participant"))

    page = request.GET.get("page")
    collection = get_page(collection, page)
    options = '<option value="0"> --------- </option><option value="1">at least 1</option>'
    for i in range(5, 105, 5):
        options += '<option value="' + str(i) + '"> at least ' + str(i) + "</option>"
    options += '<option value="101">more than 100</option>'
    options = options.replace(
        '<option value="' + str(training_index) + '">',
        '<option value="' + str(training_index) + '" selected="selected">',
    )
    context["collection"] = collection
    context["header"] = header
    context["ordering"] = ordering
    context["options"] = options

    return render(request, "statistics/templates/academic-center.html", context)
Beispiel #25
0
def training(request, slug = 'training'):
    """ Organiser index page """
    user = request.user
    collectionSet = None
    state = None
    participant_count = 0
    event_type = ['Training', 'Test']
    model_type = {
        'training' : 0,
        'onlinetest' : 1
    }
    if  not (slug in model_type.keys()):
        return HttpResponseRedirect('/statistics/training/')
    model_index = int(request.GET.get('event_type', model_type[slug]))
    model_filter = eval(event_type[model_index] + 'Filter')
    model = eval(event_type[model_index])
    collectionSet = model.objects.filter(status = 4, participant_count__gt=0).order_by('-tdate')
    header = {
        1: SortableHeader('#', False),
        2: SortableHeader('academic__state__name', True, 'State'),
        3: SortableHeader('academic__city__name', True, 'City'),
        4: SortableHeader('academic__institution_name', True, 'Institution'),
        5: SortableHeader('foss__foss', True, 'FOSS'),
        6: SortableHeader('organiser__user__first_name', True, 'Organiser'),
        7: SortableHeader('tdate', True, 'Date'),
        8: SortableHeader('participant_count', 'True', 'Participants'),
        9: SortableHeader('Action', False)
    }
    
    raw_get_data = request.GET.get('o', None)
    collection = get_sorted_list(request, collectionSet, header, raw_get_data)
    ordering = get_field_index(raw_get_data)
    
    # find state id
    state_id = None
    if 'academic__state' in request.GET and request.GET['academic__state'] and slug:
        # todo
        pass
    elif 'academic__state' in request.GET and request.GET['academic__state']:
        state = State.objects.get(id=request.GET['academic__state'])
    
    collection = model_filter(request.GET, queryset=collection, state=state)
    # find participants count
    participant_count = collection.qs.aggregate(Sum('participant_count'))
    #
    chart_query_set = collection.qs.extra(select={'year': "EXTRACT(year FROM tdate)"}).values('year').order_by('-year').annotate(total_training=Count('tdate'), total_participant=Sum('participant_count'))
    chart_data = ''
    for data in chart_query_set:
        chart_data += "['" + str(data['year']) + "', " + str(data['total_participant']) + "],"
    context = {}
    context['form'] = collection.form
    context['chart_data'] = chart_data
    page = request.GET.get('page')
    collection = get_page(collection, page)
    context['collection'] = collection
    context['header'] = header
    context['ordering'] = ordering
    context['state'] = slug
    context['participant_count'] = participant_count
    context['event_type'] = event_type[model_index].lower
    if model_index:
        context['model'] = 'Online-Test'
    else:
        context['model'] = 'Workshop/Training'
    return render(request, 'statistics/templates/training.html', context)
Beispiel #26
0
def training(request):
    """ Organiser index page """
    user = request.user
    collectionSet = None
    state = None

    collectionSet = TrainingRequest.objects.filter(
        participants__gt=0,
        sem_start_date__lte=datetime.now()).order_by('-sem_start_date')
    header = {
        1:
        SortableHeader('#', False),
        2:
        SortableHeader('training_planner__academic__state__name', True,
                       'State'),
        3:
        SortableHeader('training_planner__academic__city__name', True, 'City'),
        4:
        SortableHeader('training_planner__academic__institution_name', True,
                       'Institution'),
        5:
        SortableHeader('course__foss__foss', True, 'FOSS'),
        6:
        SortableHeader('course__category', True, 'Type'),
        7:
        SortableHeader('training_planner__organiser__user__first_name', True,
                       'Organiser'),
        8:
        SortableHeader('sem_start_date', True, 'Date'),
        9:
        SortableHeader('participants', 'True', 'Participants'),
        10:
        SortableHeader('Action', False)
    }

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

    # find state id
    state_id = None
    if 'training_planner__academic__state' in request.GET and request.GET[
            'training_planner__academic__state']:
        state = State.objects.get(
            id=request.GET['training_planner__academic__state'])

    collection = TrainingRequestFilter(request.GET,
                                       queryset=collection,
                                       state=state)
    # find participants count
    participants = collection.qs.aggregate(Sum('participants'))
    #
    chart_query_set = collection.qs.extra(
        select={
            'year': "EXTRACT(year FROM sem_start_date)"
        }).values('year').order_by('-year').annotate(
            total_training=Count('sem_start_date'),
            total_participant=Sum('participants'))
    chart_data = ''
    for data in chart_query_set:
        chart_data += "['" + str(data['year']) + "', " + str(
            data['total_participant']) + "],"
    context = {}
    context['form'] = collection.form
    context['chart_data'] = chart_data
    page = request.GET.get('page')
    collection = get_page(collection, page)
    context['collection'] = collection
    context['header'] = header
    context['ordering'] = ordering
    context['participants'] = participants
    context['model'] = 'Workshop/Training'
    return render(request, 'statistics/templates/training.html', context)
Beispiel #27
0
def training(request, slug='training'):
    """ Organiser index page """
    user = request.user
    collectionSet = None
    state = None
    participant_count = 0
    event_type = ['Training', 'Test']
    model_type = {'training': 0, 'onlinetest': 1}
    if not (slug in model_type.keys()):
        return HttpResponseRedirect('/statistics/training/')
    model_index = int(request.GET.get('event_type', model_type[slug]))
    model_filter = eval(event_type[model_index] + 'Filter')
    model = eval(event_type[model_index])
    collectionSet = model.objects.filter(
        status=4, participant_count__gt=0).order_by('-tdate')
    header = {
        1: SortableHeader('#', False),
        2: SortableHeader('academic__state__name', True, 'State'),
        3: SortableHeader('academic__city__name', True, 'City'),
        4: SortableHeader('academic__institution_name', True, 'Institution'),
        5: SortableHeader('foss__foss', True, 'FOSS'),
        6: SortableHeader('organiser__user__first_name', True, 'Organiser'),
        7: SortableHeader('tdate', True, 'Date'),
        8: SortableHeader('participant_count', 'True', 'Participants'),
        9: SortableHeader('Action', False)
    }

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

    # find state id
    state_id = None
    if 'academic__state' in request.GET and request.GET[
            'academic__state'] and slug:
        # todo
        pass
    elif 'academic__state' in request.GET and request.GET['academic__state']:
        state = State.objects.get(id=request.GET['academic__state'])

    collection = model_filter(request.GET, queryset=collection, state=state)
    # find participants count
    participant_count = collection.qs.aggregate(Sum('participant_count'))
    #
    chart_query_set = collection.qs.extra(select={
        'year': "EXTRACT(year FROM tdate)"
    }).values('year').order_by('-year').annotate(
        total_training=Count('tdate'),
        total_participant=Sum('participant_count'))
    chart_data = ''
    for data in chart_query_set:
        chart_data += "['" + str(data['year']) + "', " + str(
            data['total_participant']) + "],"
    context = {}
    context['form'] = collection.form
    context['chart_data'] = chart_data
    page = request.GET.get('page')
    collection = get_page(collection, page)
    context['collection'] = collection
    context['header'] = header
    context['ordering'] = ordering
    context['state'] = slug
    context['participant_count'] = participant_count
    context['event_type'] = event_type[model_index].lower
    if model_index:
        context['model'] = 'Online-Test'
    else:
        context['model'] = 'Workshop/Training'
    return render(request, 'statistics/templates/training.html', context)
Beispiel #28
0
def listevents(request, role, status):
	today=date.today()
	context = {}
	user = request.user
	if not (user.is_authenticated() and (is_resource_person(user) or is_administrator(user))):
		raise PermissionDenied()

	if (not role ) or (not status):
		raise PermissionDenied()

	states = State.objects.filter(resourceperson__user_id=user, resourceperson__status=1)
	TrMngerEvents = TrainingEvents.objects.filter(state__in=states).order_by('-event_start_date')
	

	status_list = {'ongoing': 0, 'completed': 1, 'closed': 2, 'expired': 3}
	roles = ['rp', 'em']
	if role in roles and status in status_list:
		if status == 'ongoing':
			queryset = TrMngerEvents.filter(training_status__lte=1, event_end_date__gte=today)
		elif status == 'completed':
			queryset =TrMngerEvents.filter(training_status=1, event_end_date__lt=today)
		elif status == 'closed':
			queryset = TrMngerEvents.filter(training_status=2)
		elif status == 'expired':
			queryset = TrMngerEvents.filter(training_status=0, event_end_date__lt=today)

		header = {
		1: SortableHeader('#', False),
		2: SortableHeader(
		  'state__name',
		  True,
		  'State'
		),
		3: SortableHeader(
		  'host_college__academic_code',
		  True,
		  'Code'
		),
		4: SortableHeader(
		  'host_college__institution_name',
		  True,
		  'Institution'
		),
		5: SortableHeader('foss__foss', True, 'Foss Name'),
		6: SortableHeader(
		  'event_coordinator_name',
		  True,
		  'Coordinator'
		),
		7: SortableHeader(
		  'registartion_end_date',
		  True,
		  'Registration Period'
		),
		8: SortableHeader(
		  'event_start_date',
		  True,
		  'Event Start Date'
		),
		9: SortableHeader(
		  'event_end_date',
		  True,
		  'Event End Date'
		),
		10: SortableHeader('Participant Count', True),
		11: SortableHeader('Action', False)
		}
		event_type = request.GET.get('event_type', None)
		pcount, mcount, fcount = get_all_events_detail(queryset, event_type) if event_type else get_all_events_detail(queryset)
		raw_get_data = request.GET.get('o', None)
		queryset = get_sorted_list(
			request,
			queryset,
			header,
			raw_get_data
		)
		collection= TrEventFilter(request.GET, queryset=queryset, user=user)
      

	else:
		raise PermissionDenied()

	context['form'] = collection.form
	page = request.GET.get('page')
	collection = get_page(collection.qs, page)
	context['collection'] =  collection
	context['role'] = role
	context['status'] = status
	context['header'] = header
	context['today'] = date.today()
	context['ordering'] = get_field_index(raw_get_data)
	context['pcount'] = pcount
	context['mcount'] = mcount
	context['fcount'] = fcount

	return render(request,'event_status_list.html',context)
Beispiel #29
0
def ilw_stats(request):
    queryset = TrainingEvents.objects.filter(
        training_status=2).order_by('-event_start_date')
    context = {}

    REG_COMPLETED = '1'
    CLOSED_TRAINING = '2'

    if request.method == 'GET':
        status = request.GET.get('status')
        if status not in [REG_COMPLETED, CLOSED_TRAINING]:
            status = CLOSED_TRAINING
    if status == REG_COMPLETED:
        queryset = TrainingEvents.objects.filter(
            training_status=1).order_by('-event_start_date')
    elif status == CLOSED_TRAINING:
        queryset = TrainingEvents.objects.filter(
            training_status=2).order_by('-event_start_date')

    header = {
        1: SortableHeader('#', False),
        2: SortableHeader('state__name', True, 'State'),
        3: SortableHeader('host_college__academic_code', True, 'Code'),
        4: SortableHeader('host_college__institution_name', True,
                          'Institution'),
        5: SortableHeader('foss__foss', True, 'Foss Name'),
        6: SortableHeader('event_coordinator_name', True, 'Coordinator'),
        7: SortableHeader('registartion_end_date', True,
                          'Registration Period'),
        8: SortableHeader('event_start_date', True, 'Event Start Date'),
        9: SortableHeader('event_end_date', True, 'Event End Date'),
        10: SortableHeader('Participant Count', True),
        11: SortableHeader('Action', False)
    }

    raw_get_data = request.GET.get('o', None)

    queryset = get_sorted_list(request, queryset, header, raw_get_data)
    collection = EventStatsFilter(request.GET, queryset=queryset)

    femalecount = 0
    malecount = 0

    if status == REG_COMPLETED:
        participants = Participant.objects.filter(event_id__in=collection.qs,
                                                  reg_approval_status=1)
        pcount = participants.count()
        female_list = list(
            participants.filter(gender__in=('f', 'F', 'female', 'Female',
                                            'FEMALE')).values_list('id'))
        male_list = list(
            participants.filter(gender__in=('m', 'M', 'male', 'Male',
                                            'MALE')).values_list('id'))

    elif status == CLOSED_TRAINING:
        participants = EventAttendance.objects.filter(
            event_id__in=collection.qs)
        pcount = participants.count()
        female_list = list(
            participants.filter(
                participant__gender__in=('f', 'F', 'female', 'Female',
                                         'FEMALE')).values_list('id'))
        male_list = list(
            participants.filter(
                participant__gender__in=('m', 'M', 'male', 'Male',
                                         'MALE')).values_list('id'))

    femalecount = len([i[0] for i in female_list])

    malecount = len([i[0] for i in male_list])

    context['form'] = collection.form
    page = request.GET.get('page')
    collection = get_page(collection.qs, page)
    context['collection'] = collection
    context['header'] = header
    context['participants'] = pcount
    context['femalecount'] = femalecount
    context['malecount'] = malecount
    context['status'] = status
    return render(request, 'statistics/templates/ilw_stats.html', context)
Beispiel #30
0
def training(request):
    """ Organiser index page """
    collectionSet = TrainingRequest.objects.filter(
        sem_start_date__lte=datetime.now()).order_by('-sem_start_date')
    state = None
    TRAINING_COMPLETED = '1'
    TRAINING_PENDING = '0'
    if request.method == 'GET':
        status = request.GET.get('status')
        print('###################', status)
        if status not in [TRAINING_COMPLETED, TRAINING_PENDING]:
            status = TRAINING_COMPLETED

        lang = request.GET.get('lang')
        if status == TRAINING_COMPLETED:
            if lang and '---------' not in lang:
                training_attend_lang = TrainingAttend.objects.filter(
                    language__name=lang).values_list('training_id').distinct()
                collectionSet = collectionSet.filter(
                    id__in=training_attend_lang)

    if status == TRAINING_PENDING:
        collectionSet = collectionSet.filter(participants=0,
                                             status=TRAINING_COMPLETED)

    else:
        collectionSet = collectionSet.filter(participants__gt=0)
    header = {
        1:
        SortableHeader('#', False),
        2:
        SortableHeader('training_planner__academic__state__name', True,
                       'State'),
        3:
        SortableHeader('training_planner__academic__city__name', True, 'City'),
        4:
        SortableHeader('training_planner__academic__institution_name', True,
                       'Institution'),
        5:
        SortableHeader('course__foss__foss', True, 'FOSS'),
        6:
        SortableHeader('department', True, 'Department'),
        7:
        SortableHeader('course__category', True, 'Type'),
        8:
        SortableHeader('training_planner__organiser__user__first_name', True,
                       'Organiser'),
        9:
        SortableHeader('sem_start_date', True, 'Date'),
        10:
        SortableHeader('participants', 'True', 'Participants'),
        11:
        SortableHeader('Action', False)
    }

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

    # find state id
    if 'training_planner__academic__state' in request.GET and request.GET[
            'training_planner__academic__state']:
        state = State.objects.get(
            id=request.GET['training_planner__academic__state'])
    collection = TrainingRequestFilter(request.GET,
                                       queryset=collection,
                                       state=state)
    # find participants count

    participants = collection.qs.aggregate(Sum('participants'))

    if lang == 'English':
        participants = participants['participants__sum'] + 294593

    else:
        participants = participants['participants__sum']

    chart_query_set = collection.qs.extra(
        select={
            'year': "EXTRACT(year FROM sem_start_date)"
        }).values('year').order_by('-year').annotate(
            total_training=Count('sem_start_date'),
            total_participant=Sum('participants'))
    chart_data = ''

    get_year = []
    pending_attendance_participant_count = 0
    key = ''.join(
        'None' if i == '' or i == '---------' else str(i).replace(" ", "")
        for i in request.GET.values())
    key = key if key else 'NoneNoneNoneNoneNoneNoneNoneNoneNoneNone1'
    female_key = key + 'female'
    male_key = key + 'male'
    femalecount = cache.get(female_key)
    malecount = cache.get(male_key)
    if status != 0:
        if not femalecount or not malecount:
            female_list = list(
                Student.objects.filter(trainingattend__training_id__in=[
                    col.id for col in collection.qs
                ],
                                       gender='Female').values_list('id'))
            femalecount = len([i[0] for i in female_list])
            male_list = list(
                Student.objects.filter(trainingattend__training_id__in=[
                    col.id for col in collection.qs
                ],
                                       gender='Male').values_list('id'))
            malecount = len([i[0] for i in male_list])
            try:
                cache.set(female_key, femalecount)
                cache.set(male_key, malecount)
            except Exception:
                print('Error setting cache key values')

    year_data_all = dict()
    visited = dict()
    if status == TRAINING_PENDING:

        pending_attendance_student_batches = StudentBatch.objects.filter(
            id__in=(collection.qs.filter(status=TRAINING_COMPLETED,
                                         participants=0,
                                         batch_id__gt=0).values('batch_id')))
        pending_attendance_training = collection.qs.filter(
            batch_id__in=pending_attendance_student_batches.filter().values(
                'id')).distinct()

        for batch in pending_attendance_student_batches:
            pending_attendance_participant_count += batch.stcount
        for a_traning in pending_attendance_training:
            if a_traning.batch_id not in visited:
                if a_traning.sem_start_date.year in year_data_all:
                    visited[a_traning.batch_id] = [a_traning.batch_id]
                    year_data_all[a_traning.sem_start_date.
                                  year] += a_traning.batch.stcount
                else:
                    visited[a_traning.batch_id] = [a_traning.batch_id]
                    year_data_all[a_traning.sem_start_date.
                                  year] = a_traning.batch.stcount

    if status == TRAINING_COMPLETED:
        for data in chart_query_set:
            chart_data += "['" + str(data['year']) + "', " + str(
                data['total_participant']) + "],"
    else:
        for year, count in list(year_data_all.items()):
            chart_data += "['" + str(year) + "', " + str(count) + "],"

    no_of_colleges = collection.qs.filter().values(
        'training_planner__academic_id').distinct().count()
    print(" ********************** no of colleges: ", no_of_colleges)

    context = {}
    context['form'] = collection.form
    context['chart_data'] = chart_data
    page = request.GET.get('page')
    collection = get_page(collection.qs, page)
    context['collection'] = collection
    context['header'] = header
    context['ordering'] = ordering
    if status == TRAINING_PENDING:
        context['participants'] = pending_attendance_participant_count
    else:
        context['participants'] = participants
    context['model'] = 'Workshop/Training'
    context['status'] = status
    context['femalecount'] = femalecount
    context['malecount'] = malecount
    context['no_of_colleges'] = no_of_colleges

    context['language'] = Language.objects.values('id', 'name')
    return render(request, 'statistics/templates/training.html', context)
Beispiel #31
0
def academic_center(request, slug=None):
    context = {}
    header = {
        1: SortableHeader('#', False),
        2: SortableHeader('State', False),
        3: SortableHeader('institution_name', True, 'Institution Name'),
        4: SortableHeader('Training', False),
        5: SortableHeader('Participants', True),
        6: SortableHeader('Action', False)
    }

    collection = None
    start_date = request.GET.get('training__tdate_0', 0)
    end_date = request.GET.get('training__tdate_1', 0)
    lookup = None
    training_query = TrainingRequest.objects.filter(
        participants__gt=0, sem_start_date__lte=datetime.now())
    if start_date or end_date:
        if start_date and end_date:
            lookup = [start_date, end_date]
        elif start_date:
            lookup = [start_date, now()]
        else:
            lookup = [datetime.strptime('1970-01-01', '%Y-%m-%d'), end_date]
    if slug:
        collection = AcademicCenter.objects.filter(
            id__in=training_query.values_list(
                'training_planner__academic_id').distinct(),
            state__slug=slug).order_by('state__name', 'institution_name')
    else:
        if lookup:
            training_query = TrainingRequest.objects.filter(
                Q(sem_start_date__range=lookup)
                & Q(sem_start_date__lte=datetime.now()),
                participants__gt=0)
            collection = AcademicCenter.objects.filter(
                id__in=training_query.values_list(
                    'training_planner__academic_id').distinct()).order_by(
                        'state__name', 'institution_name')
        else:
            collection = AcademicCenter.objects.filter(
                id__in=training_query.values_list(
                    'training_planner__academic_id').distinct()).order_by(
                        'state__name', 'institution_name')

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

    collection = AcademicCenterFilter(request.GET, queryset=collection)
    context['form'] = collection.form
    context['total_training'] = training_query.count()
    participant_count = training_query.aggregate(Sum('participants'))
    print(participant_count)
    context['total_participant'] = participant_count['participants__sum']

    page = request.GET.get('page')
    collection = get_page(collection.qs, page)
    context['collection'] = collection
    context['header'] = header
    context['ordering'] = ordering

    return render(request, 'statistics/templates/academic-center.html',
                  context)
Beispiel #32
0
def academic_center(request, slug=None):
    context = {}
    header = {
        1: SortableHeader('#', False),
        2: SortableHeader('State', False),
        3: SortableHeader('institution_name', True, 'Institution Name'),
        4: SortableHeader('Training', False),
        5: SortableHeader('Participants', True),
        6: SortableHeader('Action', False)
    }

    collection = None
    start_date = request.GET.get('training__tdate_0', 0)
    end_date = request.GET.get('training__tdate_1', 0)
    lookup = None
    training_query = TrainingRequest.objects.filter(
        participants__gt=0,
        sem_start_date__lte=datetime.now()
    )
    if start_date or end_date:
        if start_date and end_date:
            lookup = [start_date, end_date]
        elif start_date:
            lookup = [start_date, now()]
        else:
            lookup = [datetime.strptime('1970-01-01', '%Y-%m-%d'), end_date]
    if slug:
        collection = AcademicCenter.objects.filter(
            id__in=training_query.values_list(
                'training_planner__academic_id'
            ).distinct(),
            state__slug=slug
        ).order_by('state__name', 'institution_name')
    else:
        if lookup:
            training_query = TrainingRequest.objects.filter(
                Q(sem_start_date__range=lookup) & Q(sem_start_date__lte=datetime.now()),
                participants__gt=0
            )
            collection = AcademicCenter.objects.filter(
                id__in=training_query.values_list(
                    'training_planner__academic_id'
                ).distinct()
            ).order_by('state__name', 'institution_name')
        else:
            collection = AcademicCenter.objects.filter(
                id__in=training_query.values_list(
                    'training_planner__academic_id'
                ).distinct()
            ).order_by('state__name', 'institution_name')

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

    collection = AcademicCenterFilter(request.GET, queryset=collection)
    context['form'] = collection.form
    context['total_training'] = training_query.count()
    participant_count = training_query.aggregate(Sum('participants'))
    print participant_count
    context['total_participant'] = participant_count['participants__sum']

    page = request.GET.get('page')
    collection = get_page(collection, page)
    context['collection'] = collection
    context['header'] = header
    context['ordering'] = ordering

    return render(request, 'statistics/templates/academic-center.html', context)
Beispiel #33
0
def fdp_training(request):
    """ Organiser index page """
    collectionSet = None
    state = None

    collectionSet = TrainingRequest.objects.filter(
        participants__gt=0, department=169,
        sem_start_date__lte=datetime.now()).order_by('-sem_start_date')
    header = {
        1:
        SortableHeader('#', False),
        2:
        SortableHeader('training_planner__academic__state__name', True,
                       'State'),
        3:
        SortableHeader('training_planner__academic__city__name', True, 'City'),
        4:
        SortableHeader('training_planner__academic__institution_name', True,
                       'Institution'),
        5:
        SortableHeader('course__foss__foss', True, 'FOSS'),
        6:
        SortableHeader('department', True, 'Department'),
        7:
        SortableHeader('course__category', True, 'Type'),
        8:
        SortableHeader('training_planner__organiser__user__first_name', True,
                       'Organiser'),
        9:
        SortableHeader('sem_start_date', True, 'Date'),
        10:
        SortableHeader('participants', 'True', 'Participants'),
        11:
        SortableHeader('Action', False)
    }

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

    # find state id
    if 'training_planner__academic__state' in request.GET and request.GET[
            'training_planner__academic__state']:
        state = State.objects.get(
            id=request.GET['training_planner__academic__state'])

    collection = TrainingRequestFilter(request.GET,
                                       queryset=collection,
                                       state=state)
    # find participants count
    participants = collection.qs.aggregate(Sum('participants'))

    femalecount = 0
    female_list = list(
        Student.objects.filter(
            trainingattend__training_id__in=[col.id for col in collection.qs],
            gender='Female').values_list('id'))
    femalecount = len([i[0] for i in female_list])

    malecount = 0
    male_list = list(
        Student.objects.filter(
            trainingattend__training_id__in=[col.id for col in collection.qs],
            gender='Male').values_list('id'))
    malecount = len([i[0] for i in male_list])

    chart_query_set = collection.qs.extra(
        select={
            'year': "EXTRACT(year FROM sem_start_date)"
        }).values('year').order_by('-year').annotate(
            total_training=Count('sem_start_date'),
            total_participant=Sum('participants'))
    chart_data = ''
    for data in chart_query_set:
        chart_data += "['" + str(data['year']) + "', " + str(
            data['total_participant']) + "],"

    no_of_colleges = collection.qs.filter().values(
        'training_planner__academic_id').distinct().count()
    print(" ********************** no of colleges: ", no_of_colleges)

    context = {}
    context['form'] = collection.form
    context['chart_data'] = chart_data
    page = request.GET.get('page')
    collection = get_page(collection.qs, page)
    context['collection'] = collection
    context['header'] = header
    context['ordering'] = ordering
    context['participants'] = participants
    context['model'] = 'Workshop/Training'
    context['femalecount'] = femalecount
    context['malecount'] = malecount
    context['no_of_colleges'] = no_of_colleges
    return render(request, 'statistics/templates/pmmm_stats.html', context)
Beispiel #34
0
def training(request):
    """ Organiser index page """
    collectionSet = TrainingRequest.objects.filter(
        sem_start_date__lte=datetime.now()).order_by('-sem_start_date')
    state = None
    TRAINING_COMPLETED = '1'
    TRAINING_PENDING = '0'

    if request.method == 'GET':
        status = request.GET.get('status')
        if status not in [TRAINING_COMPLETED, TRAINING_PENDING]:
            status = TRAINING_COMPLETED

    if status == TRAINING_PENDING:
        collectionSet = collectionSet.filter(participants=0,
                                             status=TRAINING_COMPLETED)

    else:
        collectionSet = collectionSet.filter(participants__gt=0)
    header = {
        1:
        SortableHeader('#', False),
        2:
        SortableHeader('training_planner__academic__state__name', True,
                       'State'),
        3:
        SortableHeader('training_planner__academic__city__name', True, 'City'),
        4:
        SortableHeader('training_planner__academic__institution_name', True,
                       'Institution'),
        5:
        SortableHeader('course__foss__foss', True, 'FOSS'),
        6:
        SortableHeader('department', True, 'Department'),
        7:
        SortableHeader('course__category', True, 'Type'),
        8:
        SortableHeader('training_planner__organiser__user__first_name', True,
                       'Organiser'),
        9:
        SortableHeader('sem_start_date', True, 'Date'),
        10:
        SortableHeader('participants', 'True', 'Participants'),
        11:
        SortableHeader('Action', False)
    }

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

    # find state id
    if 'training_planner__academic__state' in request.GET and request.GET[
            'training_planner__academic__state']:
        state = State.objects.get(
            id=request.GET['training_planner__academic__state'])

    collection = TrainingRequestFilter(request.GET,
                                       queryset=collection,
                                       state=state)
    # find participants count

    participants = collection.qs.aggregate(Sum('participants'))

    chart_query_set = collection.qs.extra(
        select={
            'year': "EXTRACT(year FROM sem_start_date)"
        }).values('year').order_by('-year').annotate(
            total_training=Count('sem_start_date'),
            total_participant=Sum('participants'))
    chart_data = ''

    get_year = []
    pending_attendance_participant_count = 0

    year_data_all = dict()
    visited = dict()
    if status == TRAINING_PENDING:

        pending_attendance_student_batches = StudentBatch.objects.filter(
            id__in=(collection.qs.filter(status=TRAINING_COMPLETED,
                                         participants=0,
                                         batch_id__gt=0).values('batch_id')))
        pending_attendance_training = collection.qs.filter(
            batch_id__in=pending_attendance_student_batches.filter().values(
                'id')).distinct()

        for batch in pending_attendance_student_batches:
            pending_attendance_participant_count += batch.stcount
        for a_traning in pending_attendance_training:
            if a_traning.batch_id not in visited:
                if a_traning.sem_start_date.year in year_data_all:
                    visited[a_traning.batch_id] = [a_traning.batch_id]
                    year_data_all[a_traning.sem_start_date.
                                  year] += a_traning.batch.stcount
                else:
                    visited[a_traning.batch_id] = [a_traning.batch_id]
                    year_data_all[a_traning.sem_start_date.
                                  year] = a_traning.batch.stcount

    if status == TRAINING_COMPLETED:
        for data in chart_query_set:
            chart_data += "['" + str(data['year']) + "', " + str(
                data['total_participant']) + "],"
    else:
        for year, count in year_data_all.iteritems():
            chart_data += "['" + str(year) + "', " + str(count) + "],"

    context = {}
    context['form'] = collection.form
    context['chart_data'] = chart_data
    page = request.GET.get('page')
    collection = get_page(collection, page)
    context['collection'] = collection
    context['header'] = header
    context['ordering'] = ordering
    if status == TRAINING_PENDING:
        context['participants'] = pending_attendance_participant_count
    else:
        context['participants'] = participants
    context['model'] = 'Workshop/Training'
    context['status'] = status

    return render(request, 'statistics/templates/training.html', context)
Beispiel #35
0
def training(request):
    """ Organiser index page """
    collectionSet = TrainingRequest.objects.filter(
            sem_start_date__lte=datetime.now()
        ).order_by('-sem_start_date')
    state = None
    TRAINING_COMPLETED = '1'
    TRAINING_PENDING = '0'
    if request.method == 'GET':
        status = request.GET.get('status')
        if status not in [TRAINING_COMPLETED, TRAINING_PENDING]:
            status = TRAINING_COMPLETED

        lang= request.GET.get('lang')
        if status == TRAINING_COMPLETED:
            if lang and '---------' not in lang:
                training_attend_lang = TrainingAttend.objects.filter(language__name=lang).values_list('training_id').distinct()
                collectionSet= collectionSet.filter(id__in=training_attend_lang)
        
        
    if status == TRAINING_PENDING:
        collectionSet = collectionSet.filter(participants=0, status=TRAINING_COMPLETED)
        
    else:
        collectionSet = collectionSet.filter(participants__gt=0)
    header = {
        1: SortableHeader('#', False),
        2: SortableHeader('training_planner__academic__state__name', True, 'State'),
        3: SortableHeader('training_planner__academic__city__name', True, 'City'),
        4: SortableHeader('training_planner__academic__institution_name', True, 'Institution'),
        5: SortableHeader('course__foss__foss', True, 'FOSS'),
        6: SortableHeader('department', True, 'Department'),
        7: SortableHeader('course__category', True, 'Type'),
        8: SortableHeader('training_planner__organiser__user__first_name', True, 'Organiser'),
        9: SortableHeader('sem_start_date', True, 'Date'),
        10: SortableHeader('participants', 'True', 'Participants'),
        11: SortableHeader('Action', False)
    }

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

    
    # find state id
    if 'training_planner__academic__state' in request.GET and request.GET['training_planner__academic__state']:
        state = State.objects.get(id=request.GET['training_planner__academic__state'])

    collection = TrainingRequestFilter(request.GET, queryset=collection, state=state)
    # find participants count
    
    participants = collection.qs.aggregate(Sum('participants')) 

    if lang == 'English':
        participants = participants['participants__sum']+294593

    else:
        participants = participants['participants__sum']

    chart_query_set = collection.qs.extra(select={'year': "EXTRACT(year FROM sem_start_date)"}).values('year').order_by(
            '-year').annotate(total_training=Count('sem_start_date'), total_participant=Sum('participants'))
    chart_data = ''
    
    get_year = []
    pending_attendance_participant_count = 0

    year_data_all=dict()
    visited=dict()
    if status == TRAINING_PENDING:

        pending_attendance_student_batches = StudentBatch.objects.filter(
            id__in=(collection.qs.filter(status=TRAINING_COMPLETED,participants=0,batch_id__gt=0).values('batch_id'))
            )
        pending_attendance_training = collection.qs.filter(batch_id__in = pending_attendance_student_batches.filter().values('id')).distinct()

        for batch in pending_attendance_student_batches:
            pending_attendance_participant_count += batch.stcount
        for a_traning in pending_attendance_training:
            if a_traning.batch_id not in visited:
                if a_traning.sem_start_date.year in year_data_all:
                    visited[a_traning.batch_id] = [a_traning.batch_id]
                    year_data_all[a_traning.sem_start_date.year] +=  a_traning.batch.stcount
                else:
                    visited[a_traning.batch_id] = [a_traning.batch_id]
                    year_data_all[a_traning.sem_start_date.year] =  a_traning.batch.stcount


    if status == TRAINING_COMPLETED:
        for data in chart_query_set:
            chart_data += "['" + str(data['year']) + "', " + str(data['total_participant']) + "],"
    else:
        for year,count in year_data_all.iteritems():
            chart_data += "['" + str(year) + "', " + str(count) + "],"
    
    context = {}
    context['form'] = collection.form
    context['chart_data'] = chart_data
    page = request.GET.get('page')
    collection = get_page(collection, page)
    context['collection'] = collection
    context['header'] = header
    context['ordering'] = ordering
    if status == TRAINING_PENDING:
        context['participants'] = pending_attendance_participant_count
    else:
        context['participants'] = participants
    context['model'] = 'Workshop/Training'
    context['status']=status
    context['language'] = Language.objects.values('id','name')
    return render(request, 'statistics/templates/training.html', context)