File tree 2 files changed +7
-1
lines changed
2 files changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -130,7 +130,7 @@ class DocumentCreateForm(TranslationModelForm):
130
130
131
131
class Meta :
132
132
model = Document
133
- fields = ["title" , "doc_file" , "doc_url" ]
133
+ fields = ["title" , "doc_file" , "doc_url" , "extension" ]
134
134
widgets = {
135
135
"name" : HiddenInput (attrs = {"cols" : 80 , "rows" : 20 }),
136
136
}
@@ -159,6 +159,7 @@ def clean(self):
159
159
cleaned_data = super ().clean ()
160
160
doc_file = self .cleaned_data .get ("doc_file" )
161
161
doc_url = self .cleaned_data .get ("doc_url" )
162
+ extension = self .cleaned_data .get ("extension" )
162
163
163
164
if not doc_file and not doc_url and "doc_file" not in self .errors and "doc_url" not in self .errors :
164
165
logger .error ("Document must be a file or url." )
@@ -168,6 +169,9 @@ def clean(self):
168
169
logger .error ("A document cannot have both a file and a url." )
169
170
raise forms .ValidationError (_ ("A document cannot have both a file and a url." ))
170
171
172
+ if extension :
173
+ cleaned_data ["extension" ] = extension .replace ("." , "" )
174
+
171
175
return cleaned_data
172
176
173
177
def clean_doc_file (self ):
Original file line number Diff line number Diff line change @@ -173,6 +173,7 @@ def form_valid(self, form):
173
173
owner = self .request .user ,
174
174
doc_url = doc_form .pop ("doc_url" , None ),
175
175
title = doc_form .pop ("title" , file .name ),
176
+ extension = doc_form .pop ("extension" , None ),
176
177
files = [storage_path ],
177
178
),
178
179
)
@@ -186,6 +187,7 @@ def form_valid(self, form):
186
187
owner = self .request .user ,
187
188
doc_url = doc_form .pop ("doc_url" , None ),
188
189
title = doc_form .pop ("title" , None ),
190
+ extension = doc_form .pop ("extension" , None ),
189
191
sourcetype = enumerations .SOURCE_TYPE_REMOTE ,
190
192
),
191
193
)
You can’t perform that action at this time.
0 commit comments