Commit 71ad373dad5fe810e10d1e95c68464419d93e32d
1 parent
f231028d
Exists in
master
and in
3 other branches
non-optimal solution for resource count problem and error
Showing
2 changed files
with
7 additions
and
8 deletions
Show diff stats
subjects/templates/subjects/list_search.html
... | ... | @@ -71,10 +71,7 @@ |
71 | 71 | {% elif resources|length > 0 and all %} |
72 | 72 | <div class="panel-group" id="subject-accordion" role="tablist" aria-multiselectable="true"> |
73 | 73 | {% for resource in resources %} |
74 | - {% if request.user in resource.students.all or request.user in resource.topic.subject.category.coordinators.all or request.user.is_staff %} | |
75 | - {% include "subjects/resource_card.html" with resource=resource %} | |
76 | - {% endif %} | |
77 | - | |
74 | + {% include "subjects/resource_card.html" with resource=resource %} | |
78 | 75 | {% endfor %} |
79 | 76 | |
80 | 77 | {% pagination request paginator page_obj %} | ... | ... |
subjects/views.py
... | ... | @@ -30,7 +30,7 @@ from .utils import has_student_profile, has_professor_profile, count_subjects, g |
30 | 30 | from users.models import User |
31 | 31 | from topics.models import Resource |
32 | 32 | |
33 | -from amadeus.permissions import has_category_permissions, has_subject_permissions, has_subject_view_permissions | |
33 | +from amadeus.permissions import has_category_permissions, has_subject_permissions, has_subject_view_permissions, has_resource_permissions | |
34 | 34 | |
35 | 35 | class HomeView(LoginRequiredMixin, ListView): |
36 | 36 | login_url = reverse_lazy("users:login") |
... | ... | @@ -62,7 +62,7 @@ class HomeView(LoginRequiredMixin, ListView): |
62 | 62 | tags = Tag.objects.all() |
63 | 63 | tags_list = [] |
64 | 64 | for tag in tags: |
65 | - if Resource.objects.filter(tags__pk=tag.pk).count() > 0 and len(tags_list) <= tag_amount: | |
65 | + if Resource.objects.filter(tags__pk=tag.pk, students__pk = self.request.user.pk).count() > 0 and len(tags_list) <= tag_amount: | |
66 | 66 | tags_list.append((tag.name, Subject.objects.filter(tags__pk = tag.pk).count())) |
67 | 67 | tags_list.sort(key= lambda x: x[1], reverse=True) #sort by value |
68 | 68 | |
... | ... | @@ -567,8 +567,10 @@ class SubjectSearchView(LoginRequiredMixin, LogMixin, ListView): |
567 | 567 | q = q | Q(tags__name__unaccent__iexact=word ) |
568 | 568 | |
569 | 569 | subjects = Subject.objects.filter(q).distinct() |
570 | - self.resources = Resource.objects.select_related('link', 'filelink', 'webpage', 'ytvideo', 'pdffile').filter(q ).distinct() | |
571 | - | |
570 | + | |
571 | + self.resources = Resource.objects.select_related('link', 'filelink', 'webpage', 'ytvideo', 'pdffile').filter(q).distinct() | |
572 | + self.resources = [resource.id for resource in self.resources if has_resource_permissions(self.request.user, resource)] | |
573 | + self.resources = Resource.objects.select_related('link', 'filelink', 'webpage', 'ytvideo', 'pdffile').filter(id__in = self.resources) | |
572 | 574 | |
573 | 575 | self.totals = {'resources': self.resources.count(), 'my_subjects': subjects.count()} |
574 | 576 | ... | ... |