Skip to content

Commit

Permalink
Add example to the sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
tm-kn committed Jun 5, 2017
1 parent 543fb8a commit d7d63ad
Show file tree
Hide file tree
Showing 9,867 changed files with 1,489,684 additions and 49 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 1 addition & 1 deletion sandbox/sandbox/apps/home/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
('wagtailcore', '0033_remove_golive_expiry_help_text'),
('wagtailcore', '0001_initial'),
('wagtail_personalisation', '0011_personalisablepagemetadata'),
]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.1 on 2017-05-31 11:29
# Generated by Django 1.11.1 on 2017-05-31 16:15
from __future__ import unicode_literals

from django.db import migrations, models
Expand All @@ -13,8 +13,8 @@
class Migration(migrations.Migration):

dependencies = [
('wagtailcore', '0033_remove_golive_expiry_help_text'),
('pages', '0002_auto_20170531_0915'),
('wagtailcore', '0001_initial'),
('home', '0003_homepage_text_content'),
]

operations = [
Expand Down
30 changes: 27 additions & 3 deletions sandbox/sandbox/apps/home/models.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from __future__ import absolute_import, unicode_literals

from wagtail.wagtailadmin.edit_handlers import RichTextFieldPanel, StreamFieldPanel
from django.utils.translation import ugettext_lazy as _

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_personalisation.blocks import (PersonalisedCharBlock,
PersonalisedImageChooserBlock, PersonalisedRichTextBlock,
PersonalisedStructBlock, PersonalisedTextBlock)
from wagtail_personalisation.models import PersonalisablePageMixin
from wagtail_personalisation.blocks import PersonalisedStructBlock


class HomePage(PersonalisablePageMixin, Page):
intro = RichTextField()
Expand All @@ -21,3 +24,24 @@ class HomePage(PersonalisablePageMixin, Page):
RichTextFieldPanel('intro'),
StreamFieldPanel('body'),
]


class PersonalisedFieldsPage(Page):
body = StreamField([
('personalised_block', PersonalisedStructBlock([
('heading', blocks.CharBlock()),
('paragraph', blocks.RichTextBlock())
], render_fields=['heading', 'paragraph'])),
('personalised_block_template', PersonalisedStructBlock([
('heading', blocks.CharBlock()),
('paragraph', blocks.RichTextBlock())
], template='blocks/personalised_block_template.html', label=_('Block with template'))),
('personalised_rich_text_block', PersonalisedRichTextBlock()),
('personalised_image', PersonalisedImageChooserBlock()),
('personalised_char', PersonalisedCharBlock()),
('personalised_text', PersonalisedTextBlock()),
])

content_panels = Page.content_panels + [
StreamFieldPanel('body')
]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% load wagtailcore_tags %}

<div class="personalisation-block-template">
<div class="personalisation-block-template" style="background-color: cornsilk;">
<p>This is a block with <strong>template</strong>.</p>
<h2>Heading: {{ value.heading }}</h2>
<div>
Expand Down
19 changes: 14 additions & 5 deletions src/wagtail_personalisation/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ def __init__(self, *args, **kwargs):
Keyword Arguments:
render_fields: List with field names to be rendered or None to use
the default block rendering.
the default block rendering. Please set to None if using block
with template since then it's the template that takes care
of what fields are rendered.
"""
render_fields = kwargs.pop('render_fields',
self._meta_class.render_fields)
super(BasePersonalisedStructBlock, self).__init__(*args, **kwargs)

# Check "render_fields" are either a list or None.
if isinstance(render_fields, tuple):
render_fields = list(render_fields)

Expand All @@ -51,7 +54,13 @@ def __init__(self, *args, **kwargs):
raise ValueError('"render_fields" has to contain name(s) of the '
'specified blocks.')
else:
setattr(self._meta_class, 'render_fields', render_fields)
setattr(self.meta, 'render_fields', render_fields)

# Template can be used only when "render_fields" is set to None.
if self.meta.render_fields is not None \
and getattr(self.meta, 'template', None):
raise ValueError('"render_fields" has to be set to None when using '
'template.')


def is_visible(self, value, request):
Expand Down Expand Up @@ -87,13 +96,13 @@ def render(self, value, context=None):
if not self.is_visible(value, context['request']):
return ""

if self._meta_class.render_fields is None:
if self.meta.render_fields is None:
return super(BasePersonalisedStructBlock, self).render(
value, context)

if isinstance(self._meta_class.render_fields, list):
if isinstance(self.meta.render_fields, list):
render_value = ''
for field_name in self._meta_class.render_fields:
for field_name in self.meta.render_fields:
if hasattr(value.bound_blocks[field_name], 'render_as_block'):
block_value = value.bound_blocks[field_name] \
.render_as_block(context=context)
Expand Down
36 changes: 0 additions & 36 deletions tests/unit/test_blocks.py

This file was deleted.

76 changes: 76 additions & 0 deletions ve/bin/activate
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# This file must be used with "source bin/activate" *from bash*
# you cannot run it directly

deactivate () {
# reset old environment variables
if [ -n "$_OLD_VIRTUAL_PATH" ] ; then
PATH="$_OLD_VIRTUAL_PATH"
export PATH
unset _OLD_VIRTUAL_PATH
fi
if [ -n "$_OLD_VIRTUAL_PYTHONHOME" ] ; then
PYTHONHOME="$_OLD_VIRTUAL_PYTHONHOME"
export PYTHONHOME
unset _OLD_VIRTUAL_PYTHONHOME
fi

# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "$BASH" -o -n "$ZSH_VERSION" ] ; then
hash -r
fi

if [ -n "$_OLD_VIRTUAL_PS1" ] ; then
PS1="$_OLD_VIRTUAL_PS1"
export PS1
unset _OLD_VIRTUAL_PS1
fi

unset VIRTUAL_ENV
if [ ! "$1" = "nondestructive" ] ; then
# Self destruct!
unset -f deactivate
fi
}

# unset irrelevant variables
deactivate nondestructive

VIRTUAL_ENV="/home/tmkn/Code/wagtail-personalisation/ve"
export VIRTUAL_ENV

_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/bin:$PATH"
export PATH

# unset PYTHONHOME if set
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
# could use `if (set -u; : $PYTHONHOME) ;` in bash
if [ -n "$PYTHONHOME" ] ; then
_OLD_VIRTUAL_PYTHONHOME="$PYTHONHOME"
unset PYTHONHOME
fi

if [ -z "$VIRTUAL_ENV_DISABLE_PROMPT" ] ; then
_OLD_VIRTUAL_PS1="$PS1"
if [ "x(ve) " != x ] ; then
PS1="(ve) $PS1"
else
if [ "`basename \"$VIRTUAL_ENV\"`" = "__" ] ; then
# special case for Aspen magic directories
# see http://www.zetadev.com/software/aspen/
PS1="[`basename \`dirname \"$VIRTUAL_ENV\"\``] $PS1"
else
PS1="(`basename \"$VIRTUAL_ENV\"`)$PS1"
fi
fi
export PS1
fi

# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "$BASH" -o -n "$ZSH_VERSION" ] ; then
hash -r
fi
37 changes: 37 additions & 0 deletions ve/bin/activate.csh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This file must be used with "source bin/activate.csh" *from csh*.
# You cannot run it directly.
# Created by Davide Di Blasi <[email protected]>.
# Ported to Python 3.3 venv by Andrew Svetlov <[email protected]>

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'

# Unset irrelevant variables.
deactivate nondestructive

setenv VIRTUAL_ENV "/home/tmkn/Code/wagtail-personalisation/ve"

set _OLD_VIRTUAL_PATH="$PATH"
setenv PATH "$VIRTUAL_ENV/bin:$PATH"


set _OLD_VIRTUAL_PROMPT="$prompt"

if (! "$?VIRTUAL_ENV_DISABLE_PROMPT") then
if ("ve" != "") then
set env_name = "ve"
else
if (`basename "VIRTUAL_ENV"` == "__") then
# special case for Aspen magic directories
# see http://www.zetadev.com/software/aspen/
set env_name = `basename \`dirname "$VIRTUAL_ENV"\``
else
set env_name = `basename "$VIRTUAL_ENV"`
endif
endif
set prompt = "[$env_name] $prompt"
unset env_name
endif

alias pydoc python -m pydoc

rehash
75 changes: 75 additions & 0 deletions ve/bin/activate.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# This file must be used with ". bin/activate.fish" *from fish* (http://fishshell.org)
# you cannot run it directly

function deactivate -d "Exit virtualenv and return to normal shell environment"
# reset old environment variables
if test -n "$_OLD_VIRTUAL_PATH"
set -gx PATH $_OLD_VIRTUAL_PATH
set -e _OLD_VIRTUAL_PATH
end
if test -n "$_OLD_VIRTUAL_PYTHONHOME"
set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME
set -e _OLD_VIRTUAL_PYTHONHOME
end

if test -n "$_OLD_FISH_PROMPT_OVERRIDE"
functions -e fish_prompt
set -e _OLD_FISH_PROMPT_OVERRIDE
functions -c _old_fish_prompt fish_prompt
functions -e _old_fish_prompt
end

set -e VIRTUAL_ENV
if test "$argv[1]" != "nondestructive"
# Self destruct!
functions -e deactivate
end
end

# unset irrelevant variables
deactivate nondestructive

set -gx VIRTUAL_ENV "/home/tmkn/Code/wagtail-personalisation/ve"

set -gx _OLD_VIRTUAL_PATH $PATH
set -gx PATH "$VIRTUAL_ENV/bin" $PATH

# unset PYTHONHOME if set
if set -q PYTHONHOME
set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME
set -e PYTHONHOME
end

if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"
# fish uses a function instead of an env var to generate the prompt.

# save the current fish_prompt function as the function _old_fish_prompt
functions -c fish_prompt _old_fish_prompt

# with the original prompt function renamed, we can override with our own.
function fish_prompt
# Save the return status of the last command
set -l old_status $status

# Prompt override?
if test -n "(ve) "
printf "%s%s" "(ve) " (set_color normal)
else
# ...Otherwise, prepend env
set -l _checkbase (basename "$VIRTUAL_ENV")
if test $_checkbase = "__"
# special case for Aspen magic directories
# see http://www.zetadev.com/software/aspen/
printf "%s[%s]%s " (set_color -b blue white) (basename (dirname "$VIRTUAL_ENV")) (set_color normal)
else
printf "%s(%s)%s" (set_color -b blue white) (basename "$VIRTUAL_ENV") (set_color normal)
end
end

# Restore the return status of the previous command.
echo "exit $old_status" | .
_old_fish_prompt
end

set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV"
end
11 changes: 11 additions & 0 deletions ve/bin/chardetect
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/home/tmkn/Code/wagtail-personalisation/ve/bin/python3.5

# -*- coding: utf-8 -*-
import re
import sys

from chardet.cli.chardetect import main

if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
11 changes: 11 additions & 0 deletions ve/bin/coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/home/tmkn/Code/wagtail-personalisation/ve/bin/python3.5

# -*- coding: utf-8 -*-
import re
import sys

from coverage.cmdline import main

if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
11 changes: 11 additions & 0 deletions ve/bin/coverage-3.5
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/home/tmkn/Code/wagtail-personalisation/ve/bin/python3.5

# -*- coding: utf-8 -*-
import re
import sys

from coverage.cmdline import main

if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
Loading

0 comments on commit d7d63ad

Please sign in to comment.