Commit 76adb8d303bc6df60ec6d5e2720e68712e8b71eb
1 parent
4dfef5e3
Exists in
master
and in
3 other branches
Updating subjects query
Showing
3 changed files
with
17 additions
and
4 deletions
Show diff stats
subjects/templates/subjects/list.html
@@ -55,7 +55,13 @@ | @@ -55,7 +55,13 @@ | ||
55 | <div class="col-md-12 category-header"> | 55 | <div class="col-md-12 category-header"> |
56 | <h4 class="panel-title"> | 56 | <h4 class="panel-title"> |
57 | <a class="category-course-link pull-left" data-parent="#accordion" data-toggle="collapse" href="#{{category.slug}}"> | 57 | <a class="category-course-link pull-left" data-parent="#accordion" data-toggle="collapse" href="#{{category.slug}}"> |
58 | - <button class="btn btn-default btn-xs text-center cat-selector"><i class="fa fa-angle-right fa-2x" aria-hidden="true"></i></button> {{ category.name }} ({{ category|subject_count:user }}) | 58 | + <button class="btn btn-default btn-xs text-center cat-selector"><i class="fa fa-angle-right fa-2x" aria-hidden="true"></i></button> {{ category.name }} |
59 | + | ||
60 | + {% if not all %} | ||
61 | + ({{ category|subject_count:user }}) | ||
62 | + {% else %} | ||
63 | + ({{ category.subject_category.count }}) | ||
64 | + {% endif %} | ||
59 | </a> | 65 | </a> |
60 | </h4> | 66 | </h4> |
61 | 67 | ||
@@ -114,7 +120,13 @@ | @@ -114,7 +120,13 @@ | ||
114 | <div class="col-md-12 category-header"> | 120 | <div class="col-md-12 category-header"> |
115 | <h4 class="panel-title"> | 121 | <h4 class="panel-title"> |
116 | <a class="category-course-link pull-left" data-parent="#accordion" data-toggle="collapse" href="#{{category.slug}}"> | 122 | <a class="category-course-link pull-left" data-parent="#accordion" data-toggle="collapse" href="#{{category.slug}}"> |
117 | - <button class="btn btn-default btn-xs text-center cat-selector"><i class="fa fa-angle-right fa-2x" aria-hidden="true"></i></button> {{category.name}} ({{ category|subject_count:user }}) | 123 | + <button class="btn btn-default btn-xs text-center cat-selector"><i class="fa fa-angle-right fa-2x" aria-hidden="true"></i></button> {{category.name}} |
124 | + | ||
125 | + {% if not all %} | ||
126 | + ({{ category|subject_count:user }}) | ||
127 | + {% else %} | ||
128 | + ({{ category.subject_category.count }}) | ||
129 | + {% endif %} | ||
118 | </a> | 130 | </a> |
119 | </h4> | 131 | </h4> |
120 | 132 |
subjects/utils.py
@@ -2,14 +2,14 @@ | @@ -2,14 +2,14 @@ | ||
2 | 2 | ||
3 | def has_student_profile(user, category): | 3 | def has_student_profile(user, category): |
4 | for subject in category.subject_category.all(): | 4 | for subject in category.subject_category.all(): |
5 | - if user in subject.students.all(): | 5 | + if user in subject.students.all() and subject.visible: |
6 | return True | 6 | return True |
7 | 7 | ||
8 | return False | 8 | return False |
9 | 9 | ||
10 | def has_professor_profile(user, category): | 10 | def has_professor_profile(user, category): |
11 | for subject in category.subject_category.all(): | 11 | for subject in category.subject_category.all(): |
12 | - if user in subject.professor.all(): | 12 | + if user in subject.professor.all() and subject.visible: |
13 | return True | 13 | return True |
14 | 14 | ||
15 | return False | 15 | return False |
subjects/views.py
@@ -72,6 +72,7 @@ class IndexView(LoginRequiredMixin, ListView): | @@ -72,6 +72,7 @@ class IndexView(LoginRequiredMixin, ListView): | ||
72 | 72 | ||
73 | def get_queryset(self): | 73 | def get_queryset(self): |
74 | categories = Category.objects.all().order_by('name') | 74 | categories = Category.objects.all().order_by('name') |
75 | + categories = [category for category in categories if self.request.user.is_staff or self.request.user in category.coordinators.all() or category.visible] | ||
75 | 76 | ||
76 | self.totals['all_subjects'] = count_subjects(categories, self.request.user) | 77 | self.totals['all_subjects'] = count_subjects(categories, self.request.user) |
77 | self.totals['my_subjects'] = self.totals['all_subjects'] | 78 | self.totals['my_subjects'] = self.totals['all_subjects'] |