diff options
author | Matthew Lemon <y@yulqen.org> | 2024-08-08 17:13:51 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-08-08 17:13:51 +0100 |
commit | 5fff811c304849169c6345da334334fc233ec64d (patch) | |
tree | 2ecf46bc5804c9f2b36832d296f1a99633f4ef74 /pyblackbird_cc | |
parent | 9c9b3084939e77618854e2cbe3cce51029a70f07 (diff) |
The Cancel button is now managed by crispy forms.
Diffstat (limited to 'pyblackbird_cc')
-rw-r--r-- | pyblackbird_cc/resources/forms.py | 13 | ||||
-rw-r--r-- | pyblackbird_cc/resources/views.py | 4 | ||||
-rw-r--r-- | pyblackbird_cc/templates/resources/update_pdfs.html | 2 |
3 files changed, 12 insertions, 7 deletions
diff --git a/pyblackbird_cc/resources/forms.py b/pyblackbird_cc/resources/forms.py index 5a4a606..f4c6654 100644 --- a/pyblackbird_cc/resources/forms.py +++ b/pyblackbird_cc/resources/forms.py @@ -2,8 +2,9 @@ import logging from typing import List, Tuple import magic +from crispy_forms.bootstrap import FormActions from crispy_forms.helper import FormHelper -from crispy_forms.layout import Submit +from crispy_forms.layout import Submit, Field, Layout, Button from django import forms from pyblackbird_cc.resources.models import Resource, ResourceSubcategory @@ -182,14 +183,20 @@ class ResourceUpdateMetadataForm(forms.ModelForm): class ResourceUpdatePDFsForm(forms.Form): - def __init__(self, *args, **kwargs): + def __init__(self, cancel_url: str, *args, **kwargs): try: self.resource = kwargs.pop("resource") except KeyError: pass super().__init__(*args, **kwargs) self.helper = FormHelper(self) - self.helper.add_input(Submit("submit", "Submit")) + self.helper.layout = Layout( + Field("pdf_files"), + FormActions( + Submit("submit", "Submit", css_class="btn btn-primary"), + Button("cancel", "Cancel", css_class="btn btn-danger", onclick=f"location.href=''"), + ), + ) pdf_files = forms.FileField( widget=forms.TextInput( diff --git a/pyblackbird_cc/resources/views.py b/pyblackbird_cc/resources/views.py index 5922151..eecb7cd 100644 --- a/pyblackbird_cc/resources/views.py +++ b/pyblackbird_cc/resources/views.py @@ -344,7 +344,7 @@ def update_resource_metadata(request, pk): # Change resource_id to pk def add_resource_pdfs(request, pk): resource = get_object_or_404(Resource, pk=pk) if request.method == "POST": - form = ResourceUpdatePDFsForm(request.POST, request.FILES) + form = ResourceUpdatePDFsForm(resource.get_absolute_url(), request.POST, request.FILES) if form.is_valid(): pdf_files = form.cleaned_data["pdf_files"] @@ -380,6 +380,6 @@ def add_resource_pdfs(request, pk): return redirect("resources:resource_detail", resource_id=resource.id) else: - form = ResourceUpdatePDFsForm(resource=pk) + form = ResourceUpdatePDFsForm(resource.get_absolute_url(), resource=pk) return render(request, "resources/update_pdfs.html", {"form": form, "resource": resource}) diff --git a/pyblackbird_cc/templates/resources/update_pdfs.html b/pyblackbird_cc/templates/resources/update_pdfs.html index f5dab72..b490b4f 100644 --- a/pyblackbird_cc/templates/resources/update_pdfs.html +++ b/pyblackbird_cc/templates/resources/update_pdfs.html @@ -20,8 +20,6 @@ {% csrf_token %} {% crispy form form.helper %} </form> - - <button class="btn btn-danger" onclick="location.href='{{ resource.get_absolute_url }}';">Cancel</button> </div> </div> |