From 46d86d852d83157e3a62ee69511c29f7c85cdcf8 Mon Sep 17 00:00:00 2001 From: Jasper Berghoef Date: Fri, 2 Jun 2017 13:04:57 +0200 Subject: [PATCH] Adds stream fields to the sandbox --- sandbox/exampledata/personalisation.json | 279 +++++++++--------- .../migrations/0003_homepage_text_content.py | 9 +- sandbox/sandbox/apps/home/models.py | 16 +- .../apps/home/templates/home/home_page.html | 8 +- 4 files changed, 173 insertions(+), 139 deletions(-) diff --git a/sandbox/exampledata/personalisation.json b/sandbox/exampledata/personalisation.json index 3f8ed92..93205e5 100644 --- a/sandbox/exampledata/personalisation.json +++ b/sandbox/exampledata/personalisation.json @@ -1,133 +1,148 @@ -[ - { - "model": "wagtail_personalisation.timerule", - "pk": 1, - "fields": { - "segment": 2, - "start_time": "06:00:00", - "end_time": "10:00:00" - } - }, - { - "model": "wagtail_personalisation.visitcountrule", - "pk": 1, - "fields": { - "segment": 1, - "operator": "more_than", - "count": 3, - "counted_page": 3 - } - }, - { - "model": "wagtail_personalisation.segment", - "pk": 1, - "fields": { - "name": "Returning Rook", - "create_date": "2017-06-02T05:38:02.304Z", - "edit_date": "2017-06-02T05:38:02.304Z", - "enable_date": "2017-06-02T05:38:02.290Z", - "disable_date": null, - "visit_count": 0, - "status": "enabled", - "persistent": false, - "match_any": false - } - }, - { - "model": "wagtail_personalisation.segment", - "pk": 2, - "fields": { - "name": "Early Birds", - "create_date": "2017-06-02T05:38:14.749Z", - "edit_date": "2017-06-02T05:38:14.750Z", - "enable_date": "2017-06-02T05:38:14.736Z", - "disable_date": null, - "visit_count": 0, - "status": "enabled", - "persistent": false, - "match_any": false - } - }, - { - "model": "wagtail_personalisation.personalisablepagemetadata", - "pk": 1, - "fields": { - "canonical_page": 3, - "variant": 3, - "segment": null - } - }, - { - "model": "wagtail_personalisation.personalisablepagemetadata", - "pk": 2, - "fields": { - "canonical_page": 3, - "variant": 4, - "segment": 1 - } - }, - { - "model": "home.homepage", - "pk": 3, - "fields": { - "text_content": "

Thank you for trying Wagxperience!

" - } - }, - { - "model": "home.homepage", - "pk": 4, - "fields": { - "text_content": "

Thank you for trying Wagxperience!

You've visited the homepage more than 3 times!

" - } - }, - { - "model": "wagtailcore.page", - "pk": 3, - "fields": { - "path": "00010001", - "depth": 2, - "numchild": 0, - "title": "Home", - "slug": "home", - "content_type": 2, - "live": true, - "has_unpublished_changes": false, - "url_path": "/home/", - "owner": null, - "seo_title": "", - "show_in_menus": false, - "search_description": "", - "go_live_at": null, - "expire_at": null, - "expired": false, - "locked": false, - "first_published_at": null, - "latest_revision_created_at": null - } - }, - { - "model": "wagtailcore.page", - "pk": 4, - "fields": { - "path": "00010002", - "depth": 2, - "numchild": 0, - "title": "Home (Returning Rook)", - "slug": "home-returning-rook", - "content_type": 2, - "live": true, - "has_unpublished_changes": false, - "url_path": "/home-returning-rook/", - "owner": null, - "seo_title": "", - "show_in_menus": false, - "search_description": "", - "go_live_at": null, - "expire_at": null, - "expired": false, - "locked": false, - "first_published_at": "2017-06-02T05:38:53.568Z", - "latest_revision_created_at": "2017-06-02T05:38:53.390Z" - } +[{ + "model": "wagtail_personalisation.timerule", + "pk": 1, + "fields": { + "segment": 2, + "start_time": "06:00:00", + "end_time": "11:00:00" } -] +}, { + "model": "wagtail_personalisation.visitcountrule", + "pk": 1, + "fields": { + "segment": 1, + "operator": "more_than", + "count": 3, + "counted_page": 3 + } +}, { + "model": "wagtail_personalisation.segment", + "pk": 1, + "fields": { + "name": "Returning Rook", + "create_date": "2017-06-02T05:38:02.304Z", + "edit_date": "2017-06-02T10:58:39.399Z", + "enable_date": "2017-06-02T10:58:39.389Z", + "disable_date": "2017-06-02T10:34:51.722Z", + "visit_count": 0, + "status": "enabled", + "persistent": false, + "match_any": false + } +}, { + "model": "wagtail_personalisation.segment", + "pk": 2, + "fields": { + "name": "Early Birds", + "create_date": "2017-06-02T05:38:14.749Z", + "edit_date": "2017-06-02T10:57:44.504Z", + "enable_date": "2017-06-02T10:57:44.497Z", + "disable_date": "2017-06-02T10:57:39.984Z", + "visit_count": 1, + "status": "enabled", + "persistent": false, + "match_any": false + } +}, { + "model": "wagtail_personalisation.personalisablepagemetadata", + "pk": 1, + "fields": { + "canonical_page": 3, + "variant": 3, + "segment": null + } +}, { + "model": "wagtail_personalisation.personalisablepagemetadata", + "pk": 2, + "fields": { + "canonical_page": 3, + "variant": 4, + "segment": 1 + } +}, { + "model": "home.homepage", + "pk": 3, + "fields": { + "intro": "

Thank you for trying Wagxperience!

", + "body": "[{\"type\": \"personalisable_paragraph\", \"value\": {\"segment\": \"2\", \"paragraph\": \"

You are an early bird!

\"}}]" + } +}, { + "model": "home.homepage", + "pk": 4, + "fields": { + "intro": "

Thank you for trying Wagxperience!

You've visited the homepage more than 3 times!

", + "body": "[]" + } +}, { + "model": "wagtailcore.page", + "pk": 1, + "fields": { + "path": "0001", + "depth": 1, + "numchild": 1, + "title": "Root", + "slug": "root", + "content_type": 1, + "live": true, + "has_unpublished_changes": false, + "url_path": "/", + "owner": null, + "seo_title": "", + "show_in_menus": false, + "search_description": "", + "go_live_at": null, + "expire_at": null, + "expired": false, + "locked": false, + "first_published_at": null, + "latest_revision_created_at": null + } +}, { + "model": "wagtailcore.page", + "pk": 3, + "fields": { + "path": "00010001", + "depth": 2, + "numchild": 0, + "title": "Home", + "slug": "home", + "content_type": 2, + "live": true, + "has_unpublished_changes": false, + "url_path": "/home/", + "owner": null, + "seo_title": "", + "show_in_menus": false, + "search_description": "", + "go_live_at": null, + "expire_at": null, + "expired": false, + "locked": false, + "first_published_at": "2017-06-02T10:35:34.706Z", + "latest_revision_created_at": "2017-06-02T10:35:34.565Z" + } +}, { + "model": "wagtailcore.page", + "pk": 4, + "fields": { + "path": "00010002", + "depth": 2, + "numchild": 0, + "title": "Home (Returning Rook)", + "slug": "home-returning-rook", + "content_type": 2, + "live": true, + "has_unpublished_changes": false, + "url_path": "/home-returning-rook/", + "owner": null, + "seo_title": "", + "show_in_menus": false, + "search_description": "", + "go_live_at": null, + "expire_at": null, + "expired": false, + "locked": false, + "first_published_at": "2017-06-02T05:38:53.568Z", + "latest_revision_created_at": "2017-06-02T05:38:53.390Z" + } +}] diff --git a/sandbox/sandbox/apps/home/migrations/0003_homepage_text_content.py b/sandbox/sandbox/apps/home/migrations/0003_homepage_text_content.py index a2b8c10..d4108b9 100644 --- a/sandbox/sandbox/apps/home/migrations/0003_homepage_text_content.py +++ b/sandbox/sandbox/apps/home/migrations/0003_homepage_text_content.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals from django.db import migrations import wagtail.wagtailcore.fields +import wagtail_personalisation class Migration(migrations.Migration): @@ -15,9 +16,15 @@ class Migration(migrations.Migration): operations = [ migrations.AddField( model_name='homepage', - name='text_content', + name='intro', field=wagtail.wagtailcore.fields.RichTextField( default='

Thank you for trying Wagxperience!

'), preserve_default=False, ), + migrations.AddField( + model_name='homepage', + name='body', + field=wagtail.wagtailcore.fields.StreamField((('personalisable_paragraph', 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)), ('paragraph', wagtail.wagtailcore.blocks.RichTextBlock())), icon='pilcrow')),), default=''), + preserve_default=False, + ), ] diff --git a/sandbox/sandbox/apps/home/models.py b/sandbox/sandbox/apps/home/models.py index fd33794..0d409fe 100644 --- a/sandbox/sandbox/apps/home/models.py +++ b/sandbox/sandbox/apps/home/models.py @@ -1,15 +1,23 @@ from __future__ import absolute_import, unicode_literals +from wagtail.wagtailadmin.edit_handlers import RichTextFieldPanel, StreamFieldPanel +from wagtail.wagtailcore import blocks +from wagtail.wagtailcore.fields import RichTextField, StreamField from wagtail.wagtailcore.models import Page -from wagtail.wagtailadmin.edit_handlers import RichTextFieldPanel -from wagtail.wagtailcore.fields import RichTextField from wagtail_personalisation.models import PersonalisablePageMixin +from wagtail_personalisation.blocks import PersonalisedStructBlock class HomePage(PersonalisablePageMixin, Page): - text_content = RichTextField() + intro = RichTextField() + body = StreamField([ + ('personalisable_paragraph', PersonalisedStructBlock([ + ('paragraph', blocks.RichTextBlock()), + ], icon='pilcrow')) + ]) content_panels = Page.content_panels + [ - RichTextFieldPanel('text_content') + RichTextFieldPanel('intro'), + StreamFieldPanel('body'), ] diff --git a/sandbox/sandbox/apps/home/templates/home/home_page.html b/sandbox/sandbox/apps/home/templates/home/home_page.html index f9ea026..ba27505 100644 --- a/sandbox/sandbox/apps/home/templates/home/home_page.html +++ b/sandbox/sandbox/apps/home/templates/home/home_page.html @@ -7,8 +7,12 @@ {% block content %}

Wagtail Personalisation


-

{{ self.title }}

- {{ self.text_content|richtext }} + {{ self.intro|richtext }} + + {% for block in page.body %} +
{% include_block block %}
+ {% endfor %} + {% endblock %}