From 76adb8d303bc6df60ec6d5e2720e68712e8b71eb Mon Sep 17 00:00:00 2001 From: Zambom Date: Fri, 13 Jan 2017 17:46:50 -0200 Subject: [PATCH] Updating subjects query --- subjects/templates/subjects/list.html | 16 ++++++++++++++-- subjects/utils.py | 4 ++-- subjects/views.py | 1 + 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/subjects/templates/subjects/list.html b/subjects/templates/subjects/list.html index 8dc1d4f..53dbd63 100644 --- a/subjects/templates/subjects/list.html +++ b/subjects/templates/subjects/list.html @@ -55,7 +55,13 @@

- {{ category.name }} ({{ category|subject_count:user }}) + {{ category.name }} + + {% if not all %} + ({{ category|subject_count:user }}) + {% else %} + ({{ category.subject_category.count }}) + {% endif %}

@@ -114,7 +120,13 @@

- {{category.name}} ({{ category|subject_count:user }}) + {{category.name}} + + {% if not all %} + ({{ category|subject_count:user }}) + {% else %} + ({{ category.subject_category.count }}) + {% endif %}

diff --git a/subjects/utils.py b/subjects/utils.py index 4a984b3..c2532c8 100644 --- a/subjects/utils.py +++ b/subjects/utils.py @@ -2,14 +2,14 @@ def has_student_profile(user, category): for subject in category.subject_category.all(): - if user in subject.students.all(): + if user in subject.students.all() and subject.visible: return True return False def has_professor_profile(user, category): for subject in category.subject_category.all(): - if user in subject.professor.all(): + if user in subject.professor.all() and subject.visible: return True return False diff --git a/subjects/views.py b/subjects/views.py index 619ddd6..1d9773f 100644 --- a/subjects/views.py +++ b/subjects/views.py @@ -72,6 +72,7 @@ class IndexView(LoginRequiredMixin, ListView): def get_queryset(self): categories = Category.objects.all().order_by('name') + categories = [category for category in categories if self.request.user.is_staff or self.request.user in category.coordinators.all() or category.visible] self.totals['all_subjects'] = count_subjects(categories, self.request.user) self.totals['my_subjects'] = self.totals['all_subjects'] -- libgit2 0.21.2