API Reference

fancypages.get_fancypages_paths(path, use_with_oscar=False)

Get absolute paths for path relative to the project root

Models

class fancypages.abstract_models.AbstractPageGroup(*args, **kwargs)

A page group provides a way to group fancy pages and retrieve only pages within a specific group.

Parameters:
  • uuid (ShortUUIDField) – Unique id
  • name (CharField) – Name
  • slug (SlugField) – Slug
class fancypages.abstract_models.AbstractPageNode(*args, **kwargs)

Define the tree structure properties of the fancy page. This is a separate abstract class to make sure that it can be easily replaced by another tree handling library or none if needed.

Parameters:
  • path (CharField) – Path
  • depth (PositiveIntegerField) – Depth
  • numchild (PositiveIntegerField) – Numchild
  • name (CharField) – Name
  • slug (SlugField) – Slug
  • image (ImageField) – Image
  • description (TextField) – Description
move(target, pos=None)

Moves the current node and all its descendants to a new position relative to another node.

See https://tabo.pe/projects/django-treebeard/docs/1.61/api.html

Mixins

class fancypages.mixins.TemplateNamesModelMixin

Mixin that provides a generalised way of generating template names for a a Django model. It uses relies on at least one of two class attributes: template_name and default_template_names to generate a list of templates to look for according to Django’s rules for template lookup.

The template_name attribute specifies a specific template to be used when rendering this model. If this attribute is not None it takes precedence over all other template names and therefore will appear at the top of the templates. The default_template_names is a list of template names that provides default behaviour and a fallback in case no template name is given or it can’t be found by the template engine. Specifying both a template name and a list of default templates will result in a list of template names similar to this:

>>> from django.db import models
>>> from fancypages.mixins import TemplateNamesModelMixin
>>>
>>> class Container(TemplateNamesModelMixin, models.Model):
...     template_name = 'container.html'
...     default_template_names = ['default_container.html']
...
...     class Meta: app_label = 'fakeapp'
>>>
>>>
>>> c = Container()
>>> c.get_template_names()
['container.html', 'default_container.html']

Each template name provided in template_name or default_template_names is also run through standard Python string formatting providing the model name as provide in self._meta.module_name which allows parametrized template names. Additional keyword arguments can be passed into get_template_names to provide additional formatting keywords. Here’s an example:

>>> class Pony(TemplateNamesModelMixin, models.Model):
...     template_name = 'container_{module_name}_{magic}.html'
...
...     class Meta: app_label = 'fakeapp'
>>>
>>> c = Pony()
>>> c.get_template_names(magic='rainbow')
['container_pony_rainbow.html']

In addition to the above, language-specific template names are added if the model has a language_code attribute specified. This allows different templates for different languages to customise the appearance of the rendered data based on the language. This makes sense for langugages such as Persian where the reading direction is from left to right. Language-specific templates have the corresponding language code added as a suffix to the filename just before the file extension. In cases such as English where the language is split up into different regions such as British (en-gb) and American English (en-us) a generic template for ‘en’ is added as well. For a British language code this will be the list of templates:

>>> class Pony(TemplateNamesModelMixin, models.Model):
...     template_name = '{module_name}.html'
...     language_code = models.CharField(max_length=6)
...
...     class Meta: app_label = 'fakeapp'
>>>
>>> c = Pony(language_code='en-gb')
>>> c.get_template_names()
['pony_en-gb.html', 'pony_en.html', 'pony.html']
get_template_names(**kwargs)

Get a list of template names in order of precedence as used by the Django template engine. Keyword argument passed in are used during string formatting of the template names. This fails silently if a argument is specified in a template name but is not present in kwargs.

Rtype list:A list of template names (unicode).

Blocks

class fancypages.models.blocks.content.CarouselBlock(*args, **kwargs)

CarouselBlock(id, uuid, container_id, display_order, contentblock_ptr_id)

Parameters:
  • id (AutoField) – Id
  • uuid (ShortUUIDField) – Unique id
  • container_id (ForeignKey) – Container
  • display_order (PositiveIntegerField) – Display order
  • contentblock_ptr_id (OneToOneField) – Contentblock ptr
  • link_url_1 (CharField) – Link url 1
  • link_url_2 (CharField) – Link url 2
  • link_url_3 (CharField) – Link url 3
  • link_url_4 (CharField) – Link url 4
  • link_url_5 (CharField) – Link url 5
  • link_url_6 (CharField) – Link url 6
  • link_url_7 (CharField) – Link url 7
  • link_url_8 (CharField) – Link url 8
  • link_url_9 (CharField) – Link url 9
  • link_url_10 (CharField) – Link url 10
  • image_1_id (AssetKey) – Image 1
  • image_2_id (AssetKey) – Image 2
  • image_3_id (AssetKey) – Image 3
  • image_4_id (AssetKey) – Image 4
  • image_5_id (AssetKey) – Image 5
  • image_6_id (AssetKey) – Image 6
  • image_7_id (AssetKey) – Image 7
  • image_8_id (AssetKey) – Image 8
  • image_9_id (AssetKey) – Image 9
  • image_10_id (AssetKey) – Image 10
class fancypages.models.blocks.content.ContentBlock(*args, **kwargs)

ContentBlock(id, uuid, container_id, display_order)

Parameters:
  • id (AutoField) – Id
  • uuid (ShortUUIDField) – Unique id
  • container_id (ForeignKey) – Container
  • display_order (PositiveIntegerField) – Display order
class fancypages.models.blocks.content.FormBlock(*args, **kwargs)

FormBlock(id, uuid, container_id, display_order, contentblock_ptr_id, form_selection)

Parameters:
  • id (AutoField) – Id
  • uuid (ShortUUIDField) – Unique id
  • container_id (ForeignKey) – Container
  • display_order (PositiveIntegerField) – Display order
  • contentblock_ptr_id (OneToOneField) – Contentblock ptr
  • form_selection (CharField) – Form selection
class fancypages.models.blocks.content.ImageAndTextBlock(*args, **kwargs)

ImageAndTextBlock(id, uuid, container_id, display_order, contentblock_ptr_id, title, alt_text, link, image_asset_id, text)

Parameters:
  • id (AutoField) – Id
  • uuid (ShortUUIDField) – Unique id
  • container_id (ForeignKey) – Container
  • display_order (PositiveIntegerField) – Display order
  • contentblock_ptr_id (OneToOneField) – Contentblock ptr
  • title (CharField) – Image title
  • alt_text (CharField) – Alternative text
  • link (CharField) – Link url
  • image_asset_id (AssetKey) – Image asset
  • text (TextField) – Text
class fancypages.models.blocks.content.ImageBlock(*args, **kwargs)

ImageBlock(id, uuid, container_id, display_order, contentblock_ptr_id, title, alt_text, link, image_asset_id)

Parameters:
  • id (AutoField) – Id
  • uuid (ShortUUIDField) – Unique id
  • container_id (ForeignKey) – Container
  • display_order (PositiveIntegerField) – Display order
  • contentblock_ptr_id (OneToOneField) – Contentblock ptr
  • title (CharField) – Image title
  • alt_text (CharField) – Alternative text
  • link (CharField) – Link url
  • image_asset_id (AssetKey) – Image asset
class fancypages.models.blocks.content.PageNavigationBlock(*args, **kwargs)

PageNavigationBlock(id, uuid, container_id, display_order, contentblock_ptr_id, depth, origin)

Parameters:
  • id (AutoField) – Id
  • uuid (ShortUUIDField) – Unique id
  • container_id (ForeignKey) – Container
  • display_order (PositiveIntegerField) – Display order
  • contentblock_ptr_id (OneToOneField) – Contentblock ptr
  • depth (PositiveIntegerField) – Navigation depth
  • origin (CharField) – Navigation origin
class fancypages.models.blocks.content.TextBlock(*args, **kwargs)

TextBlock(id, uuid, container_id, display_order, contentblock_ptr_id, text)

Parameters:
  • id (AutoField) – Id
  • uuid (ShortUUIDField) – Unique id
  • container_id (ForeignKey) – Container
  • display_order (PositiveIntegerField) – Display order
  • contentblock_ptr_id (OneToOneField) – Contentblock ptr
  • text (TextField) – Text
class fancypages.models.blocks.content.TitleTextBlock(*args, **kwargs)

TitleTextBlock(id, uuid, container_id, display_order, contentblock_ptr_id, title, text)

Parameters:
  • id (AutoField) – Id
  • uuid (ShortUUIDField) – Unique id
  • container_id (ForeignKey) – Container
  • display_order (PositiveIntegerField) – Display order
  • contentblock_ptr_id (OneToOneField) – Contentblock ptr
  • title (CharField) – Title
  • text (TextField) – Text
class fancypages.models.blocks.layouts.FourColumnLayoutBlock(*args, **kwargs)

FourColumnLayoutBlock(id, uuid, container_id, display_order, contentblock_ptr_id)

Parameters:
  • id (AutoField) – Id
  • uuid (ShortUUIDField) – Unique id
  • container_id (ForeignKey) – Container
  • display_order (PositiveIntegerField) – Display order
  • contentblock_ptr_id (OneToOneField) – Contentblock ptr
class fancypages.models.blocks.layouts.HorizontalSeparatorBlock(*args, **kwargs)

HorizontalSeparatorBlock(id, uuid, container_id, display_order, contentblock_ptr_id)

Parameters:
  • id (AutoField) – Id
  • uuid (ShortUUIDField) – Unique id
  • container_id (ForeignKey) – Container
  • display_order (PositiveIntegerField) – Display order
  • contentblock_ptr_id (OneToOneField) – Contentblock ptr
class fancypages.models.blocks.layouts.TabBlock(*args, **kwargs)

TabBlock(id, uuid, container_id, display_order, contentblock_ptr_id)

Parameters:
  • id (AutoField) – Id
  • uuid (ShortUUIDField) – Unique id
  • container_id (ForeignKey) – Container
  • display_order (PositiveIntegerField) – Display order
  • contentblock_ptr_id (OneToOneField) – Contentblock ptr
class fancypages.models.blocks.layouts.ThreeColumnLayoutBlock(*args, **kwargs)

ThreeColumnLayoutBlock(id, uuid, container_id, display_order, contentblock_ptr_id)

Parameters:
  • id (AutoField) – Id
  • uuid (ShortUUIDField) – Unique id
  • container_id (ForeignKey) – Container
  • display_order (PositiveIntegerField) – Display order
  • contentblock_ptr_id (OneToOneField) – Contentblock ptr
class fancypages.models.blocks.layouts.TwoColumnLayoutBlock(*args, **kwargs)

TwoColumnLayoutBlock(id, uuid, container_id, display_order, contentblock_ptr_id, left_width)

Parameters:
  • id (AutoField) – Id
  • uuid (ShortUUIDField) – Unique id
  • container_id (ForeignKey) – Container
  • display_order (PositiveIntegerField) – Display order
  • contentblock_ptr_id (OneToOneField) – Contentblock ptr
  • left_width (PositiveIntegerField) – Left width
left_span

Returns the bootstrap span class for the left container.

right_span

Returns the bootstrap span class for the left container.

class fancypages.models.blocks.social.TwitterBlock(*args, **kwargs)

TwitterBlock(id, uuid, container_id, display_order, contentblock_ptr_id, username, max_tweets)

Parameters:
  • id (AutoField) – Id
  • uuid (ShortUUIDField) – Unique id
  • container_id (ForeignKey) – Container
  • display_order (PositiveIntegerField) – Display order
  • contentblock_ptr_id (OneToOneField) – Contentblock ptr
  • username (CharField) – Twitter username
  • max_tweets (PositiveIntegerField) – Maximum tweets
class fancypages.models.blocks.social.VideoBlock(*args, **kwargs)

VideoBlock(id, uuid, container_id, display_order, contentblock_ptr_id, source, video_code)

Parameters:
  • id (AutoField) – Id
  • uuid (ShortUUIDField) – Unique id
  • container_id (ForeignKey) – Container
  • display_order (PositiveIntegerField) – Display order
  • contentblock_ptr_id (OneToOneField) – Contentblock ptr
  • source (CharField) – Video type
  • video_code (CharField) – Video code

Template Tags

fancypages.templatetags.fp_container_tags.fp_block_container(parser, token)

Template tag for convenience to use within templates for e.g. layout blocks where the container is assigned to the widget rather then the object in the context. The same could be achieved using:

{% fp_object_container some-name fp_block %}
fancypages.templatetags.fp_container_tags.fp_object_container(parser, token)

Template tag specifying a fancypages container to be rendered in the template at the given location. It takes up to three arguments. The first argument is the name of the container which is mandatory. The object that this tag is attached to is the second argument and is optional. If it is not specified, the ‘object’ variable in the current context is used. The third argument is an optional language code that specify the language that should be used for the container. Without a language code specified, the current language is retrieved using Django’s internationalisation helpers.

Valid template tags are:

{% fp_object_container container-name %}

and with a specific object:

{% fp_object_container container-name my_object %}

and with a language code:

{% fp_object_container container-name my_object "de-de" %}
{% fp_object_container container-name object_name=my_object language="de-de" %}
fancypages.templatetags.fp_container_tags.parse_arguments(parser, token, params=None)

Parse positional arguments and keyword arguments into a dictionary for the known arguments given in params in the given order. If the number of arguments in token is greater than the known number of arguments, a TemplateSyntaxError is raised. The same is true if no tokens are provided.

Parameters:
  • parser – Parser as passed into the template tag.
  • token – Token object as passed into the template tag.
  • params – List of expected arguments in the order in which they appear when not using keyword arguments. Default to [‘container_name’, ‘object_name’, ‘language’].
Rtype dict:

containing the parsed content for the arguments above.

Editor Middleware

fancypages.middleware.replace_insensitive(string, target, replacement)

Similar to string.replace() but is case insensitive Code borrowed from: http://forums.devshed.com/python-programming-11/case-insensitive-string-replace-490921.html