{ "info": { "author": "Stefan Eletzhofer", "author_email": "stefan.eletzhofer@inquant.de", "bugtrack_url": null, "classifiers": [ "Framework :: Plone", "Framework :: Zope2", "Framework :: Zope3", "Programming Language :: Python", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "collective.beancounter\n======================\n\n:Author: $Author: seletz $\n:Date: $Date: 2007-11-14 19:46:16 +0100 (Wed, 14 Nov 2007) $\n:Revision: $Revision: 53844 $\n\nAbstract\n--------\n\nThis package scratches an itch of mine in providing a very simple viewlet\nwhich displays the percentage a content is filled by an user.\n\nsetup stuff\n------------\n\n::\n\n >>> class Mock(object):\n ... def __init__(self, **kw): self.__sict__.update(kw)\n\nBlurb\n-----\n\nFirst we define an interface to be used to mark bean-countable content::\n\n >>> from zope import interface\n >>> class IBeanContable(interface.Interface):\n ... \"\"\" a content which is bean countable \"\"\"\n\nThe counting itself is very simple and done by an adapter. We simply count\nwhich fields in the **default** schemata are filled. We there count only\nthe writable fields. From that we calculate a percentage.\n\nLets define a interface for that functionality::\n\n >>> class IBeanCounter(interface.Interface):\n ... percentage = interface.Attribute(u\"The percentage filled\")\n\nNow lets create some content class to test our stuff::\n\n >>> _ = self.folder.invokeFactory(\"Document\", \"doc\")\n >>> doc = self.folder.get(_)\n\nCount the fields which are in the **default** schemata and are rewd/write::\n\n >>> len([f for f in doc.Schema().fields() if f.schemata==\"default\" and f.mode ==\"rw\"])\n 4\n\nOk, now how many of them are filled?::\n\n >>> l = [f for f in doc.Schema().fields() if f.schemata==\"default\" and f.mode ==\"rw\"]\n >>> [f.getName() for f in l if f.get(doc)]\n ['id']\n\nOk, fair enough. Now lets do the opposite::\n\n >>> [f.getName() for f in l if not f.get(doc)]\n ['title', 'description', 'text']\n\nOk, thats enough. Lets wrap it up.\n\nImplementation\n--------------\n\nWe have an adapter::\n\n >>> from collective.beancounter.adapter import ATBeanCounter\n >>> ct = ATBeanCounter(doc)\n >>> print ct.percentage\n 25.0\n\nFill out completely::\n\n >>> doc.update( title=\"muha\", text=\"haha\", description=\"desc\")\n >>> ct = ATBeanCounter(doc)\n >>> print ct.percentage\n 100.0\n\nYay.\n\nField filter\n------------\n\nYou may provide an adapter to specify a filter to decide which\nfields you consider to be \"countable\"::\n\n >>> from collective.beancounter.interfaces import IBeanCounterFieldFilter\n\nWe provide adefault adapter for AT objects::\n\n >>> from collective.beancounter.adapter import ATFieldFilter\n\nThat adapter provides a filter which filters out fields which:\n - are not user settable\n - are not in the \"default\" schemata\n - are not in the special plone field blacklist\n - are not boolean fields (these are true or false, i.e. always \"filled\")\n\n::\n\n >>> IBeanCounterFieldFilter(doc)\n \n\nLets test that::\n\n >>> from collective.beancounter.adapter import countable_fields\n >>> sorted([f.getName() for f in countable_fields(doc)])\n ['description', 'id', 'text', 'title']\n\nOk, that filters nothing, which is fine. Now lets provide an adapter\nwhich does filter out the \"title\",\"id\" and \"description\" fields::\n\n >>> from zope import component\n >>> from Products.Archetypes.interfaces import IBaseObject\n >>> class TestFilter(object):\n ... component.adapts(IBaseObject)\n ... interface.implements(IBeanCounterFieldFilter)\n ... def __init__(self,context): self.context = context\n ... def __call__(self, field):\n ... return field.getName() not in \"title id description\".split()\n >>> component.provideAdapter(TestFilter)\n\nWe should now get our adapter::\n\n >>> IBeanCounterFieldFilter(doc)\n \n\nWe should now get ALL fields but the ones we filtered out::\n\n >>> set(\"title id description\".split()) & set([f.getName() for f in countable_fields(doc)]) \n set([])\n \n \n::\n\n vim: set ft=rst tw=75 nocin nosi ai sw=4 ts=4 expandtab:", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://svn.plone.org/svn/collective/collective.beancounter/trunk", "keywords": "", "license": "GPL", "maintainer": null, "maintainer_email": null, "name": "collective.beancounter", "package_url": "https://pypi.org/project/collective.beancounter/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/collective.beancounter/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://svn.plone.org/svn/collective/collective.beancounter/trunk" }, "release_url": "https://pypi.org/project/collective.beancounter/0.3.1/", "requires_dist": null, "requires_python": null, "summary": "package to display a fill-percentage for AT based content", "version": "0.3.1" }, "last_serial": 787656, "releases": { "0.2": [ { "comment_text": "", "digests": { "md5": "e9989b191a81a0b357a3f70d324004be", "sha256": "81931752ad17acaf731ff875ceea33007da983cef3904e43de8fddebffab610a" }, "downloads": -1, "filename": "collective.beancounter-0.2-py2.4.egg", "has_sig": false, "md5_digest": "e9989b191a81a0b357a3f70d324004be", "packagetype": "bdist_egg", "python_version": "2.4", "requires_python": null, "size": 10259, "upload_time": "2007-11-14T13:19:40", "url": "https://files.pythonhosted.org/packages/e7/55/e9c04c2d65b20c0564d7d00875e09dce4873bf4ef7853dcdd1061e3da06c/collective.beancounter-0.2-py2.4.egg" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "0335cdef54758af6b915ed1db964bbd9", "sha256": "61f70cfc7149cbf756c3ee826218733e6135be72c95e7570ef7fd87001155be5" }, "downloads": -1, "filename": "collective.beancounter-0.3-py2.4.egg", "has_sig": false, "md5_digest": "0335cdef54758af6b915ed1db964bbd9", "packagetype": "bdist_egg", "python_version": "2.4", "requires_python": null, "size": 11598, "upload_time": "2007-11-14T18:46:46", "url": "https://files.pythonhosted.org/packages/b4/ff/1d355ef4103a8dfb0b52c20af72bfe5bc96dd42baa70dad9c2fbbad1f4ae/collective.beancounter-0.3-py2.4.egg" }, { "comment_text": "", "digests": { "md5": "576ce8c7cee344a4c8a5a1cccd83ce28", "sha256": "3c1a5f7b409bf6c4b461e16d2ab6d32b453b0c0c12a9fbed8c2d54abe81d4e70" }, "downloads": -1, "filename": "collective.beancounter-0.3.tar.gz", "has_sig": false, "md5_digest": "576ce8c7cee344a4c8a5a1cccd83ce28", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10442, "upload_time": "2007-11-14T18:46:43", "url": "https://files.pythonhosted.org/packages/77/64/f1de4bd570fc407147fbef78c43f10b155ca162f9889017c8b79c3cf0dd0/collective.beancounter-0.3.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "e94b40053f3dcc89bed2542d4eda6d0f", "sha256": "e751e86d1d4ca14ba622e7dd287ded1dd1ad84b0c1d464074ee3002e67991fd0" }, "downloads": -1, "filename": "collective.beancounter-0.3.1-py2.4.egg", "has_sig": false, "md5_digest": "e94b40053f3dcc89bed2542d4eda6d0f", "packagetype": "bdist_egg", "python_version": "2.4", "requires_python": null, "size": 13051, "upload_time": "2007-11-14T18:50:24", "url": "https://files.pythonhosted.org/packages/e4/a0/3150b16ce52b307c82032e11fd1e7f6ee6b0caba6d6921515bf3a6335735/collective.beancounter-0.3.1-py2.4.egg" }, { "comment_text": "", "digests": { "md5": "dcd815319a8be9ee82ffd8b06f5f4aff", "sha256": "55385d43d4a69268540739234e890abdae5e96e219bd16375424261e20ec1f98" }, "downloads": -1, "filename": "collective.beancounter-0.3.1.tar.gz", "has_sig": false, "md5_digest": "dcd815319a8be9ee82ffd8b06f5f4aff", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10974, "upload_time": "2007-11-14T18:50:22", "url": "https://files.pythonhosted.org/packages/ae/72/1d6f91a3e53464a3e75366c7e29efb5f2021a6b93ecca3a7f0baaac60fc3/collective.beancounter-0.3.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "e94b40053f3dcc89bed2542d4eda6d0f", "sha256": "e751e86d1d4ca14ba622e7dd287ded1dd1ad84b0c1d464074ee3002e67991fd0" }, "downloads": -1, "filename": "collective.beancounter-0.3.1-py2.4.egg", "has_sig": false, "md5_digest": "e94b40053f3dcc89bed2542d4eda6d0f", "packagetype": "bdist_egg", "python_version": "2.4", "requires_python": null, "size": 13051, "upload_time": "2007-11-14T18:50:24", "url": "https://files.pythonhosted.org/packages/e4/a0/3150b16ce52b307c82032e11fd1e7f6ee6b0caba6d6921515bf3a6335735/collective.beancounter-0.3.1-py2.4.egg" }, { "comment_text": "", "digests": { "md5": "dcd815319a8be9ee82ffd8b06f5f4aff", "sha256": "55385d43d4a69268540739234e890abdae5e96e219bd16375424261e20ec1f98" }, "downloads": -1, "filename": "collective.beancounter-0.3.1.tar.gz", "has_sig": false, "md5_digest": "dcd815319a8be9ee82ffd8b06f5f4aff", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10974, "upload_time": "2007-11-14T18:50:22", "url": "https://files.pythonhosted.org/packages/ae/72/1d6f91a3e53464a3e75366c7e29efb5f2021a6b93ecca3a7f0baaac60fc3/collective.beancounter-0.3.1.tar.gz" } ] }