aboutsummaryrefslogtreecommitdiffstats
path: root/pyblackbird_cc/resources/forms.py
diff options
context:
space:
mode:
Diffstat (limited to 'pyblackbird_cc/resources/forms.py')
-rw-r--r--pyblackbird_cc/resources/forms.py41
1 files changed, 40 insertions, 1 deletions
diff --git a/pyblackbird_cc/resources/forms.py b/pyblackbird_cc/resources/forms.py
index ed2c1a6..5a4a606 100644
--- a/pyblackbird_cc/resources/forms.py
+++ b/pyblackbird_cc/resources/forms.py
@@ -181,6 +181,46 @@ class ResourceUpdateMetadataForm(forms.ModelForm):
]
+class ResourceUpdatePDFsForm(forms.Form):
+ def __init__(self, *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"))
+
+ pdf_files = forms.FileField(
+ widget=forms.TextInput(
+ attrs={
+ "multiple": True,
+ "type": "File",
+ "required": True,
+ },
+ ),
+ required=False,
+ help_text="You can multi-select up to 20 .pdf files here.",
+ label="PDF files",
+ )
+
+ pdf_files.widget.attrs.update({"class": "file_upload", "accept": ".pdf"})
+
+ def clean_pdf_files(self):
+ pdf_files = self.files.getlist("pdf_files")
+ if not pdf_files:
+ raise forms.ValidationError("Please select at least one PDF file.")
+ acceptable = ["application/pdf"]
+ for f in pdf_files:
+ content_type = magic.from_buffer(f.file.read(), mime=True)
+ f.file.seek(0)
+ if content_type not in acceptable:
+ raise forms.ValidationError("Please select only PDF files.")
+ if len(pdf_files) > ALLOWED_PDFS:
+ raise forms.ValidationError("Please select up to 20 PDF files.")
+ return pdf_files
+
+
class ResourceUpdateThumbnailsForm(forms.Form):
def __init__(self, *args, **kwargs):
try:
@@ -218,4 +258,3 @@ class ResourceUpdateThumbnailsForm(forms.Form):
if len(thumbnail_files) > ALLOWED_THUMBNAILS:
raise forms.ValidationError("Please select up to 5 files.")
return thumbnail_files
-