Commit ce0d18b721a2797e9f4281c60bc7f8df8e6dba4e

Authored by Jailson Dias
2 parents b69f9328 c36058ee

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 12 from django.db.models import Q
13 13 from django.contrib.auth.mixins import LoginRequiredMixin
14 14 from datetime import datetime, date
15   -from subjects.models import Subject
  15 +from subjects.models import Subject, Tag
16 16 from .forms import CreateInteractionReportForm, ResourceAndTagForm, BaseResourceAndTagFormset
17 17 from log.models import Log
18 18 from topics.models import Resource, Topic
... ... @@ -130,13 +130,12 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView):
130 130 context['init_date'] = params_data['init_date']
131 131 context['end_date'] = params_data['end_date']
132 132 context['subject'] = subject
133   - print(params_data)
134   -
135 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 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 139 data = {}
141 140 students = subject.students.all()
142 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 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 209 #VAR20 - number of access to mural between 6 a.m to 12a.m.
208 210 interactions[' number of access to mural between 6 a.m to 12a.m.'] = Log.objects.filter(action="access", resource="subject",
209 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 227 for day_num in day_numbers:
226 228 interactions['number of access to the subject on '+ day_names[day_num]] = Log.objects.filter(action="access", resource="subject",
227 229 user_id= student.id, context__contains = {'subject_id' : subject.id}, datetime__week_day = day_num).count()
228   -
  230 +
  231 +
229 232 for value in interactions.values():
230 233 data[student].append(value)
231 234  
... ... @@ -234,6 +237,19 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView):
234 237 header.append(key)
235 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 255 def get_resources(request):
... ...