Commit f231028d9832551414bb6d108b54f4c188034340
1 parent
af667d86
Exists in
master
and in
3 other branches
only show tags of resources available to the user
Showing
1 changed file
with
3 additions
and
2 deletions
Show diff stats
subjects/views.py
... | ... | @@ -62,11 +62,11 @@ class HomeView(LoginRequiredMixin, ListView): |
62 | 62 | tags = Tag.objects.all() |
63 | 63 | tags_list = [] |
64 | 64 | for tag in tags: |
65 | - if len(tags_list) <= tag_amount: | |
65 | + if Resource.objects.filter(tags__pk=tag.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 | |
69 | - else: | |
69 | + elif len(tags_list) > tag_amount: | |
70 | 70 | count = Subject.objects.filter(tags__pk = tag.pk).count() |
71 | 71 | if count > tags_list[tag_amount][1]: |
72 | 72 | tags_list[tag_amount - 1] = (tag.name, count) |
... | ... | @@ -85,6 +85,7 @@ class HomeView(LoginRequiredMixin, ListView): |
85 | 85 | tags.append((item[0], 2)) |
86 | 86 | i += 1 |
87 | 87 | shuffle(tags) |
88 | + | |
88 | 89 | context['tags'] = tags |
89 | 90 | context['total_subs'] = self.total |
90 | 91 | ... | ... |