Box edit taken out into it's own page; Editing of all fields 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 18s
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
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 18s
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:
@@ -10,6 +10,7 @@ from .forms import (
|
||||
BoxForm,
|
||||
BoxTypeForm,
|
||||
ThingFileForm,
|
||||
ThingForm,
|
||||
ThingFormSet,
|
||||
ThingLinkForm,
|
||||
ThingPictureForm,
|
||||
@@ -64,7 +65,17 @@ def box_detail(request, box_id):
|
||||
|
||||
@login_required
|
||||
def thing_detail(request, thing_id):
|
||||
"""Display details of a thing."""
|
||||
"""Display details of a thing (read-only)."""
|
||||
thing = get_object_or_404(
|
||||
Thing.objects.select_related('box', 'box__box_type').prefetch_related('files', 'links', 'tags'),
|
||||
pk=thing_id
|
||||
)
|
||||
return render(request, 'boxes/thing_detail.html', {'thing': thing})
|
||||
|
||||
|
||||
@login_required
|
||||
def edit_thing(request, thing_id):
|
||||
"""Edit a thing's details."""
|
||||
thing = get_object_or_404(
|
||||
Thing.objects.select_related('box', 'box__box_type').prefetch_related('files', 'links', 'tags'),
|
||||
pk=thing_id
|
||||
@@ -79,26 +90,32 @@ def thing_detail(request, thing_id):
|
||||
if request.method == 'POST':
|
||||
action = request.POST.get('action')
|
||||
|
||||
if action == 'move':
|
||||
if action == 'save_details':
|
||||
form = ThingForm(request.POST, request.FILES, instance=thing)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return redirect('thing_detail', thing_id=thing.id)
|
||||
|
||||
elif action == 'move':
|
||||
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 redirect('edit_thing', thing_id=thing.id)
|
||||
|
||||
elif action == 'upload_picture':
|
||||
picture_form = ThingPictureForm(request.POST, request.FILES, instance=thing)
|
||||
if picture_form.is_valid():
|
||||
picture_form.save()
|
||||
return redirect('thing_detail', thing_id=thing.id)
|
||||
return redirect('edit_thing', thing_id=thing.id)
|
||||
|
||||
elif action == 'delete_picture':
|
||||
if thing.picture:
|
||||
thing.picture.delete()
|
||||
thing.picture = None
|
||||
thing.save()
|
||||
return redirect('thing_detail', thing_id=thing.id)
|
||||
return redirect('edit_thing', thing_id=thing.id)
|
||||
|
||||
elif action == 'add_file':
|
||||
file_form = ThingFileForm(request.POST, request.FILES)
|
||||
@@ -106,7 +123,7 @@ def thing_detail(request, thing_id):
|
||||
thing_file = file_form.save(commit=False)
|
||||
thing_file.thing = thing
|
||||
thing_file.save()
|
||||
return redirect('thing_detail', thing_id=thing.id)
|
||||
return redirect('edit_thing', thing_id=thing.id)
|
||||
|
||||
elif action == 'add_link':
|
||||
link_form = ThingLinkForm(request.POST)
|
||||
@@ -114,7 +131,7 @@ def thing_detail(request, thing_id):
|
||||
thing_link = link_form.save(commit=False)
|
||||
thing_link.thing = thing
|
||||
thing_link.save()
|
||||
return redirect('thing_detail', thing_id=thing.id)
|
||||
return redirect('edit_thing', thing_id=thing.id)
|
||||
|
||||
elif action == 'delete_file':
|
||||
file_id = request.POST.get('file_id')
|
||||
@@ -125,7 +142,7 @@ def thing_detail(request, thing_id):
|
||||
thing_file.delete()
|
||||
except ThingFile.DoesNotExist:
|
||||
pass
|
||||
return redirect('thing_detail', thing_id=thing.id)
|
||||
return redirect('edit_thing', thing_id=thing.id)
|
||||
|
||||
elif action == 'delete_link':
|
||||
link_id = request.POST.get('link_id')
|
||||
@@ -135,7 +152,7 @@ def thing_detail(request, thing_id):
|
||||
thing_link.delete()
|
||||
except ThingLink.DoesNotExist:
|
||||
pass
|
||||
return redirect('thing_detail', thing_id=thing.id)
|
||||
return redirect('edit_thing', thing_id=thing.id)
|
||||
|
||||
elif action == 'add_tag':
|
||||
tag_id = request.POST.get('tag_id')
|
||||
@@ -149,7 +166,7 @@ def thing_detail(request, thing_id):
|
||||
thing.tags.add(tag)
|
||||
except Tag.DoesNotExist:
|
||||
pass
|
||||
return redirect('thing_detail', thing_id=thing.id)
|
||||
return redirect('edit_thing', thing_id=thing.id)
|
||||
|
||||
elif action == 'remove_tag':
|
||||
tag_id = request.POST.get('tag_id')
|
||||
@@ -159,15 +176,18 @@ def thing_detail(request, thing_id):
|
||||
thing.tags.remove(tag)
|
||||
except Tag.DoesNotExist:
|
||||
pass
|
||||
return redirect('thing_detail', thing_id=thing.id)
|
||||
return redirect('edit_thing', thing_id=thing.id)
|
||||
|
||||
return render(request, 'boxes/thing_detail.html', {
|
||||
thing_form = ThingForm(instance=thing)
|
||||
|
||||
return render(request, 'boxes/edit_thing.html', {
|
||||
'thing': thing,
|
||||
'boxes': boxes,
|
||||
'facets': facets,
|
||||
'picture_form': picture_form,
|
||||
'file_form': file_form,
|
||||
'link_form': link_form,
|
||||
'thing_form': thing_form,
|
||||
})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user