Skip to content

Commit

Permalink
[Fixes #11716] extension for remote document is not saved (#11717)
Browse files Browse the repository at this point in the history
* [Fixes #11716] extension for remote document is not saved

* [Fixes #11716] fix formatting
  • Loading branch information
mattiagiupponi committed Nov 23, 2023
1 parent a655d8d commit 7cac111
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion geonode/documents/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class DocumentCreateForm(TranslationModelForm):

class Meta:
model = Document
fields = ["title", "doc_file", "doc_url"]
fields = ["title", "doc_file", "doc_url", "extension"]
widgets = {
"name": HiddenInput(attrs={"cols": 80, "rows": 20}),
}
Expand Down Expand Up @@ -159,6 +159,7 @@ def clean(self):
cleaned_data = super().clean()
doc_file = self.cleaned_data.get("doc_file")
doc_url = self.cleaned_data.get("doc_url")
extension = self.cleaned_data.get("extension")

if not doc_file and not doc_url and "doc_file" not in self.errors and "doc_url" not in self.errors:
logger.error("Document must be a file or url.")
Expand All @@ -168,6 +169,9 @@ def clean(self):
logger.error("A document cannot have both a file and a url.")
raise forms.ValidationError(_("A document cannot have both a file and a url."))

if extension:
cleaned_data["extension"] = extension.replace(".", "")

return cleaned_data

def clean_doc_file(self):
Expand Down
2 changes: 2 additions & 0 deletions geonode/documents/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ def form_valid(self, form):
owner=self.request.user,
doc_url=doc_form.pop("doc_url", None),
title=doc_form.pop("title", file.name),
extension=doc_form.pop("extension", None),
files=[storage_path],
),
)
Expand All @@ -186,6 +187,7 @@ def form_valid(self, form):
owner=self.request.user,
doc_url=doc_form.pop("doc_url", None),
title=doc_form.pop("title", None),
extension=doc_form.pop("extension", None),
sourcetype=enumerations.SOURCE_TYPE_REMOTE,
),
)
Expand Down

0 comments on commit 7cac111

Please sign in to comment.