update exclude varient format and add variants to tests
This commit is contained in:
@ -98,18 +98,18 @@ def parse_tag(token, parser):
|
|||||||
def exclude_variants(pages):
|
def exclude_variants(pages):
|
||||||
"""Checks if page is not a variant
|
"""Checks if page is not a variant
|
||||||
|
|
||||||
:param pages: List of pages to check
|
:param pages: List | Queryset of pages to check
|
||||||
:type pages: list
|
:type pages: list or querset
|
||||||
:return: List of pages that aren't variants
|
:return: List|Queryset of pages that aren't variants
|
||||||
:rtype: list
|
:rtype: list or queryset (depending on the param type)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
for page in pages:
|
for page in pages:
|
||||||
if not ((hasattr(page, 'personalisation_metadata') is False
|
if hasattr(page, 'personalisation_metadata') is not False and \
|
||||||
) or (hasattr(page, 'personalisation_metadata') and page.personalisation_metadata is None
|
page.personalisation_metadata is not None and \
|
||||||
) or (hasattr(page, 'personalisation_metadata') and page.personalisation_metadata.is_canonical)):
|
page.personalisation_metadata.is_canonical is not True:
|
||||||
if (type(pages) == list):
|
if (type(pages) == list):
|
||||||
pages.remove(page)
|
pages.remove(page)
|
||||||
else:
|
else:
|
||||||
pages.exclude(pk=page.pk)
|
pages.exclude(pk=page.pk)
|
||||||
return pages
|
return pages
|
||||||
|
@ -69,5 +69,10 @@ def test_exclude_variants_with_pages_querysets():
|
|||||||
page = WagtailPage(path="/" + str(i), depth=0, url_path="/", title="Hoi " + str(i))
|
page = WagtailPage(path="/" + str(i), depth=0, url_path="/", title="Hoi " + str(i))
|
||||||
page.save()
|
page.save()
|
||||||
pages = WagtailPage.objects.all().order_by('id')
|
pages = WagtailPage.objects.all().order_by('id')
|
||||||
|
# add variants
|
||||||
|
for page in pages:
|
||||||
|
page.personalisation_metadata = Metadata(is_canonical=False)
|
||||||
|
pages = WagtailPage.objects.all().order_by('id')
|
||||||
result = exclude_variants(pages)
|
result = exclude_variants(pages)
|
||||||
assert result == pages
|
assert type(result) == type(pages)
|
||||||
|
assert result != pages
|
||||||
|
Reference in New Issue
Block a user