Ready for production deployment

This commit is contained in:
Lyxminxx committed 2026-09-20 00:39:02 +02:00
commit e06c56e76e
23 files changed
+664

No files matched your search

+12
View File
@@ -0,0 +1,12 @@
# Python-generated files
__pycache__/
*.py[oc]
build/
dist/
wheels/
*.egg-info
# Virtual environments
.venv/
data/
staticfiles/
+1
View File
@@ -0,0 +1 @@
3.14
+25
View File
@@ -0,0 +1,25 @@
FROM python:3.14-slim
# Install uv directly into the container
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
# Set the working directory
WORKDIR /app
# Copy your project files
COPY . .
# Tell uv to sync/install all dependencies into the system environment
RUN uv sync --system --no-dev
# Collect static files for the admin panel
RUN python manage.py collectstatic --noinput
# Create the data directory for SQLite
RUN mkdir -p data
# Expose the port
EXPOSE 8000
# Start Gunicorn
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "core.wsgi:application"]
View File
Whitespace-only changes.
View File
Whitespace-only changes.
+12
View File
@@ -0,0 +1,12 @@
from django.contrib import admin
from .models import Transaction, Category
admin.site.register(Category)
@admin.register(Transaction)
class TransactionAdmin(admin.ModelAdmin):
list_display = ('date', 'title', 'amount', 'category')
list_filter = ('category', 'date')
search_fields = ('title',)
+16
View File
@@ -0,0 +1,16 @@
"""
ASGI config for core 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/6.1/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
application = get_asgi_application()
+11
View File
@@ -0,0 +1,11 @@
from django import forms
from .models import Transaction
class TransactionForm(forms.ModelForm):
class Meta:
model = Transaction
fields = ['title', 'amount', 'category', 'date']
# This widget forces the browser to show a date picker calendar
widgets = {
'date': forms.DateInput(attrs={'type': 'date'}),
}
+36
View File
@@ -0,0 +1,36 @@
# Generated by Django 6.1.1 on 2026-09-19 22:04
import django.db.models.deletion
import django.utils.timezone
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Category',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
],
),
migrations.CreateModel(
name='Transaction',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=255)),
('amount', models.DecimalField(decimal_places=2, max_digits=10)),
('date', models.DateField(default=django.utils.timezone.now)),
('category', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='core.category')),
],
options={
'ordering': ['-date'],
},
),
]
View File
Whitespace-only changes.
+35
View File
@@ -0,0 +1,35 @@
from django.db import (
models,
)
from django.utils import(
timezone
)
class Transaction(models.Model):
title = models.CharField(max_length=255)
amount = models.DecimalField(max_digits=10, decimal_places=2)
date = models.DateField(default=timezone.now)
category = models.ForeignKey('Category', on_delete=models.SET_NULL, null=True, blank=True)
class Meta:
ordering = ['-date']
@property
def is_income(self):
return self.amount > 0
@property
def is_expense(self):
return self.amount < 0
def __str__(self):
return f"{self.date} | {self.title}: ${self.amount}"
class Category(models.Model):
name = models.CharField(max_length=255)
def __str__(self):
return self.name
+130
View File
@@ -0,0 +1,130 @@
"""
Django settings for core project.
Generated by 'django-admin startproject' using Django 6.1.1.
For more information on this file, see
https://docs.djangoproject.com/en/6.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/6.1/ref/settings/
"""
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/6.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-m#==%hz74d192o)4!#_!dpz%$yox@!hkabc9)pggkkiuvc7((q'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'core',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'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 = 'core.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR / 'core' / 'templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'core.wsgi.application'
# Database
# https://docs.djangoproject.com/en/6.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'data' / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/6.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/6.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/6.1/howto/static-files/
STATIC_URL = 'static/'
# Email
# https://docs.djangoproject.com/en/6.1/topics/email/#topic-email-configuration
MAILERS = {
'default': {
'BACKEND': 'django.core.mail.backends.console.EmailBackend',
},
}
STATIC_ROOT = BASE_DIR / "staticfiles"
+23
View File
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<title>Edit Transaction</title>
<style>
body { font-family: system-ui, sans-serif; max-width: 800px; margin: 40px auto; padding: 20px; }
.card { background: #f4f4f5; padding: 20px; border-radius: 8px; }
button { background: #3b82f6; color: white; padding: 8px 16px; border: none; border-radius: 4px; cursor: pointer; }
.cancel { background: #e4e4e7; color: black; text-decoration: none; padding: 8px 16px; border-radius: 4px; display: inline-block; margin-left: 10px; }
</style>
</head>
<body>
<h2>Editing: {{ transaction.title }}</h2>
<div class="card">
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Save Changes</button>
<a href="{% url 'home' %}" class="cancel">Cancel</a>
</form>
</div>
</body>
</html>
+61
View File
@@ -0,0 +1,61 @@
<!DOCTYPE html>
<html>
<head>
<title>DIME Tracker</title>
<style>
body { font-family: system-ui, sans-serif; max-width: 800px; margin: 40px auto; padding: 20px; }
.card { background: #f4f4f5; padding: 20px; border-radius: 8px; margin-bottom: 30px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px; border-bottom: 1px solid #e4e4e7; text-align: left; }
.income { color: #16a34a; font-weight: bold; }
.expense { color: #dc2626; }
button { background: #18181b; color: white; padding: 8px 16px; border: none; border-radius: 4px; cursor: pointer; }
.btn-edit { background: #3b82f6; color: white; text-decoration: none; padding: 6px 12px; border-radius: 4px; font-size: 14px; margin-right: 5px; }
.btn-delete { background: #ef4444; color: white; padding: 6px 12px; border: none; border-radius: 4px; cursor: pointer; font-size: 14px; }
</style>
</head>
<body>
<h1>Just another spending tracker</h1>
<div style="margin-bottom: 20px;">
<h2>Total Balance: {{ total_balance|floatformat:2 }} kr</h2>
<a href="{% url 'stats' %}" style="background: #e4e4e7; color: black; text-decoration: none; padding: 8px 16px; border-radius: 4px; font-weight: bold;">View Statistics 📊</a>
</div>
<div class="card">
<h3>Add Transaction</h3>
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Save Transaction</button>
</form>
</div>
<table>
<tr>
<th>Date</th>
<th>Title</th>
<th>Category</th>
<th>Amount</th>
<th>Actions</th>
</tr>
{% for t in transactions %}
<tr>
<td>{{ t.date }}</td>
<td>{{ t.title }}</td>
<td>{{ t.category.name|default:"-" }}</td>
<td class="{% if t.is_income %}income{% else %}expense{% endif %}">
{{ t.amount }} kr
</td>
<td>
<a href="{% url 'edit_transaction' t.pk %}" class="btn-edit">Edit</a>
<form action="{% url 'delete_transaction' t.pk %}" method="POST" style="display:inline;" onsubmit="return confirm('Are you sure you want to delete this transaction?');">
{% csrf_token %}
<button type="submit" class="btn-delete">Delete</button>
</form>
</td>
</tr>
{% empty %}
<tr><td colspan="5">No transactions yet. Start spending!</td></tr>
{% endfor %}
</table>
</body>
</html>
+68
View File
@@ -0,0 +1,68 @@
<!DOCTYPE html>
<html>
<head>
<title>DIME Statistics</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
body { font-family: system-ui, sans-serif; max-width: 800px; margin: 40px auto; padding: 20px; }
.nav { margin-bottom: 20px; }
.nav a { background: #e4e4e7; color: black; text-decoration: none; padding: 8px 16px; border-radius: 4px; font-weight: bold; }
.filters { margin-bottom: 30px; display: flex; gap: 10px; }
.filters a { padding: 6px 12px; border-radius: 4px; text-decoration: none; border: 1px solid #d4d4d8; color: black; }
.filters a.active { background: #18181b; color: white; border-color: #18181b; }
.chart-container { position: relative; height: 400px; width: 100%; margin-top: 20px; }
</style>
</head>
<body>
<div class="nav">
<a href="{% url 'home' %}">← Back to Tracker</a>
</div>
<h1>Spending Statistics</h1>
<div class="filters">
<a href="?filter=week" class="{% if current_filter == 'week' %}active{% endif %}">Last 7 Days</a>
<a href="?filter=month" class="{% if current_filter == 'month' %}active{% endif %}">Last 30 Days</a>
<a href="?filter=year" class="{% if current_filter == 'year' %}active{% endif %}">Last 365 Days</a>
<a href="?filter=all" class="{% if current_filter == 'all' %}active{% endif %}">All Time</a>
</div>
<div class="chart-container">
<canvas id="categoryChart"></canvas>
</div>
<script>
// Parse the JSON data passed from Django
const labels = JSON.parse('{{ labels|safe }}');
const data = JSON.parse('{{ data|safe }}');
const ctx = document.getElementById('categoryChart').getContext('2d');
if (data.length === 0) {
ctx.font = "16px system-ui";
ctx.fillText("No expenses logged for this time period.", 10, 50);
} else {
new Chart(ctx, {
type: 'doughnut',
data: {
labels: labels,
datasets: [{
label: 'Amount Spent (kr)',
data: data,
// A simple color palette
backgroundColor: ['#ef4444', '#3b82f6', '#10b981', '#f59e0b', '#8b5cf6', '#ec4899', '#14b8a6'],
borderWidth: 1
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: { position: 'right' }
}
}
});
}
</script>
</body>
</html>
+11
View File
@@ -0,0 +1,11 @@
from django.contrib import admin
from django.urls import path
from core import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.home, name='home'),
path('edit/<int:pk>/', views.edit_transaction, name='edit_transaction'),
path('delete/<int:pk>/', views.delete_transaction, name='delete_transaction'),
path('stats/', views.stats, name='stats'), # Add this line
]
+89
View File
@@ -0,0 +1,89 @@
from django.shortcuts import render, redirect, get_object_or_404
from django.db.models import Sum
from .models import Transaction
from .forms import TransactionForm
import json
from datetime import timedelta
from django.utils import timezone
from django.db.models import Sum
def home(request):
# 1. Handle form submission
if request.method == 'POST':
form = TransactionForm(request.POST)
if form.is_valid():
form.save()
return redirect('home') # Refresh the page
else:
form = TransactionForm()
# 2. Fetch data for the table
transactions = Transaction.objects.all()
# Calculate total balance (returns 0 if database is empty)
total_balance = transactions.aggregate(Sum('amount'))['amount__sum'] or 0
# 3. Send data to the template
context = {
'form': form,
'transactions': transactions,
'total_balance': total_balance,
}
return render(request, 'home.html', context)
def edit_transaction(request, pk):
transaction = get_object_or_404(Transaction, pk=pk)
if request.method == 'POST':
form = TransactionForm(request.POST, instance=transaction)
if form.is_valid():
form.save()
return redirect('home')
else:
form = TransactionForm(instance=transaction)
return render(request, 'edit.html', {'form': form, 'transaction': transaction})
def delete_transaction(request, pk):
transaction = get_object_or_404(Transaction, pk=pk)
if request.method == 'POST':
transaction.delete()
return redirect('home')
def stats(request):
# 1. Figure out what time period we are looking at
time_filter = request.GET.get('filter', 'all')
now = timezone.now().date()
# Start with only expenses (numbers less than 0)
expenses = Transaction.objects.filter(amount__lt=0)
# 2. Filter by date based on the button clicked
if time_filter == 'week':
expenses = expenses.filter(date__gte=now - timedelta(days=7))
elif time_filter == 'month':
expenses = expenses.filter(date__gte=now - timedelta(days=30))
elif time_filter == 'year':
expenses = expenses.filter(date__gte=now - timedelta(days=365))
# 3. Group by category and sum the amounts
category_data = expenses.values('category__name').annotate(total=Sum('amount'))
# 4. Format data for Chart.js
labels = []
data = []
for item in category_data:
# If category is null, call it 'Uncategorized'
cat_name = item['category__name'] or 'Uncategorized'
labels.append(cat_name)
# Make the number positive for the chart (so it draws correctly)
data.append(abs(float(item['total'])))
context = {
'labels': json.dumps(labels),
'data': json.dumps(data),
'current_filter': time_filter,
}
return render(request, 'stats.html', context)
+16
View File
@@ -0,0 +1,16 @@
"""
WSGI config for core 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/6.1/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
application = get_wsgi_application()
BIN
View File
Binary file not shown.
+6
View File
@@ -0,0 +1,6 @@
def main():
print("Hello from jast!")
if __name__ == "__main__":
main()
Executable
+22
View File
@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
+11
View File
@@ -0,0 +1,11 @@
[project]
name = "jast"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.14"
dependencies = [
"django>=6.1.1",
"gunicorn>=26.2.0",
"whitenoise>=6.12.0",
]
Generated
+79
View File
@@ -0,0 +1,79 @@
version = 1
revision = 3
requires-python = ">=3.14"
[[package]]
name = "asgiref"
version = "3.12.1"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/e6/26/3b59f2bdae5f640389becb1f673cded775287f5fc4f816309d9ca9a3f93d/asgiref-3.12.1.tar.gz", hash = "sha256:59dcb51c272ad209d59bed5708a64a333083e86017d7fcdd67498eeab7784340", size = 42378, upload-time = "2026-07-14T09:56:18.087Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/c0/1b/54f4ad77cd8a584fa70746c47df988e002cf1ee1eba43364d46f87803647/asgiref-3.12.1-py3-none-any.whl", hash = "sha256:fe386d1c2bff7259ea95929266d12a8cf9a8b5a1c2598402967d8792e7a7c094", size = 25478, upload-time = "2026-07-14T09:56:16.926Z" },
]
[[package]]
name = "django"
version = "6.1.1"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "asgiref" },
{ name = "sqlparse" },
{ name = "tzdata", marker = "sys_platform == 'win32'" },
]
sdist = { url = "https://files.pythonhosted.org/packages/f8/d4/8314b5bdef20832f0ac6ae3b3e4d4924e4759fa3b4af27609dd747e7a6be/django-6.1.1.tar.gz", hash = "sha256:7ab93536d8e677aa14554c56426290c69480bf2ee68d7513d4a22f57d6bfeb84", size = 11284905, upload-time = "2026-09-02T17:20:45.621Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/8d/ca/c1040a4fd15754ede7df15fd72fc2e123045b473b253ab5f5284e11c651e/django-6.1.1-py3-none-any.whl", hash = "sha256:585fb82bf15053c42cf52e67c2f1b54a032dca384759315fd6678ab1870d1d72", size = 8419512, upload-time = "2026-09-02T17:20:39.153Z" },
]
[[package]]
name = "gunicorn"
version = "26.2.0"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/d9/8a/e4ef6ee11701b6cd64702848415ffb69eeff85cb388a3c6c7fe86f22f3f8/gunicorn-26.2.0.tar.gz", hash = "sha256:62b864895d9ebff0b2f9867ba04fe811c93121596540830c9c916d0769668447", size = 787921, upload-time = "2026-08-24T15:05:59.3Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/fe/85/7522a52e5e2f42faf1a129113ab63e548c42e103e9af395b7bfe65e403e2/gunicorn-26.2.0-py3-none-any.whl", hash = "sha256:bd249d0b3f7972f7432f0a6b6ff3b3ee2d129f70cd1ff6c09a9dd9e29a2b88e3", size = 228389, upload-time = "2026-08-24T15:05:57.67Z" },
]
[[package]]
name = "jast"
version = "0.1.0"
source = { virtual = "." }
dependencies = [
{ name = "django" },
{ name = "gunicorn" },
{ name = "whitenoise" },
]
[package.metadata]
requires-dist = [
{ name = "django", specifier = ">=6.1.1" },
{ name = "gunicorn", specifier = ">=26.2.0" },
{ name = "whitenoise", specifier = ">=6.12.0" },
]
[[package]]
name = "sqlparse"
version = "0.6.0"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/5f/d3/3f06a1006f2261d1342aefb3c71eed02f5d4ca5bdbecd86ebc12ad38306e/sqlparse-0.6.0.tar.gz", hash = "sha256:113c35c75365ab9cc9c7231d68c6428fb11c085fc8e9eb1ad659b7ddbf6cd2b9", size = 178477, upload-time = "2026-08-13T19:16:06.396Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/d9/50/f00935da0ec7cbf325f8dc4f772ae46fbc7b672dd62876e73f0a94adda57/sqlparse-0.6.0-py3-none-any.whl", hash = "sha256:b861c0288ce2fa56209a9a6412d2e066ac664b3873b89c26c9d8415e8e32996f", size = 50070, upload-time = "2026-08-13T19:16:04.062Z" },
]
[[package]]
name = "tzdata"
version = "2026.4"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/e4/31/3d74fa778a63b98b7374323befcc0be5ab3bd94afd4096a0124e7379152c/tzdata-2026.4.tar.gz", hash = "sha256:f1b8bd365d8d210c55353f4d7f8d6d8561c0ba50d704b700d195a9424bba0d79", size = 199350, upload-time = "2026-09-12T12:56:03.251Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/f9/bc/8737e8d54cf51106118039b83f485a4783112fab49ea9d044b234978a46e/tzdata-2026.4-py2.py3-none-any.whl", hash = "sha256:c2169a8b0a7a5e9674da5a135ccdfb2b3e671b333ed9fed17b41f73c34476e81", size = 347494, upload-time = "2026-09-12T12:56:01.67Z" },
]
[[package]]
name = "whitenoise"
version = "6.12.0"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/cb/2a/55b3f3a4ec326cd077c1c3defeee656b9298372a69229134d930151acd01/whitenoise-6.12.0.tar.gz", hash = "sha256:f723ebb76a112e98816ff80fcea0a6c9b8ecde835f8ddda25df7a30a3c2db6ad", size = 26841, upload-time = "2026-02-27T00:05:42.028Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/db/eb/d5583a11486211f3ebd4b385545ae787f32363d453c19fffd81106c9c138/whitenoise-6.12.0-py3-none-any.whl", hash = "sha256:fc5e8c572e33ebf24795b47b6a7da8da3c00cff2349f5b04c02f28d0cc5a3cc2", size = 20302, upload-time = "2026-02-27T00:05:40.086Z" },
]