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 28, 2024
1 parent 7257825 commit db25e9e
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-28 09:00

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):
DOCUMENT_ARRETE = "arrete prefectoral ministériel", "Arrêté préfectoral/ministériel"
DOCUMENT_AUTRE = "autre", "Autre document"
DOCUMENT_CARTOGRAPHIE = "cartographie", "Cartographie"
DOCUMENT_CERTIFICAT_PHYTOSANITAIRE = "certificat phytosanitaire", "Certificat phytosanitaire"
DOCUMENT_COMPTE_RENDU_REUNION = "compte rendu reunion", "Compte rendu de réunion"
DOCUMENT_COURRIER_OFFICIEL = "courrier officiel", "Courrier officiel"
DOCUMENT_DSCE = "dsce", "DSCE"
DOCUMENT_FACTURE = "facture", "Facture"
DOCUMENT_IMAGE = "image", "Image"
DOCUMENT_PASSEPORT_PHYTOSANITAIRE = "passeport phytosanitaire", "Passeport phytosanitaire"
DOCUMENT_RAPPORT_ANALYSE = "rapport analyse", "Rapport d'analyse"
DOCUMENT_RAPPORT_INSPECTION = "rapport inspection", "Rapport d'inspection"
DOCUMENT_REGLEMENTATION = "reglementation", "Réglementation"
DOCUMENT_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 db25e9e

Please sign in to comment.