-
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.
- Loading branch information
Showing
5 changed files
with
226 additions
and
12 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
32 changes: 32 additions & 0 deletions
32
tests/sandbox/pages/migrations/0003_personalisedfieldspage.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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.1 on 2017-05-31 11:29 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import wagtail.wagtailcore.blocks | ||
import wagtail.wagtailcore.fields | ||
import wagtail.wagtailimages.blocks | ||
import wagtail_personalisation.blocks | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('wagtailcore', '0033_remove_golive_expiry_help_text'), | ||
('pages', '0002_auto_20170531_0915'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='PersonalisedFieldsPage', | ||
fields=[ | ||
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')), | ||
('body', wagtail.wagtailcore.fields.StreamField((('personalised_block', wagtail.wagtailcore.blocks.StructBlock((('segment', wagtail.wagtailcore.blocks.ChoiceBlock(choices=wagtail_personalisation.blocks.list_segment_choices, help_text='Only show this content block for users in this segment', label='Personalisation segment', required=False)), ('heading', wagtail.wagtailcore.blocks.CharBlock()), ('paragraph', wagtail.wagtailcore.blocks.RichTextBlock())))), ('personalised_block_template', wagtail.wagtailcore.blocks.StructBlock((('segment', wagtail.wagtailcore.blocks.ChoiceBlock(choices=wagtail_personalisation.blocks.list_segment_choices, help_text='Only show this content block for users in this segment', label='Personalisation segment', required=False)), ('heading', wagtail.wagtailcore.blocks.CharBlock()), ('paragraph', wagtail.wagtailcore.blocks.RichTextBlock())), label='Block with template', template='blocks/personalised_block_template.html')), ('personalised_rich_text_block', wagtail.wagtailcore.blocks.StructBlock((('segment', wagtail.wagtailcore.blocks.ChoiceBlock(choices=wagtail_personalisation.blocks.list_segment_choices, help_text='Only show this content block for users in this segment', label='Personalisation segment', required=False)), ('rich_text', wagtail.wagtailcore.blocks.RichTextBlock(label='Rich Text'))))), ('personalised_image', wagtail.wagtailcore.blocks.StructBlock((('segment', wagtail.wagtailcore.blocks.ChoiceBlock(choices=wagtail_personalisation.blocks.list_segment_choices, help_text='Only show this content block for users in this segment', label='Personalisation segment', required=False)), ('image', wagtail.wagtailimages.blocks.ImageChooserBlock(label='Image'))))), ('personalised_char', wagtail.wagtailcore.blocks.StructBlock((('segment', wagtail.wagtailcore.blocks.ChoiceBlock(choices=wagtail_personalisation.blocks.list_segment_choices, help_text='Only show this content block for users in this segment', label='Personalisation segment', required=False)), ('char', wagtail.wagtailcore.blocks.CharBlock(label='Text'))))), ('personalised_text', wagtail.wagtailcore.blocks.StructBlock((('segment', wagtail.wagtailcore.blocks.ChoiceBlock(choices=wagtail_personalisation.blocks.list_segment_choices, help_text='Only show this content block for users in this segment', label='Personalisation segment', required=False)), ('text', wagtail.wagtailcore.blocks.TextBlock(label='Mutli-line Text')))))))), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
bases=('wagtailcore.page',), | ||
), | ||
] |
9 changes: 9 additions & 0 deletions
9
tests/sandbox/templates/blocks/personalised_block_template.html
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{% load wagtailcore_tags %} | ||
|
||
<div class="personalisation-block-template"> | ||
<p>This is a block with <strong>template</strong>.</p> | ||
<h2>Heading: {{ value.heading }}</h2> | ||
<div> | ||
{{ value.paragraph|richtext }} | ||
</div> | ||
</div> |
15 changes: 15 additions & 0 deletions
15
tests/sandbox/templates/pages/page_with_personalisable_fields.html
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{% extends "base.html" %} | ||
{% load wagtailcore_tags %} | ||
|
||
{% block body_class %}template-homepage{% endblock %} | ||
|
||
{% block content %} | ||
<h1>{{ page.title }}</h1> | ||
{% for block in page.body %} | ||
<section class="section-{{ block.block_type }}"> | ||
<p><em>Section for {{ block.block_type }}.</em></p> | ||
{% include_block block %} | ||
</section> | ||
<hr> | ||
{% endfor %} | ||
{% endblock %} |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from __future__ import absolute_import, unicode_literals | ||
|
||
import pytest | ||
|
||
from tests.factories.segment import SegmentFactory | ||
from test.factories.pages import PersonalisedFieldsPageFactory | ||
from tests.utils import render_template | ||
|
||
@pytest.mark.django_db | ||
def test_render_block(rf): | ||
SegmentFactory(name='test', persistent=True) | ||
|
||
request = rf.get('/') | ||
|
||
request.session['segments'] = [{ | ||
"encoded_name": 'test', | ||
"id": 1, | ||
"timestamp": int(time.time()), | ||
"persistent": True | ||
}] | ||
|
||
PersonalisedFieldsPageFactory(body=) | ||
|
||
content = render_template(""" | ||
{% load wagtail_personalisation_tags %} | ||
{% segment name='test' %}Test{% endsegment %} | ||
""", request=request).strip() | ||
|
||
assert content == "Test" | ||
|
||
content = render_template(""" | ||
{% load wagtail_personalisation_tags %} | ||
{% segment name='test2' %}Test{% endsegment %} | ||
""", request=request).strip() | ||
|
||
assert content == "" |