From 5fc33eb9bbf07267bb8a97a0e6fb84966483ba5b Mon Sep 17 00:00:00 2001 From: Domenico DiNicola Date: Sun, 2 Mar 2025 18:55:17 +0100 Subject: [PATCH] fix --- .github/workflows/tests.yml | 4 +- .travis.yml | 15 ---- docs/conf.py | 111 ++++++++++++++-------------- example/example/wsgi.py | 1 + selectable/__init__.py | 1 - selectable/base.py | 1 + selectable/decorators.py | 3 +- selectable/forms/fields.py | 5 +- selectable/registry.py | 6 +- selectable/tests/test_decorators.py | 4 +- selectable/tests/test_functional.py | 8 +- setup.py | 3 + tox.ini | 3 +- 13 files changed, 85 insertions(+), 80 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3a50026..9a7067e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -24,8 +24,8 @@ jobs: strategy: fail-fast: false matrix: - python-version: [ "3.9", "3.10", "3.11"] - django-version: [ "3.2", "4.2"] + python-version: [ "3.9", "3.10", "3.11", "3.12, "3.13"] + django-version: [ "3.2", "4.2", "5.1"] env: PY_VER: ${{ matrix.python-version}} DJ_VER: ${{ matrix.django-version}} diff --git a/.travis.yml b/.travis.yml index b66da2a..7f7da99 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,21 +4,6 @@ dist: bionic matrix: fast_finish: true - include: - - { python: "3.6", env: DJANGO=1.11 } - - { python: "3.6", env: DJANGO=2.1 } - - { python: "3.6", env: DJANGO=2.2 } - - { python: "3.6", env: DJANGO=3.0 } - - - { python: "3.7", env: DJANGO=1.11 } - - { python: "3.7", env: DJANGO=2.1 } - - { python: "3.7", env: DJANGO=2.2 } - - { python: "3.7", env: DJANGO=3.0 } - - { python: "3.7", env: DJANGO=master } - - - { python: "3.8", env: DJANGO=2.2 } - - { python: "3.8", env: DJANGO=3.0 } - - { python: "3.8", env: DJANGO=master } install: - pip install tox tox-venv tox-travis pip wheel codecov -U diff --git a/docs/conf.py b/docs/conf.py index 7343849..48ce01e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,200 +12,204 @@ # serve to show the default. import datetime -import sys, os import selectable # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -#sys.path.insert(0, os.path.abspath('.')) +# sys.path.insert(0, os.path.abspath('.')) # -- General configuration ----------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.0' +# needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = [] # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The suffix of source filenames. -source_suffix = '.rst' +source_suffix = ".rst" # The encoding of source files. -#source_encoding = 'utf-8-sig' +# source_encoding = 'utf-8-sig' # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = u'Django-Selectable' -copyright = u'2011-%s, Mark Lavin' % datetime.date.today().year +project = "Django-Selectable" +copyright = "2011-%s, Mark Lavin" % datetime.date.today().year # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = '.'.join(selectable.__version__.split('.')[0:2]) +version = ".".join(selectable.__version__.split(".")[0:2]) # The full version, including alpha/beta/rc tags. release = selectable.__version__ # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. -#language = None +# language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: -#today = '' +# today = '' # Else, today_fmt is used as the format for a strftime call. -#today_fmt = '%B %d, %Y' +# today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. -exclude_patterns = ['_build'] +exclude_patterns = ["_build"] # The reST default role (used for this markup: `text`) to use for all documents. -#default_role = None +# default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. -#add_function_parentheses = True +# add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). -#add_module_names = True +# add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. -#show_authors = False +# show_authors = False # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] +# modindex_common_prefix = [] # -- Options for HTML output --------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -html_theme = 'default' +html_theme = "default" # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. -#html_theme_options = {} +# html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. -#html_theme_path = [] +# html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". -#html_title = None +# html_title = None # A shorter title for the navigation bar. Default is the same as html_title. -#html_short_title = None +# html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. -#html_logo = None +# html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. -#html_favicon = None +# html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -#html_static_path = ['_static'] +# html_static_path = ['_static'] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. -#html_last_updated_fmt = '%b %d, %Y' +# html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. -#html_use_smartypants = True +# html_use_smartypants = True # Custom sidebar templates, maps document names to template names. -#html_sidebars = {} +# html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. -#html_additional_pages = {} +# html_additional_pages = {} # If false, no module index is generated. -#html_domain_indices = True +# html_domain_indices = True # If false, no index is generated. -#html_use_index = True +# html_use_index = True # If true, the index is split into individual pages for each letter. -#html_split_index = False +# html_split_index = False # If true, links to the reST sources are added to the pages. -#html_show_sourcelink = True +# html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -#html_show_sphinx = True +# html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -#html_show_copyright = True +# html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. -#html_use_opensearch = '' +# html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). -#html_file_suffix = None +# html_file_suffix = None # Output file base name for HTML help builder. -htmlhelp_basename = 'Django-Selectabledoc' +htmlhelp_basename = "Django-Selectabledoc" # -- Options for LaTeX output -------------------------------------------------- # The paper size ('letter' or 'a4'). -#latex_paper_size = 'letter' +# latex_paper_size = 'letter' # The font size ('10pt', '11pt' or '12pt'). -#latex_font_size = '10pt' +# latex_font_size = '10pt' # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ - ('index', 'Django-Selectable.tex', u'Django-Selectable Documentation', - u'Mark Lavin', 'manual'), + ( + "index", + "Django-Selectable.tex", + "Django-Selectable Documentation", + "Mark Lavin", + "manual", + ), ] # The name of an image file (relative to this directory) to place at the top of # the title page. -#latex_logo = None +# latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. -#latex_use_parts = False +# latex_use_parts = False # If true, show page references after internal links. -#latex_show_pagerefs = False +# latex_show_pagerefs = False # If true, show URL addresses after external links. -#latex_show_urls = False +# latex_show_urls = False # Additional stuff for the LaTeX preamble. -#latex_preamble = '' +# latex_preamble = '' # Documents to append as an appendix to all manuals. -#latex_appendices = [] +# latex_appendices = [] # If false, no module index is generated. -#latex_domain_indices = True +# latex_domain_indices = True # -- Options for manual page output -------------------------------------------- @@ -213,6 +217,5 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - ('index', 'django-selectable', u'Django-Selectable Documentation', - [u'Mark Lavin'], 1) + ("index", "django-selectable", "Django-Selectable Documentation", ["Mark Lavin"], 1) ] diff --git a/example/example/wsgi.py b/example/example/wsgi.py index 4886fa6..29d2aa0 100644 --- a/example/example/wsgi.py +++ b/example/example/wsgi.py @@ -13,6 +13,7 @@ framework. """ + import os from django.core.wsgi import get_wsgi_application diff --git a/selectable/__init__.py b/selectable/__init__.py index 0320697..6ffbcc5 100644 --- a/selectable/__init__.py +++ b/selectable/__init__.py @@ -1,6 +1,5 @@ "Auto-complete selection widgets using Django and jQuery UI." - __version__ = "1.4.0" default_app_config = "selectable.apps.SelectableConfig" diff --git a/selectable/base.py b/selectable/base.py index afd2b54..ff9d6a8 100644 --- a/selectable/base.py +++ b/selectable/base.py @@ -1,4 +1,5 @@ "Base classes for lookup creation." + import operator import re from functools import reduce diff --git a/selectable/decorators.py b/selectable/decorators.py index 17e476a..8d77c94 100644 --- a/selectable/decorators.py +++ b/selectable/decorators.py @@ -1,4 +1,5 @@ "Decorators for additional lookup functionality." + from functools import wraps from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseForbidden @@ -43,7 +44,7 @@ def inner(self, request): @results_decorator def ajax_required(request): "Lookup decorator to require AJAX calls to the lookup view." - if not request.is_ajax(): + if not request.headers.get("x-requested-with") == "XMLHttpRequest": return HttpResponseBadRequest() diff --git a/selectable/forms/fields.py b/selectable/forms/fields.py index 410510c..3f324e6 100644 --- a/selectable/forms/fields.py +++ b/selectable/forms/fields.py @@ -5,7 +5,10 @@ from django.utils.translation import gettext_lazy as _ from selectable.forms.base import import_lookup_class -from selectable.forms.widgets import AutoCompleteSelectMultipleWidget, AutoCompleteSelectWidget +from selectable.forms.widgets import ( + AutoCompleteSelectMultipleWidget, + AutoCompleteSelectWidget, +) __all__ = ( "AutoCompleteSelectField", diff --git a/selectable/registry.py b/selectable/registry.py index ba190a4..a8705cb 100644 --- a/selectable/registry.py +++ b/selectable/registry.py @@ -2,7 +2,11 @@ from django.utils.module_loading import autodiscover_modules from selectable.base import LookupBase -from selectable.exceptions import LookupAlreadyRegistered, LookupInvalid, LookupNotRegistered +from selectable.exceptions import ( + LookupAlreadyRegistered, + LookupInvalid, + LookupNotRegistered, +) class LookupRegistry: diff --git a/selectable/tests/test_decorators.py b/selectable/tests/test_decorators.py index c24a4e9..5fa8120 100644 --- a/selectable/tests/test_decorators.py +++ b/selectable/tests/test_decorators.py @@ -16,15 +16,13 @@ def setUp(self): def test_ajax_call(self): "Ajax call should yield a successful response." - request = Mock() - request.is_ajax = lambda: True + request = Mock(headers={"x-requested-with": "XMLHttpRequest"}) response = self.lookup.results(request) self.assertTrue(response.status_code, 200) def test_non_ajax_call(self): "Non-Ajax call should yield a bad request response." request = Mock() - request.is_ajax = lambda: False response = self.lookup.results(request) self.assertEqual(response.status_code, 400) diff --git a/selectable/tests/test_functional.py b/selectable/tests/test_functional.py index cd7cb90..61da64d 100644 --- a/selectable/tests/test_functional.py +++ b/selectable/tests/test_functional.py @@ -1,10 +1,15 @@ """ Larger functional tests for fields and widgets. """ + from django import forms from ..forms import ( - AutoComboboxSelectWidget, AutoCompleteSelectField, AutoCompleteSelectMultipleField, AutoCompleteSelectWidget) + AutoComboboxSelectWidget, + AutoCompleteSelectField, + AutoCompleteSelectMultipleField, + AutoCompleteSelectWidget, +) from . import ManyThing, OtherThing, ThingLookup from .base import BaseSelectableTestCase @@ -369,6 +374,7 @@ def test_render_form(self): class SimpleForm(forms.Form): "Non-model form usage." + thing = AutoCompleteSelectField(lookup_class=ThingLookup) new_thing = AutoCompleteSelectField(lookup_class=ThingLookup, allow_new=True) things = AutoCompleteSelectMultipleField(lookup_class=ThingLookup) diff --git a/setup.py b/setup.py index ea4ddbe..81c6895 100755 --- a/setup.py +++ b/setup.py @@ -29,6 +29,7 @@ def read_file(filename): 'Framework :: Django', 'Framework :: Django :: 3.2', 'Framework :: Django :: 4.2', + 'Framework :: Django :: 5.1', 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', 'Programming Language :: Python', @@ -36,6 +37,8 @@ def read_file(filename): 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', + 'Programming Language :: Python :: 3.13', 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', ], long_description=read_file('README.rst'), diff --git a/tox.ini b/tox.ini index 1075a2f..fd4e0e7 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] envlist = - py{39,310,311}-dj{32,42} + py{39,310,311,312,313}-dj{32,42,51} docs [flake8] @@ -15,6 +15,7 @@ deps = coverage>=4.0 dj32: django==3.2.* dj42: django==4.2.* + dj51: django==5.1.* commands = coverage run runtests.py [testenv:docs]