Skip to main content

View and viewlet helper modules for Plone theme and five.grok developers

Project description

Introduction

collective.fastview provides framework level helper code for Plone view and template management. It is intended to be used to give some workarounds some rough corners on these Zope 3 and five.grok viewlewt frameworks.

Installation

Add collective.fastview to buildout.cfg eggs list:

eggs =
        ...
        collective.fastview

Render viewlets directly anywhere in the template

You can directly put in viewlet call to any page template code using a viewlet traverser. collective.fastview registers a view with name @@viewlets which you can use to traverse to render any viewlet code:

<div id="header">
    <div tal:replace="structure context/@@viewlets/plone.logo" />
</div>

Note that you still need to register viewlets against some (any) viewlet manager, but it can be a dummy one, which is never rendered using syntax:

<div tal:replace="structure provider:myarghyetanotherviewletmanagername" />

Example of dummy viewlet manager:

class MainViewletManager(grok.ViewletManager):
    """ This viewlet manager is responsible for all gomobiletheme.basic viewlet registrations.

    Viewlets are directly referred in main_template.pt by viewlet name,
    thus overriding Plone behavior to go through ViewletManager render step.
    """
    grok.name('gomobiletheme.basic.viewletmanager')

# Set viewlet manager default to all following viewlets
grok.viewletmanager(MainViewletManager)

Fix Grok 1.0 template inheritance

This fixes grok 1.0 problem that view and viewlets template are not inheritable between packages. E.g. if you subclass a view you need to manually copy over the view template also.

We hope to get rid of this in the future.

See:

Example:

from collective.fastview.utilities import fix_grok_template_inheritance
from gomobiletheme.basic import viewlets as base
from gomobiletheme.basic.viewlets import MainViewletManager
from plonecommunity.app.interfaces import IThemeLayer

# Viewlets are on all content by default.
grok.context(Interface)

# Use templates directory to search for templates.
grok.templatedir("templates")

# Viewlets are active only when gomobiletheme.basic theme layer is activated
grok.layer(IThemeLayer)

grok.viewletmanager(MainViewletManager)

class Head(base.Head):
    """
    My inherited viewlet.
    """


# Fix for grok 1.0 template inheritance
# https://bugs.launchpad.net/grok/+bug/255005
# This will force Head viewlet to use its parent class template
fix_grok_template_inheritance(Head, base.Head)

Examples

This code is mainly used with gomobiletheme.basic package to provide simple mobile themes without need to construct viewlet manager around every viewlet.

These Python packages use this code

Source code repository

Author

mFabrik Research Oy - Python and Plone professionals for hire.

Changelog

0.2.1 - 0.2.2

  • Fixed debug statement left in the code [miohtama]

0.2 - 0.2.1

  • Try to be smarter handling the cases where viewlet raises an exception on update() or render() [miohtama]

  • Cleaned up some docs [miohtama]

0.1 - 0.2

  • Plone 4 compatibility

  • Removed global defines special handlers - they were used for Plone 3, but Plone 4 is now out solving the problem itself

  • Added special exception type for the cases viewlet is not found by name. It was bad idea to return NotFound as Zope has special meaning for this exception (you get 404).

0.1

  • Initial release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

collective.fastview-0.2.2.zip (22.9 kB view details)

Uploaded Source

File details

Details for the file collective.fastview-0.2.2.zip.

File metadata

File hashes

Hashes for collective.fastview-0.2.2.zip
Algorithm Hash digest
SHA256 90df40831d3cd95863a31c3afebd2a063fb9c26096850ce16b8314295ab97bcf
MD5 f0390053400d2c04e9c6db23a06bca24
BLAKE2b-256 3dc0e61fcad0d35a4be12bbf2dfd280e267ee254f5001c58c040c8875b3eed7f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page