Commit 5a03be71c7acc5961f3b22817857f4e484288803
1 parent
df993ff8
Exists in
master
and in
2 other branches
Ordenating mural categories and subjects per name and unviewed messages
Showing
1 changed file
with
4 additions
and
4 deletions
Show diff stats
mural/views.py
... | ... | @@ -350,9 +350,9 @@ class CategoryIndex(LoginRequiredMixin, generic.ListView): |
350 | 350 | user = self.request.user |
351 | 351 | |
352 | 352 | if user.is_staff: |
353 | - categories = Category.objects.all() | |
353 | + categories = Category.objects.extra(select = {"has_message": "select 1 FROM mural_muralvisualizations AS visul LEFT JOIN mural_categorypost AS post ON visul.post_id = post.mural_ptr_id LEFT JOIN mural_comment AS com ON visul.comment_id = com.id LEFT JOIN mural_categorypost AS post2 ON com.post_id = post2.mural_ptr_id WHERE visul.viewed = FALSE AND visul.user_id = %s AND (post.space_id = categories_category.id OR post2.space_id = categories_category.id) LIMIT 1"}, select_params = (user.id, )).order_by('has_message', 'name') | |
354 | 354 | else: |
355 | - categories = Category.objects.filter(Q(coordinators__pk = user.pk) | Q(subject_category__professor__pk = user.pk) | Q(subject_category__students__pk = user.pk, visible = True)).distinct() | |
355 | + categories = Category.objects.extra(select = {"has_message": "select 1 FROM mural_muralvisualizations AS visul LEFT JOIN mural_categorypost AS post ON visul.post_id = post.mural_ptr_id LEFT JOIN mural_comment AS com ON visul.comment_id = com.id LEFT JOIN mural_categorypost AS post2 ON com.post_id = post2.mural_ptr_id WHERE visul.viewed = FALSE AND visul.user_id = %s AND (post.space_id = categories_category.id OR post2.space_id = categories_category.id) LIMIT 1"}, select_params = (user.id, )).filter(Q(coordinators__pk = user.pk) | Q(subject_category__professor__pk = user.pk) | Q(subject_category__students__pk = user.pk, visible = True)).distinct().order_by('has_message', 'name') | |
356 | 356 | |
357 | 357 | self.totals['general'] = MuralVisualizations.objects.filter(Q(user = user) & Q(viewed = False) & (Q(post__generalpost__isnull = False) | Q(comment__post__generalpost__isnull = False))).distinct().count() |
358 | 358 | self.totals['category'] = MuralVisualizations.objects.filter(Q(user = user) & Q(viewed = False) & ((Q(user__is_staff = True) & (Q(post__categorypost__isnull = False) | Q(comment__post__categorypost__isnull = False))) | Q(post__categorypost__space__coordinators = user) | Q(comment__post__categorypost__space__coordinators = user) | Q(post__categorypost__space__subject_category__students = user) | Q(comment__post__categorypost__space__subject_category__students = user) | Q(post__categorypost__space__subject_category__professor = user) | Q(comment__post__categorypost__space__subject_category__professor = user))).distinct().count() |
... | ... | @@ -639,9 +639,9 @@ class SubjectIndex(LoginRequiredMixin, generic.ListView): |
639 | 639 | user = self.request.user |
640 | 640 | |
641 | 641 | if user.is_staff: |
642 | - subjects = Subject.objects.all() | |
642 | + subjects = Subject.objects.extra(select = {"has_message": "select 1 FROM mural_muralvisualizations AS visul LEFT JOIN mural_subjectpost AS post ON visul.post_id = post.mural_ptr_id LEFT JOIN mural_comment AS com ON visul.comment_id = com.id LEFT JOIN mural_subjectpost AS post2 ON com.post_id = post2.mural_ptr_id WHERE visul.viewed = FALSE AND visul.user_id = %s AND (post.space_id = subjects_subject.id OR post2.space_id = subjects_subject.id) LIMIT 1"}, select_params = (user.id, )).order_by('has_message', 'name') | |
643 | 643 | else: |
644 | - subjects = Subject.objects.filter(Q(category__coordinators__pk = user.pk) | Q(professor__pk = user.pk) | Q(students__pk = user.pk, visible = True)).distinct() | |
644 | + subjects = Subject.objects.extra(select = {"has_message": "select 1 FROM mural_muralvisualizations AS visul LEFT JOIN mural_subjectpost AS post ON visul.post_id = post.mural_ptr_id LEFT JOIN mural_comment AS com ON visul.comment_id = com.id LEFT JOIN mural_subjectpost AS post2 ON com.post_id = post2.mural_ptr_id WHERE visul.viewed = FALSE AND visul.user_id = %s AND (post.space_id = subjects_subject.id OR post2.space_id = subjects_subject.id) LIMIT 1"}, select_params = (user.id, )).filter(Q(category__coordinators__pk = user.pk) | Q(professor__pk = user.pk) | Q(students__pk = user.pk, visible = True)).distinct().order_by('has_message', 'name') | |
645 | 645 | |
646 | 646 | self.totals['general'] = MuralVisualizations.objects.filter(Q(user = user) & Q(viewed = False) & (Q(post__generalpost__isnull = False) | Q(comment__post__generalpost__isnull = False))).distinct().count() |
647 | 647 | self.totals['category'] = MuralVisualizations.objects.filter(Q(user = user) & Q(viewed = False) & ((Q(user__is_staff = True) & (Q(post__categorypost__isnull = False) | Q(comment__post__categorypost__isnull = False))) | Q(post__categorypost__space__coordinators = user) | Q(comment__post__categorypost__space__coordinators = user) | Q(post__categorypost__space__subject_category__students = user) | Q(comment__post__categorypost__space__subject_category__students = user) | Q(post__categorypost__space__subject_category__professor = user) | Q(comment__post__categorypost__space__subject_category__professor = user))).distinct().count() | ... | ... |