Add basic UI with bootstrap and allauth profile handling

This commit is contained in:
Shaun Kruger
2026-12-01 16:46:55 -07:00
parent b3b51f6cc5
commit af18031a14
26 changed files with 3283 additions and 10 deletions
+1
View File
@@ -14,3 +14,4 @@ __pycache__/
db.sqlite3
privatestudio/settings/local.py
static/
node_modules/
+11 -5
View File
@@ -32,6 +32,7 @@ def upload_asset(
base_url: str,
api_key: str,
file_path: str,
bucket: str,
key: str,
user_name: int = 1,
) -> dict:
@@ -58,9 +59,9 @@ def upload_asset(
# boto3.set_stream_logger('botocore', logging.DEBUG)
# logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
userinfo = requests.get(f"{base_url}/api/userinfo", headers={"Authorization": f"Bearer {api_key}"})
userinfo.raise_for_status()
user_data = userinfo.json()
# userinfo = requests.get(f"{base_url}/api/userinfo", headers={"Authorization": f"Bearer {api_key}"})
# userinfo.raise_for_status()
# user_data = userinfo.json()
s3creds = requests.post(f"{base_url}/api/s3keys", headers={"Authorization": f"Bearer {api_key}"})
s3creds.raise_for_status()
@@ -72,7 +73,7 @@ def upload_asset(
print(f"\nS3 Credentials obtained:")
print(f" Access Key: {access_key}")
print(f" Secret Key: {secret_key[:10]}...{secret_key[-10:]}") # Masked for security
print(f" Bucket: {user_data.get('bucket')}")
print(f" Bucket: {bucket}")
file_path_obj = Path(file_path)
if not file_path_obj.exists():
@@ -100,7 +101,6 @@ def upload_asset(
try:
# Upload the file
file_size = file_path_obj.stat().st_size
bucket = user_data['bucket']
# print(f"\n{'='*60}")
# print(f"Starting upload:")
@@ -190,6 +190,11 @@ Examples:
default=1,
help="User ID (defaults to 1)",
)
parser.add_argument(
"--bucket",
required=True,
help="S3 bucket name (e.g., demo)",
)
args = parser.parse_args()
@@ -200,6 +205,7 @@ Examples:
file_path=args.file,
key=args.key,
user_name=args.user_id,
bucket=args.bucket,
)
print(f"\nUpload completed: {result}")
return 0
+2858
View File
File diff suppressed because it is too large Load Diff
+42
View File
@@ -0,0 +1,42 @@
{
"name": "privatestudio",
"version": "0.1.0",
"description": "Javascript and CSS dependencies for privatestudio CMS",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"devbuild": "webpack --mode development --output-path ./privatestudio/static/bundle/",
"build": "npm run build-bundle && npm run build-htmx && npm run build-tinymce",
"build-bundle": "webpack --mode production --output-path ./privatestudio/static/bundle/",
"build-htmx": "cp node_modules/htmx.org/dist/htmx*.js ./privatestudio/static/bundle/",
"build-tinymce": "mkdir -p ./privatestudio/static/bundle/tinymce && cp -r node_modules/tinymce/* ./privatestudio/static/bundle/tinymce/",
"watch": "npm run build-htmx && npm run build-tinymce && webpack --mode development --output-path ./privatestudio/static/bundle/ --watch",
"build:digitalocean": "npm install --production=false && npm run build"
},
"author": "Shaun Kruger",
"license": "ISC",
"private": true,
"engines": {
"node": "v24.22.x",
"npm": "11.19.x"
},
"devDependencies": {
"autoprefixer": "^10.4.20",
"css-loader": "^7.1.2",
"html-webpack-plugin": "^5.6.0",
"mini-css-extract-plugin": "^2.9.1",
"postcss-loader": "^8.1.1",
"sass": "^1.79.3",
"sass-loader": "^16.0.2",
"style-loader": "^4.0.0",
"webpack": "^5.94.0",
"webpack-cli": "^5.1.4"
},
"dependencies": {
"@popperjs/core": "^2.11.8",
"bootstrap": "^5.3.3",
"htmx.org": "^1.9.12",
"jquery": "^3.7.1",
"tinymce": "^8.9.3"
}
}
+20 -1
View File
@@ -21,6 +21,10 @@ INSTALLED_APPS = [
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"allauth",
"allauth.account",
"allauth.socialaccount",
]
MIDDLEWARE = [
@@ -32,8 +36,13 @@ MIDDLEWARE = [
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"allauth.account.middleware.AccountMiddleware",
]
MESSAGE_STORAGE = "django.contrib.messages.storage.session.SessionStorage"
ROOT_URLCONF = "privatestudio.urls"
TEMPLATES = [
@@ -100,8 +109,18 @@ TIME_ZONE = os.environ.get("DJANGO_TIME_ZONE", "UTC")
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/
STATICFILES_FINDERS = [
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
]
STATICFILES_DIRS = [
os.path.join(PROJECT_DIR, "static"),
]
# Static files
STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATIC_URL = "/static/"
+26 -1
View File
@@ -1,6 +1,8 @@
from django.contrib import admin
from django.contrib import admin, messages
from django.utils.html import format_html
from privatestudio.studio import models
from privatestudio.studio.auth import generate_api_key, hash_api_key
@admin.register(models.Studio)
@@ -15,6 +17,29 @@ class APIKeyAdmin(admin.ModelAdmin):
list_filter = ("is_active",)
readonly_fields = ("key_hash",)
def get_fields(self, request, obj=None):
fields = super().get_fields(request, obj)
if obj is None:
# Generated in save_model, so there is nothing to show yet.
return [f for f in fields if f != "key_hash"]
return fields
def save_model(self, request, obj, form, change):
if change:
super().save_model(request, obj, form, change)
return
plain_key = generate_api_key()
obj.key_hash = hash_api_key(plain_key)
super().save_model(request, obj, form, change)
messages.warning(
request,
format_html(
"API key for {}: <code>{}</code> Copy it now; it will not be shown again.",
obj.user,
plain_key,
),
)
@admin.register(models.S3Credential)
class S3CredentialAdmin(admin.ModelAdmin):
+11
View File
@@ -0,0 +1,11 @@
{% extends "privatestudio/base.html" %}
{% block title %}Page not found{% endblock %}
{% block body_class %}template-404{% endblock %}
{% block content %}
<h1>Page not found</h1>
<h2>Sorry, this page could not be found.</h2>
{% endblock %}
+13
View File
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8" />
<title>Internal server error</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<h1>Internal server error</h1>
<h2>Sorry, there seems to be an error. Please try again soon.</h2>
</body>
</html>
@@ -0,0 +1 @@
{% extends "privatestudio/base_usermanage.html" %}
@@ -0,0 +1 @@
{% extends "privatestudio/base_usermanage.html" %}
@@ -0,0 +1 @@
{% extends 'privatestudio/base.html' %}
+64
View File
@@ -0,0 +1,64 @@
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>
{% block title %}
Private Studio
{% endblock %}
{% block title_suffix %}
{% endblock %}
</title>
{# {% if page.search_description %}#}
{# <meta name="description" content="{{ page.search_description }}" />#}
{# {% endif %}#}
<meta name="viewport" content="width=device-width, initial-scale=1" />
{# Force all links in the live preview panel to be opened in a new tab #}
{% if request.in_preview_panel %}
<base target="_blank">
{% endif %}
{# Global stylesheets #}
<link rel="stylesheet" href="{% static 'bundle/main.css' %}" crossorigin="anonymous"/>
<script src="{% static 'bundle/tinymce/tinymce.min.js' %}" crossorigin="anonymous"></script>
{% block extra_css %}
{# Override this in templates to add extra stylesheets #}
{% endblock %}
</head>
<body class="{% block body_class %}{% endblock %}">
{# This JS is at the top of the page because of HTMX order of declaration problems #}
<script src="{% static 'bundle/htmx.min.js' %}" crossorigin="anonymous"></script>
{% include 'privatestudio/nav_header.html' %}
<div class="container">
{% block notifications %}
{% for message in messages %}
<div class="alert alert-info">
{{ message|linebreaksbr }}
</div>
{% endfor %}
{% endblock %}
{% block outer_content %}
{% block content %}{% endblock %}
{% endblock %}
</div>
{% include 'privatestudio/nav_footer.html' %}
{# Global javascript #}
<script src="{% static 'bundle/main.js' %}" crossorigin="anonymous"></script>
<script src="{% static 'tinymcehelper.js' %}" crossorigin="anonymous"></script>
{% block extra_js %}
{# Override this in templates to add extra javascript #}
{% endblock %}
{% block extra_body %}
{% endblock %}
</body>
</html>
@@ -0,0 +1 @@
{% extends 'base.html' %}
@@ -0,0 +1,15 @@
{% extends 'privatestudio/base.html' %}
{% block outer_content %}
<div class="row">
<div class="col-sm-3">
<ul>
<li><a href="{% url 'account_email' %}">Email</a></li>
<li><a href="{% url 'account_change_password' %}">Change Password</a></li>
</ul>
</div>
<div class="col-sm-9">
{% block content %}{% endblock %}
</div>
</div>
{% endblock %}
@@ -0,0 +1,21 @@
<table class="table table-striped table-sm">
<tr>
<th>File Name</th>
<th>Size (bytes)</th>
<th>Upload Timestamp</th>
</tr>
{% for asset in uploaded_assets %}
<tr>
<td>{{ asset.s3_path }}</td>
<td>{{ asset.size }}</td>
<td>{{ asset.upload_timestamp }}</td>
</tr>
<tr style="display:none;" id="asset_{{ asset.id }}">
<td colspan="3">Click to refresh</td>
</tr>
{% empty %}
<tr>
<td colspan="3">No uploaded assets found.</td>
</tr>
{% endfor %}
</table>
@@ -0,0 +1,3 @@
<div class="privatestudiofooter">
</div>
@@ -0,0 +1,32 @@
<nav class="studio-navbar navbar navbar-expand-lg navbar-dark bg-dark navbar-fixed-top justify-content-between">
<div class="container">
<a class="navbar-brand" href="/">Private Studio</a>
<button class="navbar-toggler" data-bs-toggle="collapse" data-bs-target="#navbarContainer" aria-expanded="false" aria-controls="navbarContainer" aria-label="Toggle Navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div id="navbarContainer" class="collapse navbar-collapse justify-content-between">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="{% url 'studio:list' %}">Studios</a>
</li>
</ul>
<ul class="navbar-nav d-flex">
<li class="nav-item dropdown">
<a href="#" id="accountDropdown" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false">Account <span class="caret"></span></a>
<ul class="dropdown-menu">
{% if not request.user.is_authenticated %}
<li><a class="dropdown-item" href="{% url "account_login" %}">Login</a></li>
{% else %}
{% if request.user.is_superuser or request.user.groups.exists %}
<li><a class="dropdown-item" href="/admin/">Admin</a></li>
{% endif %}
{# <li><a class="dropdown-item" href="{% url 'contributor:redirect' %}">Contributor Profile</a></li>#}
<li><a class="dropdown-item" href="{% url "account_email" %}">Account Settings</a></li>
<li><a class="dropdown-item" href="{% url "account_logout" %}">Logout</a></li>
{% endif %}
</ul>
</li>
</ul>
</div>
</div>
</nav>
@@ -0,0 +1,11 @@
{% extends "privatestudio/base.html" %}
{% block content %}
<h1>{{ studio.name }}</h1>
<p>Bucket Name: {{ studio.bucket_name }}</p>
<p>Group: {{ studio.group.name }}</p>
<div id="uploaded_assets" hx-get="{% url 'studio:uploaded_assets' studio.bucket_name %}" hx-trigger="load" hx-target="#uploaded_assets" hx-swap="innerHTML">
<p>Loading uploaded assets...</p>
</div>
{% endblock %}
@@ -0,0 +1,10 @@
{% extends "privatestudio/base.html" %}
{% block content %}
<h1>Studios</h1>
<ul>
{% for studio in studios %}
<li><a href="{% url 'studio:detail' studio.bucket_name %}">{{ studio.name }}</a></li>
{% endfor %}
</ul>
{% endblock %}
+12 -2
View File
@@ -1,10 +1,20 @@
from django.urls import re_path
from django.urls import re_path, path, include
from django.views.generic import RedirectView
from privatestudio.studio import s3_views
from privatestudio.studio import s3_views, views
# re_path without trailing-slash requirements so APPEND_SLASH never redirects
# (a redirect would invalidate AWS v4 signatures).
studio_patterns = [
path("", views.StudioListView.as_view(), name="list"),
path("<slug:bucket_name>/", views.StudioDetailView.as_view(), name="detail"),
path("<slug:bucket_name>/hx/uploaded_assets/", views.UploadedAssetsView.as_view(), name="uploaded_assets"),
]
urlpatterns = [
path("", RedirectView.as_view(url="/studio/"), name="home"),
path("studio/", include((studio_patterns, 'studio'))),
re_path(r"^s3/(?P<bucket>[^/]+)/?$", s3_views.BucketView.as_view(), name="s3_bucket"),
re_path(r"^s3/(?P<bucket>[^/]+)/(?P<key>.+)$", s3_views.ObjectView.as_view(), name="s3_object"),
]
+55
View File
@@ -0,0 +1,55 @@
from django.views.generic import ListView, DetailView
from django.contrib.auth.mixins import LoginRequiredMixin, AccessMixin
from privatestudio.studio.models import Studio, UploadedAsset, TranscodeProfile
class StudioMixin(AccessMixin):
studio_slug_url_kwarg = "bucket_name"
def dispatch(self, request, *args, **kwargs):
if not request.user.is_authenticated:
return self.handle_no_permission()
user_groups = self.request.user.groups.all()
studio_qs = Studio.objects.filter(bucket_name=kwargs.get(self.studio_slug_url_kwarg), group__in=user_groups)
self.studio = studio_qs.first()
if not self.studio:
return self.handle_no_permission()
return super().dispatch(request, *args, **kwargs)
class StudioListView(LoginRequiredMixin, ListView):
model = Studio
template_name = "privatestudio/studio_list.html"
context_object_name = "studios"
def get_queryset(self):
# Filter studios based on the user's group memberships
user_groups = self.request.user.groups.all()
return super().get_queryset().filter(group__in=user_groups)
class StudioDetailView(StudioMixin, DetailView):
model = Studio
template_name = "privatestudio/studio_detail.html"
context_object_name = "studio"
slug_field = "bucket_name"
slug_url_kwarg = "bucket_name"
def get_queryset(self):
# Filter studios based on the user's group memberships
user_groups = self.request.user.groups.all()
return super().get_queryset().filter(group__in=user_groups)
class UploadedAssetsView(StudioMixin, ListView):
model = UploadedAsset
template_name = "privatestudio/hx_uploaded_assets.html"
context_object_name = "uploaded_assets"
def get_queryset(self):
# Filter uploaded assets based on the user's group memberships
return super().get_queryset().filter(studio=self.studio)
+1
View File
@@ -13,6 +13,7 @@ def health_check(request):
urlpatterns = [
path("health", health_check, name="health"),
path("admin/", admin.site.urls),
path("accounts/", include('allauth.urls')),
path("api/", api.urls),
path("", include("privatestudio.studio.urls")),
]
+3
View File
@@ -13,6 +13,9 @@ dependencies = [
"django-ninja~=1.8",
"django-cors-headers~=4.9",
"dj-database-url~=3.1",
"whitenoise~=6.11.0",
"pytz~=2026.5",
"django-allauth[socialaccount]~=65.0.2",
]
dynamic = ["version"]
+7
View File
@@ -0,0 +1,7 @@
import '../scss/styles.scss'
import * as bootstrap from 'bootstrap'
const jquery = require('jquery')
window.$ = jquery
window.jQuery = jquery
+18
View File
@@ -0,0 +1,18 @@
$font-size-base: 1rem !default; // Assumes the browser default, typically `16px`
$h1-font-size: $font-size-base * 1.75 !default;
$h2-font-size: $font-size-base * 1.5 !default;
$h3-font-size: $font-size-base * 1.35 !default;
$h4-font-size: $font-size-base * 1.25 !default;
$h5-font-size: $font-size-base * 1.15 !default;
$h6-font-size: $font-size-base !default;
@import "bootstrap/scss/bootstrap";
form.simpleform input[type=text], form.simpleform textarea {
width: 100%;
}
form.simpleform label {
font-weight: bold;
font-size: 1.2em;
}
+44
View File
@@ -0,0 +1,44 @@
'use strict'
const path = require('path')
const autoprefixer = require('autoprefixer')
const miniCssExtractPlugin = require('mini-css-extract-plugin')
module.exports = {
mode: 'development',
entry: './src/js/main.js',
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'privatestudio/static/bundle')
},
plugins: [
new miniCssExtractPlugin()
],
module: {
rules: [
{
test: /\.(scss)$/,
use: [
{
// loader: 'style-loader'
loader: miniCssExtractPlugin.loader
},
{
loader: 'css-loader'
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [autoprefixer]
}
}
},
{
loader: 'sass-loader'
}
]
}
]
}
}