8

fixes a few future imports and adds support for new python and wagtail versions

This commit is contained in:
blurrah
2017-05-03 08:58:05 +02:00
parent 6640bf8d74
commit 82d11d57aa
3 changed files with 17 additions and 9 deletions

View File

@@ -1,3 +1,4 @@
from __future__ import absolute_import, unicode_literals
import time
from django.db.models import F

View File

@@ -1,24 +1,22 @@
from __future__ import absolute_import, unicode_literals
from wagtail.wagtailcore import blocks
from personalisation.models import Segment
def list_segment_choices():
for s in Segment.objects.all():
yield (s.pk, s.name)
class PersonalisedStructBlock(blocks.StructBlock):
segment = blocks.ChoiceBlock(
choices=list_segment_choices,
required=False, label="Personalisation segment",
help_text="Only show this content block for users in this segment")
required=False, label=_("Personalisation segment"),
help_text=_("Only show this content block for users in this segment"))
def render(self, value, context=None):
"""Only render this content block for users in this segment"""
# TODO: move logic to its own class instead of getting it from the session
user_segments = context['request'].session['segments']