Skip to content

Commit

Permalink
fix start-django-project
Browse files Browse the repository at this point in the history
  • Loading branch information
asim3 committed Sep 4, 2023
1 parent a77d514 commit 78dbaca
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci_cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Create New Django Project
run: if [ -x ./setup/set-new-django-project.bash ]; then echo "test_project" | ./setup/set-new-django-project.bash; fi;
run: if [ -x ./setup/set-new-django-project.bash ]; then echo "test_project" | make init; fi;

- name: Install requirements
run: make install
Expand Down
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ CD=${ACTIVATE} cd ./${PROJECT_NAME} &&

main: run

init: venv run-setup install


run-setup:
${ACTIVATE} pip3 install Django==3.2
init:
@sed -i -e 's/\r$$//' ./setup/set-new-django-project.bash
@./setup/set-new-django-project.bash

Expand Down
6 changes: 2 additions & 4 deletions setup/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ django-storages==1.12.3
django-debug-toolbar==3.2.4
dj-database-url==0.5.0
Pillow==9.1.1
psycopg2==2.9.3
python-dotenv==1.0.0
psycopg2-binary==2.9.3

# REST
djangorestframework==3.13.1
Expand All @@ -23,6 +24,3 @@ qrcode==7.3.1

# captcha
django-simple-captcha==0.5.17

# wagtail==3.0.1
# psycopg2-binary==2.9.3
8 changes: 7 additions & 1 deletion setup/set-new-django-project.bash
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ read name


start-django-project() {
django-admin startproject ${name}
if [ ! -d ~/.venv/${name} ]; then python3 -m venv ~/.venv/${name}; fi;

source ~/.venv/${name}/bin/activate

mv ./setup/requirements.txt ./requirements.txt

pip3 install -r ./requirements.txt

django-admin startproject ${name}
}


Expand Down
9 changes: 5 additions & 4 deletions setup/settings/main.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from pathlib import Path
from django.urls import reverse_lazy
from dotenv import dotenv_values

from .base import *
from .third_party.rest_framework import *

import os

DOTENV_CONFIG = dotenv_values(".env")

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

SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY')
SECRET_KEY = DOTENV_CONFIG["DJANGO_SECRET_KEY"]

# DEBUG = os.getenv('DJANGO_DEBUG', False) in (True, 'True')

Expand Down Expand Up @@ -101,7 +102,7 @@

EMAIL_HOST_USER = "info@gmail.com"

EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD')
EMAIL_HOST_PASSWORD = DOTENV_CONFIG.get('EMAIL_HOST_PASSWORD')

EMAIL_PORT = 587

Expand All @@ -120,6 +121,6 @@

SMS_BASE_URL = "https://api.taqnyat.sa/v1/messages"

SMS_TOKEN = os.environ.get('SMS_TOKEN')
SMS_TOKEN = DOTENV_CONFIG.get('SMS_TOKEN')

SMS_DEFAULT_FROM = "django"
8 changes: 5 additions & 3 deletions setup/settings/third_party/django_storages.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import os
from dotenv import dotenv_values


DOTENV_CONFIG = dotenv_values(".env")

AWS_S3_FILE_OVERWRITE = False

# DEFAULT_FILE_STORAGE = 'utilities.storages.PrivateMediaStorage'
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

STATICFILES_STORAGE = 'storages.backends.s3boto3.S3StaticStorage'

AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID')
AWS_ACCESS_KEY_ID = DOTENV_CONFIG.get('AWS_ACCESS_KEY_ID')

AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY')
AWS_SECRET_ACCESS_KEY = DOTENV_CONFIG.get('AWS_SECRET_ACCESS_KEY')

AWS_STORAGE_BUCKET_NAME = 'project-name'

Expand Down
8 changes: 3 additions & 5 deletions setup/settings/third_party/rest_framework.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from datetime import timedelta
from dotenv import dotenv_values

import os

DOTENV_CONFIG = dotenv_values(".env")

REST_FRAMEWORK = {
'DEFAULT_RENDERER_CLASSES': (
Expand Down Expand Up @@ -40,7 +41,7 @@


SIMPLE_JWT = {
"SIGNING_KEY": os.environ.get("REST_SIGNING_KEY"),
"SIGNING_KEY": DOTENV_CONFIG["REST_SIGNING_KEY"],
"ALGORITHM": "HS512",
"ACCESS_TOKEN_LIFETIME": timedelta(minutes=5),
"REFRESH_TOKEN_LIFETIME": timedelta(days=1),
Expand All @@ -49,6 +50,3 @@
# 'USER_ID_FIELD': 'username',
# 'USER_ID_CLAIM': 'my_user_name',
}

if not SIMPLE_JWT.get("SIGNING_KEY", None):
raise ValueError("The SIGNING_KEY setting must not be empty.")

0 comments on commit 78dbaca

Please sign in to comment.