Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
third-party
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alexis AOUN
third-party
Commits
1424912e
Commit
1424912e
authored
Apr 22, 2021
by
François
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make phone pattern validation customable
parent
dd81025f
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
50 additions
and
7 deletions
+50
-7
models.py
members/models.py
+4
-4
urls.py
members/urls.py
+0
-1
views.py
members/views.py
+2
-0
common_functions.py
outils/common_functions.py
+33
-0
common_imports.py
outils/common_imports.py
+1
-0
config.md
outils/config.md
+8
-0
validation_form.html
templates/members/validation_form.html
+2
-2
No files found.
members/models.py
View file @
1424912e
...
@@ -317,7 +317,7 @@ class CagetteMember(models.Model):
...
@@ -317,7 +317,7 @@ class CagetteMember(models.Model):
if
'street2'
in
post_data
:
if
'street2'
in
post_data
:
received_data
[
'street2'
]
=
post_data
[
'street2'
]
received_data
[
'street2'
]
=
post_data
[
'street2'
]
if
'phone'
in
post_data
:
if
'phone'
in
post_data
:
received_data
[
'phone'
]
=
post_data
[
'phone'
]
received_data
[
'phone'
]
=
format_phone_number
(
post_data
[
'phone'
])
r
=
c_db
.
updateDoc
(
received_data
,
'odoo_id'
)
r
=
c_db
.
updateDoc
(
received_data
,
'odoo_id'
)
if
r
:
if
r
:
if
(
'odoo_id'
in
r
):
if
(
'odoo_id'
in
r
):
...
@@ -394,7 +394,7 @@ class CagetteMember(models.Model):
...
@@ -394,7 +394,7 @@ class CagetteMember(models.Model):
'street'
:
post_data
[
'address'
],
'street'
:
post_data
[
'address'
],
'zip'
:
post_data
[
'zip'
],
'zip'
:
post_data
[
'zip'
],
'city'
:
post_data
[
'city'
],
'city'
:
post_data
[
'city'
],
'phone'
:
post_data
[
'mobile'
]
,
# Because list view default show Phone and people mainly gives mobile
'phone'
:
format_phone_number
(
post_data
[
'mobile'
])
,
# Because list view default show Phone and people mainly gives mobile
'barcode_rule_id'
:
settings
.
COOP_BARCODE_RULE_ID
'barcode_rule_id'
:
settings
.
COOP_BARCODE_RULE_ID
}
}
if
(
'_id'
in
post_data
):
if
(
'_id'
in
post_data
):
...
@@ -407,10 +407,10 @@ class CagetteMember(models.Model):
...
@@ -407,10 +407,10 @@ class CagetteMember(models.Model):
f
[
'street2'
]
=
post_data
[
'street2'
]
f
[
'street2'
]
=
post_data
[
'street2'
]
if
(
'phone'
in
post_data
)
and
len
(
post_data
[
'phone'
])
>
0
:
if
(
'phone'
in
post_data
)
and
len
(
post_data
[
'phone'
])
>
0
:
if
len
(
f
[
'phone'
])
==
0
:
if
len
(
f
[
'phone'
])
==
0
:
f
[
'phone'
]
=
post_data
[
'phone'
]
f
[
'phone'
]
=
format_phone_number
(
post_data
[
'phone'
])
else
:
else
:
f
[
'mobile'
]
=
f
[
'phone'
]
f
[
'mobile'
]
=
f
[
'phone'
]
f
[
'phone'
]
=
post_data
[
'phone'
]
f
[
'phone'
]
=
format_phone_number
(
post_data
[
'phone'
])
# Create coop
# Create coop
if
not
(
'odoo_id'
in
post_data
):
if
not
(
'odoo_id'
in
post_data
):
...
...
members/urls.py
View file @
1424912e
...
@@ -48,5 +48,4 @@ urlpatterns = [
...
@@ -48,5 +48,4 @@ urlpatterns = [
url
(
r'^add_pts_to_everybody/([0-9]+)/([a-zA-Z0-9_ ]+)$'
,
admin
.
add_pts_to_everybody
),
url
(
r'^add_pts_to_everybody/([0-9]+)/([a-zA-Z0-9_ ]+)$'
,
admin
.
add_pts_to_everybody
),
# conso / groupe recherche / socio
# conso / groupe recherche / socio
url
(
r'^panel_get_purchases$'
,
views
.
panel_get_purchases
),
url
(
r'^panel_get_purchases$'
,
views
.
panel_get_purchases
),
]
]
members/views.py
View file @
1424912e
...
@@ -102,6 +102,7 @@ def prepa_odoo(request):
...
@@ -102,6 +102,7 @@ def prepa_odoo(request):
'office_place_string'
:
settings
.
OFFICE_NAME
,
'office_place_string'
:
settings
.
OFFICE_NAME
,
'max_begin_hour'
:
settings
.
MAX_BEGIN_HOUR
,
'max_begin_hour'
:
settings
.
MAX_BEGIN_HOUR
,
'payment_meanings'
:
settings
.
SUBSCRIPTION_PAYMENT_MEANINGS
,
'payment_meanings'
:
settings
.
SUBSCRIPTION_PAYMENT_MEANINGS
,
'input_phone_pattern'
:
getattr
(
settings
,
'INPUT_PHONE_PATTERN'
,
default_input_phone_pattern
),
'input_barcode'
:
getattr
(
settings
,
'SUBSCRIPTION_INPUT_BARCODE'
,
False
),
'input_barcode'
:
getattr
(
settings
,
'SUBSCRIPTION_INPUT_BARCODE'
,
False
),
'ask_for_sex'
:
getattr
(
settings
,
'SUBSCRIPTION_ASK_FOR_SEX'
,
False
),
'ask_for_sex'
:
getattr
(
settings
,
'SUBSCRIPTION_ASK_FOR_SEX'
,
False
),
'ask_for_street2'
:
getattr
(
settings
,
'SUBSCRIPTION_ADD_STREET2'
,
False
),
'ask_for_street2'
:
getattr
(
settings
,
'SUBSCRIPTION_ADD_STREET2'
,
False
),
...
@@ -135,6 +136,7 @@ def validation_inscription(request, email):
...
@@ -135,6 +136,7 @@ def validation_inscription(request, email):
'office_place_string'
:
settings
.
OFFICE_NAME
,
'office_place_string'
:
settings
.
OFFICE_NAME
,
'max_begin_hour'
:
settings
.
MAX_BEGIN_HOUR
,
'max_begin_hour'
:
settings
.
MAX_BEGIN_HOUR
,
'payment_meanings'
:
settings
.
SUBSCRIPTION_PAYMENT_MEANINGS
,
'payment_meanings'
:
settings
.
SUBSCRIPTION_PAYMENT_MEANINGS
,
'input_phone_pattern'
:
getattr
(
settings
,
'INPUT_PHONE_PATTERN'
,
default_input_phone_pattern
),
'ask_for_sex'
:
getattr
(
settings
,
'SUBSCRIPTION_ASK_FOR_SEX'
,
False
),
'ask_for_sex'
:
getattr
(
settings
,
'SUBSCRIPTION_ASK_FOR_SEX'
,
False
),
'ask_for_street2'
:
getattr
(
settings
,
'SUBSCRIPTION_ADD_STREET2'
,
False
),
'ask_for_street2'
:
getattr
(
settings
,
'SUBSCRIPTION_ADD_STREET2'
,
False
),
'ask_for_second_phone'
:
getattr
(
settings
,
'SUBSCRIPTION_ADD_SECOND_PHONE'
,
False
),
'ask_for_second_phone'
:
getattr
(
settings
,
'SUBSCRIPTION_ADD_SECOND_PHONE'
,
False
),
...
...
outils/common_functions.py
View file @
1424912e
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
"""commons apps functions ."""
"""commons apps functions ."""
from
django.conf
import
settings
from
django.conf
import
settings
default_input_phone_pattern
=
"^((
\
+33(-| )
\
d{1})|
\
d{2})(
\
.| )
\
d{2}(
\
.| )
\
d{2}(
\
.| )
\
d{2}(
\
.| )
\
d{2}$"
def
format_phone_number
(
phone_string
):
"""Format phone number for DB insertion (french format)"""
try
:
import
re
# keep only figures
figures
=
re
.
sub
(
r'[^0-9]'
,
''
,
phone_string
)
international_prefix
=
''
if
len
(
figures
)
>
10
:
international_prefix
=
figures
[:
len
(
figures
)
-
9
]
figures
=
figures
[
-
9
:]
# for the moment, international prefix is omitted, since only french format is processed
if
len
(
figures
)
==
9
:
figures
=
'0'
+
figures
if
len
(
figures
)
==
10
:
number_pairs
=
[
figures
[:
2
]]
for
i
in
range
(
1
,
5
):
idx
=
i
*
2
number_pairs
.
append
(
figures
[
idx
:
idx
+
2
])
phone_pairs_separator
=
getattr
(
settings
,
'PHONE_PAIRS_SEPARATOR'
,
' '
)
output_phone_number
=
phone_pairs_separator
.
join
(
number_pairs
)
else
:
output_phone_number
=
phone_string
except
:
output_phone_number
=
phone_string
return
output_phone_number
outils/common_imports.py
View file @
1424912e
...
@@ -79,3 +79,4 @@ LOGGING = {
...
@@ -79,3 +79,4 @@ LOGGING = {
}
}
"""
"""
coop_logger
=
logging
.
getLogger
(
"coop.framework"
)
coop_logger
=
logging
.
getLogger
(
"coop.framework"
)
outils/config.md
View file @
1424912e
...
@@ -106,6 +106,14 @@
...
@@ -106,6 +106,14 @@
Maximum accepted checks numbers
Maximum accepted checks numbers
-
INPUT_PHONE_PATTERN = "^(0
\d
{9})$"
Regexp pattern which is used to validate values input in phone fields
Default is "^((
\+
33(-| )
\d
{1})|
\d
{2})(
\.
| )
\d
{2}(
\.
| )
\d
{2}(
\.
| )
\d
{2}(
\.
| )
\d
{2}$"
-
PHONE_PAIRS_SEPARATOR = "."
Character which by used to separate every 2 phone figures (04.67.23.89.21 for example)
Default is " "
### Scales and labels files generation
### Scales and labels files generation
-
DAV_PATH = '/data/dav/cagette'
-
DAV_PATH = '/data/dav/cagette'
...
...
templates/members/validation_form.html
View file @
1424912e
...
@@ -21,9 +21,9 @@
...
@@ -21,9 +21,9 @@
<input
name=
"city"
placeholder=
"Ville"
class=
"b_green"
autocomplete=
"address-level4"
/>
<input
name=
"city"
placeholder=
"Ville"
class=
"b_green"
autocomplete=
"address-level4"
/>
<input
name=
"country"
placeholder=
"Pays"
class=
"b_yellow"
autocomplete=
"address-level4"
/>
<input
name=
"country"
placeholder=
"Pays"
class=
"b_yellow"
autocomplete=
"address-level4"
/>
<span
class=
"phone-wrapper{% if ask_for_second_phone %}-2{% endif %}"
>
<span
class=
"phone-wrapper{% if ask_for_second_phone %}-2{% endif %}"
>
<input
type=
"tel"
name=
"mobile"
placeholder=
"Tél. mobile"
class=
"b_green"
pattern=
"
^(\+\d{1,3}(-| ))?\d{1,2}(\.| )\d{1,2}(\.| )\d{1,2}(\.| )\d{1,2}(\.| )\d{0,2}?$
"
autocomplete=
"address-level4"
/>
<input
type=
"tel"
name=
"mobile"
placeholder=
"Tél. mobile"
class=
"b_green"
pattern=
"
{{input_phone_pattern}}
"
autocomplete=
"address-level4"
/>
{% if ask_for_second_phone %}
{% if ask_for_second_phone %}
<input
type=
"tel"
name=
"phone"
placeholder=
"Tél. fixe"
class=
"b_green"
pattern=
"
^(\+\d{1,3}(-| ))?\d{1,2}(\.| )\d{1,2}(\.| )\d{1,2}(\.| )\d{1,2}(\.| )\d{0,2}?$
"
autocomplete=
"address-level4"
/>
<input
type=
"tel"
name=
"phone"
placeholder=
"Tél. fixe"
class=
"b_green"
pattern=
"
{{input_phone_pattern}}
"
autocomplete=
"address-level4"
/>
{% endif %}
{% endif %}
</span>
</span>
</p>
</p>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment