Skip to content

Commit 77d1979

Browse files
committed
Added django-ninja support
1 parent ceeb951 commit 77d1979

36 files changed

+873
-813
lines changed

.flake8

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[flake8]
2+
max-line-length = 88
3+
ignore = E203, E241, E501, W503
4+
exclude =
5+
.git,
6+
__pycache__
7+
.history
8+
tests

.github/workflows/publish.yml

+19-35
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,25 @@
1-
name: Publish package
1+
name: Publish
2+
23
on:
34
release:
4-
types: [created]
5+
types: [published]
6+
workflow_dispatch:
57

68
jobs:
7-
deploy:
9+
publish:
810
runs-on: ubuntu-latest
9-
1011
steps:
11-
- uses: actions/checkout@v2
12-
13-
- name: Set up Python
14-
uses: actions/setup-python@v2
15-
with:
16-
python-version: '3.8'
17-
architecture: 'x64'
18-
19-
- name: Install dependencies
20-
run: |
21-
python -m pip install --upgrade pip
22-
pip install setuptools wheel twine
23-
24-
- name: Build source and binary distribution package
25-
run: |
26-
python setup.py sdist bdist_wheel
27-
env:
28-
PACKAGE_VERSION: ${{ github.ref }}
29-
30-
- name: Check distribution package
31-
run: |
32-
twine check dist/*
33-
34-
- name: Publish distribution package
35-
run: |
36-
twine upload dist/*
37-
env:
38-
TWINE_REPOSITORY: ${{ secrets.PYPI_REPOSITORY }}
39-
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
40-
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
41-
TWINE_NON_INTERACTIVE: yes
12+
- uses: actions/checkout@v2
13+
- name: Set up Python
14+
uses: actions/setup-python@v1
15+
with:
16+
python-version: 3.6
17+
- name: Install Flit
18+
run: pip install flit
19+
- name: Install Dependencies
20+
run: flit install --symlink
21+
- name: Publish
22+
env:
23+
FLIT_USERNAME: ${{ secrets.FLIT_USERNAME }}
24+
FLIT_PASSWORD: ${{ secrets.FLIT_PASSWORD }}
25+
run: flit publish

.github/workflows/test.yml

+20-85
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,25 @@
1-
name: Run linter and tests
2-
on: [push, pull_request]
1+
name: Test
2+
3+
on:
4+
push:
5+
branches:
6+
- master
37

48
jobs:
5-
test:
9+
test_coverage:
610
runs-on: ubuntu-latest
7-
strategy:
8-
fail-fast: false
9-
matrix:
10-
python-version:
11-
- "3.5"
12-
- "3.6"
13-
- "3.7"
14-
- "3.8"
15-
- "3.9"
16-
django-version:
17-
- "2.2"
18-
- "3.1"
19-
- "3.2"
20-
drf-version:
21-
- "3.10"
22-
- "3.11"
23-
- "3.12"
24-
exclude:
25-
- python-version: "3.5"
26-
django-version: "3.1"
27-
- python-version: "3.5"
28-
django-version: "3.2"
29-
# DRF 3.10 imports FieldDoesNotExist from django.db.models,
30-
# which has been moved to django.core.exceptions as of Django 3.1
31-
- django-version: "3.1"
32-
drf-version: "3.10"
33-
- django-version: "3.2"
34-
drf-version: "3.10"
3511

3612
steps:
37-
- uses: actions/checkout@v2
38-
39-
- name: Set up Python ${{ matrix.python-version }}
40-
uses: actions/setup-python@v2
41-
with:
42-
python-version: ${{ matrix.python-version }}
43-
44-
- name: Install dependencies
45-
run: |
46-
python -m pip install --upgrade pip
47-
pip install flake8 codecov
48-
49-
- name: Lint with flake8
50-
run: |
51-
# stop the build if there are Python syntax errors or undefined names
52-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
53-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
54-
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
55-
56-
- name: Install Django version
57-
run: |
58-
python -m pip install "Django==${{ matrix.django-version }}.*"
59-
60-
- name: Install DRF version
61-
run: |
62-
python -m pip install "djangorestframework==${{ matrix.drf-version }}.*"
63-
64-
- name: Python, Django and DRF versions
65-
run: |
66-
echo "Python ${{ matrix.python-version }} -> Django ${{ matrix.django-version }} -> DRF ${{ matrix.drf-version }}"
67-
python --version
68-
echo "Django: `django-admin --version`"
69-
echo "DRF: `pip show djangorestframework|grep Version|sed s/Version:\ //`"
70-
71-
- name: Setup environment
72-
run: |
73-
pip install -e .
74-
python setup.py install
75-
76-
- name: Run tests
77-
run: |
78-
# prepare Django project: link all necessary data from the test project into the root directory
79-
# Hint: Simply changing the directory does not work (leads to missing files in coverage report)
80-
ln -s ./tests/test test
81-
ln -s ./tests/manage.py manage.py
82-
ln -s ./tests/settings.py settings.py
83-
ln -s ./tests/urls.py urls.py
84-
85-
# run tests with coverage
86-
coverage run --source='./django_rest_passwordreset' manage.py test
87-
coverage xml
88-
89-
- name: Upload coverage to Codecov
90-
uses: codecov/codecov-action@v1
13+
- uses: actions/checkout@v2
14+
- name: Set up Python
15+
uses: actions/setup-python@v1
16+
with:
17+
python-version: 3.8
18+
- name: Install Flit
19+
run: pip install flit
20+
- name: Install Dependencies
21+
run: flit install --symlink
22+
- name: Test
23+
run: pytest --cov=ninja_jwt --cov-report=xml tests
24+
- name: Coverage
25+
uses: codecov/codecov-action@v1

.github/workflows/test_full.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Full Test
2+
3+
on:
4+
push:
5+
pull_request:
6+
types: [assigned, opened, synchronize, reopened]
7+
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: ['3.6', '3.7', '3.8', '3.9']
15+
django-version: ['<2.1', '<2.2', '<3.0', '<3.1', '<3.2', '<3.3']
16+
17+
steps:
18+
- uses: actions/checkout@v2
19+
- name: Set up Python
20+
uses: actions/setup-python@v1
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
- name: Install core
24+
run: pip install "Django${{ matrix.django-version }}"
25+
- name: Install tests
26+
run: pip install pytest ninja-schema pytest-django django-ninja-extra pyjwt[crypto]
27+
- name: Test
28+
run: pytest
29+
codestyle:
30+
runs-on: ubuntu-latest
31+
32+
steps:
33+
- uses: actions/checkout@v2
34+
- name: Set up Python
35+
uses: actions/setup-python@v1
36+
with:
37+
python-version: 3.9
38+
- name: Install Flit
39+
run: pip install flit
40+
- name: Install Dependencies
41+
run: flit install --symlink
42+
- name: Black
43+
run: black --check django_rest_passwordreset tests
44+
- name: isort
45+
run: isort --check django_rest_passwordreset tests
46+
- name: Flake8
47+
run: flake8 django_rest_passwordreset tests

.isort.cfg

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[settings]
2+
profile = black
3+
combine_as_imports = true

.vscode/launch.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Python: Django",
9+
"type": "python",
10+
"request": "launch",
11+
"program": "${workspaceFolder}/manage.py",
12+
"args": [
13+
"runserver"
14+
],
15+
"django": true,
16+
"justMyCode": false
17+
}
18+
]
19+
}

Makefile

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.PHONY: help docs
2+
.DEFAULT_GOAL := help
3+
4+
help:
5+
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
6+
7+
clean: ## Removing cached python compiled files
8+
find . -name \*pyc | xargs rm -fv
9+
find . -name \*pyo | xargs rm -fv
10+
find . -name \*~ | xargs rm -fv
11+
find . -name __pycache__ | xargs rm -rfv
12+
13+
install: ## Install dependencies
14+
flit install --deps develop --symlink
15+
16+
lint: ## Run code linters
17+
make clean
18+
black --check django_rest_passwordreset tests
19+
isort --check django_rest_passwordreset tests
20+
flake8 django_rest_passwordreset tests
21+
# mypy ninja_jwt
22+
23+
fmt format: ## Run code formatters
24+
make clean
25+
black django_rest_passwordreset tests
26+
isort django_rest_passwordreset tests
27+
28+
test: ## Run tests
29+
make clean
30+
pytest .
31+
32+
test-cov: ## Run tests with coverage
33+
make clean
34+
pytest --cov=django_rest_passwordreset --cov-report term-missing tests

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ This package basically provides two REST endpoints:
1919

2020
1. Install the package from pypi using pip:
2121
```bash
22-
pip install django-rest-passwordreset
22+
pip install django-ninja-passwordreset
2323
```
2424

2525
2. Add ``django_rest_passwordreset`` to your ``INSTALLED_APPS`` (after ``rest_framework``) within your Django settings file:

django_rest_passwordreset/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
""" An extension of django ninja framework, providing a configurable password reset strategy"""
2+
__version__ = "1.0.0"
3+
4+
default_app_config = "django_rest_passwordreset.apps.DjangoRestPasswordResetConfig"

django_rest_passwordreset/admin.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
""" contains basic admin views for MultiToken """
22
from django.contrib import admin
3-
from django_rest_passwordreset.models import ResetPasswordToken
3+
4+
from .models import ResetPasswordToken
45

56

67
@admin.register(ResetPasswordToken)
78
class ResetPasswordTokenAdmin(admin.ModelAdmin):
8-
list_display = ('user', 'key', 'created_at', 'ip_address', 'user_agent')
9+
list_display = ("user", "key", "created_at", "ip_address", "user_agent")

django_rest_passwordreset/apps.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from django.apps import AppConfig
2+
from django.utils.translation import gettext_lazy as _
3+
4+
5+
class DjangoRestPasswordResetConfig(AppConfig):
6+
default_auto_field = "django.db.models.BigAutoField"
7+
name = "django_rest_passwordreset"
8+
verbose_name = _("Django REST PasswordReset")
9+
10+
def ready(self) -> None:
11+
pass

0 commit comments

Comments
 (0)