Document upload fix

* fixes some minor issues with the document upload
This commit is contained in:
mipel 2021-07-26 15:34:30 +02:00
parent 1ff02c30a6
commit 09fad6a2de
2 changed files with 16 additions and 4 deletions

View File

@ -83,13 +83,12 @@ def new_document_view(request: HttpRequest, id: str):
Returns:
"""
form = NewDocumentForm(request.POST, request.FILES, user=request.user)
intervention = get_object_or_404(Intervention, id=id)
form = NewDocumentForm(request.POST or None, request.FILES or None, instance=intervention, user=request.user)
template = form.template
if request.method == "POST":
if form.is_valid():
doc = form.save()
intervention = get_object_or_404(Intervention, id=id)
intervention.documents.add(doc)
messages.success(
request,
_("Document '{}' added").format(doc.title)

View File

@ -177,6 +177,8 @@ class NewDocumentForm(BaseModalForm):
"""
title = forms.CharField(
label=_("Title"),
label_suffix=_(""),
max_length=500,
)
creation_date = forms.DateField(
@ -195,13 +197,23 @@ class NewDocumentForm(BaseModalForm):
label=_("File"),
label_suffix=_(""),
help_text=_("Must be smaller than 15 Mb"),
widget=forms.FileInput(
attrs={
"class": "w-75"
}
)
)
comment = forms.CharField(
required=False,
label=_("Comment"),
label_suffix=_(""),
help_text=_("Additional comment on this file"),
widget=forms.Textarea()
widget=forms.Textarea(
attrs={
"cols": 30,
"rows": 5,
}
)
)
def __init__(self, *args, **kwargs):
@ -222,4 +234,5 @@ class NewDocumentForm(BaseModalForm):
document=self.cleaned_data["file"],
date_of_creation=self.cleaned_data["creation_date"],
)
self.instance.documents.add(doc)
return doc