<commit_before>from django import forms
from django.conf import settings
from geotrek.common.forms import CommonForm
from geotrek.core.forms import TopologyForm

from leaflet.forms.widgets import LeafletWidget

from .models import Infrastructure
from django.utils.translation import gettext_lazy as _

from crispy_forms.layout import Div

if settings.TREKKING_TOPOLOGY_ENABLED:
    class BaseInfrastructureForm(TopologyForm):
        implantation_year = forms.IntegerField(label=_("Implantation year"), required=False)

        class Meta(TopologyForm.Meta):
            fields = TopologyForm.Meta.fields + \
                ['structure', 'name', 'description', 'type', 'condition', 'published']
else:
    class BaseInfrastructureForm(CommonForm):

        implantation_year = forms.IntegerField(label=_("Implantation year"), required=False)
        geomfields = ['geom']

        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
            modifiable = self.fields['geom'].widget.modifiable
            self.fields['geom'].widget = LeafletWidget(attrs={'geom_type': 'POINT'})
            self.fields['geom'].widget.modifiable = modifiable

        class Meta(CommonForm.Meta):
            model = Infrastructure
            fields = CommonForm.Meta.fields + ['geom', 'structure', 'name', 'description', 'type', 'condition',
                                               'implantation_year', 'published']


class InfrastructureForm(BaseInfrastructureForm):

    fieldslayout = [<commit_msg>Fix infrastructure form<commit_after>from django import forms
from django.conf import settings
from geotrek.common.forms import CommonForm
from geotrek.core.forms import TopologyForm

from leaflet.forms.widgets import LeafletWidget

from .models import Infrastructure
from django.utils.translation import gettext_lazy as _

from crispy_forms.layout import Div

if settings.TREKKING_TOPOLOGY_ENABLED:
    class BaseInfrastructureForm(TopologyForm):
        implantation_year = forms.IntegerField(label=_("Implantation year"), required=False)

        class Meta(TopologyForm.Meta):
            fields = TopologyForm.Meta.fields + \
                ['structure', 'name', 'description', 'type', 'condition', 'implantation_year', 'published']
else:
    class BaseInfrastructureForm(CommonForm):

        implantation_year = forms.IntegerField(label=_("Implantation year"), required=False)
        geomfields = ['geom']

        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
            modifiable = self.fields['geom'].widget.modifiable
            self.fields['geom'].widget = LeafletWidget(attrs={'geom_type': 'POINT'})
            self.fields['geom'].widget.modifiable = modifiable

        class Meta(CommonForm.Meta):
            model = Infrastructure
            fields = CommonForm.Meta.fields + ['geom', 'structure', 'name', 'description', 'type', 'condition',
                                               'implantation_year', 'published']


class InfrastructureForm(BaseInfrastructureForm):

    fieldslayout = [
{'fraction_non_alphanumeric': 0.10930911449886474, 'fraction_numerical': 0.0, 'mean_word_length': 3.3559322033898304, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2245679', 'n_tokens_mistral': 828, 'n_tokens_neox': 797, 'n_words': 183}