Skip to content

Commit ce7c826

Browse files
authored
Merge pull request #28 from 101t/4.0.0
code refactor, re-design django-aio, bug fixes, adding swagger, READM…
2 parents 44fd0b3 + 04e6048 commit ce7c826

File tree

495 files changed

+661
-29362
lines changed

Some content is hidden

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

495 files changed

+661
-29362
lines changed

.dockerignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
cache/
17+
logs/
18+
public/
19+
docker-compose.yml

.gitignore

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,12 @@ staticfiles
5858
# virtual environments
5959
.env
6060
env/
61+
venv/
6162
db.sqlite3
6263

63-
# User-uploaded media
64-
lms/media/
65-
6664
# Hitch directory
6765
tests/.hitch
6866

69-
# Docker Compose
70-
/docker-compose.yml
71-
7267
#sunucudaki static ve medya ve dosyalarının konumu
7368
/public/*
7469

@@ -81,3 +76,4 @@ celerybeat.pid
8176
# IDE Settings
8277
.vscode/
8378
.idea/
79+
cache/

.travis.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@ cache:
1313
language: python
1414

1515
python:
16-
- "3.6"
16+
- "3.8"
17+
- "3.9"
18+
- "3.10"
19+
- "3.11"
20+
- "3.12"
1721
install:
1822
- pip install -r requirements.txt
1923
script:
20-
- cp -rf Sample.env .env
21-
- python manage.py reseter && python manage.py makemigrations && python manage.py migrate && python manage.py load_new
24+
- cp sample.env .env
25+
- python manage.py migrate
26+
- python manage.py load_new
27+
- python manage.py runserver 0.0.0.0:8000

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: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,27 @@ 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
3738

3839
In your terminal for **Unix** (Linux/Mac)
3940

40-
```sh
41+
```shell
4142
pip install virtualenv
4243

4344
git clone https://github.com/101t/django-aio --depth 1
@@ -50,14 +51,18 @@ 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 migrate
57+
58+
python manage.py load_new
59+
60+
python manage.py runserver
5661
```
5762

5863
In Command Prompt for **Windows**
5964

60-
```sh
65+
```shell
6166
python -m pip install virtualenv
6267

6368
git clone https://github.com/101t/django-aio --depth 1
@@ -70,15 +75,19 @@ env/Scripts/activate
7075

7176
pip install -r requirements.txt
7277

73-
copy Sample.env .env
78+
copy sample.env .env
79+
80+
python manage.py migrate
7481

75-
load_data_win.bat --init
82+
python manage.py load_new
83+
84+
python manage.py runserver
7685
```
7786

7887
Or using as new project templates
7988

80-
```sh
81-
django-admin.py startproject --template=https://github.com/101t/django-aio/archive/latest.zip --extension=py,gitignore PROJECT_NAME
89+
```shell
90+
django-admin.py startproject --template=https://github.com/101t/django-aio/archive/latest.zip --extension=py,gitignore YOUR_PROJECT_NAME
8291
```
8392

8493
> Note: the `admin` user automatically added to project as default administrator user, the credentials authentication is **Username: `admin`, Password: `secret`**.
@@ -89,7 +98,7 @@ django-admin.py startproject --template=https://github.com/101t/django-aio/archi
8998

9099
Adding translation made easy by this commands
91100

92-
```sh
101+
```shell
93102
cd django-aio/main/
94103

95104
django-admin makemessages -l en
@@ -98,42 +107,25 @@ django-admin compilemessages
98107
```
99108
> Note: make sure you have `gettext` installed in your `Unix` Environment
100109
101-
```sh
110+
```shell
102111
# using gettext in ubuntu or macOS
103112
msgunfmt [django.mo] > [django.po]
104113
```
105114

106115
### Run Celery
107116

108117
To run your celery in development
109-
```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
118+
```shell
119+
make run_celery
117120
```
118121

119122
### Run Django
120123
To run django in development as `HTTP`
121-
```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
124+
```shell
125+
make run
134126
```
135-
> Note: be careful about sub-packages compatibility and dependencies conflict while **upgrading**
136127

137128
## Conclusion
138129

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.
130+
The `django-aio` [Django All-in-One] repository is the result of years of development to starts from the middle of project-life.
131+
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)