Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Géocontrib Django
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GéoContrib
Géocontrib Django
Commits
5974db48
Commit
5974db48
authored
1 month ago
by
Timothee P
Browse files
Options
Downloads
Patches
Plain Diff
refactor(sonarQube): reduce complexity and remove unused functions
parent
5881d849
No related branches found
Branches containing commit
No related tags found
1 merge request
!536
REDMINE_ISSUE-24432 | Corriger les erreurs SonarQube & réactiver dans CI
Pipeline
#42182
passed
1 month ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
geocontrib/forms.py
+0
-87
0 additions, 87 deletions
geocontrib/forms.py
geocontrib/forms/feature.py
+42
-35
42 additions, 35 deletions
geocontrib/forms/feature.py
with
42 additions
and
122 deletions
geocontrib/forms.py
+
0
−
87
View file @
5974db48
...
...
@@ -368,93 +368,6 @@ class FeatureBaseForm(forms.ModelForm):
return
instance
class
FeatureExtraForm
(
forms
.
Form
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
extra
=
kwargs
.
pop
(
'
extra
'
,
None
)
feature
=
kwargs
.
pop
(
'
feature
'
,
None
)
super
().
__init__
(
*
args
,
**
kwargs
)
for
custom_field
in
extra
.
order_by
(
'
position
'
):
if
custom_field
.
field_type
==
'
boolean
'
:
self
.
fields
[
custom_field
.
name
]
=
forms
.
BooleanField
(
label
=
custom_field
.
label
,
initial
=
False
,
required
=
False
,
)
if
custom_field
.
field_type
==
'
char
'
:
self
.
fields
[
custom_field
.
name
]
=
forms
.
CharField
(
label
=
custom_field
.
label
,
max_length
=
256
,
required
=
False
)
if
custom_field
.
field_type
==
'
date
'
:
self
.
fields
[
custom_field
.
name
]
=
forms
.
DateField
(
label
=
custom_field
.
label
,
required
=
False
,
)
if
custom_field
.
field_type
==
'
integer
'
:
self
.
fields
[
custom_field
.
name
]
=
forms
.
IntegerField
(
label
=
custom_field
.
label
,
required
=
False
)
if
custom_field
.
field_type
==
'
decimal
'
:
self
.
fields
[
custom_field
.
name
]
=
forms
.
DecimalField
(
label
=
custom_field
.
label
,
required
=
False
,
widget
=
forms
.
TextInput
(
attrs
=
{
'
localization
'
:
False
}))
if
custom_field
.
field_type
==
'
text
'
:
self
.
fields
[
custom_field
.
name
]
=
forms
.
CharField
(
label
=
custom_field
.
label
,
required
=
False
,
widget
=
forms
.
Textarea
())
if
custom_field
.
field_type
==
'
list
'
and
custom_field
.
options
:
self
.
fields
[
custom_field
.
name
]
=
forms
.
ChoiceField
(
label
=
custom_field
.
label
,
choices
=
[(
str
(
xx
),
str
(
xx
))
for
xx
in
custom_field
.
options
],
required
=
False
)
self
.
fields
[
custom_field
.
name
].
widget
.
attrs
.
update
({
'
field_type
'
:
custom_field
.
field_type
})
if
feature
and
isinstance
(
feature
.
feature_data
,
dict
):
for
custom_field
in
extra
:
self
.
fields
[
custom_field
.
name
].
initial
=
feature
.
feature_data
.
get
(
custom_field
.
name
)
class
FeatureLinkForm
(
forms
.
ModelForm
):
feature_to
=
forms
.
ModelChoiceField
(
label
=
"
Signalement lié
"
,
queryset
=
Feature
.
objects
.
all
(),
empty_label
=
None
)
class
Meta
:
model
=
FeatureLink
fields
=
(
'
relation_type
'
,
'
feature_to
'
,
)
def
__init__
(
self
,
*
args
,
**
kwargs
):
feature_type
=
kwargs
.
pop
(
'
feature_type
'
,
None
)
feature
=
kwargs
.
pop
(
'
feature
'
,
None
)
super
().
__init__
(
*
args
,
**
kwargs
)
qs
=
Feature
.
objects
.
all
()
if
feature_type
:
qs
=
qs
.
filter
(
feature_type
=
feature_type
)
if
feature
:
qs
=
qs
.
exclude
(
feature_id
=
feature
.
feature_id
)
try
:
self
.
fields
[
'
feature_to
'
].
queryset
=
qs
self
.
fields
[
'
feature_to
'
].
label_from_instance
=
lambda
obj
:
"
{} ({} - {})
"
.
format
(
obj
.
title
,
obj
.
display_creator
,
obj
.
created_on
.
strftime
(
"
%d/%m/%Y %H:%M
"
))
except
Exception
:
logger
.
exception
(
'
No related features found
'
)
class
FeatureTypeModelForm
(
forms
.
ModelForm
):
title
=
forms
.
CharField
(
label
=
'
Titre
'
,
required
=
True
)
...
...
This diff is collapsed.
Click to expand it.
geocontrib/forms/feature.py
+
42
−
35
View file @
5974db48
...
...
@@ -91,46 +91,53 @@ class FeatureExtraForm(forms.Form):
feature
=
kwargs
.
pop
(
'
feature
'
,
None
)
super
().
__init__
(
*
args
,
**
kwargs
)
for
custom_field
in
extra
.
order_by
(
'
position
'
):
if
custom_field
.
field_type
==
'
boolean
'
:
self
.
fields
[
custom_field
.
name
]
=
forms
.
BooleanField
(
label
=
custom_field
.
label
,
initial
=
False
,
required
=
False
,
)
if
custom_field
.
field_type
==
'
char
'
:
self
.
fields
[
custom_field
.
name
]
=
forms
.
CharField
(
label
=
custom_field
.
label
,
max_length
=
256
,
required
=
False
)
if
custom_field
.
field_type
==
'
date
'
:
self
.
fields
[
custom_field
.
name
]
=
forms
.
DateField
(
label
=
custom_field
.
label
,
required
=
False
,
)
if
custom_field
.
field_type
==
'
integer
'
:
self
.
fields
[
custom_field
.
name
]
=
forms
.
IntegerField
(
label
=
custom_field
.
label
,
required
=
False
)
if
custom_field
.
field_type
==
'
decimal
'
:
self
.
fields
[
custom_field
.
name
]
=
forms
.
DecimalField
(
label
=
custom_field
.
label
,
required
=
False
,
widget
=
forms
.
TextInput
(
attrs
=
{
'
localization
'
:
False
}))
if
custom_field
.
field_type
==
'
text
'
:
self
.
fields
[
custom_field
.
name
]
=
forms
.
CharField
(
label
=
custom_field
.
label
,
required
=
False
,
widget
=
forms
.
Textarea
())
if
custom_field
.
field_type
==
'
list
'
and
custom_field
.
options
:
self
.
fields
[
custom_field
.
name
]
=
forms
.
ChoiceField
(
label
=
custom_field
.
label
,
choices
=
[(
str
(
xx
),
str
(
xx
))
for
xx
in
custom_field
.
options
],
required
=
False
)
if
not
extra
:
return
self
.
_build_fields
(
extra
)
self
.
_populate_initial_values
(
extra
,
feature
)
def
_build_fields
(
self
,
extra
):
for
custom_field
in
extra
.
order_by
(
'
position
'
):
self
.
fields
[
custom_field
.
name
]
=
self
.
_create_form_field
(
custom_field
)
self
.
fields
[
custom_field
.
name
].
widget
.
attrs
.
update
({
'
field_type
'
:
custom_field
.
field_type
})
def
_create_form_field
(
self
,
custom_field
):
"""
Return a Django form field instance based on the field type.
"""
field_type
=
custom_field
.
field_type
common_kwargs
=
{
'
label
'
:
custom_field
.
label
,
'
required
'
:
False
}
if
field_type
==
'
boolean
'
:
return
forms
.
BooleanField
(
initial
=
False
,
**
common_kwargs
)
if
field_type
==
'
char
'
:
return
forms
.
CharField
(
max_length
=
256
,
**
common_kwargs
)
if
field_type
==
'
date
'
:
return
forms
.
DateField
(
**
common_kwargs
)
if
field_type
==
'
integer
'
:
return
forms
.
IntegerField
(
**
common_kwargs
)
if
field_type
==
'
decimal
'
:
return
forms
.
DecimalField
(
widget
=
forms
.
TextInput
(
attrs
=
{
'
localization
'
:
False
}),
**
common_kwargs
)
if
field_type
==
'
text
'
:
return
forms
.
CharField
(
widget
=
forms
.
Textarea
(),
**
common_kwargs
)
if
field_type
==
'
list
'
and
custom_field
.
options
:
choices
=
[(
str
(
opt
),
str
(
opt
))
for
opt
in
custom_field
.
options
]
return
forms
.
ChoiceField
(
choices
=
choices
,
**
common_kwargs
)
# Default fallback (optional, or raise exception)
return
forms
.
CharField
(
**
common_kwargs
)
def
_populate_initial_values
(
self
,
extra
,
feature
):
if
feature
and
isinstance
(
feature
.
feature_data
,
dict
):
for
custom_field
in
extra
:
self
.
fields
[
custom_field
.
name
].
initial
=
feature
.
feature_data
.
get
(
custom_field
.
name
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment