diff --git a/.codeclimate.yml b/.codeclimate.yml new file mode 100644 index 0000000000000000000000000000000000000000..8256e514f394012a6857e5400930fc388a1fa988 --- /dev/null +++ b/.codeclimate.yml @@ -0,0 +1,11 @@ +plugins: + pep8: + enabled: true + pylint: + enabled: true + plugins: + - django + radon: + enabled: true + sonar-python: + enabled: true diff --git a/.dockerignore b/.dockerignore index e2da498ed43c06a03187e2e60cca613960236080..88751d79e41bac0f66ad35da12ae9796f00c51ee 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,6 @@ -env -*.env -*.sqlite3 -.git* -__pycache__ -*.pyc +env +*.env +*.sqlite3 +.git* +__pycache__ +*.pyc diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000000000000000000000000000000000000..ff267f4daaa1cb28b133b43c5eaece1315b8826e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,24 @@ +# https://editorconfig.org/ + +root = true + +[*] +indent_style = space +indent_size = 4 +insert_final_newline = true +trim_trailing_whitespace = true +end_of_line = lf +charset = utf-8 + +# Docstrings and comments use max_line_length = 79 +[*.py] +max_line_length = 119 + +# The JSON files contain newlines inconsistently +[*.json] +indent_size = 2 +insert_final_newline = ignore + +# Makefiles always use tabs for indentation +[Makefile] +indent_style = tab diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000000000000000000000000000000000..cfa83e4a7a1ff6c008494aa85dd7dfb608b1ca8e --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# https://git-scm.com/docs/gitattributes/#_end_of_line_conversion +* text=auto diff --git a/.gitignore b/.gitignore index db16b2442d90de53fa1ea53a16225d44a51c0eab..c6d0aa2707a4d763a2fe35f2ad9d5df2a738bc45 100644 --- a/.gitignore +++ b/.gitignore @@ -1,126 +1,147 @@ -# Django # -*.log -*.pot -*.pyc -__pycache__ -db.sqlite3 -media - -# Backup files # -*.bak - -# If you are using PyCharm # -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/dictionaries -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.xml -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml -.idea/**/gradle.xml -.idea/**/libraries -*.iws /out/ - -# Python # -*.py[cod] -*$py.class - -# Distribution / packaging -.Python build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -*.egg-info/ -.installed.cfg -*.egg -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.coverage.* -.cache -.pytest_cache/ -nosetests.xml -coverage.xml -*.cover -.hypothesis/ - -# staticfiles -staticfiles/ - -# migrations file -*/migrations/ - -# Jupyter Notebook -.ipynb_checkpoints - -# pyenv -.python-version - -# celery -celerybeat-schedule.* - -# SageMath parsed files -*.sage.py - -# Environments -.env -.db.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ - -# Sublime Text # -*.tmlanguage.cache -*.tmPreferences.cache -*.stTheme.cache -*.sublime-workspace -*.sublime-project - -# sftp configuration file -sftp-config.json - -# Package control specific files Package -Control.last-run -Control.ca-list -Control.ca-bundle -Control.system-ca-bundle -GitHub.sublime-settings - -# Visual Studio Code # -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json -.history - -# misc -.DS_Store + +# Created by https://www.toptal.com/developers/gitignore/api/django +# Edit at https://www.toptal.com/developers/gitignore?templates=django + +### Django ### +*.log +*.pot +*.pyc +__pycache__/ +local_settings.py +db.sqlite3 +db.sqlite3-journal +media + +# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/ +# in your Git repository. Update and uncomment the following line accordingly. +# <django-project-name>/staticfiles/ + +### Django.Python Stack ### +# Byte-compiled / optimized / DLL files +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo + +# Django stuff: + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# End of https://www.toptal.com/developers/gitignore/api/django diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..990179991dc2016be3b002a0f597cb773077af9e --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,81 @@ +include: + - template: Code-Quality.gitlab-ci.yml + - template: SAST.gitlab-ci.yml + - template: Secret-Detection.gitlab-ci.yml + - template: Dependency-Scanning.gitlab-ci.yml + - template: License-Scanning.gitlab-ci.yml + +stages: + - test + - deploy + +code_quality: + tags: + - docker + artifacts: + paths: [gl-code-quality-report.json] + +sast: + tags: + - docker + artifacts: + paths: [gl-sast-report.json] + +django-test: + image: python:3.8.3 + stage: test + variables: + SECRET_KEY: "2c4=+s-cv(@z%vs_zkw*(+juf=)0&j1(0yn^ekap)s+z2jsqt3" + ALLOWED_HOSTS: "*" + DEBUG: 1 + before_script: + - pip install -r requirements.txt + - python manage.py migrate + script: + - coverage run --include='sizakat/*' manage.py test + - coverage report -m + when: on_success + +deploy-development: + image: + name: alpine/git:latest + entrypoint: [""] + stage: deploy + environment: development + variables: + GIT_URL: git@$REMOTE_SERVER:sizakat-5.0-backend.git + before_script: + - mkdir ~/.ssh + - cat "$SSH_KEY" | tr -d '\r' > ~/.ssh/id_rsa + - chmod 600 ~/.ssh/id_rsa + - mv "$KNOWN_HOSTS" ~/.ssh/known_hosts + - chmod 644 ~/.ssh/known_hosts + script: + - git config remote.development.url >&- || git remote add development $GIT_URL + - git checkout $CI_COMMIT_TAG + - git push --force development $CI_COMMIT_TAG 2>&1 | tee git-push.log + - "$(grep -E 'remote: Return with exit [0-9]+' git-push.log | grep -oE 'exit [0-9]+')" + rules: + - if: '$CI_COMMIT_TAG =~ /^development-\d+$/' + +deploy-testing: + image: + name: alpine/git:latest + entrypoint: [""] + stage: deploy + environment: testing + variables: + GIT_URL: git@$REMOTE_SERVER:sizakat-5.0-backend.git + before_script: + - mkdir ~/.ssh + - cat "$SSH_KEY" | tr -d '\r' > ~/.ssh/id_rsa + - chmod 600 ~/.ssh/id_rsa + - mv "$KNOWN_HOSTS" ~/.ssh/known_hosts + - chmod 644 ~/.ssh/known_hosts + script: + - git config remote.testing.url >&- || git remote add testing $GIT_URL + - git checkout $CI_COMMIT_BRANCH + - git push testing $CI_COMMIT_BRANCH 2>&1 | tee git-push.log + - "$(grep -E 'remote: Return with exit [0-9]+' git-push.log | grep -oE 'exit [0-9]+')" + rules: + - if: '$CI_COMMIT_BRANCH == "testing"' diff --git a/Dockerfile b/Dockerfile index 5f08151bd7fd5b11e2496763afc55e0015b13849..59005e65a70c62b7264a69468a2c0fa93f36c744 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,32 +1,32 @@ -FROM python:3.8.3-alpine - -WORKDIR /app/backend - -ENV PYTHONDONTWRITEBYTECODE 1 -ENV PYTHONUNBUFFERED 1 - -COPY ./requirements.txt . - -RUN apk add --no-cache --virtual .build-deps \ - gcc postgresql-dev libpq musl-dev \ - && pip install --upgrade pip \ - && pip install -r requirements.txt \ - && find /usr/local \ - \( -type d -a -name test -o -name tests \) \ - -o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \ - -exec rm -rf '{}' + \ - && runDeps="$( \ - scanelf --needed --nobanner --recursive /usr/local \ - | awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \ - | sort -u \ - | xargs -r apk info --installed \ - | sort -u \ - )" \ - && apk add --virtual .rundeps $runDeps \ - && apk del .build-deps - -COPY ./entrypoint.sh . - -COPY . . - -ENTRYPOINT ["/app/backend/entrypoint.sh"] +FROM python:3.8.3-alpine + +WORKDIR /app/backend + +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 + +COPY ./requirements.txt . + +RUN apk add --no-cache --virtual .build-deps \ + gcc postgresql-dev libpq musl-dev \ + && pip install --upgrade pip \ + && pip install -r requirements.txt \ + && find /usr/local \ + \( -type d -a -name test -o -name tests \) \ + -o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \ + -exec rm -rf '{}' + \ + && runDeps="$( \ + scanelf --needed --nobanner --recursive /usr/local \ + | awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \ + | sort -u \ + | xargs -r apk info --installed \ + | sort -u \ + )" \ + && apk add --virtual .rundeps $runDeps \ + && apk del .build-deps + +COPY ./entrypoint.sh . + +COPY . . + +ENTRYPOINT ["/app/backend/entrypoint.sh"] diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..b9998e87e8c54de0c3e32fe2f0dd3008279f9931 --- /dev/null +++ b/README.md @@ -0,0 +1,57 @@ +## Pipeline status and coverage report + + +[](https://gitlab.cs.ui.ac.id/sizakat/5.0/sizakat-backend/-/commits/master) +[](https://gitlab.cs.ui.ac.id/sizakat/5.0/sizakat-backend/-/commits/master) + +# SiZakat 5.0 + +## Environment + +### Backend environment + +File `.env`: + +``` +SECRET_KEY=foobarbarfoo +ALLOWED_HOSTS=* +DEBUG=1 +SQL_DATABASE=sizakat +SQL_USER=postgres +SQL_PASSWORD=postgres +SQL_HOST=db +SQL_PORT=5432 +BACKEND_PORT=8000 +``` + +- `SECRET_KEY` + + https://docs.djangoproject.com/en/3.0/ref/settings/#std:setting-SECRET_KEY + +- `ALLOWED_HOSTS` + + https://docs.djangoproject.com/en/3.0/ref/settings/#std:setting-ALLOWED_HOSTS + +- `DEBUG` + + https://docs.djangoproject.com/en/3.0/ref/settings/#debug + +- `SQL_*` + + Pengaturan untuk database + +- `BACKEND_PORT` + + Port untuk service backend. Digunakan dalam `docker-compose` + +### Database environment + +File `.db.env` + +``` +POSTGRES_DB=sizakat +POSTGRES_USER=postgres +POSTGRES_PASSWORD=postgres +``` + +https://github.com/docker-library/docs/tree/master/postgres#environment-variables diff --git a/docker-compose.yml b/docker-compose.yml index 5c4e1107bba428a4c4a7b3496315c98eb183bbb2..baffad9a59d890b955f5ad70001914e0a5fbed06 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,24 +1,24 @@ -version: '3.7' - -services: - backend: - build: - context: ./ - command: python manage.py runserver 0.0.0.0:8000 - volumes: - - ./:/app/backend/ - ports: - - 8000:8000 - env_file: - - .env - depends_on: - - db - db: - image: postgres:12.0-alpine - volumes: - - postgres_data:/var/lib/postgresql/data/ - env_file: - - .db.env - -volumes: - postgres_data: +version: '3.7' + +services: + backend: + build: + context: ./ + command: gunicorn sizakat.wsgi --bind 0.0.0.0:8000 --log-file - + volumes: + - ./:/app/backend/ + ports: + - ${BACKEND_PORT:-8000}:8000 + env_file: + - .env + depends_on: + - db + db: + image: postgres:12.0-alpine + volumes: + - postgres_data:/var/lib/postgresql/data/ + env_file: + - .db.env + +volumes: + postgres_data: diff --git a/entrypoint.sh b/entrypoint.sh old mode 100644 new mode 100755 diff --git a/manage.py b/manage.py index 9120de3a8437ba1583088b87309710cf51213c17..293440199f7cdbb0871b502d1f0ff2a7bccf6fb8 100644 --- a/manage.py +++ b/manage.py @@ -1,21 +1,21 @@ -#!/usr/bin/env python -"""Django's command-line utility for administrative tasks.""" -import os -import sys - - -def main(): - os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sizakat.settings') - try: - from django.core.management import execute_from_command_line - except ImportError as exc: - raise ImportError( - "Couldn't import Django. Are you sure it's installed and " - "available on your PYTHONPATH environment variable? Did you " - "forget to activate a virtual environment?" - ) from exc - execute_from_command_line(sys.argv) - - -if __name__ == '__main__': - main() +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sizakat.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/requirements.txt b/requirements.txt index 74a30fa9ec638a5a792a935cc24811b2c7311295..cb089eea7d140094d61e6c9a7f63484a036cadea 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,10 @@ -asgiref==3.2.10 -Django==3.0.7 -django-cors-headers==3.4.0 -django-graphql-jwt==0.3.1 -graphene-django==2.10.1 -gunicorn==20.0.4 -psycopg2-binary==2.8.5 -pytz==2020.1 -sqlparse==0.3.1 +asgiref==3.2.10 +coverage==5.2.1 +Django==3.0.7 +django-cors-headers==3.4.0 +django-graphql-jwt==0.3.1 +graphene-django==2.10.1 +gunicorn==20.0.4 +psycopg2-binary==2.8.5 +pytz==2020.1 +sqlparse==0.3.1 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000000000000000000000000000000000000..d1d714659d755e3919a9aadb79cd487f8e063e43 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[pep8] +max-line-length = 119 diff --git a/sizakat/apps/mustahik/admin.py b/sizakat/apps/mustahik/admin.py index ea5d68b7c457cb7f92da9c00a5c4df77ace36cef..8c38f3f3dad51e4585f3984282c2a4bec5349c1e 100644 --- a/sizakat/apps/mustahik/admin.py +++ b/sizakat/apps/mustahik/admin.py @@ -1,3 +1,3 @@ -from django.contrib import admin - -# Register your models here. +from django.contrib import admin + +# Register your models here. diff --git a/sizakat/apps/mustahik/apps.py b/sizakat/apps/mustahik/apps.py index 90871a259e79c35f0b2271a7a339e5d56e51d0fe..8e809cc4b53e07504047bcea882376434cc1c85c 100644 --- a/sizakat/apps/mustahik/apps.py +++ b/sizakat/apps/mustahik/apps.py @@ -1,5 +1,5 @@ -from django.apps import AppConfig - - -class MustahikConfig(AppConfig): - name = 'mustahik' +from django.apps import AppConfig + + +class MustahikConfig(AppConfig): + name = 'mustahik' diff --git a/sizakat/apps/mustahik/models.py b/sizakat/apps/mustahik/models.py index fd18c6eac0dc9ffbdf025c31d136901350a0d9f2..71a836239075aa6e6e4ecb700e9c42c95c022d91 100644 --- a/sizakat/apps/mustahik/models.py +++ b/sizakat/apps/mustahik/models.py @@ -1,3 +1,3 @@ -from django.db import models - -# Create your models here. +from django.db import models + +# Create your models here. diff --git a/sizakat/apps/mustahik/tests.py b/sizakat/apps/mustahik/tests.py index de8bdc00eb2fed53494a534d48e400faa830dbd9..7ce503c2dd97ba78597f6ff6e4393132753573f6 100644 --- a/sizakat/apps/mustahik/tests.py +++ b/sizakat/apps/mustahik/tests.py @@ -1,3 +1,3 @@ -from django.test import TestCase - -# Create your tests here. +from django.test import TestCase + +# Create your tests here. diff --git a/sizakat/asgi.py b/sizakat/asgi.py index e4c84f3b9ede5b7f4a20b4e09e68b7e2424240be..8b9a3a3b822cedc45be7584a79267bedc3962bb0 100644 --- a/sizakat/asgi.py +++ b/sizakat/asgi.py @@ -1,16 +1,16 @@ -""" -ASGI config for sizakat project. - -It exposes the ASGI callable as a module-level variable named ``application``. - -For more information on this file, see -https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/ -""" - -import os - -from django.core.asgi import get_asgi_application - -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sizakat.settings') - -application = get_asgi_application() +""" +ASGI config for sizakat project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sizakat.settings') + +application = get_asgi_application() diff --git a/sizakat/schema.py b/sizakat/schema.py index 642be04a63219408e9b23e2ab268024605ada912..46be0c12efda14711befbb68458b0b6a5a68e15c 100644 --- a/sizakat/schema.py +++ b/sizakat/schema.py @@ -1,14 +1,14 @@ -from graphene_django import DjangoObjectType -import graphene - -ABOUT = 'Si Zakat merupakan sistem informasi untuk membantu masjid dalam \ -mengelola transaksi zakat. Sistem ini dibuat oleh tim lab 1231, \ -yang dipimpin oleh Prof. Dr. Wisnu Jatmiko.' - -class Query(graphene.ObjectType): - about = graphene.String() - - def resolve_about(self, info): - return ABOUT - -schema = graphene.Schema(query=Query) +from graphene_django import DjangoObjectType +import graphene + +ABOUT = 'Si Zakat merupakan sistem informasi untuk membantu masjid dalam \ +mengelola transaksi zakat. Sistem ini dibuat oleh tim lab 1231, \ +yang dipimpin oleh Prof. Dr. Wisnu Jatmiko.' + +class Query(graphene.ObjectType): + about = graphene.String() + + def resolve_about(self, info): + return ABOUT + +schema = graphene.Schema(query=Query) diff --git a/sizakat/settings.py b/sizakat/settings.py index f2caf3f04fc945634ab1875795897b3ea3e63475..351803a97eccfce8eaeea375906d8dcdd3e468d5 100644 --- a/sizakat/settings.py +++ b/sizakat/settings.py @@ -1,130 +1,136 @@ -""" -Django settings for sizakat project. - -Generated by 'django-admin startproject' using Django 3.0.7. - -For more information on this file, see -https://docs.djangoproject.com/en/3.0/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/3.0/ref/settings/ -""" - -import os - -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - - -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = os.environ.get('SECRET_KEY') - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = os.environ.get("DEBUG", False) - -ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS').split() - - -# Application definition - -INSTALLED_APPS = [ - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', - 'graphene_django', -] - -GRAPHENE = { - 'SCHEMA': 'sizakat.schema.schema', -} - -MIDDLEWARE = [ - 'django.middleware.security.SecurityMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', -] - -ROOT_URLCONF = 'sizakat.urls' - -TEMPLATES = [ - { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], - 'APP_DIRS': True, - 'OPTIONS': { - 'context_processors': [ - 'django.template.context_processors.debug', - 'django.template.context_processors.request', - 'django.contrib.auth.context_processors.auth', - 'django.contrib.messages.context_processors.messages', - ], - }, - }, -] - -WSGI_APPLICATION = 'sizakat.wsgi.application' - - -# Database -# https://docs.djangoproject.com/en/3.0/ref/settings/#databases - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.postgresql', - 'NAME': os.environ.get('SQL_DATABASE'), - 'USER': os.environ.get('SQL_USER'), - 'PASSWORD': os.environ.get('SQL_PASSWORD'), - 'HOST': os.environ.get('SQL_HOST'), - 'PORT': os.environ.get('SQL_PORT'), - } -} - - -# Password validation -# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators - -AUTH_PASSWORD_VALIDATORS = [ - { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', - }, -] - - -# Internationalization -# https://docs.djangoproject.com/en/3.0/topics/i18n/ - -LANGUAGE_CODE = 'en-us' - -TIME_ZONE = 'UTC' - -USE_I18N = True - -USE_L10N = True - -USE_TZ = True - - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/3.0/howto/static-files/ - -STATIC_URL = '/static/' -STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles") +""" +Django settings for sizakat project. + +Generated by 'django-admin startproject' using Django 3.0.7. + +For more information on this file, see +https://docs.djangoproject.com/en/3.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/3.0/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = os.environ.get('SECRET_KEY') + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = os.environ.get("DEBUG", False) + +ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS').split() + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'graphene_django', +] + +GRAPHENE = { + 'SCHEMA': 'sizakat.schema.schema', +} + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'sizakat.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'sizakat.wsgi.application' + +# Database +# https://docs.djangoproject.com/en/3.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + +if 'SQL_DATABASE' in os.environ: + DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': os.environ.get('SQL_DATABASE'), + 'USER': os.environ.get('SQL_USER'), + 'PASSWORD': os.environ.get('SQL_PASSWORD'), + 'HOST': os.environ.get('SQL_HOST'), + 'PORT': os.environ.get('SQL_PORT'), + } + } + +# Password validation +# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/3.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/3.0/howto/static-files/ + +STATIC_URL = '/static/' +STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles") diff --git a/sizakat/urls.py b/sizakat/urls.py index 214fc527ad851ba5fbee74377f1ae91a31d54b78..b1ae6cad0d22deef6baea247845c26af39f1da4a 100644 --- a/sizakat/urls.py +++ b/sizakat/urls.py @@ -1,24 +1,24 @@ -"""sizakat URL Configuration - -The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/3.0/topics/http/urls/ -Examples: -Function views - 1. Add an import: from my_app import views - 2. Add a URL to urlpatterns: path('', views.home, name='home') -Class-based views - 1. Add an import: from other_app.views import Home - 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') -Including another URLconf - 1. Import the include() function: from django.urls import include, path - 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) -""" -from django.contrib import admin -from django.urls import path -from django.views.decorators.csrf import csrf_exempt -from graphene_django.views import GraphQLView - -urlpatterns = [ - path('admin/', admin.site.urls), - path('graphql/', csrf_exempt(GraphQLView.as_view(graphiql=True))), -] +"""sizakat URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/3.0/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path +from django.views.decorators.csrf import csrf_exempt +from graphene_django.views import GraphQLView + +urlpatterns = [ + path('admin/', admin.site.urls), + path('graphql/', csrf_exempt(GraphQLView.as_view(graphiql=True))), +] diff --git a/sizakat/wsgi.py b/sizakat/wsgi.py index 5f7d7282b80d6408f7ab773d4a4cac79484296b0..f7fdcc6b2b516329734a1c19749bfc557a6c4e40 100644 --- a/sizakat/wsgi.py +++ b/sizakat/wsgi.py @@ -1,16 +1,16 @@ -""" -WSGI config for sizakat project. - -It exposes the WSGI callable as a module-level variable named ``application``. - -For more information on this file, see -https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/ -""" - -import os - -from django.core.wsgi import get_wsgi_application - -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sizakat.settings') - -application = get_wsgi_application() +""" +WSGI config for sizakat project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sizakat.settings') + +application = get_wsgi_application()