We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Formulaire INTERVENTIONS - Onglet Avancé
Le référent SENTIERS préférerait que les champs COUTS et JOURS/HOMME soient affichés à la suite du formulaire plutôt que dans un onglet AVANCE car cela à revenir en haut du formulaire après avoir saisi les infos de base et du coup de nombreux agents passent à côté de la saisie de cette information.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `geotrek/trekking/forms.py`
Content:
```
1 from django.utils.translation import ugettext as _
2 from django.conf import settings
3 from django.forms.models import inlineformset_factory
4 
5 import floppyforms as forms
6 from crispy_forms.helper import FormHelper
7 from crispy_forms.bootstrap import FormActions
8 from crispy_forms.layout import Layout, Submit, HTML, Div, Fieldset
9 from mapentity.widgets import SelectMultipleWithPop
10 
11 from geotrek.core.forms import TopologyForm
12 from geotrek.core.widgets import LineTopologyWidget, PointTopologyWidget
13 from .models import Trek, POI, WebLink
14 
15 
16 class TrekRelationshipForm(forms.ModelForm):
17 
18     def __init__(self, *args, **kwargs):
19         super(TrekRelationshipForm, self).__init__(*args, **kwargs)
20         self.helper = FormHelper()
21         self.helper.form_tag = False
22         self.helper.layout = Layout('id',
23                                     'trek_a',
24                                     'trek_b',
25                                     'has_common_departure',
26                                     'has_common_edge',
27                                     'is_circuit_step',
28                                     'DELETE')
29 
30 TrekRelationshipFormSet = inlineformset_factory(Trek, Trek.related_treks.through, form=TrekRelationshipForm, fk_name='trek_a', extra=1)
31 
32 
33 class TrekForm(TopologyForm):
34     fieldslayout = [
35         Div(
36             HTML("""
37             <ul class="nav nav-tabs">
38                 <li id="tab-main" class="active"><a href="#main" data-toggle="tab"><i class="icon-certificate"></i> %s</a></li>
39                 <li id="tab-advanced"><a href="#advanced" data-toggle="tab"><i class="icon-tasks"></i> %s</a></li>
40             </ul>""" % (unicode(_("Main")), unicode(_("Advanced")))),
41             Div(
42                 Div('name',
43                     'published',
44                     'is_park_centered',
45                     'departure',
46                     'arrival',
47                     'duration',
48                     'difficulty',
49                     'route',
50                     'ambiance',
51                     'access',
52                     'description_teaser',
53                     'description',
54 
55                     'pk',
56                     'model',
57 
58                     css_id="main",
59                     css_class="tab-pane active"
60                 ),
61                 Div(
62                     'disabled_infrastructure',
63                     'advised_parking',
64                     'parking_location',
65                     'public_transport',
66                     'advice',
67                     'themes',
68                     'networks',
69                     'usages',
70                     'web_links',
71                     'information_desk',
72                     Fieldset(_("Related treks"),),
73                     css_id="advanced",  # used in Javascript for activating tab if error
74                     css_class="tab-pane"
75                 ),
76                 css_class="tab-content"
77             ),
78             css_class="tabbable"
79         ),
80     ]
81 
82     def __init__(self, *args, **kwargs):
83         super(TrekForm, self).__init__(*args, **kwargs)
84         self.fields['topology'].widget = LineTopologyWidget()
85         self.fields['web_links'].widget = SelectMultipleWithPop(choices=self.fields['web_links'].choices,
86                                                                 add_url=WebLink.get_add_url())
87         # Make sure (force) that name is required, in default language only
88         self.fields['name_%s' % settings.LANGUAGE_CODE].required = True
89 
90     class Meta(TopologyForm.Meta):
91         model = Trek
92         fields = TopologyForm.Meta.fields + \
93             ['name', 'published', 'is_park_centered', 'departure', 'arrival', 'duration', 'difficulty',
94              'route', 'ambiance', 'access', 'description_teaser', 'description',
95              'disabled_infrastructure', 'advised_parking', 'parking_location', 'public_transport', 'advice',
96              'themes', 'networks', 'usages', 'web_links', 'information_desk']
97 
98 
99 class POIForm(TopologyForm):
100     fieldslayout = [
101         Div('pk',
102             'model',
103 
104             'type',
105             'name',
106             'description',
107 
108             css_class="tab-content"
109         )
110     ]
111 
112     def __init__(self, *args, **kwargs):
113         super(POIForm, self).__init__(*args, **kwargs)
114         self.fields['topology'].widget = PointTopologyWidget()
115 
116     class Meta(TopologyForm.Meta):
117         model = POI
118         fields = TopologyForm.Meta.fields + ['name', 'description', 'type']
119 
120 
121 class WebLinkCreateFormPopup(forms.ModelForm):
122 
123     def __init__(self, *args, **kwargs):
124         super(WebLinkCreateFormPopup, self).__init__(*args, **kwargs)
125         self.helper = FormHelper()
126         self.helper.form_action = self.instance.get_add_url()
127         # Main form layout
128         # Adds every name field explicitly (name_fr, name_en, ...)
129         self.helper.form_class = 'form-horizontal'
130         arg_list = ['name_{0}'.format(l[0]) for l in settings.MAPENTITY_CONFIG['TRANSLATED_LANGUAGES']]
131         arg_list += ['url', 'category', FormActions(
132             HTML('<a href="#" class="btn" onclick="javascript:window.close();">%s</a>' % _("Cancel")),
133             Submit('save_changes', _('Create'), css_class="btn-primary"),
134             css_class="form-actions",
135         )]
136         self.helper.layout = Layout(*arg_list)
137 
138     class Meta:
139         model = WebLink
140         fields = ['name_{0}'.format(l[0]) for l in settings.MAPENTITY_CONFIG['TRANSLATED_LANGUAGES']] + \
141                  ['url', 'category']
142
```

Path: `geotrek/maintenance/forms.py`
Content:
```
1 from django import forms
2 from django.forms import FloatField
3 from django.utils.translation import ugettext_lazy as _
4 from django.forms.models import inlineformset_factory
5 
6 from crispy_forms.helper import FormHelper
7 from crispy_forms.layout import Fieldset, Layout, Div, HTML
8 
9 from geotrek.common.forms import CommonForm
10 from geotrek.core.fields import TopologyField
11 from geotrek.core.forms import TopologyForm
12 from geotrek.core.widgets import TopologyReadonlyWidget
13 from geotrek.infrastructure.models import BaseInfrastructure
14 
15 from .models import Intervention, Project
16 
17 
18 class ManDayForm(forms.ModelForm):
19 
20     def __init__(self, *args, **kwargs):
21         super(ManDayForm, self).__init__(*args, **kwargs)
22         self.helper = FormHelper()
23         self.helper.form_tag = False
24         self.helper.layout = Layout('id', 'nb_days', 'job')
25         self.fields['nb_days'].widget.attrs['placeholder'] = _('Days')
26         self.fields['nb_days'].label = ''
27         self.fields['nb_days'].widget.attrs['class'] = 'input-mini'
28         self.fields['job'].widget.attrs['class'] = 'input-medium'
29 
30 
31 ManDayFormSet = inlineformset_factory(Intervention, Intervention.jobs.through, form=ManDayForm, extra=1)
32 
33 
34 class FundingForm(forms.ModelForm):
35 
36     def __init__(self, *args, **kwargs):
37         super(FundingForm, self).__init__(*args, **kwargs)
38         self.helper = FormHelper()
39         self.helper.form_tag = False
40         self.helper.layout = Layout('id', 'amount', 'organism')
41         self.fields['organism'].widget.attrs['class'] = 'input-xlarge'
42 
43 
44 FundingFormSet = inlineformset_factory(Project, Project.founders.through, form=FundingForm, extra=1)
45 
46 
47 class InterventionForm(CommonForm):
48     """ An intervention can be a Point or a Line """
49     topology = TopologyField(label="")
50     infrastructure = forms.ModelChoiceField(required=False,
51                                             queryset=BaseInfrastructure.objects.existing(),
52                                             widget=forms.HiddenInput())
53     length = FloatField(required=False, label=_("Length"))
54     fieldslayout = [
55         Div(
56             HTML("""
57             <ul class="nav nav-tabs">
58                 <li id="tab-main" class="active"><a href="#main" data-toggle="tab"><i class="icon-certificate"></i> %s</a></li>
59                 <li id="tab-advanced"><a href="#advanced" data-toggle="tab"><i class="icon-tasks"></i> %s</a></li>
60             </ul>""" % (unicode(_("Main")), unicode(_("Advanced")))),
61             Div(
62                 Div('name',
63                     'date',
64                     'status',
65                     'disorders',
66                     'type',
67                     'comments',
68                     'subcontracting',
69                     'length',
70                     'width',
71                     'height',
72                     'stake',
73                     'project',
74                     'infrastructure',
75 
76                     'pk',
77                     'model',
78 
79                     css_id="main",
80                     css_class="tab-pane active"
81                 ),
82                 Div(
83                     'material_cost',
84                     'heliport_cost',
85                     'subcontract_cost',
86                     Fieldset(_("Mandays")),
87                     css_id="advanced",  # used in Javascript for activating tab if error
88                     css_class="tab-pane"
89                 ),
90                 css_class="tab-content"
91             ),
92             css_class="tabbable"
93         ),
94     ]
95 
96     geomfields = ['topology']
97 
98     class Meta(CommonForm.Meta):
99         model = Intervention
100         fields = CommonForm.Meta.fields + \
101             ['structure',
102              'name', 'date', 'status', 'disorders', 'type', 'comments', 'subcontracting', 'length', 'width',
103              'height', 'stake', 'project', 'infrastructure', 'material_cost', 'heliport_cost', 'subcontract_cost',
104              'topology']
105 
106     def __init__(self, *args, **kwargs):
107         super(InterventionForm, self).__init__(*args, **kwargs)
108         # If we create or edit an intervention on infrastructure, set
109         # topology field as read-only
110         infrastructure = kwargs.get('initial', {}).get('infrastructure')
111         if self.instance.on_infrastructure:
112             infrastructure = self.instance.infrastructure
113             self.fields['infrastructure'].initial = infrastructure
114         if infrastructure:
115             self.helper.form_action += '?infrastructure=%s' % infrastructure.pk
116             self.fields['topology'].required = False
117             self.fields['topology'].widget = TopologyReadonlyWidget()
118             self.fields['topology'].label = '%s%s %s' % (
119                 self.instance.infrastructure_display,
120                 unicode(_("On %s") % _(infrastructure.kind.lower())),
121                 u'<a href="%s">%s</a>' % (infrastructure.get_detail_url(), unicode(infrastructure))
122             )
123         # Length is not editable in AltimetryMixin
124         self.fields['length'].initial = self.instance.length
125         editable = bool(self.instance.geom and self.instance.geom.geom_type == 'Point')
126         self.fields['length'].widget.attrs['readonly'] = editable
127 
128     def clean(self, *args, **kwargs):
129         # If topology was read-only, topology field is empty, get it from infra.
130         cleaned_data = super(InterventionForm, self).clean()
131         topology_readonly = self.cleaned_data.get('topology', None) is None
132         if topology_readonly and 'infrastructure' in self.cleaned_data:
133             self.cleaned_data['topology'] = self.cleaned_data['infrastructure']
134         return cleaned_data
135 
136     def save(self, *args, **kwargs):
137         self.instance.length = self.cleaned_data.get('length')
138         infrastructure = self.cleaned_data.get('infrastructure')
139         if infrastructure:
140             self.instance.set_infrastructure(infrastructure)
141         return super(InterventionForm, self).save(*args, **kwargs)
142 
143 
144 class InterventionCreateForm(InterventionForm):
145     def __init__(self, *args, **kwargs):
146         # If we create an intervention on infrastructure, get its topology
147         initial = kwargs.get('initial', {})
148         infrastructure = initial.get('infrastructure')
149         if infrastructure:
150             initial['topology'] = infrastructure
151         kwargs['initial'] = initial
152         super(InterventionCreateForm, self).__init__(*args, **kwargs)
153         # Stake is computed automatically at creation.
154         self.fields['stake'].required = False
155 
156 
157 class ProjectForm(CommonForm):
158     fieldslayout = [
159         Div(
160             Div(
161                 Div('name',
162                     'type',
163                     'domain',
164                     'begin_year',
165                     'end_year',
166                     'constraint',
167                     'global_cost',
168                     'comments',
169 
170                     'pk',
171                     'model',
172 
173                     css_class="span6"),
174                 Div('project_owner',
175                     'project_manager',
176                     'contractors',
177                     Fieldset(_("Fundings")),
178                     css_class="span6"),
179                 css_class="row-fluid"
180             ),
181             css_class="container-fluid"
182         ),
183     ]
184 
185     class Meta(CommonForm.Meta):
186         model = Project
187         fields = CommonForm.Meta.fields + \
188             ['structure',
189              'name', 'type', 'domain', 'begin_year', 'end_year', 'constraint',
190              'global_cost', 'comments', 'project_owner', 'project_manager', 'contractors']
191 
192     def __init__(self, *args, **kwargs):
193         super(ProjectForm, self).__init__(*args, **kwargs)
194         self.helper.form_tag = False
195
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/geotrek/maintenance/forms.py b/geotrek/maintenance/forms.py
--- a/geotrek/maintenance/forms.py
+++ b/geotrek/maintenance/forms.py
@@ -51,6 +51,8 @@
                                             queryset=BaseInfrastructure.objects.existing(),
                                             widget=forms.HiddenInput())
     length = FloatField(required=False, label=_("Length"))
+
+    leftpanel_scrollable = False
     fieldslayout = [
         Div(
             HTML("""
@@ -87,7 +89,7 @@
                     css_id="advanced",  # used in Javascript for activating tab if error
                     css_class="tab-pane"
                 ),
-                css_class="tab-content"
+                css_class="scrollable tab-content"
             ),
             css_class="tabbable"
         ),
diff --git a/geotrek/trekking/forms.py b/geotrek/trekking/forms.py
--- a/geotrek/trekking/forms.py
+++ b/geotrek/trekking/forms.py
@@ -31,6 +31,9 @@
 
 
 class TrekForm(TopologyForm):
+
+    leftpanel_scrollable = False
+
     fieldslayout = [
         Div(
             HTML("""
@@ -56,7 +59,7 @@
                     'model',
 
                     css_id="main",
-                    css_class="tab-pane active"
+                    css_class="scrollable tab-pane active"
                 ),
                 Div(
                     'disabled_infrastructure',
@@ -71,7 +74,7 @@
                     'information_desk',
                     Fieldset(_("Related treks"),),
                     css_id="advanced",  # used in Javascript for activating tab if error
-                    css_class="tab-pane"
+                    css_class="scrollable tab-pane"
                 ),
                 css_class="tab-content"
             ),

{"golden_diff": "diff --git a/geotrek/maintenance/forms.py b/geotrek/maintenance/forms.py\n--- a/geotrek/maintenance/forms.py\n+++ b/geotrek/maintenance/forms.py\n@@ -51,6 +51,8 @@\n                                             queryset=BaseInfrastructure.objects.existing(),\n                                             widget=forms.HiddenInput())\n     length = FloatField(required=False, label=_(\"Length\"))\n+\n+    leftpanel_scrollable = False\n     fieldslayout = [\n         Div(\n             HTML(\"\"\"\n@@ -87,7 +89,7 @@\n                     css_id=\"advanced\",  # used in Javascript for activating tab if error\n                     css_class=\"tab-pane\"\n                 ),\n-                css_class=\"tab-content\"\n+                css_class=\"scrollable tab-content\"\n             ),\n             css_class=\"tabbable\"\n         ),\ndiff --git a/geotrek/trekking/forms.py b/geotrek/trekking/forms.py\n--- a/geotrek/trekking/forms.py\n+++ b/geotrek/trekking/forms.py\n@@ -31,6 +31,9 @@\n \n \n class TrekForm(TopologyForm):\n+\n+    leftpanel_scrollable = False\n+\n     fieldslayout = [\n         Div(\n             HTML(\"\"\"\n@@ -56,7 +59,7 @@\n                     'model',\n \n                     css_id=\"main\",\n-                    css_class=\"tab-pane active\"\n+                    css_class=\"scrollable tab-pane active\"\n                 ),\n                 Div(\n                     'disabled_infrastructure',\n@@ -71,7 +74,7 @@\n                     'information_desk',\n                     Fieldset(_(\"Related treks\"),),\n                     css_id=\"advanced\",  # used in Javascript for activating tab if error\n-                    css_class=\"tab-pane\"\n+                    css_class=\"scrollable tab-pane\"\n                 ),\n                 css_class=\"tab-content\"\n             ),\n", "issue": "Formulaire INTERVENTIONS - Onglet Avanc\u00e9\nLe r\u00e9f\u00e9rent SENTIERS pr\u00e9f\u00e9rerait que les champs COUTS et JOURS/HOMME soient affich\u00e9s \u00e0 la suite du formulaire plut\u00f4t que dans un onglet AVANCE car cela \u00e0 revenir en haut du formulaire apr\u00e8s avoir saisi les infos de base et du coup de nombreux agents passent \u00e0 c\u00f4t\u00e9 de la saisie de cette information.\n\n", "before_files": [{"content": "from django.utils.translation import ugettext as _\nfrom django.conf import settings\nfrom django.forms.models import inlineformset_factory\n\nimport floppyforms as forms\nfrom crispy_forms.helper import FormHelper\nfrom crispy_forms.bootstrap import FormActions\nfrom crispy_forms.layout import Layout, Submit, HTML, Div, Fieldset\nfrom mapentity.widgets import SelectMultipleWithPop\n\nfrom geotrek.core.forms import TopologyForm\nfrom geotrek.core.widgets import LineTopologyWidget, PointTopologyWidget\nfrom .models import Trek, POI, WebLink\n\n\nclass TrekRelationshipForm(forms.ModelForm):\n\n    def __init__(self, *args, **kwargs):\n        super(TrekRelationshipForm, self).__init__(*args, **kwargs)\n        self.helper = FormHelper()\n        self.helper.form_tag = False\n        self.helper.layout = Layout('id',\n                                    'trek_a',\n                                    'trek_b',\n                                    'has_common_departure',\n                                    'has_common_edge',\n                                    'is_circuit_step',\n                                    'DELETE')\n\nTrekRelationshipFormSet = inlineformset_factory(Trek, Trek.related_treks.through, form=TrekRelationshipForm, fk_name='trek_a', extra=1)\n\n\nclass TrekForm(TopologyForm):\n    fieldslayout = [\n        Div(\n            HTML(\"\"\"\n            <ul class=\"nav nav-tabs\">\n                <li id=\"tab-main\" class=\"active\"><a href=\"#main\" data-toggle=\"tab\"><i class=\"icon-certificate\"></i> %s</a></li>\n                <li id=\"tab-advanced\"><a href=\"#advanced\" data-toggle=\"tab\"><i class=\"icon-tasks\"></i> %s</a></li>\n            </ul>\"\"\" % (unicode(_(\"Main\")), unicode(_(\"Advanced\")))),\n            Div(\n                Div('name',\n                    'published',\n                    'is_park_centered',\n                    'departure',\n                    'arrival',\n                    'duration',\n                    'difficulty',\n                    'route',\n                    'ambiance',\n                    'access',\n                    'description_teaser',\n                    'description',\n\n                    'pk',\n                    'model',\n\n                    css_id=\"main\",\n                    css_class=\"tab-pane active\"\n                ),\n                Div(\n                    'disabled_infrastructure',\n                    'advised_parking',\n                    'parking_location',\n                    'public_transport',\n                    'advice',\n                    'themes',\n                    'networks',\n                    'usages',\n                    'web_links',\n                    'information_desk',\n                    Fieldset(_(\"Related treks\"),),\n                    css_id=\"advanced\",  # used in Javascript for activating tab if error\n                    css_class=\"tab-pane\"\n                ),\n                css_class=\"tab-content\"\n            ),\n            css_class=\"tabbable\"\n        ),\n    ]\n\n    def __init__(self, *args, **kwargs):\n        super(TrekForm, self).__init__(*args, **kwargs)\n        self.fields['topology'].widget = LineTopologyWidget()\n        self.fields['web_links'].widget = SelectMultipleWithPop(choices=self.fields['web_links'].choices,\n                                                                add_url=WebLink.get_add_url())\n        # Make sure (force) that name is required, in default language only\n        self.fields['name_%s' % settings.LANGUAGE_CODE].required = True\n\n    class Meta(TopologyForm.Meta):\n        model = Trek\n        fields = TopologyForm.Meta.fields + \\\n            ['name', 'published', 'is_park_centered', 'departure', 'arrival', 'duration', 'difficulty',\n             'route', 'ambiance', 'access', 'description_teaser', 'description',\n             'disabled_infrastructure', 'advised_parking', 'parking_location', 'public_transport', 'advice',\n             'themes', 'networks', 'usages', 'web_links', 'information_desk']\n\n\nclass POIForm(TopologyForm):\n    fieldslayout = [\n        Div('pk',\n            'model',\n\n            'type',\n            'name',\n            'description',\n\n            css_class=\"tab-content\"\n        )\n    ]\n\n    def __init__(self, *args, **kwargs):\n        super(POIForm, self).__init__(*args, **kwargs)\n        self.fields['topology'].widget = PointTopologyWidget()\n\n    class Meta(TopologyForm.Meta):\n        model = POI\n        fields = TopologyForm.Meta.fields + ['name', 'description', 'type']\n\n\nclass WebLinkCreateFormPopup(forms.ModelForm):\n\n    def __init__(self, *args, **kwargs):\n        super(WebLinkCreateFormPopup, self).__init__(*args, **kwargs)\n        self.helper = FormHelper()\n        self.helper.form_action = self.instance.get_add_url()\n        # Main form layout\n        # Adds every name field explicitly (name_fr, name_en, ...)\n        self.helper.form_class = 'form-horizontal'\n        arg_list = ['name_{0}'.format(l[0]) for l in settings.MAPENTITY_CONFIG['TRANSLATED_LANGUAGES']]\n        arg_list += ['url', 'category', FormActions(\n            HTML('<a href=\"#\" class=\"btn\" onclick=\"javascript:window.close();\">%s</a>' % _(\"Cancel\")),\n            Submit('save_changes', _('Create'), css_class=\"btn-primary\"),\n            css_class=\"form-actions\",\n        )]\n        self.helper.layout = Layout(*arg_list)\n\n    class Meta:\n        model = WebLink\n        fields = ['name_{0}'.format(l[0]) for l in settings.MAPENTITY_CONFIG['TRANSLATED_LANGUAGES']] + \\\n                 ['url', 'category']\n", "path": "geotrek/trekking/forms.py"}, {"content": "from django import forms\nfrom django.forms import FloatField\nfrom django.utils.translation import ugettext_lazy as _\nfrom django.forms.models import inlineformset_factory\n\nfrom crispy_forms.helper import FormHelper\nfrom crispy_forms.layout import Fieldset, Layout, Div, HTML\n\nfrom geotrek.common.forms import CommonForm\nfrom geotrek.core.fields import TopologyField\nfrom geotrek.core.forms import TopologyForm\nfrom geotrek.core.widgets import TopologyReadonlyWidget\nfrom geotrek.infrastructure.models import BaseInfrastructure\n\nfrom .models import Intervention, Project\n\n\nclass ManDayForm(forms.ModelForm):\n\n    def __init__(self, *args, **kwargs):\n        super(ManDayForm, self).__init__(*args, **kwargs)\n        self.helper = FormHelper()\n        self.helper.form_tag = False\n        self.helper.layout = Layout('id', 'nb_days', 'job')\n        self.fields['nb_days'].widget.attrs['placeholder'] = _('Days')\n        self.fields['nb_days'].label = ''\n        self.fields['nb_days'].widget.attrs['class'] = 'input-mini'\n        self.fields['job'].widget.attrs['class'] = 'input-medium'\n\n\nManDayFormSet = inlineformset_factory(Intervention, Intervention.jobs.through, form=ManDayForm, extra=1)\n\n\nclass FundingForm(forms.ModelForm):\n\n    def __init__(self, *args, **kwargs):\n        super(FundingForm, self).__init__(*args, **kwargs)\n        self.helper = FormHelper()\n        self.helper.form_tag = False\n        self.helper.layout = Layout('id', 'amount', 'organism')\n        self.fields['organism'].widget.attrs['class'] = 'input-xlarge'\n\n\nFundingFormSet = inlineformset_factory(Project, Project.founders.through, form=FundingForm, extra=1)\n\n\nclass InterventionForm(CommonForm):\n    \"\"\" An intervention can be a Point or a Line \"\"\"\n    topology = TopologyField(label=\"\")\n    infrastructure = forms.ModelChoiceField(required=False,\n                                            queryset=BaseInfrastructure.objects.existing(),\n                                            widget=forms.HiddenInput())\n    length = FloatField(required=False, label=_(\"Length\"))\n    fieldslayout = [\n        Div(\n            HTML(\"\"\"\n            <ul class=\"nav nav-tabs\">\n                <li id=\"tab-main\" class=\"active\"><a href=\"#main\" data-toggle=\"tab\"><i class=\"icon-certificate\"></i> %s</a></li>\n                <li id=\"tab-advanced\"><a href=\"#advanced\" data-toggle=\"tab\"><i class=\"icon-tasks\"></i> %s</a></li>\n            </ul>\"\"\" % (unicode(_(\"Main\")), unicode(_(\"Advanced\")))),\n            Div(\n                Div('name',\n                    'date',\n                    'status',\n                    'disorders',\n                    'type',\n                    'comments',\n                    'subcontracting',\n                    'length',\n                    'width',\n                    'height',\n                    'stake',\n                    'project',\n                    'infrastructure',\n\n                    'pk',\n                    'model',\n\n                    css_id=\"main\",\n                    css_class=\"tab-pane active\"\n                ),\n                Div(\n                    'material_cost',\n                    'heliport_cost',\n                    'subcontract_cost',\n                    Fieldset(_(\"Mandays\")),\n                    css_id=\"advanced\",  # used in Javascript for activating tab if error\n                    css_class=\"tab-pane\"\n                ),\n                css_class=\"tab-content\"\n            ),\n            css_class=\"tabbable\"\n        ),\n    ]\n\n    geomfields = ['topology']\n\n    class Meta(CommonForm.Meta):\n        model = Intervention\n        fields = CommonForm.Meta.fields + \\\n            ['structure',\n             'name', 'date', 'status', 'disorders', 'type', 'comments', 'subcontracting', 'length', 'width',\n             'height', 'stake', 'project', 'infrastructure', 'material_cost', 'heliport_cost', 'subcontract_cost',\n             'topology']\n\n    def __init__(self, *args, **kwargs):\n        super(InterventionForm, self).__init__(*args, **kwargs)\n        # If we create or edit an intervention on infrastructure, set\n        # topology field as read-only\n        infrastructure = kwargs.get('initial', {}).get('infrastructure')\n        if self.instance.on_infrastructure:\n            infrastructure = self.instance.infrastructure\n            self.fields['infrastructure'].initial = infrastructure\n        if infrastructure:\n            self.helper.form_action += '?infrastructure=%s' % infrastructure.pk\n            self.fields['topology'].required = False\n            self.fields['topology'].widget = TopologyReadonlyWidget()\n            self.fields['topology'].label = '%s%s %s' % (\n                self.instance.infrastructure_display,\n                unicode(_(\"On %s\") % _(infrastructure.kind.lower())),\n                u'<a href=\"%s\">%s</a>' % (infrastructure.get_detail_url(), unicode(infrastructure))\n            )\n        # Length is not editable in AltimetryMixin\n        self.fields['length'].initial = self.instance.length\n        editable = bool(self.instance.geom and self.instance.geom.geom_type == 'Point')\n        self.fields['length'].widget.attrs['readonly'] = editable\n\n    def clean(self, *args, **kwargs):\n        # If topology was read-only, topology field is empty, get it from infra.\n        cleaned_data = super(InterventionForm, self).clean()\n        topology_readonly = self.cleaned_data.get('topology', None) is None\n        if topology_readonly and 'infrastructure' in self.cleaned_data:\n            self.cleaned_data['topology'] = self.cleaned_data['infrastructure']\n        return cleaned_data\n\n    def save(self, *args, **kwargs):\n        self.instance.length = self.cleaned_data.get('length')\n        infrastructure = self.cleaned_data.get('infrastructure')\n        if infrastructure:\n            self.instance.set_infrastructure(infrastructure)\n        return super(InterventionForm, self).save(*args, **kwargs)\n\n\nclass InterventionCreateForm(InterventionForm):\n    def __init__(self, *args, **kwargs):\n        # If we create an intervention on infrastructure, get its topology\n        initial = kwargs.get('initial', {})\n        infrastructure = initial.get('infrastructure')\n        if infrastructure:\n            initial['topology'] = infrastructure\n        kwargs['initial'] = initial\n        super(InterventionCreateForm, self).__init__(*args, **kwargs)\n        # Stake is computed automatically at creation.\n        self.fields['stake'].required = False\n\n\nclass ProjectForm(CommonForm):\n    fieldslayout = [\n        Div(\n            Div(\n                Div('name',\n                    'type',\n                    'domain',\n                    'begin_year',\n                    'end_year',\n                    'constraint',\n                    'global_cost',\n                    'comments',\n\n                    'pk',\n                    'model',\n\n                    css_class=\"span6\"),\n                Div('project_owner',\n                    'project_manager',\n                    'contractors',\n                    Fieldset(_(\"Fundings\")),\n                    css_class=\"span6\"),\n                css_class=\"row-fluid\"\n            ),\n            css_class=\"container-fluid\"\n        ),\n    ]\n\n    class Meta(CommonForm.Meta):\n        model = Project\n        fields = CommonForm.Meta.fields + \\\n            ['structure',\n             'name', 'type', 'domain', 'begin_year', 'end_year', 'constraint',\n             'global_cost', 'comments', 'project_owner', 'project_manager', 'contractors']\n\n    def __init__(self, *args, **kwargs):\n        super(ProjectForm, self).__init__(*args, **kwargs)\n        self.helper.form_tag = False\n", "path": "geotrek/maintenance/forms.py"}], "after_files": [{"content": "from django.utils.translation import ugettext as _\nfrom django.conf import settings\nfrom django.forms.models import inlineformset_factory\n\nimport floppyforms as forms\nfrom crispy_forms.helper import FormHelper\nfrom crispy_forms.bootstrap import FormActions\nfrom crispy_forms.layout import Layout, Submit, HTML, Div, Fieldset\nfrom mapentity.widgets import SelectMultipleWithPop\n\nfrom geotrek.core.forms import TopologyForm\nfrom geotrek.core.widgets import LineTopologyWidget, PointTopologyWidget\nfrom .models import Trek, POI, WebLink\n\n\nclass TrekRelationshipForm(forms.ModelForm):\n\n    def __init__(self, *args, **kwargs):\n        super(TrekRelationshipForm, self).__init__(*args, **kwargs)\n        self.helper = FormHelper()\n        self.helper.form_tag = False\n        self.helper.layout = Layout('id',\n                                    'trek_a',\n                                    'trek_b',\n                                    'has_common_departure',\n                                    'has_common_edge',\n                                    'is_circuit_step',\n                                    'DELETE')\n\nTrekRelationshipFormSet = inlineformset_factory(Trek, Trek.related_treks.through, form=TrekRelationshipForm, fk_name='trek_a', extra=1)\n\n\nclass TrekForm(TopologyForm):\n\n    leftpanel_scrollable = False\n\n    fieldslayout = [\n        Div(\n            HTML(\"\"\"\n            <ul class=\"nav nav-tabs\">\n                <li id=\"tab-main\" class=\"active\"><a href=\"#main\" data-toggle=\"tab\"><i class=\"icon-certificate\"></i> %s</a></li>\n                <li id=\"tab-advanced\"><a href=\"#advanced\" data-toggle=\"tab\"><i class=\"icon-tasks\"></i> %s</a></li>\n            </ul>\"\"\" % (unicode(_(\"Main\")), unicode(_(\"Advanced\")))),\n            Div(\n                Div('name',\n                    'published',\n                    'is_park_centered',\n                    'departure',\n                    'arrival',\n                    'duration',\n                    'difficulty',\n                    'route',\n                    'ambiance',\n                    'access',\n                    'description_teaser',\n                    'description',\n\n                    'pk',\n                    'model',\n\n                    css_id=\"main\",\n                    css_class=\"scrollable tab-pane active\"\n                ),\n                Div(\n                    'disabled_infrastructure',\n                    'advised_parking',\n                    'parking_location',\n                    'public_transport',\n                    'advice',\n                    'themes',\n                    'networks',\n                    'usages',\n                    'web_links',\n                    'information_desk',\n                    Fieldset(_(\"Related treks\"),),\n                    css_id=\"advanced\",  # used in Javascript for activating tab if error\n                    css_class=\"scrollable tab-pane\"\n                ),\n                css_class=\"tab-content\"\n            ),\n            css_class=\"tabbable\"\n        ),\n    ]\n\n    def __init__(self, *args, **kwargs):\n        super(TrekForm, self).__init__(*args, **kwargs)\n        self.fields['topology'].widget = LineTopologyWidget()\n        self.fields['web_links'].widget = SelectMultipleWithPop(choices=self.fields['web_links'].choices,\n                                                                add_url=WebLink.get_add_url())\n        # Make sure (force) that name is required, in default language only\n        self.fields['name_%s' % settings.LANGUAGE_CODE].required = True\n\n    class Meta(TopologyForm.Meta):\n        model = Trek\n        fields = TopologyForm.Meta.fields + \\\n            ['name', 'published', 'is_park_centered', 'departure', 'arrival', 'duration', 'difficulty',\n             'route', 'ambiance', 'access', 'description_teaser', 'description',\n             'disabled_infrastructure', 'advised_parking', 'parking_location', 'public_transport', 'advice',\n             'themes', 'networks', 'usages', 'web_links', 'information_desk']\n\n\nclass POIForm(TopologyForm):\n    fieldslayout = [\n        Div('pk',\n            'model',\n\n            'type',\n            'name',\n            'description',\n\n            css_class=\"tab-content\"\n        )\n    ]\n\n    def __init__(self, *args, **kwargs):\n        super(POIForm, self).__init__(*args, **kwargs)\n        self.fields['topology'].widget = PointTopologyWidget()\n\n    class Meta(TopologyForm.Meta):\n        model = POI\n        fields = TopologyForm.Meta.fields + ['name', 'description', 'type']\n\n\nclass WebLinkCreateFormPopup(forms.ModelForm):\n\n    def __init__(self, *args, **kwargs):\n        super(WebLinkCreateFormPopup, self).__init__(*args, **kwargs)\n        self.helper = FormHelper()\n        self.helper.form_action = self.instance.get_add_url()\n        # Main form layout\n        # Adds every name field explicitly (name_fr, name_en, ...)\n        self.helper.form_class = 'form-horizontal'\n        arg_list = ['name_{0}'.format(l[0]) for l in settings.MAPENTITY_CONFIG['TRANSLATED_LANGUAGES']]\n        arg_list += ['url', 'category', FormActions(\n            HTML('<a href=\"#\" class=\"btn\" onclick=\"javascript:window.close();\">%s</a>' % _(\"Cancel\")),\n            Submit('save_changes', _('Create'), css_class=\"btn-primary\"),\n            css_class=\"form-actions\",\n        )]\n        self.helper.layout = Layout(*arg_list)\n\n    class Meta:\n        model = WebLink\n        fields = ['name_{0}'.format(l[0]) for l in settings.MAPENTITY_CONFIG['TRANSLATED_LANGUAGES']] + \\\n                 ['url', 'category']\n", "path": "geotrek/trekking/forms.py"}, {"content": "from django import forms\nfrom django.forms import FloatField\nfrom django.utils.translation import ugettext_lazy as _\nfrom django.forms.models import inlineformset_factory\n\nfrom crispy_forms.helper import FormHelper\nfrom crispy_forms.layout import Fieldset, Layout, Div, HTML\n\nfrom geotrek.common.forms import CommonForm\nfrom geotrek.core.fields import TopologyField\nfrom geotrek.core.forms import TopologyForm\nfrom geotrek.core.widgets import TopologyReadonlyWidget\nfrom geotrek.infrastructure.models import BaseInfrastructure\n\nfrom .models import Intervention, Project\n\n\nclass ManDayForm(forms.ModelForm):\n\n    def __init__(self, *args, **kwargs):\n        super(ManDayForm, self).__init__(*args, **kwargs)\n        self.helper = FormHelper()\n        self.helper.form_tag = False\n        self.helper.layout = Layout('id', 'nb_days', 'job')\n        self.fields['nb_days'].widget.attrs['placeholder'] = _('Days')\n        self.fields['nb_days'].label = ''\n        self.fields['nb_days'].widget.attrs['class'] = 'input-mini'\n        self.fields['job'].widget.attrs['class'] = 'input-medium'\n\n\nManDayFormSet = inlineformset_factory(Intervention, Intervention.jobs.through, form=ManDayForm, extra=1)\n\n\nclass FundingForm(forms.ModelForm):\n\n    def __init__(self, *args, **kwargs):\n        super(FundingForm, self).__init__(*args, **kwargs)\n        self.helper = FormHelper()\n        self.helper.form_tag = False\n        self.helper.layout = Layout('id', 'amount', 'organism')\n        self.fields['organism'].widget.attrs['class'] = 'input-xlarge'\n\n\nFundingFormSet = inlineformset_factory(Project, Project.founders.through, form=FundingForm, extra=1)\n\n\nclass InterventionForm(CommonForm):\n    \"\"\" An intervention can be a Point or a Line \"\"\"\n    topology = TopologyField(label=\"\")\n    infrastructure = forms.ModelChoiceField(required=False,\n                                            queryset=BaseInfrastructure.objects.existing(),\n                                            widget=forms.HiddenInput())\n    length = FloatField(required=False, label=_(\"Length\"))\n\n    leftpanel_scrollable = False\n    fieldslayout = [\n        Div(\n            HTML(\"\"\"\n            <ul class=\"nav nav-tabs\">\n                <li id=\"tab-main\" class=\"active\"><a href=\"#main\" data-toggle=\"tab\"><i class=\"icon-certificate\"></i> %s</a></li>\n                <li id=\"tab-advanced\"><a href=\"#advanced\" data-toggle=\"tab\"><i class=\"icon-tasks\"></i> %s</a></li>\n            </ul>\"\"\" % (unicode(_(\"Main\")), unicode(_(\"Advanced\")))),\n            Div(\n                Div('name',\n                    'date',\n                    'status',\n                    'disorders',\n                    'type',\n                    'comments',\n                    'subcontracting',\n                    'length',\n                    'width',\n                    'height',\n                    'stake',\n                    'project',\n                    'infrastructure',\n\n                    'pk',\n                    'model',\n\n                    css_id=\"main\",\n                    css_class=\"tab-pane active\"\n                ),\n                Div(\n                    'material_cost',\n                    'heliport_cost',\n                    'subcontract_cost',\n                    Fieldset(_(\"Mandays\")),\n                    css_id=\"advanced\",  # used in Javascript for activating tab if error\n                    css_class=\"tab-pane\"\n                ),\n                css_class=\"scrollable tab-content\"\n            ),\n            css_class=\"tabbable\"\n        ),\n    ]\n\n    geomfields = ['topology']\n\n    class Meta(CommonForm.Meta):\n        model = Intervention\n        fields = CommonForm.Meta.fields + \\\n            ['structure',\n             'name', 'date', 'status', 'disorders', 'type', 'comments', 'subcontracting', 'length', 'width',\n             'height', 'stake', 'project', 'infrastructure', 'material_cost', 'heliport_cost', 'subcontract_cost',\n             'topology']\n\n    def __init__(self, *args, **kwargs):\n        super(InterventionForm, self).__init__(*args, **kwargs)\n        # If we create or edit an intervention on infrastructure, set\n        # topology field as read-only\n        infrastructure = kwargs.get('initial', {}).get('infrastructure')\n        if self.instance.on_infrastructure:\n            infrastructure = self.instance.infrastructure\n            self.fields['infrastructure'].initial = infrastructure\n        if infrastructure:\n            self.helper.form_action += '?infrastructure=%s' % infrastructure.pk\n            self.fields['topology'].required = False\n            self.fields['topology'].widget = TopologyReadonlyWidget()\n            self.fields['topology'].label = '%s%s %s' % (\n                self.instance.infrastructure_display,\n                unicode(_(\"On %s\") % _(infrastructure.kind.lower())),\n                u'<a href=\"%s\">%s</a>' % (infrastructure.get_detail_url(), unicode(infrastructure))\n            )\n        # Length is not editable in AltimetryMixin\n        self.fields['length'].initial = self.instance.length\n        editable = bool(self.instance.geom and self.instance.geom.geom_type == 'Point')\n        self.fields['length'].widget.attrs['readonly'] = editable\n\n    def clean(self, *args, **kwargs):\n        # If topology was read-only, topology field is empty, get it from infra.\n        cleaned_data = super(InterventionForm, self).clean()\n        topology_readonly = self.cleaned_data.get('topology', None) is None\n        if topology_readonly and 'infrastructure' in self.cleaned_data:\n            self.cleaned_data['topology'] = self.cleaned_data['infrastructure']\n        return cleaned_data\n\n    def save(self, *args, **kwargs):\n        self.instance.length = self.cleaned_data.get('length')\n        infrastructure = self.cleaned_data.get('infrastructure')\n        if infrastructure:\n            self.instance.set_infrastructure(infrastructure)\n        return super(InterventionForm, self).save(*args, **kwargs)\n\n\nclass InterventionCreateForm(InterventionForm):\n    def __init__(self, *args, **kwargs):\n        # If we create an intervention on infrastructure, get its topology\n        initial = kwargs.get('initial', {})\n        infrastructure = initial.get('infrastructure')\n        if infrastructure:\n            initial['topology'] = infrastructure\n        kwargs['initial'] = initial\n        super(InterventionCreateForm, self).__init__(*args, **kwargs)\n        # Stake is computed automatically at creation.\n        self.fields['stake'].required = False\n\n\nclass ProjectForm(CommonForm):\n    fieldslayout = [\n        Div(\n            Div(\n                Div('name',\n                    'type',\n                    'domain',\n                    'begin_year',\n                    'end_year',\n                    'constraint',\n                    'global_cost',\n                    'comments',\n\n                    'pk',\n                    'model',\n\n                    css_class=\"span6\"),\n                Div('project_owner',\n                    'project_manager',\n                    'contractors',\n                    Fieldset(_(\"Fundings\")),\n                    css_class=\"span6\"),\n                css_class=\"row-fluid\"\n            ),\n            css_class=\"container-fluid\"\n        ),\n    ]\n\n    class Meta(CommonForm.Meta):\n        model = Project\n        fields = CommonForm.Meta.fields + \\\n            ['structure',\n             'name', 'type', 'domain', 'begin_year', 'end_year', 'constraint',\n             'global_cost', 'comments', 'project_owner', 'project_manager', 'contractors']\n\n    def __init__(self, *args, **kwargs):\n        super(ProjectForm, self).__init__(*args, **kwargs)\n        self.helper.form_tag = False\n", "path": "geotrek/maintenance/forms.py"}]}