grokcore.viewlet


Namegrokcore.viewlet JSON
Version 4.0 PyPI version JSON
download
home_pagehttps://github.com/zopefoundation/grokcore.viewlet
SummaryGrok-like configuration for zope viewlets
upload_time2023-08-28 09:28:06
maintainer
docs_urlNone
authorGrok Team
requires_python
licenseZPL
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            This package provides support to write and register Zope Viewlets
directly in Python (without ZCML). It's designed to be used with
`grokcore.view`_ which let you write and register Zope Views.

.. contents::

Setting up ``grokcore.viewlet``
===============================

This package is set up like the `grokcore.component`_
package. Please refer to its documentation for more details. The
additional ZCML lines you will need are::

  <include package="grokcore.viewlet" file="meta.zcml" />
  <include package="grokcore.viewlet" />

Put the first line somewhere near the top of your root ZCML file.

Examples
========

First we need a view to call our viewlet manager::

   from grokcore import viewlet

   class Index(viewlet.View):
       pass

   index = viewlet.Page Template("""
   <html>
     <head>Test</head>
     <body>
       <div tail:content="structure provider:content">
       </div>
     </body>
   </html>
   """)

After that we could define only a manager which display something::

   class Content(viewlet.ViewletManager):
       viewlet.View(Index)

       def render(self):
           return u'<h1>Hello World</h1>'


Or a completely different example::

   class AdvancedContent(viewlet.ViewletManager):
       viewlet.name('content')
       viewlet.view(Index)

And some viewlets for that one::

   class StaticData(viewlet.Viewlet):
       viewlet.view(Index)
       viewlet.viewletmanager(AdvancedContent)

       def render(self):
           return f'<p> Data from {self.context.id}</p>'

Or::

   class SecretData(viewlet.Viewlet):
       viewlet.view(Index)
       viewlet.viewletmanager(AdvancedContent)
       viewlet.require('agent.secret')

   secretdata = viewlet.PageTemplate("""
     <p>Nothing to see here.</p>
   """)

The way templates are bound to components works exactly the way as
in `grokcore.view`_, for more information refer to its
documentation.

API Overview
============

Base classes
------------

``ViewletManager``
  Define a new viewlet manager. You can either provide a render
  method, a template, which can or not use registered viewlets.

  If you define a template, ``view`` is added as a reference to the
  current view for which the manager is rendering in the template's
  namespace. It is available as well as an attribute on the manager
  object.

``Viewlet``
  Define a new viewlet. You can either provide a template or a render
  method on it. Like in views, you can define an update method to
  process needed data.

  Like for manager, ``view`` is added to the template namespace if
  used. ``viewletmanager`` is defined as well as a reference to the
  manager in the template's namespace and as an attribute on the
  viewlet object.

Directives
----------

You can use directives from `grokcore.view`_ to register your
viewlet or viewlet manager: ``name``, ``context``, ``layer`` and
``require`` (for security on a viewlet).

To that is added:

``view``
   Select for which view is registered a viewlet or a viewlet manager.

``viewletmanager``
   Select for which viewlet manager is registered a viewlet.

``order``
   Define a rendering order for viewlets in a viewlet manager. This
   should be a number, the smaller order render first, bigger last.


Additionally, the ``grokcore.viewlet`` package exposes the
`grokcore.component`_, `grokcore.security`_ and `grokcore.view`_ APIs.

.. _grokcore.component: https://pypi.org/project/grokcore.component
.. _grokcore.viewlet: https://pypi.org/project/grokcore.viewlet
.. _grokcore.security: https://pypi.org/project/grokcore.security
.. _grokcore.view: https://pypi.org/project/grokcore.view

Changes
=======

4.0 (2023-08-28)
----------------

* Add support for Python 3.7, 3.8, 3.9, 3.10, 3.11.

* Drop support for Python 2.7, 3.4, 3.5, 3.6.


3.1.0 (2018-02-05)
------------------

* viewletmanager.viewlets should be a list so we can iterate over it several
  times in consumer code instead of having to remember it's an iterable we can
  only list once.

3.0.1 (2018-01-12)
------------------

* Rearrange tests such that Travis CI can pick up all functional tests too.

3.0.0 (2018-01-04)
------------------

* Python 3 compatibility.

1.11 (2012-09-04)
-----------------

* Make the ``has_render()`` and ``has_no_render()`` symmetrical to those
  in grokcore.view, grokcore.layout and grokcore.formlib, where a
  ``render.base_method`` attribute is checked.

1.10.1 (2012-05-02)
-------------------

* Do not require the role extra from grokcore.security.

1.10 (2012-05-02)
-----------------

* Use the component registration api from grokcore.component.

* Update how the static resources are found on a ``ViewletManager``
  and a ``Viewlet``, following the new name ``__static_name__`` set by
  the template association.

1.9 (2011-06-28)
----------------

* Introduce the `available()` method on viewlet component. The viewlet
  manager will filter out unavailable viewlet by calling this method. The
  `available()` method is called *after* the viewlet's `update()` is called,
  but *before* the `render()` is called.

1.8 (2010-12-16)
----------------

* Update to use TemplateGrokker from grokcore.view to associate
  viewlet and viewletmanager templates.

1.7 (2010-11-03)
----------------

* The computed default value for the viewletmanager directive is now defined
  in the directiv itself, not as a separate function that needs to be passed
  along.

1.6 (2010-11-01)
----------------

* Upped version requirements for martian, grokcore.component, and grokcore.view.

* Move the order directive to grokcore.component.

* Move the view directive to grokcore.view.

1.5 (2010-10-18)
----------------

* Make package comply to zope.org repository policy.

* Update functional tests to use Browser implementation of zope.app.wsgi
  instead of zope.app.testing.

* Reduce dependencies (zope.app.pagetemplate no longer necessary).

1.4.1 (2010-02-28)
------------------

* Dropped the dependency on ``zope.app.zcmlfiles``.

* Cleaned the code to remove unused imports and ensure the pep8 syntax.

* Updated tests to have a return value consistency. The
  grokcore.viewlet viewlet manager implementation requires viewlets to
  return unicode strings. Now, viewlets return unicode strings in the
  test packages.

1.4 (2010-02-19)
----------------

* Define test requires.

1.3 (2009-09-17)
----------------

* Reverted the use of grokcore.view.CodeView. We now require
  ``grokcore.view`` 1.12.1 or newer. As of ``grokcore.view`` 1.12, the
  CodeView/View separation has been undone.

1.2 (2009-09-16)
----------------

* Remove the reference to the grok.View permission that is no longer in
  grokcore.security 1.2

* Use the grok.zope.org/releaseinfo information instead of our own
  copy of ``versions.cfg``, for easier maintenance.


1.1 (2009-07-20)
----------------

* Adapted tests to new grokcore.view release: switched from View to CodeView.

* Add grok.View permissions to functional tests (requires grokcore.security
  1.1)

1.0 (2008-11-15)
----------------

* Created ``grokcore.viewlet`` in November 2008 by factoring
  ``zope.viewlet``-based components, grokkers and directives out of
  Grok.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/zopefoundation/grokcore.viewlet",
    "name": "grokcore.viewlet",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Grok Team",
    "author_email": "grok-dev@zope.org",
    "download_url": "https://files.pythonhosted.org/packages/d8/a5/e5043dfa84847fde2db39ccf7509bd1c78d6db52a526bc95ea0c4c0cc04b/grokcore.viewlet-4.0.tar.gz",
    "platform": null,
    "description": "This package provides support to write and register Zope Viewlets\ndirectly in Python (without ZCML). It's designed to be used with\n`grokcore.view`_ which let you write and register Zope Views.\n\n.. contents::\n\nSetting up ``grokcore.viewlet``\n===============================\n\nThis package is set up like the `grokcore.component`_\npackage. Please refer to its documentation for more details. The\nadditional ZCML lines you will need are::\n\n  <include package=\"grokcore.viewlet\" file=\"meta.zcml\" />\n  <include package=\"grokcore.viewlet\" />\n\nPut the first line somewhere near the top of your root ZCML file.\n\nExamples\n========\n\nFirst we need a view to call our viewlet manager::\n\n   from grokcore import viewlet\n\n   class Index(viewlet.View):\n       pass\n\n   index = viewlet.Page Template(\"\"\"\n   <html>\n     <head>Test</head>\n     <body>\n       <div tail:content=\"structure provider:content\">\n       </div>\n     </body>\n   </html>\n   \"\"\")\n\nAfter that we could define only a manager which display something::\n\n   class Content(viewlet.ViewletManager):\n       viewlet.View(Index)\n\n       def render(self):\n           return u'<h1>Hello World</h1>'\n\n\nOr a completely different example::\n\n   class AdvancedContent(viewlet.ViewletManager):\n       viewlet.name('content')\n       viewlet.view(Index)\n\nAnd some viewlets for that one::\n\n   class StaticData(viewlet.Viewlet):\n       viewlet.view(Index)\n       viewlet.viewletmanager(AdvancedContent)\n\n       def render(self):\n           return f'<p> Data from {self.context.id}</p>'\n\nOr::\n\n   class SecretData(viewlet.Viewlet):\n       viewlet.view(Index)\n       viewlet.viewletmanager(AdvancedContent)\n       viewlet.require('agent.secret')\n\n   secretdata = viewlet.PageTemplate(\"\"\"\n     <p>Nothing to see here.</p>\n   \"\"\")\n\nThe way templates are bound to components works exactly the way as\nin `grokcore.view`_, for more information refer to its\ndocumentation.\n\nAPI Overview\n============\n\nBase classes\n------------\n\n``ViewletManager``\n  Define a new viewlet manager. You can either provide a render\n  method, a template, which can or not use registered viewlets.\n\n  If you define a template, ``view`` is added as a reference to the\n  current view for which the manager is rendering in the template's\n  namespace. It is available as well as an attribute on the manager\n  object.\n\n``Viewlet``\n  Define a new viewlet. You can either provide a template or a render\n  method on it. Like in views, you can define an update method to\n  process needed data.\n\n  Like for manager, ``view`` is added to the template namespace if\n  used. ``viewletmanager`` is defined as well as a reference to the\n  manager in the template's namespace and as an attribute on the\n  viewlet object.\n\nDirectives\n----------\n\nYou can use directives from `grokcore.view`_ to register your\nviewlet or viewlet manager: ``name``, ``context``, ``layer`` and\n``require`` (for security on a viewlet).\n\nTo that is added:\n\n``view``\n   Select for which view is registered a viewlet or a viewlet manager.\n\n``viewletmanager``\n   Select for which viewlet manager is registered a viewlet.\n\n``order``\n   Define a rendering order for viewlets in a viewlet manager. This\n   should be a number, the smaller order render first, bigger last.\n\n\nAdditionally, the ``grokcore.viewlet`` package exposes the\n`grokcore.component`_, `grokcore.security`_ and `grokcore.view`_ APIs.\n\n.. _grokcore.component: https://pypi.org/project/grokcore.component\n.. _grokcore.viewlet: https://pypi.org/project/grokcore.viewlet\n.. _grokcore.security: https://pypi.org/project/grokcore.security\n.. _grokcore.view: https://pypi.org/project/grokcore.view\n\nChanges\n=======\n\n4.0 (2023-08-28)\n----------------\n\n* Add support for Python 3.7, 3.8, 3.9, 3.10, 3.11.\n\n* Drop support for Python 2.7, 3.4, 3.5, 3.6.\n\n\n3.1.0 (2018-02-05)\n------------------\n\n* viewletmanager.viewlets should be a list so we can iterate over it several\n  times in consumer code instead of having to remember it's an iterable we can\n  only list once.\n\n3.0.1 (2018-01-12)\n------------------\n\n* Rearrange tests such that Travis CI can pick up all functional tests too.\n\n3.0.0 (2018-01-04)\n------------------\n\n* Python 3 compatibility.\n\n1.11 (2012-09-04)\n-----------------\n\n* Make the ``has_render()`` and ``has_no_render()`` symmetrical to those\n  in grokcore.view, grokcore.layout and grokcore.formlib, where a\n  ``render.base_method`` attribute is checked.\n\n1.10.1 (2012-05-02)\n-------------------\n\n* Do not require the role extra from grokcore.security.\n\n1.10 (2012-05-02)\n-----------------\n\n* Use the component registration api from grokcore.component.\n\n* Update how the static resources are found on a ``ViewletManager``\n  and a ``Viewlet``, following the new name ``__static_name__`` set by\n  the template association.\n\n1.9 (2011-06-28)\n----------------\n\n* Introduce the `available()` method on viewlet component. The viewlet\n  manager will filter out unavailable viewlet by calling this method. The\n  `available()` method is called *after* the viewlet's `update()` is called,\n  but *before* the `render()` is called.\n\n1.8 (2010-12-16)\n----------------\n\n* Update to use TemplateGrokker from grokcore.view to associate\n  viewlet and viewletmanager templates.\n\n1.7 (2010-11-03)\n----------------\n\n* The computed default value for the viewletmanager directive is now defined\n  in the directiv itself, not as a separate function that needs to be passed\n  along.\n\n1.6 (2010-11-01)\n----------------\n\n* Upped version requirements for martian, grokcore.component, and grokcore.view.\n\n* Move the order directive to grokcore.component.\n\n* Move the view directive to grokcore.view.\n\n1.5 (2010-10-18)\n----------------\n\n* Make package comply to zope.org repository policy.\n\n* Update functional tests to use Browser implementation of zope.app.wsgi\n  instead of zope.app.testing.\n\n* Reduce dependencies (zope.app.pagetemplate no longer necessary).\n\n1.4.1 (2010-02-28)\n------------------\n\n* Dropped the dependency on ``zope.app.zcmlfiles``.\n\n* Cleaned the code to remove unused imports and ensure the pep8 syntax.\n\n* Updated tests to have a return value consistency. The\n  grokcore.viewlet viewlet manager implementation requires viewlets to\n  return unicode strings. Now, viewlets return unicode strings in the\n  test packages.\n\n1.4 (2010-02-19)\n----------------\n\n* Define test requires.\n\n1.3 (2009-09-17)\n----------------\n\n* Reverted the use of grokcore.view.CodeView. We now require\n  ``grokcore.view`` 1.12.1 or newer. As of ``grokcore.view`` 1.12, the\n  CodeView/View separation has been undone.\n\n1.2 (2009-09-16)\n----------------\n\n* Remove the reference to the grok.View permission that is no longer in\n  grokcore.security 1.2\n\n* Use the grok.zope.org/releaseinfo information instead of our own\n  copy of ``versions.cfg``, for easier maintenance.\n\n\n1.1 (2009-07-20)\n----------------\n\n* Adapted tests to new grokcore.view release: switched from View to CodeView.\n\n* Add grok.View permissions to functional tests (requires grokcore.security\n  1.1)\n\n1.0 (2008-11-15)\n----------------\n\n* Created ``grokcore.viewlet`` in November 2008 by factoring\n  ``zope.viewlet``-based components, grokkers and directives out of\n  Grok.\n",
    "bugtrack_url": null,
    "license": "ZPL",
    "summary": "Grok-like configuration for zope viewlets",
    "version": "4.0",
    "project_urls": {
        "Download": "https://pypi.org/project/grokcore.viewlet",
        "Homepage": "https://github.com/zopefoundation/grokcore.viewlet"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "291ba9d25908055b08afc6794c0975909621035d2ea8705e55380748e59b3fa5",
                "md5": "c16a34928331234cb307c8c27bad0dce",
                "sha256": "38e60d2b24b380bf253eeca47d4bedeefd9ccf81d9709fc4c3b4be4237aa7dac"
            },
            "downloads": -1,
            "filename": "grokcore.viewlet-4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c16a34928331234cb307c8c27bad0dce",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 36474,
            "upload_time": "2023-08-28T09:28:04",
            "upload_time_iso_8601": "2023-08-28T09:28:04.786100Z",
            "url": "https://files.pythonhosted.org/packages/29/1b/a9d25908055b08afc6794c0975909621035d2ea8705e55380748e59b3fa5/grokcore.viewlet-4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d8a5e5043dfa84847fde2db39ccf7509bd1c78d6db52a526bc95ea0c4c0cc04b",
                "md5": "a27c47251026cbef161ec19b128f8f83",
                "sha256": "4876407511c9153a43c4fd621b419fb7e80f7fa09242c07d9bb1f41683b359f6"
            },
            "downloads": -1,
            "filename": "grokcore.viewlet-4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a27c47251026cbef161ec19b128f8f83",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 24437,
            "upload_time": "2023-08-28T09:28:06",
            "upload_time_iso_8601": "2023-08-28T09:28:06.752007Z",
            "url": "https://files.pythonhosted.org/packages/d8/a5/e5043dfa84847fde2db39ccf7509bd1c78d6db52a526bc95ea0c4c0cc04b/grokcore.viewlet-4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-28 09:28:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "zopefoundation",
    "github_project": "grokcore.viewlet",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "grokcore.viewlet"
}
        
Elapsed time: 0.11099s