Skip to content
Browse files

Merge branch 'query_count_reduction' into fixes

  • Loading branch information...
2 parents 2f81f4f + 302fa5c commit 730d772cb5149f28df07d83b5d69416cd06e388f @spookylukey committed Jan 17, 2012
Showing with 9 additions and 25 deletions.
  1. +1 −1 fiber/context_processors.py
  2. +0 −17 fiber/managers.py
  3. +3 −1 fiber/models.py
  4. +5 −6 fiber/templatetags/fiber_tags.py
View
2 fiber/context_processors.py
@@ -63,7 +63,7 @@ def page_info(request):
Block access to pages that the current user isn't supposed to see.
"""
if page:
- if page not in Page.objects.public_for_user(request.user):
+ if not page.is_public_for_user(request.user):
page = None
"""
View
17 fiber/managers.py
@@ -82,23 +82,6 @@ def rename_markup(markup):
content_item.save()
-class PageManager(models.Manager):
-
- def public_for_user(self, user):
- public_pages_qs = self.get_query_set()
- if not user.is_staff:
- public_pages_qs = public_pages_qs.filter(is_public=True)
-
- return public_pages_qs
-
- def shown_in_menu_for_user(self, user):
- shown_in_menu_pages_qs = self.get_query_set()
- if not user.is_staff:
- shown_in_menu_pages_qs = shown_in_menu_pages_qs.filter(show_in_menu=True, is_public=True)
-
- return shown_in_menu_pages_qs
-
-
class PageContentItemManager(models.Manager):
def move(self, item, next_item=None, block_name=None):
View
4 fiber/models.py
@@ -86,7 +86,6 @@ class Page(MPTTModel):
content_items = models.ManyToManyField(ContentItem, through='PageContentItem', verbose_name=_('content items'))
metadata = JSONField(blank=True, null=True, schema=METADATA_PAGE_SCHEMA, prefill_from='fiber.models.Page')
- objects = managers.PageManager()
tree = TreeManager()
class Meta:
@@ -204,6 +203,9 @@ def move_page(self, parent_id, left_id=0):
if old_url != new_url:
ContentItem.objects.rename_url(old_url, new_url)
+ def is_public_for_user(self, user):
+ return user.is_staff or self.is_public
+
class PageContentItem(models.Model):
content_item = models.ForeignKey(ContentItem, related_name='page_content_items', verbose_name=_('content item'))
View
11 fiber/templatetags/fiber_tags.py
@@ -55,11 +55,10 @@ def show_menu(context, menu_name, min_level, max_level, expand=None):
elif expand == 'all':
menu_pages.extend(Page.objects.filter(tree_id=root_page.tree_id).filter(level__range=(min_level, max_level)))
- """
- Remove pages that shouldn't be shown in the menu for the current user.
- """
- shown_in_menu_for_user = Page.objects.shown_in_menu_for_user(context['user'])
- menu_pages = list(set(menu_pages) & set(shown_in_menu_for_user))
+ # Remove pages that shouldn't be shown in the menu for the current user.
+ user = context['user']
+ menu_pages = [p for p in menu_pages if (p.is_public_for_user(user)
+ and p.show_in_menu)]
"""
Order menu_pages for use with tree_info template tag.
@@ -133,7 +132,7 @@ def __init__(self, page, block_name):
def render(self, context):
try:
page = self.page.resolve(context)
- page_content_items = page.page_content_items.filter(block_name=self.block_name).order_by('sort')
+ page_content_items = page.page_content_items.filter(block_name=self.block_name).order_by('sort').select_related('content_item')
content_items = []
for page_content_item in page_content_items:

0 comments on commit 730d772

Please sign in to comment.
Something went wrong with that request. Please try again.