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 | 55 | <div class="col-md-12 category-header"> |
56 | 56 | <h4 class="panel-title"> |
57 | 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 | 65 | </a> |
60 | 66 | </h4> |
61 | 67 | |
... | ... | @@ -114,7 +120,13 @@ |
114 | 120 | <div class="col-md-12 category-header"> |
115 | 121 | <h4 class="panel-title"> |
116 | 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 | 130 | </a> |
119 | 131 | </h4> |
120 | 132 | ... | ... |
subjects/utils.py
... | ... | @@ -2,14 +2,14 @@ |
2 | 2 | |
3 | 3 | def has_student_profile(user, category): |
4 | 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 | 6 | return True |
7 | 7 | |
8 | 8 | return False |
9 | 9 | |
10 | 10 | def has_professor_profile(user, category): |
11 | 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 | 13 | return True |
14 | 14 | |
15 | 15 | return False | ... | ... |
subjects/views.py
... | ... | @@ -72,6 +72,7 @@ class IndexView(LoginRequiredMixin, ListView): |
72 | 72 | |
73 | 73 | def get_queryset(self): |
74 | 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 | 77 | self.totals['all_subjects'] = count_subjects(categories, self.request.user) |
77 | 78 | self.totals['my_subjects'] = self.totals['all_subjects'] | ... | ... |