mirror of
https://github.com/TrentSPalmer/trentpalmerdotorg.git
synced 2025-08-22 21:43:57 -07:00
initial commit
This commit is contained in:
0
tp/__init__.py
Normal file
0
tp/__init__.py
Normal file
16
tp/asgi.py
Normal file
16
tp/asgi.py
Normal file
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
ASGI config for tp 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.1/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tp.settings')
|
||||
|
||||
application = get_asgi_application()
|
9
tp/models.py
Normal file
9
tp/models.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from django.db import models
|
||||
import uuid
|
||||
|
||||
|
||||
class UUIDAsIDModel(models.Model):
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
141
tp/settings.py
Normal file
141
tp/settings.py
Normal file
@@ -0,0 +1,141 @@
|
||||
from pathlib import Path
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
load_dotenv()
|
||||
|
||||
# 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.1/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = str(os.getenv('SECRET_KEY'))
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True if str(os.getenv('DEBUG')) == "True" else False
|
||||
|
||||
ALLOWED_HOSTS = [x for x in 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',
|
||||
'bootstrap4',
|
||||
'crispy_forms',
|
||||
'audio.apps.AudioConfig',
|
||||
'accounts.apps.AccountsConfig',
|
||||
'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',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'tp.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': ['tp/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 = 'tp.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',
|
||||
}
|
||||
}
|
||||
|
||||
CRISPY_TEMPLATE_PACK = 'bootstrap4'
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/3.1/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.1/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'America/Los_Angeles'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_L10N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/3.1/howto/static-files/
|
||||
|
||||
# STATIC_URL = '/static/'
|
||||
|
||||
# aws settings
|
||||
AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID')
|
||||
AWS_SECRET_ACCESS_KEY = os.getenv('AWS_SECRET_ACCESS_KEY')
|
||||
AWS_STORAGE_BUCKET_NAME = os.getenv('AWS_STORAGE_BUCKET_NAME')
|
||||
AWS_S3_ENDPOINT_URL = os.getenv('AWS_S3_ENDPOINT_URL')
|
||||
AWS_DEFAULT_ACL = None
|
||||
# AWS_S3_CUSTOM_DOMAIN = f'{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com'
|
||||
AWS_S3_CUSTOM_DOMAIN = os.getenv('AWS_S3_CUSTOM_DOMAIN')
|
||||
AWS_S3_OBJECT_PARAMETERS = {'CacheControl': 'max-age=86400'}
|
||||
# s3 static settings
|
||||
STATIC_LOCATION = 'static'
|
||||
STATIC_URL = f'https://{AWS_S3_CUSTOM_DOMAIN}/{STATIC_LOCATION}/'
|
||||
STATICFILES_STORAGE = 'tp.storage_backends.StaticStorage'
|
||||
# s3 public media settings
|
||||
PUBLIC_MP3_LOCATION = 'mp3'
|
||||
MP3_URL = f'https://{AWS_S3_CUSTOM_DOMAIN}/{PUBLIC_MP3_LOCATION}/'
|
||||
MP3_FILE_STORAGE = 'tp.storage_backends.PublicMP3Storage'
|
||||
PUBLIC_IMAGES_LOCATION = 'images'
|
||||
IMAGES_URL = f'https://{AWS_S3_CUSTOM_DOMAIN}/{PUBLIC_IMAGES_LOCATION}/'
|
||||
IMAGES_FILE_STORAGE = 'tp.storage_backends.PublicImageStorage'
|
||||
|
||||
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)
|
18
tp/storage_backends.py
Normal file
18
tp/storage_backends.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from storages.backends.s3boto3 import S3Boto3Storage
|
||||
# from django.conf import settings
|
||||
|
||||
|
||||
class StaticStorage(S3Boto3Storage):
|
||||
location = 'static'
|
||||
default_acl = 'public-read'
|
||||
|
||||
|
||||
class PublicMP3Storage(S3Boto3Storage):
|
||||
location = 'mp3'
|
||||
default_acl = 'public-read'
|
||||
# file_overwrite = False
|
||||
|
||||
|
||||
class PublicImageStorage(S3Boto3Storage):
|
||||
location = 'images'
|
||||
default_acl = 'public-read'
|
49
tp/templates/base.html
Normal file
49
tp/templates/base.html
Normal file
@@ -0,0 +1,49 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<title>
|
||||
|
||||
{% url 'audio:home' as home_url %}
|
||||
{% url 'accounts:login' as login_url %}
|
||||
{% url 'accounts:logout' as logout_url %}
|
||||
{% url 'accounts:edit_profile' as edit_profile_url %}
|
||||
{% url 'accounts:password_change' as password_change_url %}
|
||||
{% url 'accounts:enable_totp' as enable_totp_url %}
|
||||
{% url 'accounts:disable_totp' as disable_totp_url %}
|
||||
{% url 'audio:new_feed' as new_feed_url %}
|
||||
{% url 'audio:feeds' as feeds_url %}
|
||||
|
||||
{% if request.path == home_url %}
|
||||
Home
|
||||
{% elif request.path == login_url %}
|
||||
Login?
|
||||
{% elif request.path == logout_url %}
|
||||
Logout?
|
||||
{% elif request.path == edit_profile_url %}
|
||||
Edit Profile?
|
||||
{% elif request.path == password_change_url %}
|
||||
Change Password?
|
||||
{% elif request.path == enable_totp_url %}
|
||||
Enable 2fa?
|
||||
{% elif request.path == disable_totp_url %}
|
||||
Disable 2fa?
|
||||
{% elif request.path == new_feed_url %}
|
||||
New Feed?
|
||||
{% elif request.path == feeds_url %}
|
||||
Feeds
|
||||
{% endif %}
|
||||
|
||||
{{ title }}
|
||||
|
||||
</title>
|
||||
{% load bootstrap4 %}
|
||||
{% bootstrap_css %}
|
||||
{% bootstrap_messages %}
|
||||
</head>
|
||||
<body>
|
||||
{% block content %}{% endblock content %}
|
||||
{% bootstrap_javascript jquery='full' %}
|
||||
</body>
|
||||
</html>
|
54
tp/templates/base_form.html
Normal file
54
tp/templates/base_form.html
Normal file
@@ -0,0 +1,54 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% load crispy_forms_tags %}
|
||||
|
||||
{% block content %}
|
||||
{% url 'accounts:login' as login_url %}
|
||||
{% url 'accounts:edit_profile' as edit_profile_url %}
|
||||
{% url 'accounts:password_change' as password_change_url %}
|
||||
{% url 'audio:new_feed' as new_feed_url %}
|
||||
|
||||
{% if request.path == login_url %}
|
||||
{% firstof 'Login' as submit %}
|
||||
{% elif request.path == edit_profile_url %}
|
||||
{% firstof 'Update' as submit %}
|
||||
{% elif request.path == password_change_url %}
|
||||
{% firstof 'Update' as submit %}
|
||||
{% elif request.path == new_feed_url %}
|
||||
{% firstof 'Submit' as submit %}
|
||||
{% endif %}
|
||||
|
||||
{% include "base_navbar.html" %}
|
||||
{% include "base_heading.html" %}
|
||||
|
||||
<div class="container">
|
||||
<div class="d-flex flex-column offset-sm-3 col-sm-6 col-xs-12 px-0">
|
||||
|
||||
{% if request.path == new_feed_url %}
|
||||
<form method="POST" enctype="multipart/form-data">
|
||||
{% elif form_data == "TRUE" %}
|
||||
<form method="POST" enctype="multipart/form-data">
|
||||
{% else %}
|
||||
<form method="POST">
|
||||
{% endif %}
|
||||
{% csrf_token %}
|
||||
{{ form | crispy }}
|
||||
<div class="mt-3">
|
||||
<input type="submit" class="btn btn-dark btn-lg" value="{{ submit }}">
|
||||
</div>
|
||||
</form><br>
|
||||
{% if request.path == edit_profile_url %}
|
||||
<div class="container px-0">
|
||||
<div class="d-flex flex-column align-items-start">
|
||||
{% if user.account.use_totp %}
|
||||
<a type="button" class="btn btn-lg btn-dark mb-4" href="{% url 'accounts:disable_totp' %}">Disable 2fa</a>
|
||||
{% else %}
|
||||
<a type="button" class="btn btn-lg btn-dark mb-4" href="{% url 'accounts:enable_totp' %}">Enable 2fa</a>
|
||||
{% endif %}
|
||||
<a type="button" class="btn btn-lg btn-dark" href="{% url 'accounts:password_change' %}">Change Password</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
35
tp/templates/base_heading.html
Normal file
35
tp/templates/base_heading.html
Normal file
@@ -0,0 +1,35 @@
|
||||
<div class="container">
|
||||
<div class="row justify-content-center my-2 mx-0">
|
||||
<h1 class="">
|
||||
{% url 'accounts:login' as login_url %}
|
||||
{% url 'accounts:edit_profile' as edit_profile_url %}
|
||||
{% url 'accounts:password_change' as password_change_url %}
|
||||
{% url 'accounts:enable_totp' as enable_totp_url %}
|
||||
{% url 'accounts:disable_totp' as disable_totp_url %}
|
||||
{% url 'audio:new_feed' as new_feed_url %}
|
||||
{% url 'audio:feeds' as feeds_url %}
|
||||
{% url 'audio:home' as home_url %}
|
||||
|
||||
{% if request.path == login_url %}
|
||||
Login?
|
||||
{% elif request.path == edit_profile_url %}
|
||||
Edit Profile?
|
||||
{% elif request.path == password_change_url %}
|
||||
Change Password?
|
||||
{% elif request.path == enable_totp_url %}
|
||||
Enable 2fa?
|
||||
{% elif request.path == disable_totp_url %}
|
||||
Disable 2fa?
|
||||
{% elif request.path == new_feed_url %}
|
||||
New Feed?
|
||||
{% elif request.path == feeds_url %}
|
||||
Feeds
|
||||
{% elif request.path == home_url %}
|
||||
Home
|
||||
{% endif %}
|
||||
|
||||
{{ heading }}
|
||||
|
||||
</h1>
|
||||
</div>
|
||||
</div>
|
20
tp/templates/base_navbar.html
Normal file
20
tp/templates/base_navbar.html
Normal file
@@ -0,0 +1,20 @@
|
||||
<div class="d-flex justify-content-center bg-dark">
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark" style="width: 950px; max-width: 95vw;">
|
||||
<a class="navbar-brand" href="{% url 'audio:home' %}">Home</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
|
||||
<div class="navbar-nav">
|
||||
<a class="nav-item nav-link" href="{% url 'audio:feeds' %}">Feeds</a>
|
||||
{% if user.is_authenticated %}
|
||||
<a class="nav-item nav-link" href="{% url 'accounts:logout' %}">Logout</a>
|
||||
<a class="nav-item nav-link" href="{% url 'accounts:edit_profile' %}">Profile</a>
|
||||
<a class="nav-item nav-link" href="{% url 'audio:new_feed' %}">NewFeed</a>
|
||||
{% else %}
|
||||
<a class="nav-item nav-link" href="{% url 'accounts:login' %}">Login</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</div>
|
26
tp/templates/confirmation.html
Normal file
26
tp/templates/confirmation.html
Normal file
@@ -0,0 +1,26 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% load crispy_forms_tags %}
|
||||
|
||||
{% block content %}
|
||||
{% url 'accounts:logout' as logout_url %}
|
||||
{% url 'accounts:disable_totp' as disable_totp_url %}
|
||||
|
||||
{% if request.path == logout_url %}
|
||||
{% firstof 'Logout' as submit %}
|
||||
{% elif request.path == disable_totp_url %}
|
||||
{% firstof 'OK' as submit %}
|
||||
{% endif %}
|
||||
|
||||
{% include "base_navbar.html" %}
|
||||
<div style="height: 10vh;"></div>
|
||||
{% include "base_heading.html" %}
|
||||
<div style="height: 30vh;" class="">
|
||||
<div class="h-100 col-sm-12 col-xs-12 d-flex justify-content-center align-content-center row p-0 mx-0">
|
||||
<form method="POST">
|
||||
{% csrf_token %}
|
||||
<input type="submit" class="btn btn-dark btn-lg" value="{{ submit }}">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
23
tp/urls.py
Normal file
23
tp/urls.py
Normal file
@@ -0,0 +1,23 @@
|
||||
"""tp URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/3.1/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, include
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('', include('audio.urls')),
|
||||
path('accounts/', include('accounts.urls')),
|
||||
]
|
16
tp/wsgi.py
Normal file
16
tp/wsgi.py
Normal file
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
WSGI config for tp 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.1/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tp.settings')
|
||||
|
||||
application = get_wsgi_application()
|
Reference in New Issue
Block a user