File tree 1 file changed +1
-14
lines changed
1 file changed +1
-14
lines changed Original file line number Diff line number Diff line change 1
- from django .core .exceptions import ValidationError
2
1
from wagtail import blocks
3
2
from wagtail .documents .blocks import DocumentChooserBlock
4
3
5
4
6
- class LimitedDocumentChooserBlock (DocumentChooserBlock ):
7
- def clean (self , value ):
8
- document = super ().clean (value )
9
- max_file_size = 5 * 1024 * 1024 # 5 MB
10
-
11
- # Check if the file size exceeds the limit
12
- if document .file_size > max_file_size :
13
- raise ValidationError ("File size exceeds the limit of 5 MB." )
14
-
15
- return document
16
-
17
-
18
5
class FileBlock (blocks .StructBlock ):
19
6
title = blocks .CharBlock (
20
7
help_text = "Title for this file as you'd like it to be seen by the public. It will fall back to document title if this field is empty" ,
21
8
label = "Customised File Title" ,
22
9
required = False ,
23
10
)
24
11
25
- file = LimitedDocumentChooserBlock (
12
+ file = DocumentChooserBlock (
26
13
verbose_name = "Document" ,
27
14
required = True ,
28
15
)
You can’t perform that action at this time.
0 commit comments