Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajouter des nouveaux types de documents #268

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -52,7 +52,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 @@ -74,7 +74,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 @@ -165,7 +165,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 @@ -243,7 +243,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/0019_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-11-12 10:05

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("core", "0018_alter_document_file"),
]

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 @@ -128,13 +128,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=get_timestamped_filename)
date_creation = models.DateTimeField(auto_now_add=True, verbose_name="Date de création")
is_deleted = models.BooleanField(default=False)
Expand Down