Skip to content

Commit

Permalink
Merge branch 'structure'
Browse files Browse the repository at this point in the history
  • Loading branch information
Flaiers committed Oct 24, 2021
2 parents e15e1a3 + 085f86e commit 0cd2ab0
Show file tree
Hide file tree
Showing 53 changed files with 143 additions and 103 deletions.
8 changes: 3 additions & 5 deletions deployment/example.env
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
SECRET_KEY=z64oc2d-4&_p@*@5pr2pdbq$i69b#jsrn5mzm(1y$!11w&fw&)
SECRET_KEY=**************************************************
DEBUG=True
ALLOWED_HOSTS=*
LANGUAGE_CODE=en-us
TIME_ZONE=Europe/Moscow

APPEND_SLASH=False
USE_I18N=False
USE_L10N=True
DATE_FORMAT=F d, Y
USE_TZ=False

DATA_UPLOAD_MAX_MEMORY_SIZE=251658240
FILE_UPLOAD_MAX_MEMORY_SIZE=251658240

ALPHABET={'а': 'a', 'б': 'b', 'в': 'v', 'г': 'g', 'д': 'd', 'е': 'e', 'ё': 'yo', 'ж': 'zh', 'з': 'z', 'и': 'i', 'й': 'y', 'к': 'k', 'л': 'l', 'м': 'm', 'н': 'n', 'о': 'o', 'п': 'p', 'р': 'r', 'с': 's', 'т': 't', 'у': 'u', 'ф': 'f', 'х': 'kh', 'ц': 'ts', 'ч': 'ch', 'ш': 'sh', 'щ': 'shch', 'ы': 'y', 'э': 'e', 'ю': 'yu', 'я': 'ya'}

DATA_UPLOAD_MAX_MEMORY_SIZE=251658240
FILE_UPLOAD_MAX_MEMORY_SIZE=251658240
LOCAL_DOMAIN=http://localhost:8000
DOMAIN=https://fla.codes
8 changes: 8 additions & 0 deletions deployment/scripts/gunicorn.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

source env/bin/activate
cd src/

python manage.py migrate
python build.py
gunicorn --reload -b 0.0.0.0:${WEB_PORT} -c config/gunicorn.conf.py -k uvicorn.workers.UvicornWorker config.asgi:application
17 changes: 10 additions & 7 deletions deployment/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@ python_interpreter=""
read -p "┌────────────────────┐
| Python interpreter |
└────────────────────┘
Default: /usr/bin/python3
Default: /usr/bin/python
(Сlick Enter for choose default)
If you wont to change, write: " python_interpreter


if [ -z "$python_interpreter" ]; then
/usr/bin/python3 -m venv env
/usr/bin/python -m venv env
else
`$python_interpreter -m venv env`
fi

source env/bin/activate
pip install -U pip && pip install -r src/requirements.txt
cd src/

python src/manage.py collectstatic --noinput
python src/manage.py makemigrations
python src/manage.py migrate
python src/manage.py runserver --insecure
pip install -U pip && pip install -r requirements.txt

python manage.py collectstatic --noinput
python manage.py makemigrations --name alter_db_table
python manage.py migrate
python build.py
python manage.py runserver --insecure
8 changes: 8 additions & 0 deletions deployment/scripts/uvicorn.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

source env/bin/activate
cd src/

python manage.py migrate
python build.py
uvicorn --reload --host 0.0.0.0 --port ${WEB_PORT} config.asgi:application
6 changes: 0 additions & 6 deletions src/api/apps.py

This file was deleted.

File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions src/apps/api/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.apps import AppConfig


class ApiConfig(AppConfig):

name = 'apps.api'
verbose_name = 'API'
4 changes: 2 additions & 2 deletions src/api/views.py → src/apps/api/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from core.models import Article, Storage
from core.forms import ArticleForm, StorageForm
from apps.core.models import Article, Storage
from apps.core.forms import ArticleForm, StorageForm

from django.middleware.csrf import get_token

Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions src/apps/core/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.apps import AppConfig


class CoreConfig(AppConfig):

name = 'apps.core'
verbose_name = 'Core'
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added src/apps/core/static/img/favicon.ico
Binary file not shown.
Binary file added src/apps/core/static/img/favicon1.ico
Binary file not shown.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions src/apps/ext_auth/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.apps import AppConfig


class ExtAuthConfig(AppConfig):

name = 'apps.ext_auth'
verbose_name = 'Authentication and Authorization'
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/ext_auth/views.py → src/apps/ext_auth/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from core.models import Article
from apps.core.models import Article

from .forms import UserCreationForm

Expand Down
29 changes: 29 additions & 0 deletions src/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python
import os

import django

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')

django.setup()


def main():
from django.contrib.auth import get_user_model

'''Create first superuser'''
UserModel = get_user_model()
User = UserModel.objects.filter(username='root')
if User.exists():
print('Root user already exists!')
else:
UserModel.objects.create_superuser(
username='root',
password='root',
email='[email protected]'
)
print('Root user created!')


if __name__ == '__main__':
main()
14 changes: 14 additions & 0 deletions src/config/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env python
import os

import packs

import django


os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')

django.setup()

'''Rename tables in database'''
packs.rename_tables()
6 changes: 6 additions & 0 deletions src/config/gunicorn.conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import os
import signal


def worker_int(worker):
os.kill(worker.pid, signal.SIGINT)
12 changes: 8 additions & 4 deletions src/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

from packs import bool

from pathlib import Path

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))

BASE_DIR = Path(__file__).parent.parent.parent.parent

SECRET_KEY = os.getenv('SECRET_KEY')

Expand All @@ -20,9 +22,11 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'api.apps.ApiConfig',
'core.apps.CoreConfig',
'ext_auth.apps.ExtAuthConfig',

# Your apps
'apps.api.conf.ApiConfig',
'apps.core.conf.CoreConfig',
'apps.ext_auth.conf.ExtAuthConfig'
]

MIDDLEWARE = [
Expand Down
7 changes: 5 additions & 2 deletions src/config/settings/local.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import os

from dotenv import load_dotenv

import os
from pathlib import Path


BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
BASE_DIR = Path(__file__).parent.parent.parent.parent

# reading ./deployment/example.env file
load_dotenv(os.path.join(BASE_DIR, 'deployment', 'example.env'))
Expand Down
16 changes: 9 additions & 7 deletions src/config/settings/production.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from dotenv import load_dotenv

import os

from pathlib import Path

from dotenv import load_dotenv


BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
BASE_DIR = Path(__file__).parent.parent.parent.parent

# reading ./deployment/.env file
load_dotenv(os.path.join(BASE_DIR, 'deployment', '.env'))
Expand All @@ -22,10 +24,10 @@
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.getenv('POSTGRES_DB'),
'USER': os.getenv('POSTGRES_USER'),
'PASSWORD': os.getenv('POSTGRES_PASSWORD'),
'NAME': os.getenv('DB_NAME'),
'USER': os.getenv('DB_USER'),
'PASSWORD': os.getenv('DB_PASSWORD'),
'HOST': os.getenv('HOST'),
'PORT': os.getenv('PORT_DB'),
'PORT': os.getenv('DB_PORT'),
}
}
38 changes: 0 additions & 38 deletions src/core/admin.py

This file was deleted.

6 changes: 0 additions & 6 deletions src/core/apps.py

This file was deleted.

13 changes: 0 additions & 13 deletions src/ext_auth/apps.py

This file was deleted.

2 changes: 0 additions & 2 deletions src/manage.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
try:
from django.core.management import execute_from_command_line
Expand Down
15 changes: 12 additions & 3 deletions src/packs/db.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
def rename_tables():
def rename_tables() -> None:

from django.db.migrations.recorder import MigrationRecorder
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import Group, Permission
from django.contrib.sessions.models import Session
from django.contrib.admin.models import LogEntry


'''Init Migration class'''
MigrationRecorder.Migration()

'''Edit db_table in M2M field Group model'''
Group.permissions.db_table = 'group_permissions'
Group._meta.get_field('permissions').db_table = 'group_permissions'

'''Edit db_table of Group model'''
Group._meta.db_table = 'groups'
Group._meta.original_attrs['db_table'] = 'groups'
Group.permissions.db_table = 'group_permissions'

'''Edit db_table of Permission model'''
Permission._meta.db_table = 'permissions'
Permission._meta.original_attrs['db_table'] = 'permissions'

'''Edit db_table of LogEntry model'''
LogEntry._meta.db_table = 'admin_log'
LogEntry._meta.original_attrs['db_table'] = 'admin_log'

'''Edit db_table of Session model'''
Session._meta.db_table = 'sessions'
Session._meta.original_attrs['db_table'] = 'sessions'

'''Edit db_table of ContentType model'''
ContentType._meta.db_table = 'content_types'
ContentType._meta.original_attrs['db_table'] = 'content_types'

'''Edit db_table of Migration model'''
MigrationRecorder._migration_class._meta.db_table = 'migrations'
MigrationRecorder._migration_class._meta.original_attrs['db_table'] = 'migrations'
8 changes: 4 additions & 4 deletions src/routers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
admin.site.site_title = "Flatype Admin"
admin.site.index_title = "Welcome to Flatype Admin Panel"

handler400 = "core.exceptions.bad_request"
handler403 = "core.exceptions.permission_denied"
handler404 = "core.exceptions.page_not_found"
handler500 = "core.exceptions.server_error"
handler400 = "apps.core.exceptions.bad_request"
handler403 = "apps.core.exceptions.permission_denied"
handler404 = "apps.core.exceptions.page_not_found"
handler500 = "apps.core.exceptions.server_error"

if settings.DEBUG:
from django.conf.urls.static import static
Expand Down
2 changes: 1 addition & 1 deletion src/routers/api_router.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.urls import path

from api import views as views_api
from apps.api import views as views_api


urlpatterns = [
Expand Down
2 changes: 1 addition & 1 deletion src/routers/auth_router.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.urls import path

from ext_auth import views as views_auth
from apps.ext_auth import views as views_auth


urlpatterns = [
Expand Down
2 changes: 1 addition & 1 deletion src/routers/core_router.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.urls import path

from core import views as views_core
from apps.core import views as views_core


urlpatterns = [
Expand Down

0 comments on commit 0cd2ab0

Please sign in to comment.