6363from ietf .utils .pipe import pipe
6464from ietf .utils .pdf import pdf_pages
6565from ietf .utils .text import xslugify
66- from ietf .utils .validators import ( validate_file_size , validate_mime_type ,
67- validate_file_extension , validate_no_html_frame , get_mime_type )
66+ from ietf .utils .validators import get_mime_type
6867
6968from .forms import (InterimMeetingModelForm , InterimAnnounceForm , InterimSessionModelForm ,
70- InterimCancelForm , InterimSessionInlineFormSet )
69+ InterimCancelForm , InterimSessionInlineFormSet , FileUploadForm )
7170
7271
7372def get_menu_entries (request ):
@@ -1117,14 +1116,13 @@ def add_session_drafts(request, session_id, num):
11171116 'form' : form ,
11181117 })
11191118
1120- class UploadBlueSheetForm (forms .Form ):
1121- file = forms .FileField (label = 'Bluesheet scan to upload' )
11221119
1123- def clean_file (self ):
1124- file = self .cleaned_data ['file' ]
1125- validate_mime_type (file , settings .MEETING_VALID_BLUESHEET_MIME_TYPES )
1126- validate_file_extension (file , settings .MEETING_VALID_BLUESHEET_EXTENSIONS )
1127- return file
1120+ class UploadBlueSheetForm (FileUploadForm ):
1121+
1122+ def __init__ (self , * args , ** kwargs ):
1123+ kwargs ['doc_type' ] = 'bluesheets'
1124+ super (UploadBlueSheetForm , self ).__init__ (* args , ** kwargs )
1125+
11281126
11291127@role_required ('Area Director' , 'Secretariat' , 'IRTF Chair' , 'WG Chair' , 'RG Chair' )
11301128def upload_session_bluesheets (request , session_id , num ):
@@ -1193,25 +1191,15 @@ def upload_session_bluesheets(request, session_id, num):
11931191 })
11941192
11951193
1196- # FIXME: This form validation code (based on the secretariat upload code) only looks at filename extensions
1197- # It should look at the contents of the files instead.
1198- class UploadMinutesForm (forms .Form ):
1199- file = forms .FileField (label = 'Minutes file to upload. Note that you can only upload minutes in txt, html, or pdf formats.' )
1194+ class UploadMinutesForm (FileUploadForm ):
12001195 apply_to_all = forms .BooleanField (label = 'Apply to all group sessions at this meeting' ,initial = True ,required = False )
12011196
12021197 def __init__ (self , show_apply_to_all_checkbox , * args , ** kwargs ):
1203- super (UploadMinutesForm , self ).__init__ (* args , ** kwargs )
1198+ kwargs ['doc_type' ] = 'minutes'
1199+ super (UploadMinutesForm , self ).__init__ (* args , ** kwargs )
12041200 if not show_apply_to_all_checkbox :
12051201 self .fields .pop ('apply_to_all' )
12061202
1207- def clean_file (self ):
1208- file = self .cleaned_data ['file' ]
1209- validate_file_size (file )
1210- ext = validate_file_extension (file , settings .MEETING_VALID_MINUTES_EXTENSIONS )
1211- mime_type , encoding = validate_mime_type (file , settings .MEETING_VALID_MINUTES_MIME_TYPES )
1212- if ext in ['.html' , '.htm' ] or mime_type in ['text/html' , ]:
1213- validate_no_html_frame (file )
1214- return file
12151203
12161204def upload_session_minutes (request , session_id , num ):
12171205 # num is redundant, but we're dragging it along an artifact of where we are in the current URL structure
@@ -1301,26 +1289,15 @@ def upload_session_minutes(request, session_id, num):
13011289 })
13021290
13031291
1304- # FIXME: This form validation code (based on the secretariat upload code) only looks at filename extensions
1305- # It should look at the contents of the files instead.
1306- class UploadAgendaForm (forms .Form ):
1307- file = forms .FileField (label = 'Agenda file to upload. Note that you can only upload agendas in txt or html formats.' )
1292+ class UploadAgendaForm (FileUploadForm ):
13081293 apply_to_all = forms .BooleanField (label = 'Apply to all group sessions at this meeting' ,initial = True ,required = False )
13091294
13101295 def __init__ (self , show_apply_to_all_checkbox , * args , ** kwargs ):
1311- super (UploadAgendaForm , self ).__init__ (* args , ** kwargs )
1296+ kwargs ['doc_type' ] = 'agenda'
1297+ super (UploadAgendaForm , self ).__init__ (* args , ** kwargs )
13121298 if not show_apply_to_all_checkbox :
13131299 self .fields .pop ('apply_to_all' )
13141300
1315- def clean_file (self ):
1316- file = self .cleaned_data ['file' ]
1317- validate_file_size (file )
1318- ext = validate_file_extension (file , settings .MEETING_VALID_AGENDA_EXTENSIONS )
1319- mime_type , encoding = validate_mime_type (file , settings .MEETING_VALID_AGENDA_MIME_TYPES )
1320- if ext in ['.html' , '.htm' ] or mime_type in ['text/html' , ]:
1321- validate_no_html_frame (file )
1322- return file
1323-
13241301def upload_session_agenda (request , session_id , num ):
13251302 # num is redundant, but we're dragging it along an artifact of where we are in the current URL structure
13261303 session = get_object_or_404 (Session ,pk = session_id )
@@ -1399,7 +1376,7 @@ def upload_session_agenda(request, session_id, num):
13991376 e = NewRevisionDocEvent .objects .create (doc = doc ,by = request .user .person ,type = 'new_revision' ,desc = 'New revision available: %s' % doc .rev ,rev = doc .rev )
14001377 doc .save_with_history ([e ])
14011378 # The way this function builds the filename it will never trigger the file delete in handle_file_upload.
1402- handle_upload_file (file , filename , session .meeting , 'agenda' )
1379+ handle_upload_file (file , filename , session .meeting , 'agenda' , request )
14031380 return redirect ('ietf.meeting.views.session_details' ,num = num ,acronym = session .group .acronym )
14041381 else :
14051382 form = UploadAgendaForm (show_apply_to_all_checkbox , initial = {'apply_to_all' :session .type_id == 'session' })
@@ -1412,23 +1389,16 @@ def upload_session_agenda(request, session_id, num):
14121389 })
14131390
14141391
1415- # FIXME: This form validation code (based on the secretariat upload code) only looks at filename extensions
1416- # It should look at the contents of the files instead.
1417- class UploadSlidesForm (forms .Form ):
1392+ class UploadSlidesForm (FileUploadForm ):
14181393 title = forms .CharField (max_length = 255 )
1419- file = forms .FileField (label = 'Slides file to upload.' )
14201394 apply_to_all = forms .BooleanField (label = 'Apply to all group sessions at this meeting' ,initial = False ,required = False )
14211395
14221396 def __init__ (self , show_apply_to_all_checkbox , * args , ** kwargs ):
1423- super (UploadSlidesForm , self ).__init__ (* args , ** kwargs )
1397+ kwargs ['doc_type' ] = 'slides'
1398+ super (UploadSlidesForm , self ).__init__ (* args , ** kwargs )
14241399 if not show_apply_to_all_checkbox :
14251400 self .fields .pop ('apply_to_all' )
14261401
1427- def clean_file (self ):
1428- file = self .cleaned_data ['file' ]
1429- validate_file_size (file )
1430- validate_file_extension (file , settings .MEETING_VALID_SLIDES_EXTENSIONS )
1431- return file
14321402
14331403def upload_session_slides (request , session_id , num , name ):
14341404 # num is redundant, but we're dragging it along an artifact of where we are in the current URL structure
0 commit comments