Add temporary /setup/ URL to bootstrap admin + test data from browser

Visit your-site.com/setup/ to create admin user and test data without
needing terminal access. Links to admin panel and dashboard after setup.
REMOVE THIS after initial testing is complete.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Konrad du Plessis 2026-02-22 18:55:59 +02:00
parent 4449bf6fb8
commit 98ef3f5b90
2 changed files with 39 additions and 0 deletions

View File

@ -42,4 +42,9 @@ urlpatterns = [
# Preview a worker's payslip (AJAX — returns JSON)
path('payroll/preview/<int:worker_id>/', views.preview_payslip, name='preview_payslip'),
# === TEMPORARY SETUP ===
# Visit /setup/ to create admin user + test data from the browser.
# REMOVE THIS after initial setup is done!
path('setup/', views.run_setup, name='run_setup'),
]

View File

@ -16,6 +16,7 @@ from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.http import JsonResponse, HttpResponseForbidden, HttpResponse
from django.contrib.auth.models import User
from .models import Worker, Project, WorkLog, Team, PayrollRecord, Loan, PayrollAdjustment
from .forms import AttendanceLogForm, PayrollAdjustmentForm
@ -1099,3 +1100,36 @@ def preview_payslip(request, worker_id):
'net_pay': log_amount + adj_total,
'logs': unpaid_logs,
})
# =============================================================================
# === ONE-TIME SETUP (TEMPORARY) ===
# Runs the setup_test_data management command from the browser.
# Visit /setup/ to create admin user + test data.
# REMOVE THIS VIEW after initial setup is done!
# =============================================================================
def run_setup(request):
"""
Temporary view that creates the admin user and test data.
Accessible without login so you can bootstrap the system.
Visit your-site.com/setup/ to run it.
"""
from django.core.management import call_command
from io import StringIO
output = StringIO()
call_command('setup_test_data', stdout=output)
result = output.getvalue()
# Return the output as a simple HTML page
lines = result.replace('\n', '<br>')
return HttpResponse(
f'<html><body style="font-family: monospace; padding: 20px;">'
f'<h2>Setup Complete!</h2>'
f'<div>{lines}</div>'
f'<br><br>'
f'<a href="/admin/">Go to Admin Panel</a> | '
f'<a href="/">Go to Dashboard</a>'
f'</body></html>'
)