Commit ce0d18b721a2797e9f4281c60bc7f8df8e6dba4e
Exists in
master
and in
3 other branches
Merge branch 'refactoring' of https://github.com/amadeusproject/amadeuslms into refactoring
Showing
1 changed file
with
23 additions
and
7 deletions
Show diff stats
reports/views.py
@@ -12,7 +12,7 @@ from mural.models import SubjectPost, Comment, MuralVisualizations | @@ -12,7 +12,7 @@ from mural.models import SubjectPost, Comment, MuralVisualizations | ||
12 | from django.db.models import Q | 12 | from django.db.models import Q |
13 | from django.contrib.auth.mixins import LoginRequiredMixin | 13 | from django.contrib.auth.mixins import LoginRequiredMixin |
14 | from datetime import datetime, date | 14 | from datetime import datetime, date |
15 | -from subjects.models import Subject | 15 | +from subjects.models import Subject, Tag |
16 | from .forms import CreateInteractionReportForm, ResourceAndTagForm, BaseResourceAndTagFormset | 16 | from .forms import CreateInteractionReportForm, ResourceAndTagForm, BaseResourceAndTagFormset |
17 | from log.models import Log | 17 | from log.models import Log |
18 | from topics.models import Resource, Topic | 18 | from topics.models import Resource, Topic |
@@ -130,13 +130,12 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): | @@ -130,13 +130,12 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): | ||
130 | context['init_date'] = params_data['init_date'] | 130 | context['init_date'] = params_data['init_date'] |
131 | context['end_date'] = params_data['end_date'] | 131 | context['end_date'] = params_data['end_date'] |
132 | context['subject'] = subject | 132 | context['subject'] = subject |
133 | - print(params_data) | ||
134 | - | ||
135 | if params_data['from_mural']: | 133 | if params_data['from_mural']: |
136 | - context['data'], context['header'] = self.get_mural_data(subject, params_data['init_date'], params_data['end_date']) | 134 | + context['data'], context['header'] = self.get_mural_data(subject, params_data['init_date'], params_data['end_date'], |
135 | + params_data.getlist('resource'), params_data.getlist('tag')) | ||
137 | return context | 136 | return context |
138 | 137 | ||
139 | - def get_mural_data(self, subject, init_date, end_date): | 138 | + def get_mural_data(self, subject, init_date, end_date, resources_id, tags_id): |
140 | data = {} | 139 | data = {} |
141 | students = subject.students.all() | 140 | students = subject.students.all() |
142 | formats = ["%d/%m/%Y", "%m/%d/%Y"] #so it accepts english and portuguese date formats | 141 | formats = ["%d/%m/%Y", "%m/%d/%Y"] #so it accepts english and portuguese date formats |
@@ -202,8 +201,11 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): | @@ -202,8 +201,11 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): | ||
202 | user = student).count() | 201 | user = student).count() |
203 | 202 | ||
204 | 203 | ||
205 | - #VAR08 - | 204 | + #VAR08 through VAR_019 of documenttation: |
205 | + print(resources_id) | ||
206 | + resources_data = self.get_resources_and_tags_data(resources_id, tags_id, student, subject) | ||
206 | 207 | ||
208 | + interactions = {**interactions, **resources_data} | ||
207 | #VAR20 - number of access to mural between 6 a.m to 12a.m. | 209 | #VAR20 - number of access to mural between 6 a.m to 12a.m. |
208 | interactions[' number of access to mural between 6 a.m to 12a.m.'] = Log.objects.filter(action="access", resource="subject", | 210 | interactions[' number of access to mural between 6 a.m to 12a.m.'] = Log.objects.filter(action="access", resource="subject", |
209 | user_id= student.id, context__contains = {'subject_id' : subject.id}, datetime__hour__range = (5, 11)).count() | 211 | user_id= student.id, context__contains = {'subject_id' : subject.id}, datetime__hour__range = (5, 11)).count() |
@@ -225,7 +227,8 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): | @@ -225,7 +227,8 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): | ||
225 | for day_num in day_numbers: | 227 | for day_num in day_numbers: |
226 | interactions['number of access to the subject on '+ day_names[day_num]] = Log.objects.filter(action="access", resource="subject", | 228 | interactions['number of access to the subject on '+ day_names[day_num]] = Log.objects.filter(action="access", resource="subject", |
227 | user_id= student.id, context__contains = {'subject_id' : subject.id}, datetime__week_day = day_num).count() | 229 | user_id= student.id, context__contains = {'subject_id' : subject.id}, datetime__week_day = day_num).count() |
228 | - | 230 | + |
231 | + | ||
229 | for value in interactions.values(): | 232 | for value in interactions.values(): |
230 | data[student].append(value) | 233 | data[student].append(value) |
231 | 234 | ||
@@ -234,6 +237,19 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): | @@ -234,6 +237,19 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): | ||
234 | header.append(key) | 237 | header.append(key) |
235 | return data, header | 238 | return data, header |
236 | 239 | ||
240 | + def get_resources_and_tags_data(self, resources, tags, student, subject): | ||
241 | + data = {} | ||
242 | + | ||
243 | + for i in range(len(resources)): | ||
244 | + print(data) | ||
245 | + print(resources) | ||
246 | + print(resources[i]) | ||
247 | + print(tags[i]) | ||
248 | + data[str(resources[i]) + " with tag " + Tag.objects.get(id=int(tags[i])).name] = Log.objects.filter(action="view", resource=resources[i].lower(), | ||
249 | + user_id = student.id, context__contains = {'subject_id': subject.id}).count() | ||
250 | + | ||
251 | + return data | ||
252 | + | ||
237 | 253 | ||
238 | 254 | ||
239 | def get_resources(request): | 255 | def get_resources(request): |