Merge branch 'release/1.0.3'
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -13,6 +13,7 @@
|
|||||||
.vscode/
|
.vscode/
|
||||||
|
|
||||||
build/
|
build/
|
||||||
|
ve/
|
||||||
dist/
|
dist/
|
||||||
htmlcov/
|
htmlcov/
|
||||||
docs/_build
|
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
|
1.0.2
|
||||||
==================
|
==================
|
||||||
- Upgrade to Wagtail 2.2
|
- Upgrade to Wagtail 2.2
|
||||||
|
@@ -186,8 +186,7 @@ class SessionSegmentsAdapter(BaseSegmentsAdapter):
|
|||||||
for segment in enabled_segments:
|
for segment in enabled_segments:
|
||||||
if segment.is_static and segment.static_users.filter(id=self.request.user.id).exists():
|
if segment.is_static and segment.static_users.filter(id=self.request.user.id).exists():
|
||||||
additional_segments.append(segment)
|
additional_segments.append(segment)
|
||||||
elif (segment.excluded_users.filter(id=self.request.user.id).exists() or
|
elif (segment.excluded_users.filter(id=self.request.user.id).exists() or segment in excluded_segments):
|
||||||
segment in excluded_segments):
|
|
||||||
continue
|
continue
|
||||||
elif not segment.is_static or not segment.is_full:
|
elif not segment.is_static or not segment.is_full:
|
||||||
segment_rules = []
|
segment_rules = []
|
||||||
|
@@ -98,22 +98,17 @@ 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)
|
||||||
"""
|
"""
|
||||||
return [
|
for page in pages:
|
||||||
page for page in pages
|
if hasattr(page, 'personalisation_metadata') is not False and \
|
||||||
if (
|
page.personalisation_metadata is not None and \
|
||||||
(
|
page.personalisation_metadata.is_canonical is not True:
|
||||||
hasattr(page, 'personalisation_metadata') is False
|
if (type(pages) == list):
|
||||||
) or
|
pages.remove(page)
|
||||||
(
|
else:
|
||||||
hasattr(page, 'personalisation_metadata') and page.personalisation_metadata is None
|
pages = pages.exclude(pk=page.pk)
|
||||||
) or
|
return pages
|
||||||
(
|
|
||||||
hasattr(page, 'personalisation_metadata') and page.personalisation_metadata.is_canonical
|
|
||||||
)
|
|
||||||
)
|
|
||||||
]
|
|
||||||
|
@@ -185,8 +185,7 @@ class PersonalisedPagesSummaryPanel(PagesSummaryItem):
|
|||||||
order = 2100
|
order = 2100
|
||||||
|
|
||||||
def render(self):
|
def render(self):
|
||||||
page_count = models.PersonalisablePageMetadata.objects.filter(
|
page_count = models.PersonalisablePageMetadata.objects.filter(segment__isnull=True).count()
|
||||||
segment__isnull=True).count()
|
|
||||||
title = _("Personalised Page")
|
title = _("Personalised Page")
|
||||||
return mark_safe("""
|
return mark_safe("""
|
||||||
<li class="icon icon-fa-file-o">
|
<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')
|
@pytest.fixture(scope='session')
|
||||||
def django_db_setup(django_db_setup, django_db_blocker):
|
def django_db_setup(django_db_setup, django_db_blocker):
|
||||||
from wagtail.core.models import Page, Site
|
from wagtail.core.models import Page, Site
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
from wagtail_personalisation.utils import (
|
from wagtail_personalisation.utils import (
|
||||||
exclude_variants, impersonate_other_page)
|
exclude_variants, impersonate_other_page)
|
||||||
|
|
||||||
|
from wagtail.core.models import Page as WagtailPage
|
||||||
|
|
||||||
|
|
||||||
class Page(object):
|
class Page(object):
|
||||||
def __init__(self, path, depth, url_path, title):
|
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
|
page.personalisation_metadata.is_canonical = False
|
||||||
result = exclude_variants([page])
|
result = exclude_variants([page])
|
||||||
assert result == []
|
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