Add thing type detail page and move functionality
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 29s
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 7s

- Add thing type detail page showing hierarchical structure and things
- Add move to box functionality on thing detail page
- Fix add things form to only show items in current box
- Update thumbnails to 50x50 on box detail page
- Make thing names linkable on box detail page

Bump container version to 0.026
This commit is contained in:
2025-12-28 23:33:47 +01:00
parent bcba59b5e4
commit fbd3c9bee5
5 changed files with 277 additions and 7 deletions

View File

@@ -2,7 +2,7 @@ from django.http import HttpResponse, JsonResponse
from django.shortcuts import get_object_or_404, redirect, render
from .forms import ThingFormSet
from .models import Box, Thing
from .models import Box, Thing, ThingType
def index(request):
@@ -27,7 +27,21 @@ def thing_detail(request, thing_id):
Thing.objects.select_related('thing_type', 'box', 'box__box_type'),
pk=thing_id
)
return render(request, 'boxes/thing_detail.html', {'thing': thing})
boxes = Box.objects.select_related('box_type').all().order_by('id')
if request.method == 'POST':
new_box_id = request.POST.get('new_box')
if new_box_id:
new_box = get_object_or_404(Box, pk=new_box_id)
thing.box = new_box
thing.save()
return redirect('thing_detail', thing_id=thing.id)
return render(request, 'boxes/thing_detail.html', {
'thing': thing,
'boxes': boxes,
})
def search(request):
@@ -65,7 +79,7 @@ def add_things(request, box_id):
success_message = None
if request.method == 'POST':
formset = ThingFormSet(request.POST)
formset = ThingFormSet(request.POST, queryset=Thing.objects.filter(box=box))
if formset.is_valid():
things = formset.save(commit=False)
@@ -77,12 +91,30 @@ def add_things(request, box_id):
created_count += 1
if created_count > 0:
success_message = f'Added {created_count} thing{"s" if created_count > 1 else ""} successfully.'
formset = ThingFormSet()
formset = ThingFormSet(queryset=Thing.objects.filter(box=box))
else:
formset = ThingFormSet()
formset = ThingFormSet(queryset=Thing.objects.filter(box=box))
return render(request, 'boxes/add_things.html', {
'box': box,
'formset': formset,
'success_message': success_message,
})
def thing_type_detail(request, type_id):
"""Display details of a thing type with its hierarchy and things."""
thing_type = get_object_or_404(ThingType, pk=type_id)
descendants = thing_type.get_descendants(include_self=True)
things_by_type = {}
for descendant in descendants:
things = descendant.things.select_related('box', 'box__box_type').all()
if things:
things_by_type[descendant] = things
return render(request, 'boxes/thing_type_detail.html', {
'thing_type': thing_type,
'things_by_type': things_by_type,
})