From 4dacbdf2837ef3328fa1e84667a90e4b5477cb86 Mon Sep 17 00:00:00 2001 From: Johannes Hoppe Date: Thu, 4 Feb 2016 11:47:21 +0100 Subject: [PATCH] enchant the docs -- adds spell checking --- .travis.yml | 8 ++++++++ django_select2/cache.py | 4 ++-- django_select2/conf.py | 4 ++-- django_select2/forms.py | 26 +++++++++++++------------- django_select2/urls.py | 4 ++-- django_select2/views.py | 2 +- docs/Makefile | 5 +++++ docs/conf.py | 6 ++++++ docs/django_select2.rst | 2 +- docs/get_started.rst | 2 +- docs/spelling_wordlist.txt | 17 +++++++++++++++++ requirements_dev.in | 3 +++ requirements_dev.txt | 24 ++++++++++++++++++------ 13 files changed, 79 insertions(+), 28 deletions(-) create mode 100644 docs/spelling_wordlist.txt diff --git a/.travis.yml b/.travis.yml index accdd8a..f6a318d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: python sudo: false cache: + - apt - pip services: - memcached @@ -8,6 +9,12 @@ python: - "2.7" - "3.4" - "3.5" +addons: + apt: + packages: + - python3-enchant + - python2-enchant + - graphviz env: global: - DISPLAY=:99.0 @@ -31,6 +38,7 @@ script: - isort --check-only --recursive --diff . - flake8 --jobs=2 . - pep257 --explain --source --count django_select2 + - (cd docs; make spelling) - coverage run --source=django_select2 -m py.test after_success: - coveralls diff --git a/django_select2/cache.py b/django_select2/cache.py index ffa8cae..d817b5e 100644 --- a/django_select2/cache.py +++ b/django_select2/cache.py @@ -1,11 +1,11 @@ # -*- 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 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``]. It is advised to always setup a separate cache server for Select2. diff --git a/django_select2/conf.py b/django_select2/conf.py index f4660c1..b792598 100644 --- a/django_select2/conf.py +++ b/django_select2/conf.py @@ -58,7 +58,7 @@ class Select2Conf(AppConf): SELECT2_JS = 'assets/js/select2.min.js' .. 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' @@ -71,7 +71,7 @@ class Select2Conf(AppConf): SELECT2_CSS = 'assets/css/select2.css' .. 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: diff --git a/django_select2/forms.py b/django_select2/forms.py index b1020d3..29689a1 100644 --- a/django_select2/forms.py +++ b/django_select2/forms.py @@ -190,13 +190,13 @@ class HeavySelect2Mixin(object): super(HeavySelect2Mixin, self).__init__(**kwargs) 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: return self.data_url return reverse(self.data_view) 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) # encrypt instance Id @@ -221,7 +221,7 @@ class HeavySelect2Mixin(object): return "%s%s" % (settings.SELECT2_CACHE_PREFIX, id(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(), { 'widget': self, 'url': self.get_url(), @@ -283,7 +283,7 @@ class ModelSelect2Mixin(object): queryset = None search_fields = [] """ - Model lookups that are used to filter the queryset. + Model lookups that are used to filter the QuerySet. Example:: @@ -317,9 +317,9 @@ class ModelSelect2Mixin(object): 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() cache.set(self._get_cache_key(), { @@ -385,7 +385,7 @@ class ModelSelect2Mixin(object): raise NotImplementedError('%s, must implement "search_fields".' % self.__class__.__name__) 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 = ['' if not self.is_required else ''] if isinstance(self.choices, ModelChoiceIterator): if not self.queryset: @@ -454,8 +454,8 @@ class ModelSelect2Widget(ModelSelect2Mixin, HeavySelect2Widget): ) .. tip:: The ModelSelect2(Multiple)Widget will try - to get the queryset from the fields choices. - Therefore you don't need to define a queryset, + to get the QuerySet from the fields choices. + Therefore you don't need to define a QuerySet, 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. 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:: @@ -487,10 +487,10 @@ class ModelSelect2TagWidget(ModelSelect2Mixin, HeavySelect2TagWidget): def value_from_datadict(self, data, files, name): values = super().value_from_datadict(self, data, files, name) - queryset = self.get_queryset() - pks = queryset.filter(**{'pk__in': list(values)}).values_list('pk', flat=True) + qs = self.queryset.filter(**{'pk__in': list(values)}) + pks = set(force_text(getattr(o, pk)) for o in qs) cleaned_values = [] - for val in values: + for val in value: if force_text(val) not in pks: val = queryset.create(title=val).pk cleaned_values.append(val) diff --git a/django_select2/urls.py b/django_select2/urls.py index fc3fa5c..f0e8673 100644 --- a/django_select2/urls.py +++ b/django_select2/urls.py @@ -1,8 +1,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')), diff --git a/django_select2/views.py b/django_select2/views.py index 6c2f837..71a12aa 100644 --- a/django_select2/views.py +++ b/django_select2/views.py @@ -51,7 +51,7 @@ class AutoResponseView(BaseListView): }) def get_queryset(self): - """Get queryset from cached widget.""" + """Get QuerySet from cached widget.""" return self.widget.filter_queryset(self.term, self.queryset) def get_paginate_by(self, queryset): diff --git a/docs/Makefile b/docs/Makefile index 4122120..a26d381 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -46,6 +46,11 @@ html: @echo @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: $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml @echo diff --git a/docs/conf.py b/docs/conf.py index 8d49044..8588703 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -47,6 +47,7 @@ extensions = [ 'sphinx.ext.inheritance_diagram', 'sphinx.ext.intersphinx', 'sphinx.ext.viewcode', + 'sphinxcontrib.spelling', ] intersphinx_mapping = { @@ -55,6 +56,11 @@ intersphinx_mapping = { '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. templates_path = ['_templates'] diff --git a/docs/django_select2.rst b/docs/django_select2.rst index d1b4aab..ebd36d5 100644 --- a/docs/django_select2.rst +++ b/docs/django_select2.rst @@ -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! 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.:: $('.django-select2').djangoSelect2(); diff --git a/docs/get_started.rst b/docs/get_started.rst index 23bef6a..6c941f4 100644 --- a/docs/get_started.rst +++ b/docs/get_started.rst @@ -18,7 +18,7 @@ Installation 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>`:: url(r'^select2/', include('django_select2.urls')), diff --git a/docs/spelling_wordlist.txt b/docs/spelling_wordlist.txt new file mode 100644 index 0000000..17f4100 --- /dev/null +++ b/docs/spelling_wordlist.txt @@ -0,0 +1,17 @@ +jQuery +Django +mixin +backend +redis +memcached +AJAX +Cloudflare +lookup +QuerySet +pre +py +lookups +functionalities +plugin +multi +Indices diff --git a/requirements_dev.in b/requirements_dev.in index 69a9de5..8cc821d 100644 --- a/requirements_dev.in +++ b/requirements_dev.in @@ -7,3 +7,6 @@ pep257 pytest pytest-django selenium +sphinx +sphinxcontrib-spelling +pyenchant \ No newline at end of file diff --git a/requirements_dev.txt b/requirements_dev.txt index f7877b0..696eabb 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -4,16 +4,28 @@ # # pip-compile requirements_dev.in # +alabaster==0.7.7 # via sphinx +babel==2.2.0 # via sphinx django-appconf==1.0.1 -flake8==2.5.0 +docutils==0.12 # via sphinx +flake8==2.5.2 isort==4.2.2 -mccabe==0.3.1 +Jinja2==2.8 +MarkupSafe==0.23 +mccabe==0.4.0 pep257==0.7.0 pep8-naming==0.3.3 -pep8==1.5.7 # via flake8 +pep8==1.7.0 # via flake8 py==1.4.31 # via pytest +pyenchant==1.6.6 pyflakes==1.0.0 # via flake8 +Pygments==2.1 pytest-django==2.9.1 -pytest==2.8.3 -selenium==2.48.0 -six==1.10.0 # via django-appconf +pytest==2.8.7 +pytz==2015.7 # via babel +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