{ "info": { "author": "Souheil Chelfouh", "author_email": "trollfot@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Framework :: Zope3", "Intended Audience :: Developers", "Programming Language :: Python", "Programming Language :: Zope", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "===============\nmegrok.z3ctable\n===============\n\nThe `megrok.z3ctable` package is a wrapper around the z3c.table\ncomponents. z3c.table allows you to define HTML tables as zope3\ncomponents, defining columns as multi adapters.\n\nThanks to megrok.z3ctable, these components are now fully available\nin Grok, making them easy to declare and configure. The following\ncomponents are available :\n\n - Table\n - Column\n - Value\n\nBeyond a simple wrapping, megrok.z3cform brings you new convenient\nways to create pages displaying a table:\n\n - TableView: a simple browser view displaying a table.\n - TablePage: a table browser view included in a layout\n (see megrok.layout)\n\nFor more information and more detailed examples please look in the\ntests directory of this package.\n\n\nGetting started\n---------------\n\nFirst, we grok the package grokkers::\n\n >>> import grokcore.component as grok\n >>> from grokcore.component import testing\n >>> from grokcore.component.testing import grok_component\n >>> testing.grok('megrok.z3ctable')\n \n\nTest Setup\n----------\n\nLet's create simple items to demonstrate the package. Here, the\ntable will be the representation of a folder listing, displaying (in an\nordered way), the content of a simple container::\n\n >>> from megrok.z3ctable.tests import Container, Content\n >>> from zope.container import btree\n >>> from zope.publisher.browser import TestRequest\n >>> request = TestRequest()\n\nLet's create 2 dummy content::\n\n >>> christian = Content('Christian', 29)\n >>> trollfot = Content('Trollfot', 27) \n\nThen, we instanciate a container and store the 2 dummies inside::\n\n >>> container = Container()\n >>> container['christian'] = christian\n >>> container['trollfot'] = trollfot\n\n \nA simple Table\n--------------\n\nWe define a simple table. Here, the component only registers itself,\nthere's no logic defined inside::\n\n >>> from megrok.z3ctable import Table, Values \n >>> from megrok.z3ctable import ITable\n\n >>> class SimpleTable(Table):\n ... \"\"\" My Simple Table \"\"\"\n\n >>> ITable.implementedBy(Table)\n True\n\nLet's make an instance of the Table::\n\n >>> myTable = SimpleTable(container, request)\n >>> ITable.providedBy(myTable)\n True\n\nNow, we need to feed our table with contents. In order to provide a\npluggable way to fetch the content, z3c.table proposes an adapter\ncalled \"Values\". It is in charge of getting in the data to display::\n\n >>> class MyValues(Values):\n ... grok.adapts(btree.BTreeContainer, None, SimpleTable)\n ...\n ... @property\n ... def values(self):\n ... return self.context.values()\n\nWe grok the MyValues Adapter::\n\n >>> grok_component('MyValues', MyValues)\n True\n\n >>> myTable.update()\n >>> myTable.render()\n u''\n\nThere is currently no output this is because the table itself contains\nno logic. The data is displayed by components called \"Column\". A\nColumn is a multi adapter, adapting the context, the request and the\ntable. It permits a very flexible handling of the tables and the data\nrepresentations. Let's define a simple Column::\n\n >>> from zope.interface import Interface\n >>> from megrok.z3ctable import NameColumn\n >>> from megrok.z3ctable import table\n >>> class Names(NameColumn):\n ... grok.context(Interface)\n ... table(SimpleTable)\n\nNow we grok our Column::\n\n >>> grok_component('Names', Names)\n True\n\nand render the Table again::\n\n >>> myTable.update()\n >>> print myTable.render()\n
| Name | \n
|---|
| christian | \n
| trollfot | \n