mirror of
https://github.com/Hopiu/django-select2.git
synced 2026-03-17 05:50:23 +00:00
Compare commits
58 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e7fa49a6e2 | ||
|
|
39ab326884 | ||
|
|
d63f410bca | ||
|
|
5680f0daf9 | ||
|
|
8deb2b6a11 | ||
|
|
37e2515be6 | ||
|
|
cc8989a625 | ||
|
|
1ae52d7436 | ||
|
|
dca7dbc5d1 | ||
|
|
8bd7f7209f | ||
|
|
6b1ca10b06 | ||
|
|
4f96e21333 | ||
|
|
8494b10fcc | ||
|
|
ff68bf1050 | ||
|
|
c15de464d5 | ||
|
|
898b2e84dd | ||
|
|
1e4056bd62 | ||
|
|
2bb6f3a974 | ||
|
|
fa9d8baba8 | ||
|
|
df5bf9e893 | ||
|
|
4d0d702aaf | ||
|
|
0c82edf65c | ||
|
|
0021f35b2a | ||
|
|
ad42a01083 | ||
|
|
3a7ecd1666 | ||
|
|
2f17e21b0b | ||
|
|
9de7f29815 | ||
|
|
ffe91627d8 | ||
|
|
66d2051c20 | ||
|
|
48ceeaa312 | ||
|
|
9b54cc30c7 | ||
|
|
82859121a6 | ||
|
|
d34cd2e5de | ||
|
|
e4efaab6f1 | ||
|
|
1e8971c12b | ||
|
|
de7e7a1903 | ||
|
|
0f18958099 | ||
|
|
ebbdd2b9be | ||
|
|
e9d96cf856 | ||
|
|
f6eaa26c16 | ||
|
|
73d4be8992 | ||
|
|
e1d42bfcad | ||
|
|
1954bf57fa | ||
|
|
08ca1c1c36 | ||
|
|
aef27f48df | ||
|
|
f31beec0c4 | ||
|
|
496cc7c502 | ||
|
|
17af750d88 | ||
|
|
67bf060991 | ||
|
|
d9c899e8f7 | ||
|
|
e4729feb9a | ||
|
|
2ea6ef8edb | ||
|
|
a9aa31146f | ||
|
|
c2331b272a | ||
|
|
5d98048c9f | ||
|
|
7782e9bc3d | ||
|
|
426cace3a3 | ||
|
|
90fbf7422f |
43 changed files with 769 additions and 1172 deletions
2
.bandit
Normal file
2
.bandit
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
[bandit]
|
||||
exclude: tests
|
||||
20
.editorconfig
Normal file
20
.editorconfig
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# http://editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
|
||||
[*.{json,yml,yaml,js,jsx}]
|
||||
indent_size = 2
|
||||
|
||||
[LICENSE]
|
||||
insert_final_newline = false
|
||||
|
||||
[Makefile]
|
||||
indent_style = tab
|
||||
4
.fussyfox.yml
Normal file
4
.fussyfox.yml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
- bandit
|
||||
- flake8
|
||||
- isort
|
||||
- pydocstyle
|
||||
2
.github/FUNDING.yml
vendored
Normal file
2
.github/FUNDING.yml
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
github: codingjoe
|
||||
custom: https://paypal.me/codingjoe
|
||||
30
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
30
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: codingjoe
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**Exception & Traceback**
|
||||
Should you have run into an exception, please provide us with the exception as well as with the full traceback.
|
||||
|
||||
**Code Snippet**
|
||||
Please provide us with a code example on how to reproduce the error.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
13
.github/ISSUE_TEMPLATE/problem-with-django-admin.md
vendored
Normal file
13
.github/ISSUE_TEMPLATE/problem-with-django-admin.md
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
name: Problem with Django admin
|
||||
about: You are facing a problem integrating django-select2 into Django's admin interface
|
||||
title: ''
|
||||
labels: wontfix
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
Django-Select2 does NOT support Django admin, since Django admin has a built-in feature called `autocomplete_fields`. Autocomplete fields are superior and we recommend using them, instead of this package for the admin.
|
||||
|
||||
You can find more information here:
|
||||
https://docs.djangoproject.com/en/stable/ref/contrib/admin/#django.contrib.admin.ModelAdmin.autocomplete_fields
|
||||
17
.github/ISSUE_TEMPLATE/question.md
vendored
Normal file
17
.github/ISSUE_TEMPLATE/question.md
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
name: Question
|
||||
about: You have a question about Django-Select2
|
||||
title: ''
|
||||
labels: question
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Goal**
|
||||
Please describe your goal in all detail. What are you trying to do
|
||||
|
||||
**Problem**
|
||||
Please describe your problem in all detail. Where are you struggling?
|
||||
|
||||
**Code Snippet**
|
||||
Please provide a code snippet of your problem.
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -20,3 +20,6 @@ venv/
|
|||
geckodriver.log
|
||||
ghostdriver.log
|
||||
.coverage
|
||||
|
||||
coverage.xml
|
||||
.eggs/
|
||||
|
|
|
|||
127
.travis.yml
127
.travis.yml
|
|
@ -1,58 +1,87 @@
|
|||
language: python
|
||||
sudo: false
|
||||
dist: trusty
|
||||
cache:
|
||||
- apt
|
||||
- pip
|
||||
services:
|
||||
- redis
|
||||
addons:
|
||||
chrome: stable
|
||||
apt:
|
||||
packages:
|
||||
- python3-enchant
|
||||
- python-enchant
|
||||
- graphviz
|
||||
dist: xenial
|
||||
|
||||
python:
|
||||
- "3.6"
|
||||
- "3.7"
|
||||
- "3.8"
|
||||
env:
|
||||
matrix:
|
||||
- DJANGO=111
|
||||
- DJANGO=20
|
||||
- DJANGO=22
|
||||
- DJANGO=30
|
||||
- DJANGO=master
|
||||
- TOXENV=qa
|
||||
- TOXENV=docs
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
allow_failures:
|
||||
- env: DJANGO=master
|
||||
install:
|
||||
- pip install --upgrade pip tox
|
||||
- pip install -U codecov
|
||||
- env: DJANGO=master
|
||||
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- chromium-chromedriver
|
||||
|
||||
install: pip install tox-travis codecov
|
||||
|
||||
before_script:
|
||||
- mkdir bin
|
||||
- export CHROME_DRIVER_VERSION=`curl https://chromedriver.storage.googleapis.com/LATEST_RELEASE`
|
||||
- curl -O https://chromedriver.storage.googleapis.com/${CHROME_DRIVER_VERSION}/chromedriver_linux64.zip
|
||||
- unzip chromedriver_linux64.zip -d bin
|
||||
- PATH=$PATH:$PWD/bin
|
||||
- nvm install --lts
|
||||
- npm install -g standard
|
||||
- |
|
||||
if [[ -z $TOXENV ]]; then
|
||||
export TOXENV=py$(echo $TRAVIS_PYTHON_VERSION | sed -e 's/\.//g')-dj$DJANGO
|
||||
fi
|
||||
- echo $TOXENV
|
||||
script:
|
||||
- tox -e $TOXENV
|
||||
- standard
|
||||
after_success:
|
||||
- codecov
|
||||
deploy:
|
||||
provider: pypi
|
||||
user: codingjoe
|
||||
password:
|
||||
secure: fEP9K7y0ZF9fRvQEUN4kgPXQEZvi3Cx3ikUebG2UM/2uhcaUQm0+KpgZ2S+lvOTYcBnNgzPzFsVIZMcVcTxwIKuQDEMq9y2eop2hnisb9KXsIm9qPYSzOnRm74VuiOt4hNOZMe0qVBK2cO3vC9NDXuzdI8A0JynJhthfl4t+kFM=
|
||||
on:
|
||||
tags: true
|
||||
distributions: sdist bdist_wheel
|
||||
repo: applegrew/django-select2
|
||||
- ln -s /usr/lib/chromium-browser/chromedriver ~/bin/chromedriver
|
||||
- |
|
||||
if [[ -z $TOXENV ]]; then
|
||||
export TOXENV=py$(echo $TRAVIS_PYTHON_VERSION | sed -e 's/\.//g')-dj$DJANGO
|
||||
fi
|
||||
- echo $TOXENV
|
||||
|
||||
script: tox
|
||||
|
||||
after_success: codecov
|
||||
|
||||
stages:
|
||||
- test
|
||||
- name: deploy
|
||||
if: tag is present
|
||||
|
||||
jobs:
|
||||
include:
|
||||
- python: "3.7"
|
||||
env: TOXENV=docs
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- python3-enchant
|
||||
- python-enchant
|
||||
- graphviz
|
||||
- language: node_js
|
||||
addons: {}
|
||||
install: npm install
|
||||
script: npm test
|
||||
node_js: lts/*
|
||||
cache: npm
|
||||
- stage: deploy
|
||||
python: "3.8"
|
||||
install: skip
|
||||
script: skip
|
||||
after_success: true
|
||||
deploy:
|
||||
provider: pypi
|
||||
distributions: sdist bdist_wheel
|
||||
on:
|
||||
tags: true
|
||||
user: codingjoe
|
||||
password:
|
||||
secure: fEP9K7y0ZF9fRvQEUN4kgPXQEZvi3Cx3ikUebG2UM/2uhcaUQm0+KpgZ2S+lvOTYcBnNgzPzFsVIZMcVcTxwIKuQDEMq9y2eop2hnisb9KXsIm9qPYSzOnRm74VuiOt4hNOZMe0qVBK2cO3vC9NDXuzdI8A0JynJhthfl4t+kFM=
|
||||
- stage: deploy
|
||||
language: node_js
|
||||
node_js: lts/*
|
||||
python: "3.8"
|
||||
install: skip
|
||||
script: skip
|
||||
after_success: true
|
||||
skip_cleanup: true
|
||||
before_deploy:
|
||||
- ./set_version.py
|
||||
deploy:
|
||||
provider: npm
|
||||
on:
|
||||
tags: true
|
||||
email: info@johanneshoppe.com
|
||||
api_key:
|
||||
secure: PV38cQx9qhEFkpSdytbM72UzIMCfhpjmRJ8dzT+bCAaOIs5rEcyKN+h1r5ranunCxWyuFsMW4A2iW/SCxnKCR/oPAguuwUbT5ogBXlsskqPFWUxuoTHYMrd+zB+SC6+bMgq+o5ul+kJCYtEkWP6cMlIEzKyTLab7m5PsnDXNVnI=
|
||||
|
|
|
|||
216
CHANGELOG.md
216
CHANGELOG.md
|
|
@ -1,216 +0,0 @@
|
|||
Changelog Summary
|
||||
=================
|
||||
|
||||
### v6.0.0
|
||||
|
||||
* Add Support for Django 2.0
|
||||
* Drop Python 2 support
|
||||
* Drop Python 3.5 support
|
||||
* Drop Django 1.8 support
|
||||
* Drop Django 1.10 support
|
||||
|
||||
### v5.10.0
|
||||
* Add support for dependent select fields [321](github.com/applegrew/django-select2/pull/321/).
|
||||
|
||||
### v5.9.0
|
||||
* Add support for Django 1.11 LTS
|
||||
* Drop support for Django 1.9
|
||||
|
||||
### v5.8.10
|
||||
* Fixes tests for Django 1.10+
|
||||
* retain order of choices [299](https://github.com/applegrew/django-select2/pull/299)
|
||||
|
||||
### v5.8.9
|
||||
* Fixes tests. No functional change from 5.8.8.
|
||||
|
||||
### v5.8.8
|
||||
* Upgrade Select2 to version 4.0.3
|
||||
|
||||
### v5.8.7
|
||||
* Fix #285 -- Do not evaluate queryset in `render_options`.
|
||||
|
||||
### v5.8.3
|
||||
* Remove six dependency -- User django.utils.six instead.
|
||||
|
||||
### v5.8.2
|
||||
* Fixes #260 -- Fixes bug in render choices
|
||||
|
||||
### v5.8.0
|
||||
* Changed signature of `render` and `render_choices` to satisfy Django 1.10 changes.
|
||||
* Changed widgets' inheritance tree to be more consistent.
|
||||
|
||||
### v5.7.1
|
||||
* Fixes pickle bug of lazy object
|
||||
|
||||
### v5.7.0
|
||||
* Security fix that allows a `field_id` to only be used for the intended JSON endpoint.
|
||||
|
||||
Prior to that change you could use any `field_id` on any select2 JSON endpoint.
|
||||
Even if the id was intended to be used on a private endpoint if could be used on
|
||||
the default one and therefore leak sensitive data.
|
||||
|
||||
* Breaking change on how `Heavy` widgets are being cached.
|
||||
|
||||
Heavy widgets used to add themselves to the cache. Now they add a dictionary to
|
||||
the cache containing themselves and the target url.
|
||||
|
||||
```python
|
||||
{
|
||||
'widget': self,
|
||||
'url': self.get_url(),
|
||||
}
|
||||
```
|
||||
|
||||
### v5.6.0
|
||||
* Added `label_from_instance` method for model widgets to define custom option labels.
|
||||
|
||||
### v5.5.0
|
||||
* Added settings to delivery static assets from different source.
|
||||
|
||||
### v5.4.2
|
||||
* Fixed initial data not being shown for heavy widgets.
|
||||
|
||||
### v5.4.1
|
||||
* Fixed memory leak in `ModelSelect2Mixin` and subclasses
|
||||
|
||||
### v5.4.0
|
||||
* Added `Select2TagWidget` a light widget with tagging support
|
||||
|
||||
### v5.3.0
|
||||
* Added djangoSelect2 jQuery plugin to support
|
||||
dynamic field initialisation
|
||||
|
||||
### v5.2.0
|
||||
* Added pagination
|
||||
|
||||
### v5.1.0
|
||||
* Added search term splitting
|
||||
* Model widgets get smarter pickling to reduce size and avoid pickling issues
|
||||
|
||||
### v5.0.0
|
||||
Version 5 is a complete rewrite of the package to drastically reduce
|
||||
the code base and to ensure a future maintainability.
|
||||
|
||||
While we feature set remained unchanged, the API changed completely.
|
||||
Major changes:
|
||||
* Fields have been removed in favor of widgets.
|
||||
* All version 4 settings have been removed.
|
||||
* Template tags have been removed.
|
||||
* 3rd party javascript is served by a CDN.
|
||||
* No more inline javascript code.
|
||||
|
||||
### v4.3.2
|
||||
|
||||
* Use `django.contrib.staticfiles.templatetags.staticfiles.static` over `django.templatetags.static.static` to allow hashing.
|
||||
* Py23 unicode fixes
|
||||
|
||||
|
||||
### v4.3.1
|
||||
|
||||
* Build failure fix.
|
||||
|
||||
### v4.3.0
|
||||
|
||||
* Now the package supports both Python2 and Python3.
|
||||
* Django 1.8 support added.
|
||||
* Many bug fixes.
|
||||
|
||||
### v4.2.2
|
||||
|
||||
* Misc fixes and enhancements - [61](https://github.com/applegrew/django-select2/pull/61), [64](https://github.com/applegrew/django-select2/issues/64).
|
||||
|
||||
### v4.2.1
|
||||
|
||||
* Finally fixed performance issue[#54](https://github.com/applegrew/django-select2/issues/54) (and issue[#41](https://github.com/applegrew/django-select2/issues/41)) in widgets when backing field is based on models and the field has an initial value.
|
||||
|
||||
### v4.2.0
|
||||
|
||||
* Updated Select2 to version 3.4.2. **Please note**, that if you need any of the Select2 locale files, then you need to download them yourself from http://ivaynberg.github.com/select2/ and add to your project.
|
||||
* Tagging support added. See [Field API reference](http://django-select2.readthedocs.org/en/latest/ref_fields.html) in documentation.
|
||||
|
||||
### v4.1.0
|
||||
|
||||
* Updated Select2 to version 3.4.1. **Please note**, that if you need any of the Select2 locale files, then you need to download them yourself from http://ivaynberg.github.com/select2/ and add to your project.
|
||||
* Address isssue[#36](https://github.com/applegrew/django-select2/issues/36) - Fix importerror under django1.6.
|
||||
* Fixed the way `setup.py` handles Unicode files while minifying them during package build.
|
||||
* Address isssue[#39](https://github.com/applegrew/django-select2/issues/39) - MultipleSelect2HiddenInput.render() should use mark_safe().
|
||||
* Address isssue[#45](https://github.com/applegrew/django-select2/issues/45) - MultipleSelect2HiddenInput returns bad has_changed value.
|
||||
|
||||
### v4.0.0
|
||||
|
||||
* Main version number bumped to bring your attention to the fact that the default Id generation scheme has now changed. Now Django Select2 will use hashed paths of fields to generate their Ids. The old scheme of generating random Ids are still there. You can enable that by setting `GENERATE_RANDOM_SELECT2_ID` to `True`.
|
||||
|
||||
### v3.3.1
|
||||
|
||||
* Addressed issue[#30](https://github.com/applegrew/django-select2/issues/30).
|
||||
* Merged pull request[#31](https://github.com/applegrew/django-select2/issues/31).
|
||||
* Added `light` parameter to `import_django_select2_js`, `import_django_select2_css` and `import_django_select2_js_css` template tags. Please see doc's "Getting Started", for more details.
|
||||
|
||||
### v3.3.0
|
||||
|
||||
* Updated Select2 to version 3.3.1.
|
||||
* Added multi-process support. ([Issue#28](https://github.com/applegrew/django-select2/issues/28)).
|
||||
* Addressed issue[#26](https://github.com/applegrew/django-select2/issues/26).
|
||||
* Addressed issue[#24](https://github.com/applegrew/django-select2/issues/24).
|
||||
* Addressed issue[#23](https://github.com/applegrew/django-select2/issues/23).
|
||||
* Addressed some typos.
|
||||
|
||||
### v3.2.0
|
||||
|
||||
* Fixed issue[#20](https://github.com/applegrew/django-select2/issues/20). Infact while fixing that I realised that heavy components do not need the help of cookies, infact due to a logic error in previous code the cookies were not being used anyway. Now Django Select2 does not use cookies etc.
|
||||
* Few more bugs fixed in `heav_data.js`.
|
||||
* Now production code will use minimized versions of js and css files.
|
||||
* Codes added in `setup.py` to automate the task of minimizing js and css files, using a web service.
|
||||
|
||||
### v3.1.5
|
||||
|
||||
* Merged pull request (issue[#17](https://github.com/applegrew/django-select2/issues/17)). Which allows the user to pass some extra data to Select2 clients-side component.
|
||||
* Updated License. The previous one was inadequently worded. Now this project use Apache 2.0 license.
|
||||
|
||||
### v3.1.4
|
||||
|
||||
* Manually merged changes from pull request (issue[#16](https://github.com/applegrew/django-select2/issues/16)).
|
||||
* Django Select2 widgets now allow passing of any Select2 Js options. Previously it used to allow only white-listed options. Now it will block only black-listed options. For example, Light Select2 widgets won't allow you to set `multiple` option, since it is an error to set them when Select2 Js is bound to `<select>` fields.
|
||||
|
||||
### v3.1.3
|
||||
|
||||
* Addressed enhancement issue[#12](https://github.com/applegrew/django-select2/issues/12).
|
||||
* Addressed enhancement issue[#11](https://github.com/applegrew/django-select2/issues/11).
|
||||
* Addressed performance issue[#8](https://github.com/applegrew/django-select2/issues/8).
|
||||
|
||||
### v3.1.2
|
||||
|
||||
* Fixed issue[#7](https://github.com/applegrew/django-select2/issues/7).
|
||||
|
||||
### v3.1.1
|
||||
|
||||
* Bumping up minor version since Select2 JS has been updated to version 3.2. It seems Select2 JS now includes new higher resolution icons for [Retina displays](http://en.wikipedia.org/wiki/Retina_Display).
|
||||
* Fixed an issue in `setup.py` because of which `templatetags` directory was not included in last PIP releases' tar file.
|
||||
|
||||
### v3.0.2
|
||||
|
||||
* Added `AUTO_RENDER_SELECT2_STATICS` settings. This, when specified and set to `False` in `settings.py` then Django_Select2 widgets won't automatically include the required scripts and stylesheets. When this setting is `True` (default) then every Select2 field on the page will output `<script>` and `<link>` tags to include the required JS and CSS files. This is convinient but will output the same JS and CSS files multiple times if there are more than one Select2 fields on the page.
|
||||
* Added `django_select2_tags` template tags to manually include the required JS and CSS files, when `AUTO_RENDER_SELECT2_STATICS` is turned off.
|
||||
|
||||
### v3.0.1
|
||||
|
||||
* Revised the design of heavy fields. The previous design didn't quite make it easy to back heavy fields by big data sources. See `fields.HeavyChoiceField` class and its methods' docs for more info.
|
||||
* Updated docs.
|
||||
* Some more fixes for issue[#4](https://github.com/applegrew/django-select2/issues/4).
|
||||
* Updated Select2 JS to version 3.1.
|
||||
|
||||
### v3.0
|
||||
|
||||
* Added docs.
|
||||
* Some bug fixes. See issue[#4](https://github.com/applegrew/django-select2/issues/4).
|
||||
* `widgets.Select2Mixin.__init__` now accepts `select2_options` kwarg to override its `options` settings. Previously `attrs` were being used for this too. This means backward compatibility has been broken here. `attrs` will no longer override `options` values. **The major release version has been changed to 3, because of this backward incompatible change.**
|
||||
|
||||
### v2.0.1
|
||||
|
||||
* Auto id registration fixes.
|
||||
|
||||
### v2.0
|
||||
|
||||
* Mostly major bug fixes in code and design. The changes were many, raising the possibility of backward incompatibility. However, the backward incompatibility would be subtle.
|
||||
|
||||
* Auto fields (sub-classes of AutoViewFieldMixin) now accepts `auto_id` parameter. This can be used to provide custom id for the field. The default is 'module.field_class_name'. Ideally only the first instance of an auto field is registered. This parameter can be used to force registration of additional instances by passing a unique value.
|
||||
22
CONTRIBUTING.rst
Normal file
22
CONTRIBUTING.rst
Normal file
|
|
@ -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.
|
||||
28
LICENSE
28
LICENSE
|
|
@ -1,13 +1,21 @@
|
|||
Copyright 2017 Johannes Hoppe
|
||||
MIT License
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
Copyright (c) 2017 Johannes Hoppe
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
|
|
|||
6
MANIFEST.in
Normal file
6
MANIFEST.in
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
include django_select2/static/django_select2/django_select2.js
|
||||
prune tests
|
||||
prune .github
|
||||
exclude .fussyfox.yml
|
||||
exclude .travis.yml
|
||||
exclude .gitignore
|
||||
10
README.rst
10
README.rst
|
|
@ -7,6 +7,10 @@ This is a `Django`_ integration of `Select2`_.
|
|||
|
||||
The app includes Select2 driven Django Widgets.
|
||||
|
||||
.. note::
|
||||
Django's admin comes with builtin support for Select2
|
||||
since version 2.0 via the `autocomplete_fields`_ feature.
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
|
|
@ -19,7 +23,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 ‘Auto’ fields.
|
||||
3. Add ``django_select`` to your urlconf if you use any "Auto" fields.
|
||||
|
||||
.. code:: python
|
||||
|
||||
|
|
@ -46,12 +50,14 @@ good example.
|
|||
Changelog
|
||||
---------
|
||||
|
||||
See `CHANGELOG.md`_
|
||||
See `Github releases`_
|
||||
|
||||
|
||||
.. _Django: https://www.djangoproject.com/
|
||||
.. _Select2: http://ivaynberg.github.com/select2/
|
||||
.. _autocomplete_fields: https://docs.djangoproject.com/en/stable/ref/contrib/admin/#django.contrib.admin.ModelAdmin.autocomplete_fields
|
||||
.. _CHANGELOG.md: CHANGELOG.md
|
||||
.. _Github releases: https://github.com/applegrew/django-select2/releases
|
||||
|
||||
.. |version| image:: https://img.shields.io/pypi/v/Django-Select2.svg
|
||||
:target: https://pypi.python.org/pypi/Django-Select2/
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@ __all__ = ('settings', 'Select2Conf')
|
|||
class Select2Conf(AppConf):
|
||||
"""Settings for Django-Select2."""
|
||||
|
||||
LIB_VERSION = '4.0.12'
|
||||
"""Version of the Select2 library."""
|
||||
|
||||
CACHE_BACKEND = 'default'
|
||||
"""
|
||||
Django-Select2 uses Django's cache to sure a consistent state across multiple machines.
|
||||
|
|
@ -23,8 +26,11 @@ class Select2Conf(AppConf):
|
|||
}
|
||||
},
|
||||
'select2': {
|
||||
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
|
||||
'LOCATION': '127.0.0.1:11211',
|
||||
"BACKEND": "django_redis.cache.RedisCache",
|
||||
"LOCATION": "redis://127.0.0.1:6379/2",
|
||||
"OPTIONS": {
|
||||
"CLIENT_CLASS": "django_redis.client.DefaultClient",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -34,6 +40,11 @@ class Select2Conf(AppConf):
|
|||
.. tip:: To ensure a consistent state across all you machines you need to user
|
||||
a consistent external cache backend like Memcached, Redis or a database.
|
||||
|
||||
.. note::
|
||||
Should you have copied the example configuration please make sure you
|
||||
have Redis setup. It's recommended to run a separate Redis server in a
|
||||
production environment.
|
||||
|
||||
.. note:: The timeout of select2's caching backend determines
|
||||
how long a browser session can last.
|
||||
Once widget is dropped from the cache the json response view will return a 404.
|
||||
|
|
@ -45,7 +56,7 @@ class Select2Conf(AppConf):
|
|||
It has set `select2_` as a default value, which you can change if needed.
|
||||
"""
|
||||
|
||||
JS = '//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js'
|
||||
JS = '//cdnjs.cloudflare.com/ajax/libs/select2/{version}/js/select2.min.js'.format(version=LIB_VERSION)
|
||||
"""
|
||||
The URI for the Select2 JS file. By default this points to the Cloudflare CDN.
|
||||
|
||||
|
|
@ -54,11 +65,16 @@ class Select2Conf(AppConf):
|
|||
|
||||
SELECT2_JS = 'assets/js/select2.min.js'
|
||||
|
||||
If you provide your own JS and would not like Django-Select2 to load any, change
|
||||
this setting to a blank string like so::
|
||||
|
||||
SELECT2_JS = ''
|
||||
|
||||
.. tip:: Change this setting to a local asset in your development environment to
|
||||
develop without an Internet connection.
|
||||
"""
|
||||
|
||||
CSS = '//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css'
|
||||
CSS = '//cdnjs.cloudflare.com/ajax/libs/select2/{version}/css/select2.min.css'.format(version=LIB_VERSION)
|
||||
"""
|
||||
The URI for the Select2 CSS file. By default this points to the Cloudflare CDN.
|
||||
|
||||
|
|
@ -67,11 +83,16 @@ class Select2Conf(AppConf):
|
|||
|
||||
SELECT2_CSS = 'assets/css/select2.css'
|
||||
|
||||
If you provide your own CSS and would not like Django-Select2 to load any, change
|
||||
this setting to a blank string like so::
|
||||
|
||||
SELECT2_CSS = ''
|
||||
|
||||
.. tip:: Change this setting to a local asset in your development environment to
|
||||
develop without an Internet connection.
|
||||
"""
|
||||
|
||||
I18N_PATH = '//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/i18n'
|
||||
I18N_PATH = '//cdnjs.cloudflare.com/ajax/libs/select2/{version}/js/i18n'.format(version=LIB_VERSION)
|
||||
"""
|
||||
The base URI for the Select2 i18n files. By default this points to the Cloudflare CDN.
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -47,9 +48,10 @@ Light widgets are normally named, i.e. there is no
|
|||
"""
|
||||
from functools import reduce
|
||||
from itertools import chain
|
||||
from pickle import PicklingError
|
||||
from pickle import PicklingError # nosec
|
||||
|
||||
from django import forms
|
||||
from django.contrib.admin.widgets import SELECT2_TRANSLATIONS
|
||||
from django.core import signing
|
||||
from django.db.models import Q
|
||||
from django.forms.models import ModelChoiceIterator
|
||||
|
|
@ -60,7 +62,7 @@ from .cache import cache
|
|||
from .conf import settings
|
||||
|
||||
|
||||
class Select2Mixin(object):
|
||||
class Select2Mixin:
|
||||
"""
|
||||
The base mixin of all Select2 widgets.
|
||||
|
||||
|
|
@ -69,16 +71,20 @@ class Select2Mixin(object):
|
|||
form media.
|
||||
"""
|
||||
|
||||
def build_attrs(self, *args, **kwargs):
|
||||
"""Add select2 data attributes."""
|
||||
attrs = super(Select2Mixin, self).build_attrs(*args, **kwargs)
|
||||
if self.is_required:
|
||||
attrs.setdefault('data-allow-clear', 'false')
|
||||
else:
|
||||
attrs.setdefault('data-allow-clear', 'true')
|
||||
attrs.setdefault('data-placeholder', '')
|
||||
empty_label = ''
|
||||
|
||||
def build_attrs(self, base_attrs, extra_attrs=None):
|
||||
"""Add select2 data attributes."""
|
||||
default_attrs = {'data-minimum-input-length': 0}
|
||||
if self.is_required:
|
||||
default_attrs['data-allow-clear'] = 'false'
|
||||
else:
|
||||
default_attrs['data-allow-clear'] = 'true'
|
||||
default_attrs['data-placeholder'] = self.empty_label or ""
|
||||
|
||||
default_attrs.update(base_attrs)
|
||||
attrs = super().build_attrs(default_attrs, extra_attrs=extra_attrs)
|
||||
|
||||
attrs.setdefault('data-minimum-input-length', 0)
|
||||
if 'class' in attrs:
|
||||
attrs['class'] += ' django-select2'
|
||||
else:
|
||||
|
|
@ -96,31 +102,38 @@ class Select2Mixin(object):
|
|||
Construct Media as a dynamic property.
|
||||
|
||||
.. Note:: For more information visit
|
||||
https://docs.djangoproject.com/en/1.8/topics/forms/media/#media-as-a-dynamic-property
|
||||
https://docs.djangoproject.com/en/stable/topics/forms/media/#media-as-a-dynamic-property
|
||||
"""
|
||||
try:
|
||||
# get_language() will always return a lower case language code, where some files are named upper case.
|
||||
i = [x.lower() for x in settings.SELECT2_I18N_AVAILABLE_LANGUAGES].index(get_language())
|
||||
i18n_file = ('%s/%s.js' % (settings.SELECT2_I18N_PATH, settings.SELECT2_I18N_AVAILABLE_LANGUAGES[i]), )
|
||||
except ValueError:
|
||||
i18n_file = ()
|
||||
lang = get_language()
|
||||
select2_js = (settings.SELECT2_JS,) if settings.SELECT2_JS else ()
|
||||
select2_css = (settings.SELECT2_CSS,) if settings.SELECT2_CSS else ()
|
||||
|
||||
i18n_name = SELECT2_TRANSLATIONS.get(lang)
|
||||
if i18n_name not in settings.SELECT2_I18N_AVAILABLE_LANGUAGES:
|
||||
i18n_name = None
|
||||
|
||||
i18n_file = ('%s/%s.js' % (settings.SELECT2_I18N_PATH, i18n_name),) if i18n_name else ()
|
||||
|
||||
return forms.Media(
|
||||
js=(settings.SELECT2_JS,) + i18n_file + ('django_select2/django_select2.js',),
|
||||
css={'screen': (settings.SELECT2_CSS,)}
|
||||
js=select2_js + i18n_file + ('django_select2/django_select2.js',),
|
||||
css={'screen': select2_css}
|
||||
)
|
||||
|
||||
media = property(_get_media)
|
||||
|
||||
|
||||
class Select2TagMixin(object):
|
||||
class Select2TagMixin:
|
||||
"""Mixin to add select2 tag functionality."""
|
||||
|
||||
def build_attrs(self, *args, **kwargs):
|
||||
def build_attrs(self, base_attrs, extra_attrs=None):
|
||||
"""Add select2's tag attributes."""
|
||||
self.attrs.setdefault('data-minimum-input-length', 1)
|
||||
self.attrs.setdefault('data-tags', 'true')
|
||||
self.attrs.setdefault('data-token-separators', '[",", " "]')
|
||||
return super(Select2TagMixin, self).build_attrs(*args, **kwargs)
|
||||
default_attrs = {
|
||||
'data-minimum-input-length': 1,
|
||||
'data-tags': 'true',
|
||||
'data-token-separators': '[",", " "]'
|
||||
}
|
||||
default_attrs.update(base_attrs)
|
||||
return super().build_attrs(default_attrs, extra_attrs=extra_attrs)
|
||||
|
||||
|
||||
class Select2Widget(Select2Mixin, forms.Select):
|
||||
|
|
@ -180,7 +193,7 @@ class Select2TagWidget(Select2TagMixin, Select2Mixin, forms.SelectMultiple):
|
|||
pass
|
||||
|
||||
|
||||
class HeavySelect2Mixin(object):
|
||||
class HeavySelect2Mixin:
|
||||
"""Mixin that adds select2's AJAX options and registers itself on Django's cache."""
|
||||
|
||||
dependent_fields = {}
|
||||
|
|
@ -198,6 +211,7 @@ class HeavySelect2Mixin(object):
|
|||
widget could be dependent on a country.
|
||||
Key is a name of a field in a form.
|
||||
Value is a name of a field in a model (used in `queryset`).
|
||||
|
||||
"""
|
||||
self.choices = choices
|
||||
if attrs is not None:
|
||||
|
|
@ -221,20 +235,26 @@ class HeavySelect2Mixin(object):
|
|||
return self.data_url
|
||||
return reverse(self.data_view)
|
||||
|
||||
def build_attrs(self, *args, **kwargs):
|
||||
def build_attrs(self, base_attrs, extra_attrs=None):
|
||||
"""Set select2's AJAX attributes."""
|
||||
attrs = super(HeavySelect2Mixin, self).build_attrs(*args, **kwargs)
|
||||
default_attrs = {
|
||||
'data-ajax--url': self.get_url(),
|
||||
'data-ajax--cache': "true",
|
||||
'data-ajax--type': "GET",
|
||||
'data-minimum-input-length': 2,
|
||||
}
|
||||
|
||||
if self.dependent_fields:
|
||||
default_attrs['data-select2-dependent-fields'] = " ".join(self.dependent_fields)
|
||||
|
||||
default_attrs.update(base_attrs)
|
||||
|
||||
attrs = super().build_attrs(default_attrs, extra_attrs=extra_attrs)
|
||||
|
||||
# encrypt instance Id
|
||||
self.widget_id = signing.dumps(id(self))
|
||||
|
||||
attrs['data-field_id'] = self.widget_id
|
||||
attrs.setdefault('data-ajax--url', self.get_url())
|
||||
attrs.setdefault('data-ajax--cache', "true")
|
||||
attrs.setdefault('data-ajax--type', "GET")
|
||||
attrs.setdefault('data-minimum-input-length', 2)
|
||||
if self.dependent_fields:
|
||||
attrs.setdefault('data-select2-dependent-fields', " ".join(self.dependent_fields))
|
||||
|
||||
attrs['class'] += ' django-select2-heavy'
|
||||
return attrs
|
||||
|
|
@ -277,7 +297,7 @@ class HeavySelect2Widget(HeavySelect2Mixin, Select2Widget):
|
|||
or::
|
||||
|
||||
class MyForm(forms.Form):
|
||||
my_field = forms.ChoicesField(
|
||||
my_field = forms.ChoiceField(
|
||||
widget=HeavySelect2Widget(
|
||||
data_url='/url/to/json/response'
|
||||
)
|
||||
|
|
@ -303,7 +323,7 @@ class HeavySelect2TagWidget(HeavySelect2Mixin, Select2TagWidget):
|
|||
# Auto Heavy widgets
|
||||
|
||||
|
||||
class ModelSelect2Mixin(object):
|
||||
class ModelSelect2Mixin:
|
||||
"""Widget mixin that provides attributes and methods for :class:`.AutoResponseView`."""
|
||||
|
||||
model = None
|
||||
|
|
@ -323,6 +343,12 @@ class ModelSelect2Mixin(object):
|
|||
max_results = 25
|
||||
"""Maximal results returned by :class:`.AutoResponseView`."""
|
||||
|
||||
@property
|
||||
def empty_label(self):
|
||||
if isinstance(self.choices, ModelChoiceIterator):
|
||||
return self.choices.field.empty_label
|
||||
return ''
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""
|
||||
Overwrite class parameters if passed as keyword arguments.
|
||||
|
|
@ -338,7 +364,7 @@ class ModelSelect2Mixin(object):
|
|||
self.queryset = kwargs.pop('queryset', self.queryset)
|
||||
self.search_fields = kwargs.pop('search_fields', self.search_fields)
|
||||
self.max_results = kwargs.pop('max_results', self.max_results)
|
||||
defaults = {'data_view': 'django_select2-json'}
|
||||
defaults = {'data_view': 'django_select2:auto-json'}
|
||||
defaults.update(kwargs)
|
||||
super(ModelSelect2Mixin, self).__init__(*args, **defaults)
|
||||
|
||||
|
|
@ -356,22 +382,24 @@ class ModelSelect2Mixin(object):
|
|||
queryset.query,
|
||||
],
|
||||
'cls': self.__class__,
|
||||
'search_fields': self.search_fields,
|
||||
'max_results': self.max_results,
|
||||
'url': self.get_url(),
|
||||
'dependent_fields': self.dependent_fields,
|
||||
'search_fields': tuple(self.search_fields),
|
||||
'max_results': int(self.max_results),
|
||||
'url': str(self.get_url()),
|
||||
'dependent_fields': dict(self.dependent_fields),
|
||||
})
|
||||
|
||||
def filter_queryset(self, term, queryset=None, **dependent_fields):
|
||||
def filter_queryset(self, request, term, queryset=None, **dependent_fields):
|
||||
"""
|
||||
Return QuerySet filtered by search_fields matching the passed term.
|
||||
|
||||
Args:
|
||||
request (django.http.request.HttpRequest): The request is being passed from
|
||||
the JSON view and can be used to dynamically alter the response queryset.
|
||||
term (str): Search term
|
||||
queryset (django.db.models.query.QuerySet): QuerySet to select choices from.
|
||||
**dependent_fields: Dependent fields and their values. If you want to inherit
|
||||
from ModelSelect2Mixin and later call to this method, be sure to pop
|
||||
from kwargs everything if it is not a dependent field.
|
||||
from ModelSelect2Mixin and later call to this method, be sure to pop
|
||||
everything from keyword arguments that is not a dependent field.
|
||||
|
||||
Returns:
|
||||
QuerySet: Filtered QuerySet
|
||||
|
|
@ -384,7 +412,7 @@ class ModelSelect2Mixin(object):
|
|||
term = term.replace('\t', ' ')
|
||||
term = term.replace('\n', ' ')
|
||||
for t in [t for t in term.split(' ') if not t == '']:
|
||||
select &= reduce(lambda x, y: x | Q(**{y: t}), search_fields,
|
||||
select &= reduce(lambda x, y: x | Q(**{y: t}), search_fields[1:],
|
||||
Q(**{search_fields[0]: t}))
|
||||
if dependent_fields:
|
||||
select &= Q(**dependent_fields)
|
||||
|
|
@ -401,6 +429,8 @@ class ModelSelect2Mixin(object):
|
|||
"""
|
||||
if self.queryset is not None:
|
||||
queryset = self.queryset
|
||||
elif hasattr(self.choices, 'queryset'):
|
||||
queryset = self.choices.queryset
|
||||
elif self.model is not None:
|
||||
queryset = self.model._default_manager.all()
|
||||
else:
|
||||
|
|
@ -433,11 +463,12 @@ class ModelSelect2Mixin(object):
|
|||
c for c in selected_choices
|
||||
if c not in self.choices.field.empty_values
|
||||
}
|
||||
choices = (
|
||||
(obj.pk, self.label_from_instance(obj))
|
||||
for obj in self.choices.queryset.filter(pk__in=selected_choices)
|
||||
)
|
||||
for option_value, option_label in choices:
|
||||
field_name = self.choices.field.to_field_name or 'pk'
|
||||
query = Q(**{'%s__in' % field_name: selected_choices})
|
||||
for obj in self.choices.queryset.filter(query):
|
||||
option_value = self.choices.choice(obj)[0]
|
||||
option_label = self.label_from_instance(obj)
|
||||
|
||||
selected = (
|
||||
str(option_value) in value and
|
||||
(has_selected is False or self.allow_multiple_selected)
|
||||
|
|
@ -533,14 +564,15 @@ class ModelSelect2TagWidget(ModelSelect2Mixin, HeavySelect2TagWidget):
|
|||
queryset = MyModel.objects.all()
|
||||
|
||||
def value_from_datadict(self, data, files, name):
|
||||
values = super().value_from_datadict(self, data, files, name)
|
||||
qs = self.queryset.filter(**{'pk__in': list(values)})
|
||||
pks = set(str(getattr(o, pk)) for o in qs)
|
||||
cleaned_values = []
|
||||
for val in value:
|
||||
if str(val) not in pks:
|
||||
val = queryset.create(title=val).pk
|
||||
cleaned_values.append(val)
|
||||
'''Create objects for given non-pimary-key values. Return list of all primary keys.'''
|
||||
values = set(super().value_from_datadict(data, files, name))
|
||||
# This may only work for MyModel, if MyModel has title field.
|
||||
# You need to implement this method yourself, to ensure proper object creation.
|
||||
pks = self.queryset.filter(**{'pk__in': list(values)}).values_list('pk', flat=True)
|
||||
pks = set(map(str, pks))
|
||||
cleaned_values = list(values)
|
||||
for val in values - pks:
|
||||
cleaned_values.append(self.queryset.create(title=val).pk)
|
||||
return cleaned_values
|
||||
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,4 +1,15 @@
|
|||
(function ($) {
|
||||
/* global define, jQuery */
|
||||
(function (factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define(['jquery'], factory)
|
||||
} else if (typeof module === 'object' && module.exports) {
|
||||
module.exports = factory(require('jquery'))
|
||||
} else {
|
||||
// Browser globals
|
||||
factory(jQuery)
|
||||
}
|
||||
}(function ($) {
|
||||
'use strict'
|
||||
var init = function ($element, options) {
|
||||
$element.select2(options)
|
||||
}
|
||||
|
|
@ -53,4 +64,6 @@
|
|||
$(function () {
|
||||
$('.django-select2').djangoSelect2()
|
||||
})
|
||||
}(this.jQuery))
|
||||
|
||||
return $.fn.djangoSelect2
|
||||
}))
|
||||
|
|
|
|||
|
|
@ -3,14 +3,18 @@ Django-Select2 URL configuration.
|
|||
|
||||
Add `django_select` to your ``urlconf`` **if** you use any 'Model' fields::
|
||||
|
||||
url(r'^select2/', include('django_select2.urls')),
|
||||
from django.urls import path
|
||||
|
||||
|
||||
path('select2/', include('django_select2.urls')),
|
||||
|
||||
"""
|
||||
from django.conf.urls import url
|
||||
from django.urls import path
|
||||
|
||||
from .views import AutoResponseView
|
||||
|
||||
app_name = 'django_select2'
|
||||
|
||||
urlpatterns = [
|
||||
url(r"^fields/auto.json$",
|
||||
AutoResponseView.as_view(), name="django_select2-json"),
|
||||
path("fields/auto.json", AutoResponseView.as_view(), name="auto-json"),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ class AutoResponseView(BaseListView):
|
|||
for form_field_name, model_field_name in self.widget.dependent_fields.items()
|
||||
if form_field_name in self.request.GET and self.request.GET.get(form_field_name, '') != ''
|
||||
}
|
||||
return self.widget.filter_queryset(self.term, self.queryset, **kwargs)
|
||||
return self.widget.filter_queryset(self.request, self.term, self.queryset, **kwargs)
|
||||
|
||||
def get_paginate_by(self, queryset):
|
||||
"""Paginate response by size of widget's `max_results` parameter."""
|
||||
|
|
|
|||
1
docs/CONTRIBUTING.rst
Normal file
1
docs/CONTRIBUTING.rst
Normal file
|
|
@ -0,0 +1 @@
|
|||
.. include:: ../CONTRIBUTING.rst
|
||||
158
docs/Makefile
158
docs/Makefile
|
|
@ -1,158 +0,0 @@
|
|||
# Makefile for Sphinx documentation
|
||||
#
|
||||
|
||||
# You can set these variables from the command line.
|
||||
SPHINXOPTS =
|
||||
SPHINXBUILD = sphinx-build
|
||||
PAPER =
|
||||
BUILDDIR = _build
|
||||
|
||||
# Internal variables.
|
||||
PAPEROPT_a4 = -D latex_paper_size=a4
|
||||
PAPEROPT_letter = -D latex_paper_size=letter
|
||||
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
|
||||
# the i18n builder cannot share the environment and doctrees with the others
|
||||
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
|
||||
|
||||
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
|
||||
|
||||
help:
|
||||
@echo "Please use \`make <target>' where <target> is one of"
|
||||
@echo " html to make standalone HTML files"
|
||||
@echo " dirhtml to make HTML files named index.html in directories"
|
||||
@echo " singlehtml to make a single large HTML file"
|
||||
@echo " pickle to make pickle files"
|
||||
@echo " json to make JSON files"
|
||||
@echo " htmlhelp to make HTML files and a HTML help project"
|
||||
@echo " qthelp to make HTML files and a qthelp project"
|
||||
@echo " devhelp to make HTML files and a Devhelp project"
|
||||
@echo " epub to make an epub"
|
||||
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
|
||||
@echo " latexpdf to make LaTeX files and run them through pdflatex"
|
||||
@echo " text to make text files"
|
||||
@echo " man to make manual pages"
|
||||
@echo " texinfo to make Texinfo files"
|
||||
@echo " info to make Texinfo files and run them through makeinfo"
|
||||
@echo " gettext to make PO message catalogs"
|
||||
@echo " changes to make an overview of all changed/added/deprecated items"
|
||||
@echo " linkcheck to check all external links for integrity"
|
||||
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
|
||||
|
||||
clean:
|
||||
-rm -rf $(BUILDDIR)/*
|
||||
|
||||
html:
|
||||
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/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
|
||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
|
||||
|
||||
singlehtml:
|
||||
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
|
||||
@echo
|
||||
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
|
||||
|
||||
pickle:
|
||||
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
|
||||
@echo
|
||||
@echo "Build finished; now you can process the pickle files."
|
||||
|
||||
json:
|
||||
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
|
||||
@echo
|
||||
@echo "Build finished; now you can process the JSON files."
|
||||
|
||||
htmlhelp:
|
||||
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
|
||||
@echo
|
||||
@echo "Build finished; now you can run HTML Help Workshop with the" \
|
||||
".hhp project file in $(BUILDDIR)/htmlhelp."
|
||||
|
||||
qthelp:
|
||||
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
|
||||
@echo
|
||||
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
|
||||
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
|
||||
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/Django-Select2.qhcp"
|
||||
@echo "To view the help file:"
|
||||
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/Django-Select2.qhc"
|
||||
|
||||
devhelp:
|
||||
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
|
||||
@echo
|
||||
@echo "Build finished."
|
||||
@echo "To view the help file:"
|
||||
@echo "# mkdir -p $$HOME/.local/share/devhelp/Django-Select2"
|
||||
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/Django-Select2"
|
||||
@echo "# devhelp"
|
||||
|
||||
epub:
|
||||
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
|
||||
@echo
|
||||
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
|
||||
|
||||
latex:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo
|
||||
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
|
||||
@echo "Run \`make' in that directory to run these through (pdf)latex" \
|
||||
"(use \`make latexpdf' here to do that automatically)."
|
||||
|
||||
latexpdf:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo "Running LaTeX files through pdflatex..."
|
||||
$(MAKE) -C $(BUILDDIR)/latex all-pdf
|
||||
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
|
||||
|
||||
text:
|
||||
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
|
||||
@echo
|
||||
@echo "Build finished. The text files are in $(BUILDDIR)/text."
|
||||
|
||||
man:
|
||||
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
|
||||
@echo
|
||||
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
|
||||
|
||||
texinfo:
|
||||
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
|
||||
@echo
|
||||
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
|
||||
@echo "Run \`make' in that directory to run these through makeinfo" \
|
||||
"(use \`make info' here to do that automatically)."
|
||||
|
||||
info:
|
||||
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
|
||||
@echo "Running Texinfo files through makeinfo..."
|
||||
make -C $(BUILDDIR)/texinfo info
|
||||
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
|
||||
|
||||
gettext:
|
||||
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
|
||||
@echo
|
||||
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
|
||||
|
||||
changes:
|
||||
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
|
||||
@echo
|
||||
@echo "The overview file is in $(BUILDDIR)/changes."
|
||||
|
||||
linkcheck:
|
||||
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
|
||||
@echo
|
||||
@echo "Link check complete; look for any errors in the above output " \
|
||||
"or in $(BUILDDIR)/linkcheck/output.txt."
|
||||
|
||||
doctest:
|
||||
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
|
||||
@echo "Testing of doctests in the sources finished, look at the " \
|
||||
"results in $(BUILDDIR)/doctest/output.txt."
|
||||
338
docs/conf.py
338
docs/conf.py
|
|
@ -1,286 +1,52 @@
|
|||
#
|
||||
# Django-Select2 documentation build configuration file, created by
|
||||
# sphinx-quickstart on Sat Aug 25 10:23:46 2012.
|
||||
#
|
||||
# This file is execfile()d with the current directory set to its containing dir.
|
||||
#
|
||||
# Note that not all possible configuration values are present in this
|
||||
# autogenerated file.
|
||||
#
|
||||
# All configuration values have a default; values that are commented out
|
||||
# serve to show the default.
|
||||
|
||||
import datetime
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
|
||||
|
||||
year = datetime.datetime.now().strftime("%Y")
|
||||
|
||||
# This is needed since django_select2 requires django model modules
|
||||
# and those modules assume that django settings is configured and
|
||||
# have proper DB settings.
|
||||
# Using this we give a proper environment with working django settings.
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.testapp.settings")
|
||||
|
||||
# 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('../tests.testapp'))
|
||||
sys.path.insert(0, os.path.abspath('..'))
|
||||
|
||||
|
||||
|
||||
# -- General configuration -----------------------------------------------------
|
||||
|
||||
# If your documentation needs a minimal Sphinx version, state it here.
|
||||
#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 = [
|
||||
'sphinx.ext.autodoc',
|
||||
'sphinx.ext.napoleon',
|
||||
'sphinx.ext.inheritance_diagram',
|
||||
'sphinx.ext.intersphinx',
|
||||
'sphinx.ext.viewcode',
|
||||
'sphinxcontrib.spelling',
|
||||
]
|
||||
|
||||
intersphinx_mapping = {
|
||||
'python': ('http://docs.python.org/3.5', None),
|
||||
'django': ('https://docs.djangoproject.com/en/dev/',
|
||||
'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']
|
||||
|
||||
# The suffix of source filenames.
|
||||
source_suffix = '.rst'
|
||||
|
||||
# The encoding of source files.
|
||||
#source_encoding = 'utf-8-sig'
|
||||
|
||||
# The master toctree document.
|
||||
master_doc = 'index'
|
||||
|
||||
# General information about the project.
|
||||
project = u'django-select2'
|
||||
copyright = u'%s, Johannes Hoppe' % year
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
#language = None
|
||||
|
||||
# There are two options for replacing |today|: either, you set today to some
|
||||
# non-false value, then it is used:
|
||||
#today = ''
|
||||
# Else, today_fmt is used as the format for a strftime call.
|
||||
#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']
|
||||
|
||||
# The reST default role (used for this markup: `text`) to use for all documents.
|
||||
#default_role = None
|
||||
|
||||
# If true, '()' will be appended to :func: etc. cross-reference text.
|
||||
#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
|
||||
|
||||
# If true, sectionauthor and moduleauthor directives will be shown in the
|
||||
# output. They are ignored by default.
|
||||
#show_authors = False
|
||||
|
||||
# The name of the Pygments (syntax highlighting) style to use.
|
||||
pygments_style = 'sphinx'
|
||||
|
||||
# A list of ignored prefixes for module index sorting.
|
||||
#modindex_common_prefix = []
|
||||
|
||||
def skip(app, what, name, obj, skip, options):
|
||||
if name == "__init__" and obj.__doc__:
|
||||
return False
|
||||
return skip
|
||||
|
||||
def setup(app):
|
||||
app.connect("autodoc-skip-member", skip)
|
||||
|
||||
autodoc_default_flags = ['members', 'show-inheritance']
|
||||
autodoc_member_order = 'bysource'
|
||||
|
||||
inheritance_graph_attrs = dict(rankdir='TB')
|
||||
|
||||
inheritance_node_attrs = dict(shape='rect', fontsize=14, fillcolor='gray90',
|
||||
color='gray30', style='filled')
|
||||
|
||||
inheritance_edge_attrs = dict(penwidth=0.75)
|
||||
|
||||
# -- Options for HTML output ---------------------------------------------------
|
||||
|
||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
if on_rtd:
|
||||
html_theme = 'default'
|
||||
else:
|
||||
html_theme = 'sphinx_rtd_theme'
|
||||
|
||||
# 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 = {}
|
||||
|
||||
# Add any paths that contain custom themes here, relative to this directory.
|
||||
#html_theme_path = []
|
||||
|
||||
# The name for this set of Sphinx documents. If None, it defaults to
|
||||
# "<project> v<release> documentation".
|
||||
#html_title = None
|
||||
|
||||
# A shorter title for the navigation bar. Default is the same as html_title.
|
||||
#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
|
||||
|
||||
# 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
|
||||
|
||||
# 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']
|
||||
|
||||
# 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'
|
||||
|
||||
# If true, SmartyPants will be used to convert quotes and dashes to
|
||||
# typographically correct entities.
|
||||
#html_use_smartypants = True
|
||||
|
||||
# Custom sidebar templates, maps document names to template names.
|
||||
#html_sidebars = {}
|
||||
|
||||
# Additional templates that should be rendered to pages, maps page names to
|
||||
# template names.
|
||||
#html_additional_pages = {}
|
||||
|
||||
# If false, no module index is generated.
|
||||
#html_domain_indices = True
|
||||
|
||||
# If false, no index is generated.
|
||||
#html_use_index = True
|
||||
|
||||
# If true, the index is split into individual pages for each letter.
|
||||
#html_split_index = False
|
||||
|
||||
# If true, links to the reST sources are added to the pages.
|
||||
#html_show_sourcelink = True
|
||||
|
||||
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
|
||||
#html_show_sphinx = True
|
||||
|
||||
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
|
||||
#html_show_copyright = True
|
||||
|
||||
# If true, an OpenSearch description file will be output, and all pages will
|
||||
# contain a <link> tag referring to it. The value of this option must be the
|
||||
# base URL from which the finished HTML is served.
|
||||
#html_use_opensearch = ''
|
||||
|
||||
# This is the file name suffix for HTML files (e.g. ".xhtml").
|
||||
#html_file_suffix = None
|
||||
|
||||
# Output file base name for HTML help builder.
|
||||
htmlhelp_basename = 'Django-Select2doc'
|
||||
|
||||
|
||||
# -- Options for LaTeX output --------------------------------------------------
|
||||
|
||||
latex_elements = {
|
||||
# The paper size ('letterpaper' or 'a4paper').
|
||||
#'papersize': 'letterpaper',
|
||||
|
||||
# The font size ('10pt', '11pt' or '12pt').
|
||||
#'pointsize': '10pt',
|
||||
|
||||
# Additional stuff for the LaTeX preamble.
|
||||
#'preamble': '',
|
||||
}
|
||||
|
||||
# Grouping the document tree into LaTeX files. List of tuples
|
||||
# (source start file, target name, title, author, documentclass [howto/manual]).
|
||||
latex_documents = [
|
||||
('index', 'Django-Select2.tex', u'Django-Select2 Documentation',
|
||||
u'Nirupam Biswas', 'manual'),
|
||||
]
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top of
|
||||
# the title page.
|
||||
#latex_logo = None
|
||||
|
||||
# For "manual" documents, if this is true, then toplevel headings are parts,
|
||||
# not chapters.
|
||||
#latex_use_parts = False
|
||||
|
||||
# If true, show page references after internal links.
|
||||
#latex_show_pagerefs = False
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
#latex_show_urls = False
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
#latex_appendices = []
|
||||
|
||||
# If false, no module index is generated.
|
||||
#latex_domain_indices = True
|
||||
|
||||
|
||||
# -- Options for manual page output --------------------------------------------
|
||||
|
||||
# One entry per manual page. List of tuples
|
||||
# (source start file, name, description, authors, manual section).
|
||||
man_pages = [
|
||||
('index', 'django-select2', u'Django-Select2 Documentation',
|
||||
[u'Nirupam Biswas'], 1)
|
||||
]
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
#man_show_urls = False
|
||||
|
||||
|
||||
# -- Options for Texinfo output ------------------------------------------------
|
||||
|
||||
# Grouping the document tree into Texinfo files. List of tuples
|
||||
# (source start file, target name, title, author,
|
||||
# dir menu entry, description, category)
|
||||
texinfo_documents = [
|
||||
('index', 'Django-Select2', u'Django-Select2 Documentation',
|
||||
u'Nirupam Biswas', 'Django-Select2', 'One line description of project.',
|
||||
'Miscellaneous'),
|
||||
]
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
#texinfo_appendices = []
|
||||
|
||||
# If false, no module index is generated.
|
||||
#texinfo_domain_indices = True
|
||||
|
||||
# How to display URL addresses: 'footnote', 'no', or 'inline'.
|
||||
#texinfo_show_urls = 'footnote'
|
||||
import os
|
||||
import sys
|
||||
|
||||
from pkg_resources import get_distribution
|
||||
|
||||
# This is needed since django_select2 requires django model modules
|
||||
# and those modules assume that django settings is configured and
|
||||
# have proper DB settings.
|
||||
# Using this we give a proper environment with working django settings.
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.testapp.settings")
|
||||
|
||||
# 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('../tests.testapp'))
|
||||
sys.path.insert(0, os.path.abspath('..'))
|
||||
|
||||
|
||||
project = "Django-Select2"
|
||||
author = "Johannes Hoppe"
|
||||
copyright = "2017, Johannes Hoppe"
|
||||
release = get_distribution('django_select2').version
|
||||
version = '.'.join(release.split('.')[:2])
|
||||
|
||||
|
||||
master_doc = 'index' # default in Sphinx v2
|
||||
|
||||
|
||||
extensions = [
|
||||
'sphinx.ext.autodoc',
|
||||
'sphinx.ext.napoleon',
|
||||
'sphinx.ext.inheritance_diagram',
|
||||
'sphinx.ext.intersphinx',
|
||||
'sphinx.ext.viewcode',
|
||||
'sphinx.ext.doctest',
|
||||
]
|
||||
|
||||
intersphinx_mapping = {
|
||||
'python': ('http://docs.python.org/3', None),
|
||||
'django': ('https://docs.djangoproject.com/en/stable/',
|
||||
'https://docs.djangoproject.com/en/stable/_objects/'),
|
||||
}
|
||||
|
||||
autodoc_default_flags = ['members', 'show-inheritance']
|
||||
autodoc_member_order = 'bysource'
|
||||
|
||||
inheritance_graph_attrs = dict(rankdir='TB')
|
||||
|
||||
inheritance_node_attrs = dict(shape='rect', fontsize=14, fillcolor='gray90',
|
||||
color='gray30', style='filled')
|
||||
|
||||
inheritance_edge_attrs = dict(penwidth=0.75)
|
||||
|
|
|
|||
|
|
@ -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 <https://select2.github.io/options.html>`_ if
|
|||
|
||||
$('.django-select2').djangoSelect2({placeholder: 'Select an option'});
|
||||
|
||||
Please replace all your ``.select2`` invocations with the here provided
|
||||
``.djangoSelect2``.
|
||||
|
||||
Security & Authentication
|
||||
-------------------------
|
||||
|
||||
|
|
@ -81,6 +85,6 @@ want to be accessible to the general public. Doing so is easy::
|
|||
kwargs['data_view'] = 'user-select2-view'
|
||||
super(UserSelect2WidgetMixin, self).__init__(*args, **kwargs)
|
||||
|
||||
class MySecretWidget(UserSelect2WidgetMixin, Select2ModelWidget):
|
||||
class MySecretWidget(UserSelect2WidgetMixin, ModelSelect2Widget):
|
||||
model = MySecretModel
|
||||
search_fields = ['title__icontains']
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
Django >= 1.8
|
||||
sphinxcontrib-spelling
|
||||
pyenchant
|
||||
|
|
@ -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,19 +23,53 @@ 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
|
||||
-----------
|
||||
|
||||
Here is a quick example to get you started:
|
||||
|
||||
0. Follow the installation instructions above.
|
||||
|
||||
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::
|
||||
|
||||
from django import forms
|
||||
from django_select2 import forms as s2forms
|
||||
|
||||
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::
|
||||
|
||||
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::
|
||||
|
||||
{{ form.media.css }}
|
||||
|
||||
3. Add the JavaScript to the end of the ``body`` of your Django template::
|
||||
|
||||
{{ form.media.js }}
|
||||
|
||||
4. Done - enjoy the wonders of Select2!
|
||||
|
||||
External Dependencies
|
||||
---------------------
|
||||
|
||||
* jQuery version 2
|
||||
This is not included in the package since it is expected
|
||||
that in most scenarios this would already be available.
|
||||
* jQuery (version >=2)
|
||||
jQuery is not included in the package since it is expected
|
||||
that in most scenarios jQuery is already loaded.
|
||||
|
||||
Example Application
|
||||
-------------------
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ Contents:
|
|||
get_started
|
||||
django_select2
|
||||
extra
|
||||
CONTRIBUTING
|
||||
|
||||
Indices and tables
|
||||
==================
|
||||
|
|
|
|||
190
docs/make.bat
190
docs/make.bat
|
|
@ -1,190 +0,0 @@
|
|||
@ECHO OFF
|
||||
|
||||
REM Command file for Sphinx documentation
|
||||
|
||||
if "%SPHINXBUILD%" == "" (
|
||||
set SPHINXBUILD=sphinx-build
|
||||
)
|
||||
set BUILDDIR=_build
|
||||
set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% .
|
||||
set I18NSPHINXOPTS=%SPHINXOPTS% .
|
||||
if NOT "%PAPER%" == "" (
|
||||
set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
|
||||
set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS%
|
||||
)
|
||||
|
||||
if "%1" == "" goto help
|
||||
|
||||
if "%1" == "help" (
|
||||
:help
|
||||
echo.Please use `make ^<target^>` where ^<target^> is one of
|
||||
echo. html to make standalone HTML files
|
||||
echo. dirhtml to make HTML files named index.html in directories
|
||||
echo. singlehtml to make a single large HTML file
|
||||
echo. pickle to make pickle files
|
||||
echo. json to make JSON files
|
||||
echo. htmlhelp to make HTML files and a HTML help project
|
||||
echo. qthelp to make HTML files and a qthelp project
|
||||
echo. devhelp to make HTML files and a Devhelp project
|
||||
echo. epub to make an epub
|
||||
echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
|
||||
echo. text to make text files
|
||||
echo. man to make manual pages
|
||||
echo. texinfo to make Texinfo files
|
||||
echo. gettext to make PO message catalogs
|
||||
echo. changes to make an overview over all changed/added/deprecated items
|
||||
echo. linkcheck to check all external links for integrity
|
||||
echo. doctest to run all doctests embedded in the documentation if enabled
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "clean" (
|
||||
for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
|
||||
del /q /s %BUILDDIR%\*
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "html" (
|
||||
%SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The HTML pages are in %BUILDDIR%/html.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "dirhtml" (
|
||||
%SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "singlehtml" (
|
||||
%SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "pickle" (
|
||||
%SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; now you can process the pickle files.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "json" (
|
||||
%SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; now you can process the JSON files.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "htmlhelp" (
|
||||
%SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; now you can run HTML Help Workshop with the ^
|
||||
.hhp project file in %BUILDDIR%/htmlhelp.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "qthelp" (
|
||||
%SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; now you can run "qcollectiongenerator" with the ^
|
||||
.qhcp project file in %BUILDDIR%/qthelp, like this:
|
||||
echo.^> qcollectiongenerator %BUILDDIR%\qthelp\Django-Select2.qhcp
|
||||
echo.To view the help file:
|
||||
echo.^> assistant -collectionFile %BUILDDIR%\qthelp\Django-Select2.ghc
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "devhelp" (
|
||||
%SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "epub" (
|
||||
%SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The epub file is in %BUILDDIR%/epub.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "latex" (
|
||||
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "text" (
|
||||
%SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The text files are in %BUILDDIR%/text.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "man" (
|
||||
%SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The manual pages are in %BUILDDIR%/man.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "texinfo" (
|
||||
%SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "gettext" (
|
||||
%SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "changes" (
|
||||
%SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.The overview file is in %BUILDDIR%/changes.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "linkcheck" (
|
||||
%SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Link check complete; look for any errors in the above output ^
|
||||
or in %BUILDDIR%/linkcheck/output.txt.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "doctest" (
|
||||
%SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Testing of doctests in the sources finished, look at the ^
|
||||
results in %BUILDDIR%/doctest/output.txt.
|
||||
goto end
|
||||
)
|
||||
|
||||
:end
|
||||
37
package.json
Normal file
37
package.json
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
{
|
||||
"name": "django-select2",
|
||||
"version": "0.0.0",
|
||||
"description": "This is a Django integration of Select2.",
|
||||
"files": [
|
||||
"django_select2/static/**/*"
|
||||
],
|
||||
"main": "django_select2/static/django_select2/django_select2.js",
|
||||
"directories": {
|
||||
"doc": "docs",
|
||||
"test": "tests"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "standard"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/applegrew/django-select2.git"
|
||||
},
|
||||
"keywords": [
|
||||
"django",
|
||||
"select2"
|
||||
],
|
||||
"author": "Johannes Hoppe",
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/applegrew/django-select2/issues"
|
||||
},
|
||||
"homepage": "https://github.com/applegrew/django-select2#readme",
|
||||
"peerDependencies": {
|
||||
"select2": "*",
|
||||
"jquery": ">= 1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"standard": "*"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
coverage
|
||||
django-appconf
|
||||
flake8
|
||||
pep8-naming
|
||||
mccabe
|
||||
isort
|
||||
pydocstyle
|
||||
pytest
|
||||
pytest-django
|
||||
selenium
|
||||
sphinx
|
||||
sphinxcontrib-spelling
|
||||
pyenchant
|
||||
django-redis
|
||||
|
|
@ -1 +0,0 @@
|
|||
django-appconf>=0.6.0
|
||||
12
set_version.py
Executable file
12
set_version.py
Executable file
|
|
@ -0,0 +1,12 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Set the version in NPM's package.json to match the git tag."""
|
||||
import json
|
||||
import os
|
||||
|
||||
if __name__ == '__main__':
|
||||
with open('package.json', 'r+') as f:
|
||||
data = json.load(f)
|
||||
f.seek(0)
|
||||
data['version'] = os.environ['TRAVIS_TAG']
|
||||
json.dump(data, f)
|
||||
f.truncate()
|
||||
77
setup.cfg
77
setup.cfg
|
|
@ -1,11 +1,12 @@
|
|||
[metadata]
|
||||
name = django-select2
|
||||
author = Johannes Hoppe
|
||||
author-email = info@johanneshoppe.com
|
||||
summary = Select2 option fields for Django.
|
||||
description-file = README.rst
|
||||
home-page = https://github.com/applegrew/django-select2
|
||||
license = Apache-2
|
||||
author_email = info@johanneshoppe.com
|
||||
description = Select2 option fields for Django
|
||||
long_description = file: README.rst
|
||||
url = https://github.com/applegrew/django-select2
|
||||
license = MIT
|
||||
license_file = LICENSE
|
||||
classifier =
|
||||
Development Status :: 5 - Production/Stable
|
||||
Environment :: Web Environment
|
||||
|
|
@ -15,38 +16,68 @@ classifier =
|
|||
Programming Language :: Python
|
||||
Programming Language :: Python :: 3
|
||||
Framework :: Django
|
||||
Framework :: Django :: 1.8
|
||||
Framework :: Django :: 1.10
|
||||
Framework :: Django :: 1.11
|
||||
|
||||
[files]
|
||||
packages =
|
||||
django_select2
|
||||
[options]
|
||||
include_package_data = True
|
||||
packages = django_select2
|
||||
install_requires =
|
||||
django>=2.2
|
||||
django-appconf>=0.6.0
|
||||
setup_requires =
|
||||
setuptools_scm
|
||||
sphinx
|
||||
pytest-runner
|
||||
tests_require =
|
||||
pytest
|
||||
pytest-cov
|
||||
pytest-django
|
||||
selenium
|
||||
|
||||
[bdist_wheel]
|
||||
universal = 1
|
||||
|
||||
[bdist_rpm]
|
||||
requires =
|
||||
python-django-appconf >= 2.0
|
||||
python-django-appconf >= 0.6
|
||||
|
||||
[aliases]
|
||||
test = pytest
|
||||
|
||||
[build_sphinx]
|
||||
source-dir = docs
|
||||
build-dir = docs/_build
|
||||
|
||||
[tool:pytest]
|
||||
norecursedirs = env docs
|
||||
addopts = --tb=short -rxs
|
||||
addopts = --cov=django_select2 --cov-report xml
|
||||
DJANGO_SETTINGS_MODULE=tests.testapp.settings
|
||||
|
||||
[tox:tox]
|
||||
envlist = py{36,37,38}-dj{22,30,master},docs
|
||||
|
||||
[testenv]
|
||||
passenv=CI
|
||||
deps =
|
||||
dj22: django~=2.2
|
||||
dj30: django~=3.0
|
||||
djmaster: https://github.com/django/django/archive/master.tar.gz#egg=django
|
||||
commands = python setup.py test
|
||||
|
||||
[testenv:docs]
|
||||
commands = python setup.py build_sphinx -W -b doctest -b html
|
||||
|
||||
[flake8]
|
||||
max-line-length = 120
|
||||
max-complexity = 10
|
||||
statistics = true
|
||||
show-source = true
|
||||
exclude = docs,runtests.py,setup.py,.tox,env
|
||||
|
||||
[pep257]
|
||||
match = (?!setup).*.py
|
||||
match-dir = (?!tests|env|docs|\.).*
|
||||
[pydocstyle]
|
||||
add_ignore = D1
|
||||
|
||||
[isort]
|
||||
atomic = true
|
||||
multi_line_output = 5
|
||||
line_length = 79
|
||||
skip = manage.py,docs,.tox,env
|
||||
known_first_party = django_select2, tests
|
||||
known_third_party = django
|
||||
default_section=THIRDPARTY
|
||||
combine_as_imports = true
|
||||
|
||||
[bdist_rpm]
|
||||
requires = python-django-appconf >= 0.6
|
||||
|
|
|
|||
5
setup.py
5
setup.py
|
|
@ -2,7 +2,4 @@
|
|||
|
||||
from setuptools import setup
|
||||
|
||||
setup(
|
||||
setup_requires=['pbr'],
|
||||
pbr=True,
|
||||
)
|
||||
setup(name='django-select2', use_scm_version=True)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import random
|
|||
import string
|
||||
|
||||
import pytest
|
||||
from django.utils.encoding import force_text
|
||||
from selenium import webdriver
|
||||
from selenium.common.exceptions import WebDriverException
|
||||
|
||||
|
|
@ -22,12 +21,11 @@ def random_name(n):
|
|||
@pytest.yield_fixture(scope='session')
|
||||
def driver():
|
||||
chrome_options = webdriver.ChromeOptions()
|
||||
chrome_options.add_argument('headless')
|
||||
chrome_options.add_argument('window-size=1200x800')
|
||||
chrome_options.headless = True
|
||||
try:
|
||||
b = webdriver.Chrome(chrome_options=chrome_options)
|
||||
b = webdriver.Chrome(options=chrome_options)
|
||||
except WebDriverException as e:
|
||||
pytest.skip(force_text(e))
|
||||
pytest.skip(str(e))
|
||||
else:
|
||||
yield b
|
||||
b.quit()
|
||||
|
|
|
|||
|
|
@ -1,19 +1,20 @@
|
|||
import collections
|
||||
import json
|
||||
import os
|
||||
from collections.abc import Iterable
|
||||
|
||||
import pytest
|
||||
from django.core import signing
|
||||
from django.db.models import QuerySet
|
||||
from django.urls import reverse
|
||||
from django.utils import translation
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.six import text_type
|
||||
from selenium.common.exceptions import NoSuchElementException
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support import expected_conditions
|
||||
from selenium.webdriver.support.wait import WebDriverWait
|
||||
|
||||
from django_select2.cache import cache
|
||||
from django_select2.conf import settings
|
||||
from django_select2.forms import (
|
||||
HeavySelect2MultipleWidget, HeavySelect2Widget, ModelSelect2TagWidget,
|
||||
ModelSelect2Widget, Select2Widget
|
||||
|
|
@ -22,15 +23,10 @@ from tests.testapp import forms
|
|||
from tests.testapp.forms import (
|
||||
NUMBER_CHOICES, HeavySelect2MultipleWidgetForm, TitleModelSelect2Widget
|
||||
)
|
||||
from tests.testapp.models import City, Country, Genre
|
||||
|
||||
try:
|
||||
from django.urls import reverse
|
||||
except ImportError:
|
||||
from django.core.urlresolvers import reverse
|
||||
from tests.testapp.models import Artist, City, Country, Genre, Groupie
|
||||
|
||||
|
||||
class TestSelect2Mixin(object):
|
||||
class TestSelect2Mixin:
|
||||
url = reverse('select2_widget')
|
||||
form = forms.AlbumSelect2WidgetForm()
|
||||
multiple_form = forms.AlbumSelect2MultipleWidgetForm()
|
||||
|
|
@ -39,7 +35,7 @@ class TestSelect2Mixin(object):
|
|||
def test_initial_data(self, genres):
|
||||
genre = genres[0]
|
||||
form = self.form.__class__(initial={'primary_genre': genre.pk})
|
||||
assert text_type(genre) in form.as_p()
|
||||
assert str(genre) in form.as_p()
|
||||
|
||||
def test_initial_form_class(self):
|
||||
widget = self.widget_cls(attrs={'class': 'my-class'})
|
||||
|
|
@ -99,50 +95,61 @@ class TestSelect2Mixin(object):
|
|||
multiple_select = self.multiple_form.fields['featured_artists']
|
||||
assert multiple_select.required is False
|
||||
assert multiple_select.widget.allow_multiple_selected
|
||||
assert '<option value=""></option>' not in multiple_select.widget.render('featured_artists', None)
|
||||
output = multiple_select.widget.render('featured_artists', None)
|
||||
assert '<option value=""></option>' not in output
|
||||
assert 'data-placeholder=""' in output
|
||||
|
||||
def test_i18n(self):
|
||||
translation.activate('de')
|
||||
assert tuple(Select2Widget().media._js) == (
|
||||
'//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js',
|
||||
'//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/i18n/de.js',
|
||||
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js',
|
||||
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/i18n/de.js',
|
||||
'django_select2/django_select2.js'
|
||||
)
|
||||
|
||||
translation.activate('en')
|
||||
assert tuple(Select2Widget().media._js) == (
|
||||
'//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js',
|
||||
'//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/i18n/en.js',
|
||||
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js',
|
||||
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/i18n/en.js',
|
||||
'django_select2/django_select2.js'
|
||||
)
|
||||
|
||||
translation.activate('00')
|
||||
assert tuple(Select2Widget().media._js) == (
|
||||
'//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js',
|
||||
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js',
|
||||
'django_select2/django_select2.js'
|
||||
)
|
||||
|
||||
translation.activate('sr-cyrl')
|
||||
assert tuple(Select2Widget().media._js) == (
|
||||
'//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js',
|
||||
'//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/i18n/sr-Cyrl.js',
|
||||
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js',
|
||||
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/i18n/sr-Cyrl.js',
|
||||
'django_select2/django_select2.js'
|
||||
)
|
||||
|
||||
translation.activate('zh-cn')
|
||||
pytest.importorskip("django", minversion="2.0.4")
|
||||
|
||||
translation.activate('zh-hans')
|
||||
assert tuple(Select2Widget().media._js) == (
|
||||
'//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js',
|
||||
'//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/i18n/zh-CN.js',
|
||||
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js',
|
||||
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/i18n/zh-CN.js',
|
||||
'django_select2/django_select2.js'
|
||||
)
|
||||
|
||||
translation.activate('zh-hant')
|
||||
assert tuple(Select2Widget().media._js) == (
|
||||
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js',
|
||||
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/i18n/zh-TW.js',
|
||||
'django_select2/django_select2.js'
|
||||
)
|
||||
|
||||
|
||||
class TestSelect2MixinSettings(object):
|
||||
class TestSelect2MixinSettings:
|
||||
def test_default_media(self):
|
||||
sut = Select2Widget()
|
||||
result = sut.media.render()
|
||||
assert '//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js' in result
|
||||
assert '//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css' in result
|
||||
assert f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js' in result
|
||||
assert f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/css/select2.min.css' in result
|
||||
assert 'django_select2/django_select2.js' in result
|
||||
|
||||
def test_js_setting(self, settings):
|
||||
|
|
@ -152,12 +159,24 @@ class TestSelect2MixinSettings(object):
|
|||
assert 'alternate.js' in result
|
||||
assert 'django_select2/django_select2.js' in result
|
||||
|
||||
def test_empty_js_setting(self, settings):
|
||||
settings.SELECT2_JS = ''
|
||||
sut = Select2Widget()
|
||||
result = sut.media.render()
|
||||
assert 'django_select2/django_select2.js' in result
|
||||
|
||||
def test_css_setting(self, settings):
|
||||
settings.SELECT2_CSS = 'alternate.css'
|
||||
sut = Select2Widget()
|
||||
result = sut.media.render()
|
||||
assert 'alternate.css' in result
|
||||
|
||||
def test_empty_css_setting(self, settings):
|
||||
settings.SELECT2_CSS = ''
|
||||
sut = Select2Widget()
|
||||
result = sut.media.render()
|
||||
assert '.css' not in result
|
||||
|
||||
|
||||
class TestHeavySelect2Mixin(TestSelect2Mixin):
|
||||
url = reverse('heavy_select2_widget')
|
||||
|
|
@ -200,12 +219,17 @@ class TestHeavySelect2Mixin(TestSelect2Mixin):
|
|||
driver.find_element_by_css_selector('.select2-results')
|
||||
|
||||
elem1, elem2 = driver.find_elements_by_css_selector('.select2-selection')
|
||||
elem1.click()
|
||||
|
||||
elem1.click()
|
||||
search1 = driver.find_element_by_css_selector('.select2-search__field')
|
||||
search1.send_keys('fo')
|
||||
result1 = WebDriverWait(driver, 60).until(
|
||||
expected_conditions.presence_of_element_located((By.CSS_SELECTOR, '.select2-results li:first-child'))
|
||||
).text
|
||||
|
||||
elem2.click()
|
||||
search2 = driver.find_element_by_css_selector('.select2-search__field')
|
||||
search2.send_keys('fo')
|
||||
result2 = WebDriverWait(driver, 60).until(
|
||||
expected_conditions.presence_of_element_located((By.CSS_SELECTOR, '.select2-results li:first-child'))
|
||||
).text
|
||||
|
|
@ -218,12 +242,12 @@ class TestHeavySelect2Mixin(TestSelect2Mixin):
|
|||
|
||||
def test_get_url(self):
|
||||
widget = self.widget_cls(data_view='heavy_data_1', attrs={'class': 'my-class'})
|
||||
assert isinstance(widget.get_url(), text_type)
|
||||
assert isinstance(widget.get_url(), str)
|
||||
|
||||
def test_can_not_pickle(self):
|
||||
widget = self.widget_cls(data_view='heavy_data_1', attrs={'class': 'my-class'})
|
||||
|
||||
class NoPickle(object):
|
||||
class NoPickle:
|
||||
pass
|
||||
|
||||
widget.no_pickle = NoPickle()
|
||||
|
|
@ -238,7 +262,7 @@ class TestModelSelect2Mixin(TestHeavySelect2Mixin):
|
|||
def test_initial_data(self, genres):
|
||||
genre = genres[0]
|
||||
form = self.form.__class__(initial={'primary_genre': genre.pk})
|
||||
assert text_type(genre) in form.as_p()
|
||||
assert str(genre) in form.as_p()
|
||||
|
||||
def test_label_from_instance_initial(self, genres):
|
||||
genre = genres[0]
|
||||
|
|
@ -298,40 +322,71 @@ class TestModelSelect2Mixin(TestHeavySelect2Mixin):
|
|||
widget.queryset = Genre.objects.all()
|
||||
assert isinstance(widget.get_queryset(), QuerySet)
|
||||
|
||||
def test_tag_attrs_Select2Widget(self):
|
||||
widget = Select2Widget()
|
||||
output = widget.render('name', 'value')
|
||||
assert 'data-minimum-input-length="0"' in output
|
||||
|
||||
def test_custom_tag_attrs_Select2Widget(self):
|
||||
widget = Select2Widget(attrs={'data-minimum-input-length': '3'})
|
||||
output = widget.render('name', 'value')
|
||||
assert 'data-minimum-input-length="3"' in output
|
||||
|
||||
def test_tag_attrs_ModelSelect2Widget(self):
|
||||
widget = ModelSelect2Widget(queryset=Genre.objects.all(), search_fields=['title__icontains'])
|
||||
output = widget.render('name', 'value')
|
||||
assert 'data-minimum-input-length="2"' in output
|
||||
|
||||
def test_tag_attrs_ModelSelect2TagWidget(self):
|
||||
widget = ModelSelect2TagWidget(queryset=Genre.objects.all(), search_fields=['title__icontains'])
|
||||
output = widget.render('name', 'value')
|
||||
assert 'data-minimum-input-length="2"' in output
|
||||
|
||||
def test_tag_attrs_HeavySelect2Widget(self):
|
||||
widget = HeavySelect2Widget(data_url='/foo/bar/')
|
||||
output = widget.render('name', 'value')
|
||||
assert 'data-minimum-input-length="2"' in output
|
||||
|
||||
def test_custom_tag_attrs_ModelSelect2Widget(self):
|
||||
widget = ModelSelect2Widget(
|
||||
queryset=Genre.objects.all(), search_fields=['title__icontains'], attrs={'data-minimum-input-length': '3'})
|
||||
output = widget.render('name', 'value')
|
||||
assert 'data-minimum-input-length="3"' in output
|
||||
|
||||
def test_get_search_fields(self):
|
||||
widget = ModelSelect2Widget()
|
||||
with pytest.raises(NotImplementedError):
|
||||
widget.get_search_fields()
|
||||
|
||||
widget.search_fields = ['title__icontains']
|
||||
assert isinstance(widget.get_search_fields(), collections.Iterable)
|
||||
assert all(isinstance(x, text_type) for x in widget.get_search_fields())
|
||||
assert isinstance(widget.get_search_fields(), Iterable)
|
||||
assert all(isinstance(x, str) for x in widget.get_search_fields())
|
||||
|
||||
def test_filter_queryset(self, genres):
|
||||
widget = TitleModelSelect2Widget(queryset=Genre.objects.all())
|
||||
assert widget.filter_queryset(genres[0].title[:3]).exists()
|
||||
assert widget.filter_queryset(None, genres[0].title[:3]).exists()
|
||||
|
||||
widget = TitleModelSelect2Widget(search_fields=['title__icontains'],
|
||||
queryset=Genre.objects.all())
|
||||
qs = widget.filter_queryset(" ".join([genres[0].title[:3], genres[0].title[3:]]))
|
||||
qs = widget.filter_queryset(None, " ".join([genres[0].title[:3], genres[0].title[3:]]))
|
||||
assert qs.exists()
|
||||
|
||||
def test_model_kwarg(self):
|
||||
widget = ModelSelect2Widget(model=Genre, search_fields=['title__icontains'])
|
||||
genre = Genre.objects.last()
|
||||
result = widget.filter_queryset(genre.title)
|
||||
result = widget.filter_queryset(None, genre.title)
|
||||
assert result.exists()
|
||||
|
||||
def test_queryset_kwarg(self):
|
||||
widget = ModelSelect2Widget(queryset=Genre.objects.all(), search_fields=['title__icontains'])
|
||||
genre = Genre.objects.last()
|
||||
result = widget.filter_queryset(genre.title)
|
||||
result = widget.filter_queryset(None, genre.title)
|
||||
assert result.exists()
|
||||
|
||||
def test_ajax_view_registration(self, client):
|
||||
widget = ModelSelect2Widget(queryset=Genre.objects.all(), search_fields=['title__icontains'])
|
||||
widget.render('name', 'value')
|
||||
url = reverse('django_select2-json')
|
||||
url = reverse('django_select2:auto-json')
|
||||
genre = Genre.objects.last()
|
||||
response = client.get(url, data=dict(field_id=signing.dumps(id(widget)), term=genre.title))
|
||||
assert response.status_code == 200, response.content
|
||||
|
|
@ -344,14 +399,28 @@ class TestModelSelect2Mixin(TestHeavySelect2Mixin):
|
|||
widget.render('name', 'value')
|
||||
cached_widget = cache.get(widget._get_cache_key())
|
||||
assert cached_widget['max_results'] == widget.max_results
|
||||
assert cached_widget['search_fields'] == widget.search_fields
|
||||
assert cached_widget['search_fields'] == tuple(widget.search_fields)
|
||||
qs = widget.get_queryset()
|
||||
assert isinstance(cached_widget['queryset'][0], qs.__class__)
|
||||
assert text_type(cached_widget['queryset'][1]) == text_type(qs.query)
|
||||
assert str(cached_widget['queryset'][1]) == str(qs.query)
|
||||
|
||||
def test_get_url(self):
|
||||
widget = ModelSelect2Widget(queryset=Genre.objects.all(), search_fields=['title__icontains'])
|
||||
assert isinstance(widget.get_url(), text_type)
|
||||
assert isinstance(widget.get_url(), str)
|
||||
|
||||
def test_custom_to_field_name(self):
|
||||
the_best_band_in_the_world = Artist.objects.create(title='Take That')
|
||||
groupie = Groupie.objects.create(obsession=the_best_band_in_the_world)
|
||||
form = forms.GroupieForm(instance=groupie)
|
||||
assert '<option value="Take That" selected>TAKE THAT</option>' in form.as_p()
|
||||
|
||||
def test_empty_label(self, db):
|
||||
# Empty options is only required for single selects
|
||||
# https://select2.github.io/options.html#allowClear
|
||||
single_select = self.form.fields['primary_genre']
|
||||
single_select.empty_label = 'Hello World'
|
||||
assert single_select.required is False
|
||||
assert 'data-placeholder="Hello World"' in single_select.widget.render('primary_genre', None)
|
||||
|
||||
|
||||
class TestHeavySelect2TagWidget(TestHeavySelect2Mixin):
|
||||
|
|
@ -359,7 +428,7 @@ class TestHeavySelect2TagWidget(TestHeavySelect2Mixin):
|
|||
def test_tag_attrs(self):
|
||||
widget = ModelSelect2TagWidget(queryset=Genre.objects.all(), search_fields=['title__icontains'])
|
||||
output = widget.render('name', 'value')
|
||||
assert 'data-minimum-input-length="1"' in output
|
||||
assert 'data-minimum-input-length="2"' in output
|
||||
assert 'data-tags="true"' in output
|
||||
assert 'data-token-separators' in output
|
||||
|
||||
|
|
@ -370,7 +439,7 @@ class TestHeavySelect2TagWidget(TestHeavySelect2Mixin):
|
|||
assert 'data-minimum-input-length="3"' in output
|
||||
|
||||
|
||||
class TestHeavySelect2MultipleWidget(object):
|
||||
class TestHeavySelect2MultipleWidget:
|
||||
url = reverse('heavy_select2_multiple_widget')
|
||||
form = forms.HeavySelect2MultipleWidgetForm()
|
||||
widget_cls = HeavySelect2MultipleWidget
|
||||
|
|
@ -400,7 +469,7 @@ class TestHeavySelect2MultipleWidget(object):
|
|||
assert result_title == 'One'
|
||||
|
||||
|
||||
class TestAddressChainedSelect2Widget(object):
|
||||
class TestAddressChainedSelect2Widget:
|
||||
url = reverse('model_chained_select2_widget')
|
||||
form = forms.AddressChainedSelect2WidgetForm()
|
||||
|
||||
|
|
|
|||
|
|
@ -16,13 +16,13 @@ except ImportError:
|
|||
from django.core.urlresolvers import reverse
|
||||
|
||||
|
||||
class TestAutoResponseView(object):
|
||||
class TestAutoResponseView:
|
||||
def test_get(self, client, artists):
|
||||
artist = artists[0]
|
||||
form = AlbumModelSelect2WidgetForm()
|
||||
assert form.as_p()
|
||||
field_id = signing.dumps(id(form.fields['artist'].widget))
|
||||
url = reverse('django_select2-json')
|
||||
url = reverse('django_select2:auto-json')
|
||||
response = client.get(url, {'field_id': field_id, 'term': artist.title})
|
||||
assert response.status_code == 200
|
||||
data = json.loads(response.content.decode('utf-8'))
|
||||
|
|
@ -31,25 +31,25 @@ class TestAutoResponseView(object):
|
|||
|
||||
def test_no_field_id(self, client, artists):
|
||||
artist = artists[0]
|
||||
url = reverse('django_select2-json')
|
||||
url = reverse('django_select2:auto-json')
|
||||
response = client.get(url, {'term': artist.title})
|
||||
assert response.status_code == 404
|
||||
|
||||
def test_wrong_field_id(self, client, artists):
|
||||
artist = artists[0]
|
||||
url = reverse('django_select2-json')
|
||||
url = reverse('django_select2:auto-json')
|
||||
response = client.get(url, {'field_id': 123, 'term': artist.title})
|
||||
assert response.status_code == 404
|
||||
|
||||
def test_field_id_not_found(self, client, artists):
|
||||
artist = artists[0]
|
||||
field_id = signing.dumps(123456789)
|
||||
url = reverse('django_select2-json')
|
||||
url = reverse('django_select2:auto-json')
|
||||
response = client.get(url, {'field_id': field_id, 'term': artist.title})
|
||||
assert response.status_code == 404
|
||||
|
||||
def test_pagination(self, genres, client):
|
||||
url = reverse('django_select2-json')
|
||||
url = reverse('django_select2:auto-json')
|
||||
widget = ModelSelect2Widget(
|
||||
max_results=10,
|
||||
model=Genre,
|
||||
|
|
@ -72,7 +72,7 @@ class TestAutoResponseView(object):
|
|||
assert data['more'] is False
|
||||
|
||||
def test_label_from_instance(self, artists, client):
|
||||
url = reverse('django_select2-json')
|
||||
url = reverse('django_select2:auto-json')
|
||||
|
||||
form = AlbumModelSelect2WidgetForm()
|
||||
form.fields['artist'].widget = ArtistCustomTitleWidget()
|
||||
|
|
@ -96,6 +96,6 @@ class TestAutoResponseView(object):
|
|||
widget_dict = cache.get(cache_key)
|
||||
widget_dict['url'] = 'yet/another/url'
|
||||
cache.set(cache_key, widget_dict)
|
||||
url = reverse('django_select2-json')
|
||||
url = reverse('django_select2:auto-json')
|
||||
response = client.get(url, {'field_id': field_id, 'term': artist.title})
|
||||
assert response.status_code == 404
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ from tests.testapp import models
|
|||
from tests.testapp.models import Album, City, Country
|
||||
|
||||
|
||||
class TitleSearchFieldMixin(object):
|
||||
class TitleSearchFieldMixin:
|
||||
search_fields = [
|
||||
'title__icontains',
|
||||
'pk__startswith'
|
||||
|
|
@ -149,11 +149,19 @@ class HeavySelect2WidgetForm(forms.Form):
|
|||
class HeavySelect2MultipleWidgetForm(forms.Form):
|
||||
title = forms.CharField(max_length=50)
|
||||
genres = forms.MultipleChoiceField(
|
||||
widget=HeavySelect2MultipleWidget(data_view='heavy_data_1', choices=NUMBER_CHOICES),
|
||||
widget=HeavySelect2MultipleWidget(
|
||||
data_view='heavy_data_1',
|
||||
choices=NUMBER_CHOICES,
|
||||
attrs={'data-minimum-input-length': 0},
|
||||
),
|
||||
choices=NUMBER_CHOICES
|
||||
)
|
||||
featured_artists = forms.MultipleChoiceField(
|
||||
widget=HeavySelect2MultipleWidget(data_view='heavy_data_2', choices=NUMBER_CHOICES),
|
||||
widget=HeavySelect2MultipleWidget(
|
||||
data_view='heavy_data_2',
|
||||
choices=NUMBER_CHOICES,
|
||||
attrs={'data-minimum-input-length': 0},
|
||||
),
|
||||
choices=NUMBER_CHOICES,
|
||||
required=False
|
||||
)
|
||||
|
|
@ -178,10 +186,10 @@ class AddressChainedSelect2WidgetForm(forms.Form):
|
|||
queryset=Country.objects.all(),
|
||||
label='Country',
|
||||
widget=ModelSelect2Widget(
|
||||
model=Country,
|
||||
search_fields=['name__icontains'],
|
||||
max_results=500,
|
||||
dependent_fields={'city': 'cities'},
|
||||
attrs={'data-minimum-input-length': 0},
|
||||
)
|
||||
)
|
||||
|
||||
|
|
@ -189,9 +197,18 @@ class AddressChainedSelect2WidgetForm(forms.Form):
|
|||
queryset=City.objects.all(),
|
||||
label='City',
|
||||
widget=ModelSelect2Widget(
|
||||
model=City,
|
||||
search_fields=['name__icontains'],
|
||||
dependent_fields={'country': 'country'},
|
||||
max_results=500,
|
||||
attrs={'data-minimum-input-length': 0},
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class GroupieForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = models.Groupie
|
||||
fields = '__all__'
|
||||
widgets = {
|
||||
'obsession': ArtistCustomTitleWidget
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ class Genre(models.Model):
|
|||
|
||||
|
||||
class Artist(models.Model):
|
||||
title = models.CharField(max_length=50)
|
||||
title = models.CharField(max_length=50, unique=True)
|
||||
genres = models.ManyToManyField(Genre)
|
||||
|
||||
class Meta:
|
||||
|
|
@ -56,3 +56,7 @@ class City(models.Model):
|
|||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class Groupie(models.Model):
|
||||
obsession = models.ForeignKey(Artist, to_field='title', on_delete=models.CASCADE)
|
||||
|
|
|
|||
|
|
@ -20,12 +20,6 @@ INSTALLED_APPS = (
|
|||
'tests.testapp',
|
||||
)
|
||||
|
||||
MIDDLEWARE = (
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
)
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
|
||||
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
|
||||
|
|
@ -50,14 +44,3 @@ SECRET_KEY = '123456'
|
|||
|
||||
USE_L10N = True
|
||||
USE_I18N = True
|
||||
|
||||
if os.environ.get('TRAVIS'):
|
||||
CACHES = {
|
||||
"default": {
|
||||
"BACKEND": "django_redis.cache.RedisCache",
|
||||
"LOCATION": "redis://127.0.0.1:6379/1",
|
||||
"OPTIONS": {
|
||||
"CLIENT_CLASS": "django_redis.client.DefaultClient",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
{% load staticfiles %}
|
||||
{% load static %}
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from django.conf.urls import include, url
|
||||
from django.urls import include, path
|
||||
|
||||
from .forms import (
|
||||
AddressChainedSelect2WidgetForm, AlbumModelSelect2WidgetForm,
|
||||
|
|
@ -8,28 +8,28 @@ from .forms import (
|
|||
from .views import TemplateFormView, heavy_data_1, heavy_data_2
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^select2_widget/$',
|
||||
TemplateFormView.as_view(form_class=Select2WidgetForm), name='select2_widget'),
|
||||
url(r'^heavy_select2_widget/$',
|
||||
TemplateFormView.as_view(form_class=HeavySelect2WidgetForm), name='heavy_select2_widget'),
|
||||
url(r'^heavy_select2_multiple_widget/$',
|
||||
TemplateFormView.as_view(form_class=HeavySelect2MultipleWidgetForm, success_url='/'),
|
||||
name='heavy_select2_multiple_widget'),
|
||||
path('select2_widget',
|
||||
TemplateFormView.as_view(form_class=Select2WidgetForm), name='select2_widget'),
|
||||
path('heavy_select2_widget',
|
||||
TemplateFormView.as_view(form_class=HeavySelect2WidgetForm), name='heavy_select2_widget'),
|
||||
path('heavy_select2_multiple_widget',
|
||||
TemplateFormView.as_view(form_class=HeavySelect2MultipleWidgetForm, success_url='/'),
|
||||
name='heavy_select2_multiple_widget'),
|
||||
|
||||
url(r'^model_select2_widget/$',
|
||||
TemplateFormView.as_view(form_class=AlbumModelSelect2WidgetForm),
|
||||
name='model_select2_widget'),
|
||||
path('model_select2_widget',
|
||||
TemplateFormView.as_view(form_class=AlbumModelSelect2WidgetForm),
|
||||
name='model_select2_widget'),
|
||||
|
||||
url(r'^model_select2_tag_widget/$',
|
||||
TemplateFormView.as_view(form_class=ModelSelect2TagWidgetForm),
|
||||
name='model_select2_tag_widget'),
|
||||
path('model_select2_tag_widget',
|
||||
TemplateFormView.as_view(form_class=ModelSelect2TagWidgetForm),
|
||||
name='model_select2_tag_widget'),
|
||||
|
||||
url(r'^model_chained_select2_widget/$',
|
||||
TemplateFormView.as_view(form_class=AddressChainedSelect2WidgetForm),
|
||||
name='model_chained_select2_widget'),
|
||||
path('model_chained_select2_widget',
|
||||
TemplateFormView.as_view(form_class=AddressChainedSelect2WidgetForm),
|
||||
name='model_chained_select2_widget'),
|
||||
|
||||
url(r'^heavy_data_1/$', heavy_data_1, name='heavy_data_1'),
|
||||
url(r'^heavy_data_2/$', heavy_data_2, name='heavy_data_2'),
|
||||
path('heavy_data_1', heavy_data_1, name='heavy_data_1'),
|
||||
path('heavy_data_2', heavy_data_2, name='heavy_data_2'),
|
||||
|
||||
url(r'^select2/', include('django_select2.urls')),
|
||||
path('select2/', include('django_select2.urls')),
|
||||
]
|
||||
|
|
|
|||
33
tox.ini
33
tox.ini
|
|
@ -1,33 +0,0 @@
|
|||
[tox]
|
||||
envlist = py{36}-dj{111,20,master},qa,docs
|
||||
[testenv]
|
||||
setenv=
|
||||
PYTHONPATH = {toxinidir}
|
||||
passenv=CI
|
||||
deps=
|
||||
-rrequirements-dev.txt
|
||||
dj111: https://github.com/django/django/archive/stable/1.11.x.tar.gz#egg=django
|
||||
dj20: https://github.com/django/django/archive/stable/2.0.x.tar.gz#egg=django
|
||||
djmaster: https://github.com/django/django/archive/master.tar.gz#egg=django
|
||||
commands=
|
||||
coverage run --source=django_select2 -m 'pytest' \
|
||||
--basetemp={envtmpdir} \
|
||||
--ignore=.tox \
|
||||
{posargs}
|
||||
|
||||
[testenv:qa]
|
||||
changedir={toxinidir}
|
||||
deps=
|
||||
-rrequirements-dev.txt
|
||||
commands=
|
||||
isort --check-only --recursive --diff {posargs}
|
||||
flake8 --jobs=2 {posargs}
|
||||
pydocstyle --verbose --explain --source --count {posargs}
|
||||
|
||||
[testenv:docs]
|
||||
whitelist_externals=make
|
||||
changedir={toxinidir}/docs
|
||||
deps=
|
||||
-rrequirements-dev.txt
|
||||
https://github.com/django/django/archive/stable/1.11.x.tar.gz#egg=django
|
||||
commands=make spelling
|
||||
Loading…
Reference in a new issue