<commit_before>from django import forms
from django.core import validators
from django.core.exceptions import ValidationError
from django.core.validators import MaxValueValidator
from django.db.models import Sum
from django.urls import reverse
from django.utils import timezone
from django.utils.html import format_html, format_html_join

from agir.events.models import Event
from agir.gestion.admin.widgets import HierarchicalSelect, SuggestingTextInput
from agir.gestion.models import (
    Commentaire,
    Depense,
    Fournisseur,
    Projet,
    Reglement,
)
from agir.gestion.models.documents import Document, VersionDocument
from agir.gestion.models.commentaires import ajouter_commentaire
from agir.gestion.typologies import TypeDocument, TypeDepense, NATURE


class DocumentForm(forms.ModelForm):
    titre_version = forms.CharField(
        label="Nom de la version",
        required=False,
    )
    fichier = forms.FileField(label="Fichier de la version", required=True)

    def clean(self):
        cleaned_data = super().clean()

        if cleaned_data.get("titre_version") and not cleaned_data.get("fichier"):
            self.add_error(
                "fichier",<commit_msg>fix(gestion document): champ fichier pas obligatoire<commit_after>from django import forms
from django.core import validators
from django.core.exceptions import ValidationError
from django.core.validators import MaxValueValidator
from django.db.models import Sum
from django.urls import reverse
from django.utils import timezone
from django.utils.html import format_html, format_html_join

from agir.events.models import Event
from agir.gestion.admin.widgets import HierarchicalSelect, SuggestingTextInput
from agir.gestion.models import (
    Commentaire,
    Depense,
    Fournisseur,
    Projet,
    Reglement,
)
from agir.gestion.models.documents import Document, VersionDocument
from agir.gestion.models.commentaires import ajouter_commentaire
from agir.gestion.typologies import TypeDocument, TypeDepense, NATURE


class DocumentForm(forms.ModelForm):
    titre_version = forms.CharField(
        label="Nom de la version",
        required=False,
    )
    fichier = forms.FileField(label="Fichier de la version", required=False)

    def clean(self):
        cleaned_data = super().clean()

        if cleaned_data.get("titre_version") and not cleaned_data.get("fichier"):
            self.add_error(
                "fichier",
{'fraction_non_alphanumeric': 0.07448559670781893, 'fraction_numerical': 0.0, 'mean_word_length': 4.216738197424893, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7457345', 'n_tokens_mistral': 696, 'n_tokens_neox': 687, 'n_words': 186}