diff --git a/pdf_file/locale/pt_BR/LC_MESSAGES/django.po b/pdf_file/locale/pt_BR/LC_MESSAGES/django.po index b809829..591bd3d 100644 --- a/pdf_file/locale/pt_BR/LC_MESSAGES/django.po +++ b/pdf_file/locale/pt_BR/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-04-15 00:12-0300\n" +"POT-Creation-Date: 2017-04-28 20:39-0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -18,100 +18,139 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" -#: pdf_file/forms.py:25 +#: forms.py:25 msgid "Tags" -msgstr "" +msgstr "Tags" -#: pdf_file/forms.py:30 +#: forms.py:30 msgid "File name" msgstr "Nome do arquivo" -#: pdf_file/forms.py:51 +#: forms.py:51 msgid "This subject already has a pdf file with this name" msgstr "Este assunto já possui um arquivo PDF com este nome" -#: pdf_file/forms.py:63 +#: forms.py:63 msgid "The file is too large. It should have less than 10MB." msgstr "O arquivo é muito grande. Deve ser menor do que 10MB" -#: pdf_file/forms.py:68 +#: forms.py:68 msgid "This field is required." -msgstr "" +msgstr "Este campo é requerido." -#: pdf_file/models.py:16 +#: models.py:16 msgid "File not supported, use PDF format instead." msgstr "Este formato não é suportado, use PDF." -#: pdf_file/models.py:19 +#: models.py:19 msgid "File" -msgstr "" +msgstr "Arquivo" -#: pdf_file/models.py:42 +#: models.py:42 msgid "Are you sure you want delete the PDF File" msgstr "Tem certeza que deseja deletar este arquivo PDF?" -#: pdf_file/templates/pdf_file/_form.html:32 +#: templates/pdf_file/_form.html:32 msgid "Choose your file..." msgstr "" -#: pdf_file/templates/pdf_file/_form.html:46 +#: templates/pdf_file/_form.html:46 msgid "Click or drop the file here" msgstr "Clique ou arraste o arquivo aqui." -#: pdf_file/templates/pdf_file/_form.html:48 +#: templates/pdf_file/_form.html:48 msgid "The file could not exceed 10MB." msgstr "O arquivo não pode exceder 10MB." -#: pdf_file/templates/pdf_file/_form.html:68 +#: templates/pdf_file/_form.html:68 msgid "Common resources settings" -msgstr "" +msgstr "Configurações comuns à todos os recursos" -#: pdf_file/templates/pdf_file/_form.html:119 +#: templates/pdf_file/_form.html:119 msgid "Pendencies Notifications" -msgstr "" +msgstr "Notificações pendentes" -#: pdf_file/templates/pdf_file/_form.html:135 +#: templates/pdf_file/_form.html:135 msgid "Action not performed by the user" -msgstr "" +msgstr "Ação não permitida pelo usuário" -#: pdf_file/templates/pdf_file/_form.html:161 +#: templates/pdf_file/_form.html:161 msgid "Wished period" msgstr "" -#: pdf_file/templates/pdf_file/_form.html:257 +#: templates/pdf_file/_form.html:257 msgid "Attribute students to file link" msgstr "" -#: pdf_file/templates/pdf_file/_form.html:277 +#: templates/pdf_file/_form.html:277 msgid "Attribute groups to file link" msgstr "" -#: pdf_file/templates/pdf_file/_form.html:346 +#: templates/pdf_file/_form.html:346 msgid "Save" -msgstr "" +msgstr "Salvar" -#: pdf_file/templates/pdf_file/create.html:20 +#: templates/pdf_file/create.html:20 msgid "Create PDF file" msgstr "Criar arquivo PDF" -#: pdf_file/templates/pdf_file/update.html:20 +#: templates/pdf_file/relatorios.html:16 templates/pdf_file/relatorios.html:30 +#: templates/pdf_file/relatorios.html:37 +msgid "User" +msgstr "Usuário" + +#: templates/pdf_file/relatorios.html:16 templates/pdf_file/relatorios.html:30 +#: templates/pdf_file/relatorios.html:37 +msgid "Group" +msgstr "Grupo" + +#: templates/pdf_file/relatorios.html:16 templates/pdf_file/relatorios.html:30 +msgid "Action" +msgstr "Ação" + +#: templates/pdf_file/relatorios.html:16 templates/pdf_file/relatorios.html:30 +msgid "Date of Action" +msgstr "Data da ação" + +#: templates/pdf_file/relatorios.html:135 +#: templates/pdf_file/relatorios.html:155 +msgid "Reports" +msgstr "Relatórios" + +#: templates/pdf_file/relatorios.html:162 +msgid "Report of the resource " +msgstr "Relatórios do recurso " + +#: templates/pdf_file/relatorios.html:165 +msgid "Select the period: " +msgstr "Selecione o período: " + +#: templates/pdf_file/relatorios.html:178 +msgid "Search" +msgstr "Pesquisar" + +#: templates/pdf_file/relatorios.html:200 +msgid "Filter: " +msgstr "Filtro: " + +#: templates/pdf_file/update.html:20 msgid "Edit: " msgstr "Editar: " -#: pdf_file/templates/pdf_file/view.html:52 +#: templates/pdf_file/view.html:52 msgid "PDF could not be displayed" msgstr "PDF não pode ser mostrado" -#: pdf_file/views.py:110 pdf_file/views.py:123 pdf_file/views.py:234 -#: pdf_file/views.py:236 pdf_file/views.py:252 pdf_file/views.py:254 +#: views.py:112 views.py:125 views.py:236 views.py:238 views.py:254 +#: views.py:256 msgid "Visualize" -msgstr "" +msgstr "Visualizar" -#: pdf_file/views.py:183 +#: views.py:185 msgid "Create PDF File" msgstr "Criar o arquivo PDF" -#: pdf_file/views.py:194 +#: views.py:196 #, python-format msgid "" "The PDF File \"%s\" was added to the Topic \"%s\" of the virtual environment " @@ -120,18 +159,50 @@ msgstr "" "O arquivo PDF \"%s\" foi adicionado ao topico \"%s\" do ambiente virtual " "\"%s\" com sucesso!" -#: pdf_file/views.py:298 +#: views.py:300 msgid "Update PDF File" msgstr "Atualize arquivo PDF" -#: pdf_file/views.py:309 +#: views.py:311 #, python-format msgid "The PDF File \"%s\" was updated successfully!" msgstr "O arquivo PDF \"%s\" foi atualizado com sucesso!" -#: pdf_file/views.py:336 +#: views.py:338 #, python-format msgid "" "The PDF File \"%s\" was removed successfully from virtual environment \"%s\"!" msgstr "" "O arquivo PDF \"%s\" foi removido com sucesso do ambiente virtual \"%s\" " + +#: views.py:396 +msgid "PDF File Reports" +msgstr "Relatórios do arquivo de PDF" + +#: views.py:414 +msgid "Users who viewed" +msgstr "Usuário que visualizaram" + +#: views.py:414 +msgid "Users who did not viewed" +msgstr "Usuários que não visualizaram" + +#: views.py:414 +msgid "Historic" +msgstr "Histórico" + +#: views.py:446 +msgid "PDF File" +msgstr "Criar o arquivo PDF" + +#: views.py:447 +msgid "View" +msgstr "Visualizar" + +#: views.py:451 +msgid "Students viewing the PDF File" +msgstr "Estudantes que visualizaram o arquivo PDF" + +#: views.py:452 +msgid "Quantity" +msgstr "Quantidade" diff --git a/pdf_file/templates/pdf_file/relatorios.html b/pdf_file/templates/pdf_file/relatorios.html new file mode 100644 index 0000000..1332307 --- /dev/null +++ b/pdf_file/templates/pdf_file/relatorios.html @@ -0,0 +1,357 @@ +{% extends "pdf_file/view.html" %} + +{% load static i18n pagination permissions_tags subject_counter %} +{% load django_bootstrap_breadcrumbs %} + +{% block javascript%} + {{ block.super }} + + + + + +{% endblock%} + +{% block breadcrumbs %} + {{ block.super }} + {% trans 'Reports' as bread %} + {% breadcrumb bread pdf_file%} +{% endblock %} + +{% block content %} + {% if messages %} + {% for message in messages %} + + {% endfor %} + {% endif %} +
+
+
+
+

+ {{pdf_file}} / {% trans "Reports" %} +

+
+
+
+
+
+

{% trans "Report of the resource " %}{{pdf_file}}

+
+
+

{% trans "Select the period: " %}

+
+
+
+
+
+ +
+ +
+ {# #} + +
+ +
+
+
+
+
+
+
+
+
+ +
+
+
+ +
+ +
+
+
    + +
+
+
+
+
+

+
+
+ + +{% endblock %} diff --git a/pdf_file/templates/pdf_file/view.html b/pdf_file/templates/pdf_file/view.html index 7509ac4..4f3d48c 100644 --- a/pdf_file/templates/pdf_file/view.html +++ b/pdf_file/templates/pdf_file/view.html @@ -18,8 +18,8 @@ {% breadcrumb subject.category 'subjects:cat_view' subject.category.slug %} {% breadcrumb subject 'subjects:view' subject.slug %} {% breadcrumb pdf_file.topic 'subjects:topic_view' subject.slug pdf_file.topic.slug %} - {% breadcrumb pdf_file 'pdf_file:view' pdf_file.slug %} - + {% breadcrumb pdf_file 'pdf_files:view' pdf_file.slug %} + {% endblock %} @@ -52,6 +52,6 @@

{% trans "PDF could not be displayed" %}

- - -{% endblock content %} \ No newline at end of file + + +{% endblock content %} diff --git a/pdf_file/urls.py b/pdf_file/urls.py index ef6768a..068e071 100644 --- a/pdf_file/urls.py +++ b/pdf_file/urls.py @@ -8,5 +8,5 @@ urlpatterns = [ url(r'^update/(?P[\w_-]+)/(?P[\w_-]+)/$', views.UpdateView.as_view(), name = 'update'), url(r'^delete/(?P[\w_-]+)/$', views.DeleteView.as_view(), name = 'delete'), url(r'^view/(?P[\w_-]+)/$', views.ViewPDFFile.as_view(), name = 'view'), - -] \ No newline at end of file + url(r'^chart/(?P[\w_-]+)/$', views.StatisticsView.as_view(), name = 'get_chart'), +] diff --git a/pdf_file/views.py b/pdf_file/views.py index daa84f1..8f53eb6 100644 --- a/pdf_file/views.py +++ b/pdf_file/views.py @@ -10,6 +10,8 @@ from django.contrib import messages from amadeus.permissions import has_subject_permissions, has_resource_permissions from .forms import PDFFileForm from os import path +import datetime +from log.models import Log from django.http import HttpResponse, Http404 from log.mixins import LogMixin @@ -100,7 +102,7 @@ class PDFFileCreateView(LoginRequiredMixin, LogMixin , generic.CreateView): def get(self, request, *args, **kwargs): self.object = None - + form_class = self.get_form_class() form = self.get_form(form_class) @@ -113,7 +115,7 @@ class PDFFileCreateView(LoginRequiredMixin, LogMixin , generic.CreateView): def post(self, request, *args, **kwargs): self.object = None - + form_class = self.get_form_class() form = self.get_form(form_class) @@ -121,7 +123,7 @@ class PDFFileCreateView(LoginRequiredMixin, LogMixin , generic.CreateView): topic = get_object_or_404(Topic, slug = slug) pendencies_form = PendenciesForm(self.request.POST, initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) - + if (form.is_valid() and pendencies_form.is_valid()): return self.form_valid(form, pendencies_form) else: @@ -134,7 +136,7 @@ class PDFFileCreateView(LoginRequiredMixin, LogMixin , generic.CreateView): topic = get_object_or_404(Topic, slug = slug) initial['subject'] = topic.subject - + return initial def form_invalid(self, form, pendencies_form): @@ -156,10 +158,10 @@ class PDFFileCreateView(LoginRequiredMixin, LogMixin , generic.CreateView): pend_form = pendencies_form.save(commit = False) pend_form.resource = self.object - + if not pend_form.action == "": - pend_form.save() - + pend_form.save() + self.log_context['category_id'] = self.object.topic.subject.category.id self.log_context['category_name'] = self.object.topic.subject.category.name self.log_context['category_slug'] = self.object.topic.subject.category.slug @@ -221,7 +223,7 @@ class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): def get(self, request, *args, **kwargs): self.object = self.get_object() - + form_class = self.get_form_class() form = self.get_form(form_class) @@ -239,7 +241,7 @@ class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): def post(self, request, *args, **kwargs): self.object = self.get_object() - + form_class = self.get_form_class() form = self.get_form(form_class) @@ -252,12 +254,12 @@ class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): pendencies_form = PendenciesForm(self.request.POST, instance = pend_form[0], initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) else: pendencies_form = PendenciesForm(self.request.POST, initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) - + if (form.is_valid() and pendencies_form.is_valid()): return self.form_valid(form, pendencies_form) else: return self.form_invalid(form, pendencies_form) - + def form_invalid(self, form, pendencies_form): return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) @@ -266,7 +268,7 @@ class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): if not self.object.topic.visible and not self.object.topic.repository: self.object.visible = False - + self.object.save() pend_form = pendencies_form.save(commit = False) @@ -274,7 +276,7 @@ class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): if not pend_form.action == "": pend_form.save() - + self.log_context['category_id'] = self.object.topic.subject.category.id self.log_context['category_name'] = self.object.topic.subject.category.name self.log_context['category_slug'] = self.object.topic.subject.category.slug @@ -352,5 +354,104 @@ class DeleteView(LoginRequiredMixin, LogMixin, generic.DeleteView): return reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) +class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): + log_component = 'resources' + log_action = 'view_statistics' + log_resource = 'pdf_file' + log_context = {} + + login_url = reverse_lazy("users:login") + redirect_field_name = 'next' + model = PDFFile + template_name = 'pdf_file/relatorios.html' + + def dispatch(self, request, *args, **kwargs): + slug = self.kwargs.get('slug', '') + pdf_file = get_object_or_404(PDFFile, slug = slug) + if not has_subject_permissions(request.user, pdf_file.topic.subject): + return redirect(reverse_lazy('subjects:home')) + return super(StatisticsView, self).dispatch(request, *args, **kwargs) + + def get_context_data(self, **kwargs): + context = super(StatisticsView, self).get_context_data(**kwargs) + + self.log_context['category_id'] = self.object.topic.subject.category.id + self.log_context['category_name'] = self.object.topic.subject.category.name + self.log_context['category_slug'] = self.object.topic.subject.category.slug + self.log_context['subject_id'] = self.object.topic.subject.id + self.log_context['subject_name'] = self.object.topic.subject.name + self.log_context['subject_slug'] = self.object.topic.subject.slug + self.log_context['topic_id'] = self.object.topic.id + self.log_context['topic_name'] = self.object.topic.name + self.log_context['topic_slug'] = self.object.topic.slug + self.log_context['pdffile_id'] = self.object.id + self.log_context['pdffile_name'] = self.object.name + self.log_context['pdffile_slug'] = self.object.slug + + super(StatisticsView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) + + + context['title'] = _('PDF File Reports') + + slug = self.kwargs.get('slug') + pdf_file = get_object_or_404(PDFFile, slug = slug) + context['pdf_file'] = pdf_file + date_format = "%d/%m/%Y %H:%M" if self.request.GET.get('language','') == 'pt-br' else "%m/%d/%Y %I:%M %p" + if self.request.GET.get('language','') == "": + start_date = datetime.datetime.now() - datetime.timedelta(30) + end_date = datetime.datetime.now() + else : + start_date = datetime.datetime.strptime(self.request.GET.get('init_date',''),date_format) + end_date = datetime.datetime.strptime(self.request.GET.get('end_date',''),date_format) + # print (start_date," depois") + context["init_date"] = start_date + context["end_date"] = end_date + alunos = pdf_file.students.all() + + vis_ou = Log.objects.filter(context__contains={'pdffile_id':pdf_file.id},resource="pdffile",action="view",user_email__in=(aluno.email for aluno in alunos), datetime__range=(start_date,end_date + datetime.timedelta(minutes = 1))) + did,n_did,history = str(_("Users who viewed")),str(_("Users who did not viewed")),str(_("Historic")) + re = [] + data_did, data_n_did,data_history = [],[],[] + json_did, json_n_did, json_history = {},{},{} + + from django.db.models import Count, Max + views_user = vis_ou.values("user_email").annotate(views=Count("user_email")) + date_last = vis_ou.values("user_email").annotate(last=Max("datetime")) + + for i in range(0,len(views_user)): + data_did.append([str(alunos.get(email=views_user[i].get("user_email"))), + ", ".join([str(x) for x in pdf_file.topic.subject.group_subject.filter(participants__email=views_user[i].get("user_email"))]), + views_user[i].get("views"),date_last.get(user_email=views_user[i].get("user_email")).get("last")]) + json_did["data"] = data_did + + + for log_al in vis_ou.order_by("datetime"): + data_history.append([str(alunos.get(email=log_al.user_email)), + ", ".join([str(x) for x in pdf_file.topic.subject.group_subject.filter(participants__email=log_al.user_email)]), + log_al.action,log_al.datetime]) + json_history["data"] = data_history + + not_view = alunos.exclude(email__in=[log.user_email for log in vis_ou.distinct("user_email")]) + for alun in not_view: + data_n_did.append([str(alun),", ".join([str(x) for x in pdf_file.topic.subject.group_subject.filter(participants__email=alun.email)])]) + json_n_did["data"] = data_n_did + + + context["json_did"] = json_did + context["json_n_did"] = json_n_did + context["json_history"] = json_history + c_visualizou = vis_ou.distinct("user_email").count() + re.append([str(_('PDF File')),did,n_did]) + re.append([str(_('View')),c_visualizou, alunos.count() - c_visualizou]) + context['topic'] = pdf_file.topic + context['subject'] = pdf_file.topic.subject + context['db_data'] = re + context['title_chart'] = _('Students viewing the PDF File') + context['title_vAxis'] = _('Quantity') + + context["n_did_table"] = n_did + context["did_table"] = did + context["history_table"] = history + return context diff --git a/topics/templates/resources/list.html b/topics/templates/resources/list.html index 39c6d70..4615deb 100644 --- a/topics/templates/resources/list.html +++ b/topics/templates/resources/list.html @@ -33,6 +33,9 @@ {% if resource|class_name == 'webpage' %}
  • {% trans 'Reports' %}
  • {% endif %} + {% if resource|class_name == 'pdffile' %} +
  • {% trans 'Reports' %}
  • + {% endif %} {% if resource|class_name == 'goals' %}
  • {% trans 'Reports' %}
  • {% endif %} -- libgit2 0.21.2