Skip to content

Commit 4074c3f

Browse files
committed
Release v0.0.1 - Initial Version
1 parent 8f5b544 commit 4074c3f

File tree

26 files changed

+1497
-1
lines changed

26 files changed

+1497
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Change Log
2+
3+
## [0.0.1] 2022-10-30
4+
### Initial Version
5+
6+
- Codebase design

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 [App Generator](https://appseed.us)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

MANIFEST.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include LICENSE.md
2+
include README.md
3+
recursive-include django_dyn_tb *
4+
recursive-include docs *

README.md

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,100 @@
1-
# django-dynamic-datatb
1+
# [Django Dynamic DataTables](https://github.com/app-generator/django-dynamic-datatb)
2+
3+
Simple tool that **Generates Secure APIs** on top of `DRF` with minimum effort - actively supported by [AppSeed](https://appseed.us/).
4+
5+
<br />
6+
7+
> Features
8+
9+
- `DataTables` provided by `Simple DataTables`
10+
- `Minimal Configuration` (single line in config for each model)
11+
- `Handles any model` defined across the project
12+
13+
<br />
14+
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+
19+
## How to use it
20+
21+
<br />
22+
23+
> **Step #1** - `Install the package`
24+
25+
```bash
26+
$ pip install django-dynamic-datatb
27+
// OR
28+
$ pip install git+https://github.com/app-generator/django-dynamic-datatb.git
29+
```
30+
31+
<br />
32+
33+
> **Step #2** - `Update Configuration`, include the new APPs
34+
35+
```python
36+
INSTALLED_APPS = [
37+
'django_dyn_dt', # Django Dynamic Data tables # <-- NEW
38+
]
39+
```
40+
41+
<br />
42+
43+
> **Step #3** - `Register the model` in `core/settings.py` (DYNAMIC_API section)
44+
45+
This sample code assumes that `app1` exists and model `Book` is defined and migrated.
46+
47+
```python
48+
49+
DYNAMIC_DATATB = {
50+
# SLUG -> Import_PATH
51+
'books' : "app1.models.Book",
52+
}
53+
54+
```
55+
56+
<br />
57+
58+
> **Step #4** - `Migrate DB`
59+
60+
```bash
61+
$ python manage.py makemigrations
62+
$ python manage.py migrate
63+
```
64+
65+
<br />
66+
67+
> **Step #5** - `Update routing`, include APIs
68+
69+
```python
70+
from django.contrib import admin
71+
from django.urls import path, include # <-- NEW: 'include` directive added
72+
73+
urlpatterns = [
74+
path("admin/", admin.site.urls),
75+
path('', include('django_dyn_dt.urls')), # <-- NEW: API routing rules
76+
]
77+
```
78+
79+
<br />
80+
81+
> **Step #7** - Use the Dynamic Datatable module
82+
83+
If the managed model is `Books`, the dynamic interface is `/datatb/books/` and all features available.
84+
85+
<br />
86+
87+
![Django API Generator - POSTMAN Interface (open-source tool).](https://user-images.githubusercontent.com/51070104/197181265-eb648e27-e5cf-4f3c-b330-d000aba53c6a.jpg)
88+
89+
<br />
90+
91+
### Links & resources
92+
93+
- [DRF](https://www.django-rest-framework.org/) - HOMEpage
94+
- More [Developer Tools](https://appseed.us/developer-tools/) provided by `AppSeed`
95+
- Ask for [Support](https://appseed.us/support/) via `Email` & `Discord`
96+
97+
<br />
98+
99+
---
100+
[Django Dynamic DataTables](https://github.com/app-generator/django-dynamic-datatb) - Open-source library provided by **[AppSeed](https://appseed.us/)**

django_dyn_dt/__init__.py

Whitespace-only changes.

django_dyn_dt/admin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

django_dyn_dt/apps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class DynDatatablesConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'apps.dyn_datatables'

django_dyn_dt/helpers.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# -*- encoding: utf-8 -*-
2+
"""
3+
Copyright (c) 2019 - present AppSeed.us
4+
"""
5+
6+
import datetime, sys, inspect, importlib
7+
8+
from functools import wraps
9+
10+
11+
from django.db import models
12+
from rest_framework import serializers
13+
14+
from functools import wraps
15+
16+
from django.http import HttpResponseRedirect, HttpResponse
17+
18+
class Utils:
19+
@staticmethod
20+
def get_class(config, name: str) -> models.Model:
21+
return Utils.model_name_to_class(config[name])
22+
23+
@staticmethod
24+
def get_manager(config, name: str) -> models.Manager:
25+
return Utils.get_class(config, name).objects
26+
27+
@staticmethod
28+
def get_serializer(config, name: str):
29+
class Serializer(serializers.ModelSerializer):
30+
class Meta:
31+
model = Utils.get_class(config, name)
32+
fields = '__all__'
33+
34+
return Serializer
35+
36+
@staticmethod
37+
def model_name_to_class(name: str):
38+
39+
model_name = name.split('.')[-1]
40+
model_import = name.replace('.'+model_name, '')
41+
42+
module = importlib.import_module(model_import)
43+
cls = getattr(module, model_name)
44+
45+
return cls
46+
47+
def check_permission(function):
48+
@wraps(function)
49+
def wrap(viewRequest, *args, **kwargs):
50+
51+
try:
52+
53+
# Check user
54+
if viewRequest.request.user.is_authenticated:
55+
return function(viewRequest, *args, **kwargs)
56+
57+
# All good - allow the processing
58+
return HttpResponseRedirect('/login/')
59+
60+
except Exception as e:
61+
62+
# On error
63+
return HttpResponse( 'Error: ' + str( e ) )
64+
65+
return function(viewRequest, *args, **kwargs)
66+
67+
return wrap

django_dyn_dt/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.db import models
2+
3+
# Create your models here.

django_dyn_dt/templates/404.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>404 not found</title>
6+
7+
<!-- bootstrap5 -->
8+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
9+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
10+
11+
</head>
12+
<body>
13+
<div class="d-flex flex-column text-center vh-100 justify-content-center">
14+
<h1 class="fw-bolder display-1">404</h1>
15+
<h3>
16+
page not found!
17+
</h3>
18+
</div>
19+
</body>
20+
</html>

0 commit comments

Comments
 (0)