commit e06c56e76ee2ef6388bf353233e74c520fa9e748 Author: Lyxminxx Date: Sun Sep 20 00:39:02 2026 +0200 Ready for production deployment diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..43ab33c --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +# Python-generated files +__pycache__/ +*.py[oc] +build/ +dist/ +wheels/ +*.egg-info + +# Virtual environments +.venv/ +data/ +staticfiles/ diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..6324d40 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.14 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d993b83 --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/core/__init__.py b/core/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/core/admin.py b/core/admin.py new file mode 100644 index 0000000..315f708 --- /dev/null +++ b/core/admin.py @@ -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',) diff --git a/core/asgi.py b/core/asgi.py new file mode 100644 index 0000000..a0b44fd --- /dev/null +++ b/core/asgi.py @@ -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() diff --git a/core/forms.py b/core/forms.py new file mode 100644 index 0000000..789e647 --- /dev/null +++ b/core/forms.py @@ -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'}), + } diff --git a/core/migrations/0001_initial.py b/core/migrations/0001_initial.py new file mode 100644 index 0000000..63737dd --- /dev/null +++ b/core/migrations/0001_initial.py @@ -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'], + }, + ), + ] diff --git a/core/migrations/__init__.py b/core/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/core/models.py b/core/models.py new file mode 100644 index 0000000..72901d3 --- /dev/null +++ b/core/models.py @@ -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 diff --git a/core/settings.py b/core/settings.py new file mode 100644 index 0000000..fc80819 --- /dev/null +++ b/core/settings.py @@ -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" diff --git a/core/templates/edit.html b/core/templates/edit.html new file mode 100644 index 0000000..19b9cb1 --- /dev/null +++ b/core/templates/edit.html @@ -0,0 +1,23 @@ + + + + Edit Transaction + + + +

Editing: {{ transaction.title }}

+
+
+ {% csrf_token %} + {{ form.as_p }} + + Cancel +
+
+ + diff --git a/core/templates/home.html b/core/templates/home.html new file mode 100644 index 0000000..18364c4 --- /dev/null +++ b/core/templates/home.html @@ -0,0 +1,61 @@ + + + + DIME Tracker + + + +

Just another spending tracker

+
+

Total Balance: {{ total_balance|floatformat:2 }} kr

+ View Statistics 📊 +
+
+

Add Transaction

+
+ {% csrf_token %} + {{ form.as_p }} + +
+
+ + + + + + + + + + {% for t in transactions %} + + + + + + + + {% empty %} + + {% endfor %} +
DateTitleCategoryAmountActions
{{ t.date }}{{ t.title }}{{ t.category.name|default:"-" }} + {{ t.amount }} kr + + Edit +
+ {% csrf_token %} + +
+
No transactions yet. Start spending!
+ + diff --git a/core/templates/stats.html b/core/templates/stats.html new file mode 100644 index 0000000..32e5abd --- /dev/null +++ b/core/templates/stats.html @@ -0,0 +1,68 @@ + + + + DIME Statistics + + + + + + +

Spending Statistics

+ +
+ Last 7 Days + Last 30 Days + Last 365 Days + All Time +
+ +
+ +
+ + + + diff --git a/core/urls.py b/core/urls.py new file mode 100644 index 0000000..12708da --- /dev/null +++ b/core/urls.py @@ -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//', views.edit_transaction, name='edit_transaction'), + path('delete//', views.delete_transaction, name='delete_transaction'), + path('stats/', views.stats, name='stats'), # Add this line +] diff --git a/core/views.py b/core/views.py new file mode 100644 index 0000000..1022ccc --- /dev/null +++ b/core/views.py @@ -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) diff --git a/core/wsgi.py b/core/wsgi.py new file mode 100644 index 0000000..6ea9106 --- /dev/null +++ b/core/wsgi.py @@ -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() diff --git a/db.sqlite3 b/db.sqlite3 new file mode 100644 index 0000000..30760e4 Binary files /dev/null and b/db.sqlite3 differ diff --git a/main.py b/main.py new file mode 100644 index 0000000..9fef0b6 --- /dev/null +++ b/main.py @@ -0,0 +1,6 @@ +def main(): + print("Hello from jast!") + + +if __name__ == "__main__": + main() diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..f2a662c --- /dev/null +++ b/manage.py @@ -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() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..618555e --- /dev/null +++ b/pyproject.toml @@ -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", +] diff --git a/uv.lock b/uv.lock new file mode 100644 index 0000000..6605f7f --- /dev/null +++ b/uv.lock @@ -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" }, +]