diff options
author | Matthew Lemon <y@yulqen.org> | 2024-05-15 16:28:41 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-05-15 16:28:41 +0100 |
commit | cf0ceb545421c58acc9478fc376b51065f97e532 (patch) | |
tree | 26ab2b9eebd6b03febec1bdb498742c50c8b7253 /pyblackbird_cc/resources/views.py | |
parent | 8d1f465ceb2f5e357b19b6e4c8468703725b4795 (diff) |
Basic form to update Resource metadata
Diffstat (limited to 'pyblackbird_cc/resources/views.py')
-rw-r--r-- | pyblackbird_cc/resources/views.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/pyblackbird_cc/resources/views.py b/pyblackbird_cc/resources/views.py index c1d7672..e96e701 100644 --- a/pyblackbird_cc/resources/views.py +++ b/pyblackbird_cc/resources/views.py @@ -15,6 +15,7 @@ from django.shortcuts import render from . import services from .forms import ResourceCreateForm +from .forms import ResourceUpdateMetadataForm from .models import PDFPageSnapshot from .models import PDFResource from .models import Resource @@ -357,3 +358,25 @@ def hx_download_button(request): "resources/hx_download_button.html", {"pdf_url": _extract_metadata_from_resource(res).pdf_url}, ) + + +@login_required +def update_resource_metadata(request, pk): # Change resource_id to pk + resource = get_object_or_404(Resource, pk=pk) + + if request.method == "POST": + form = ResourceUpdateMetadataForm(request.POST, instance=resource) + if form.is_valid(): + form.save() + return redirect( + "resources:resource_detail", + resource_id=resource.pk, + ) # Use pk instead of resource_id + else: + form = ResourceUpdateMetadataForm(instance=resource) + + return render( + request, + "resources/resource_metadata_update.html", + {"form": form, "resource": resource}, + ) |