Browse Source

simplified posts query some

Rafał Pitoń 9 years ago
parent
commit
254b80ebbe
1 changed files with 8 additions and 14 deletions
  1. 8 14
      misago/threads/permissions/threads.py

+ 8 - 14
misago/threads/permissions/threads.py

@@ -856,19 +856,13 @@ def exclude_invisible_threads(user, categories, queryset):
 
 
 def exclude_invisible_posts(user, category, queryset):
-    if category.acl['can_hide_events'] and category.acl['can_approve_content']:
-        return queryset # don't do extra filtering for posts
-
-    if category.acl['can_approve_content']:
-        visible_posts = Q(is_event=False)
-    elif user.is_authenticated():
-        visible_posts = Q(is_event=False) & (Q(poster_id=user.id) | Q(is_unapproved=False))
-    else:
-        visible_posts = Q(is_event=False) & Q(is_unapproved=False)
+    if not category.acl['can_approve_content']:
+        if user.is_authenticated():
+            queryset = queryset.filter(Q(is_unapproved=False) | Q(poster=user))
+        else:
+            queryset = queryset.exclude(is_unapproved=True)
 
-    if category.acl['can_hide_events']:
-        visible_events = Q(is_event=True)
-    else:
-        visible_events = Q(is_event=True) & Q(is_hidden=False)
+    if not category.acl['can_hide_events']:
+        queryset = queryset.exclude(is_event=True, is_hidden=True)
 
-    return queryset.filter(visible_posts | visible_events)
+    return queryset