ReznikovRoman / netflix-admin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Netflix Admin

Netflix admin management panel.

Stack

Django, Postgres, Nginx

Services

Configuration

Docker containers:

  1. server
  2. db

docker-compose files:

  1. docker-compose.yml - for local development.

To run docker containers, you need to create a .env file in the root directory.

.env example:

ENV=.env

# Django
DJANGO_SETTINGS_MODULE=netflix.settings
DJANGO_CONFIGURATION=Local
DJANGO_ADMIN=django-cadmin
DJANGO_SECRET_KEY=change-me
ALLOWED_HOSTS=localhost,127.0.0.1

# Project
NA_PROJECT_BASE_URL=http://localhost:8000

# Media
NA_MEDIA_URL=/media/
NA_STATIC_URL=/staticfiles/

# Postgres
NA_DB_HOST=db
NA_DB_PORT=5432
NA_DB_NAME=
NA_DB_USER=
NA_DB_PASSWORD=

# Scripts
NA_DB_POSTGRES_BATCH_SIZE=500

To run project locally, you need to create local Django settings tb_content/settings/local.py:

import mimetypes
import socket

from .base import Base
from .values import from_environ


class Local(Base):
    DEBUG = True
    ALLOWED_HOSTS = ['*']
    CSRF_TRUSTED_ORIGINS = [
        'http://127.0.0.1:8000',
        'http://localhost:8000',
    ]

    STATIC_URL = "staticfiles/"

    LOG_SQL = from_environ(name='PROJECT_LOG_SQL', type=bool, default=False)

    # debug toolbar
    hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
    INTERNAL_IPS = [ip[: ip.rfind(".")] + ".1" for ip in ips] + ["127.0.0.1", "10.0.2.2"]
    DEBUG_TOOLBAR_CONFIG = {
        "SHOW_TOOLBAR_CALLBACK": lambda show_toolbar: True,
    }
    mimetypes.add_type('application/javascript', '.js', True)

    DEV_INSTALLED_APPS = [
        "debug_toolbar",
    ]
    DEV_MIDDLEWARE = [
        "debug_toolbar.middleware.DebugToolbarMiddleware",
    ]

    Base.INSTALLED_APPS.extend(DEV_INSTALLED_APPS)
    Base.MIDDLEWARE.extend(DEV_MIDDLEWARE)

Start project:

Locally:

docker-compose build
docker-compose up

To fill DB with test data

docker-compose run --rm server bash -c "cd /app/scripts/load_db && python load_data.py"

On startup migrations are applied and static files are collected.

Development

In this project we use django-configurations, therefore for running management commands instead of using ./manage.py / python -m django / django-admin you have to use django-cadmin.

Example: Creating a superuser

django-cadmin createsuperuser

Sync environment with requirements.txt / requirements.dev.txt (will install/update missing packages, remove redundant ones):

make sync-requirements

Compile requirements.*.txt files (have to re-compile after changes in requirements.*.in):

make compile-requirements

Use requirements.local.in for local dependencies; always specify constraints files (-c ...)

Example:

# requirements.local.txt

-c requirements.txt

ipython

Code style:

Before pushing a commit run all linters:

make lint

Documentation

OpenAPI 3 documentation:

  • ${PROJECT_BASE_URL}/api/v1/schema - YAML or JSON, selection via content negotiation with the Accept header
  • ${PROJECT_BASE_URL}/api/v1/schema/redoc - ReDoc
  • ${PROJECT_BASE_URL}/api/v1/schema/swagger - Swagger

About


Languages

Language:Python 93.8%Language:Dockerfile 4.1%Language:Makefile 1.8%Language:Shell 0.2%