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 955784fc45
commit ea4cbcffff
2 changed files with 16 additions and 4 deletions

View File

@ -83,13 +83,12 @@ def new_document_view(request: HttpRequest, id: str):
Returns: 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 template = form.template
if request.method == "POST": if request.method == "POST":
if form.is_valid(): if form.is_valid():
doc = form.save() doc = form.save()
intervention = get_object_or_404(Intervention, id=id)
intervention.documents.add(doc)
messages.success( messages.success(
request, request,
_("Document '{}' added").format(doc.title) _("Document '{}' added").format(doc.title)

View File

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