mirror of
https://github.com/Hopiu/django-select2.git
synced 2026-05-20 02:31:52 +00:00
enchant the docs -- adds spell checking
This commit is contained in:
parent
bc9601b3d3
commit
4dacbdf283
13 changed files with 79 additions and 28 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
language: python
|
language: python
|
||||||
sudo: false
|
sudo: false
|
||||||
cache:
|
cache:
|
||||||
|
- apt
|
||||||
- pip
|
- pip
|
||||||
services:
|
services:
|
||||||
- memcached
|
- memcached
|
||||||
|
|
@ -8,6 +9,12 @@ python:
|
||||||
- "2.7"
|
- "2.7"
|
||||||
- "3.4"
|
- "3.4"
|
||||||
- "3.5"
|
- "3.5"
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
packages:
|
||||||
|
- python3-enchant
|
||||||
|
- python2-enchant
|
||||||
|
- graphviz
|
||||||
env:
|
env:
|
||||||
global:
|
global:
|
||||||
- DISPLAY=:99.0
|
- DISPLAY=:99.0
|
||||||
|
|
@ -31,6 +38,7 @@ script:
|
||||||
- isort --check-only --recursive --diff .
|
- isort --check-only --recursive --diff .
|
||||||
- flake8 --jobs=2 .
|
- flake8 --jobs=2 .
|
||||||
- pep257 --explain --source --count django_select2
|
- pep257 --explain --source --count django_select2
|
||||||
|
- (cd docs; make spelling)
|
||||||
- coverage run --source=django_select2 -m py.test
|
- coverage run --source=django_select2 -m py.test
|
||||||
after_success:
|
after_success:
|
||||||
- coveralls
|
- coveralls
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""
|
"""
|
||||||
Shared memory across multiple machines to the heavy ajax lookups.
|
Shared memory across multiple machines to the heavy AJAX lookups.
|
||||||
|
|
||||||
Select2 uses django.core.cache_ to share fields across
|
Select2 uses django.core.cache_ to share fields across
|
||||||
multiple threads and even machines.
|
multiple threads and even machines.
|
||||||
|
|
||||||
Select2 uses the cabhe backend defind in the setting
|
Select2 uses the cache backend defined in the setting
|
||||||
``SELECT2_CACHE_BACKEND`` [default=``default``].
|
``SELECT2_CACHE_BACKEND`` [default=``default``].
|
||||||
|
|
||||||
It is advised to always setup a separate cache server for Select2.
|
It is advised to always setup a separate cache server for Select2.
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ class Select2Conf(AppConf):
|
||||||
SELECT2_JS = 'assets/js/select2.min.js'
|
SELECT2_JS = 'assets/js/select2.min.js'
|
||||||
|
|
||||||
.. tip:: Change this setting to a local asset in your development environment to
|
.. tip:: Change this setting to a local asset in your development environment to
|
||||||
develop without an internet connection.
|
develop without an Internet connection.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
CSS = '//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css'
|
CSS = '//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css'
|
||||||
|
|
@ -71,7 +71,7 @@ class Select2Conf(AppConf):
|
||||||
SELECT2_CSS = 'assets/css/select2.css'
|
SELECT2_CSS = 'assets/css/select2.css'
|
||||||
|
|
||||||
.. tip:: Change this setting to a local asset in your development environment to
|
.. tip:: Change this setting to a local asset in your development environment to
|
||||||
develop without an internet connection.
|
develop without an Internet connection.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
||||||
|
|
@ -190,13 +190,13 @@ class HeavySelect2Mixin(object):
|
||||||
super(HeavySelect2Mixin, self).__init__(**kwargs)
|
super(HeavySelect2Mixin, self).__init__(**kwargs)
|
||||||
|
|
||||||
def get_url(self):
|
def get_url(self):
|
||||||
"""Return url from instance or by reversing :attr:`.data_view`."""
|
"""Return URL from instance or by reversing :attr:`.data_view`."""
|
||||||
if self.data_url:
|
if self.data_url:
|
||||||
return self.data_url
|
return self.data_url
|
||||||
return reverse(self.data_view)
|
return reverse(self.data_view)
|
||||||
|
|
||||||
def build_attrs(self, extra_attrs=None, **kwargs):
|
def build_attrs(self, extra_attrs=None, **kwargs):
|
||||||
"""Set select2's ajax attributes."""
|
"""Set select2's AJAX attributes."""
|
||||||
attrs = super(HeavySelect2Mixin, self).build_attrs(extra_attrs=extra_attrs, **kwargs)
|
attrs = super(HeavySelect2Mixin, self).build_attrs(extra_attrs=extra_attrs, **kwargs)
|
||||||
|
|
||||||
# encrypt instance Id
|
# encrypt instance Id
|
||||||
|
|
@ -221,7 +221,7 @@ class HeavySelect2Mixin(object):
|
||||||
return "%s%s" % (settings.SELECT2_CACHE_PREFIX, id(self))
|
return "%s%s" % (settings.SELECT2_CACHE_PREFIX, id(self))
|
||||||
|
|
||||||
def set_to_cache(self):
|
def set_to_cache(self):
|
||||||
"""Add widget object to Djnago's cache."""
|
"""Add widget object to Django's cache."""
|
||||||
cache.set(self._get_cache_key(), {
|
cache.set(self._get_cache_key(), {
|
||||||
'widget': self,
|
'widget': self,
|
||||||
'url': self.get_url(),
|
'url': self.get_url(),
|
||||||
|
|
@ -283,7 +283,7 @@ class ModelSelect2Mixin(object):
|
||||||
queryset = None
|
queryset = None
|
||||||
search_fields = []
|
search_fields = []
|
||||||
"""
|
"""
|
||||||
Model lookups that are used to filter the queryset.
|
Model lookups that are used to filter the QuerySet.
|
||||||
|
|
||||||
Example::
|
Example::
|
||||||
|
|
||||||
|
|
@ -317,9 +317,9 @@ class ModelSelect2Mixin(object):
|
||||||
|
|
||||||
def set_to_cache(self):
|
def set_to_cache(self):
|
||||||
"""
|
"""
|
||||||
Add widget's attributes to Djnago's cache.
|
Add widget's attributes to Django's cache.
|
||||||
|
|
||||||
Split the queryset, to not pickle the result set.
|
Split the QuerySet, to not pickle the result set.
|
||||||
"""
|
"""
|
||||||
queryset = self.get_queryset()
|
queryset = self.get_queryset()
|
||||||
cache.set(self._get_cache_key(), {
|
cache.set(self._get_cache_key(), {
|
||||||
|
|
@ -385,7 +385,7 @@ class ModelSelect2Mixin(object):
|
||||||
raise NotImplementedError('%s, must implement "search_fields".' % self.__class__.__name__)
|
raise NotImplementedError('%s, must implement "search_fields".' % self.__class__.__name__)
|
||||||
|
|
||||||
def render_options(self, choices, selected_choices):
|
def render_options(self, choices, selected_choices):
|
||||||
"""Render only selected options and set queryset from :class:`ModelChoicesIterator`."""
|
"""Render only selected options and set QuerySet from :class:`ModelChoicesIterator`."""
|
||||||
output = ['<option></option>' if not self.is_required else '']
|
output = ['<option></option>' if not self.is_required else '']
|
||||||
if isinstance(self.choices, ModelChoiceIterator):
|
if isinstance(self.choices, ModelChoiceIterator):
|
||||||
if not self.queryset:
|
if not self.queryset:
|
||||||
|
|
@ -454,8 +454,8 @@ class ModelSelect2Widget(ModelSelect2Mixin, HeavySelect2Widget):
|
||||||
)
|
)
|
||||||
|
|
||||||
.. tip:: The ModelSelect2(Multiple)Widget will try
|
.. tip:: The ModelSelect2(Multiple)Widget will try
|
||||||
to get the queryset from the fields choices.
|
to get the QuerySet from the fields choices.
|
||||||
Therefore you don't need to define a queryset,
|
Therefore you don't need to define a QuerySet,
|
||||||
if you just drop in the widget for a ForeignKey field.
|
if you just drop in the widget for a ForeignKey field.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
@ -478,7 +478,7 @@ class ModelSelect2TagWidget(ModelSelect2Mixin, HeavySelect2TagWidget):
|
||||||
|
|
||||||
This it not a simple drop in widget.
|
This it not a simple drop in widget.
|
||||||
It requires to implement you own :func:`.value_from_datadict`
|
It requires to implement you own :func:`.value_from_datadict`
|
||||||
that adds missing tags to you queryset.
|
that adds missing tags to you QuerySet.
|
||||||
|
|
||||||
Example::
|
Example::
|
||||||
|
|
||||||
|
|
@ -487,10 +487,10 @@ class ModelSelect2TagWidget(ModelSelect2Mixin, HeavySelect2TagWidget):
|
||||||
|
|
||||||
def value_from_datadict(self, data, files, name):
|
def value_from_datadict(self, data, files, name):
|
||||||
values = super().value_from_datadict(self, data, files, name)
|
values = super().value_from_datadict(self, data, files, name)
|
||||||
queryset = self.get_queryset()
|
qs = self.queryset.filter(**{'pk__in': list(values)})
|
||||||
pks = queryset.filter(**{'pk__in': list(values)}).values_list('pk', flat=True)
|
pks = set(force_text(getattr(o, pk)) for o in qs)
|
||||||
cleaned_values = []
|
cleaned_values = []
|
||||||
for val in values:
|
for val in value:
|
||||||
if force_text(val) not in pks:
|
if force_text(val) not in pks:
|
||||||
val = queryset.create(title=val).pk
|
val = queryset.create(title=val).pk
|
||||||
cleaned_values.append(val)
|
cleaned_values.append(val)
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""
|
"""
|
||||||
Django-Select2 url config.
|
Django-Select2 URL configuration.
|
||||||
|
|
||||||
Add `django_select` to your urlconf **if** you use any 'Model' fields::
|
Add `django_select` to your ``urlconf`` **if** you use any 'Model' fields::
|
||||||
|
|
||||||
url(r'^select2/', include('django_select2.urls')),
|
url(r'^select2/', include('django_select2.urls')),
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ class AutoResponseView(BaseListView):
|
||||||
})
|
})
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
"""Get queryset from cached widget."""
|
"""Get QuerySet from cached widget."""
|
||||||
return self.widget.filter_queryset(self.term, self.queryset)
|
return self.widget.filter_queryset(self.term, self.queryset)
|
||||||
|
|
||||||
def get_paginate_by(self, queryset):
|
def get_paginate_by(self, queryset):
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,11 @@ html:
|
||||||
@echo
|
@echo
|
||||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
|
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
|
||||||
|
|
||||||
|
spelling:
|
||||||
|
$(SPHINXBUILD) -b spelling -W $(ALLSPHINXOPTS) $(BUILDDIR)/spelling
|
||||||
|
@echo
|
||||||
|
@echo "Spell check finished. The results are in $(BUILDDIR)/spelling."
|
||||||
|
|
||||||
dirhtml:
|
dirhtml:
|
||||||
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
|
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
|
||||||
@echo
|
@echo
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ extensions = [
|
||||||
'sphinx.ext.inheritance_diagram',
|
'sphinx.ext.inheritance_diagram',
|
||||||
'sphinx.ext.intersphinx',
|
'sphinx.ext.intersphinx',
|
||||||
'sphinx.ext.viewcode',
|
'sphinx.ext.viewcode',
|
||||||
|
'sphinxcontrib.spelling',
|
||||||
]
|
]
|
||||||
|
|
||||||
intersphinx_mapping = {
|
intersphinx_mapping = {
|
||||||
|
|
@ -55,6 +56,11 @@ intersphinx_mapping = {
|
||||||
'https://docs.djangoproject.com/en/dev/_objects/'),
|
'https://docs.djangoproject.com/en/dev/_objects/'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# spell check
|
||||||
|
spelling_word_list_filename = 'spelling_wordlist.txt'
|
||||||
|
spelling_show_suggestions = True
|
||||||
|
|
||||||
|
|
||||||
# Add any paths that contain templates here, relative to this directory.
|
# Add any paths that contain templates here, relative to this directory.
|
||||||
templates_path = ['_templates']
|
templates_path = ['_templates']
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ DjangoSelect2 handles the initialization of select2 fields automatically. Just i
|
||||||
``{{ form.media.js }}`` in your template before the closing ``body`` tag. That's it!
|
``{{ 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
|
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
|
yourself, DjangoSelect2 provides a jQuery plugin. It will handle both normal and
|
||||||
heavy fields. Simply call ``djangoSelect2(options)`` on your select fields.::
|
heavy fields. Simply call ``djangoSelect2(options)`` on your select fields.::
|
||||||
|
|
||||||
$('.django-select2').djangoSelect2();
|
$('.django-select2').djangoSelect2();
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ Installation
|
||||||
2. Add ``django_select2`` to your ``INSTALLED_APPS`` in your project settings.
|
2. Add ``django_select2`` to your ``INSTALLED_APPS`` in your project settings.
|
||||||
|
|
||||||
|
|
||||||
3. Add ``django_select`` to your urlconf **if** you use any
|
3. Add ``django_select`` to your ``urlconf`` **if** you use any
|
||||||
:class:`ModelWidgets <.django_select2.forms.ModelSelect2Mixin>`::
|
:class:`ModelWidgets <.django_select2.forms.ModelSelect2Mixin>`::
|
||||||
|
|
||||||
url(r'^select2/', include('django_select2.urls')),
|
url(r'^select2/', include('django_select2.urls')),
|
||||||
|
|
|
||||||
17
docs/spelling_wordlist.txt
Normal file
17
docs/spelling_wordlist.txt
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
jQuery
|
||||||
|
Django
|
||||||
|
mixin
|
||||||
|
backend
|
||||||
|
redis
|
||||||
|
memcached
|
||||||
|
AJAX
|
||||||
|
Cloudflare
|
||||||
|
lookup
|
||||||
|
QuerySet
|
||||||
|
pre
|
||||||
|
py
|
||||||
|
lookups
|
||||||
|
functionalities
|
||||||
|
plugin
|
||||||
|
multi
|
||||||
|
Indices
|
||||||
|
|
@ -7,3 +7,6 @@ pep257
|
||||||
pytest
|
pytest
|
||||||
pytest-django
|
pytest-django
|
||||||
selenium
|
selenium
|
||||||
|
sphinx
|
||||||
|
sphinxcontrib-spelling
|
||||||
|
pyenchant
|
||||||
|
|
@ -4,16 +4,28 @@
|
||||||
#
|
#
|
||||||
# pip-compile requirements_dev.in
|
# pip-compile requirements_dev.in
|
||||||
#
|
#
|
||||||
|
alabaster==0.7.7 # via sphinx
|
||||||
|
babel==2.2.0 # via sphinx
|
||||||
django-appconf==1.0.1
|
django-appconf==1.0.1
|
||||||
flake8==2.5.0
|
docutils==0.12 # via sphinx
|
||||||
|
flake8==2.5.2
|
||||||
isort==4.2.2
|
isort==4.2.2
|
||||||
mccabe==0.3.1
|
Jinja2==2.8
|
||||||
|
MarkupSafe==0.23
|
||||||
|
mccabe==0.4.0
|
||||||
pep257==0.7.0
|
pep257==0.7.0
|
||||||
pep8-naming==0.3.3
|
pep8-naming==0.3.3
|
||||||
pep8==1.5.7 # via flake8
|
pep8==1.7.0 # via flake8
|
||||||
py==1.4.31 # via pytest
|
py==1.4.31 # via pytest
|
||||||
|
pyenchant==1.6.6
|
||||||
pyflakes==1.0.0 # via flake8
|
pyflakes==1.0.0 # via flake8
|
||||||
|
Pygments==2.1
|
||||||
pytest-django==2.9.1
|
pytest-django==2.9.1
|
||||||
pytest==2.8.3
|
pytest==2.8.7
|
||||||
selenium==2.48.0
|
pytz==2015.7 # via babel
|
||||||
six==1.10.0 # via django-appconf
|
selenium==2.50.1
|
||||||
|
six==1.10.0 # via django-appconf, sphinx, sphinxcontrib-spelling
|
||||||
|
snowballstemmer==1.2.1 # via sphinx
|
||||||
|
sphinx-rtd-theme==0.1.9 # via sphinx
|
||||||
|
sphinx==1.3.5
|
||||||
|
sphinxcontrib-spelling==2.1.2
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue