Skip to content

Commit

Permalink
Merge pull request #1 from Bloodmallet/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Bloodmallet authored Apr 26, 2019
2 parents 608e25a + 6f2959c commit 4cb48d8
Show file tree
Hide file tree
Showing 88 changed files with 11,509 additions and 18,823 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ env/
*.zip
debug.log
secrets.py
bloodmallet/db.sqlite3
compute_api/
bloodmallet/db.sqlite3
bloodmallet/static/
.gcloudignore
__pycache__/
cloud_sql_proxy.exe
local_dev_commands.txt
deploy_to_live.ps1
*.mo
3 changes: 3 additions & 0 deletions .style.yapf
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
[style]
based_on_style = chromium
indent_width = 4
SPACES_BEFORE_COMMENT = 5
BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF = true
DEDENT_CLOSING_BRACKETS = true
JOIN_MULTIPLE_LINES = true
CONTINUATION_INDENT_WIDTH = 4
COLUMN_LIMIT = 119
COALESCE_BRACKETS = true
INDENT_DICTIONARY_VALUE = true
16 changes: 16 additions & 0 deletions bloodmallet/.gcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
env/
.vscode/

debug.log
bloodmallet/db.sqlite3
requirements_dev.txt
requirements_commented.txt

__pycache__/
*.pyc
*.zip
*.exe

.git
.gitignore
.gcloudignore
16 changes: 2 additions & 14 deletions bloodmallet/bloodmallet/settings/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
import os

from .common import *

if os.getenv('GAE_APPLICATION', None):
from .production import *
from .production import *
else:
from .development import *

# secrets
try:
from .secrets import *
except:
pass
try:
from .secrets import SECRET_KEY
except:
pass
from .development import *
73 changes: 51 additions & 22 deletions bloodmallet/bloodmallet/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,30 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites', # required by django-allauth
'django.contrib.sites', # required by django-allauth
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.patreon',
'sass_processor',
'bootstrap4',
'corsheaders',
'crispy_forms',
'general_website',
'compute_api',
'vinaigrette',
'general_website.apps.GeneralWebsiteConfig',
'compute_api.apps.ComputeApiConfig',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'vinaigrette.middleware.VinaigretteAdminLanguageMiddleware',
]

ROOT_URLCONF = 'bloodmallet.urls'
Expand All @@ -55,19 +59,18 @@
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'general_website', 'templates', 'allauth') # allauth templates
os.path.join(BASE_DIR, 'general_website', 'templates', 'allauth') # allauth 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',
],
},
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.template.context_processors.i18n',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

Expand All @@ -91,6 +94,8 @@
},
]

from .secrets import SECRET_KEY

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

Expand All @@ -109,9 +114,6 @@

STATIC_URL = '/static/'

# location of the sass files (css with logic)
# SASS_PROCESSOR_ROOT = ''

STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
Expand All @@ -121,17 +123,44 @@
# TODO: Check https://django-allauth.readthedocs.io/en/latest/faq.html for patreon connection
# django-allauth
AUTHENTICATION_BACKENDS = (
# Needed to login by username in Django admin, regardless of `allauth`
# Needed to login by username in Django admin, regardless of `allauth`
'django.contrib.auth.backends.ModelBackend',

# `allauth` specific authentication methods, such as login by e-mail
# `allauth` specific authentication methods, such as login by e-mail
'allauth.account.auth_backends.AuthenticationBackend',
)

# allauth
SITE_ID = 1
# ACCOUNT_ADAPTER = 'general_website.allauth_overwrite.SocialAccountAdapter'

# we can either use crispy or bootstrap4
CRISPY_TEMPLATE_PACK = 'bootstrap4' # automatic bootstrap form frontend generator
CRISPY_TEMPLATE_PACK = 'bootstrap4' # automatic bootstrap form frontend generator

# from where is this?
LOGIN_URL = 'login'

# replaces the Django standard User
AUTH_USER_MODEL = 'general_website.User'

# Google cloud storage handling
DEFAULT_FILE_STORAGE = 'storages.backends.gcloud.GoogleCloudStorage'

LOCALE_PATHS = (BASE_DIR + '/general_website/locale',)

from .secrets import PROJECT, ZONE, CPU_TYPE, IMAGE_FAMILY, FALLBACK_ZONE

STANDARD_CHART_NAME = 'Bloodmallet Standard Chart'

# adjust messages tags to match bootstrap
from django.contrib.messages import constants as messages
MESSAGE_TAGS = {
messages.DEBUG: 'alert-info',
messages.INFO: 'alert-info',
messages.SUCCESS: 'alert-success',
messages.WARNING: 'alert-warning',
messages.ERROR: 'alert-danger',
}

# try to fix the cors issue for the downloader
CORS_ORIGIN_ALLOW_ALL = True
CORS_URLS_REGEX = r'^/chart/get/.*$'
56 changes: 36 additions & 20 deletions bloodmallet/bloodmallet/settings/development.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
import os

from .common import * # pylint: disable=unused-wildcard-import

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

Expand All @@ -18,26 +20,28 @@
'disable_existing_loggers': False,
'formatters': {
'default': {
'format': '%(asctime)s %(levelname)s %(module)s / %(funcName)s - %(message)s',
'format': '%(asctime)s %(levelname)s %(module)s / %(funcName)s:%(lineno)d - %(message)s',
}, # "%(asctime)s - %(filename)s / %(funcName)s - %(levelname)s - %(message)s"

},
'handlers': {
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'formatter': 'default',
'filename': os.path.join(BASE_DIR, 'debug.log'),
},
'console': {
'level': 'DEBUG' if DEBUG else 'INFO',
'class': 'logging.StreamHandler',
'formatter': 'default',
'level': 'DEBUG' if DEBUG else 'INFO'
},
},
'loggers': {
'django': {
'handlers': [
'file'
# 'console',
'file',
],
'level': 'DEBUG',
'propagate': True,
Expand All @@ -55,39 +59,51 @@
],
'level': 'DEBUG' if DEBUG else 'INFO',
'propagate': True,
},
'allauth.socialaccount.providers.patreon': {
'handlers': [
'console',
],
'level': 'DEBUG',
'propagate': True
}

},
}
# 'allauth.account',
# 'allauth.socialaccount',
# 'allauth.socialaccount.providers.patreon',

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
import pymysql
pymysql.install_as_MySQLdb()
from .secrets import DB_HOST, DB_NAME, DB_USER, DB_PASSWORD
from .secrets import LIVE_DB_HOST, LIVE_DB_NAME, LIVE_DB_USER, LIVE_DB_PASSWORD

DATABASES = {
'default':
{
'ENGINE': 'django.db.backends.mysql',
'HOST': '127.0.0.1',
'PORT': '3306',
'NAME': DB_NAME,
'USER': DB_USER,
'PASSWORD': DB_PASSWORD,
'OPTIONS': {
'charset': 'utf8mb4'
},
}
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '127.0.0.1',
'PORT': '3306',
'NAME': LIVE_DB_NAME,
'USER': LIVE_DB_USER,
'PASSWORD': LIVE_DB_PASSWORD,
'OPTIONS': {
'charset': 'utf8mb4'
},
}
}

# used to serve files from this path in non-debug production
STATIC_ROOT = 'static'

# SASS settings
SASS_PRECISION = 8
SASS_PROCESSOR_ROOT = 'general_website/static/'
# SASS_PROCESSOR_INCLUDE_FILE_PATTERN = r'^.+\.scss$'
# SASS_PROCESSOR_ENABLED = True
SASS_PROCESSOR_ROOT = STATIC_ROOT

# google cloud storage
from .secrets import DEV_BUCKET_NAME, DEV_CREDENTIALS
GS_BUCKET_NAME = DEV_BUCKET_NAME
from google.oauth2 import service_account
GS_CREDENTIALS = service_account.Credentials.from_service_account_file(DEV_CREDENTIALS)
46 changes: 33 additions & 13 deletions bloodmallet/bloodmallet/settings/production.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# -*- coding: utf-8 -*-

from .common import * # pylint: disable=unused-wildcard-import

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

ALLOWED_HOSTS = ['*']
ALLOWED_HOSTS = [
'dev.bloodmallet.com',
'bloodmallet.com',
]

# logging
LOGGING = {
Expand Down Expand Up @@ -41,6 +47,14 @@
],
'level': 'DEBUG' if DEBUG else 'INFO',
'propagate': True,
},
'compute_api': { # add app to logger!
'handlers': [
'console',
#'file'
],
'level': 'DEBUG' if DEBUG else 'INFO',
'propagate': True,
}
},
}
Expand All @@ -49,20 +63,19 @@
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
import pymysql
pymysql.install_as_MySQLdb()
from .secrets import DB_HOST, DB_NAME, DB_USER, DB_PASSWORD
from .secrets import LIVE_DB_HOST, LIVE_DB_NAME, LIVE_DB_USER, LIVE_DB_PASSWORD

DATABASES = {
'default':
{
'ENGINE': 'django.db.backends.mysql',
'HOST': '/cloudsql/{}'.format(DB_HOST),
'NAME': DB_NAME,
'USER': DB_USER,
'PASSWORD': DB_PASSWORD,
'OPTIONS': {
'charset': 'utf8mb4'
},
}
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '/cloudsql/{}'.format(LIVE_DB_HOST),
'NAME': LIVE_DB_NAME,
'USER': LIVE_DB_USER,
'PASSWORD': LIVE_DB_PASSWORD,
'OPTIONS': {
'charset': 'utf8mb4'
},
}
}

# used to serve files from this path in non-debug production
Expand All @@ -73,3 +86,10 @@
SASS_PROCESSOR_ROOT = STATIC_ROOT
# SASS_PROCESSOR_INCLUDE_FILE_PATTERN = r'^.+\.scss$'
SASS_PROCESSOR_ENABLED = False

# google cloud storage
from .secrets import LIVE_BUCKET_NAME
GS_BUCKET_NAME = LIVE_BUCKET_NAME

# SECURE_SSL_REDIRECT = True
SECURE_HSTS_SECONDS = 3600
7 changes: 5 additions & 2 deletions bloodmallet/bloodmallet/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
from django.contrib import admin
from django.urls import include, path

from general_website.views import login as app_login

urlpatterns = [
path('admin/', admin.site.urls),
path('', include('general_website.urls')),
path('compute_api/', include('compute_api.urls')),
path('admin/login/', app_login),
path('admin/', admin.site.urls),
path('compute_api/', include('compute_api.urls', namespace='compute_engine')),
]

handler400 = 'general_website.views.handler404'
Expand Down
Empty file removed bloodmallet/db.sqlite3
Empty file.
Loading

0 comments on commit 4cb48d8

Please sign in to comment.