Commit 491acec3d2247f1636de5d42ee85488f2b909fae
1 parent
f530725e
Exists in
master
and in
2 other branches
Criando links e view para estatisticas da webpage
Showing
3 changed files
with
116 additions
and
22 deletions
Show diff stats
topics/templates/resources/list.html
... | ... | @@ -29,6 +29,10 @@ |
29 | 29 | </button> |
30 | 30 | <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="moreResources"> |
31 | 31 | <li><a href="{% url resource.update_link topic.slug resource.slug %}" class="edit"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> |
32 | + | |
33 | + {% if resource|class_name == 'webpage' %} | |
34 | + <li><a href="{% url 'webpages:get_chart' resource.slug %}" class="edit"><i class="fa fa-line-chart fa-fw" aria-hidden="true"></i>{% trans 'Statistics' %}</a></li> | |
35 | + {% endif %} | |
32 | 36 | {% if resource|class_name == 'goals' %} |
33 | 37 | <li><a href="{% url 'goals:reports' resource.slug %}" class="edit"><i class="fa fa-file-pdf-o fa-fw" aria-hidden="true"></i>{% trans 'Reports' %}</a></li> |
34 | 38 | {% endif %} | ... | ... |
webpage/urls.py
... | ... | @@ -9,4 +9,5 @@ urlpatterns = [ |
9 | 9 | url(r'^delete/(?P<slug>[\w_-]+)/$', views.DeleteView.as_view(), name = 'delete'), |
10 | 10 | url(r'^window_view/(?P<slug>[\w_-]+)/$', views.NewWindowView.as_view(), name = 'window_view'), |
11 | 11 | url(r'^view/(?P<slug>[\w_-]+)/$', views.InsideView.as_view(), name = 'view'), |
12 | + url(r'^chart/(?P<slug>[\w_-]+)/$', views.StatisticsView.as_view(), name = 'get_chart'), | |
12 | 13 | ] | ... | ... |
webpage/views.py
... | ... | @@ -4,6 +4,7 @@ from django.contrib import messages |
4 | 4 | from django.core.urlresolvers import reverse, reverse_lazy |
5 | 5 | from django.utils.translation import ugettext_lazy as _ |
6 | 6 | from django.contrib.auth.mixins import LoginRequiredMixin |
7 | +from django.http import JsonResponse | |
7 | 8 | |
8 | 9 | from amadeus.permissions import has_subject_permissions, has_resource_permissions |
9 | 10 | |
... | ... | @@ -57,7 +58,7 @@ class NewWindowView(LoginRequiredMixin, LogMixin, generic.DetailView): |
57 | 58 | self.log_context['webpage_slug'] = self.object.slug |
58 | 59 | self.log_context['timestamp_start'] = str(int(time.time())) |
59 | 60 | |
60 | - super(NewWindowView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
61 | + super(NewWindowView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
61 | 62 | |
62 | 63 | self.request.session['log_id'] = Log.objects.latest('id').id |
63 | 64 | |
... | ... | @@ -68,13 +69,13 @@ class InsideView(LoginRequiredMixin, LogMixin, generic.DetailView): |
68 | 69 | log_action = 'view' |
69 | 70 | log_resource = 'webpage' |
70 | 71 | log_context = {} |
71 | - | |
72 | + | |
72 | 73 | login_url = reverse_lazy("users:login") |
73 | 74 | redirect_field_name = 'next' |
74 | 75 | |
75 | 76 | template_name = 'webpages/view.html' |
76 | 77 | model = Webpage |
77 | - context_object_name = 'webpage' | |
78 | + context_object_name = 'webpage' | |
78 | 79 | |
79 | 80 | def dispatch(self, request, *args, **kwargs): |
80 | 81 | slug = self.kwargs.get('slug', '') |
... | ... | @@ -89,7 +90,7 @@ class InsideView(LoginRequiredMixin, LogMixin, generic.DetailView): |
89 | 90 | context = super(InsideView, self).get_context_data(**kwargs) |
90 | 91 | |
91 | 92 | context['title'] = self.object.name |
92 | - | |
93 | + | |
93 | 94 | context['topic'] = self.object.topic |
94 | 95 | context['subject'] = self.object.topic.subject |
95 | 96 | |
... | ... | @@ -107,7 +108,7 @@ class InsideView(LoginRequiredMixin, LogMixin, generic.DetailView): |
107 | 108 | self.log_context['webpage_slug'] = self.object.slug |
108 | 109 | self.log_context['timestamp_start'] = str(int(time.time())) |
109 | 110 | |
110 | - super(InsideView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
111 | + super(InsideView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
111 | 112 | |
112 | 113 | self.request.session['log_id'] = Log.objects.latest('id').id |
113 | 114 | |
... | ... | @@ -136,7 +137,7 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
136 | 137 | |
137 | 138 | def get(self, request, *args, **kwargs): |
138 | 139 | self.object = None |
139 | - | |
140 | + | |
140 | 141 | form_class = self.get_form_class() |
141 | 142 | form = self.get_form(form_class) |
142 | 143 | |
... | ... | @@ -149,7 +150,7 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
149 | 150 | |
150 | 151 | def post(self, request, *args, **kwargs): |
151 | 152 | self.object = None |
152 | - | |
153 | + | |
153 | 154 | form_class = self.get_form_class() |
154 | 155 | form = self.get_form(form_class) |
155 | 156 | |
... | ... | @@ -157,7 +158,7 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
157 | 158 | topic = get_object_or_404(Topic, slug = slug) |
158 | 159 | |
159 | 160 | pendencies_form = PendenciesForm(self.request.POST, initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) |
160 | - | |
161 | + | |
161 | 162 | if (form.is_valid() and pendencies_form.is_valid()): |
162 | 163 | return self.form_valid(form, pendencies_form) |
163 | 164 | else: |
... | ... | @@ -170,7 +171,7 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
170 | 171 | |
171 | 172 | topic = get_object_or_404(Topic, slug = slug) |
172 | 173 | initial['subject'] = topic.subject |
173 | - | |
174 | + | |
174 | 175 | return initial |
175 | 176 | |
176 | 177 | def form_invalid(self, form, pendencies_form): |
... | ... | @@ -192,7 +193,7 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
192 | 193 | |
193 | 194 | pend_form = pendencies_form.save(commit = False) |
194 | 195 | pend_form.resource = self.object |
195 | - | |
196 | + | |
196 | 197 | if not pend_form.action == "": |
197 | 198 | pend_form.save() |
198 | 199 | |
... | ... | @@ -209,8 +210,8 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
209 | 210 | self.log_context['webpage_name'] = self.object.name |
210 | 211 | self.log_context['webpage_slug'] = self.object.slug |
211 | 212 | |
212 | - super(CreateView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
213 | - | |
213 | + super(CreateView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
214 | + | |
214 | 215 | return redirect(self.get_success_url()) |
215 | 216 | |
216 | 217 | def get_context_data(self, **kwargs): |
... | ... | @@ -264,7 +265,7 @@ class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): |
264 | 265 | |
265 | 266 | def get(self, request, *args, **kwargs): |
266 | 267 | self.object = self.get_object() |
267 | - | |
268 | + | |
268 | 269 | form_class = self.get_form_class() |
269 | 270 | form = self.get_form(form_class) |
270 | 271 | |
... | ... | @@ -282,7 +283,7 @@ class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): |
282 | 283 | |
283 | 284 | def post(self, request, *args, **kwargs): |
284 | 285 | self.object = self.get_object() |
285 | - | |
286 | + | |
286 | 287 | form_class = self.get_form_class() |
287 | 288 | form = self.get_form(form_class) |
288 | 289 | |
... | ... | @@ -295,12 +296,12 @@ class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): |
295 | 296 | pendencies_form = PendenciesForm(self.request.POST, instance = pend_form[0], initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) |
296 | 297 | else: |
297 | 298 | pendencies_form = PendenciesForm(self.request.POST, initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) |
298 | - | |
299 | + | |
299 | 300 | if (form.is_valid() and pendencies_form.is_valid()): |
300 | 301 | return self.form_valid(form, pendencies_form) |
301 | 302 | else: |
302 | 303 | return self.form_invalid(form, pendencies_form) |
303 | - | |
304 | + | |
304 | 305 | def form_invalid(self, form, pendencies_form): |
305 | 306 | return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) |
306 | 307 | |
... | ... | @@ -309,7 +310,7 @@ class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): |
309 | 310 | |
310 | 311 | if not self.object.topic.visible and not self.object.topic.repository: |
311 | 312 | self.object.visible = False |
312 | - | |
313 | + | |
313 | 314 | self.object.save() |
314 | 315 | |
315 | 316 | pend_form = pendencies_form.save(commit = False) |
... | ... | @@ -331,8 +332,8 @@ class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): |
331 | 332 | self.log_context['webpage_name'] = self.object.name |
332 | 333 | self.log_context['webpage_slug'] = self.object.slug |
333 | 334 | |
334 | - super(UpdateView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
335 | - | |
335 | + super(UpdateView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
336 | + | |
336 | 337 | return redirect(self.get_success_url()) |
337 | 338 | |
338 | 339 | def get_context_data(self, **kwargs): |
... | ... | @@ -400,6 +401,94 @@ class DeleteView(LoginRequiredMixin, LogMixin, generic.DeleteView): |
400 | 401 | self.log_context['webpage_name'] = self.object.name |
401 | 402 | self.log_context['webpage_slug'] = self.object.slug |
402 | 403 | |
403 | - super(DeleteView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
404 | - | |
405 | - return reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) | |
406 | 404 | \ No newline at end of file |
405 | + super(DeleteView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
406 | + | |
407 | + return reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) | |
408 | + | |
409 | + | |
410 | +def get_chart(request,slug): | |
411 | + webpage = get_object_or_404(Webpage, slug=slug) | |
412 | + alunos = webpage.students.all() | |
413 | + visualizou = Log.objects.filter(context__contains={'webpage_id':webpage.id},resource="webpage",action="view",user_email__in=(aluno.email for aluno in alunos)).distinct("user_email") | |
414 | + re = [] | |
415 | + c_visualizou = visualizou.count() | |
416 | + re.append(["Página Web","Fez","Não fez"]) | |
417 | + re.append(["Visualizar",c_visualizou, alunos.count() - c_visualizou]) | |
418 | + return JsonResponse({"dados":re}) | |
419 | + | |
420 | + | |
421 | +class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): | |
422 | + log_component = 'resources' | |
423 | + log_action = 'view_statistics' | |
424 | + log_resource = 'webpage' | |
425 | + log_context = {} | |
426 | + | |
427 | + login_url = reverse_lazy("users:login") | |
428 | + redirect_field_name = 'next' | |
429 | + model = Webpage | |
430 | + template_name = 'webpages/estatisticas.html' | |
431 | + | |
432 | + def dispatch(self, request, *args, **kwargs): | |
433 | + slug = self.kwargs.get('slug', '') | |
434 | + webpage = get_object_or_404(Webpage, slug = slug) | |
435 | + | |
436 | + if not has_subject_permissions(request.user, webpage.topic.subject): | |
437 | + return redirect(reverse_lazy('subjects:home')) | |
438 | + | |
439 | + return super(StatisticsView, self).dispatch(request, *args, **kwargs) | |
440 | + | |
441 | + def get_context_data(self, **kwargs): | |
442 | + context = super(StatisticsView, self).get_context_data(**kwargs) | |
443 | + | |
444 | + self.log_context['category_id'] = self.object.topic.subject.category.id | |
445 | + self.log_context['category_name'] = self.object.topic.subject.category.name | |
446 | + self.log_context['category_slug'] = self.object.topic.subject.category.slug | |
447 | + self.log_context['subject_id'] = self.object.topic.subject.id | |
448 | + self.log_context['subject_name'] = self.object.topic.subject.name | |
449 | + self.log_context['subject_slug'] = self.object.topic.subject.slug | |
450 | + self.log_context['topic_id'] = self.object.topic.id | |
451 | + self.log_context['topic_name'] = self.object.topic.name | |
452 | + self.log_context['topic_slug'] = self.object.topic.slug | |
453 | + self.log_context['webpage_id'] = self.object.id | |
454 | + self.log_context['webpage_name'] = self.object.name | |
455 | + self.log_context['webpage_slug'] = self.object.slug | |
456 | + | |
457 | + super(StatisticsView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
458 | + | |
459 | + | |
460 | + context['title'] = _('Webpage Statistics') | |
461 | + | |
462 | + slug = self.kwargs.get('slug') | |
463 | + webpage = get_object_or_404(Webpage, slug = slug) | |
464 | + | |
465 | + parameter = self.request.GET.get('col','') | |
466 | + | |
467 | + alunos = webpage.students.all() | |
468 | + visualizou = Log.objects.filter(context__contains={'webpage_id':webpage.id},resource="webpage",action="view",user_email__in=(aluno.email for aluno in alunos)).distinct("user_email") | |
469 | + re = [] | |
470 | + c_visualizou = visualizou.count() | |
471 | + did,n_did = str(_("Did")),str(_("Did not")) | |
472 | + re.append(['Webpage',did,n_did]) | |
473 | + re.append(['View',c_visualizou, alunos.count() - c_visualizou]) | |
474 | + context['topic'] = webpage.topic | |
475 | + context['subject'] = webpage.topic.subject | |
476 | + context['db_data'] = re | |
477 | + context['title_chart'] = _('Students viewing the web conference') | |
478 | + context['title_vAxis'] = _('Quantity') | |
479 | + data = [] | |
480 | + if not parameter == n_did: | |
481 | + for a in visualizou: | |
482 | + data.append([str(alunos.get(email=a.user_email)),a.user_email,a.action,a.datetime]) | |
483 | + | |
484 | + if not parameter == did: | |
485 | + alunos = alunos.exclude(email__in=(log.user_email for log in visualizou)) | |
486 | + for a in alunos: | |
487 | + data.append([str(a),a.email,None,None]) | |
488 | + | |
489 | + context["history"] = data | |
490 | + context["title_table"] = _("History") | |
491 | + if parameter == did: | |
492 | + context["title_table"] = did | |
493 | + elif parameter == n_did: | |
494 | + context["title_table"] = n_did | |
495 | + return context | ... | ... |