From a71ff4336da4ca9390afdce31dd2b3a2117b9ed2 Mon Sep 17 00:00:00 2001 From: fbormann Date: Mon, 27 Mar 2017 16:13:48 -0300 Subject: [PATCH] added webconference variables to report view as well as added distinct days variables to all kind of resources --- links/views.py | 4 ++-- reports/views.py | 23 ++++++++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/links/views.py b/links/views.py index 914849d..d82c720 100644 --- a/links/views.py +++ b/links/views.py @@ -21,7 +21,7 @@ from topics.models import Topic class CreateLinkView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): log_component = 'resources' log_action = 'create' - log_resource = 'links' + log_resource = 'link' log_context = {} login_url = reverse_lazy("users:login") @@ -185,7 +185,7 @@ class DeleteLinkView(LoginRequiredMixin, LogMixin, generic.edit.DeleteView): class DetailLinkView(LoginRequiredMixin, LogMixin, generic.detail.DetailView): log_component = 'resources' log_action = 'view' - log_resource = 'links' + log_resource = 'link' log_context = {} login_url = reverse_lazy("users:login") redirect_field_name = 'next' diff --git a/reports/views.py b/reports/views.py index 2788563..87957c9 100644 --- a/reports/views.py +++ b/reports/views.py @@ -58,7 +58,6 @@ class ReportView(LoginRequiredMixin, generic.FormView): classes = Resource.__subclasses__() - #set formset resourceTagFormSet = formset_factory(ResourceAndTagForm, formset=BaseResourceAndTagFormset) resourceTagFormSet = resourceTagFormSet() @@ -319,26 +318,44 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): distinct_resources = 0 total_count = 0 + day_numbers = [0, 1, 2, 3, 4, 5, 6] + distinct_days = 0 for resource in resources: + if isinstance(topics,Topic): #or it selected only one topic to work with count = Log.objects.filter(action="view", resource=resources_types[i].lower(), user_id = student.id, context__contains = {'subject_id': subject.id, resources_types[i].lower()+'_id': resource.id, 'topic_id': topics.id}, datetime__range=(init_date, end_date)).count() - + + for daynum in day_numbers: + count_temp = Log.objects.filter(action="view", resource=resources_types[i].lower(), + user_id = student.id, context__contains = {'subject_id': subject.id, + resources_types[i].lower()+'_id': resource.id, 'topic_id': topics.id}, datetime__week_day = day_num+1, datetime__range=(init_date, end_date)).count() + if count_temp > 0: + distinct_days += 1 else: #or the user selected all - count = Log.objects.filter(action="view", resource=resources_types[i].lower(), + count = Log.objects.filter(action="view", resource=resources_types[i].lower(), user_id = student.id, context__contains = {'subject_id': subject.id, resources_types[i].lower()+'_id': resource.id}, datetime__range=(init_date, end_date)).count() + for daynum in day_numbers: + count_temp = Log.objects.filter(action="view", resource=resources_types[i].lower(), + user_id = student.id, context__contains = {'subject_id': subject.id, + resources_types[i].lower()+'_id': resource.id}, datetime__week_day = daynum+1, + datetime__range=(init_date, end_date)).count() + if count_temp > 0: + distinct_days += 1 if count > 0: distinct_resources += 1 total_count += count data[str(resources_types[i]) + " with tag " + Tag.objects.get(id=int(tags[i])).name] = total_count data["distintic " + str(resources_types[i]) + " with tag " + Tag.objects.get(id=int(tags[i])).name] = distinct_resources + data["distintic days " + str(resources_types[i]) + " with tag " + Tag.objects.get(id=int(tags[i])).name] = distinct_days + """data["distinct" + str(resources[i]) + " with tag " + Tag.objects.get(id=int(tags[i])).name] = Log.objects.filter(action="view", resource=resources[i].lower(), user_id = student.id, context__contains = {'subject_id': subject.id}).distinct().count()""" -- libgit2 0.21.2