diff --git a/.gitignore b/.gitignore index 16914b0..df72266 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ .vscode/ build/ +ve/ dist/ htmlcov/ docs/_build diff --git a/CHANGES b/CHANGES index 744d2e7..27dfc33 100644 --- a/CHANGES +++ b/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 diff --git a/VERSON b/VERSON new file mode 100644 index 0000000..21e8796 --- /dev/null +++ b/VERSON @@ -0,0 +1 @@ +1.0.3 diff --git a/src/wagtail_personalisation/adapters.py b/src/wagtail_personalisation/adapters.py index 7c84f42..ad2971e 100644 --- a/src/wagtail_personalisation/adapters.py +++ b/src/wagtail_personalisation/adapters.py @@ -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 = [] diff --git a/src/wagtail_personalisation/utils.py b/src/wagtail_personalisation/utils.py index 49bea40..2cd1951 100644 --- a/src/wagtail_personalisation/utils.py +++ b/src/wagtail_personalisation/utils.py @@ -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 diff --git a/src/wagtail_personalisation/wagtail_hooks.py b/src/wagtail_personalisation/wagtail_hooks.py index 6c91c99..b7e1ff3 100644 --- a/src/wagtail_personalisation/wagtail_hooks.py +++ b/src/wagtail_personalisation/wagtail_hooks.py @@ -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("""