From e174643594f2d692638deb55cab08316693b6be8 Mon Sep 17 00:00:00 2001 From: Jailson Dias Date: Thu, 4 May 2017 23:38:10 -0300 Subject: [PATCH 01/24] =?UTF-8?q?colocando=20op=C3=A7=C3=A3o=20de=20enviar?= =?UTF-8?q?=20foto=20junto=20com=20o=20comentario=20em=20relatorios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webpage/forms.py | 191 ++++---- webpage/templates/webpages/relatorios.html | 91 ++-- webpage/templates/webpages/send_message.html | 112 +++++ webpage/urls.py | 2 +- webpage/views.py | 455 ++++++++++--------- 5 files changed, 520 insertions(+), 331 deletions(-) create mode 100644 webpage/templates/webpages/send_message.html diff --git a/webpage/forms.py b/webpage/forms.py index 99c8fad7a..199d37914 100644 --- a/webpage/forms.py +++ b/webpage/forms.py @@ -7,91 +7,122 @@ from .models import Webpage +from resubmit.widgets import ResubmitFileWidget + class WebpageForm(forms.ModelForm): - subject = None - - def __init__(self, *args, **kwargs): - super(WebpageForm, self).__init__(*args, **kwargs) - - self.subject = kwargs['initial'].get('subject', None) - - if self.instance.id: - self.subject = self.instance.topic.subject - self.initial['tags'] = ", ".join(self.instance.tags.all().values_list("name", flat = True)) - - self.fields['students'].queryset = self.subject.students.all() - self.fields['groups'].queryset = self.subject.group_subject.all() - - tags = forms.CharField(label = _('Tags'), required = False) - - class Meta: - model = Webpage - fields = ['name', 'content', 'brief_description', 'all_students', 'students', 'groups', 'show_window', 'visible'] - labels = { - 'name': _('Webpage name'), - 'content': _('Webpage content'), - } - widgets = { - 'content': forms.Textarea, - 'brief_description': forms.Textarea, - 'students': forms.SelectMultiple, - 'groups': forms.SelectMultiple, - } - - def clean_name(self): - name = self.cleaned_data.get('name', '') - - topics = self.subject.topic_subject.all() - - for topic in topics: - if self.instance.id: - same_name = topic.resource_topic.filter(name__unaccent__iexact = name).exclude(id = self.instance.id).count() - else: - same_name = topic.resource_topic.filter(name__unaccent__iexact = name).count() - - if same_name > 0: - self._errors['name'] = [_('This subject already has a webpage with this name')] - - return ValueError - - return name - - def clean_content(self): - content = self.cleaned_data.get('content', '') - cleaned_content = strip_tags(content) - - if cleaned_content == '': - self._errors['content'] = [_('This field is required.')] - - return ValueError - - return content - - def save(self, commit = True): - super(WebpageForm, self).save(commit = True) - - self.instance.save() - - previous_tags = self.instance.tags.all() - - tags = self.cleaned_data['tags'].split(",") + subject = None + + def __init__(self, *args, **kwargs): + super(WebpageForm, self).__init__(*args, **kwargs) + + self.subject = kwargs['initial'].get('subject', None) + + if self.instance.id: + self.subject = self.instance.topic.subject + self.initial['tags'] = ", ".join(self.instance.tags.all().values_list("name", flat = True)) + + self.fields['students'].queryset = self.subject.students.all() + self.fields['groups'].queryset = self.subject.group_subject.all() + + tags = forms.CharField(label = _('Tags'), required = False) + + class Meta: + model = Webpage + fields = ['name', 'content', 'brief_description', 'all_students', 'students', 'groups', 'show_window', 'visible'] + labels = { + 'name': _('Webpage name'), + 'content': _('Webpage content'), + } + widgets = { + 'content': forms.Textarea, + 'brief_description': forms.Textarea, + 'students': forms.SelectMultiple, + 'groups': forms.SelectMultiple, + } + + def clean_name(self): + name = self.cleaned_data.get('name', '') + + topics = self.subject.topic_subject.all() + + for topic in topics: + if self.instance.id: + same_name = topic.resource_topic.filter(name__unaccent__iexact = name).exclude(id = self.instance.id).count() + else: + same_name = topic.resource_topic.filter(name__unaccent__iexact = name).count() + + if same_name > 0: + self._errors['name'] = [_('This subject already has a webpage with this name')] + + return ValueError + + return name + + def clean_content(self): + content = self.cleaned_data.get('content', '') + cleaned_content = strip_tags(content) + + if cleaned_content == '': + self._errors['content'] = [_('This field is required.')] + + return ValueError + + return content + + def save(self, commit = True): + super(WebpageForm, self).save(commit = True) + + self.instance.save() + + previous_tags = self.instance.tags.all() + + tags = self.cleaned_data['tags'].split(",") #Excluding unwanted tags - for prev in previous_tags: - if not prev.name in tags: - self.instance.tags.remove(prev) + for prev in previous_tags: + if not prev.name in tags: + self.instance.tags.remove(prev) - for tag in tags: - tag = tag.strip() + for tag in tags: + tag = tag.strip() + + exist = Tag.objects.filter(name = tag).exists() + + if exist: + new_tag = Tag.objects.get(name = tag) + else: + new_tag = Tag.objects.create(name = tag) + + if not new_tag in self.instance.tags.all(): + self.instance.tags.add(new_tag) + + return self.instance + +class FormModalMessage(forms.Form): + MAX_UPLOAD_SIZE = 5*1024*1024 + + comment = forms.CharField(widget=forms.Textarea) + image = forms.FileField(widget=ResubmitFileWidget(attrs={'accept':'image/*'})) + + def clean_comment(self): + comment = self.cleaned_data.get('comment', '') + cleaned_comment = strip_tags(comment) + + if cleaned_comment == '': + self._errors['comment'] = [_('This field is required.')] + + return ValueError + + return comment - exist = Tag.objects.filter(name = tag).exists() + def clean_image(self): + image = self.cleaned_data.get('image', False) - if exist: - new_tag = Tag.objects.get(name = tag) - else: - new_tag = Tag.objects.create(name = tag) + if image: + if hasattr(image, '_size'): + if image._size > self.MAX_UPLOAD_SIZE: + self._errors['image'] = [_("The image is too large. It should have less than 5MB.")] - if not new_tag in self.instance.tags.all(): - self.instance.tags.add(new_tag) + return ValueError - return self.instance \ No newline at end of file + return image \ No newline at end of file diff --git a/webpage/templates/webpages/relatorios.html b/webpage/templates/webpages/relatorios.html index a3444796f..dcfa8564a 100644 --- a/webpage/templates/webpages/relatorios.html +++ b/webpage/templates/webpages/relatorios.html @@ -9,9 +9,8 @@ {% endblock %} diff --git a/webpage/templates/webpages/send_message.html b/webpage/templates/webpages/send_message.html new file mode 100644 index 000000000..8c4854094 --- /dev/null +++ b/webpage/templates/webpages/send_message.html @@ -0,0 +1,112 @@ + + {% load widget_tweaks i18n %} + + + + \ No newline at end of file diff --git a/webpage/urls.py b/webpage/urls.py index 57aa88a0b..4b849911c 100644 --- a/webpage/urls.py +++ b/webpage/urls.py @@ -10,5 +10,5 @@ url(r'^window_view/(?P[\w_-]+)/$', views.NewWindowView.as_view(), name = 'window_view'), url(r'^view/(?P[\w_-]+)/$', views.InsideView.as_view(), name = 'view'), url(r'^chart/(?P[\w_-]+)/$', views.StatisticsView.as_view(), name = 'get_chart'), - url(r'^send-message/(?P[\w_-]+)/$', views.sendMessage, name = 'send_message'), + url(r'^send-message/(?P[\w_-]+)/$', views.SendMessage.as_view(), name = 'send_message'), ] diff --git a/webpage/views.py b/webpage/views.py index 33aa1eda5..1501bc231 100644 --- a/webpage/views.py +++ b/webpage/views.py @@ -20,100 +20,107 @@ from .forms import WebpageForm from .models import Webpage +from chat.models import Conversation, TalkMessages +from users.models import User +from subjects.models import Subject + +from .forms import FormModalMessage + class NewWindowView(LoginRequiredMixin, LogMixin, generic.DetailView): - log_component = 'resources' - log_action = 'view' - log_resource = 'webpage' - log_context = {} + log_component = 'resources' + log_action = 'view' + log_resource = 'webpage' + log_context = {} - login_url = reverse_lazy("users:login") - redirect_field_name = 'next' + login_url = reverse_lazy("users:login") + redirect_field_name = 'next' - template_name = 'webpages/window_view.html' - model = Webpage - context_object_name = 'webpage' + template_name = 'webpages/window_view.html' + model = Webpage + context_object_name = 'webpage' - def dispatch(self, request, *args, **kwargs): - slug = self.kwargs.get('slug', '') - webpage = get_object_or_404(Webpage, slug = slug) + def dispatch(self, request, *args, **kwargs): + slug = self.kwargs.get('slug', '') + webpage = get_object_or_404(Webpage, slug=slug) - if not has_resource_permissions(request.user, webpage): - return redirect(reverse_lazy('subjects:home')) + if not has_resource_permissions(request.user, webpage): + return redirect(reverse_lazy('subjects:home')) - return super(NewWindowView, self).dispatch(request, *args, **kwargs) + return super(NewWindowView, self).dispatch(request, *args, **kwargs) - def get_context_data(self, **kwargs): - context = super(NewWindowView, self).get_context_data(**kwargs) + def get_context_data(self, **kwargs): + context = super(NewWindowView, 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['webpage_id'] = self.object.id - self.log_context['webpage_name'] = self.object.name - self.log_context['webpage_slug'] = self.object.slug - self.log_context['timestamp_start'] = str(int(time.time())) + 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['webpage_id'] = self.object.id + self.log_context['webpage_name'] = self.object.name + self.log_context['webpage_slug'] = self.object.slug + self.log_context['timestamp_start'] = str(int(time.time())) - super(NewWindowView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) + super(NewWindowView, self).createLog(self.request.user, self.log_component, self.log_action, + self.log_resource, self.log_context) - self.request.session['log_id'] = Log.objects.latest('id').id + self.request.session['log_id'] = Log.objects.latest('id').id - return context + return context class InsideView(LoginRequiredMixin, LogMixin, generic.DetailView): - log_component = 'resources' - log_action = 'view' - log_resource = 'webpage' - log_context = {} + log_component = 'resources' + log_action = 'view' + log_resource = 'webpage' + log_context = {} - login_url = reverse_lazy("users:login") - redirect_field_name = 'next' + login_url = reverse_lazy("users:login") + redirect_field_name = 'next' - template_name = 'webpages/view.html' - model = Webpage - context_object_name = 'webpage' + template_name = 'webpages/view.html' + model = Webpage + context_object_name = 'webpage' - def dispatch(self, request, *args, **kwargs): - slug = self.kwargs.get('slug', '') - webpage = get_object_or_404(Webpage, slug = slug) + def dispatch(self, request, *args, **kwargs): + slug = self.kwargs.get('slug', '') + webpage = get_object_or_404(Webpage, slug=slug) - if not has_resource_permissions(request.user, webpage): - return redirect(reverse_lazy('subjects:home')) + if not has_resource_permissions(request.user, webpage): + return redirect(reverse_lazy('subjects:home')) - return super(InsideView, self).dispatch(request, *args, **kwargs) + return super(InsideView, self).dispatch(request, *args, **kwargs) - def get_context_data(self, **kwargs): - context = super(InsideView, self).get_context_data(**kwargs) + def get_context_data(self, **kwargs): + context = super(InsideView, self).get_context_data(**kwargs) - context['title'] = self.object.name + context['title'] = self.object.name - context['topic'] = self.object.topic - context['subject'] = self.object.topic.subject + context['topic'] = self.object.topic + context['subject'] = self.object.topic.subject - 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['webpage_id'] = self.object.id - self.log_context['webpage_name'] = self.object.name - self.log_context['webpage_slug'] = self.object.slug - self.log_context['timestamp_start'] = str(int(time.time())) + 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['webpage_id'] = self.object.id + self.log_context['webpage_name'] = self.object.name + self.log_context['webpage_slug'] = self.object.slug + self.log_context['timestamp_start'] = str(int(time.time())) - super(InsideView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) + super(InsideView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) - self.request.session['log_id'] = Log.objects.latest('id').id + self.request.session['log_id'] = Log.objects.latest('id').id - return context + return context class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): log_component = 'resources' @@ -128,55 +135,55 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): form_class = WebpageForm def dispatch(self, request, *args, **kwargs): - slug = self.kwargs.get('slug', '') - topic = get_object_or_404(Topic, slug = slug) - - if not has_subject_permissions(request.user, topic.subject): - return redirect(reverse_lazy('subjects:home')) + slug = self.kwargs.get('slug', '') + topic = get_object_or_404(Topic, slug = slug) + + if not has_subject_permissions(request.user, topic.subject): + return redirect(reverse_lazy('subjects:home')) - return super(CreateView, self).dispatch(request, *args, **kwargs) + return super(CreateView, self).dispatch(request, *args, **kwargs) def get(self, request, *args, **kwargs): - self.object = None + self.object = None - form_class = self.get_form_class() - form = self.get_form(form_class) + form_class = self.get_form_class() + form = self.get_form(form_class) - slug = self.kwargs.get('slug', '') - topic = get_object_or_404(Topic, slug = slug) + slug = self.kwargs.get('slug', '') + topic = get_object_or_404(Topic, slug = slug) - pendencies_form = PendenciesForm(initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) + pendencies_form = PendenciesForm(initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) - return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) + return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) def post(self, request, *args, **kwargs): - self.object = None + self.object = None - form_class = self.get_form_class() - form = self.get_form(form_class) + form_class = self.get_form_class() + form = self.get_form(form_class) - slug = self.kwargs.get('slug', '') - topic = get_object_or_404(Topic, slug = slug) + slug = self.kwargs.get('slug', '') + topic = get_object_or_404(Topic, slug = slug) - pendencies_form = PendenciesForm(self.request.POST, initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) + 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) + 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 get_initial(self): - initial = super(CreateView, self).get_initial() + initial = super(CreateView, self).get_initial() - slug = self.kwargs.get('slug', '') + slug = self.kwargs.get('slug', '') - topic = get_object_or_404(Topic, slug = slug) - initial['subject'] = topic.subject + topic = get_object_or_404(Topic, slug = slug) + initial['subject'] = topic.subject - return initial + return initial def form_invalid(self, form, pendencies_form): - return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) + return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) def form_valid(self, form, pendencies_form): self.object = form.save(commit = False) @@ -187,18 +194,18 @@ def form_valid(self, form, pendencies_form): self.object.order = topic.resource_topic.count() + 1 if not self.object.topic.visible and not self.object.topic.repository: - self.object.visible = False + self.object.visible = False - if form.cleaned_data["all_students"]: - self.object.students.add(*self.object.topic.subject.students.all()) + # if form.cleaned_data["all_students"]: + # self.object.students.add(*self.object.topic.subject.students.all()) self.object.save() 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 @@ -218,153 +225,153 @@ def form_valid(self, form, pendencies_form): return redirect(self.get_success_url()) def get_context_data(self, **kwargs): - context = super(CreateView, self).get_context_data(**kwargs) + context = super(CreateView, self).get_context_data(**kwargs) - context['title'] = _('Create Webpage') + context['title'] = _('Create Webpage') - slug = self.kwargs.get('slug', '') - topic = get_object_or_404(Topic, slug = slug) + slug = self.kwargs.get('slug', '') + topic = get_object_or_404(Topic, slug = slug) - context['topic'] = topic - context['subject'] = topic.subject + context['topic'] = topic + context['subject'] = topic.subject - return context + return context def get_success_url(self): - messages.success(self.request, _('The Webpage "%s" was added to the Topic "%s" of the virtual environment "%s" successfully!')%(self.object.name, self.object.topic.name, self.object.topic.subject.name)) + messages.success(self.request, _('The Webpage "%s" was added to the Topic "%s" of the virtual environment "%s" successfully!')%(self.object.name, self.object.topic.name, self.object.topic.subject.name)) - success_url = reverse_lazy('webpages:view', kwargs = {'slug': self.object.slug}) + success_url = reverse_lazy('webpages:view', kwargs = {'slug': self.object.slug}) - if self.object.show_window: - self.request.session['resources'] = {} - self.request.session['resources']['new_page'] = True - self.request.session['resources']['new_page_url'] = reverse('webpages:window_view', kwargs = {'slug': self.object.slug}) + if self.object.show_window: + self.request.session['resources'] = {} + self.request.session['resources']['new_page'] = True + self.request.session['resources']['new_page_url'] = reverse('webpages:window_view', kwargs = {'slug': self.object.slug}) - success_url = reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) + success_url = reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) - return success_url + return success_url class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): - log_component = 'resources' - log_action = 'update' - log_resource = 'webpage' - log_context = {} + log_component = 'resources' + log_action = 'update' + log_resource = 'webpage' + log_context = {} - login_url = reverse_lazy("users:login") - redirect_field_name = 'next' + login_url = reverse_lazy("users:login") + redirect_field_name = 'next' - template_name = 'webpages/update.html' - model = Webpage - form_class = WebpageForm + template_name = 'webpages/update.html' + model = Webpage + form_class = WebpageForm - def dispatch(self, request, *args, **kwargs): - slug = self.kwargs.get('topic_slug', '') - topic = get_object_or_404(Topic, slug = slug) + def dispatch(self, request, *args, **kwargs): + slug = self.kwargs.get('topic_slug', '') + topic = get_object_or_404(Topic, slug = slug) - if not has_subject_permissions(request.user, topic.subject): - return redirect(reverse_lazy('subjects:home')) + if not has_subject_permissions(request.user, topic.subject): + return redirect(reverse_lazy('subjects:home')) - return super(UpdateView, self).dispatch(request, *args, **kwargs) + return super(UpdateView, self).dispatch(request, *args, **kwargs) - def get(self, request, *args, **kwargs): - self.object = self.get_object() + def get(self, request, *args, **kwargs): + self.object = self.get_object() - form_class = self.get_form_class() - form = self.get_form(form_class) + form_class = self.get_form_class() + form = self.get_form(form_class) - slug = self.kwargs.get('topic_slug', '') - topic = get_object_or_404(Topic, slug = slug) + slug = self.kwargs.get('topic_slug', '') + topic = get_object_or_404(Topic, slug = slug) - pend_form = self.object.pendencies_resource.all() + pend_form = self.object.pendencies_resource.all() - if len(pend_form) > 0: - pendencies_form = PendenciesForm(instance = pend_form[0], initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) - else: - pendencies_form = PendenciesForm(initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) + if len(pend_form) > 0: + pendencies_form = PendenciesForm(instance = pend_form[0], initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) + else: + pendencies_form = PendenciesForm(initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) - return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) + return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) - def post(self, request, *args, **kwargs): - self.object = self.get_object() + def post(self, request, *args, **kwargs): + self.object = self.get_object() - form_class = self.get_form_class() - form = self.get_form(form_class) + form_class = self.get_form_class() + form = self.get_form(form_class) - slug = self.kwargs.get('topic_slug', '') - topic = get_object_or_404(Topic, slug = slug) + slug = self.kwargs.get('topic_slug', '') + topic = get_object_or_404(Topic, slug = slug) - pend_form = self.object.pendencies_resource.all() + pend_form = self.object.pendencies_resource.all() - if len(pend_form) > 0: - 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 len(pend_form) > 0: + 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) + 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)) + def form_invalid(self, form, pendencies_form): + return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) - def form_valid(self, form, pendencies_form): - self.object = form.save(commit = False) + def form_valid(self, form, pendencies_form): + self.object = form.save(commit = False) - if not self.object.topic.visible and not self.object.topic.repository: - self.object.visible = False + if not self.object.topic.visible and not self.object.topic.repository: + self.object.visible = False - self.object.save() + self.object.save() - pend_form = pendencies_form.save(commit = False) - pend_form.resource = self.object + pend_form = pendencies_form.save(commit = False) + pend_form.resource = self.object - if not pend_form.action == "": - pend_form.save() + 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 - 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['webpage_id'] = self.object.id - self.log_context['webpage_name'] = self.object.name - self.log_context['webpage_slug'] = self.object.slug + 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['webpage_id'] = self.object.id + self.log_context['webpage_name'] = self.object.name + self.log_context['webpage_slug'] = self.object.slug - super(UpdateView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) + super(UpdateView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) - return redirect(self.get_success_url()) + return redirect(self.get_success_url()) - def get_context_data(self, **kwargs): - context = super(UpdateView, self).get_context_data(**kwargs) + def get_context_data(self, **kwargs): + context = super(UpdateView, self).get_context_data(**kwargs) - context['title'] = _('Update Webpage') + context['title'] = _('Update Webpage') - slug = self.kwargs.get('topic_slug', '') - topic = get_object_or_404(Topic, slug = slug) + slug = self.kwargs.get('topic_slug', '') + topic = get_object_or_404(Topic, slug = slug) - context['topic'] = topic - context['subject'] = topic.subject + context['topic'] = topic + context['subject'] = topic.subject - return context + return context - def get_success_url(self): - messages.success(self.request, _('The Webpage "%s" was updated successfully!')%(self.object.name)) + def get_success_url(self): + messages.success(self.request, _('The Webpage "%s" was updated successfully!')%(self.object.name)) - success_url = reverse_lazy('webpages:view', kwargs = {'slug': self.object.slug}) + success_url = reverse_lazy('webpages:view', kwargs = {'slug': self.object.slug}) - if self.object.show_window: - self.request.session['resources'] = {} - self.request.session['resources']['new_page'] = True - self.request.session['resources']['new_page_url'] = reverse('webpages:window_view', kwargs = {'slug': self.object.slug}) + if self.object.show_window: + self.request.session['resources'] = {} + self.request.session['resources']['new_page'] = True + self.request.session['resources']['new_page_url'] = reverse('webpages:window_view', kwargs = {'slug': self.object.slug}) - success_url = reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) + success_url = reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) - return success_url + return success_url class DeleteView(LoginRequiredMixin, LogMixin, generic.DeleteView): log_component = 'resources' @@ -474,6 +481,8 @@ def get_context_data(self, **kwargs): context["init_date"] = start_date context["end_date"] = end_date alunos = webpage.students.all() + if webpage.all_students : + alunos = webpage.topic.subject.students.all() vis_ou = Log.objects.filter(context__contains={'webpage_id':webpage.id},resource="webpage",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(_("Realized")),str(_("Unrealized")),str(_("Historic")) @@ -516,9 +525,47 @@ def get_context_data(self, **kwargs): return context -from chat.models import Conversation, TalkMessages -from users.models import User -from subjects.models import Subject + +class SendMessage(LoginRequiredMixin, LogMixin, generic.edit.FormView): + log_component = 'resources' + log_action = 'send' + log_resource = 'webpage' + log_context = {} + + login_url = reverse_lazy("users:login") + redirect_field_name = 'next' + + template_name = 'webpages/send_message.html' + form_class = FormModalMessage + + def dispatch(self, request, *args, **kwargs): + slug = self.kwargs.get('slug', '') + webpage = get_object_or_404(Webpage, slug = slug) + self.webpage = webpage + + if not has_subject_permissions(request.user, webpage.topic.subject): + return redirect(reverse_lazy('subjects:home')) + + return super(SendMessage, self).dispatch(request, *args, **kwargs) + + def form_valid(self, form): + message = form.cleaned_data.get('comment') + image = form.cleaned_data.get("image") + users = (self.request.POST.get('users[]','')).split(",") + user = self.request.user + subject = self.webpage.topic.subject + for u in users: + to_user = User.objects.get(email=u) + talk, create = Conversation.objects.get_or_create(user_one=user,user_two=to_user) + created = TalkMessages.objects.create(text=message,talk=talk,user=user,subject=subject,image=image) + return JsonResponse({"message":"ok"}) + + def get_context_data(self, **kwargs): + context = super(SendMessage,self).get_context_data() + context["webpage"] = get_object_or_404(Webpage, slug=self.kwargs.get('slug', '')) + return context + + def sendMessage(request, slug): message = request.GET.get('message','') users = request.GET.getlist('users[]','') From de10b96f4dcfabc3b676033f474ffe7e4853b8c5 Mon Sep 17 00:00:00 2001 From: Felipe Bormann Date: Fri, 5 May 2017 16:33:39 -0300 Subject: [PATCH 02/24] improved styling as well as displaying most active users as well as most accessed subjects --- .../general.sassc | Bin 19769 -> 24706 bytes analytics/static/analytics/general.css | 21 +++++- analytics/static/analytics/general.css.map | 2 +- analytics/static/analytics/general.sass | 26 +++++++- analytics/static/analytics/js/behavior.js | 40 +++++++++-- analytics/static/analytics/js/charts.js | 63 ++++++++++++------ analytics/templates/analytics/general.html | 5 +- analytics/tests/test_general_dashboard.py | 2 +- analytics/urls.py | 3 + analytics/views.py | 31 +++++++-- 10 files changed, 152 insertions(+), 41 deletions(-) diff --git a/analytics/static/.sass-cache/9bdb779ec82a4a96f72be09b83b7c997addd0129/general.sassc b/analytics/static/.sass-cache/9bdb779ec82a4a96f72be09b83b7c997addd0129/general.sassc index d0f82f7a9a2e7867b0faf0230e1dcdd8d4e46fd7..bc6da56d5caed1cd414f6ad4031dad9afaec0726 100644 GIT binary patch delta 3053 zcmbVOOK%%h6pjNp$t1CHocIy9v5A$J+k}Z7$H`pB84@+r5Cl>qRS;FqWM*tn7<(*x zN>#Cl;1?9`4%l>62??R9QY#iLx?sg7NbHc1_yu&uf)(dnJM)T*s#vn@@0)YacOG}{ zxj%j5`|`Q(L3}}y@*7Gnzj3^oFRZTfyduf@&D_RD;W#U)t9f~im-FkZ*{{S!-^63> zouaQof6K%Mhd1dj#b4>4L!=e@ z$sGF2vlA-~O;L1pnVuG|O@(?uu1jsxPeu+%M61xpE4gTxT;)lUM@;6$5c|bv4`bnc zg(NgTxnhv%A;u>(um+o?7$$4l0P!FCZNV|{tjW4c&qykMbA$|+XU{1nSVoN_ra5kD z9`!Vj*fY>fAAu%kX(9@FHR;po8)=C|4H6q6@m_QiSWa8(5T$4+{C2n>59K;UKH##C zSvnC-VsQn;QH+c19XMbGpq+JWrD1f;Wl5IRPDfRib**DU1?Cgci+r!{GS+~;pXbKq zUiLDm$XM~T3{lw?M-;cB>Q;Q5^5W*r+a#pHJ_|{G^$`3wKS@9Wi1!!ltaJKDH0AJLrT;E2GXFJ? z{~B0EEdMn+9?k{5+=t;r5;?m@h$bEWYjk%zQyd_;i8c=hhyY(wp7rz4pgqDGRQCwi z!9~mxuCv6v943aGEsQAQ5Uzh6Ez$?2SX%SA*TB&34WbBpMf&m3pB?0F8AQ(hXa>m# z$uOQZL9;D2JDRB(O}6{S46;5(3Wp=~i`httyQe8;ojt%>Y>^V#=DP(r@kDrnF*JOU0zBrjohtP>KFM= zfNi0w(Qdr*MiE`|8NdLRB#ld4g{VtdbU)<>X z>_|l3e&rB3kCYQ?Oo~38&5v*2h{LtaB*KvLXb=P{Gz6i|F54KbEEHj^OcwV*! z*xIiNq8WA^^yA?;s331oOhnF+&~S`M-90g7*TkIhOiayG8$#Xqj2^v}JRLF!Ka5ug z&-g?mwlN}b?7+Ke2#H%#ry~frR9%%#qb&#@b=13xF)B=oo%>BwlHoE^G4Hoj=!*`f z=#&E)wT*s+5m9Q_cp)HmdJb@48titGv~DL%3VHSn=d%G>+w&O_Si5gTY(8(}e13%U z`3HMG=On2hIp%ZA(~uUpvm1h_JD)u~&gUD**&79svl%T%GYr-Y9#1n!7wXv3B~vZW z4&EMmvh(iT8{tiUj!VI(u4=WqDWvdv`T72{8IDVF=a)!!Z)8@zTOLPWloM0%{KD;r zqrr0Yw0jp}E7_;s M#c~~Y^mXsxKcJ`hxBvhE delta 156 zcmZoV$hdPB;{-`{Lt|r8qr|k-RAV4CFfg$&PPQ;GPBBb2HA*ruvNT9GG_kNWNt)=O z!N|Wc)6r(~0dMum7j5=W&QaBzyxmrbQEalHu>NFDJ0T#;kV|~CvE4TgaceaLYd!~V zD?W#k)ZBuc#FA7`C8iIon^huJSw$=iRJjy@AR{$1J)^`*!Nj1TVscE}c6K&v&Jb(2 F5C9osEa?CM diff --git a/analytics/static/analytics/general.css b/analytics/static/analytics/general.css index 3214902aa..4b4e334f2 100644 --- a/analytics/static/analytics/general.css +++ b/analytics/static/analytics/general.css @@ -63,8 +63,8 @@ color: #009688; } .selector { - width: 80%; - height: 40px; + width: 90%; + height: 20%; color: white; padding-left: 5px; background-color: #009688; @@ -74,4 +74,21 @@ padding-top: 10px; font-size: 16px; } +.middle-chart article { + text-align: center; } + +.most-accessed-list { + background-color: #52b7bd; + width: 80%; + margin-left: 2%; + margin-top: 2%; + padding-left: 0; + color: white; + transition: width 2s, height 2s, background-color 2s, transform 2s; } + .most-accessed-list li { + padding-left: 1%; } + +.most-accessed-item:hover { + background-color: #3aa7ad; } + /*# sourceMappingURL=general.css.map */ diff --git a/analytics/static/analytics/general.css.map b/analytics/static/analytics/general.css.map index 9048f9fcc..a7362a523 100644 --- a/analytics/static/analytics/general.css.map +++ b/analytics/static/analytics/general.css.map @@ -1,6 +1,6 @@ { "version": 3, -"mappings": "AAEA,YAAY;EACR,MAAM,EAAE,iBAAiB;EACzB,aAAa,EAAE,IAAI;EACnB,OAAO,EAAE,IAAI;EACb,QAAQ,EAAE,IAAI;EACd,KAAK,EAAE,IAAI;;AAEf,sBAAsB;EAClB,MAAM,EAAE,GAAG;EACX,OAAO,EAAE,KAAK;EACd,yBAAE;IACE,KAAK,EAbC,OAAO;EAejB,yBAAE;IACE,KAAK,EAAE,KAAK;IACZ,OAAO,EAAE,WAAW;IACpB,KAAK,EAAE,GAAG;IACV,MAAM,EAAE,GAAG;IAEX,4BAAE;MACE,YAAY,EAAE,EAAE;MAChB,KAAK,EAAE,GAAG;MACV,KAAK,EAAE,KAAK;MAEZ,yCAAY;QACR,gBAAgB,EAAE,OAAO;QACzB,KAAK,EAAE,IAAI;QACX,UAAU,EAAE,MAAM;QAClB,aAAa,EAAE,IAAI;MAEvB,gCAAG;QACC,gBAAgB,EAAE,OAAO;QACzB,KAAK,EAAE,IAAI;QACX,UAAU,EAAE,MAAM;QAClB,aAAa,EAAE,IAAI;;AAInC,sBAAsB;EAClB,UAAU,EAAE,2CAA2C;EACvD,MAAM,EAAE,IAAI;EACZ,aAAa,EAAE,IAAI;EACnB,KAAK,EAAE,OAAO;EACd,WAAW,EAAE,GAAG;EAChB,UAAU,EAAE,IAAI;EAEhB,yBAAE;IACE,WAAW,EAAE,EAAE;;AAEvB,eAAe;EACX,KAAK,EAAE,IAAI;EACX,MAAM,EAAE,IAAI;;AAEhB,UAAU;EACN,aAAa,EAAE,IAAI;EACnB,KAAK,EAAE,OAAO;EACd,KAAK,EAAE,IAAI;;AAIf,SAAS;EACL,KAAK,EAAE,OAAO;EACd,SAAS,EAAE,IAAI;;AAGnB,mBAAmB;EACf,UAAU,EAAE,iCAAmC;;AAEnD,MAAM;EACF,KAAK,EAAE,GAAG;EACV,KAAK,EAAE,IAAI;EACX,SAAE;IACE,KAAK,EA1EC,OAAO;;AA4ErB,SAAS;EACL,KAAK,EAAE,GAAG;EACV,MAAM,EAAE,IAAI;EACZ,KAAK,EAAE,KAAK;EACZ,YAAY,EAAE,GAAG;EACjB,gBAAgB,EAAE,OAAO;EACzB,UAAU,EAAE,IAAI;EAChB,aAAa,EAAE,iBAAiB;EAChC,WAAC;IACG,WAAW,EAAE,IAAI;IACjB,SAAS,EAAE,IAAI", +"mappings": "AAEA,YAAY;EACR,MAAM,EAAE,iBAAiB;EACzB,aAAa,EAAE,IAAI;EACnB,OAAO,EAAE,IAAI;EACb,QAAQ,EAAE,IAAI;EACd,KAAK,EAAE,IAAI;;AAEf,sBAAsB;EAClB,MAAM,EAAE,GAAG;EACX,OAAO,EAAE,KAAK;EACd,yBAAE;IACE,KAAK,EAbC,OAAO;EAejB,yBAAE;IACE,KAAK,EAAE,KAAK;IACZ,OAAO,EAAE,WAAW;IACpB,KAAK,EAAE,GAAG;IACV,MAAM,EAAE,GAAG;IAEX,4BAAE;MACE,YAAY,EAAE,EAAE;MAChB,KAAK,EAAE,GAAG;MACV,KAAK,EAAE,KAAK;MAEZ,yCAAY;QACR,gBAAgB,EAAE,OAAO;QACzB,KAAK,EAAE,IAAI;QACX,UAAU,EAAE,MAAM;QAClB,aAAa,EAAE,IAAI;MAEvB,gCAAG;QACC,gBAAgB,EAAE,OAAO;QACzB,KAAK,EAAE,IAAI;QACX,UAAU,EAAE,MAAM;QAClB,aAAa,EAAE,IAAI;;AAInC,sBAAsB;EAClB,UAAU,EAAE,2CAA2C;EACvD,MAAM,EAAE,IAAI;EACZ,aAAa,EAAE,IAAI;EACnB,KAAK,EAAE,OAAO;EACd,WAAW,EAAE,GAAG;EAChB,UAAU,EAAE,IAAI;EAEhB,yBAAE;IACE,WAAW,EAAE,EAAE;;AAEvB,eAAe;EACX,KAAK,EAAE,IAAI;EACX,MAAM,EAAE,IAAI;;AAEhB,UAAU;EACN,aAAa,EAAE,IAAI;EACnB,KAAK,EAAE,OAAO;EACd,KAAK,EAAE,IAAI;;AAIf,SAAS;EACL,KAAK,EAAE,OAAO;EACd,SAAS,EAAE,IAAI;;AAGnB,mBAAmB;EACf,UAAU,EAAE,iCAAmC;;AAEnD,MAAM;EACF,KAAK,EAAE,GAAG;EACV,KAAK,EAAE,IAAI;EACX,SAAE;IACE,KAAK,EA1EC,OAAO;;AA4ErB,SAAS;EACL,KAAK,EAAE,GAAG;EACV,MAAM,EAAE,GAAG;EACX,KAAK,EAAE,KAAK;EACZ,YAAY,EAAE,GAAG;EACjB,gBAAgB,EAAE,OAAO;EACzB,UAAU,EAAE,IAAI;EAChB,aAAa,EAAE,iBAAiB;EAChC,WAAC;IACG,WAAW,EAAE,IAAI;IACjB,SAAS,EAAE,IAAI;;AAInB,qBAAO;EACH,UAAU,EAAE,MAAM;;AAE1B,mBAAmB;EACf,gBAAgB,EAAE,OAAO;EACzB,KAAK,EAAE,GAAG;EACV,WAAW,EAAE,EAAE;EACf,UAAU,EAAE,EAAE;EACd,YAAY,EAAE,CAAC;EACf,KAAK,EAAE,KAAK;EACZ,UAAU,EAAE,sDAAsD;EAElE,sBAAE;IACE,YAAY,EAAE,EAAE;;AAExB,yBAAyB;EACrB,gBAAgB,EAAE,OAAO", "sources": ["general.sass"], "names": [], "file": "general.css" diff --git a/analytics/static/analytics/general.sass b/analytics/static/analytics/general.sass index a99e8accc..92f6e9441 100644 --- a/analytics/static/analytics/general.sass +++ b/analytics/static/analytics/general.sass @@ -75,8 +75,8 @@ $title-color: #009688 color: $title-color .selector - width: 80% - height: 40px + width: 90% + height: 20% color: white padding-left: 5px background-color: #009688 @@ -84,4 +84,24 @@ $title-color: #009688 border-radius: 0px 20px 20px 0px p padding-top: 10px - font-size: 16px \ No newline at end of file + font-size: 16px + + +.middle-chart + article + text-align: center + +.most-accessed-list + background-color: #52b7bd + width: 80% + margin-left: 2% + margin-top: 2% + padding-left: 0 + color: white + transition: width 2s, height 2s, background-color 2s, transform 2s + + li + padding-left: 1% + +.most-accessed-item:hover + background-color: #3aa7ad \ No newline at end of file diff --git a/analytics/static/analytics/js/behavior.js b/analytics/static/analytics/js/behavior.js index 410367cd8..627747338 100644 --- a/analytics/static/analytics/js/behavior.js +++ b/analytics/static/analytics/js/behavior.js @@ -13,8 +13,23 @@ var selectors_options = { }, loadData: function(e){ if (e){ - if (e.attributes['data-url'].value == "subjects"){ - var url = "/analytics/most_accessed_subjects"; + opened = $(e).attr('opened'); + if (typeof opened !== typeof undefined && opened !== false){ + selectors_options.deleteChildren(e); + }else { + switch(e.attributes['data-url'].value){ + case "subjects": + var url = "/analytics/most_accessed_subjects"; + break; + case "categories": + var url = "/analytics/most_accessed_categories"; + break; + case "resources": + var url = "/analytics/most_accessed_resources"; + break; + + } + } } if(url){ @@ -32,16 +47,29 @@ var selectors_options = { }, modifyElement: function(e, data){ var string_build = ""; - string_build += "
    "; + string_build += '"; - $(e).append(string_build); - - e.attributes.open = True; + $(e).after(string_build); + var new_elem = $(e).next(); + new_elem.slideDown(); + $(e).attr("opened", true); + + }, + deleteChildren: function(e){ + console.log("delete children"); + var most_accessed_list = $(e).next(); + $(most_accessed_list).animate( + {height: 0, + opacity: 0.1 + }, 1000, function(){ + $(this).remove(); //remove list from UI + }); + $(e).removeAttr("opened"); //remove attribute so it can call API again }, }; diff --git a/analytics/static/analytics/js/charts.js b/analytics/static/analytics/js/charts.js index b9fb9b6a3..4471b5fef 100644 --- a/analytics/static/analytics/js/charts.js +++ b/analytics/static/analytics/js/charts.js @@ -91,7 +91,7 @@ var charts = { build_bubble_user: function(url){ $.get(url, function(dataset){ - var width = 600; + var width = 300; var height = 300; @@ -121,7 +121,7 @@ var charts = { var color = d3.scaleOrdinal(d3.schemeCategory20); //adding new div to carousel-inner div - var new_div = d3.select(".carousel-inner").append("div").attr("class","item"); + var new_div = d3.select(".middle-chart").append("div").attr("class","item"); var radiusScale = d3.scaleSqrt().domain([min(), max()]).range([10,50]); var svg = new_div.append("svg").attr("width", width).attr("height", height) .style("margin","auto") @@ -131,17 +131,7 @@ var charts = { .attr("width", width) .attr("height", height); - //adding svg title - - svg.append("text") - .attr("text-anchor", "middle") - .attr("x", width/2 ) - .attr("y", 30) - .style("font-size", "30px") - .text("Usuários mais ativos no Amadeus") - .attr("fill", "#003333") - .style("font-weight", "bold") - .style("font-style", "italic"); + var simulation = d3.forceSimulation() .force("x", d3.forceX(width/2).strength(0.05)) @@ -158,6 +148,29 @@ var charts = { .append("g") .attr("class",".user-dot"); + + var defs = groups.append('svg:defs'); + + var gradient = defs.append("linearGradient") + .attr("id", "svgGradient") + .attr("x1", "0%") + .attr("x2", "100%") + .attr("y1", "0%") + .attr("y2", "100%"); + + gradient.append("stop") + .attr('class', 'start') + .attr("offset", "0%") + .attr("stop-color", "#007991") + .attr("stop-opacity", 1); + + gradient.append("stop") + .attr('class', 'end') + .attr("offset", "100%") + .attr("stop-color", "#78ffd6") + .attr("stop-opacity", 1); + + //Create circles to be drawn var circles = groups .append('circle') @@ -167,7 +180,9 @@ var charts = { .attr("fill", function(d){ return 'url('+'#'+'user_'+d['user_id']+')'; - }); + }) + .attr("stroke", "url(#svgGradient)") //using id setted by the svg + .attr("stroke-width", 3); @@ -175,7 +190,7 @@ var charts = { groups.append("text") .text(function(d){ return d['user'] +'('+ d['count'] + ')'; - }).attr("fill", "#FFFFFF") + }).attr("fill", "#000000") .attr("id", function(d){ return "user_tooltip_"+d['user_id']; }).style("display", "none"); @@ -190,7 +205,6 @@ var charts = { $("#"+"user_tooltip_"+d['user_id']).hide(); }); - var defs = groups.append('svg:defs'); //Attching images to bubbles defs.append("svg:pattern") @@ -217,11 +231,13 @@ var charts = { .attr("y", 0); + //simulation simulation.nodes(dataset) .on('tick', ticked); //so all data points are attached to it + console.log("finished simulation"); function ticked(){ groups.attr("transform", function(d){ return "translate(" + d.x + "," + d.y + ")"; @@ -234,10 +250,10 @@ var charts = { most_accessed_subjects: function(url){ $.get(url, function(dataset){ - var width = 800; + var width = 200; var height = 300; - var new_div = d3.select(".carousel-inner").append("div").attr("class","item"); + var new_div = d3.select(".carousel-inner").append("div").attr("test","ok"); var svg = new_div.append("svg").attr("width", "100%").attr("height", height) .style("margin","auto") @@ -417,7 +433,10 @@ var charts = { } } -charts.most_used_tags('/analytics/most_used_tags'); -//charts.build_resource('/topics/count_resources/'); -//charts.build_bubble_user('/users/get_users_log/'); -//charts.most_accessed_subjects('/subjects/most_accessed_subjects'); \ No newline at end of file + +$(document).ready(function(){ + charts.most_used_tags('/analytics/most_used_tags'); + //charts.build_resource('/topics/count_resources/'); + charts.build_bubble_user('/analytics/most_active_users/'); + //charts.most_accessed_subjects('/subjects/most_accessed_subjects'); +}); diff --git a/analytics/templates/analytics/general.html b/analytics/templates/analytics/general.html index 4eac9f1fc..fe81a9ab6 100644 --- a/analytics/templates/analytics/general.html +++ b/analytics/templates/analytics/general.html @@ -72,7 +72,7 @@

    -
    +

    {% trans "most accessed categories" %}

    @@ -80,7 +80,7 @@

    {% trans "most accessed subjects" %}

    -
    +

    {% trans "most accessed resource" %}

    @@ -91,6 +91,7 @@

    {% trans "most active users" %}

    +

    diff --git a/analytics/tests/test_general_dashboard.py b/analytics/tests/test_general_dashboard.py index 75618826d..9c82ae49a 100644 --- a/analytics/tests/test_general_dashboard.py +++ b/analytics/tests/test_general_dashboard.py @@ -88,7 +88,7 @@ def test_most_accessed_subjects(self): def test_most_accessed_categories(self): - self.fail("finish the test") + self.fail("finish test on categories") def test_most_active_users(self): self.fail("finish the test") diff --git a/analytics/urls.py b/analytics/urls.py index 89cf2e5b6..24cadc065 100644 --- a/analytics/urls.py +++ b/analytics/urls.py @@ -8,4 +8,7 @@ #"api" callls url(r'^most_used_tags/$', views.most_used_tags, name="most_used_tags"), url(r'^most_accessed_subjects/$', views.most_accessed_subjects, name="most_accessed_subjects"), + url(r'^most_accessed_categories/$', views.most_accessed_categories, name = "most_accessed_categories"), + url(r'^most_accessed_resources/$', views.most_accessed_resource_kind, name= "most_accessed_resources"), + url(r'^most_active_users/$', views.most_active_users, name= "most_active_users"), ] \ No newline at end of file diff --git a/analytics/views.py b/analytics/views.py index 4228a0476..d06aa56ee 100644 --- a/analytics/views.py +++ b/analytics/views.py @@ -79,15 +79,38 @@ def most_accessed_subjects(request): def most_accessed_categories(request): data = {} - data = Log.objects.filter('category') + data = Log.objects.filter(resource = 'category') categories = {} for datum in data: if datum.context: - pass - return None + category_id = datum.context['category_id'] + if category_id in categories.keys(): + categories[category_id]['count'] = categories[category_id]['count'] + 1 + else: + categories[category_id] = {'name': datum.context['category_name'], 'count': 1 } + + categories = sorted(categories.values(), key = lambda x: x['count'], reverse = True) + categories = categories[:5] + return JsonResponse(categories, safe= False) def most_accessed_resource_kind(request): - return None + resources_names = [cls.__name__ for cls in Resource.__subclasses__()] + print(resources_names) + resources = {} + + mapping = {} + mapping['pdffile'] = str(_('PDF File')) + mapping['goals'] = str(_('Topic Goals')) + mapping['link'] = str(_('Link to Website')) + mapping['filelink'] = str(_('File Link')) + mapping['webconference'] = str(_('Web Conference')) + mapping['ytvideo'] = str(_('YouTube Video')) + mapping['webpage'] = str(_('WebPage')) + + + + + return JsonResponse(resources, safe = False) def most_active_users(request): From bcf2559ab547e76f983c70377377a26cacfabb4a Mon Sep 17 00:00:00 2001 From: Felipe Bormann Date: Fri, 5 May 2017 17:18:24 -0300 Subject: [PATCH 03/24] finished user charts --- .../general.sassc | Bin 24706 -> 26226 bytes analytics/static/analytics/general.css | 6 +++++ analytics/static/analytics/general.css.map | 2 +- analytics/static/analytics/general.sass | 6 +++++ analytics/static/analytics/js/charts.js | 24 +++++++++++++++--- 5 files changed, 33 insertions(+), 5 deletions(-) diff --git a/analytics/static/.sass-cache/9bdb779ec82a4a96f72be09b83b7c997addd0129/general.sassc b/analytics/static/.sass-cache/9bdb779ec82a4a96f72be09b83b7c997addd0129/general.sassc index bc6da56d5caed1cd414f6ad4031dad9afaec0726..3138c27c34f57e83cd9fd4b34c75def7367a9a10 100644 GIT binary patch delta 1716 zcmZuyO>Yxd6xBpkp#B*4S1id(i{<_5JSV=;Hftf_ z2No*3$Sf2bL#o|zB0fT?u_znt-*y}rbWXa*+nyfDC+D*5M?DP5U7qC~VV7K#lE z%Q4u~VwPfj#KDxfR>FgpEOyDti!b`3xUUMFgncy%e{>O#RwwY6I>$v278g*i3uHyT zI`s^cg;|`fX7I5t`D1p5O*~$c`Ax#kVjtJyXfy;aid&5cem)xK0%%raUmRUF?%~(Q z3@_RQTT~cLC(@M{r^$;OLM*IISHeo7B9h{_lr&j~Dt@x=;BBqVX?Sr`hFb6iHES=T zX=G2svk8&c2|ngW-yiu|J`1Sgq1ckm&W!fSOtv8_aP zW#UUEc6j{Tgfnb&ZsS==7Cjj8kSHsOjcY!~msmWLV;etaGx({VPV_xF`ouG8$Mtbg zmw7K{DJ;U9b-Jw@MKO83y~#L+omYW@F2K8MpornplEwb(<} zk#4roxx#jaL44xa|0agl=hI|wj+?=&ZzI%;IXDCPb8A*)(k_-prkO~Iclwgi}r z#XIlAz?)Vae_j!S?29myoRTe!M@vsKVcNBMygj%fZJx1rqlAWW& zZ6#D0_I8YZd)TYZjs5mAb@lkT`$LhvK8xRPgoTVRNq!x@ubV5$ySKGr4|lIm2aI;N Rs|~hRl4Rz-RBtYG{{fB%#V-H= delta 1158 zcmZuwOHUI~7|j?1vCS~HQ~LymKr9MI+D-=shrkdb38j<@rKP-*QfND*&7ccc#t?sj zdKM;Xd?Y5aFeXS$+`4eb!XMy5{{g{2;JpLPTt*i&x!<|xoO|x$J3izdf8(A+u2(9G zx+yE_#)vYU97-fMD^+DgR@LE+RAnovRMUy7GL%fIPbc~~|GrV1#^hW9p-dVxiU*6C z6x#D9zRv`NPOa0_qU~DH*wkW1FMQ&lNJnlw=?URZ*3U<^F5Ra|x=0o9-Ob=@wg>Ok z1U$2TE&$3)&)&d(zXWMMjt{c|Z^&MwhQWd?)QCTe-7Cb&F7@L7BaQ) zB`tEAu}+jh+pP{>lm$07C&u8N^Ya15t&WNDe*9VJk{T|@25}7AjtwiH8zcFME@pTf zo|VHniN>?gDBfnnlHsy92+?QD41CJTf*U)^#fXlzrgyYikb0l{OFHME!S2jWwGBYvD=i_Veg7oY}>S~3>~`H$}v@7$|{Cd>zs+#tIOn1L*HEU@aAb~ zlL$;2S~Q7eo4o+7By_Jtq3VP9ymk%COKfNFkol9&rXwfp2~ImUzwD2&5qFqOCLXPa QxzfS&^?|m7v8^=s7q1{K-2eap diff --git a/analytics/static/analytics/general.css b/analytics/static/analytics/general.css index 4b4e334f2..1bcc62744 100644 --- a/analytics/static/analytics/general.css +++ b/analytics/static/analytics/general.css @@ -77,6 +77,12 @@ .middle-chart article { text-align: center; } +.user-tooltip { + background: linear-gradient(#0e8999, #6bf0ce); + color: white; + border-radius: 10px; + padding: 7px; } + .most-accessed-list { background-color: #52b7bd; width: 80%; diff --git a/analytics/static/analytics/general.css.map b/analytics/static/analytics/general.css.map index a7362a523..8e59cf6c3 100644 --- a/analytics/static/analytics/general.css.map +++ b/analytics/static/analytics/general.css.map @@ -1,6 +1,6 @@ { "version": 3, -"mappings": "AAEA,YAAY;EACR,MAAM,EAAE,iBAAiB;EACzB,aAAa,EAAE,IAAI;EACnB,OAAO,EAAE,IAAI;EACb,QAAQ,EAAE,IAAI;EACd,KAAK,EAAE,IAAI;;AAEf,sBAAsB;EAClB,MAAM,EAAE,GAAG;EACX,OAAO,EAAE,KAAK;EACd,yBAAE;IACE,KAAK,EAbC,OAAO;EAejB,yBAAE;IACE,KAAK,EAAE,KAAK;IACZ,OAAO,EAAE,WAAW;IACpB,KAAK,EAAE,GAAG;IACV,MAAM,EAAE,GAAG;IAEX,4BAAE;MACE,YAAY,EAAE,EAAE;MAChB,KAAK,EAAE,GAAG;MACV,KAAK,EAAE,KAAK;MAEZ,yCAAY;QACR,gBAAgB,EAAE,OAAO;QACzB,KAAK,EAAE,IAAI;QACX,UAAU,EAAE,MAAM;QAClB,aAAa,EAAE,IAAI;MAEvB,gCAAG;QACC,gBAAgB,EAAE,OAAO;QACzB,KAAK,EAAE,IAAI;QACX,UAAU,EAAE,MAAM;QAClB,aAAa,EAAE,IAAI;;AAInC,sBAAsB;EAClB,UAAU,EAAE,2CAA2C;EACvD,MAAM,EAAE,IAAI;EACZ,aAAa,EAAE,IAAI;EACnB,KAAK,EAAE,OAAO;EACd,WAAW,EAAE,GAAG;EAChB,UAAU,EAAE,IAAI;EAEhB,yBAAE;IACE,WAAW,EAAE,EAAE;;AAEvB,eAAe;EACX,KAAK,EAAE,IAAI;EACX,MAAM,EAAE,IAAI;;AAEhB,UAAU;EACN,aAAa,EAAE,IAAI;EACnB,KAAK,EAAE,OAAO;EACd,KAAK,EAAE,IAAI;;AAIf,SAAS;EACL,KAAK,EAAE,OAAO;EACd,SAAS,EAAE,IAAI;;AAGnB,mBAAmB;EACf,UAAU,EAAE,iCAAmC;;AAEnD,MAAM;EACF,KAAK,EAAE,GAAG;EACV,KAAK,EAAE,IAAI;EACX,SAAE;IACE,KAAK,EA1EC,OAAO;;AA4ErB,SAAS;EACL,KAAK,EAAE,GAAG;EACV,MAAM,EAAE,GAAG;EACX,KAAK,EAAE,KAAK;EACZ,YAAY,EAAE,GAAG;EACjB,gBAAgB,EAAE,OAAO;EACzB,UAAU,EAAE,IAAI;EAChB,aAAa,EAAE,iBAAiB;EAChC,WAAC;IACG,WAAW,EAAE,IAAI;IACjB,SAAS,EAAE,IAAI;;AAInB,qBAAO;EACH,UAAU,EAAE,MAAM;;AAE1B,mBAAmB;EACf,gBAAgB,EAAE,OAAO;EACzB,KAAK,EAAE,GAAG;EACV,WAAW,EAAE,EAAE;EACf,UAAU,EAAE,EAAE;EACd,YAAY,EAAE,CAAC;EACf,KAAK,EAAE,KAAK;EACZ,UAAU,EAAE,sDAAsD;EAElE,sBAAE;IACE,YAAY,EAAE,EAAE;;AAExB,yBAAyB;EACrB,gBAAgB,EAAE,OAAO", +"mappings": "AAEA,YAAY;EACR,MAAM,EAAE,iBAAiB;EACzB,aAAa,EAAE,IAAI;EACnB,OAAO,EAAE,IAAI;EACb,QAAQ,EAAE,IAAI;EACd,KAAK,EAAE,IAAI;;AAEf,sBAAsB;EAClB,MAAM,EAAE,GAAG;EACX,OAAO,EAAE,KAAK;EACd,yBAAE;IACE,KAAK,EAbC,OAAO;EAejB,yBAAE;IACE,KAAK,EAAE,KAAK;IACZ,OAAO,EAAE,WAAW;IACpB,KAAK,EAAE,GAAG;IACV,MAAM,EAAE,GAAG;IAEX,4BAAE;MACE,YAAY,EAAE,EAAE;MAChB,KAAK,EAAE,GAAG;MACV,KAAK,EAAE,KAAK;MAEZ,yCAAY;QACR,gBAAgB,EAAE,OAAO;QACzB,KAAK,EAAE,IAAI;QACX,UAAU,EAAE,MAAM;QAClB,aAAa,EAAE,IAAI;MAEvB,gCAAG;QACC,gBAAgB,EAAE,OAAO;QACzB,KAAK,EAAE,IAAI;QACX,UAAU,EAAE,MAAM;QAClB,aAAa,EAAE,IAAI;;AAInC,sBAAsB;EAClB,UAAU,EAAE,2CAA2C;EACvD,MAAM,EAAE,IAAI;EACZ,aAAa,EAAE,IAAI;EACnB,KAAK,EAAE,OAAO;EACd,WAAW,EAAE,GAAG;EAChB,UAAU,EAAE,IAAI;EAEhB,yBAAE;IACE,WAAW,EAAE,EAAE;;AAEvB,eAAe;EACX,KAAK,EAAE,IAAI;EACX,MAAM,EAAE,IAAI;;AAEhB,UAAU;EACN,aAAa,EAAE,IAAI;EACnB,KAAK,EAAE,OAAO;EACd,KAAK,EAAE,IAAI;;AAIf,SAAS;EACL,KAAK,EAAE,OAAO;EACd,SAAS,EAAE,IAAI;;AAGnB,mBAAmB;EACf,UAAU,EAAE,iCAAmC;;AAEnD,MAAM;EACF,KAAK,EAAE,GAAG;EACV,KAAK,EAAE,IAAI;EACX,SAAE;IACE,KAAK,EA1EC,OAAO;;AA4ErB,SAAS;EACL,KAAK,EAAE,GAAG;EACV,MAAM,EAAE,GAAG;EACX,KAAK,EAAE,KAAK;EACZ,YAAY,EAAE,GAAG;EACjB,gBAAgB,EAAE,OAAO;EACzB,UAAU,EAAE,IAAI;EAChB,aAAa,EAAE,iBAAiB;EAChC,WAAC;IACG,WAAW,EAAE,IAAI;IACjB,SAAS,EAAE,IAAI;;AAInB,qBAAO;EACH,UAAU,EAAE,MAAM;;AAE1B,aAAa;EACT,UAAU,EAAE,iCAAkC;EAC9C,KAAK,EAAE,KAAK;EACZ,aAAa,EAAE,IAAI;EACnB,OAAO,EAAE,GAAG;;AAEhB,mBAAmB;EACf,gBAAgB,EAAE,OAAO;EACzB,KAAK,EAAE,GAAG;EACV,WAAW,EAAE,EAAE;EACf,UAAU,EAAE,EAAE;EACd,YAAY,EAAE,CAAC;EACf,KAAK,EAAE,KAAK;EACZ,UAAU,EAAE,sDAAsD;EAElE,sBAAE;IACE,YAAY,EAAE,EAAE;;AAExB,yBAAyB;EACrB,gBAAgB,EAAE,OAAO", "sources": ["general.sass"], "names": [], "file": "general.css" diff --git a/analytics/static/analytics/general.sass b/analytics/static/analytics/general.sass index 92f6e9441..f521cb237 100644 --- a/analytics/static/analytics/general.sass +++ b/analytics/static/analytics/general.sass @@ -91,6 +91,12 @@ $title-color: #009688 article text-align: center +.user-tooltip + background: linear-gradient( #0e8999, #6bf0ce) + color: white + border-radius: 10px + padding: 7px + .most-accessed-list background-color: #52b7bd width: 80% diff --git a/analytics/static/analytics/js/charts.js b/analytics/static/analytics/js/charts.js index 4471b5fef..4f9e2cd85 100644 --- a/analytics/static/analytics/js/charts.js +++ b/analytics/static/analytics/js/charts.js @@ -187,22 +187,38 @@ var charts = { //Add texts to show user names - groups.append("text") + /*groups.append("text") .text(function(d){ return d['user'] +'('+ d['count'] + ')'; }).attr("fill", "#000000") .attr("id", function(d){ return "user_tooltip_"+d['user_id']; - }).style("display", "none"); + }).style("display", "none");*/ + + var tooltip_div = d3.select("body").append("div") + .attr('class','user-tooltip') + .attr("display", "none") + .attr("height", 28) + .attr("width", 80) + .style("position", "absolute") + .style('pointer-events', 'none'); + + groups.on("mouseover", function(d){ - $("#"+"user_tooltip_"+d['user_id']).show(); + //$("#"+"user_tooltip_"+d['user_id']).show(); + tooltip_div.transition().duration(200).style("opacity", .9); + tooltip_div.html(d['user'] + '
    ' + d['count'] + ' acessos') + .style("left", (d3.event.pageX) + "px") + .style("top", (d3.event.pageY - 28) + "px"); + console.log(d3.event.pageX); + console.log(d3.event.pageY); }); groups.on("mouseout", function(d){ - $("#"+"user_tooltip_"+d['user_id']).hide(); + //$("#"+"user_tooltip_"+d['user_id']).hide(); }); From 54304f2c28c35416cd30d37219c64d6aaf30096c Mon Sep 17 00:00:00 2001 From: Jailson Dias Date: Fri, 5 May 2017 17:21:40 -0300 Subject: [PATCH 04/24] =?UTF-8?q?resolvendo=20problemas=20com=20tradu?= =?UTF-8?q?=C3=A7=C3=B5es=20nos=20relatorios=20de=20webpage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webpage/locale/pt_BR/LC_MESSAGES/django.po | 125 ++++++++++++++------- webpage/templates/webpages/relatorios.html | 9 +- webpage/views.py | 26 ----- 3 files changed, 87 insertions(+), 73 deletions(-) diff --git a/webpage/locale/pt_BR/LC_MESSAGES/django.po b/webpage/locale/pt_BR/LC_MESSAGES/django.po index cfb1eee5e..184433799 100644 --- a/webpage/locale/pt_BR/LC_MESSAGES/django.po +++ b/webpage/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-28 20:41-0300\n" +"POT-Creation-Date: 2017-05-05 17:14-0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -18,26 +18,30 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" -#: forms.py:25 +#: forms.py:27 msgid "Tags" msgstr "Tags" -#: forms.py:31 +#: forms.py:33 msgid "Webpage name" msgstr "Nome da Página Web" -#: forms.py:32 +#: forms.py:34 msgid "Webpage content" msgstr "Conteúdo da Página Web" -#: forms.py:53 +#: forms.py:55 msgid "This subject already has a webpage with this name" msgstr "Esse assunto já possui uma Página Web com esse nome" -#: forms.py:64 +#: forms.py:66 forms.py:112 msgid "This field is required." msgstr "Esse campo é obrigatório." +#: forms.py:124 +msgid "The image is too large. It should have less than 5MB." +msgstr "A imagem é muito grande. Deve ser menor do que 5MB" + #: models.py:8 msgid "Webpage Content" msgstr "Conteúdo da Página Web" @@ -82,59 +86,87 @@ msgstr "Atribuir grupos de estudo à Página Web" msgid "Save" msgstr "Salvar" -#: templates/webpages/create.html:20 views.py:221 +#: templates/webpages/create.html:20 views.py:227 msgid "Create Webpage" msgstr "Criar Página Web" -#: templates/webpages/relatorios.html:16 templates/webpages/relatorios.html:30 -#: templates/webpages/relatorios.html:37 +#: templates/webpages/relatorios.html:17 templates/webpages/relatorios.html:37 msgid "User" msgstr "Usuário" -#: templates/webpages/relatorios.html:16 templates/webpages/relatorios.html:30 -#: templates/webpages/relatorios.html:37 +#: templates/webpages/relatorios.html:17 templates/webpages/relatorios.html:37 msgid "Group" msgstr "Grupo" -#: templates/webpages/relatorios.html:16 templates/webpages/relatorios.html:30 +#: templates/webpages/relatorios.html:17 msgid "Action" msgstr "Ação" -#: templates/webpages/relatorios.html:16 templates/webpages/relatorios.html:30 +#: templates/webpages/relatorios.html:17 msgid "Date of Action" msgstr "Data da ação" -#: templates/webpages/relatorios.html:135 -#: templates/webpages/relatorios.html:155 +#: templates/webpages/relatorios.html:37 +msgid "Send message" +msgstr "Enviar Mensagem" + +#: templates/webpages/relatorios.html:37 +#| msgid "Action" +msgid "Action don't realized" +msgstr "Ação não realizada" + +#: templates/webpages/relatorios.html:151 +#: templates/webpages/relatorios.html:171 msgid "Reports" msgstr "Relatórios" -#: templates/webpages/relatorios.html:162 +#: templates/webpages/relatorios.html:178 msgid "Report of the resource " msgstr "Relatórios do recurso " -#: templates/webpages/relatorios.html:165 +#: templates/webpages/relatorios.html:187 msgid "Select the period: " msgstr "Selecione o período: " -#: templates/webpages/relatorios.html:179 +#: templates/webpages/relatorios.html:196 msgid "Search" msgstr "Pesquisar" -#: templates/webpages/relatorios.html:201 +#: templates/webpages/relatorios.html:220 msgid "Filter: " msgstr "Filtro: " +#: templates/webpages/relatorios.html:244 +#: templates/webpages/relatorios.html:329 +msgid "record(s)" +msgstr "Relatório(s)" + +#: templates/webpages/send_message.html:38 +msgid "Click or drop the picture here" +msgstr "Clique ou arraste a imagem aqui" + +#: templates/webpages/send_message.html:40 +msgid "The picture could not exceed 5MB." +msgstr "A imagem não pode exceder 5MB." + +#: templates/webpages/send_message.html:62 +msgid "Close" +msgstr "Fechar" + +#: templates/webpages/send_message.html:63 +msgid "Send" +msgstr "Enviar" + #: templates/webpages/update.html:20 msgid "Edit: " msgstr "Editar: " -#: views.py:148 views.py:161 views.py:279 views.py:281 views.py:297 -#: views.py:299 +#: views.py:155 views.py:168 views.py:285 views.py:287 views.py:303 +#: views.py:305 msgid "Visualize" msgstr "Visualizar" -#: views.py:232 +#: views.py:238 #, python-format msgid "" "The Webpage \"%s\" was added to the Topic \"%s\" of the virtual environment " @@ -143,50 +175,59 @@ msgstr "" "A Página Web \"%s\" foi adicionado ao tópico \"%s\" do ambiente virtual \"%s" "\" com sucesso!" -#: views.py:343 +#: views.py:349 msgid "Update Webpage" msgstr "Atualizar Página Web" -#: views.py:354 +#: views.py:360 #, python-format msgid "The Webpage \"%s\" was updated successfully!" msgstr "A Página Web \"%s\" foi atualizada com sucesso!" -#: views.py:390 +#: views.py:396 #, python-format msgid "" "The webpage \"%s\" was removed successfully from virtual environment \"%s\"!" msgstr "" "A Página Web \"%s\" foi removida do ambiente virtual \"%s\" com sucesso!" -#: views.py:460 +#: views.py:455 msgid "Webpage Reports" msgstr "Nome da Página Web" -#: views.py:478 -msgid "Users who viewed" -msgstr "Usuários que visualizaram" +#: views.py:474 +msgid "Realized" +msgstr "Realizado" -#: views.py:478 -msgid "Users who did not viewed" -msgstr "Usuários que não visualizaram" +#: views.py:474 +msgid "Unrealized" +msgstr "Não Realizado" -#: views.py:478 +#: views.py:474 msgid "Historic" msgstr "Histórico" -#: views.py:515 -msgid "Webpage" -msgstr "Nome da Página Web" - -#: views.py:516 +#: views.py:492 views.py:501 msgid "View" msgstr "Visualizar" -#: views.py:520 -msgid "Students viewing the webpage" -msgstr "Estudantes que visualizaram a webpage" +#: views.py:500 +msgid "Webpage" +msgstr "Nome da Página Web" + +#: views.py:505 +msgid "Actions about resource" +msgstr "Ações sobre o recurso" -#: views.py:521 +#: views.py:506 msgid "Quantity" msgstr "Quantidade" + +#~ msgid "Users who viewed" +#~ msgstr "Usuários que visualizaram" + +#~ msgid "Users who did not viewed" +#~ msgstr "Usuários que não visualizaram" + +#~ msgid "Students viewing the webpage" +#~ msgstr "Estudantes que visualizaram a webpage" diff --git a/webpage/templates/webpages/relatorios.html b/webpage/templates/webpages/relatorios.html index dcfa8564a..17f7cedb6 100644 --- a/webpage/templates/webpages/relatorios.html +++ b/webpage/templates/webpages/relatorios.html @@ -34,7 +34,7 @@ array_n_did.push([input,"{{data_json.1}}","{{data_json.2}}","{{data_json.3}}"]); {% endfor%} var json_n_did = {"data":array_n_did}; - var column_n_did = [{"string":' {% trans "Send message" %}'},{"string":'{% trans "User" %}'},{"string":'{% trans "Group" %}'},{"string":"Action don't realized"}]; + var column_n_did = [{"string":' {% trans "Send message" %}'},{"string":'{% trans "User" %}'},{"string":'{% trans "Group" %}'},{"string":"{% trans "Action don't realized" %}"}]; @@ -74,6 +74,7 @@ json_n_did["data"][i][2],json_n_did["data"][i][3]]); } searcher(col, tabela_atual,true); + } else if (col == "{{did_table}}"){ tabela_atual = true; search = []; @@ -92,6 +93,7 @@ chart.draw(data, options); } + var sortAscending = {0:false,1:false,2:false,3:false}; function drawTable(columns = column_history,rows = pagination(json_history["data"],1),isdate = true,columndate = 3) { var data_table = new google.visualization.DataTable(); @@ -197,6 +199,7 @@

    {% trans "Report of t

    +
    @@ -376,8 +379,6 @@

    {% trans "Report of t .appendTo('#text_chat_form'); var formData = new FormData($('#text_chat_form').get(0)); - console.log("formData"); - console.log(formData); $.ajax({ url: "{% url 'webpages:send_message' webpage.slug %}", type: "POST", @@ -392,7 +393,6 @@

    {% trans "Report of t $( "#modal-message" ).empty(); $(".modal-backdrop.fade.in").remove(); } else { - console.log("teste"); $( "#modal-message" ).empty(); $(".modal-backdrop.fade.in").remove(); $( "#modal-message" ).append( data ); @@ -401,7 +401,6 @@

    {% trans "Report of t }, error: function(data){ console.log("erro"); - console.log(data); } }); } diff --git a/webpage/views.py b/webpage/views.py index 1501bc231..924029204 100644 --- a/webpage/views.py +++ b/webpage/views.py @@ -196,9 +196,6 @@ def form_valid(self, form, pendencies_form): if not self.object.topic.visible and not self.object.topic.repository: self.object.visible = False - - # if form.cleaned_data["all_students"]: - # self.object.students.add(*self.object.topic.subject.students.all()) self.object.save() pend_form = pendencies_form.save(commit = False) @@ -416,17 +413,6 @@ def get_success_url(self): return reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) -def get_chart(request,slug): - webpage = get_object_or_404(Webpage, slug=slug) - alunos = webpage.students.all() - 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") - re = [] - c_visualizou = visualizou.count() - re.append(["Página Web","Fez","Não fez"]) - re.append(["Visualizar",c_visualizou, alunos.count() - c_visualizou]) - return JsonResponse({"dados":re}) - - class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): log_component = 'resources' log_action = 'view_statistics' @@ -566,15 +552,3 @@ def get_context_data(self, **kwargs): return context -def sendMessage(request, slug): - message = request.GET.get('message','') - users = request.GET.getlist('users[]','') - user = request.user - subject = get_object_or_404(Subject,slug = slug) - - for u in users: - to_user = User.objects.get(email=u) - talk, create = Conversation.objects.get_or_create(user_one=user,user_two=to_user) - created = TalkMessages.objects.create(text=message,talk=talk,user=user,subject=subject) - - return JsonResponse({"message":"ok"}) From 082830a137173cdf9fdfcabc61b4e0379f8af1d4 Mon Sep 17 00:00:00 2001 From: Jailson Dias Date: Fri, 5 May 2017 17:23:01 -0300 Subject: [PATCH 05/24] =?UTF-8?q?colocando=20a=20op=C3=A7=C3=A3o=20de=20en?= =?UTF-8?q?viar=20mensagem=20junto=20com=20o=20texto=20quando=20for=20envi?= =?UTF-8?q?ar=20uma=20mensagem=20para=20varias=20pessoas=20no=20relatorio?= =?UTF-8?q?=20de=20pdf=5Ffile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pdf_file/templates/pdf_file/relatorios.html | 96 ++++++++------- pdf_file/templates/pdf_file/send_message.html | 112 ++++++++++++++++++ pdf_file/urls.py | 12 +- pdf_file/views.py | 62 +++++++--- 4 files changed, 209 insertions(+), 73 deletions(-) create mode 100644 pdf_file/templates/pdf_file/send_message.html diff --git a/pdf_file/templates/pdf_file/relatorios.html b/pdf_file/templates/pdf_file/relatorios.html index 649ef17d8..39ce64c4d 100644 --- a/pdf_file/templates/pdf_file/relatorios.html +++ b/pdf_file/templates/pdf_file/relatorios.html @@ -34,7 +34,7 @@ array_n_did.push([input,"{{data_json.1}}","{{data_json.2}}", "{{data_json.3}}"]); {% endfor%} var json_n_did = {"data":array_n_did}; - var column_n_did = [{"string":' {% trans "Send message" %}'},{"string":'{% trans "User" %}'},{"string":'{% trans "Group" %}'},{"string":"Action don't realized"}]; + var column_n_did = [{"string":' {% trans "Send message" %}'},{"string":'{% trans "User" %}'},{"string":'{% trans "Group" %}'},{"string":"{% trans "Action don't realized" %}"}]; @@ -138,6 +138,7 @@ table.draw(data_table, options); } } + var table = new google.visualization.Table(document.getElementById('table_div')); google.visualization.events.addListener(table, 'sort', function(e) {ordenar(e)}); table.draw(data_table, options); @@ -205,13 +206,13 @@

    {% trans "Report of t

    -
    +
    - -
    +
    +
    +
      @@ -231,44 +233,14 @@

      {% trans "Report of t

    - - - +


    {% endblock %} diff --git a/pdf_file/templates/pdf_file/send_message.html b/pdf_file/templates/pdf_file/send_message.html new file mode 100644 index 000000000..8c4854094 --- /dev/null +++ b/pdf_file/templates/pdf_file/send_message.html @@ -0,0 +1,112 @@ + + {% load widget_tweaks i18n %} + + + + \ No newline at end of file diff --git a/pdf_file/urls.py b/pdf_file/urls.py index 585e67e90..67700a372 100644 --- a/pdf_file/urls.py +++ b/pdf_file/urls.py @@ -4,10 +4,10 @@ from . import views urlpatterns = [ - url(r'^create/(?P[\w_-]+)/$', views.PDFFileCreateView.as_view(), name='create'), - 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'), - url(r'^chart/(?P[\w_-]+)/$', views.StatisticsView.as_view(), name = 'get_chart'), - url(r'^send-message/(?P[\w_-]+)/$', views.sendMessage, name = 'send_message'), + url(r'^create/(?P[\w_-]+)/$', views.PDFFileCreateView.as_view(), name='create'), + 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'), + url(r'^chart/(?P[\w_-]+)/$', views.StatisticsView.as_view(), name = 'get_chart'), + url(r'^send-message/(?P[\w_-]+)/$', views.SendMessage.as_view(), name = 'send_message'), ] diff --git a/pdf_file/views.py b/pdf_file/views.py index 259acc03f..fdf57ecc5 100644 --- a/pdf_file/views.py +++ b/pdf_file/views.py @@ -19,6 +19,10 @@ from .models import PDFFile from pendencies.forms import PendenciesForm +from chat.models import Conversation, TalkMessages +from users.models import User +from subjects.models import Subject +from webpage.forms import FormModalMessage class ViewPDFFile(LoginRequiredMixin, LogMixin, generic.TemplateView): @@ -154,9 +158,6 @@ def form_valid(self, form, pendencies_form): if not self.object.topic.visible and not self.object.topic.repository: self.object.visible = False - if form.cleaned_data["all_students"]: - self.object.students.add(*self.object.topic.subject.students.all()) - self.object.save() pend_form = pendencies_form.save(commit = False) @@ -412,6 +413,8 @@ def get_context_data(self, **kwargs): context["init_date"] = start_date context["end_date"] = end_date alunos = pdf_file.students.all() + if pdf_file.all_students : + alunos = pdf_file.topic.subject.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(_("Realized")),str(_("Unrealized")),str(_("Historic")) @@ -454,19 +457,42 @@ def get_context_data(self, **kwargs): context["history_table"] = history return context +class SendMessage(LoginRequiredMixin, LogMixin, generic.edit.FormView): + log_component = 'resources' + log_action = 'send' + log_resource = 'pdffile' + log_context = {} + + login_url = reverse_lazy("users:login") + redirect_field_name = 'next' + + template_name = 'pdf_file/send_message.html' + form_class = FormModalMessage + + def dispatch(self, request, *args, **kwargs): + slug = self.kwargs.get('slug', '') + pdf_file = get_object_or_404(PDFFile, slug = slug) + self.pdf_file = pdf_file + + if not has_subject_permissions(request.user, pdf_file.topic.subject): + return redirect(reverse_lazy('subjects:home')) + + return super(SendMessage, self).dispatch(request, *args, **kwargs) + + def form_valid(self, form): + message = form.cleaned_data.get('comment') + image = form.cleaned_data.get("image") + users = (self.request.POST.get('users[]','')).split(",") + user = self.request.user + subject = self.pdf_file.topic.subject + for u in users: + to_user = User.objects.get(email=u) + talk, create = Conversation.objects.get_or_create(user_one=user,user_two=to_user) + created = TalkMessages.objects.create(text=message,talk=talk,user=user,subject=subject,image=image) + return JsonResponse({"message":"ok"}) + + def get_context_data(self, **kwargs): + context = super(SendMessage,self).get_context_data() + context["pdf_file"] = get_object_or_404(PDFFile, slug=self.kwargs.get('slug', '')) + return context -from chat.models import Conversation, TalkMessages -from users.models import User -from subjects.models import Subject -def sendMessage(request, slug): - message = request.GET.get('message','') - users = request.GET.getlist('users[]','') - user = request.user - subject = get_object_or_404(Subject,slug = slug) - - for u in users: - to_user = User.objects.get(email=u) - talk, create = Conversation.objects.get_or_create(user_one=user,user_two=to_user) - created = TalkMessages.objects.create(text=message,talk=talk,user=user,subject=subject) - - return JsonResponse({"message":"ok"}) From 0d54effaaaf3789727452d90f58fd9a79d112ddd Mon Sep 17 00:00:00 2001 From: Jailson Dias Date: Fri, 5 May 2017 17:23:24 -0300 Subject: [PATCH 06/24] =?UTF-8?q?resolvendo=20problemas=20com=20tradu?= =?UTF-8?q?=C3=A7=C3=B5es=20nos=20relatorios=20de=20pdf=5Ffile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pdf_file/locale/pt_BR/LC_MESSAGES/django.po | 111 +++++++++++++------- 1 file changed, 74 insertions(+), 37 deletions(-) diff --git a/pdf_file/locale/pt_BR/LC_MESSAGES/django.po b/pdf_file/locale/pt_BR/LC_MESSAGES/django.po index 591bd3d7a..d78792255 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-28 20:39-0300\n" +"POT-Creation-Date: 2017-05-05 17:16-0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -76,7 +76,7 @@ msgstr "Ação não permitida pelo usuário" #: templates/pdf_file/_form.html:161 msgid "Wished period" -msgstr "" +msgstr "Período desejado" #: templates/pdf_file/_form.html:257 msgid "Attribute students to file link" @@ -94,45 +94,73 @@ msgstr "Salvar" msgid "Create PDF file" msgstr "Criar arquivo PDF" -#: templates/pdf_file/relatorios.html:16 templates/pdf_file/relatorios.html:30 -#: templates/pdf_file/relatorios.html:37 +#: templates/pdf_file/relatorios.html:17 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 +#: templates/pdf_file/relatorios.html:17 templates/pdf_file/relatorios.html:37 msgid "Group" msgstr "Grupo" -#: templates/pdf_file/relatorios.html:16 templates/pdf_file/relatorios.html:30 +#: templates/pdf_file/relatorios.html:17 msgid "Action" msgstr "Ação" -#: templates/pdf_file/relatorios.html:16 templates/pdf_file/relatorios.html:30 +#: templates/pdf_file/relatorios.html:17 msgid "Date of Action" msgstr "Data da ação" -#: templates/pdf_file/relatorios.html:135 -#: templates/pdf_file/relatorios.html:155 +#: templates/pdf_file/relatorios.html:37 +msgid "Send message" +msgstr "Enviar Mensagem" + +#: templates/pdf_file/relatorios.html:37 +#| msgid "Actions about resource" +msgid "Action don't realized" +msgstr "Ação não realizada" + +#: templates/pdf_file/relatorios.html:151 +#: templates/pdf_file/relatorios.html:171 msgid "Reports" msgstr "Relatórios" -#: templates/pdf_file/relatorios.html:162 +#: templates/pdf_file/relatorios.html:178 msgid "Report of the resource " msgstr "Relatórios do recurso " -#: templates/pdf_file/relatorios.html:165 +#: templates/pdf_file/relatorios.html:187 msgid "Select the period: " msgstr "Selecione o período: " -#: templates/pdf_file/relatorios.html:178 +#: templates/pdf_file/relatorios.html:196 msgid "Search" msgstr "Pesquisar" -#: templates/pdf_file/relatorios.html:200 +#: templates/pdf_file/relatorios.html:220 msgid "Filter: " msgstr "Filtro: " +#: templates/pdf_file/relatorios.html:244 +#: templates/pdf_file/relatorios.html:329 +msgid "record(s)" +msgstr "Relatório(s)" + +#: templates/pdf_file/send_message.html:38 +msgid "Click or drop the picture here" +msgstr "Clique ou arraste a imagem aqui" + +#: templates/pdf_file/send_message.html:40 +msgid "The picture could not exceed 5MB." +msgstr "A imagem não pode exceder 5MB." + +#: templates/pdf_file/send_message.html:62 +msgid "Close" +msgstr "Fechar" + +#: templates/pdf_file/send_message.html:63 +msgid "Send" +msgstr "Enviar" + #: templates/pdf_file/update.html:20 msgid "Edit: " msgstr "Editar: " @@ -141,16 +169,16 @@ msgstr "Editar: " msgid "PDF could not be displayed" msgstr "PDF não pode ser mostrado" -#: views.py:112 views.py:125 views.py:236 views.py:238 views.py:254 -#: views.py:256 +#: views.py:116 views.py:129 views.py:240 views.py:242 views.py:258 +#: views.py:260 msgid "Visualize" msgstr "Visualizar" -#: views.py:185 +#: views.py:189 msgid "Create PDF File" msgstr "Criar o arquivo PDF" -#: views.py:196 +#: views.py:200 #, python-format msgid "" "The PDF File \"%s\" was added to the Topic \"%s\" of the virtual environment " @@ -159,50 +187,59 @@ msgstr "" "O arquivo PDF \"%s\" foi adicionado ao topico \"%s\" do ambiente virtual " "\"%s\" com sucesso!" -#: views.py:300 +#: views.py:304 msgid "Update PDF File" msgstr "Atualize arquivo PDF" -#: views.py:311 +#: views.py:315 #, python-format msgid "The PDF File \"%s\" was updated successfully!" msgstr "O arquivo PDF \"%s\" foi atualizado com sucesso!" -#: views.py:338 +#: views.py:342 #, 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 +#: views.py:400 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:420 +msgid "Realized" +msgstr "Realizado" -#: views.py:414 -msgid "Users who did not viewed" -msgstr "Usuários que não visualizaram" +#: views.py:420 +msgid "Unrealized" +msgstr "Não Realizado" -#: views.py:414 +#: views.py:420 msgid "Historic" msgstr "Histórico" -#: views.py:446 -msgid "PDF File" -msgstr "Criar o arquivo PDF" - -#: views.py:447 +#: views.py:439 views.py:448 msgid "View" msgstr "Visualizar" -#: views.py:451 -msgid "Students viewing the PDF File" -msgstr "Estudantes que visualizaram o arquivo PDF" +#: views.py:447 +msgid "PDF File" +msgstr "Criar o arquivo PDF" #: views.py:452 +msgid "Actions about resource" +msgstr "Ações sobre o recurso" + +#: views.py:453 msgid "Quantity" msgstr "Quantidade" + +#~ msgid "Users who viewed" +#~ msgstr "Usuário que visualizaram" + +#~ msgid "Users who did not viewed" +#~ msgstr "Usuários que não visualizaram" + +#~ msgid "Students viewing the PDF File" +#~ msgstr "Estudantes que visualizaram o arquivo PDF" From f90a61aceeb4fb953626983db6b0a63f509ec24d Mon Sep 17 00:00:00 2001 From: Jailson Dias Date: Fri, 5 May 2017 18:02:15 -0300 Subject: [PATCH 07/24] =?UTF-8?q?criando=20a=20p=C3=A1gina=20de=20relat?= =?UTF-8?q?=C3=B3rios=20para=20link=20para=20arquivo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templates/file_links/relatorios.html | 408 ++++++++++++++++++ file_link/urls.py | 2 + file_link/views.py | 151 ++++++- topics/templates/resources/list.html | 4 +- 4 files changed, 563 insertions(+), 2 deletions(-) create mode 100644 file_link/templates/file_links/relatorios.html diff --git a/file_link/templates/file_links/relatorios.html b/file_link/templates/file_links/relatorios.html new file mode 100644 index 000000000..da2d2cdff --- /dev/null +++ b/file_link/templates/file_links/relatorios.html @@ -0,0 +1,408 @@ +{% extends "webpages/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 filelink%} +{% endblock %} + +{% block content %} + {% if messages %} + {% for message in messages %} + + {% endfor %} + {% endif %} +
    +
    +
    +
    +

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

    +
    +
    +
    +
    +
    +

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

    +
    +
    +
    +
    + +
    +
    + +
    +
    +
    +
    +
    + +
    +
    +
    + +
    +
    +
    +
    +
    +
      + +
    +
    +
    +
    + +
    +

    +
    +
    + + +{% endblock %} diff --git a/file_link/urls.py b/file_link/urls.py index c2ee34c6b..f2be5439f 100644 --- a/file_link/urls.py +++ b/file_link/urls.py @@ -8,4 +8,6 @@ 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'^download/(?P[\w_-]+)/$', views.DownloadFile.as_view(), name = 'download'), + url(r'^chart/(?P[\w_-]+)/$', views.StatisticsView.as_view(), name = 'get_chart'), + url(r'^send-message/(?P[\w_-]+)/$', views.SendMessage.as_view(), name = 'send_message'), ] diff --git a/file_link/views.py b/file_link/views.py index 79d2240b2..99d86a8a0 100644 --- a/file_link/views.py +++ b/file_link/views.py @@ -18,6 +18,15 @@ from .forms import FileLinkForm from .models import FileLink + +import datetime +from log.models import Log +from chat.models import Conversation, TalkMessages +from users.models import User +from subjects.models import Subject + +from webpage.forms import FormModalMessage + class DownloadFile(LoginRequiredMixin, LogMixin, generic.DetailView): log_component = 'resources' log_action = 'view' @@ -343,4 +352,144 @@ def get_success_url(self): super(DeleteView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) - return reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) \ No newline at end of file + 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 = 'filelink' + log_context = {} + + login_url = reverse_lazy("users:login") + redirect_field_name = 'next' + model = FileLink + template_name = 'file_links/relatorios.html' + + def dispatch(self, request, *args, **kwargs): + slug = self.kwargs.get('slug', '') + filelink = get_object_or_404(FileLink, slug = slug) + + if not has_subject_permissions(request.user, filelink.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['filelink_id'] = self.object.id + self.log_context['filelink_name'] = self.object.name + self.log_context['filelink_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'] = _('File Link Reports') + + slug = self.kwargs.get('slug') + filelink = get_object_or_404(FileLink, slug = slug) + print (self.request.GET.get('init_date','')) + 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) + context["init_date"] = start_date + context["end_date"] = end_date + alunos = filelink.students.all() + if filelink.all_students : + alunos = filelink.topic.subject.students.all() + + vis_ou = Log.objects.filter(context__contains={'filelink_id':filelink.id},resource="filelink",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(_("Realized")),str(_("Unrealized")),str(_("Historic")) + re = [] + data_n_did,data_history = [],[] + 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 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 filelink.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")]) + index = 0 + for alun in not_view: + data_n_did.append([index,str(alun),", ".join([str(x) for x in filelink.topic.subject.group_subject.filter(participants__email=alun.email)]),str(_('View')), str(alun.email)]) + index += 1 + json_n_did["data"] = data_n_did + + + context["json_n_did"] = json_n_did + context["json_history"] = json_history + c_visualizou = vis_ou.distinct("user_email").count() + re.append([str(_('File link')),did,n_did]) + re.append([str(_('View')),c_visualizou, alunos.count() - c_visualizou]) + context['topic'] = filelink.topic + context['subject'] = filelink.topic.subject + context['db_data'] = re + context['title_chart'] = _('Actions about resource') + context['title_vAxis'] = _('Quantity') + + context["n_did_table"] = n_did + context["did_table"] = did + context["history_table"] = history + return context + + + +class SendMessage(LoginRequiredMixin, LogMixin, generic.edit.FormView): + log_component = 'resources' + log_action = 'send' + log_resource = 'filelink' + log_context = {} + + login_url = reverse_lazy("users:login") + redirect_field_name = 'next' + + template_name = 'file_links/send_message.html' + form_class = FormModalMessage + + def dispatch(self, request, *args, **kwargs): + slug = self.kwargs.get('slug', '') + filelink = get_object_or_404(FileLink, slug = slug) + self.filelink = filelink + + if not has_subject_permissions(request.user, filelink.topic.subject): + return redirect(reverse_lazy('subjects:home')) + + return super(SendMessage, self).dispatch(request, *args, **kwargs) + + def form_valid(self, form): + message = form.cleaned_data.get('comment') + image = form.cleaned_data.get("image") + users = (self.request.POST.get('users[]','')).split(",") + user = self.request.user + subject = self.filelink.topic.subject + for u in users: + to_user = User.objects.get(email=u) + talk, create = Conversation.objects.get_or_create(user_one=user,user_two=to_user) + created = TalkMessages.objects.create(text=message,talk=talk,user=user,subject=subject,image=image) + return JsonResponse({"message":"ok"}) + + def get_context_data(self, **kwargs): + context = super(SendMessage,self).get_context_data() + context["filelink"] = get_object_or_404(FileLink, slug=self.kwargs.get('slug', '')) + return context + diff --git a/topics/templates/resources/list.html b/topics/templates/resources/list.html index 4615debdf..6ed93e517 100644 --- a/topics/templates/resources/list.html +++ b/topics/templates/resources/list.html @@ -29,7 +29,9 @@