Skip to content

Commit

Permalink
Ajout d'une pièce jointe aux évènements
Browse files Browse the repository at this point in the history
  • Loading branch information
syldb committed Sep 5, 2024
1 parent e8cbfb9 commit 53e36a3
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 8 deletions.
5 changes: 5 additions & 0 deletions conventions/forms/evenement.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ class EvenementForm(forms.Form):
label="Type d'évènement",
choices=TypeEvenement.choices,
)
piece_jointe = forms.CharField(required=False, label="Fichier joint")
piece_jointe_files = forms.CharField(
required=False,
help_text="Les fichiers de type docx sont acceptés dans la limite de 100 Mo",
)
18 changes: 18 additions & 0 deletions conventions/migrations/0093_evenement_piece_jointe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.13 on 2024-09-05 07:52

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("conventions", "0092_remove_pret_convention_alter_pret_lot"),
]

operations = [
migrations.AddField(
model_name="evenement",
name="piece_jointe",
field=models.TextField(blank=True),
),
]
1 change: 1 addition & 0 deletions conventions/models/evenement.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Evenement(models.Model):
)
survenu_le = models.DateField(editable=False)
description = models.TextField(null=True, blank=True)
piece_jointe = models.TextField(blank=True)

def save(
self, force_insert=False, force_update=False, using=None, update_fields=None
Expand Down
27 changes: 25 additions & 2 deletions conventions/views/conventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
currentrole_campaign_permission_required_view_function,
currentrole_permission_required,
)
from conventions.services import convention_generator
from conventions.services import convention_generator, utils
from conventions.services.avenants import create_avenant
from conventions.services.convention_generator import fiche_caf_doc
from conventions.services.conventions import convention_post_action
Expand Down Expand Up @@ -667,23 +667,46 @@ def journal(request, convention_uuid):
uuid=selected.uuid,
description=selected.description,
type_evenement=selected.type_evenement,
**utils.get_text_and_files_from_field(
"piece_jointe",
selected.piece_jointe,
),
)
)
# Handle submitted data
if action == "submit":
form = EvenementForm(request.POST)
form = EvenementForm(
{
"uuid": request.POST.get("uuid"),
"description": request.POST.get("description"),
"type_evenement": request.POST.get("type_evenement"),
**utils.init_text_and_files_from_field(
request, None, "piece_jointe"
),
}
)
if form.is_valid():
if form.cleaned_data["uuid"] is not None:
evenement = Evenement.objects.get(uuid=form.cleaned_data["uuid"])
evenement.description = form.cleaned_data["description"]
evenement.type_evenement = form.cleaned_data["type_evenement"]
evenement.piece_jointe = utils.set_files_and_text_field(
form.cleaned_data["piece_jointe_files"],
form.cleaned_data["piece_jointe"],
)
evenement.save()
else:
Evenement.objects.create(
evenement = Evenement.objects.create(
convention=convention,
description=form.cleaned_data["description"],
type_evenement=form.cleaned_data["type_evenement"],
)
evenement.piece_jointe = utils.set_files_and_text_field(
form.cleaned_data["piece_jointe_files"],
form.cleaned_data["piece_jointe"],
)
evenement.save()

return render(
request,
Expand Down
2 changes: 1 addition & 1 deletion templates/common/form/input_upload.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="fr-col-12 fr-col-md-12 fr-col-lg-6 fr-mb-2w">
{% endif %}
<div class="block--row-strech" id="{{form_input.id_for_label}}_div">
{% if not override_cerfa %}
{% if not no_title %}
<label class="block--row-strech-1 fr-label fr-mt-1w fr-mb-2w fr-h4" for="{{form_input.id_for_label}}">
{{ form_input.label }}
{% if additional_informations %}
Expand Down
2 changes: 1 addition & 1 deletion templates/conventions/finalisation/cerfa.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ <h3 class="fr-accordion__title">
</div>
<form id="cerfa-form" method="post" action="{% url 'conventions:finalisation_cerfa' convention_uuid=convention.uuid %}" data-turbo="false">
{% csrf_token %}
{% include "common/form/input_upload.html" with form_input=form.fichier_override_cerfa form_input_files=form.fichier_override_cerfa_files object_name='convention' single_file=True override_cerfa=True object_uuid=convention.uuid file_list=convention.fichier_override_cerfa|get_files_from_textfiles object_field="convention__fichier_override_cerfa__"|add:form.uuid.value %}
{% include "common/form/input_upload.html" with form_input=form.fichier_override_cerfa form_input_files=form.fichier_override_cerfa_files object_name='convention' single_file=True override_cerfa=True no_title=True object_uuid=convention.uuid file_list=convention.fichier_override_cerfa|get_files_from_textfiles object_field="convention__fichier_override_cerfa__"|add:form.uuid.value %}
</form>
</div>
</section>
Expand Down
29 changes: 25 additions & 4 deletions templates/conventions/journal.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@

{% load static %}

{% block javascript_extras %}
<script src="{% static "dropzonejs/min/dropzone.min.js" %}" nonce="{{request.csp_nonce}}"></script>
<script src="{% static "dropzonejs/min/dropzone-amd-module.min.js" %}" nonce="{{request.csp_nonce}}"></script>
<script src="{% static "js/dropzone-client.js" %}" nonce="{{request.csp_nonce}}"></script>
<script src="{% static "js/comment-factory.js" %}" nonce="{{request.csp_nonce}}"></script>
{% endblock %}

{% block css_extras %}
<link rel="stylesheet" href="{% static "dropzonejs/min/basic.min.css" %}">
<link rel="stylesheet" href="{% static "dropzonejs/min/dropzone.min.css" %}">
{% endblock %}

{% block content %}
<div class="fr-container-fluid ds_banner">
{% include "conventions/common/form_header.html"%}
Expand All @@ -20,11 +32,13 @@ <h2 class="fr-text--lg">Ajouter un évènement au journal</h2>
<div class="fr-col-12 fr-mb-2w">
{% include "common/form/input_select.html" with form_input=form.type_evenement editable=True %}
</div>

<div class="fr-col-12 fr-mb-4w">
<div class="fr-col-12 fr-mb-2w">
{% include "common/form/input_textarea.html" with form_input=form.description editable=True %}
</div>

<div class="fr-col-12 fr-mb-4w">
<label class="fr-label">Ajouter un fichier (optionnel)</label>
{% include "common/form/input_upload.html" with no_title=True form_input=form.piece_jointe form_input_files=form.piece_jointe_files object_name='convention' single_file=True object_uuid=convention.uuid file_list=evenement.piece_jointe|get_files_from_textfiles object_field="evenement__piece_jointe__"|add:form.uuid.value %}
</div>
<div class="fr-grid-row fr-grid-row--right">
<div class="fr-mr-4w fr-mt-1w">
<a class="fr-link" href={% url 'conventions:journal' convention_uuid=convention.uuid %}>Annuler</a>
Expand Down Expand Up @@ -65,9 +79,13 @@ <h2 class="fr-mr-2w fr-text--lg">Modifier l'évènement du {{ evenement.survenu_
{% include "common/form/input_select.html" with form_input=form.type_evenement editable=True %}
</div>

<div class="fr-col-12 fr-mb-4w">
<div class="fr-col-12 fr-mb-2w">
{% include "common/form/input_textarea.html" with form_input=form.description editable=True %}
</div>
<div class="fr-col-12 fr-mb-4w">
<label class="fr-label">Ajouter un fichier (optionnel)</label>
{% include "common/form/input_upload.html" with no_title=True form_input=form.piece_jointe form_input_files=form.piece_jointe_files object_name='convention' single_file=True object_uuid=convention.uuid file_list=evenement.piece_jointe|get_files_from_textfiles object_field="evenement__piece_jointe__"|add:form.uuid.value %}
</div>
</div>
<div class="fr-grid-row fr-grid-row--right">
<div class="fr-mr-4w fr-mt-2w">
Expand Down Expand Up @@ -100,6 +118,9 @@ <h2 class="fr-mr-2w fr-text--lg">Modifier l'évènement du {{ evenement.survenu_
</div>
</div>
<div class="fr-col-12 fr-ml-4w">{{ evenement.description|linebreaksbr }}</div>
<div class="fr-col-12 fr-ml-4w">
{% include "common/display_text_and_files_if_exists.html" with label="Fichier joint" text=evenement.piece_jointe|get_text_from_textfiles file_list=evenement.piece_jointe|get_files_from_textfiles object_field="evenement__piece_jointe__"|add:evenement.uuid %}
</div>
</div>
</div>
{% endif %}
Expand Down

0 comments on commit 53e36a3

Please sign in to comment.