0003-cells-exclude-cells-with-inactive-placeholders-from-.patch
combo/apps/assets/templatetags/assets.py | ||
---|---|---|
72 | 72 |
return 'none' |
73 | 73 | |
74 | 74 | |
75 |
@register.simple_tag |
|
76 |
def get_asset(*args, **kwargs): |
|
75 |
@register.simple_tag(takes_context=True) |
|
76 |
def get_asset(context, *args, **kwargs): |
|
77 |
if context.get('traverse_cells'): |
|
78 |
# assets are not required when we are just searching for page placeholders |
|
79 |
return None |
|
80 | ||
77 | 81 |
key = None |
78 | 82 |
if 'cell' in kwargs and 'type' in kwargs: |
79 | 83 |
try: |
combo/data/models.py | ||
---|---|---|
859 | 859 |
return self.invalid_reason_codes.get( |
860 | 860 |
validity_info.invalid_reason_code, validity_info.invalid_reason_code) |
861 | 861 | |
862 |
def is_placeholder_active(self): |
|
863 |
if not self.placeholder: |
|
864 |
return False |
|
865 |
if self.placeholder.startswith('_'): |
|
866 |
return True |
|
867 | ||
868 |
request = RequestFactory().get('/') |
|
869 |
if not hasattr(self.page, '_placeholders'): |
|
870 |
self.page._placeholders = self.page.get_placeholders(request, traverse_cells=True) |
|
871 |
for placeholder in self.page._placeholders: |
|
872 |
if placeholder.key == self.placeholder: |
|
873 |
return True |
|
874 |
return False |
|
875 | ||
862 | 876 |
def is_visible(self, user=None, check_validity_info=True): |
863 | 877 |
if check_validity_info: |
864 | 878 |
validity_info = self.get_validity_info() |
combo/manager/views.py | ||
---|---|---|
95 | 95 | |
96 | 96 |
def invalid_cell_report(request): |
97 | 97 |
invalid_cells = CellBase.get_cells( |
98 |
select_related={'__all__': ['page']}, |
|
99 | 98 |
page__snapshot__isnull=True, |
100 | 99 |
validity_info__invalid_since__isnull=False, |
101 | 100 |
load_contenttypes=True) |
101 |
# manual prefetch of cell pages (for ordering and placeholders) |
|
102 |
all_pages_by_pk = {p.pk: p for p in Page.objects.filter(snapshot__isnull=True)} |
|
103 |
for cell in invalid_cells: |
|
104 |
cell.page = all_pages_by_pk.get(cell.page_id) |
|
105 |
# exclude some cells on placeholder naming |
|
102 | 106 |
invalid_cells = [c for c in invalid_cells if c.placeholder and not c.placeholder.startswith('_')] |
107 |
# exclude cells with an inactive placeholder |
|
108 |
invalid_cells = [c for c in invalid_cells if c.is_placeholder_active()] |
|
109 |
# sort cells |
|
103 | 110 |
invalid_cells.sort(key=attrgetter('page.order', 'page.pk', 'order')) |
111 | ||
104 | 112 |
context = { |
105 | 113 |
'object_list': invalid_cells, |
106 | 114 |
} |
combo/public/templatetags/combo.py | ||
---|---|---|
70 | 70 |
# ajax call |
71 | 71 |
page_cells = context.get('page_cells') |
72 | 72 |
elif 'page' in context and hasattr(context['page'], 'prefetched_cells'): |
73 |
# sometimes cells are prefetched; use them |
|
73 | 74 |
page_cells = context['page'].prefetched_cells |
74 | 75 |
elif not context.get('render_skeleton'): |
75 | 76 |
page_cells = context['page'].get_cells() if 'page' in context else [] |
77 |
if 'page' in context: |
|
78 |
# store cells for later use |
|
79 |
context['page'].prefetched_cells = page_cells |
|
76 | 80 |
context['cells'] = [ |
77 | 81 |
x for x in page_cells if |
78 | 82 |
x.placeholder == placeholder_name and |
tests/test_manager.py | ||
---|---|---|
13 | 13 |
from django.db import connection |
14 | 14 |
from django.template import TemplateSyntaxError |
15 | 15 |
from django.test import override_settings |
16 |
from django.test.client import RequestFactory |
|
16 | 17 |
from django.test.utils import CaptureQueriesContext |
17 | 18 |
from django.utils.http import urlencode |
18 | 19 |
from django.utils.six import BytesIO |
... | ... | |
627 | 628 |
resp = app.get('/manage/cells/invalid-report/') |
628 | 629 |
assert resp.context['object_list'] == [cell] |
629 | 630 | |
631 |
# cells without placeholder are not reported |
|
632 |
cell.placeholder = '' |
|
633 |
cell.save() |
|
634 |
resp = app.get('/manage/cells/invalid-report/') |
|
635 |
assert resp.context['object_list'] == [] |
|
636 | ||
637 |
# cells with unknown placeholder are not reported |
|
638 |
request = RequestFactory().get('/') |
|
639 |
assert [p.key for p in page.get_placeholders(request, traverse_cells=True)] == ['content', 'footer'] |
|
640 |
cell.placeholder = 'foobar' |
|
641 |
cell.save() |
|
642 |
resp = app.get('/manage/cells/invalid-report/') |
|
643 |
assert resp.context['object_list'] == [] |
|
644 |
cell.placeholder = 'footer' |
|
645 |
cell.save() |
|
646 |
resp = app.get('/manage/cells/invalid-report/') |
|
647 |
assert resp.context['object_list'] == [cell] |
|
648 | ||
630 | 649 | |
631 | 650 |
def test_duplicate_page(app, admin_user): |
632 | 651 |
page = Page.objects.create(title='One', slug='one', template_name='standard', exclude_from_navigation=False) |
633 |
- |