Skip to content

Commit d7d63ad

Browse files
committed
Add example to the sandbox
1 parent 543fb8a commit d7d63ad

File tree

9,867 files changed

+1489684
-49
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

9,867 files changed

+1489684
-49
lines changed

sandbox/sandbox/apps/home/migrations/0001_initial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Migration(migrations.Migration):
1212
initial = True
1313

1414
dependencies = [
15-
('wagtailcore', '0033_remove_golive_expiry_help_text'),
15+
('wagtailcore', '0001_initial'),
1616
('wagtail_personalisation', '0011_personalisablepagemetadata'),
1717
]
1818

tests/sandbox/pages/migrations/0003_personalisedfieldspage.py renamed to sandbox/sandbox/apps/home/migrations/0004_create_personalised_fields_page.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Generated by Django 1.11.1 on 2017-05-31 11:29
2+
# Generated by Django 1.11.1 on 2017-05-31 16:15
33
from __future__ import unicode_literals
44

55
from django.db import migrations, models
@@ -13,8 +13,8 @@
1313
class Migration(migrations.Migration):
1414

1515
dependencies = [
16-
('wagtailcore', '0033_remove_golive_expiry_help_text'),
17-
('pages', '0002_auto_20170531_0915'),
16+
('wagtailcore', '0001_initial'),
17+
('home', '0003_homepage_text_content'),
1818
]
1919

2020
operations = [

sandbox/sandbox/apps/home/models.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
from __future__ import absolute_import, unicode_literals
22

3-
from wagtail.wagtailadmin.edit_handlers import RichTextFieldPanel, StreamFieldPanel
3+
from django.utils.translation import ugettext_lazy as _
4+
5+
from wagtail.wagtailadmin.edit_handlers import RichTextFieldPanel,StreamFieldPanel
46
from wagtail.wagtailcore import blocks
57
from wagtail.wagtailcore.fields import RichTextField, StreamField
68
from wagtail.wagtailcore.models import Page
79

10+
from wagtail_personalisation.blocks import (PersonalisedCharBlock,
11+
PersonalisedImageChooserBlock, PersonalisedRichTextBlock,
12+
PersonalisedStructBlock, PersonalisedTextBlock)
813
from wagtail_personalisation.models import PersonalisablePageMixin
9-
from wagtail_personalisation.blocks import PersonalisedStructBlock
10-
1114

1215
class HomePage(PersonalisablePageMixin, Page):
1316
intro = RichTextField()
@@ -21,3 +24,24 @@ class HomePage(PersonalisablePageMixin, Page):
2124
RichTextFieldPanel('intro'),
2225
StreamFieldPanel('body'),
2326
]
27+
28+
29+
class PersonalisedFieldsPage(Page):
30+
body = StreamField([
31+
('personalised_block', PersonalisedStructBlock([
32+
('heading', blocks.CharBlock()),
33+
('paragraph', blocks.RichTextBlock())
34+
], render_fields=['heading', 'paragraph'])),
35+
('personalised_block_template', PersonalisedStructBlock([
36+
('heading', blocks.CharBlock()),
37+
('paragraph', blocks.RichTextBlock())
38+
], template='blocks/personalised_block_template.html', label=_('Block with template'))),
39+
('personalised_rich_text_block', PersonalisedRichTextBlock()),
40+
('personalised_image', PersonalisedImageChooserBlock()),
41+
('personalised_char', PersonalisedCharBlock()),
42+
('personalised_text', PersonalisedTextBlock()),
43+
])
44+
45+
content_panels = Page.content_panels + [
46+
StreamFieldPanel('body')
47+
]

tests/sandbox/templates/blocks/personalised_block_template.html renamed to sandbox/sandbox/apps/home/templates/blocks/personalised_block_template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{% load wagtailcore_tags %}
22

3-
<div class="personalisation-block-template">
3+
<div class="personalisation-block-template" style="background-color: cornsilk;">
44
<p>This is a block with <strong>template</strong>.</p>
55
<h2>Heading: {{ value.heading }}</h2>
66
<div>

tests/sandbox/templates/pages/page_with_personalisable_fields.html renamed to sandbox/sandbox/apps/home/templates/home/personalised_fields_page.html

File renamed without changes.

src/wagtail_personalisation/blocks.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@ def __init__(self, *args, **kwargs):
3434
3535
Keyword Arguments:
3636
render_fields: List with field names to be rendered or None to use
37-
the default block rendering.
37+
the default block rendering. Please set to None if using block
38+
with template since then it's the template that takes care
39+
of what fields are rendered.
3840
"""
3941
render_fields = kwargs.pop('render_fields',
4042
self._meta_class.render_fields)
4143
super(BasePersonalisedStructBlock, self).__init__(*args, **kwargs)
4244

45+
# Check "render_fields" are either a list or None.
4346
if isinstance(render_fields, tuple):
4447
render_fields = list(render_fields)
4548

@@ -51,7 +54,13 @@ def __init__(self, *args, **kwargs):
5154
raise ValueError('"render_fields" has to contain name(s) of the '
5255
'specified blocks.')
5356
else:
54-
setattr(self._meta_class, 'render_fields', render_fields)
57+
setattr(self.meta, 'render_fields', render_fields)
58+
59+
# Template can be used only when "render_fields" is set to None.
60+
if self.meta.render_fields is not None \
61+
and getattr(self.meta, 'template', None):
62+
raise ValueError('"render_fields" has to be set to None when using '
63+
'template.')
5564

5665

5766
def is_visible(self, value, request):
@@ -87,13 +96,13 @@ def render(self, value, context=None):
8796
if not self.is_visible(value, context['request']):
8897
return ""
8998

90-
if self._meta_class.render_fields is None:
99+
if self.meta.render_fields is None:
91100
return super(BasePersonalisedStructBlock, self).render(
92101
value, context)
93102

94-
if isinstance(self._meta_class.render_fields, list):
103+
if isinstance(self.meta.render_fields, list):
95104
render_value = ''
96-
for field_name in self._meta_class.render_fields:
105+
for field_name in self.meta.render_fields:
97106
if hasattr(value.bound_blocks[field_name], 'render_as_block'):
98107
block_value = value.bound_blocks[field_name] \
99108
.render_as_block(context=context)

tests/unit/test_blocks.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

ve/bin/activate

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# This file must be used with "source bin/activate" *from bash*
2+
# you cannot run it directly
3+
4+
deactivate () {
5+
# reset old environment variables
6+
if [ -n "$_OLD_VIRTUAL_PATH" ] ; then
7+
PATH="$_OLD_VIRTUAL_PATH"
8+
export PATH
9+
unset _OLD_VIRTUAL_PATH
10+
fi
11+
if [ -n "$_OLD_VIRTUAL_PYTHONHOME" ] ; then
12+
PYTHONHOME="$_OLD_VIRTUAL_PYTHONHOME"
13+
export PYTHONHOME
14+
unset _OLD_VIRTUAL_PYTHONHOME
15+
fi
16+
17+
# This should detect bash and zsh, which have a hash command that must
18+
# be called to get it to forget past commands. Without forgetting
19+
# past commands the $PATH changes we made may not be respected
20+
if [ -n "$BASH" -o -n "$ZSH_VERSION" ] ; then
21+
hash -r
22+
fi
23+
24+
if [ -n "$_OLD_VIRTUAL_PS1" ] ; then
25+
PS1="$_OLD_VIRTUAL_PS1"
26+
export PS1
27+
unset _OLD_VIRTUAL_PS1
28+
fi
29+
30+
unset VIRTUAL_ENV
31+
if [ ! "$1" = "nondestructive" ] ; then
32+
# Self destruct!
33+
unset -f deactivate
34+
fi
35+
}
36+
37+
# unset irrelevant variables
38+
deactivate nondestructive
39+
40+
VIRTUAL_ENV="/home/tmkn/Code/wagtail-personalisation/ve"
41+
export VIRTUAL_ENV
42+
43+
_OLD_VIRTUAL_PATH="$PATH"
44+
PATH="$VIRTUAL_ENV/bin:$PATH"
45+
export PATH
46+
47+
# unset PYTHONHOME if set
48+
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
49+
# could use `if (set -u; : $PYTHONHOME) ;` in bash
50+
if [ -n "$PYTHONHOME" ] ; then
51+
_OLD_VIRTUAL_PYTHONHOME="$PYTHONHOME"
52+
unset PYTHONHOME
53+
fi
54+
55+
if [ -z "$VIRTUAL_ENV_DISABLE_PROMPT" ] ; then
56+
_OLD_VIRTUAL_PS1="$PS1"
57+
if [ "x(ve) " != x ] ; then
58+
PS1="(ve) $PS1"
59+
else
60+
if [ "`basename \"$VIRTUAL_ENV\"`" = "__" ] ; then
61+
# special case for Aspen magic directories
62+
# see http://www.zetadev.com/software/aspen/
63+
PS1="[`basename \`dirname \"$VIRTUAL_ENV\"\``] $PS1"
64+
else
65+
PS1="(`basename \"$VIRTUAL_ENV\"`)$PS1"
66+
fi
67+
fi
68+
export PS1
69+
fi
70+
71+
# This should detect bash and zsh, which have a hash command that must
72+
# be called to get it to forget past commands. Without forgetting
73+
# past commands the $PATH changes we made may not be respected
74+
if [ -n "$BASH" -o -n "$ZSH_VERSION" ] ; then
75+
hash -r
76+
fi

ve/bin/activate.csh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# This file must be used with "source bin/activate.csh" *from csh*.
2+
# You cannot run it directly.
3+
# Created by Davide Di Blasi <davidedb@gmail.com>.
4+
# Ported to Python 3.3 venv by Andrew Svetlov <andrew.svetlov@gmail.com>
5+
6+
alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PATH" && unset _OLD_VIRTUAL_PATH; rehash; test $?_OLD_VIRTUAL_PROMPT != 0 && set prompt="$_OLD_VIRTUAL_PROMPT" && unset _OLD_VIRTUAL_PROMPT; unsetenv VIRTUAL_ENV; test "\!:*" != "nondestructive" && unalias deactivate'
7+
8+
# Unset irrelevant variables.
9+
deactivate nondestructive
10+
11+
setenv VIRTUAL_ENV "/home/tmkn/Code/wagtail-personalisation/ve"
12+
13+
set _OLD_VIRTUAL_PATH="$PATH"
14+
setenv PATH "$VIRTUAL_ENV/bin:$PATH"
15+
16+
17+
set _OLD_VIRTUAL_PROMPT="$prompt"
18+
19+
if (! "$?VIRTUAL_ENV_DISABLE_PROMPT") then
20+
if ("ve" != "") then
21+
set env_name = "ve"
22+
else
23+
if (`basename "VIRTUAL_ENV"` == "__") then
24+
# special case for Aspen magic directories
25+
# see http://www.zetadev.com/software/aspen/
26+
set env_name = `basename \`dirname "$VIRTUAL_ENV"\``
27+
else
28+
set env_name = `basename "$VIRTUAL_ENV"`
29+
endif
30+
endif
31+
set prompt = "[$env_name] $prompt"
32+
unset env_name
33+
endif
34+
35+
alias pydoc python -m pydoc
36+
37+
rehash

ve/bin/activate.fish

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# This file must be used with ". bin/activate.fish" *from fish* (http://fishshell.org)
2+
# you cannot run it directly
3+
4+
function deactivate -d "Exit virtualenv and return to normal shell environment"
5+
# reset old environment variables
6+
if test -n "$_OLD_VIRTUAL_PATH"
7+
set -gx PATH $_OLD_VIRTUAL_PATH
8+
set -e _OLD_VIRTUAL_PATH
9+
end
10+
if test -n "$_OLD_VIRTUAL_PYTHONHOME"
11+
set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME
12+
set -e _OLD_VIRTUAL_PYTHONHOME
13+
end
14+
15+
if test -n "$_OLD_FISH_PROMPT_OVERRIDE"
16+
functions -e fish_prompt
17+
set -e _OLD_FISH_PROMPT_OVERRIDE
18+
functions -c _old_fish_prompt fish_prompt
19+
functions -e _old_fish_prompt
20+
end
21+
22+
set -e VIRTUAL_ENV
23+
if test "$argv[1]" != "nondestructive"
24+
# Self destruct!
25+
functions -e deactivate
26+
end
27+
end
28+
29+
# unset irrelevant variables
30+
deactivate nondestructive
31+
32+
set -gx VIRTUAL_ENV "/home/tmkn/Code/wagtail-personalisation/ve"
33+
34+
set -gx _OLD_VIRTUAL_PATH $PATH
35+
set -gx PATH "$VIRTUAL_ENV/bin" $PATH
36+
37+
# unset PYTHONHOME if set
38+
if set -q PYTHONHOME
39+
set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME
40+
set -e PYTHONHOME
41+
end
42+
43+
if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"
44+
# fish uses a function instead of an env var to generate the prompt.
45+
46+
# save the current fish_prompt function as the function _old_fish_prompt
47+
functions -c fish_prompt _old_fish_prompt
48+
49+
# with the original prompt function renamed, we can override with our own.
50+
function fish_prompt
51+
# Save the return status of the last command
52+
set -l old_status $status
53+
54+
# Prompt override?
55+
if test -n "(ve) "
56+
printf "%s%s" "(ve) " (set_color normal)
57+
else
58+
# ...Otherwise, prepend env
59+
set -l _checkbase (basename "$VIRTUAL_ENV")
60+
if test $_checkbase = "__"
61+
# special case for Aspen magic directories
62+
# see http://www.zetadev.com/software/aspen/
63+
printf "%s[%s]%s " (set_color -b blue white) (basename (dirname "$VIRTUAL_ENV")) (set_color normal)
64+
else
65+
printf "%s(%s)%s" (set_color -b blue white) (basename "$VIRTUAL_ENV") (set_color normal)
66+
end
67+
end
68+
69+
# Restore the return status of the previous command.
70+
echo "exit $old_status" | .
71+
_old_fish_prompt
72+
end
73+
74+
set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV"
75+
end

0 commit comments

Comments
 (0)