Skip to content

Commit 7d7a9e0

Browse files
committed
code refactor, re-design django-aio, bug fixes, adding swagger, README.md updated
1 parent 44fd0b3 commit 7d7a9e0

File tree

493 files changed

+570
-29347
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

493 files changed

+570
-29347
lines changed

.dockerignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.git/
2+
.gitignore
3+
.gitattributes
4+
.vscode/
5+
.github/
6+
.env
7+
.travis.yml
8+
Dockerfile
9+
10+
.cache
11+
*.md
12+
!README*.md
13+
env/
14+
venv/
15+
16+
logs/
17+
public/
18+
docker-compose.yml

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ python:
1717
install:
1818
- pip install -r requirements.txt
1919
script:
20-
- cp -rf Sample.env .env
20+
- cp -rf sample.env .env
2121
- python manage.py reseter && python manage.py makemigrations && python manage.py migrate && python manage.py load_new

Dockerfile

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
FROM python:3.11-slim
2+
3+
# disable debian interactive
4+
ENV DEBIAN_FRONTEND noninteractive
5+
ENV PIP_NO_CACHE_DIR 1
6+
ENV PYTHONUNBUFFERED 1
7+
8+
ENV APP_DIR /app
9+
ENV APP_USER app
10+
11+
RUN apt-get update && apt-get -y upgrade
12+
13+
RUN apt-get install --no-install-recommends -y \
14+
python3-dev python3-wheel python3-setuptools virtualenv \
15+
build-essential nano gcc curl \
16+
libpq-dev libpq5 telnet \
17+
libjemalloc2
18+
19+
RUN apt-get clean autoclean && apt-get autoremove -y && \
20+
rm -rf /var/lib/{apt,dpkg,cache,log}/
21+
22+
ENV LD_PRELOAD /usr/lib/x86_64-linux-gnu/libjemalloc.so.2
23+
24+
RUN useradd -m -d ${APP_DIR} -U -r -s /bin/bash ${APP_USER}
25+
26+
USER ${APP_USER}
27+
28+
WORKDIR ${APP_DIR}
29+
30+
RUN python -m venv /app/env
31+
32+
ENV PATH="$APP_DIR/env/bin:$PATH"
33+
34+
RUN mkdir media static logs
35+
36+
COPY requirements.txt .
37+
38+
RUN pip install -U pip wheel
39+
40+
RUN pip install -r requirements.txt
41+
42+
COPY --chown=$APP_USER . .
43+
44+
ENV PYTHONPATH "${PYTHONPATH}:/app"
45+
46+
RUN chmod +x entrypoint.sh
47+
RUN chmod +x entrypoint-celery.sh
48+
49+
RUN chown -R app: $APP_DIR
50+
51+
ENTRYPOINT ["bash", "entrypoint.sh"]

Makefile

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Variables definitions
2+
# -----------------------------------------------------------------------------
3+
4+
TIMEOUT ?= 60
5+
6+
# Determine the OS platform (Windows or Linux)
7+
ifeq ($(OS),Windows_NT)
8+
SHELL := cmd.exe
9+
RM := del /Q
10+
EXE := .exe
11+
else
12+
SHELL := /bin/bash
13+
RM := rm -rf
14+
EXE :=
15+
endif
16+
17+
18+
# Target section and Global definitions
19+
# -----------------------------------------------------------------------------
20+
.PHONY: all clean test install run deploy down
21+
22+
all: clean test install run deploy down
23+
24+
test:
25+
python -m pytest tests -vv --show-capture=all
26+
27+
install: generate_dot_env
28+
pip install --upgrade pip wheel
29+
pip install -r requirements.txt
30+
31+
run:
32+
PYTHONPATH=. python manage.py runserver 0.0.0.0:8000
33+
34+
run_uvicorn:
35+
PYTHONPATH=. uvicorn config.asgi:application --reload --host 0.0.0.0 --port 8000
36+
37+
run_celery:
38+
PYTHONPATH=. celery -A config worker --max-tasks-per-child 1 -l info
39+
40+
run_channels:
41+
PYTHONPATH=. daphne config.asgi:application -b 0.0.0.0 -p 9000
42+
43+
run_docker: generate_dot_env
44+
docker-compose build
45+
docker-compose up
46+
47+
generate_dot_env:
48+
@if [ ! -e .env ]; then \
49+
cp sample.env .env; \
50+
fi
51+
52+
make_migrations:
53+
python manage.py makemigrations
54+
55+
migrate:
56+
python manage.py migrate
57+
58+
clean:
59+
$(RM) *.pyc
60+
$(RM) -r __pycache__
61+
$(RM) Thumbs.db
62+
$(RM) *~
63+
$(RM) .cache
64+
$(RM) build
65+
$(RM) dist
66+
$(RM) *.egg-info
67+
$(RM) htmlcov
68+
$(RM) .tox/
69+
$(RM) -r docs/_build
70+
$(RM) .env
71+

README.md

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,20 @@ All in one pre-configured and prepared as django project, your project will be r
1818
3. Channels
1919
4. Postgres
2020
5. Redis
21-
6. DRF (Django REST Framework)
21+
6. DRF (Django REST Framework, Swagger, JWT)
2222

23-
Also has some features customization:
23+
Also has some features' customization:
2424

2525
1. Custom User
2626
2. Custom sending Mail
2727
3. Sending Notification via channels
28-
4. loggin everything in the system
28+
4. login everything in the system
2929
5. custom sample data loader `python manage.py load_new` and migrations reseter `python manage.py reseter`
3030
6. custom utils functions
3131
7. easy to deployments
3232
8. easy to translate
33-
9. seperating `config/` for configurations and `main/` for all `apps`, `static`, `templates`
33+
9. separating `config/` for configurations and `main/` for all `apps`, `static`, `templates`
34+
10. Pre-configured API using JWT authentication and swagger-ui
3435

3536

3637
## Getting Started
@@ -50,9 +51,9 @@ source env/bin/activate
5051

5152
pip install -r requirements.txt
5253

53-
cp -rf Sample.env .env
54+
cp sample.env .env
5455

55-
./load_data.sh --init
56+
python manage.py runserver
5657
```
5758

5859
In Command Prompt for **Windows**
@@ -70,15 +71,15 @@ env/Scripts/activate
7071

7172
pip install -r requirements.txt
7273

73-
copy Sample.env .env
74+
copy sample.env .env
7475

75-
load_data_win.bat --init
76+
python manage.py runserver
7677
```
7778

7879
Or using as new project templates
7980

8081
```sh
81-
django-admin.py startproject --template=https://github.com/101t/django-aio/archive/latest.zip --extension=py,gitignore PROJECT_NAME
82+
django-admin.py startproject --template=https://github.com/101t/django-aio/archive/latest.zip --extension=py,gitignore YOUR_PROJECT_NAME
8283
```
8384

8485
> Note: the `admin` user automatically added to project as default administrator user, the credentials authentication is **Username: `admin`, Password: `secret`**.
@@ -107,33 +108,16 @@ msgunfmt [django.mo] > [django.po]
107108

108109
To run your celery in development
109110
```sh
110-
celery worker -A main.taskapp -l debug
111-
```
112-
113-
### Run Channels
114-
To run channels in development as `ASGI` using `daphne`
115-
```sh
116-
daphne config.asgi:application -b 0.0.0.0 -p 9000
111+
make run_celery
117112
```
118113

119114
### Run Django
120115
To run django in development as `HTTP`
121116
```sh
122-
python manage.py runserver 0.0.0.0:8000
123-
```
124-
125-
### Upgrading Packages
126-
127-
Here the following examples how to upgrade some packages
128-
129-
```sh
130-
pip install -U django
131-
pip install -U channels
132-
pip install -U celery
133-
pip install -U djangorestframework markdown django-filter
117+
make run
134118
```
135-
> Note: be careful about sub-packages compatibility and dependencies conflict while **upgrading**
136119

137120
## Conclusion
138121

139-
The `django-aio` [Django All-in-One] repository is the result of team collaboration with developing a big web application. It's designed to make quick-starting for the pre-defined installed packages with all nice features to make sure the implementation initialized, these efforts represent predefined goals and base templates for django frameworks and its beautiful 3rd-party packages.
122+
The `django-aio` [Django All-in-One] repository is the result of years of development to starts from the middle of project-life.
123+
The repository represent predefined goals and base templates for django frameworks and its beautiful 3rd-party packages.

celery_run.sh

Lines changed: 0 additions & 1 deletion
This file was deleted.

config/celery.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import os
2+
3+
from celery import Celery
4+
from celery.utils.log import get_task_logger
5+
from django.conf import settings
6+
7+
logger = get_task_logger(__name__)
8+
9+
__all__ = ['app', 'debug_task', 'revoke_task', 'clear_tasks']
10+
11+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.dev")
12+
13+
app = Celery(
14+
'main',
15+
backend=settings.REDIS_URI,
16+
broker=settings.REDIS_URI,
17+
)
18+
app.config_from_object('django.conf:settings', namespace='CELERY')
19+
app.conf.broker_connection_retry_on_startup = True
20+
21+
CELERY_TIMEZONE = settings.TIME_ZONE
22+
CELERY_ENABLE_UTC = bool(os.environ.get('CELERY_ENABLE_UTC', default=False))
23+
24+
25+
@app.task(bind=True)
26+
def debug_task(self):
27+
logger.info('Request: {0!r}'.format(self.request)) # pragma: no cover
28+
29+
30+
def revoke_task(task_id):
31+
app.control.revoke(task_id)
32+
33+
34+
def clear_tasks():
35+
return app.control.purge()

config/constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import os
2+
3+
DEFAULT_RETRY_DELAY = int(os.environ.get('DEFAULT_RETRY_DELAY', default=5)) # 15 seconds
4+
MAX_RETRIES = int(os.environ.get('MAX_RETRIES', default=5))

0 commit comments

Comments
 (0)