Skip to content

Commit

Permalink
#974 Sort the header menu (#976)
Browse files Browse the repository at this point in the history
* #974  Sort the top menu

* #974  Apply pdd rules
  • Loading branch information
duker33 authored Sep 30, 2019
1 parent 77991fd commit 4da0030
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
3 changes: 3 additions & 0 deletions shopelectro/logic/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import header

__all__ = ['header']
24 changes: 24 additions & 0 deletions shopelectro/logic/header.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from django.conf import settings
from django.db.models import Q

from pages import models as pages_models
from shopelectro import models


def menu_qs() -> pages_models.PageQuerySet:
return (
pages_models.Page.objects.active()
.filter(
Q(slug__in=settings.HEADER_LINKS['add'])
& ~Q(slug__in=settings.HEADER_LINKS['exclude'])
| (
# @todo #974:30m Optimize the header menu query.
# Fetch catalog page for the header menu at the same query.
# root category pages.
Q(parent=pages_models.CustomPage.objects.filter(slug='catalog'))
& Q(related_model_name=models.Category._meta.db_table)
& Q(parent=pages_models.CustomPage.objects.filter(slug='catalog'))
)
)
.order_by('position')
)
3 changes: 2 additions & 1 deletion shopelectro/templatetags/se_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@

from images.models import ImageMixin
from pages.models import Page

from shopelectro.models import CategoryPage

register = template.Library()


@register.simple_tag
def roots():
# @todo #974:60m Reuse the logic.header.menu_qs menu menu query.
# And test HEADER_LINKS "exclude/add" settings option.
return sorted(
chain(
Page.objects.filter(slug__in=settings.HEADER_LINKS['add']),
Expand Down
14 changes: 14 additions & 0 deletions shopelectro/tests/tests_logic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.test import TestCase, override_settings, tag

from shopelectro import models, logic


@tag('fast')
@override_settings(HEADER_LINKS={'exclude': [], 'add': []})
class HeaderMenu(TestCase):
fixtures = ['dump.json']

def test_roots_are_presented(self):
from_db = set(models.CategoryPage.objects.get_cached_trees())
from_logic = set(logic.header.menu_qs())
self.assertEqual(from_db, from_logic)

2 comments on commit 4da0030

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 4da0030 Sep 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 974-ceadb5de discovered in shopelectro/templatetags/se_extras.py and submitted as #980. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 4da0030 Sep 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 974-1680c064 discovered in shopelectro/logic/header.py and submitted as #981. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.