Aggregated counts on front page; "Add items" page now saves pictures
All checks were successful
Build containers when image tags change / build-if-image-changed (., web, containers, main container, git.baumann.gr/adebaumann/labhelper) (push) Successful in 14s
Build containers when image tags change / build-if-image-changed (data-loader, loader, initContainers, init-container, git.baumann.gr/adebaumann/labhelper-data-loader) (push) Successful in 4s

This commit is contained in:
2025-12-30 01:10:40 +01:00
parent 17e713964c
commit 88a5c12bbc
6 changed files with 23 additions and 5 deletions

View File

@@ -27,7 +27,7 @@ spec:
mountPath: /data
containers:
- name: web
image: git.baumann.gr/adebaumann/labhelper:0.036
image: git.baumann.gr/adebaumann/labhelper:0.037
imagePullPolicy: Always
ports:
- containerPort: 8000

View File

@@ -41,7 +41,7 @@
{% endif %}
{% if formset.total_form_count %}
<form method="post" style="overflow-x: auto;">
<form method="post" enctype="multipart/form-data" style="overflow-x: auto;">
{% csrf_token %}
<table style="width: 100%; border-collapse: collapse; margin-bottom: 20px;">
<thead>

View File

@@ -1,5 +1,6 @@
{% extends "base.html" %}
{% load mptt_tags %}
{% load dict_extras %}
{% block title %}LabHelper - Home{% endblock %}
@@ -55,9 +56,11 @@
<span class="toggle-handle" style="display: inline-block; width: 24px; color: #ccc;">&nbsp;</span>
{% endif %}
<a href="{% url 'thing_type_detail' node.pk %}" style="color: #667eea; text-decoration: none; font-size: 16px; font-weight: 500; transition: color 0.2s;">{{ node.name }}</a>
{% if node.things.exists %}
<span style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600;">{{ node.things.count }}</span>
{% with count=type_counts|get_item:node.pk %}
{% if count and count > 0 %}
<span style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600;">{{ count }}</span>
{% endif %}
{% endwith %}
</div>
{% if children %}
<ul style="list-style: none; padding-left: 32px;">

View File

View File

@@ -0,0 +1,7 @@
from django import template
register = template.Library()
@register.filter
def get_item(dictionary, key):
return dictionary.get(key)

View File

@@ -11,9 +11,17 @@ def index(request):
"""Home page with boxes and thing types."""
boxes = Box.objects.select_related('box_type').all().order_by('id')
thing_types = ThingType.objects.all()
type_counts = {}
for thing_type in thing_types:
descendants = thing_type.get_descendants(include_self=True)
count = Thing.objects.filter(thing_type__in=descendants).count()
type_counts[thing_type.pk] = count
return render(request, 'boxes/index.html', {
'boxes': boxes,
'thing_types': thing_types,
'type_counts': type_counts,
})
@@ -90,7 +98,7 @@ def add_things(request, box_id):
success_message = None
if request.method == 'POST':
formset = ThingFormSet(request.POST, queryset=Thing.objects.filter(box=box))
formset = ThingFormSet(request.POST, request.FILES, queryset=Thing.objects.filter(box=box))
if formset.is_valid():
things = formset.save(commit=False)