コード例 #1
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)

        get_user(self.request, self.object.pk)  #TODO: Change permissions check
        course = can_view_course(self.request, self.kwargs['course_id'])

        act_quizzes = Activity.objects \
            .filter(section__course=course, type=Activity.QUIZ) \
            .order_by('section__order', 'order')

        quizzes_attempted = 0
        quizzes_passed = 0
        course_pretest = None

        quizzes = []
        for aq in act_quizzes:
            quiz, course_pretest, quizzes_attempted, quizzes_passed = \
                process_quiz_activity(self.object, aq, course_pretest, quizzes_attempted, quizzes_passed)
            quizzes.append(quiz)

        activities_completed = course.get_activities_completed(
            course, self.object)
        activities_total = course.get_no_activities()
        activities_percent = (activities_completed * 100) / activities_total

        start_date, end_date = self.get_daterange()

        activity = get_tracker_activities(start_date,
                                          end_date,
                                          self.object,
                                          course=course)

        order_options = [
            'quiz_order', 'no_attempts', 'max_score', 'min_score',
            'first_score', 'latest_score', 'avg_score'
        ]
        default_order = 'quiz_order'
        ordering = self.request.GET.get('order_by', default_order)
        inverse_order = ordering.startswith('-')
        if inverse_order:
            ordering = ordering[1:]
        if ordering not in order_options:
            ordering = default_order
            inverse_order = False

        quizzes.sort(key=operator.itemgetter(ordering), reverse=inverse_order)

        context['page_ordering'] = ('-' if inverse_order else '') + ordering
        context['course'] = course
        context['quizzes'] = quizzes
        context['quizzes_passed'] = quizzes_passed
        context['quizzes_attempted'] = quizzes_attempted
        context['pretest_score'] = course_pretest
        context['activities_completed'] = activities_completed
        context['activities_total'] = activities_total
        context['activities_percent'] = activities_percent
        context['activity_graph_data'] = activity

        return context
コード例 #2
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        get_user(self.request, self.object.pk)  #TODO: Change permissions check
        cohort_courses, other_courses, all_courses = get_user_courses(
            self.request, self.object)

        courses = []
        for course in all_courses:
            course.can_view_course_activity = can_view_course_activity(
                self.request, course.id)
            courses.append(
                UserCourseSummary.objects.get_stats_summary(
                    self.object, course))

        order_options = [
            'course_display', 'no_quizzes_completed', 'pretest_score',
            'no_activities_completed', 'no_points', 'no_badges',
            'no_media_viewed'
        ]
        default_order = 'course_display'

        ordering = self.request.GET.get('order_by', default_order)
        inverse_order = ordering.startswith('-')
        if inverse_order:
            ordering = ordering[1:]

        if ordering not in order_options:
            ordering = default_order
            inverse_order = False

        courses.sort(key=operator.itemgetter(ordering), reverse=inverse_order)

        start_date, end_date = self.get_daterange()
        course_ids = list(
            chain(cohort_courses.values_list('id', flat=True),
                  other_courses.values_list('id', flat=True)))
        activity = get_tracker_activities(start_date,
                                          end_date,
                                          self.object,
                                          course_ids=course_ids)

        context['courses'] = courses
        context['page_ordering'] = ('-' if inverse_order else '') + ordering
        context['activity_graph_data'] = activity
        return context
コード例 #3
0
ファイル: activity.py プロジェクト: zbidi/django-oppia
def user_course_activity_view(request, user_id, course_id):

    view_user = get_user(request, user_id)

    dashboard_accessed.send(sender=None, request=request, data=None)
    course = can_view_course(request, course_id)

    act_quizzes = Activity.objects \
        .filter(section__course=course, type=Activity.QUIZ) \
        .order_by('section__order', 'order')

    quizzes_attempted = 0
    quizzes_passed = 0
    course_pretest = None

    quizzes = []
    for aq in act_quizzes:
        quiz, course_pretest, quizzes_attempted, quizzes_passed = \
            process_quiz_activity(view_user,
                                  aq,
                                  course_pretest,
                                  quizzes_attempted,
                                  quizzes_passed)
        quizzes.append(quiz)

    activities_completed = course.get_activities_completed(course, view_user)
    activities_total = course.get_no_activities()
    activities_percent = (activities_completed * 100) / activities_total

    start_date = timezone.now() - datetime.timedelta(days=31)
    end_date = timezone.now()

    activity = get_tracker_activities(start_date,
                                      end_date,
                                      view_user,
                                      course=course)

    order_options = [
        'quiz_order', 'no_attempts', 'max_score', 'min_score', 'first_score',
        'latest_score', 'avg_score'
    ]
    default_order = 'quiz_order'
    ordering = request.GET.get('order_by', default_order)
    inverse_order = ordering.startswith('-')
    if inverse_order:
        ordering = ordering[1:]
    if ordering not in order_options:
        ordering = default_order
        inverse_order = False

    quizzes.sort(key=operator.itemgetter(ordering), reverse=inverse_order)

    return render(
        request, 'profile/user-course-scorecard.html', {
            'view_user': view_user,
            'course': course,
            'quizzes': quizzes,
            'quizzes_passed': quizzes_passed,
            'quizzes_attempted': quizzes_attempted,
            'pretest_score': course_pretest,
            'activities_completed': activities_completed,
            'activities_total': activities_total,
            'activities_percent': activities_percent,
            'page_ordering': ('-' if inverse_order else '') + ordering,
            'activity_graph_data': activity
        })
コード例 #4
0
ファイル: activity.py プロジェクト: zbidi/django-oppia
def user_activity(request, user_id):

    view_user = get_user(request, user_id)

    dashboard_accessed.send(sender=None, request=request, data=None)

    cohort_courses, other_courses, all_courses = get_user_courses(
        request, view_user)

    courses = []
    for course in all_courses:
        course_stats = UserCourseSummary.objects.filter(user=view_user,
                                                        course=course)
        if course_stats:
            course_stats = course_stats[0]
            data = {
                'course': course,
                'course_display': str(course),
                'no_quizzes_completed': course_stats.quizzes_passed,
                'pretest_score': course_stats.pretest_score,
                'no_activities_completed': course_stats.completed_activities,
                'no_media_viewed': course_stats.media_viewed,
                'no_points': course_stats.points,
                'no_badges': course_stats.badges_achieved,
            }
        else:
            data = {
                'course': course,
                'course_display': str(course),
                'no_quizzes_completed': 0,
                'pretest_score': None,
                'no_activities_completed': 0,
                'no_media_viewed': 0,
                'no_points': 0,
                'no_badges': 0,
            }

        courses.append(data)

    order_options = [
        'course_display', 'no_quizzes_completed', 'pretest_score',
        'no_activities_completed', 'no_points', 'no_badges', 'no_media_viewed'
    ]
    default_order = 'course_display'

    ordering = request.GET.get('order_by', default_order)
    inverse_order = ordering.startswith('-')
    if inverse_order:
        ordering = ordering[1:]

    if ordering not in order_options:
        ordering = default_order
        inverse_order = False

    courses.sort(key=operator.itemgetter(ordering), reverse=inverse_order)

    start_date = timezone.now() - datetime.timedelta(days=31)
    end_date = timezone.now()

    course_ids = list(
        chain(cohort_courses.values_list('id', flat=True),
              other_courses.values_list('id', flat=True)))
    activity = get_tracker_activities(start_date,
                                      end_date,
                                      view_user,
                                      course_ids=course_ids)

    return render(
        request, 'profile/user-scorecard.html', {
            'view_user': view_user,
            'courses': courses,
            'page_ordering': ('-' if inverse_order else '') + ordering,
            'activity_graph_data': activity
        })