File tree Expand file tree Collapse file tree 2 files changed +7
-1
lines changed
Expand file tree Collapse file tree 2 files changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -130,7 +130,7 @@ class DocumentCreateForm(TranslationModelForm):
130130
131131 class Meta :
132132 model = Document
133- fields = ["title" , "doc_file" , "doc_url" ]
133+ fields = ["title" , "doc_file" , "doc_url" , "extension" ]
134134 widgets = {
135135 "name" : HiddenInput (attrs = {"cols" : 80 , "rows" : 20 }),
136136 }
@@ -159,6 +159,7 @@ def clean(self):
159159 cleaned_data = super ().clean ()
160160 doc_file = self .cleaned_data .get ("doc_file" )
161161 doc_url = self .cleaned_data .get ("doc_url" )
162+ extension = self .cleaned_data .get ("extension" )
162163
163164 if not doc_file and not doc_url and "doc_file" not in self .errors and "doc_url" not in self .errors :
164165 logger .error ("Document must be a file or url." )
@@ -168,6 +169,9 @@ def clean(self):
168169 logger .error ("A document cannot have both a file and a url." )
169170 raise forms .ValidationError (_ ("A document cannot have both a file and a url." ))
170171
172+ if extension :
173+ cleaned_data ["extension" ] = extension .replace ("." , "" )
174+
171175 return cleaned_data
172176
173177 def clean_doc_file (self ):
Original file line number Diff line number Diff line change @@ -173,6 +173,7 @@ def form_valid(self, form):
173173 owner = self .request .user ,
174174 doc_url = doc_form .pop ("doc_url" , None ),
175175 title = doc_form .pop ("title" , file .name ),
176+ extension = doc_form .pop ("extension" , None ),
176177 files = [storage_path ],
177178 ),
178179 )
@@ -186,6 +187,7 @@ def form_valid(self, form):
186187 owner = self .request .user ,
187188 doc_url = doc_form .pop ("doc_url" , None ),
188189 title = doc_form .pop ("title" , None ),
190+ extension = doc_form .pop ("extension" , None ),
189191 sourcetype = enumerations .SOURCE_TYPE_REMOTE ,
190192 ),
191193 )
You can’t perform that action at this time.
0 commit comments