-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add adapters.get_segment_adapter to set the segment adapter on the re…
…quest object. Previously the segment adapter was set globally with the request as attribute. This causes thread safety issues. Instead we now initialise the segment adapter for each request and set it as attribute
- Loading branch information
1 parent
4158baf
commit cc38634
Showing
5 changed files
with
59 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
18 changes: 10 additions & 8 deletions
18
src/wagtail_personalisation/templatetags/datalayer_tags.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
from django.template import Library | ||
|
||
from wagtail_personalisation.app_settings import segments_adapter | ||
from wagtail_personalisation.adapters import get_segment_adapter | ||
|
||
register = Library() | ||
|
||
|
||
@register.inclusion_tag('wagtail_personalisation/tags/datalayer.html') | ||
def render_datalayer(): | ||
@register.inclusion_tag('wagtail_personalisation/tags/datalayer.html', takes_context=True) | ||
def render_datalayer(context): | ||
"""Render the sessions active segments in a data layer script tag.""" | ||
segments = segments_adapter.get_all_segments() | ||
segment_names = [item['encoded_name'] for item in segments] | ||
request = context.get('request') | ||
if request: | ||
segments = get_segment_adapter(request).get_all_segments() | ||
segment_names = [item['encoded_name'] for item in segments] | ||
|
||
return { | ||
'segments': segment_names | ||
} | ||
return { | ||
'segments': segment_names | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters