Open source cms for mobile and desktop websites

Element plugin example: Python configuration

python configuration example for a page element including new object type, data model, form definition and template

Scaffold download:

The module has to be in the current python path to be added to your website.

website.modules.append("nive_tmpl_element_python")

__init__.py

The modules __init__.py configures the plugin and sets it up as python module.

from nive.definitions import ObjectConf

configuration = ObjectConf(
    id="article",
    name="Article",
    dbparam="article",
    context="nive_cms.baseobjects.PageElementBase",
    template="nive_tmpl_element_python:article.pt",
    selectTag=20,
    description=""
)

configuration.data = [
    FieldConf(id="textblock", datatype="htext", size=10000, default="",
       name="Text", fulltext=1),
    FieldConf(id="image",     datatype="file",  size=0,     default="",
       name="Image file"),
    FieldConf(id="link",      datatype="url",   size=255,   default="",
       name="Link"),
]

configuration.forms = {
    "create": {"fields": ["title", "textblock", "image"]},
    "edit":   {"fields": ["title", "textblock", "image"]}
}

article.pt

The page template article.pt is used to render the contents on the web page.

<div class="pageelement peArticle" id="nive-element${context.GetID()}"
     tal:define="link view.ResolveLink(context.data.link)">

<div class="teaser">
<img tal:condition="context.files.get('image')"
          tal:attributes="src view.FileUrl('image', context);
                          title context.GetTitle()" />
<div class="itext">
<h3 tal:content="structure context.GetTitle()"/>
<p tal:condition="context.data.textblock"
   tal:replace="structure context.data.textblock"></p>
<a tal:condition="link" tal:attributes="href link">&gt; more</a>
</div>
</div>

</div>
© 2013 Nive GmbH