From 8d82a1f92eb096559f1932c248ad4501b57c6607 Mon Sep 17 00:00:00 2001 From: fbormann Date: Fri, 10 Mar 2017 19:43:21 -0300 Subject: [PATCH] made progress on template using formsets, still has to send data through URL to the other view and find a good way to select resources dynamically --- reports/forms.py | 14 +++++++++++--- reports/static/reports/js/report.js | 5 +++++ reports/templates/reports/_form.html | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------- reports/templates/reports/create.html | 14 +++++++++++++- reports/templates/reports/view.html | 10 +++------- reports/views.py | 53 ++++++++++++++++++++++++++++++++++++++--------------- 6 files changed, 132 insertions(+), 49 deletions(-) create mode 100644 reports/static/reports/js/report.js diff --git a/reports/forms.py b/reports/forms.py index 4287293..8ce3093 100644 --- a/reports/forms.py +++ b/reports/forms.py @@ -2,6 +2,13 @@ from django import forms from django.utils.translation import ugettext_lazy as _ import datetime +from django.forms.formsets import BaseFormSet + +class ResourceAndTagForm(forms.Form): + + resource = forms.ChoiceField(label=_("Resources"), required=True) + tag = forms.ChoiceField(label=_('Tag')) + class CreateInteractionReportForm(forms.Form): @@ -17,13 +24,14 @@ class CreateInteractionReportForm(forms.Form): def __init__(self, *args, **kwargs): super(CreateInteractionReportForm, self).__init__(*args, **kwargs) - initial = kwargs['initial'] topics = list(initial['topic']) self.subject = initial['subject'] #so we can check date cleaned data self.fields['topic'].choices = [(topic.id, topic.name) for topic in topics] self.fields['topic'].choices.append((_("All"), _("All"))) + + def clean_init_date(self): init_date = self.cleaned_data.get('init_date') if init_date < self.subject.init_date: @@ -32,6 +40,6 @@ class CreateInteractionReportForm(forms.Form): def clean_end_date(self): end_date = self.cleaned_data.get('init_date') - if end_date > self.subject.init_date: - self._errors['end_date'] = [_('This date should be right or before ' + str(self.subject.init_date) + ', which is when the subject finishes. ')] + if end_date > self.subject.end_date: + self._errors['end_date'] = [_('This date should be right or before ' + str(self.subject.end_date) + ', which is when the subject finishes. ')] return end_date \ No newline at end of file diff --git a/reports/static/reports/js/report.js b/reports/static/reports/js/report.js new file mode 100644 index 0000000..c8b4f52 --- /dev/null +++ b/reports/static/reports/js/report.js @@ -0,0 +1,5 @@ + +//Function to get all resources of all topics related to that subjct +$(function (){ + +}); \ No newline at end of file diff --git a/reports/templates/reports/_form.html b/reports/templates/reports/_form.html index 66355c8..8fe22d3 100644 --- a/reports/templates/reports/_form.html +++ b/reports/templates/reports/_form.html @@ -1,33 +1,72 @@ {% load widget_tweaks static i18n %}
{% csrf_token %} +

{% trans "General Parameters" %}


{% for field in form %} - {% if field.auto_id == 'id_init_date' or field.auto_id == 'id_end_date' %} - - {% render_field field class='form-control date-picker' %} - - {% else %} - - {% render_field field class='form-control' %} - {% endif %} - - {% if field.errors %} -
-
- -
+ {% if field.auto_id == 'id_init_date' or field.auto_id == 'id_end_date' %} + + {% render_field field class='form-control date-picker' %} + + + {% elif field.auto_id == 'id_from_mural' %} +

{% trans "Data Source" %}


+ + {% render_field field class='form-control' %} + {% else %} + + {% render_field field class='form-control' %} {% endif %} + + {% if field.errors %} +
+
+ +
+ {% endif %} {% endfor %} + + +
+
+ + +
+ {{ resource_tag_formset.management_form }} + + {% for resource_tag_form in resource_tag_formset %} +
+ {% for field in resource_tag_form %} + + {% render_field field class="form-control" %} + {% endfor %} +
+ {% endfor %} +
+
+
+
+ + diff --git a/reports/templates/reports/create.html b/reports/templates/reports/create.html index a053ae5..710b476 100644 --- a/reports/templates/reports/create.html +++ b/reports/templates/reports/create.html @@ -11,6 +11,12 @@ {% breadcrumb 'analytics' '' %} {% endblock %} +{% block javascript %} + {{block.super}} + + +{% endblock javascript %} + {% block content %}
@@ -41,5 +47,11 @@ {% include "reports/_form.html" %} - + + {% endblock content %} \ No newline at end of file diff --git a/reports/templates/reports/view.html b/reports/templates/reports/view.html index 38c3654..ee83f7b 100644 --- a/reports/templates/reports/view.html +++ b/reports/templates/reports/view.html @@ -6,9 +6,9 @@ {% block breadcrumbs %} {{ block.super }} - {% breadcrumb view.subject.category 'subjects:cat_view' view.subject.category.slug %} - {% breadcrumb view.subject 'subjects:view' view.subject.slug %} - {% breadcrumb 'analytics' '' %} + {% breadcrumb subject.category 'subjects:cat_view' subject.category.slug %} + {% breadcrumb subject 'subjects:view' subject.slug %} + {% breadcrumb 'Analytics' '' %} {% endblock %} {% block content %} @@ -65,10 +65,6 @@ diff --git a/reports/views.py b/reports/views.py index 1c58ed7..f66f10b 100644 --- a/reports/views.py +++ b/reports/views.py @@ -13,9 +13,11 @@ from django.db.models import Q from django.contrib.auth.mixins import LoginRequiredMixin from datetime import datetime, date from subjects.models import Subject -from .forms import CreateInteractionReportForm +from .forms import CreateInteractionReportForm, ResourceAndTagForm from log.models import Log +from topics.models import Resource +from django.forms import formset_factory class ReportView(LoginRequiredMixin, generic.FormView): template_name = "reports/create.html" @@ -40,7 +42,24 @@ class ReportView(LoginRequiredMixin, generic.FormView): subject = Subject.objects.get(id=self.request.GET['subject_id']) context['subject'] = subject + + topics = subject.topic_subject.all() + #get all resources associated with topics + resources = [] + tags = [] + for topic in topics: + resources_set = topic.resource_topic.all() + for resource in resources_set: + for tag in resource.tags.all(): + tags.append(tag) + resources.append(resource) + context['resources'] = resources + context['tags'] = tags + + #set formset + resourceTagFormSet = formset_factory(ResourceAndTagForm, extra= 1) + context['resource_tag_formset'] = resourceTagFormSet return context def get_success_url(self): @@ -65,8 +84,9 @@ class ReportView(LoginRequiredMixin, generic.FormView): POST variables and then checked for validity. """ form = self.get_form() + print(form) if form.is_valid(): - + print(form) self.form_data = form.cleaned_data return self.form_valid(form) else: @@ -86,6 +106,8 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): context['init_date'] = params_data['init_date'] context['end_date'] = params_data['end_date'] context['subject'] = subject + + if params_data['from_mural']: context['data'], context['header'] = self.get_mural_data(subject, params_data['init_date'], params_data['end_date']) return context @@ -115,22 +137,22 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): create_date__range=(init_date, end_date)) #number of help posts created by the student - interactions['v01'] = help_posts_made_by_user.count() + interactions['number of help posts created by the user'] = help_posts_made_by_user.count() help_posts = SubjectPost.objects.filter(action="help", create_date__range=(init_date, end_date), space__id=subject.id) #comments count on help posts created by the student - interactions['v02'] = Comment.objects.filter(post__in = help_posts.filter(user=student), + interactions['amount of comments on help posts created by the student'] = Comment.objects.filter(post__in = help_posts.filter(user=student), create_date__range=(init_date, end_date)).count() #count the amount of comments made by the student on posts made by one of the professors - interactions['v03'] = Comment.objects.filter(post__in = help_posts.filter(user__in= subject.professor.all()), create_date__range=(init_date, end_date), + interactions['amount of comments made by the student on teachers help posts'] = Comment.objects.filter(post__in = help_posts.filter(user__in= subject.professor.all()), create_date__range=(init_date, end_date), user=student).count() #comments made by the user on other users posts - interactions['v04'] = Comment.objects.filter(post__in = help_posts.exclude(user=student), + interactions['amount of comments made by the student on other students help posts'] = Comment.objects.filter(post__in = help_posts.exclude(user=student), create_date__range=(init_date, end_date), user= student).count() @@ -141,7 +163,7 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): for comment in comments_by_teacher: help_posts_ids.append(comment.post.id) #number of help posts created by the user that the teacher commented on - interactions['v05'] = help_posts.filter(user=student, id__in = help_posts_ids).count() + interactions['Number of help posts created by the user that the teacher commented on'] = help_posts.filter(user=student, id__in = help_posts_ids).count() comments_by_others = Comment.objects.filter(user__in=subject.students.exclude(id = student.id)) @@ -149,33 +171,33 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): for comment in comments_by_teacher: help_posts_ids.append(comment.post.id) #number of help posts created by the user others students commented on - interactions['v06'] = help_posts.filter(user=student, id__in = help_posts_ids).count() + interactions['number of help posts created by the user others students commented on'] = help_posts.filter(user=student, id__in = help_posts_ids).count() #Number of student visualizations on the mural of the subject - interactions['v07'] = MuralVisualizations.objects.filter(post__in = SubjectPost.objects.filter(space__id=subject.id), + interactions['Number of student visualizations on the mural of the subject'] = MuralVisualizations.objects.filter(post__in = SubjectPost.objects.filter(space__id=subject.id), user = student).count() #VAR20 - number of access to mural between 6 a.m to 12a.m. - interactions['v20'] = Log.objects.filter(action="access", resource="subject", + interactions[' number of access to mural between 6 a.m to 12a.m.'] = Log.objects.filter(action="access", resource="subject", user_id= student.id, context__contains = {'subject_id' : subject.id}, datetime__hour__range = (5, 11)).count() - #VAR21 - number of access to mural between 6 a.m to 12a.m. - interactions['v21'] = Log.objects.filter(action="access", resource="subject", + #VAR21 - number of access to mural between 0 p.m to 6p.m. + interactions['number of access to mural between 0 p.m to 6p.m.'] = Log.objects.filter(action="access", resource="subject", user_id= student.id, context__contains = {'subject_id' : subject.id}, datetime__hour__range = (11, 17)).count() #VAR22 - interactions['v22'] = Log.objects.filter(action="access", resource="subject", + interactions[' number of access to mural between 6 p.m to 12p.m.'] = Log.objects.filter(action="access", resource="subject", user_id= student.id, context__contains = {'subject_id' : subject.id}, datetime__hour__range = (17, 23)).count() #VAR23 - interactions['v23'] = Log.objects.filter(action="access", resource="subject", + interactions[' number of access to mural between 0 a.m to 6a.m.'] = Log.objects.filter(action="access", resource="subject", user_id= student.id, context__contains = {'subject_id' : subject.id}, datetime__hour__range = (23, 5)).count() #VAR24 through 30 day_numbers = [0, 1, 2, 3, 4, 5, 6] day_names = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"] for day_num in day_numbers: - interactions['v'+ str(24+day_num)] = Log.objects.filter(action="access", resource="subject", + interactions['number of access to the subject on '+ day_names[day_num]] = Log.objects.filter(action="access", resource="subject", user_id= student.id, context__contains = {'subject_id' : subject.id}, datetime__week_day = day_num).count() for value in interactions.values(): @@ -185,3 +207,4 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): header.append(key) return data, header + -- libgit2 0.21.2