{ "info": { "author": "Zope Foundation and Contributors", "author_email": "grok-dev@zope.org", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "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": "grokui.base -- Base components for Grok UI\n******************************************\n\n``grokui.base`` is a base layer to build a zope instance-level set of\nutilities. The package provides a collection of easy-to-use components\nthat will allow you to build your own configuration or admin panels.\n`grokui.base` provides the components that should be used by other\n`grokui` packages to plug into a coherent layout.\n\nUsing `grokui.base` we can provide different UI parts that can be used\nindenpendently from each other, for example a ZODB browser or a\ngeneral admin panel to manage local Grok applications. It is up to the\nadmins to decide what grok UI parts they want to have installed.\n\nIn general, `grokui.base` provides viewlets, menus, layouts and a\nspecial namespace for use by other components.\n\n\n\n.. contents::\n\n\nDetailed Description\n********************\n\n``grokui.base`` provides tools to assemble a coherent environment.\n\n\nThe ``++grokui++`` namespace\n============================\n\nIn order to keep a sane and clean naming policy, the grokui components\nare compartmented in a logical namespace, ``++grokui++``, which is\ndefined and registered in `grokui.base`.\n\nThis namespace is a multi-adapter that will act like a parent for the\nview. It's the natural context of all the grokui pages. Let's get out\nfirst contact with this namespace::\n\n >>> from grokui.base import GrokUINamespace\n >>> from grokui.base import IGrokUIRealm\n\n >>> IGrokUIRealm.implementedBy(GrokUINamespace)\n True\n\nExample\n-------\n\nWe can build a simple admin screen that fits into the environment like\nthis:\n\n >>> from martian.testing import FakeModule\n >>> import grok\n >>> from zope.interface import Interface\n >>> from grokui.base import GrokUILayer\n\n >>> class mymodule(FakeModule):\n ... class MyAdminScreen(grok.View):\n ... grok.layer(GrokUILayer)\n ... grok.name('helloadmin')\n ... grok.context(Interface)\n ... def render(self):\n ... return u'Hello admin!'\n >>> from martiantest.fake.mymodule import MyAdminScreen\n\nThe important thing here is, that we set our view to belong to the\nGrokUI namespace, which is named ``++grokui++`` in URLs.\n\nWe grok this view to register it with the component architechture:\n\n >>> from grokcore.component.testing import grok_component\n >>> grok_component('MyAdminScreen', MyAdminScreen)\n True\n\nLet's create a browser to lookup this view:\n\n >>> from zope.app.wsgi.testlayer import Browser\n >>> browser = Browser()\n >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')\n\nWe can get this screen when we ask for the correct namespace:\n\n >>> browser.open('http://localhost/++grokui++/@@helloadmin')\n >>> print browser.contents\n Hello admin!\n\nIf we ask for this view without the namespace set correctly, the view\nwill not be found:\n\n >>> browser.open('http://localhost/@@helloadmin')\n Traceback (most recent call last):\n ...\n HTTPError: HTTP Error 404: Not Found\n\n\nGrokUI Pages\n============\n\nWe can, however, also create admin pages, that fit completely into the\nGrokUI layout without much hassle, providing a menu bar, images and\nall other parts of the standard grokui layout automatically for your\npage.\n\nTo do so, we derive our admin page from ``GrokUIView``, give it a\ntitle, and optionally set an order number:\n\n >>> from grokui.base.layout import GrokUIView\n >>> from grokui.base.namespace import GrokUILayer\n\n >>> class mymodule(FakeModule):\n ... class CaveManagementScreen(GrokUIView):\n ... # Name where we can access this page via URL:\n ... grok.name('managecave')\n ... # Also optional, but highly recommended:\n ... grok.require('zope.ManageServices')\n ... # Set title of page in menu bar:\n ... grok.title('admin stuff')\n ... # Display this entry very far to the left in menu bar:\n ... grok.order(-1)\n ...\n ... def render(self):\n ... # Instead of render() we could also define a page template\n ... # for the actual contents of this page.\n ... return u'Hello cave manager!'\n >>> from martiantest.fake.mymodule import CaveManagementScreen\n >>> grok_component('CaveManagementScreen', CaveManagementScreen)\n True\n\nWhile the title will be displayed in the main menu bar of the GrokUI\nlayout automatically, the ``order`` tells at which position in the\nmenu we want our page to appear. Pages without a title do not appear\nin the menu bar at all.\n\nInstances of `GrokUIView` are in fact `grok.Page` instances\nthat render the content provided by a template or `render` method\ninto a given layout (here: the general GrokUI layout).\n\nWe can access the page in GrokUI namespace ``++grokui++`` under the\nname given above (``managecave``):\n\n >>> browser.open('http://localhost/++grokui++/managecave')\n >>> print browser.contents\n \n ...
\n ...