Skip to content

Commit ba2297d

Browse files
committed
Release v0.0.3 - CRUD Works, JWT Auth Added
1 parent 920e1a3 commit ba2297d

File tree

10 files changed

+64
-15
lines changed

10 files changed

+64
-15
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## [0.0.3] 2022-10-24
4+
### Improvements
5+
6+
- CRUD Works
7+
- JWT added
8+
39
## [0.0.2] 2022-10-24
410
### Improvements
511

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ Simple tool that **Generates Secure APIs** on top of `DRF` with minimum effort -
1212

1313
<br />
1414

15+
![Django Dynamic API - DRF Interface (open-source tool).](https://user-images.githubusercontent.com/51070104/197181145-f7458df7-23c3-4c14-bcb1-8e168882a104.jpg)
16+
17+
<br />
18+
1519
## How to use it
1620

1721
<br />
@@ -82,10 +86,26 @@ urlpatterns = [
8286

8387
<br />
8488

85-
> **Step #6** - `Use API`
89+
> **Step #6** - `Update routing`, include `DRF` JWT authentication
90+
91+
```python
92+
from django.contrib import admin
93+
from rest_framework.authtoken.views import obtain_auth_token # <-- NEW
94+
95+
urlpatterns = [
96+
path("admin/", admin.site.urls),
97+
path("api/", include("api.urls")), # <-- Added in the previous step
98+
path('login/jwt/', view=obtain_auth_token), # <-- NEW
99+
]
100+
```
101+
102+
<br />
103+
104+
> **Step #7** - `Use API`
86105
87106
If the managed model is `Books`, the API interface is `/api/books/` and all CRUD methods are available.
88107

108+
> Note: for mutating requests, the `JWT Token` is provided by `http://localhost:8000/login/jwt/` route (the user should exist).
89109
90110
<br />
91111

django_dyn_api/admin.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# -*- encoding: utf-8 -*-
2+
"""
3+
Copyright (c) 2019 - present AppSeed.us
4+
"""
5+
16
from django.contrib import admin
27

38
# Register your models here.

django_dyn_api/apps.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
from django.apps import AppConfig
1+
# -*- encoding: utf-8 -*-
2+
"""
3+
Copyright (c) 2019 - present AppSeed.us
4+
"""
25

6+
from django.apps import AppConfig
37

48
class DynApiConfig(AppConfig):
59
default_auto_field = 'django.db.models.BigAutoField'
6-
name = 'apps.dyn_api'
10+
name = 'django_dyn_api'

django_dyn_api/helpers.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Copyright (c) 2019 - present AppSeed.us
44
"""
55

6-
import datetime, sys, inspect
6+
import datetime, sys, inspect, importlib
77

88
from functools import wraps
99

@@ -32,13 +32,14 @@ class Meta:
3232

3333
@staticmethod
3434
def model_name_to_class(name: str):
35-
all_classes = inspect.getmembers(sys.modules[__name__], inspect.isclass)
36-
for cls in all_classes:
37-
if cls[0] == name:
38-
return cls[1]
39-
40-
# we are confident that never returns None
41-
return None
35+
36+
model_name = name.split('.')[-1]
37+
model_import = name.replace('.'+model_name, '')
38+
39+
module = importlib.import_module(model_import)
40+
cls = getattr(module, model_name)
41+
42+
return cls
4243

4344
def check_permission(function):
4445
@wraps(function)

django_dyn_api/models.py

Whitespace-only changes.

django_dyn_api/tests.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# -*- encoding: utf-8 -*-
2+
"""
3+
Copyright (c) 2019 - present AppSeed.us
4+
"""
5+
16
from django.test import TestCase
27

38
# Create your tests here.

django_dyn_api/urls.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# -*- encoding: utf-8 -*-
2+
"""
3+
Copyright (c) 2019 - present AppSeed.us
4+
"""
5+
16
from django.contrib import admin
27
from django.urls import path
38
from .views import DynamicAPI

django_dyn_api/views.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# -*- encoding: utf-8 -*-
2+
"""
3+
Copyright (c) 2019 - present AppSeed.us
4+
"""
5+
16
from django.http import Http404
27

38
from django.contrib.auth.decorators import login_required
@@ -57,7 +62,7 @@ def get(self, request, **kwargs):
5762
'data': output,
5863
'success': True
5964
}, status=200)
60-
65+
6166
# CREATE : POST api/model/
6267
#@check_permission
6368
def post(self, request, **kwargs):
@@ -81,7 +86,6 @@ def post(self, request, **kwargs):
8186
}, status=200)
8287

8388
# UPDATE : PUT api/model/id/
84-
#@method_decorator(login_required, name='dispatch')
8589
#@check_permission
8690
def put(self, request, **kwargs):
8791
try:
@@ -112,7 +116,6 @@ def put(self, request, **kwargs):
112116
}, status=200)
113117

114118
# DELETE : DELETE api/model/id/
115-
#@method_decorator(login_required, name='dispatch')
116119
#@check_permission
117120
def delete(self, request, **kwargs):
118121
try:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setup(
1010
name='django-dynamic-api',
11-
version='0.0.2',
11+
version='0.0.3',
1212
zip_safe=False,
1313
packages=find_packages(),
1414
include_package_data=True,

0 commit comments

Comments
 (0)