@@ -44,35 +44,30 @@ class BofreqUploadForm(forms.Form):
4444 bofreq_file = forms .FileField (label = "Markdown source file to upload" , required = False )
4545 bofreq_content = forms .CharField (widget = forms .Textarea (attrs = {'rows' :30 }), required = False , strip = False )
4646
47- def clean_bofreq_content (self ):
48- content = self .cleaned_data ["bofreq_content" ].replace ("\r " , "" )
49- default_content = render_to_string ('doc/bofreq/bofreq_template.md' ,{})
50- if content == default_content :
51- raise forms .ValidationError ('The example content may not be saved. Edit it as instructed to document this BOF request.' )
52- try :
53- _ = markdown .markdown (content , extensions = ['extra' ])
54- except Exception as e :
55- raise forms .ValidationError (f'Markdown processing failed: { e } ' )
56- return content
57-
58- def clean_bofreq_file (self ):
59- content = get_cleaned_text_file_content (self .cleaned_data ["bofreq_file" ])
60- try :
61- _ = markdown .markdown (content , extensions = ['extra' ])
62- except Exception as e :
63- raise forms .ValidationError (f'Markdown processing failed: { e } ' )
64- return content
65-
6647 def clean (self ):
6748 def require_field (f ):
6849 if not self .cleaned_data .get (f ):
6950 self .add_error (f , forms .ValidationError ("You must fill in this field." ))
51+ return False
52+ else :
53+ return True
7054
7155 submission_method = self .cleaned_data .get ("bofreq_submission" )
56+ content = ''
7257 if submission_method == "enter" :
73- require_field ("bofreq_content" )
58+ if require_field ("bofreq_content" ):
59+ content = self .cleaned_data ["bofreq_content" ].replace ("\r " , "" )
60+ default_content = render_to_string ('doc/bofreq/bofreq_template.md' ,{})
61+ if content == default_content :
62+ raise forms .ValidationError ('The example content may not be saved. Edit it as instructed to document this BOF request.' )
7463 elif submission_method == "upload" :
75- require_field ("bofreq_file" )
64+ if require_field ("bofreq_file" ):
65+ content = get_cleaned_text_file_content (self .cleaned_data ["bofreq_file" ])
66+ try :
67+ _ = markdown .markdown (content , extensions = ['extra' ])
68+ except Exception as e :
69+ raise forms .ValidationError (f'Markdown processing failed: { e } ' )
70+
7671
7772
7873@login_required
@@ -98,7 +93,7 @@ def submit(request, name):
9893 bofreq .save_with_history ([e ])
9994 bofreq_submission = form .cleaned_data ['bofreq_submission' ]
10095 if bofreq_submission == "upload" :
101- content = form .cleaned_data [' bofreq_file' ]
96+ content = get_cleaned_text_file_content ( form .cleaned_data [" bofreq_file" ])
10297 else :
10398 content = form .cleaned_data ['bofreq_content' ]
10499 with io .open (bofreq .get_file_name (), 'w' , encoding = 'utf-8' ) as destination :
@@ -168,7 +163,7 @@ def new_bof_request(request):
168163 alias .docs .set ([bofreq ])
169164 bofreq_submission = form .cleaned_data ['bofreq_submission' ]
170165 if bofreq_submission == "upload" :
171- content = form .cleaned_data [' bofreq_file' ]
166+ content = get_cleaned_text_file_content ( form .cleaned_data [" bofreq_file" ])
172167 else :
173168 content = form .cleaned_data ['bofreq_content' ]
174169 with io .open (bofreq .get_file_name (), 'w' , encoding = 'utf-8' ) as destination :
0 commit comments