Commit 502256a8ba0f0c9dfad3c233224f2b237f0f0d20
1 parent
1cdb1240
Exists in
master
and in
3 other branches
added safety check for no errors in code and ordered data report
Showing
3 changed files
with
32 additions
and
22 deletions
Show diff stats
reports/forms.py
... | ... | @@ -11,6 +11,7 @@ class BaseResourceAndTagFormset(BaseFormSet): |
11 | 11 | Adds validation to check that no two links have the same anchor or URL |
12 | 12 | and that all links have both an anchor and URL. |
13 | 13 | """ |
14 | + print(self.errors) | |
14 | 15 | if any(self.errors): |
15 | 16 | return |
16 | 17 | |
... | ... | @@ -26,8 +27,9 @@ class ResourceAndTagForm(forms.Form): |
26 | 27 | super(ResourceAndTagForm, self).__init__(*args, **kwargs) |
27 | 28 | if kwargs.get('initial'): |
28 | 29 | initial = kwargs['initial'] |
29 | - self.fields['resource'].choices = [(classes.__name__, classes.__name__) for classes in initial['class_name']] | |
30 | + self.fields['resource'].choices = [(classes.__name__.lower(), classes.__name__.lower()) for classes in initial['class_name']] | |
30 | 31 | self.fields['tag'].choices = [(tag.id, tag.name) for tag in initial['tag']] |
32 | + | |
31 | 33 | |
32 | 34 | |
33 | 35 | class CreateInteractionReportForm(forms.Form): | ... | ... |
reports/templates/reports/create.html
... | ... | @@ -89,5 +89,7 @@ |
89 | 89 | }); |
90 | 90 | |
91 | 91 | $('.resource-tag-formset').remove(); //I remove the element so there is no empty form with no data, I can't override this behavior on the previous function call |
92 | + | |
93 | + $('#id_form-TOTAL_FORMS')[0].value = 0; | |
92 | 94 | </script> |
93 | 95 | {% endblock content %} |
94 | 96 | \ No newline at end of file | ... | ... |
reports/views.py
... | ... | @@ -16,7 +16,7 @@ from subjects.models import Subject, Tag |
16 | 16 | from .forms import CreateInteractionReportForm, ResourceAndTagForm, BaseResourceAndTagFormset |
17 | 17 | from log.models import Log |
18 | 18 | from topics.models import Resource, Topic |
19 | - | |
19 | +from collections import OrderedDict | |
20 | 20 | from django.forms import formset_factory |
21 | 21 | |
22 | 22 | class ReportView(LoginRequiredMixin, generic.FormView): |
... | ... | @@ -130,10 +130,13 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): |
130 | 130 | context['init_date'] = params_data['init_date'] |
131 | 131 | context['end_date'] = params_data['end_date'] |
132 | 132 | context['subject'] = subject |
133 | + | |
134 | + resources = params_data.getlist('resource') | |
135 | + tags = params_data.getlist('tag') | |
133 | 136 | if params_data['from_mural']: |
134 | 137 | #I used getlist method so it can get more than one tag and one resource class_name |
135 | 138 | context['data'], context['header'] = self.get_mural_data(subject, params_data['init_date'], params_data['end_date'], |
136 | - params_data.getlist('resource'), params_data.getlist('tag')) | |
139 | + resources, tags ) | |
137 | 140 | return context |
138 | 141 | |
139 | 142 | def get_mural_data(self, subject, init_date, end_date, resources_id, tags_id): |
... | ... | @@ -155,40 +158,40 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): |
155 | 158 | |
156 | 159 | data[student].append(student.social_name) |
157 | 160 | |
158 | - interactions = {} | |
161 | + interactions = OrderedDict() | |
159 | 162 | #interactions['username'] = student.social_name |
160 | 163 | |
161 | 164 | help_posts_made_by_user = SubjectPost.objects.filter(action="help",space__id=subject.id, user=student, |
162 | 165 | create_date__range=(init_date, end_date)) |
163 | 166 | |
164 | 167 | #number of help posts created by the student |
165 | - interactions['number of help posts created by the user'] = help_posts_made_by_user.count() | |
168 | + interactions[_('Number of help posts created by the user.')] = help_posts_made_by_user.count() | |
166 | 169 | |
167 | 170 | help_posts = SubjectPost.objects.filter(action="help", create_date__range=(init_date, end_date), |
168 | 171 | space__id=subject.id) |
169 | 172 | |
170 | 173 | #comments count on help posts created by the student |
171 | - interactions['amount of comments on help posts created by the student'] = Comment.objects.filter(post__in = help_posts.filter(user=student), | |
174 | + interactions[_('Amount of comments on help posts created by the student.')] = Comment.objects.filter(post__in = help_posts.filter(user=student), | |
172 | 175 | create_date__range=(init_date, end_date)).count() |
173 | 176 | |
174 | 177 | |
175 | 178 | #count the amount of comments made by the student on posts made by one of the professors |
176 | - 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), | |
179 | + 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), | |
177 | 180 | user=student).count() |
178 | 181 | |
179 | 182 | #comments made by the user on other users posts |
180 | - interactions['amount of comments made by the student on other students help posts'] = Comment.objects.filter(post__in = help_posts.exclude(user=student), | |
183 | + interactions[_('Amount of comments made by the student on other students help posts.')] = Comment.objects.filter(post__in = help_posts.exclude(user=student), | |
181 | 184 | create_date__range=(init_date, end_date), |
182 | 185 | user= student).count() |
183 | 186 | |
184 | 187 | |
185 | - | |
188 | + | |
186 | 189 | comments_by_teacher = Comment.objects.filter(user__in=subject.professor.all()) |
187 | 190 | help_posts_ids = [] |
188 | 191 | for comment in comments_by_teacher: |
189 | 192 | help_posts_ids.append(comment.post.id) |
190 | 193 | #number of help posts created by the user that the teacher commented on |
191 | - 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() | |
194 | + 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() | |
192 | 195 | |
193 | 196 | |
194 | 197 | comments_by_others = Comment.objects.filter(user__in=subject.students.exclude(id = student.id)) |
... | ... | @@ -196,30 +199,33 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): |
196 | 199 | for comment in comments_by_teacher: |
197 | 200 | help_posts_ids.append(comment.post.id) |
198 | 201 | #number of help posts created by the user others students commented on |
199 | - interactions['number of help posts created by the user others students commented on'] = help_posts.filter(user=student, id__in = help_posts_ids).count() | |
202 | + interactions[_('Number of help posts created by the user others students commented on.')] = help_posts.filter(user=student, id__in = help_posts_ids).count() | |
200 | 203 | |
201 | 204 | #Number of student visualizations on the mural of the subject |
202 | - interactions['Number of student visualizations on the mural of the subject'] = MuralVisualizations.objects.filter(post__in = SubjectPost.objects.filter(space__id=subject.id), | |
205 | + interactions[_('Number of student visualizations on the mural of the subject.')] = MuralVisualizations.objects.filter(post__in = SubjectPost.objects.filter(space__id=subject.id), | |
203 | 206 | user = student).count() |
204 | 207 | |
205 | 208 | |
206 | 209 | #VAR08 through VAR_019 of documenttation: |
207 | - resources_data = self.get_resources_and_tags_data(resources_id, tags_id, student, subject) | |
210 | + if len(resources_id) > 0: | |
211 | + resources_data = self.get_resources_and_tags_data(resources_id, tags_id, student, subject) | |
212 | + for key, value in resources_data.items(): | |
213 | + interactions[key] = value | |
214 | + | |
208 | 215 | |
209 | - interactions = {**interactions, **resources_data} | |
210 | 216 | #VAR20 - number of access to mural between 6 a.m to 12a.m. |
211 | - interactions[' number of access to mural between 6 a.m to 12a.m.'] = Log.objects.filter(action="access", resource="subject", | |
217 | + interactions[_('Number of access to mural between 6 a.m to 12a.m. .')] = Log.objects.filter(action="access", resource="subject", | |
212 | 218 | user_id= student.id, context__contains = {'subject_id' : subject.id}, datetime__hour__range = (5, 11)).count() |
213 | 219 | |
214 | 220 | #VAR21 - number of access to mural between 0 p.m to 6p.m. |
215 | - interactions['number of access to mural between 0 p.m to 6p.m.'] = Log.objects.filter(action="access", resource="subject", | |
221 | + interactions[_('Number of access to mural between 0 p.m to 6p.m. .')] = Log.objects.filter(action="access", resource="subject", | |
216 | 222 | user_id= student.id, context__contains = {'subject_id' : subject.id}, datetime__hour__range = (11, 17)).count() |
217 | 223 | #VAR22 |
218 | - interactions['number of access to mural between 6 p.m to 12p.m.'] = Log.objects.filter(action="access", resource="subject", | |
224 | + interactions[_('Number of access to mural between 6 p.m to 12p.m. .')] = Log.objects.filter(action="access", resource="subject", | |
219 | 225 | user_id= student.id, context__contains = {'subject_id' : subject.id}, datetime__hour__range = (17, 23)).count() |
220 | 226 | |
221 | 227 | #VAR23 |
222 | - interactions['number of access to mural between 0 a.m to 6a.m.'] = Log.objects.filter(action="access", resource="subject", | |
228 | + interactions[_('Number of access to mural between 0 a.m to 6a.m. .')] = Log.objects.filter(action="access", resource="subject", | |
223 | 229 | user_id= student.id, context__contains = {'subject_id' : subject.id}, datetime__hour__range = (23, 5)).count() |
224 | 230 | |
225 | 231 | #VAR24 through 30 |
... | ... | @@ -227,13 +233,13 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): |
227 | 233 | day_names = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"] |
228 | 234 | distinct_days = 0 |
229 | 235 | for day_num in day_numbers: |
230 | - interactions['number of access to the subject on '+ day_names[day_num]] = Log.objects.filter(action="access", resource="subject", | |
236 | + interactions['Number of access to the subject on '+ day_names[day_num]] = Log.objects.filter(action="access", resource="subject", | |
231 | 237 | user_id= student.id, context__contains = {'subject_id' : subject.id}, datetime__week_day = day_num).count() |
232 | 238 | #to save the distinct days the user has accessed |
233 | - if interactions['number of access to the subject on '+ day_names[day_num]] > 0: | |
239 | + if interactions['Number of access to the subject on '+ day_names[day_num]] > 0: | |
234 | 240 | distinct_days += 1 |
235 | 241 | |
236 | - interactions['number of distinct days the user access the subject'] = distinct_days | |
242 | + interactions[_('Number of distinct days the user access the subject')] = distinct_days | |
237 | 243 | |
238 | 244 | for value in interactions.values(): |
239 | 245 | data[student].append(value) |
... | ... | @@ -263,7 +269,7 @@ def get_resources(request): |
263 | 269 | |
264 | 270 | data = {} |
265 | 271 | subject = Subject.objects.get(id=request.GET['subject_id']) |
266 | - | |
272 | + | |
267 | 273 | topic_choice = request.GET["topic_choice"] |
268 | 274 | if topic_choice.lower() == "all": |
269 | 275 | topics = subject.topic_subject.all() | ... | ... |