From a78290281b1778cd8ceb13d64b9fddee1ca85c5c Mon Sep 17 00:00:00 2001 From: blurrah Date: Wed, 31 May 2017 12:13:12 +0200 Subject: [PATCH] fixes adapter issues and fixes block for segments adapter --- src/wagtail_personalisation/adapters.py | 7 +++++-- .../templatetags/wagtail_personalisation_tags.py | 3 +-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/wagtail_personalisation/adapters.py b/src/wagtail_personalisation/adapters.py index 55afea3..047f5b4 100644 --- a/src/wagtail_personalisation/adapters.py +++ b/src/wagtail_personalisation/adapters.py @@ -97,8 +97,11 @@ class SessionSegmentsAdapter(BaseSegmentsAdapter): :rtype: wagtail_personalisation.models.Segment or None """ - return next(item for item in self.request.session['segments'] - if item.id == segment_id) + try: + return next(item for item in self.request.session['segments'] + if item['id'] == segment_id) + except StopIteration: + return None def add(self, segment): """Add a segment to the request session. diff --git a/src/wagtail_personalisation/templatetags/wagtail_personalisation_tags.py b/src/wagtail_personalisation/templatetags/wagtail_personalisation_tags.py index 76b56a0..bc5a48a 100644 --- a/src/wagtail_personalisation/templatetags/wagtail_personalisation_tags.py +++ b/src/wagtail_personalisation/templatetags/wagtail_personalisation_tags.py @@ -3,7 +3,6 @@ from django.template import TemplateSyntaxError from django.template.base import FilterExpression, kwarg_re from django.utils.safestring import mark_safe -from wagtail_personalisation.app_settings import segments_adapter from wagtail_personalisation.models import Segment register = template.Library() @@ -81,7 +80,7 @@ class SegmentNode(template.Node): return "" # Check if user has segment - user_segment = segments_adapter.get_segment(segment_id=segment.pk) + user_segment = context['request'].segment_adapter.get_segment(segment_id=segment.pk) if not user_segment: return ""