Skip to content

Commit

Permalink
Ajouter des nouveaux types de documents
Browse files Browse the repository at this point in the history
  • Loading branch information
Anto59290 committed Oct 31, 2024
1 parent 7257825 commit eae1ad5
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 9 deletions.
2 changes: 1 addition & 1 deletion core/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self, *args, **kwargs):
self.queryset.values_list("document_type", flat=True).order_by("document_type").distinct("document_type")
)
self.filters["document_type"].extra["choices"] = [
(k, v) for (k, v) in Document.DOCUMENT_TYPE_CHOICES if k in actual_document_types
(k, v) for (k, v) in Document.TypeDocument.choices if k in actual_document_types
]

structure_queryset = Structure.objects.filter(
Expand Down
13 changes: 9 additions & 4 deletions core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class DocumentUploadForm(DSFRForm, WithNextUrlMixin, WithContentTypeMixin, forms
nom = forms.CharField(
help_text="Nommer le document de manière claire et compréhensible pour tous", label="Intitulé du document"
)
document_type = forms.ChoiceField(choices=Document.DOCUMENT_TYPE_CHOICES, label="Type de document")
document_type = forms.ChoiceField(choices=Document.TypeDocument, label="Type de document")
description = forms.CharField(
widget=forms.Textarea(attrs={"cols": 30, "rows": 4}), label="Commentaire - facultatif", required=False
)
Expand All @@ -73,7 +73,7 @@ class DocumentEditForm(DSFRForm, forms.ModelForm):
nom = forms.CharField(
help_text="Nommer le document de manière claire et compréhensible pour tous", label="Intitulé du document"
)
document_type = forms.ChoiceField(choices=Document.DOCUMENT_TYPE_CHOICES, label="Type de document")
document_type = forms.ChoiceField(choices=Document.TypeDocument, label="Type de document")
description = forms.CharField(
widget=forms.Textarea(attrs={"cols": 30, "rows": 4}), label="Commentaire - facultatif", required=False
)
Expand Down Expand Up @@ -164,7 +164,7 @@ def _add_files_inputs(self, data, files):
raise ValidationError("Il n'y a pas le même nombre de documents et de type de documents.")

for key, value in document_types.items():
self.fields[key] = forms.ChoiceField(initial=value, choices=Document.DOCUMENT_TYPE_CHOICES)
self.fields[key] = forms.ChoiceField(initial=value, choices=Document.TypeDocument)
document_number = key.split("_")[-1]
document_field = forms.FileField(initial=documents[f"document_file_{document_number}"])
self.fields[f"document_{document_number}"] = document_field
Expand Down Expand Up @@ -220,7 +220,12 @@ def clean(self):

class MessageDocumentForm(DSFRForm, forms.ModelForm):
document_type = forms.ChoiceField(
choices=(("", ""),) + Document.DOCUMENT_TYPE_CHOICES, label="Type de document", required=False
choices=[
("", ""),
]
+ Document.TypeDocument.choices,
label="Type de document",
required=False,
)
file = forms.FileField(
label="Ajouter un Document", required=False, widget=forms.FileInput(attrs={"disabled": True})
Expand Down
39 changes: 39 additions & 0 deletions core/migrations/0017_alter_document_document_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Generated by Django 5.0.3 on 2024-10-31 05:28

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("core", "0016_alter_message_message_type_finsuivicontact_and_more"),
]

operations = [
migrations.AlterField(
model_name="document",
name="document_type",
field=models.CharField(
choices=[
(
"arrete_prefectoral_ministériel",
"Arrêté préfectoral/ministériel",
),
("autre", "Autre document"),
("cartographie", "Cartographie"),
("certificat_phytosanitaire", "Certificat phytosanitaire"),
("compte_rendu_reunion", "Compte rendu de réunion"),
("courrier_officiel", "Courrier officiel"),
("dsce", "DSCE"),
("facture", "Facture"),
("image", "Image"),
("passeport_phytosanitaire", "Passeport phytosanitaire"),
("rapport_analyse", "Rapport d'analyse"),
("rapport_inspection", "Rapport d'inspection"),
("reglementation", "Réglementation"),
("document_de_transport", "Document de transport"),
],
max_length=100,
verbose_name="Type de document",
),
),
]
20 changes: 16 additions & 4 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,25 @@ def clean(self):


class Document(models.Model):
DOCUMENT_AUTRE = "autre"
DOCUMENT_CARTOGRAPHIE = "cartographie"
DOCUMENT_TYPE_CHOICES = ((DOCUMENT_CARTOGRAPHIE, "Cartographie"), (DOCUMENT_AUTRE, "Autre document"))
class TypeDocument(models.TextChoices):
ARRETE = "arrete_prefectoral_ministériel", "Arrêté préfectoral/ministériel"
AUTRE = "autre", "Autre document"
CARTOGRAPHIE = "cartographie", "Cartographie"
CERTIFICAT_PHYTOSANITAIRE = "certificat_phytosanitaire", "Certificat phytosanitaire"
COMPTE_RENDU_REUNION = "compte_rendu_reunion", "Compte rendu de réunion"
COURRIER_OFFICIEL = "courrier_officiel", "Courrier officiel"
DSCE = "dsce", "DSCE"
FACTURE = "facture", "Facture"
IMAGE = "image", "Image"
PASSEPORT_PHYTOSANITAIRE = "passeport_phytosanitaire", "Passeport phytosanitaire"
RAPPORT_ANALYSE = "rapport_analyse", "Rapport d'analyse"
RAPPORT_INSPECTION = "rapport_inspection", "Rapport d'inspection"
REGLEMENTATION = "reglementation", "Réglementation"
TRANSPORT = "document_de_transport", "Document de transport"

nom = models.CharField(max_length=256)
description = models.TextField()
document_type = models.CharField(max_length=100, choices=DOCUMENT_TYPE_CHOICES, verbose_name="Type de document")
document_type = models.CharField(max_length=100, choices=TypeDocument.choices, verbose_name="Type de document")
file = models.FileField(upload_to="")
date_creation = models.DateTimeField(auto_now_add=True, verbose_name="Date de création")
is_deleted = models.BooleanField(default=False)
Expand Down

0 comments on commit eae1ad5

Please sign in to comment.