Example #1
0
    def get_context_data(self, **kwargs):

        context = super().get_context_data(**kwargs)
        can_view_course_detail(self.request, self.object.id)

        start_date = timezone.now() - datetime.timedelta(
            days=constants.ACTIVITY_GRAPH_DEFAULT_NO_DAYS)
        end_date = timezone.now()
        initial = {'start_date': start_date, 'end_date': end_date}
        initial.update(self.request.GET.dict())

        form = DateRangeForm(initial)
        if form.is_valid():
            start_date = timezone.make_aware(
                datetime.datetime.strptime(form.cleaned_data.get("start_date"),
                                           constants.STR_DATE_FORMAT),
                timezone.get_current_timezone())
            end_date = timezone.make_aware(
                datetime.datetime.strptime(form.cleaned_data.get("end_date"),
                                           constants.STR_DATE_FORMAT),
                timezone.get_current_timezone())

        form.form_method = 'get'
        context['form'] = form
        context['page'] = self.get_activitylogs_page(start_date, end_date)
        return context
Example #2
0
def recent_activity_detail(request, course_id):
    course, response = can_view_course_detail(request, course_id)

    if response is not None:
        return response

    start_date = datetime.datetime.now() - datetime.timedelta(days=31)
    end_date = datetime.datetime.now()
    if request.method == 'POST':
        form = DateRangeForm(request.POST)
        if form.is_valid():
            start_date = form.cleaned_data.get("start_date")
            start_date = datetime.datetime.strptime(start_date, "%Y-%m-%d")
            end_date = form.cleaned_data.get("end_date")
            end_date = datetime.datetime.strptime(end_date, "%Y-%m-%d")
            trackers = Tracker.objects.filter(
                course=course,
                tracker_date__gte=start_date,
                tracker_date__lte=end_date).order_by('-tracker_date')
        else:
            trackers = Tracker.objects.filter(
                course=course).order_by('-tracker_date')
    else:
        data = {}
        data['start_date'] = start_date
        data['end_date'] = end_date
        form = DateRangeForm(initial=data)
        trackers = Tracker.objects.filter(
            course=course).order_by('-tracker_date')

    paginator = Paginator(trackers, 25)
    # Make sure page request is an int. If not, deliver first page.
    try:
        page = int(request.GET.get('page', '1'))
    except ValueError:
        page = 1

    # If page request (9999) is out of range, deliver last page of results.
    try:
        tracks = paginator.page(page)
        for t in tracks:
            t.data_obj = []
            try:
                data_dict = json.loads(t.data)
                for key, value in data_dict.items():
                    t.data_obj.append([key, value])
            except ValueError:
                pass
            t.data_obj.append(['agent', t.agent])
            t.data_obj.append(['ip', t.ip])
    except (EmptyPage, InvalidPage):
        tracks = paginator.page(paginator.num_pages)

    return render(request, 'course/activity-detail.html', {
        'course': course,
        'form': form,
        'page': tracks,
    })
Example #3
0
def recent_activity_detail(request, course_id):
    course, response = can_view_course_detail(request, course_id)

    if response is not None:
        return response

    start_date = datetime.datetime.now() - datetime.timedelta(days=31)
    end_date = datetime.datetime.now()
    if request.method == 'POST':
        form = DateRangeForm(request.POST)
        if form.is_valid():
            start_date = form.cleaned_data.get("start_date")
            start_date = datetime.datetime.strptime(start_date, "%Y-%m-%d")
            end_date = form.cleaned_data.get("end_date")
            end_date = datetime.datetime.strptime(end_date, "%Y-%m-%d")
            trackers = Tracker.objects.filter(course=course, tracker_date__gte=start_date, tracker_date__lte=end_date).order_by('-tracker_date')
        else:
            trackers = Tracker.objects.filter(course=course).order_by('-tracker_date')
    else:
        data = {}
        data['start_date'] = start_date
        data['end_date'] = end_date
        form = DateRangeForm(initial=data)
        trackers = Tracker.objects.filter(course=course).order_by('-tracker_date')

    paginator = Paginator(trackers, 25)
    # Make sure page request is an int. If not, deliver first page.
    try:
        page = int(request.GET.get('page', '1'))
    except ValueError:
        page = 1

    # If page request (9999) is out of range, deliver last page of results.
    try:
        tracks = paginator.page(page)
        for t in tracks:
            t.data_obj = []
            try:
                data_dict = json.loads(t.data)
                for key, value in data_dict.items():
                    t.data_obj.append([key, value])
            except ValueError:
                pass
            t.data_obj.append(['agent', t.agent])
            t.data_obj.append(['ip', t.ip])
    except (EmptyPage, InvalidPage):
        tracks = paginator.page(paginator.num_pages)

    return render(request, 'oppia/course/activity-detail.html',
                              {'course': course,
                               'form': form,
                               'page': tracks, })
Example #4
0
    def post(self, request, course_id):
        course = can_view_course_detail(request, course_id)

        form = DateRangeForm(request.POST)
        if form.is_valid():
            start_date = form.cleaned_data.get("start_date")
            start_date = datetime.datetime.strptime(start_date, "%Y-%m-%d")
            end_date = form.cleaned_data.get("end_date")
            end_date = datetime.datetime.strptime(end_date, "%Y-%m-%d")
        else:
            start_date = datetime.datetime.now() - datetime.timedelta(days=31)
            end_date = datetime.datetime.now()

        return self.process(request, course, form, start_date, end_date)
Example #5
0
    def post(self, request, course_id):
        course = can_view_course_detail(request, course_id)

        form = DateRangeForm(request.POST)
        if form.is_valid():
            start_date = timezone.make_aware(
                datetime.datetime.strptime(form.cleaned_data.get("start_date"),
                                           constants.STR_DATE_FORMAT),
                timezone.get_current_timezone())
            end_date = timezone.make_aware(
                datetime.datetime.strptime(form.cleaned_data.get("end_date"),
                                           constants.STR_DATE_FORMAT),
                timezone.get_current_timezone())
        else:
            start_date = timezone.now() - datetime.timedelta(
                days=constants.ACTIVITY_GRAPH_DEFAULT_NO_DAYS)
            end_date = timezone.now()

        return self.process(request, course, form, start_date, end_date)