Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish Introduction and Django Admin #6

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Binary file added blango/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file added blango/__pycache__/settings.cpython-36.pyc
Binary file not shown.
Binary file added blango/__pycache__/urls.cpython-36.pyc
Binary file not shown.
Binary file added blango/__pycache__/wsgi.cpython-36.pyc
Binary file not shown.
289 changes: 184 additions & 105 deletions blango/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,116 +10,195 @@
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

import os
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-+sn%dpa!086+g+%44z9*^j^q-u4n!j(#wl)x9a%_1op@zz2+1-'

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

ALLOWED_HOSTS = []


# Application definition

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

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 = 'blango.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',
],
from configurations import Configuration, values




class Dev(Configuration):
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "django-insecure-ym=d)ft4%)xiukqr&tgstl6i2091+x_#&o%*%n6g^epgy(bpd6"

AUTH_USER_MODEL = "blango_auth.User"
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
ACCOUNT_ACTIVATION_DAYS = 7
SITE_ID = 1
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_AUTHENTICATION_METHOD = "email"
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = values.ListValue(["localhost", "0.0.0.0", ".codio.io"])
# 7 rows below belong are codio related and upper line was ALLOWED_HOSTS = [] by default
X_FRAME_OPTIONS = 'ALLOW-FROM ' + os.environ.get('CODIO_HOSTNAME') + '-8000.codio.io'
CSRF_COOKIE_SAMESITE = None
CSRF_TRUSTED_ORIGINS = ['https://' + os.environ.get('CODIO_HOSTNAME') + '-8000.codio.io']
CSRF_COOKIE_SECURE = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SAMESITE = 'None'
SESSION_COOKIE_SAMESITE = 'None'

# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.sites',
'django.contrib.staticfiles',
'blango_auth',
'blog',
"crispy_forms",
"crispy_bootstrap5",
"debug_toolbar",
"allauth",
"allauth.account",
"allauth.socialaccount",
"allauth.socialaccount.providers.google",
]

MIDDLEWARE = [
"debug_toolbar.middleware.DebugToolbarMiddleware",
'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 = 'blango.urls'

INTERNAL_IPS = ["192.168.11.179"] # for usage of DjDT

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [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',
],
},
},
]

WSGI_APPLICATION = 'blango.wsgi.application'


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

DATABASES = values.DatabaseURLValue(f"sqlite:///{BASE_DIR}/db.sqlite3")


# Password validation
# https://docs.djangoproject.com/en/3.2/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',
},
]
PASSWORD_HASHERS = [
'django.contrib.auth.hashers.Argon2PasswordHasher',
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
]

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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = values.Value("UTC")

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/

STATIC_URL = '/static/'

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

# Settings enabling usage of Crispy forms ( as well as adding "crispy_forms" and "crispy_bootstrap5" to INSTALLED_APPS )
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5"
CRISPY_TEMPLATE_PACK = "bootstrap5"
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"filters": {
"require_debug_false": {
"()": "django.utils.log.RequireDebugFalse",
},
},
]

WSGI_APPLICATION = 'blango.wsgi.application'


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

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


# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
"formatters": {
"verbose": {
"format": "{levelname} {asctime} {module} {process:d} {thread:d} {message}",
"style": "{",
},
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
"handlers": {
"console": {
"class": "logging.StreamHandler",
"stream": "ext://sys.stdout",
"formatter": "verbose",
},
"mail_admins": {
"level": "ERROR",
"class": "django.utils.log.AdminEmailHandler",
"filters": ["require_debug_false"],
},
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
"loggers": {
"django.request": {
"handlers": ["mail_admins"],
"level": "ERROR",
"propagate": True,
},
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
"root": {
"handlers": ["console"],
"level": "DEBUG",
},
]


# Internationalization
# https://docs.djangoproject.com/en/3.2/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.2/howto/static-files/

STATIC_URL = '/static/'

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
}

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
class Prod(Dev):
DEBUG = values.BooleanValue(True)
SECRET_KEY = values.SecretValue()
26 changes: 25 additions & 1 deletion blango/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,33 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
import debug_toolbar
from django.conf import settings
from django.contrib import admin
from django.urls import path
from django.urls import path, include
import blango_auth.views
import blog.views
from django_registration.backends.activation.views import RegistrationView
from blango_auth.forms import BlangoRegistrationForm

urlpatterns = [
path('admin/', admin.site.urls),
path("", blog.views.index),
path("post/<slug>/", blog.views.post_detail, name="blog-post-detail"),
path("ip/", blog.views.get_ip),
path("accounts/", include("django.contrib.auth.urls")),
path("accounts/", include("allauth.urls")),
path("accounts/profile/", blango_auth.views.profile, name="profile"),
path(
"accounts/register/",
RegistrationView.as_view(form_class=BlangoRegistrationForm),
name="django_registration_register",
),
path("accounts/", include("django_registration.backends.activation.urls")),
]


if settings.DEBUG:
urlpatterns += [
path("__debug__/", include(debug_toolbar.urls)),
]
8 changes: 4 additions & 4 deletions blango/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "blango.settings")
os.environ.setdefault("DJANGO_CONFIGURATION", "Prod")

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'blango.settings')
from configurations.wsgi import get_wsgi_application

application = get_wsgi_application()
application = get_wsgi_application()
Empty file added blango_auth/__init__.py
Empty file.
Binary file added blango_auth/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file added blango_auth/__pycache__/admin.cpython-36.pyc
Binary file not shown.
Binary file added blango_auth/__pycache__/apps.cpython-36.pyc
Binary file not shown.
Binary file added blango_auth/__pycache__/forms.cpython-36.pyc
Binary file not shown.
Binary file added blango_auth/__pycache__/models.cpython-36.pyc
Binary file not shown.
Binary file added blango_auth/__pycache__/views.cpython-36.pyc
Binary file not shown.
40 changes: 40 additions & 0 deletions blango_auth/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from blango_auth.models import User, BlangoUserManager
from django.utils.translation import gettext_lazy as _
# Register your models here.


class BlangoUserAdmin(UserAdmin):
fieldsets = (
(None, {"fields": ("email", "password")}),
(_("Personal info"), {"fields": ("first_name", "last_name")}),
(
_("Permissions"),
{
"fields": (
"is_active",
"is_staff",
"is_superuser",
"groups",
"user_permissions",
)
},
),
(_("Important dates"), {"fields": ("last_login", "date_joined")}),
)
add_fieldsets = (
(
None,
{
"classes": ("wide",),
"fields": ("email", "password1", "password2"),
},
),
)
list_display = ("email", "first_name", "last_name", "is_staff")
search_fields = ("email", "first_name", "last_name")
ordering = ("email",)


admin.site.register(User, BlangoUserAdmin)
Loading