{ "info": { "author": "kiorky", "author_email": "kiorky@cryptelium.net", "bugtrack_url": null, "classifiers": [ "Framework :: Plone", "Framework :: Plone :: 4.0", "Framework :: Plone :: 4.1", "Framework :: Plone :: 4.2", "Programming Language :: Python", "Topic :: Software Development" ], "description": "==============================\nIntroduction\n==============================\n\n.. contents::\n\n\n.. image:: https://secure.travis-ci.org/collective/collective.z3cform.chosen.png\n :target: http://travis-ci.org/collective/collective.z3cform.chosen\n\nCredits\n========\nCompanies\n---------\n|makinacom|_\n\n * `Planet Makina Corpus `_\n * `Contact us `_\n\n.. |makinacom| image:: http://depot.makina-corpus.org/public/logo.gif\n.. _makinacom: http://www.makina-corpus.com\n\nAuthors\n------------\n\n- kiorky \n\nContributors\n-----------------\n\nDescription\n=============\nThis package contains 4 widgets for z3cform using the `chosen `_ and `ajaxchosen `_ libraries.\n\n - A single valued widget for chosen\n - A multi valued widget for chosen\n - A single valued widget for ajaxchosen\n - A multi valued widget for ajaxchosen\n\n\nRepository : `github `_\n\n\n\n\nChosen widget\n===================\n\ncollective.chosen.widget provides an autocomplete widget based on the\njQuery Autocomplete widget.\n\n >>> from collective.z3cform.chosen import AjaxChosenFieldWidget\n >>> from collective.z3cform.chosen import AjaxChosenMultiFieldWidget\n >>> from collective.z3cform.chosen import ChosenFieldWidget\n >>> from collective.z3cform.chosen import ChosenMultiFieldWidget\n\nFirst, we need a vocabulary to search. This is shamelessly stolen from\nz3c.formwidget.query, which we extend.\n\n\n >>> from zope.interface import implements\n >>> from z3c.formwidget.query.interfaces import IQuerySource\n >>> from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm\n\n >>> class ItalianCities(object):\n ... implements(IQuerySource)\n ...\n ... vocabulary = SimpleVocabulary((\n ... SimpleTerm(u'bologna', 'bologna', u'Bologna'),\n ... SimpleTerm(u'palermo', 'palermo', u'Palermo'),\n ... SimpleTerm(u'sorrento', 'sorrento', u'Sorrento'),\n ... SimpleTerm(u'torino', 'torino', u'Torino')))\n ...\n ... def __init__(self, context):\n ... self.context = context\n ...\n ... __contains__ = vocabulary.__contains__\n ... __iter__ = vocabulary.__iter__\n ... getTerm = vocabulary.getTerm\n ... getTermByToken = vocabulary.getTermByToken\n ...\n ... def search(self, query_string):\n ... return [v\n ... for v in self\n ... if query_string.lower() in v.value.lower()]\n\n >>> from zope.schema.interfaces import IContextSourceBinder\n\n >>> class ItalianCitiesSourceBinder(object):\n ... implements(IContextSourceBinder)\n ...\n ... def __call__(self, context):\n ... return ItalianCities(context)\n\nThen, we will set up a simple test form and context.\n\n >>> from zope.interface import alsoProvides\n >>> from OFS.SimpleItem import SimpleItem\n >>> from Testing.makerequest import makerequest\n >>> from zope.annotation.interfaces import IAttributeAnnotatable\n >>> from z3c.form.interfaces import IFormLayer\n\n >>> def make_request(path, form={}):\n ... app = SimpleItem('')\n ... request = makerequest(app).REQUEST\n ... request.form.update(form)\n ... alsoProvides(request, IFormLayer)\n ... alsoProvides(request, IAttributeAnnotatable)\n ... request._script = path.split('/')\n ... request._steps = []\n ... request._resetURLS()\n ... return request\n\n >>> from zope.interface import Interface\n >>> from zope import schema\n >>> from z3c.form import form, field, button\n >>> from plone.z3cform.layout import wrap_form\n\n >>> class ICities(Interface):\n ... afavourite_city = schema.Choice(title=u\"Favourite city\",\n ... source=ItalianCitiesSourceBinder(), required=False)\n ... avisited_cities = schema.List(title=u\"Visited cities\",\n ... value_type=schema.Choice(title=u\"Selection\",\n ... source=ItalianCitiesSourceBinder()))\n ... favourite_city = schema.Choice(title=u\"Favourite city\",\n ... source=ItalianCitiesSourceBinder())\n ... visited_cities = schema.List(title=u\"Visited cities\",\n ... value_type=schema.Choice(title=u\"Selection\",\n ... source=ItalianCitiesSourceBinder()))\n\n >>> from z3c.form.interfaces import IFieldsForm\n >>> from zope.interface import implements\n >>> class CitiesForm(form.Form):\n ... implements(ICities)\n ... fields = field.Fields(ICities)\n ... fields['afavourite_city'].widgetFactory = AjaxChosenFieldWidget\n ... fields['avisited_cities'].widgetFactory = AjaxChosenMultiFieldWidget\n ... fields['favourite_city'].widgetFactory = ChosenFieldWidget\n ... fields['visited_cities'].widgetFactory = ChosenMultiFieldWidget\n ...\n ... @button.buttonAndHandler(u'Apply')\n ... def handleApply(self, action):\n ... data, errors = self.extractData()\n ... print \"Submitted data:\", data\n\n >>> form_view = wrap_form(CitiesForm)\n\n >>> from zope.component import provideAdapter\n >>> from zope.publisher.interfaces.browser import IBrowserRequest\n >>> from zope.interface import Interface\n\n >>> provideAdapter(adapts=(ICities, IBrowserRequest),\n ... provides=Interface,\n ... factory=form_view,\n ... name=u\"cities-form\")\n\n >>> from OFS.SimpleItem import SimpleItem\n >>> class Bar(SimpleItem):\n ... implements(ICities)\n ...\n ... def __init__(self, id):\n ... self.id = id\n ... self.favourite_city = None\n ... self.visited_cities = []\n ... self.afavourite_city = None\n ... self.avisited_cities = []\n ... def absolute_url(self):\n ... return 'http://foo/bar'\n\nLet us now look up the form and attempt to render the widget.\n\n >>> from zope.component import getMultiAdapter\n >>> context = Bar('bar')\n\nSimulates traversal:\n\n >>> request = make_request('bar/@@cities-form')\n >>> from Testing.makerequest import makerequest\n >>> context = makerequest(context)\n >>> form_view = getMultiAdapter((context, request), name=u\"cities-form\")\n >>> form_view.__name__ = 'cities-form'\n\nSimulates partial rendering:\n\n >>> form = form_view.form_instance\n >>> form.__name__ = 'cities-form'\n >>> form.update()\n\n >>> print form.widgets['favourite_city'].render().replace(\"...\", \"\") # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE +REPORT_UDIFF\n \n \n
\n \n \n
\n \n\nWe can see that the rendered JavaScript is expecting to call a view for ajax widgets\nlike this:\n\n >>> widget = form.widgets['afavourite_city']\n >>> context.REQUEST._script = 'bar/@@cities-form/++widget++form.widgets.avisited_cities/@@chosen-autocomplete-search'.split('/')\n >>> context.REQUEST._resetURLS()\n >>> context.REQUEST.form['term'] = 'or'\n >>> search_view = getMultiAdapter((widget, context.REQUEST), name=u'chosen-autocomplete-search')\n\nThe results are a json tuple list of tokens:\n\n >>> print search_view()\n [[\"sorrento\",\"Sorrento\"],[\"torino\",\"Torino\"]]\n\nAt first we didnt set anything in the request, we are missing fields\n\n >>> form.update()\n >>> data, errors = form.extractData()\n >>> len(errors)\n 3\n >>> form.request.form.update({\n ... \"form.buttons.apply\" : \"Apply\",\n ... \"form.widgets.visited_cities\" : [\"palermo\", \"bologna\"],\n ... \"form.widgets.avisited_cities\" : [\"palermo\", \"bologna\"],\n ... \"form.widgets.afavourite_city\" :\"bologna\",\n ... \"form.widgets.favourite_city\" : \"palermo\",\n ... })\n >>> form.update() # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS\n Submitted data:...\n >>> data, errors = form.extractData()\n >>> items = data.items()\n >>> items.sort(key=lambda x:x[0])\n >>> pprint(items)\n [('afavourite_city', u'bologna'),\n ('avisited_cities', [u'palermo', u'bologna']),\n ('favourite_city', u'palermo'),\n ('visited_cities', [u'palermo', u'bologna'])]\n\n\n\nOur values are marked as selected\n\n >>> results = form.render().replace('...', '')\n >>> False not in [\n ... (it in results)\n ... for it in ['id=\"form-widgets-visited_cities-0\" value=\"bologna\" selected=\"selected\">Bologna',\n ... 'id=\"form-widgets-visited_cities-1\" value=\"palermo\" selected=\"selected\">Palermo']]\n True\n\nOur widget also handle display mode\n\n >>> form.widgets['favourite_city'].mode = 'display'\n >>> print form.widgets['favourite_city'].render().strip()\n Palermo\n\n >>> form.widgets['visited_cities'].mode = 'display'\n >>> print form.widgets['visited_cities'].render().strip()\n Palermo, Bologna\n\nOur widget also handle hidden mode\n\n >>> form.widgets['favourite_city'].mode = 'hidden'\n >>> print form.widgets['favourite_city'].render().strip()\n \n \n \n \n \n \n \n \n \n\n >>> form.widgets['visited_cities'].mode = 'hidden'\n >>> print form.widgets['visited_cities'].render().strip()\n \n \n \n \n \n \n \n \n \n \n \n \n\n\n\ncollective.z3cform.chosen Installation\n=================================================================================\n\nTo install collective.z3cform.chosen, follow this `documentation `_. \n\n\n\nChangelog\n=========\n\n1.2.1 (2014-09-25)\n------------------\n\n- Widget works when the field is initially hidden (for instance in an overlay).\n [thomasdesvenain]\n\n- Pyflakes, pep8, unused code removed, etc.\n [thomasdesvenain]\n\n\n1.2 (2014-06-03)\n----------------\n\n- Set width, and apply as chosen parameter rather than styling widgets with a\n specific width; doing so ensures chosen will set a valid width when it's\n initialized off-screen or when the element applied to it is invisible.\n [damilgra]\n\n- Updated french translations.\n [cedricmessiant]\n\n\n1.1 (2013-06-04)\n----------------\n\n- buildout, tests & travis [kiorky]\n\n- Change prompt message and update French translations.\n Fix bug for no value in List fields.\n [cedricmessiant]\n\n\n1.0 (2012-06-06)\n----------------\n\n* Initial release [kiorky]", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://pypi.python.org/pypi/collective.z3cform.chosen", "keywords": "chosen z3cform widget plone", "license": "GPL", "maintainer": null, "maintainer_email": null, "name": "collective.z3cform.chosen", "package_url": "https://pypi.org/project/collective.z3cform.chosen/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/collective.z3cform.chosen/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://pypi.python.org/pypi/collective.z3cform.chosen" }, "release_url": "https://pypi.org/project/collective.z3cform.chosen/1.2.1/", "requires_dist": null, "requires_python": null, "summary": "chosen widget for z3cform (both chosen & ajax version)", "version": "1.2.1" }, "last_serial": 1254493, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "f6922b2ab4f617301020b5da4f1b7df4", "sha256": "e9a97459b744328cfbc0887351eced165b8ae8f367029280a2e51130bfe73aa4" }, "downloads": -1, "filename": "collective.z3cform.chosen-1.0.zip", "has_sig": false, "md5_digest": "f6922b2ab4f617301020b5da4f1b7df4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 73755, "upload_time": "2012-06-06T18:12:47", "url": "https://files.pythonhosted.org/packages/0e/f4/2ec791358078b293c4da321b2ad6d70bb1c8988840436b0fbf406e345ea4/collective.z3cform.chosen-1.0.zip" } ], "1.1": [ { "comment_text": "", "digests": { "md5": "3a7fad0e73411c76885ebb192eff6c75", "sha256": "ad4b87f5306c0e8b28cc1e0e49a43710c1d1107546c5f7916d7a394ec0dc7d67" }, "downloads": -1, "filename": "collective.z3cform.chosen-1.1.zip", "has_sig": false, "md5_digest": "3a7fad0e73411c76885ebb192eff6c75", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 62285, "upload_time": "2013-06-04T16:35:27", "url": "https://files.pythonhosted.org/packages/ec/34/1975b742d5d420f0d075444107a6f1b237de33f1d72a94df1da88a16ab79/collective.z3cform.chosen-1.1.zip" } ], "1.2": [ { "comment_text": "", "digests": { "md5": "82f21a770b67f4656e5a1aba4fc3cba3", "sha256": "f555e535c7a5ba883ddc36db3e25bfaef9c05f2e6e12ae52156cd53f7cb9a011" }, "downloads": -1, "filename": "collective.z3cform.chosen-1.2.zip", "has_sig": false, "md5_digest": "82f21a770b67f4656e5a1aba4fc3cba3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 62141, "upload_time": "2014-06-03T18:40:25", "url": "https://files.pythonhosted.org/packages/a0/a9/b10ea8b0928d49162e492677cb0d8c06f2d2c1f066e78fc034ee893aaa6a/collective.z3cform.chosen-1.2.zip" } ], "1.2.1": [ { "comment_text": "", "digests": { "md5": "cd4b80a5353333ea12abbcc8179c2684", "sha256": "9c14a7cfe1f4ef18c9009cdecd8eb6a784c1e86822f0c5e129b7449ae66091b7" }, "downloads": -1, "filename": "collective.z3cform.chosen-1.2.1.zip", "has_sig": false, "md5_digest": "cd4b80a5353333ea12abbcc8179c2684", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 60542, "upload_time": "2014-09-25T11:57:15", "url": "https://files.pythonhosted.org/packages/ce/be/3386891c3567b4c993969fbed2bf8177f128430cf9cc88fcc67420f5c16b/collective.z3cform.chosen-1.2.1.zip" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "cd4b80a5353333ea12abbcc8179c2684", "sha256": "9c14a7cfe1f4ef18c9009cdecd8eb6a784c1e86822f0c5e129b7449ae66091b7" }, "downloads": -1, "filename": "collective.z3cform.chosen-1.2.1.zip", "has_sig": false, "md5_digest": "cd4b80a5353333ea12abbcc8179c2684", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 60542, "upload_time": "2014-09-25T11:57:15", "url": "https://files.pythonhosted.org/packages/ce/be/3386891c3567b4c993969fbed2bf8177f128430cf9cc88fcc67420f5c16b/collective.z3cform.chosen-1.2.1.zip" } ] }