diff --git a/.travis.yml b/.travis.yml index dac4f0c..d3e75cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -41,7 +41,7 @@ stages: jobs: include: - - python: "3.5" + - python: "3.7" env: TOXENV=docs addons: apt: diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst new file mode 100644 index 0000000..d3ccb2e --- /dev/null +++ b/CONTRIBUTING.rst @@ -0,0 +1,22 @@ +Contributing +============ + +This package uses the pyTest test runner. To run the tests locally simply run:: + + python setup.py test + +If you need to the development dependencies installed of you local IDE, you can run:: + + python setup.py develop + +Documentation pull requests welcome. The Sphinx documentation can be compiled via:: + + python setup.py build_sphinx + +Bug reports welcome, even more so if they include a correct patch. Much +more so if you start your patch by adding a failing unit test, and correct +the code until zero unit tests fail. + +The list of supported Django and Python version can be found in the CI suite setup. +Please make sure to verify that none of the linters or tests failed, before you submit +a patch for review. diff --git a/django_select2/forms.py b/django_select2/forms.py index c650557..1fa858a 100644 --- a/django_select2/forms.py +++ b/django_select2/forms.py @@ -20,10 +20,11 @@ Widgets are generally of two types: drop-in-replacement for Django's default select widgets. - 2. **Heavy** -- + 2(a). **Heavy** -- They are suited for scenarios when the number of options are large and need complex queries (from maybe different sources) to get the options. + This dynamic fetching of options undoubtedly requires Ajax communication with the server. Django-Select2 includes a helper JS file which is included automatically, @@ -31,15 +32,15 @@ Widgets are generally of two types: Although on the server side you do need to create a view specifically to respond to the queries. - 3. **Model** -- + 2(b). **Model** -- Model-widgets are a further specialized versions of Heavies. These do not require views to serve Ajax requests. When they are instantiated, they register themselves with one central view which handles Ajax requests for them. -Heavy widgets have the word 'Heavy' in their name. -Light widgets are normally named, i.e. there is no -'Light' word in their names. +Heavy and Model widgets have respectively the word 'Heavy' and 'Model' in +their name. Light widgets are normally named, i.e. there is no 'Light' word +in their names. .. inheritance-diagram:: django_select2.forms :parts: 1 diff --git a/docs/CONTRIBUTING.rst b/docs/CONTRIBUTING.rst new file mode 100644 index 0000000..e582053 --- /dev/null +++ b/docs/CONTRIBUTING.rst @@ -0,0 +1 @@ +.. include:: ../CONTRIBUTING.rst diff --git a/docs/django_select2.rst b/docs/django_select2.rst index e8d0423..b726099 100644 --- a/docs/django_select2.rst +++ b/docs/django_select2.rst @@ -49,8 +49,9 @@ DjangoSelect2 handles the initialization of select2 fields automatically. Just i ``{{ form.media.js }}`` in your template before the closing ``body`` tag. That's it! If you insert forms after page load or if you want to handle the initialization -yourself, DjangoSelect2 provides a jQuery plugin. It will handle both normal and -heavy fields. Simply call ``djangoSelect2(options)`` on your select fields.:: +yourself, DjangoSelect2 provides a jQuery plugin, replacing and enhancing the Select2 +plugin. It will handle both normal and heavy fields. Simply call +``djangoSelect2(options)`` on your select fields.:: $('.django-select2').djangoSelect2(); @@ -59,6 +60,9 @@ You can pass see `Select2 options `_ if $('.django-select2').djangoSelect2({placeholder: 'Select an option'}); +Please replace all your ``.select2`` invocations with the here provided +``.djangoSelect2``. + Security & Authentication ------------------------- diff --git a/docs/get_started.rst b/docs/get_started.rst index a9571a5..3af8b26 100644 --- a/docs/get_started.rst +++ b/docs/get_started.rst @@ -8,6 +8,12 @@ Overview .. automodule:: django_select2 :members: +Assumptions +----------- + +* You have a running Django up and running. +* You have form fully working without Django-Select2. + Installation ------------ @@ -17,11 +23,12 @@ Installation 2. Add ``django_select2`` to your ``INSTALLED_APPS`` in your project settings. +3. Add ``django_select`` to your ``urlconf``:: -3. Add ``django_select`` to your ``urlconf`` **if** you use any -:class:`ModelWidgets <.django_select2.forms.ModelSelect2Mixin>`:: + path('select2/', include('django_select2.urls')), - url(r'^select2/', include('django_select2.urls')), + You can safely skip this one if you do not use any + :class:`ModelWidgets <.django_select2.forms.ModelSelect2Mixin>` Quick Start ----------- @@ -30,19 +37,22 @@ Here is a quick example to get you started: 0. Follow the installation instructions above. -1. Add a select2 widget to the form. For example if you wanted Select2 with multi-select you would use -``Select2MultipleWidget`` -Replacing:: +1. Replace native Django forms widgets with one of the several ``django_select2.form`` widgets. + Start by importing them into your ``forms.py``, right next to Django own ones:: - class MyForm(forms.Form): - things = ModelMultipleChoiceField(queryset=Thing.objects.all()) + from django import forms + from django_select2 import forms as s2forms -with:: + Then let's assume you have a model with a choice, a :class:`.ForeignKey`, and a + :class:`.ManyToManyField`, you would add this information to your Form Meta + class:: - from django_select2.forms import Select2MultipleWidget - - class MyForm(forms.Form): - things = ModelMultipleChoiceField(queryset=Thing.objects.all(), widget=Select2MultipleWidget) + widgets = { + 'category': s2forms.Select2Widget, + 'author': s2forms.ModelSelect2Widget(model=auth.get_user_model(), + search_fields=['first_name__istartswith', 'last_name__icontains']), + 'attending': s2forms.ModelSelect2MultipleWidget … + } 2. Add the CSS to the ``head`` of your Django template:: diff --git a/docs/index.rst b/docs/index.rst index b0e8051..dedf2e9 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -15,6 +15,7 @@ Contents: get_started django_select2 extra + CONTRIBUTING Indices and tables ==================