Skip to content

Commit

Permalink
Release 0.1.0 (#270)
Browse files Browse the repository at this point in the history
* Add poetry and update deps

* lint code, setup github actions

* Add default auto field key

* Remove unnecessary file

* lint code and remove deps file

* Add gunicorn to env

* Add url to path

* remove django heroku

* Add whitenoise

* Update env vars

* Update csrf trusted origins

* add https

* enable dev via http and prod via https auth

* Add collectstatic

* Add new setup instructions
  • Loading branch information
Praful932 authored Oct 17, 2022
1 parent 55bdf1a commit f36df81
Show file tree
Hide file tree
Showing 25 changed files with 1,778 additions and 527 deletions.
24 changes: 14 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is a basic workflow to help you get started with Actions
name: Tests
# Controls when the action will run.
# Controls when the action will run.
on:
# Triggers the workflow on all branches
push:
Expand All @@ -19,26 +19,30 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8']
python-version: ['3.8.6']

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Set up Python 🐍 ${{ matrix.python-version }}


- name: Set up Python 🐍 ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}


- name: Install dependencies
run: pip install -r requirements.txt
run: |
curl -sSL https://install.python-poetry.org | python3 -
poetry export -f requirements.txt --output requirements.txt --without-hashes
pip install -r requirements.txt
- name: Run Lint and Unit Tests ⚒
env:
KITABE_SECRET_KEY: "RANDOM_KEY"
run: |
flake8
pre-commit run --all-files
python manage.py collectstatic --no-input
python manage.py test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
bookenv/
.vscode
# colllect static output
staticfiles/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
exclude: 'wip'
repos:
- repo: https:/ambv/black
rev: 22.3.0
hooks:
- id: black
name: black-py
- repo: https:/asottile/pyupgrade
rev: v2.32.0
hooks:
- id: pyupgrade
name: pyupgrade-py
2 changes: 1 addition & 1 deletion BookRecSystem/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'BookRecSystem.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "BookRecSystem.settings")

application = get_asgi_application()
168 changes: 92 additions & 76 deletions BookRecSystem/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,75 +22,87 @@
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('KITABE_SECRET_KEY')
SECRET_KEY = os.environ.get("SECRET_KEY", "RANDOM_KEY")

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = str(os.environ.get("DEBUG", True)) == "True"

ALLOWED_HOSTS = ['kitabe-app.herokuapp.com']
ALLOWED_HOSTS = [
"kitabe-app.herokuapp.com",
"kitabe.up.railway.app",
"127.0.0.1",
"localhost",
]

CSRF_TRUSTED_ORIGINS = [
"https://kitabe-app.herokuapp.com",
"https://kitabe.up.railway.app",
]


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',

'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google',
'mainapp',
'storages',
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
# disable django static file handling during development as well
"whitenoise.runserver_nostatic",
"django.contrib.staticfiles",
"django.contrib.sites",
"allauth",
"allauth.account",
"allauth.socialaccount",
"allauth.socialaccount.providers.google",
"mainapp",
"storages",
]

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',
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"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 = 'BookRecSystem.urls'
ROOT_URLCONF = "BookRecSystem.urls"

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'templates'),
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [
os.path.join(BASE_DIR, "templates"),
],
'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',
"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",
# allauth
'django.template.context_processors.request'
"django.template.context_processors.request",
],
},
},
]

WSGI_APPLICATION = 'BookRecSystem.wsgi.application'
WSGI_APPLICATION = "BookRecSystem.wsgi.application"


# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
}

Expand All @@ -100,26 +112,26 @@

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]


# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/

LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = "en-us"

TIME_ZONE = 'Asia/Calcutta'
TIME_ZONE = "Asia/Calcutta"

USE_I18N = True

Expand All @@ -131,62 +143,66 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
# url/placeholder path at which static files are served
STATIC_URL = "/static/"
# other folders to look for static files
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"

# Deployment
# Directory where collectstatic will collect the static files for deployment
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")


AUTHENICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
"django.contrib.auth.backends.ModelBackend",
# allauth
'allauth.account.auth_backends.AuthenicationBackend'
"allauth.account.auth_backends.AuthenicationBackend",
]

SITE_ID = 1

SOCIALACCOUNT_PROVIDERS = {
'google': {
'APP': {
'client_id': os.environ.get('KITABE_AUTH_ID'),
'secret': os.environ.get('KITABE_AUTH_SECRET'),
'key': ''
"google": {
"APP": {
"client_id": os.environ.get("KITABE_AUTH_ID"),
"secret": os.environ.get("KITABE_AUTH_SECRET"),
"key": "",
}
}
}

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

# media files
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
MEDIA_URL = "/media/"

LOGIN_REDIRECT_URL = 'index'
LOGOUT_REDIRECT_URL = 'index'
LOGIN_REDIRECT_URL = "index"
LOGOUT_REDIRECT_URL = "index"

# simple mail transfer protocal
# EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST = "smtp.gmail.com"
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = os.environ.get('KITABE_EMAIL')
EMAIL_HOST_PASSWORD = os.environ.get('KITABE_PASS')
EMAIL_HOST_USER = os.environ.get("KITABE_EMAIL")
EMAIL_HOST_PASSWORD = os.environ.get("KITABE_PASS")

# Alluth Settings
ACCOUNT_AUTHENTICATION_METHOD = "username"
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = "none"
ACCOUNT_LOGOUT_ON_GET = True

if not DEBUG:
# access via https in production
ACCOUNT_DEFAULT_HTTP_PROTOCOL = "https"

MESSAGE_TAGS = {
messages.DEBUG: 'alert-info',
messages.INFO: 'alert-info',
messages.SUCCESS: 'alert-success',
messages.WARNING: 'alert-warning',
messages.ERROR: 'alert-danger',
messages.DEBUG: "alert-info",
messages.INFO: "alert-info",
messages.SUCCESS: "alert-success",
messages.WARNING: "alert-warning",
messages.ERROR: "alert-danger",
}

# Django Heroku Settings
if 'CHECK_HEROKU' in os.environ:
DEBUG = eval(os.environ.get('KITABE_DEBUG'))
import django_heroku
django_heroku.settings(locals())
12 changes: 6 additions & 6 deletions BookRecSystem/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
from django.conf.urls.static import static

urlpatterns = [
path('', include('mainapp.urls')),
path('admin/', admin.site.urls),
path('accounts/', include('allauth.urls')),
]+static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
path("", include("mainapp.urls")),
path("admin/", admin.site.urls),
path("accounts/", include("allauth.urls")),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
# error handler
handler404 = 'mainapp.views.handler404'
handler500 = 'mainapp.views.handler500'
handler404 = "mainapp.views.handler404"
handler500 = "mainapp.views.handler500"
2 changes: 1 addition & 1 deletion BookRecSystem/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'BookRecSystem.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "BookRecSystem.settings")

application = get_wsgi_application()
Loading

0 comments on commit f36df81

Please sign in to comment.