Skip to content

Commit

Permalink
Merge pull request #28 from 101t/4.0.0
Browse files Browse the repository at this point in the history
code refactor, re-design django-aio, bug fixes, adding swagger, READM…
  • Loading branch information
101t authored Jan 6, 2024
2 parents 44fd0b3 + 04e6048 commit ce7c826
Show file tree
Hide file tree
Showing 495 changed files with 661 additions and 29,362 deletions.
19 changes: 19 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.git/
.gitignore
.gitattributes
.vscode/
.github/
.env
.travis.yml
Dockerfile

.cache
*.md
!README*.md
env/
venv/

cache/
logs/
public/
docker-compose.yml
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,12 @@ staticfiles
# virtual environments
.env
env/
venv/
db.sqlite3

# User-uploaded media
lms/media/

# Hitch directory
tests/.hitch

# Docker Compose
/docker-compose.yml

#sunucudaki static ve medya ve dosyalarının konumu
/public/*

Expand All @@ -81,3 +76,4 @@ celerybeat.pid
# IDE Settings
.vscode/
.idea/
cache/
12 changes: 9 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ cache:
language: python

python:
- "3.6"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
install:
- pip install -r requirements.txt
script:
- cp -rf Sample.env .env
- python manage.py reseter && python manage.py makemigrations && python manage.py migrate && python manage.py load_new
- cp sample.env .env
- python manage.py migrate
- python manage.py load_new
- python manage.py runserver 0.0.0.0:8000
51 changes: 51 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
FROM python:3.11-slim

# disable debian interactive
ENV DEBIAN_FRONTEND noninteractive
ENV PIP_NO_CACHE_DIR 1
ENV PYTHONUNBUFFERED 1

ENV APP_DIR /app
ENV APP_USER app

RUN apt-get update && apt-get -y upgrade

RUN apt-get install --no-install-recommends -y \
python3-dev python3-wheel python3-setuptools virtualenv \
build-essential nano gcc curl \
libpq-dev libpq5 telnet \
libjemalloc2

RUN apt-get clean autoclean && apt-get autoremove -y && \
rm -rf /var/lib/{apt,dpkg,cache,log}/

ENV LD_PRELOAD /usr/lib/x86_64-linux-gnu/libjemalloc.so.2

RUN useradd -m -d ${APP_DIR} -U -r -s /bin/bash ${APP_USER}

USER ${APP_USER}

WORKDIR ${APP_DIR}

RUN python -m venv /app/env

ENV PATH="$APP_DIR/env/bin:$PATH"

RUN mkdir media static logs

COPY requirements.txt .

RUN pip install -U pip wheel

RUN pip install -r requirements.txt

COPY --chown=$APP_USER . .

ENV PYTHONPATH "${PYTHONPATH}:/app"

RUN chmod +x entrypoint.sh
RUN chmod +x entrypoint-celery.sh

RUN chown -R app: $APP_DIR

ENTRYPOINT ["bash", "entrypoint.sh"]
71 changes: 71 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Variables definitions
# -----------------------------------------------------------------------------

TIMEOUT ?= 60

# Determine the OS platform (Windows or Linux)
ifeq ($(OS),Windows_NT)
SHELL := cmd.exe
RM := del /Q
EXE := .exe
else
SHELL := /bin/bash
RM := rm -rf
EXE :=
endif


# Target section and Global definitions
# -----------------------------------------------------------------------------
.PHONY: all clean test install run deploy down

all: clean test install run deploy down

test:
python -m pytest tests -vv --show-capture=all

install: generate_dot_env
pip install --upgrade pip wheel
pip install -r requirements.txt

run:
PYTHONPATH=. python manage.py runserver 0.0.0.0:8000

run_uvicorn:
PYTHONPATH=. uvicorn config.asgi:application --reload --host 0.0.0.0 --port 8000

run_celery:
PYTHONPATH=. celery -A config worker --max-tasks-per-child 1 -l info

run_channels:
PYTHONPATH=. daphne config.asgi:application -b 0.0.0.0 -p 9000

run_docker: generate_dot_env
docker-compose build
docker-compose up

generate_dot_env:
@if [ ! -e .env ]; then \
cp sample.env .env; \
fi

make_migrations:
python manage.py makemigrations

migrate:
python manage.py migrate

clean:
$(RM) *.pyc
$(RM) -r __pycache__
$(RM) Thumbs.db
$(RM) *~
$(RM) .cache
$(RM) build
$(RM) dist
$(RM) *.egg-info
$(RM) htmlcov
$(RM) .tox/
$(RM) -r docs/_build
$(RM) .env

66 changes: 29 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,27 @@ All in one pre-configured and prepared as django project, your project will be r
3. Channels
4. Postgres
5. Redis
6. DRF (Django REST Framework)
6. DRF (Django REST Framework, Swagger, JWT)

Also has some features customization:
Also has some features' customization:

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


## Getting Started

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

```sh
```shell
pip install virtualenv

git clone https://github.com/101t/django-aio --depth 1
Expand All @@ -50,14 +51,18 @@ source env/bin/activate

pip install -r requirements.txt

cp -rf Sample.env .env
cp sample.env .env

./load_data.sh --init
python manage.py migrate

python manage.py load_new

python manage.py runserver
```

In Command Prompt for **Windows**

```sh
```shell
python -m pip install virtualenv

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

pip install -r requirements.txt

copy Sample.env .env
copy sample.env .env

python manage.py migrate

load_data_win.bat --init
python manage.py load_new

python manage.py runserver
```

Or using as new project templates

```sh
django-admin.py startproject --template=https://github.com/101t/django-aio/archive/latest.zip --extension=py,gitignore PROJECT_NAME
```shell
django-admin.py startproject --template=https://github.com/101t/django-aio/archive/latest.zip --extension=py,gitignore YOUR_PROJECT_NAME
```

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

Adding translation made easy by this commands

```sh
```shell
cd django-aio/main/

django-admin makemessages -l en
Expand All @@ -98,42 +107,25 @@ django-admin compilemessages
```
> Note: make sure you have `gettext` installed in your `Unix` Environment
```sh
```shell
# using gettext in ubuntu or macOS
msgunfmt [django.mo] > [django.po]
```

### Run Celery

To run your celery in development
```sh
celery worker -A main.taskapp -l debug
```

### Run Channels
To run channels in development as `ASGI` using `daphne`
```sh
daphne config.asgi:application -b 0.0.0.0 -p 9000
```shell
make run_celery
```

### Run Django
To run django in development as `HTTP`
```sh
python manage.py runserver 0.0.0.0:8000
```

### Upgrading Packages

Here the following examples how to upgrade some packages

```sh
pip install -U django
pip install -U channels
pip install -U celery
pip install -U djangorestframework markdown django-filter
```shell
make run
```
> Note: be careful about sub-packages compatibility and dependencies conflict while **upgrading**

## Conclusion

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.
The `django-aio` [Django All-in-One] repository is the result of years of development to starts from the middle of project-life.
The repository represent predefined goals and base templates for django frameworks and its beautiful 3rd-party packages.
1 change: 0 additions & 1 deletion celery_run.sh

This file was deleted.

35 changes: 35 additions & 0 deletions config/celery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os

from celery import Celery
from celery.utils.log import get_task_logger
from django.conf import settings

logger = get_task_logger(__name__)

__all__ = ['app', 'debug_task', 'revoke_task', 'clear_tasks']

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.dev")

app = Celery(
'main',
backend=settings.REDIS_URI,
broker=settings.REDIS_URI,
)
app.config_from_object('django.conf:settings', namespace='CELERY')
app.conf.broker_connection_retry_on_startup = True

CELERY_TIMEZONE = settings.TIME_ZONE
CELERY_ENABLE_UTC = bool(os.environ.get('CELERY_ENABLE_UTC', default=False))


@app.task(bind=True)
def debug_task(self):
logger.info('Request: {0!r}'.format(self.request)) # pragma: no cover


def revoke_task(task_id):
app.control.revoke(task_id)


def clear_tasks():
return app.control.purge()
4 changes: 4 additions & 0 deletions config/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import os

DEFAULT_RETRY_DELAY = int(os.environ.get('DEFAULT_RETRY_DELAY', default=5)) # 15 seconds
MAX_RETRIES = int(os.environ.get('MAX_RETRIES', default=5))
Loading

0 comments on commit ce7c826

Please sign in to comment.