{ "info": { "author": "Zope Corporation and Contributors", "author_email": "zope3-dev@zope.org", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Environment :: Web Environment", "Framework :: Zope3", "Intended Audience :: Developers", "License :: OSI Approved :: Zope Public License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Internet :: WWW/HTTP" ], "description": "This package allows us to separate the registration of the view code and the\nview templates.\n\nWhy is this a good thing?\n\nWhile developing customizable applications that require us to develop multiple\ncustomer UIs for one particular application, we noticed there is a fine but\nclear distinction between skins and layers. Layers contain the logic to\nprepare data for presentation output, namely the view classes. Skins, on the\nother hand contain the resources to generate the UI, for example templates,\nimages and CSS files.\n\nThe problem of the existing infrastructure is that code, template and layer\nare all hardlinked in one zcml configuration directive of the view component\n-- page, content provider, viewlet. This package separates this triplet --\ncode, template, layer -- into two pairs, code/layer and template/skin. No\nadditional components are introduced, since skins and layers are physically\nthe same components.\n\n\n\nDetailed Dcoumentation\n======================\n\n\n============\nViewTemplate\n============\n\nThis package allows us to separate the registration of the view code and the\nview templates.\n\nWhy is this a good thing?\n\nWhile developing customizable applications that require us to develop multiple\ncustomer UIs for one particular application, we noticed there is a fine but\nclear distinction between skins and layers. Layers contain the logic to\nprepare data for presentation output, namely the view classes. Skins, on the\nother hand contain the resources to generate the UI, for example templates,\nimages and CSS files.\n\nThe problem of the existing infrastructure is that code, template and layer\nare all hardlinked in one zcml configuration directive of the view component\n-- page, content provider, viewlet. This package separates this triplet --\ncode, template, layer -- into two pairs, code/layer and template/skin. No\nadditional components are introduced, since skins and layers are physically\nthe same components.\n\nBefore we can setup a view component using this new method, we have to first\ncreate a template ...\n\n >>> import os, tempfile\n >>> temp_dir = tempfile.mkdtemp()\n >>> template = os.path.join(temp_dir, 'demoTemplate.pt')\n >>> open(template, 'w').write('''
demo
''')\n\nand the view code:\n\n >>> from zope.publisher.browser import TestRequest\n >>> request = TestRequest()\n\n >>> from zope import interface\n >>> from z3c.viewtemplate.baseview import BaseView\n >>> class IMyView(interface.Interface):\n ... pass\n >>> class MyView(BaseView):\n ... interface.implements(IMyView)\n\n >>> view = MyView(root, request)\n\nSince the template is not yet registered, rendering the view will fail:\n\n >>> print view()\n Traceback (most recent call last):\n ...\n ComponentLookupError: ......\n\nLet's now register the template (commonly done using ZCML):\n\n >>> from zope import component\n >>> from zope.publisher.interfaces.browser import IDefaultBrowserLayer\n >>> from z3c.viewtemplate.zcml import TemplateFactory\n >>> from zope.pagetemplate.interfaces import IPageTemplate\n\nThe template factory allows us to create a ViewPageTeplateFile instance.\n\n >>> factory = TemplateFactory(template, None, 'text/html')\n\nWe register the factory on a view interface and a layer.\n\n >>> component.provideAdapter(factory,\n ... (interface.Interface, IDefaultBrowserLayer),\n ... IPageTemplate)\n >>> template = component.getMultiAdapter(\n ... (view, request), IPageTemplate)\n >>> template\n \n\nNow that we have a registered template for the default layer we can\ncall our view again. The view is a contentprovider so a\nBeforeUpdateEvent is fired before its update method is called.\n\n >>> events = []\n >>> component.provideHandler(events.append, (None,))\n >>> print view()\n
demo
\n >>> events\n []\n\nNow we register a new template on the specific interface of our view.\n\n >>> myTemplate = os.path.join(temp_dir, 'myViewTemplate.pt')\n >>> open(myTemplate, 'w').write('''
IMyView
''')\n >>> factory = TemplateFactory(myTemplate, None, 'text/html')\n >>> component.provideAdapter(factory,\n ... (IMyView, IDefaultBrowserLayer),\n ... IPageTemplate)\n >>> print view()\n
IMyView
\n\nWe can also render the view with debug flags set.\n\n >>> request.debug.sourceAnnotations = True\n >>> print view()\n
IMyView
\n >>> request.debug.sourceAnnotations = False\n\nIt is possible to provide the template directly.\n\nWe create a new template.\n\n >>> viewTemplate = os.path.join(temp_dir, 'viewTemplate.pt')\n >>> open(viewTemplate, 'w').write('''
view
''')\n\n >>> from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile\n >>> class MyViewWithTemplate(BaseView):\n ... interface.implements(IMyView)\n ... template = ViewPageTemplateFile(viewTemplate)\n >>> templatedView = MyViewWithTemplate(root, request)\n\nIf we render this view we get the original template and not the registered\none.\n\n >>> print templatedView()\n
view
\n\n\nUse of macros.\n\n >>> macroTemplate = os.path.join(temp_dir, 'macroTemplate.pt')\n >>> open(macroTemplate, 'w').write('''\n ... \n ...
macro1
\n ...
\n ... \n ...
macro2
\n ...
\n ... ''')\n\n >>> factory = TemplateFactory(macroTemplate, 'macro1', 'text/html')\n >>> print factory(view, request)()\n
macro1
\n\nSince it is possible to pass options to the viewlet let's prove if this\nis possible for macros as well:\n\n >>> factory = TemplateFactory(macroTemplate, 'macro2', 'text/html')\n >>> print factory(view, request)(foo='bar')\n
bar
\n\n\nWhy didn't we use named templates from the ``zope.formlib`` package?\n\nWhile named templates allow us to separate the view code from the template\nregistration, they are not registrable for a particular layer making it\nimpossible to implement multiple skins using named templates.\n\n\nPage Template\n-------------\n\nAnd for the simplest possible use we provide a RegisteredPageTemplate a la\nViewPageTemplateFile or NamedTemplate.\n\nThe RegisteredPageTemplate allows us to use the new template registration\nsystem with all existing implementations such as `zope.formlib` and\n`zope.viewlet`.\n\n >>> from z3c.viewtemplate.pagetemplate import RegisteredPageTemplate\n >>> class IMyUseOfView(interface.Interface):\n ... pass\n >>> class UseOfRegisteredPageTemplate(object):\n ... interface.implements(IMyUseOfView)\n ...\n ... template = RegisteredPageTemplate()\n ...\n ... def __init__(self, context, request):\n ... self.context = context\n ... self.request = request\n\nBy defining the \"template\" property as a \"RegisteredPageTemplate\" a lookup for\na registered template is done when it is called. Also notice that it is no\nlonger necessary to derive the view from BaseView!\n\n >>> simple = UseOfRegisteredPageTemplate(root, request)\n >>> print simple.template()\n
demo
\n\nBecause the demo template was registered for any (\"None\") interface we see the\ndemo template when rendering our new view. We register a new template\nespecially for the new view. Also not that the \"macroTemplate\" has been\ncreated earlier in this test.\n\n >>> factory = TemplateFactory(macroTemplate, 'macro2', 'text/html')\n >>> component.provideAdapter(factory,\n ... (IMyUseOfView, IDefaultBrowserLayer),\n ... IPageTemplate)\n >>> print simple.template(foo='bar')\n
bar
\n\n\n\n=======\nCHANGES\n=======\n\n0.4.1 (2010-12-12)\n------------------\n\n - Fixed exception handling if macro is not found in the template.\n\n - Fixed tests, so they can successfully run on Windows.\n\n - Using Python's ``doctest`` module instead of depreacted\n ``zope.testing.doctest``.\n\n - Removed ZCML slugs and ZPKG ones.\n\n\n0.4.0 (2008-11-05)\n------------------\n\n - added support for TAL debug flags\n\n0.3.2 (2007-11-01)\n------------------\n\n- Fix package meta-data.\n\n0.3.1 (2007-10-31)\n------------------\n\n- Bugfix: Options did not get passed in to macro templates.\n\n\n0.3.0 (2007-09-27)\n------------------\n\n- Add the request to ``BeforeUpdateEvent``, this requires a recent\n zope.contentprovider package.\n\n- No dev release anymore.\n\n\n0.2 (2007-05-01)\n----------------\n\n- Fire a ``BeforeUpdateEvent`` in the base views. This requires zope 3.4.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://cheeseshop.python.org/pypi/z3c.viewtemplate", "keywords": "zope3 view template pagetemplate macro", "license": "ZPL 2.1", "maintainer": null, "maintainer_email": null, "name": "z3c.viewtemplate", "package_url": "https://pypi.org/project/z3c.viewtemplate/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/z3c.viewtemplate/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://cheeseshop.python.org/pypi/z3c.viewtemplate" }, "release_url": "https://pypi.org/project/z3c.viewtemplate/0.4.1/", "requires_dist": null, "requires_python": null, "summary": "View Templates", "version": "0.4.1" }, "last_serial": 802124, "releases": { "0.3.0": [ { "comment_text": "", "digests": { "md5": "0b44da6388e8946db7419457975c9e85", "sha256": "4673d0a27c12eb7f496a3cb4e2c8eca1ba27274623d566ab94a7172258caa5a0" }, "downloads": -1, "filename": "z3c.viewtemplate-0.3.0.tar.gz", "has_sig": false, "md5_digest": "0b44da6388e8946db7419457975c9e85", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7146, "upload_time": "2007-11-01T19:55:01", "url": "https://files.pythonhosted.org/packages/da/f7/acd091dc0bc958cf1a394f53e6e7292da1f7a8c99b85aea2b3d58a01ba15/z3c.viewtemplate-0.3.0.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "883ad80dc17208fdf5371e5ffb8863d7", "sha256": "4329951f507d15f3095cc72a03555e5fa0c0912b07eb710bf62218367ba5d909" }, "downloads": -1, "filename": "z3c.viewtemplate-0.3.1.tar.gz", "has_sig": false, "md5_digest": "883ad80dc17208fdf5371e5ffb8863d7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7284, "upload_time": "2007-11-01T19:57:02", "url": "https://files.pythonhosted.org/packages/af/c7/188324b91119002884a120e4dc58414d7b707422e50b65fa570be0a1171c/z3c.viewtemplate-0.3.1.tar.gz" } ], "0.3.2": [ { "comment_text": "", "digests": { "md5": "32a445573a78a6bf9cdb27a5d2e78ce5", "sha256": "37fa0d79981165bc82183186de219994aafe07ff37e8009666c1f67f2d24d7b0" }, "downloads": -1, "filename": "z3c.viewtemplate-0.3.2.tar.gz", "has_sig": false, "md5_digest": "32a445573a78a6bf9cdb27a5d2e78ce5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8652, "upload_time": "2007-11-01T20:05:13", "url": "https://files.pythonhosted.org/packages/3e/b3/53ad21694c04578bc4f450fb8bcca51dea53d3dde8cfaefbe43a5005a58d/z3c.viewtemplate-0.3.2.tar.gz" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "25a7b2bd296d1756b5973df65db35a2a", "sha256": "b2b47cf2c34aa959a0debb2d1691215b7f081d46349c2514c031f106e6dd941c" }, "downloads": -1, "filename": "z3c.viewtemplate-0.4.0.tar.gz", "has_sig": false, "md5_digest": "25a7b2bd296d1756b5973df65db35a2a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9880, "upload_time": "2008-11-05T15:12:22", "url": "https://files.pythonhosted.org/packages/e9/57/4060779b97ed3ccc4520a99943c15c8bf6e065bcb6dfbf517494c43cafda/z3c.viewtemplate-0.4.0.tar.gz" } ], "0.4.1": [ { "comment_text": "", "digests": { "md5": "ce7671f95526904a4b8f2c7123733487", "sha256": "eb28b6e7e63546309a50b2823c6b6a2b78bc5029689aa6be3dd4b41ebcba0505" }, "downloads": -1, "filename": "z3c.viewtemplate-0.4.1.tar.gz", "has_sig": false, "md5_digest": "ce7671f95526904a4b8f2c7123733487", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9539, "upload_time": "2010-12-12T17:46:16", "url": "https://files.pythonhosted.org/packages/d3/98/83cf00493f463beb8043158e5f1f65356432cb70c91151b9e571b9a41c80/z3c.viewtemplate-0.4.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "ce7671f95526904a4b8f2c7123733487", "sha256": "eb28b6e7e63546309a50b2823c6b6a2b78bc5029689aa6be3dd4b41ebcba0505" }, "downloads": -1, "filename": "z3c.viewtemplate-0.4.1.tar.gz", "has_sig": false, "md5_digest": "ce7671f95526904a4b8f2c7123733487", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9539, "upload_time": "2010-12-12T17:46:16", "url": "https://files.pythonhosted.org/packages/d3/98/83cf00493f463beb8043158e5f1f65356432cb70c91151b9e571b9a41c80/z3c.viewtemplate-0.4.1.tar.gz" } ] }