Box management page added
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 20s
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 5s
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 20s
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 5s
This commit is contained in:
@@ -3,8 +3,13 @@ from django.db.models import Q
|
||||
from django.http import HttpResponse, JsonResponse
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
|
||||
from .forms import ThingFormSet, ThingPictureForm
|
||||
from .models import Box, Thing, ThingType
|
||||
from .forms import (
|
||||
BoxForm,
|
||||
BoxTypeForm,
|
||||
ThingFormSet,
|
||||
ThingPictureForm,
|
||||
)
|
||||
from .models import Box, BoxType, Thing, ThingType
|
||||
|
||||
|
||||
@login_required
|
||||
@@ -146,16 +151,96 @@ def add_things(request, box_id):
|
||||
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,
|
||||
})
|
||||
|
||||
|
||||
@login_required
|
||||
def box_management(request):
|
||||
"""Main page for managing boxes and box types."""
|
||||
box_types = BoxType.objects.all().prefetch_related('boxes')
|
||||
boxes = Box.objects.select_related('box_type').all().prefetch_related('things')
|
||||
box_type_form = BoxTypeForm()
|
||||
box_form = BoxForm()
|
||||
|
||||
return render(request, 'boxes/box_management.html', {
|
||||
'box_types': box_types,
|
||||
'boxes': boxes,
|
||||
'box_type_form': box_type_form,
|
||||
'box_form': box_form,
|
||||
})
|
||||
|
||||
|
||||
@login_required
|
||||
def add_box_type(request):
|
||||
"""Add a new box type."""
|
||||
if request.method == 'POST':
|
||||
form = BoxTypeForm(request.POST)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return redirect('box_management')
|
||||
|
||||
|
||||
@login_required
|
||||
def edit_box_type(request, type_id):
|
||||
"""Edit an existing box type."""
|
||||
box_type = get_object_or_404(BoxType, pk=type_id)
|
||||
if request.method == 'POST':
|
||||
form = BoxTypeForm(request.POST, instance=box_type)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return redirect('box_management')
|
||||
|
||||
|
||||
@login_required
|
||||
def delete_box_type(request, type_id):
|
||||
"""Delete a box type."""
|
||||
box_type = get_object_or_404(BoxType, pk=type_id)
|
||||
if request.method == 'POST':
|
||||
if box_type.boxes.exists():
|
||||
return redirect('box_management')
|
||||
box_type.delete()
|
||||
return redirect('box_management')
|
||||
|
||||
|
||||
@login_required
|
||||
def add_box(request):
|
||||
"""Add a new box."""
|
||||
if request.method == 'POST':
|
||||
form = BoxForm(request.POST)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return redirect('box_management')
|
||||
|
||||
|
||||
@login_required
|
||||
def edit_box(request, box_id):
|
||||
"""Edit an existing box."""
|
||||
box = get_object_or_404(Box, pk=box_id)
|
||||
if request.method == 'POST':
|
||||
form = BoxForm(request.POST, instance=box)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return redirect('box_management')
|
||||
|
||||
|
||||
@login_required
|
||||
def delete_box(request, box_id):
|
||||
"""Delete a box."""
|
||||
box = get_object_or_404(Box, pk=box_id)
|
||||
if request.method == 'POST':
|
||||
if box.things.exists():
|
||||
return redirect('box_management')
|
||||
box.delete()
|
||||
return redirect('box_management')
|
||||
|
||||
Reference in New Issue
Block a user