{ "info": { "author": "Samuel Goldszmidt", "author_email": "samuel.goldszmidt@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python" ], "description": "Django-Select2Light\n===================\n\n[![Build Status](https://travis-ci.org/ouhouhsami/django-select2light.png?branch=master)](https://travis-ci.org/ouhouhsami/django-select2light)\n\nThis is a [Django](https://www.djangoproject.com/) integration of [Select2](http://ivaynberg.github.com/select2/).\n\nThe app includes Select2 driven Django Widgets, and is based on an initial great work by [AppleGrew](https://github.com/applegrew)\n\n\nInstallation\n============\n\n1. Install Django_Select2Light\n\n pip install django_select2light\n\n2. Add `select2light` to your `INSTALLED_APPS` in your project settings (you must also add `floppyforms` and `tastypie`)\n\n3. When deploying on production server, run\n\n python manage.py collectstatic\n\n\nExternal Dependencies\n=====================\n\n* django, as long as this is a django app ...\n* django-floppyforms, used to create the select2 html templates\n* django-tastypie, used to build the ajax requests\n\nNote: \n* This application provides a copy of jquery and a 'personal ugly hack' of select2 version 3.3.2 (see select2light/static/select2-3.3.2/select2.js initSelection: for single and multi fields)\n* For this package I used [django-tastypie](http://django-tastypie.readthedocs.org/en/latest/), but we could easily use [django-rest-framework](http://django-rest-framework.org/), as well a [django-piston](https://django-piston.readthedocs.org/en/latest/documentation.html))\n\n\nUsage\n=====\n\nSelect2Widget and Select2MultipleWidget\n---------------------------------------\n\nThis is just a widget customization. Using Select2Widget or Select2MultipleWidget, you will replace the default widget with Select2Widget for your ModelChoiceField or Select2MultipleWidget for your ModelMultipleChoiceField.\n\nYou can set it as follow:\n\n\timport floppyforms as forms\n\tfrom select2light.models import Select2ModelChoiceField, Select2ModelMultipleChoiceField\n\tfrom select2light.widgets import Select2Widget, Select2MultipleWidget\n\tform models import Bar, Baz\n\n\t# use directly the custom field\n\tclass FooForm(forms.Form):\n\t\tbar = Select2ModelChoiceField(queryset=Bar.objects.all()) \n\t\tbazs = Select2ModelMultipleChoiceField(queryset=Baz.objects.all())\n\n\t# ... or just use the widget\n\tclass FooForm(forms.Form):\n\t\tbar = forms.ModelChoiceField(queryset=Bar.objects.all(), widget=Select2Widget) \n\t\tbazs = forms.ModelMultipleChoiceField(queryset=Baz.objects.all(), widget=Select2MultipleWidget)\n\n\nYou can also see an usage exemple within the `EmployeeForm` ModelForm class Meta in [forms.py](https://github.com/ouhouhsami/django-select2light/blob/master/testapp/testapp/testmain/forms.py#L13)\n\nNote: \n* If you only use Select2Widget (and not the Ajax widgets as described below), you don't need to install tastypie nor floppyforms.\n* If you want to set specific params to the Select2 instanciation (see list in Constructor part of this page http://ivaynberg.github.io/select2/), for this case, you need to override the default select2light/select2.html template. Depending on user needs, we could consider, as below for the Ajax widgets, having some instantiations params that would configure select2 widget.\n\n\nAjaxSelect2Widget and AjaxSelect2MultipleWidget\n-----------------------------------------------\n\n### django-tastypie part\n\nCreate a ModelResource for resources (in most cases, Django models) you would like to use with Select2 as widget. For this, you must read [django-tastypie](http://django-tastypie.readthedocs.org/en/latest/) documentation. Here are the outlines: \n\nCreate a ModelResource for a Django model in `api.py` file inside your app (see [api.py](https://github.com/ouhouhsami/django-select2light/blob/master/testapp/testapp/testmain/api.py))\n\n\t# api.py file\n\tfrom tastypie.resources import ModelResource\n\tfrom tastypie.constants import ALL\n\tfrom models import Bar\n\n\tclass BarResource(ModelResource):\n\n \tclass Meta:\n \tqueryset = Bar.objects.all()\n \tresource_name = 'bar'\n \tfiltering = {\n \t'name': ALL # assuming Bar has a field named name\n \t}\n\n\nSet the urls with your API enabled (see [urls.py](https://github.com/ouhouhsami/django-select2light/blob/master/testapp/testapp/urls.py)), referencing your ModelResources.\n\n\t# urls.py file\n\tfrom django.conf.urls import *\n\tfrom tastypie.api import Api\n\tfrom myapp.api import BarResource\n\n\tfoo_api = Api(api_name='foobar')\n\tfoo_api.register(BarResource())\n\n\t# ... your urlpatterns\n\n\turlpatterns += patterns('',\n (r'^api/', include(foo_api.urls)),\n )\n\t\n\n### select2light part\n\nAssociate `AjaxSelect2Widget` to your `ModelChoiceField` (or `AjaxSelect2MultipleWidget` to your `ModelMultipleChoiceField`) in a Form class. \nInside `AjaxSelect2Widget` (or `AjaxSelect2MultipleWidget`) you configure the following params: \n* `resource_name` (required) is the value set in your tastypie ModelResource (see example [api.py](https://github.com/ouhouhsami/django-select2light/blob/master/testapp/testapp/testmain/api.py#L14))\n* `api_name` (required) is the value of your api, set in your urls.py (see example [urls.py](https://github.com/ouhouhsami/django-select2light/blob/master/testapp/testapp/urls.py#L6))\n* `label_key` (optional) corresponds to the field you want to search on in your ModelResource. Default is set to 'name'. There are two ways to work with it: you can add a field name `name` to your ModelResource (and [use dehydrate tastypie functionality](http://django-tastypie.readthedocs.org/en/latest/cookbook.html#adding-custom-values)) or you can set `label_key` to a custom field on your ModelResource to search by this key.\n\n```\n# forms.py file\nfrom models import Bar\nimport floppyforms as forms\nform select2light.models import AjaxSelect2ModelChoiceField, AjaxSelect2ModelMultipleChoiceField\nform select2light.wigets import AjaxSelect2Widget, AjaxSelect2MultipleWidget\n\n# use directly the custom field\nclass FooForm(form.Form):\n\t# assuming Bar model has a name field\n\tbar = AjaxSelect2ModelChoiceField(queryset=Bar.objects.all(),\n\t resource_name='bar', api_name='foobar')\n\tbazs = AjaxSelect2ModelMultipleChoiceField(queryset=Baz.objects.all(),\n\t resource_name='bar', api_name='foobar')\n\n# ... or just use the widget\nclass FooForm(form.Form):\n\t# assuming Bar model has a name field\n\tbar = forms.ModelChoiceField(queryset=Bar.objects.all(),\n\t widget=AjaxSelect2Widget(resource_name='bar', api_name='foobar'))\n\tbazs = forms.ModelMultipleChoiceField(queryset=Baz.objects.all(),\n\t\t\t\t\t\t\t\t\t\t widget=AjaxSelect2MultipleWidget(resource_name='baz', api_name='foobar'))\n```\n\nNote:\nFor ModelForm you can just override widget dict in class Meta of your ModelForm, as done in test app [forms.py](https://github.com/ouhouhsami/django-select2light/blob/master/testapp/testapp/testmain/forms.py#L15). \n\n\nAdmin integration\n=================\n\nYou can use the widgets or the fields in the admin. The testapp project propose different use cases, see [admin.py](https://github.com/ouhouhsami/django-select2light/blob/master/testapp/testapp/testmain/admin.py) for examples.\n\n\nTo go further (shared ideas)\n============================\n\n* Consider replacing Select2 with a custom HTML5 datalist implementation\n* Be Rest framework agnostic, try to work with any of the Django Rest Framework mentioned above\n* Remove 'Hold down \"Control\", or \"Command\" on a Mac, to select more than one.' on select multiple widget rendering.\n\n\nChangelog\n=========\n\n0.3\n* Add Travis CI as continuous integration service\n* Add admin integration examples\n\n0.2\n* Add tests\n* Add fields Select2ModelChoiceField, Select2ModelMultipleChoiceField, AjaxSelect2ModelChoiceField, AjaxSelect2ModelMultipleChoiceField for convenience\n* Update README\n\n0.1\n* First release to test the feasibility, using base structuration proposed by [AppleGrew](https://github.com/applegrew)\n\n\nExample Application\n===================\n\nPlease see `testapp` application. \nThis application is used to manually test the functionalities of this package. This also serves as a good starting point example.\n\nYou can test django-select2light using github repository (also you should consider using virtualenv and virtualenvwrapper)\n\n\tmkvirtualenv django-select2light-test\n\tgit clone https://github.com/ouhouhsami/django-select2light.git\n\tcd django-select2light\n\tpip install -r requirements.txt\n\tpip install -r requirements-tests.txt\n\tadd2virtualenv select2light\n\tcd testapp\n\tpython manage.py syncdb\n\tpython manage.py runserver\n\nThen go to http://127.0.0.1:8000/ !\n\n\nYou can also test this application using the tar.gz archive available on pypi.\n\n\tDownload the tar.gz https://pypi.python.org/pypi/django-select2light/\n\tExtract it\n\trun 'python setup.py install'\n\tinstall converage and django-coverage\n\tcd into testapp\n\tpython manage.py syncdb\n\tpython manage.py runserver\n\tgo to http://127.0.0.1:8000/\n\n\nLicense\n=======\n\nCopyright 2012 Samuel Goldszmidt\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this project except in compliance with the License.\nYou may obtain a copy of the License at\n\n[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/ouhouhsami/django-select2light", "keywords": null, "license": "Apache License 2.0", "maintainer": null, "maintainer_email": null, "name": "django-select2light", "package_url": "https://pypi.org/project/django-select2light/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-select2light/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/ouhouhsami/django-select2light" }, "release_url": "https://pypi.org/project/django-select2light/0.3/", "requires_dist": null, "requires_python": null, "summary": "Select2 widget 'light edition' for Django projects", "version": "0.3" }, "last_serial": 790558, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "1825e01af259f7e9cf2f75c80804eddb", "sha256": "f10e367665ba77674253d81332cad4d65124510125000773d843b989c0024b06" }, "downloads": -1, "filename": "django-select2light-0.1.tar.gz", "has_sig": false, "md5_digest": "1825e01af259f7e9cf2f75c80804eddb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 84843, "upload_time": "2013-05-06T15:58:35", "url": "https://files.pythonhosted.org/packages/c8/79/bc685a8597b804b03dd9671b326ad6843f15057911d01a65c9035bde89de/django-select2light-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "0a691f580e0aac43020f34f409f941c8", "sha256": "0e0e6e585328bb3f50c9e446025985950195991f46d31b21e50ac0961c8ae4b2" }, "downloads": -1, "filename": "django-select2light-0.2.tar.gz", "has_sig": false, "md5_digest": "0a691f580e0aac43020f34f409f941c8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 87443, "upload_time": "2013-05-13T09:40:34", "url": "https://files.pythonhosted.org/packages/e7/6d/6e17c0b98c7a0df93a23a37d078a8b577334342a863408469b7fc285754b/django-select2light-0.2.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "af973927732af9ed3be236fad1a34841", "sha256": "766a0fdfcc334dc35b441f9e5046cf47df1ef7dc3c87024ea7407b32a6b18177" }, "downloads": -1, "filename": "django-select2light-0.3.tar.gz", "has_sig": false, "md5_digest": "af973927732af9ed3be236fad1a34841", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 88068, "upload_time": "2013-05-14T09:12:51", "url": "https://files.pythonhosted.org/packages/7a/38/6f6c4055f8ca98c9e5b64dcbadd8f187b544b028d5c5decbeaa51bac0ced/django-select2light-0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "af973927732af9ed3be236fad1a34841", "sha256": "766a0fdfcc334dc35b441f9e5046cf47df1ef7dc3c87024ea7407b32a6b18177" }, "downloads": -1, "filename": "django-select2light-0.3.tar.gz", "has_sig": false, "md5_digest": "af973927732af9ed3be236fad1a34841", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 88068, "upload_time": "2013-05-14T09:12:51", "url": "https://files.pythonhosted.org/packages/7a/38/6f6c4055f8ca98c9e5b64dcbadd8f187b544b028d5c5decbeaa51bac0ced/django-select2light-0.3.tar.gz" } ] }