Skip to content

Commit 35a4a20

Browse files
committed
first commit
0 parents  commit 35a4a20

File tree

12 files changed

+466
-0
lines changed

12 files changed

+466
-0
lines changed

Diff for: .github/dependabot.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"
7+
target-branch: "main"
8+
9+
- package-ecosystem: "pip"
10+
directory: "/"
11+
schedule:
12+
interval: "daily"
13+
target-branch: "main"

Diff for: .github/workflows/workflow.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: CI/CD Pipeline
2+
3+
on:
4+
push:
5+
pull_request:
6+
release:
7+
types: [published]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
run-linter:
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
matrix:
18+
python-version: [3.11, 3.12]
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
24+
- name: Run linter on Python ${{ matrix.python-version }}
25+
uses: chartboost/ruff-action@v1
26+
27+
publish-to-pypi:
28+
needs: run-linter
29+
if: github.event_name == 'release' && github.event.action == 'published'
30+
runs-on: ubuntu-latest
31+
32+
environment: release
33+
34+
permissions:
35+
id-token: write
36+
37+
strategy:
38+
matrix:
39+
python-version: [3.12]
40+
41+
steps:
42+
- name: Checkout repository
43+
uses: actions/checkout@v4
44+
45+
- name: Set up Python ${{ matrix.python-version }}
46+
uses: actions/setup-python@v5
47+
with:
48+
python-version: ${{ matrix.python-version }}
49+
50+
- name: Install dependencies
51+
run: |
52+
python -m pip install --upgrade pip
53+
pip install build
54+
55+
- name: Build package
56+
run: python -m build
57+
58+
- name: Publish package
59+
uses: pypa/gh-action-pypi-publish@release/v1.8

Diff for: .gitignore

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
# Custom
2+
.DS_Store
3+
4+
# Byte-compiled / optimized / DLL files
5+
__pycache__/
6+
*.py[cod]
7+
*$py.class
8+
9+
# C extensions
10+
*.so
11+
12+
# Distribution / packaging
13+
.Python
14+
build/
15+
develop-eggs/
16+
dist/
17+
downloads/
18+
eggs/
19+
.eggs/
20+
lib/
21+
lib64/
22+
parts/
23+
sdist/
24+
var/
25+
wheels/
26+
share/python-wheels/
27+
*.egg-info/
28+
.installed.cfg
29+
*.egg
30+
MANIFEST
31+
32+
# PyInstaller
33+
# Usually these files are written by a python script from a template
34+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
35+
*.manifest
36+
*.spec
37+
38+
# Installer logs
39+
pip-log.txt
40+
pip-delete-this-directory.txt
41+
42+
# Unit test / coverage reports
43+
htmlcov/
44+
.tox/
45+
.nox/
46+
.coverage
47+
.coverage.*
48+
.cache
49+
nosetests.xml
50+
coverage.xml
51+
*.cover
52+
*.py,cover
53+
.hypothesis/
54+
.pytest_cache/
55+
cover/
56+
57+
# Translations
58+
*.mo
59+
*.pot
60+
61+
# Django stuff:
62+
*.log
63+
local_settings.py
64+
db.sqlite3
65+
db.sqlite3-journal
66+
67+
# Flask stuff:
68+
instance/
69+
.webassets-cache
70+
71+
# Scrapy stuff:
72+
.scrapy
73+
74+
# Sphinx documentation
75+
docs/_build/
76+
77+
# PyBuilder
78+
.pybuilder/
79+
target/
80+
81+
# Jupyter Notebook
82+
.ipynb_checkpoints
83+
84+
# IPython
85+
profile_default/
86+
ipython_config.py
87+
88+
# pyenv
89+
# For a library or package, you might want to ignore these files since the code is
90+
# intended to run in multiple environments; otherwise, check them in:
91+
# .python-version
92+
93+
# pipenv
94+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
95+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
96+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
97+
# install all needed dependencies.
98+
#Pipfile.lock
99+
100+
# poetry
101+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
102+
# This is especially recommended for binary packages to ensure reproducibility, and is more
103+
# commonly ignored for libraries.
104+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
105+
#poetry.lock
106+
107+
# pdm
108+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
109+
#pdm.lock
110+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
111+
# in version control.
112+
# https://pdm.fming.dev/#use-with-ide
113+
.pdm.toml
114+
115+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
116+
__pypackages__/
117+
118+
# Celery stuff
119+
celerybeat-schedule
120+
celerybeat.pid
121+
122+
# SageMath parsed files
123+
*.sage.py
124+
125+
# Environments
126+
.env
127+
.venv
128+
env/
129+
venv/
130+
ENV/
131+
env.bak/
132+
venv.bak/
133+
134+
# Spyder project settings
135+
.spyderproject
136+
.spyproject
137+
138+
# Rope project settings
139+
.ropeproject
140+
141+
# mkdocs documentation
142+
/site
143+
144+
# mypy
145+
.mypy_cache/
146+
.dmypy.json
147+
dmypy.json
148+
149+
# Pyre type checker
150+
.pyre/
151+
152+
# pytype static type analyzer
153+
.pytype/
154+
155+
# Cython debug symbols
156+
cython_debug/
157+
158+
# PyCharm
159+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
160+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
161+
# and can be added to the global gitignore or merged into this file. For a more nuclear
162+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
163+
#.idea/

Diff for: .pre-commit-config.yaml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
default_language_version:
2+
python: python3.12
3+
4+
repos:
5+
- repo: https://github.com/pre-commit/pre-commit-hooks
6+
rev: v4.6.0
7+
hooks:
8+
- id: check-toml
9+
- id: check-yaml
10+
- id: requirements-txt-fixer
11+
12+
- repo: https://github.com/asottile/pyupgrade
13+
rev: v3.16.0
14+
hooks:
15+
- id: pyupgrade
16+
17+
- repo: https://github.com/astral-sh/ruff-pre-commit
18+
rev: v0.5.0
19+
hooks:
20+
- id: ruff
21+
args: [--fix]
22+
- id: ruff-format
23+
24+
- repo: https://github.com/astral-sh/uv-pre-commit
25+
rev: 0.2.13
26+
hooks:
27+
- id: pip-compile
28+
args: [requirements.in, -o, requirements.txt]

Diff for: CONTRIBUTING.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Contributing
2+
This project welcomes contributions from the community. Contributions are accepted using GitHub pull requests.

Diff for: LICENSE

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
The MIT License (MIT)
2+
Copyright © 2024 Stefano Fusai
3+
4+
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:
5+
6+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
8+
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.

Diff for: README.md

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# drf-haystack-search-filter
2+
3+
A simple package to implement a [django-haystack](https://github.com/django-haystack/django-haystack) search filter in Django Rest Framework.
4+
5+
## Installation
6+
7+
```bash
8+
pip install drf-haystack-search-filter
9+
```
10+
11+
## Usage
12+
13+
Simply import the `HaystackSearchFilter` and use it in your API views:
14+
15+
```python
16+
from drf_haystack_search_filter.filters import HaystackSearchFilter
17+
18+
...
19+
20+
class MyAPIView(...):
21+
...
22+
filter_backends = [HaystackSearchFilter, ...]
23+
...
24+
```
25+
26+
You can customize the search behavior by overriding the `_search` method.
27+
28+
```python
29+
from drf_haystack_search_filter.filters import HaystackSearchFilter
30+
31+
class MyHaystackSearchFilter(HaystackSearchFilter):
32+
def _search(self, request: Request, queryset: QuerySet[T], view: APIView, query: str) -> QuerySet[T]:
33+
# Customize the search behavior here
34+
return queryset.filter(
35+
pk__in=(
36+
SearchQuerySet()
37+
.models(queryset.model)
38+
.filter(content__startswith=query)
39+
.values_list("pk", flat=True)
40+
)
41+
)
42+
43+
class MyAPIView(...):
44+
...
45+
filter_backends = [MyHaystackSearchFilter, ...]
46+
...
47+
```
48+
49+
## Contributing
50+
51+
Contributions are welcome! To get started, please refer to our [contribution guidelines](https://github.com/stefanofusai/drf-haystack-search-filter/blob/main/CONTRIBUTING.md).
52+
53+
## Issues
54+
55+
If you encounter any problems while using this package, please open a new issue [here](https://github.com/stefanofusai/drf-haystack-search-filter/issues).

0 commit comments

Comments
 (0)