Merge branch 'release/1.0.3'
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -13,6 +13,7 @@
|
||||
.vscode/
|
||||
|
||||
build/
|
||||
ve/
|
||||
dist/
|
||||
htmlcov/
|
||||
docs/_build
|
||||
|
4
CHANGES
4
CHANGES
@@ -1,3 +1,7 @@
|
||||
1.0.3
|
||||
==================
|
||||
- bugfix:exclude variant returns queryset when params is queryset
|
||||
|
||||
1.0.2
|
||||
==================
|
||||
- Upgrade to Wagtail 2.2
|
||||
|
@@ -186,8 +186,7 @@ class SessionSegmentsAdapter(BaseSegmentsAdapter):
|
||||
for segment in enabled_segments:
|
||||
if segment.is_static and segment.static_users.filter(id=self.request.user.id).exists():
|
||||
additional_segments.append(segment)
|
||||
elif (segment.excluded_users.filter(id=self.request.user.id).exists() or
|
||||
segment in excluded_segments):
|
||||
elif (segment.excluded_users.filter(id=self.request.user.id).exists() or segment in excluded_segments):
|
||||
continue
|
||||
elif not segment.is_static or not segment.is_full:
|
||||
segment_rules = []
|
||||
|
@@ -98,22 +98,17 @@ def parse_tag(token, parser):
|
||||
def exclude_variants(pages):
|
||||
"""Checks if page is not a variant
|
||||
|
||||
:param pages: List of pages to check
|
||||
:type pages: list
|
||||
:return: List of pages that aren't variants
|
||||
:rtype: list
|
||||
:param pages: List | Queryset of pages to check
|
||||
:type pages: list or querset
|
||||
:return: List|Queryset of pages that aren't variants
|
||||
:rtype: list or queryset (depending on the param type)
|
||||
"""
|
||||
return [
|
||||
page for page in pages
|
||||
if (
|
||||
(
|
||||
hasattr(page, 'personalisation_metadata') is False
|
||||
) or
|
||||
(
|
||||
hasattr(page, 'personalisation_metadata') and page.personalisation_metadata is None
|
||||
) or
|
||||
(
|
||||
hasattr(page, 'personalisation_metadata') and page.personalisation_metadata.is_canonical
|
||||
)
|
||||
)
|
||||
]
|
||||
for page in pages:
|
||||
if hasattr(page, 'personalisation_metadata') is not False and \
|
||||
page.personalisation_metadata is not None and \
|
||||
page.personalisation_metadata.is_canonical is not True:
|
||||
if (type(pages) == list):
|
||||
pages.remove(page)
|
||||
else:
|
||||
pages = pages.exclude(pk=page.pk)
|
||||
return pages
|
||||
|
@@ -185,8 +185,7 @@ class PersonalisedPagesSummaryPanel(PagesSummaryItem):
|
||||
order = 2100
|
||||
|
||||
def render(self):
|
||||
page_count = models.PersonalisablePageMetadata.objects.filter(
|
||||
segment__isnull=True).count()
|
||||
page_count = models.PersonalisablePageMetadata.objects.filter(segment__isnull=True).count()
|
||||
title = _("Personalised Page")
|
||||
return mark_safe("""
|
||||
<li class="icon icon-fa-file-o">
|
||||
|
@@ -7,6 +7,11 @@ pytest_plugins = [
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def enable_db_access(db):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def django_db_setup(django_db_setup, django_db_blocker):
|
||||
from wagtail.core.models import Page, Site
|
||||
|
@@ -1,6 +1,8 @@
|
||||
from wagtail_personalisation.utils import (
|
||||
exclude_variants, impersonate_other_page)
|
||||
|
||||
from wagtail.core.models import Page as WagtailPage
|
||||
|
||||
|
||||
class Page(object):
|
||||
def __init__(self, path, depth, url_path, title):
|
||||
@@ -57,3 +59,54 @@ def test_exclude_variants_excludes_pages_with_metadata_not_canonical():
|
||||
page.personalisation_metadata.is_canonical = False
|
||||
result = exclude_variants([page])
|
||||
assert result == []
|
||||
|
||||
|
||||
def test_exclude_variants_with_pages_querysets():
|
||||
'''
|
||||
Test that excludes variant works for querysets
|
||||
'''
|
||||
for i in range(5):
|
||||
page = WagtailPage(path="/" + str(i), depth=0, url_path="/", title="Hoi " + str(i))
|
||||
page.save()
|
||||
pages = WagtailPage.objects.all().order_by('id')
|
||||
|
||||
result = exclude_variants(pages)
|
||||
assert type(result) == type(pages)
|
||||
assert result == pages
|
||||
|
||||
|
||||
def test_exclude_variants_with_pages_querysets_not_canonical():
|
||||
'''
|
||||
Test that excludes variant works for querysets with
|
||||
personalisation_metadata canonical False
|
||||
'''
|
||||
for i in range(5):
|
||||
page = WagtailPage(path="/" + str(i), depth=0, url_path="/", title="Hoi " + str(i))
|
||||
page.save()
|
||||
pages = WagtailPage.objects.all().order_by('id')
|
||||
# add variants
|
||||
for page in pages:
|
||||
page.personalisation_metadata = Metadata(is_canonical=False)
|
||||
page.save()
|
||||
|
||||
result = exclude_variants(pages)
|
||||
assert type(result) == type(pages)
|
||||
assert result.count() == 0
|
||||
|
||||
|
||||
def test_exclude_variants_with_pages_querysets_meta_none():
|
||||
'''
|
||||
Test that excludes variant works for querysets with meta as none
|
||||
'''
|
||||
for i in range(5):
|
||||
page = WagtailPage(path="/" + str(i), depth=0, url_path="/", title="Hoi " + str(i))
|
||||
page.save()
|
||||
pages = WagtailPage.objects.all().order_by('id')
|
||||
# add variants
|
||||
for page in pages:
|
||||
page.personalisation_metadata = None
|
||||
page.save()
|
||||
|
||||
result = exclude_variants(pages)
|
||||
assert type(result) == type(pages)
|
||||
assert result == pages
|
||||
|
Reference in New Issue
Block a user