grenoble_gru: strip emojis from demand description (#54028)

This commit is contained in:
Serghei Mihai 2021-05-17 15:31:51 +02:00
parent cab9ddf370
commit f2996eb9c6
2 changed files with 17 additions and 1 deletions

View File

@ -14,6 +14,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import re
from django.core.cache import cache
from django.db import models
from django.utils import dateparse
@ -60,6 +62,18 @@ def check_value(data, field_name, values):
return value
def strip_emoji(value):
emoji_pattern = re.compile(
"["
"\U00002700-\U000027BF" # Dingbats
"\U0001F300-\U0001F5FF" # symbols & pictographs
"\U0001F600-\U0001F64F" # emoticons
"\U0001F680-\U0001F6FF" # transport & map symbols
"]+",
)
return emoji_pattern.sub(r'', value)
class GrenobleGRU(BaseResource):
base_url = models.URLField(
max_length=256, blank=False, verbose_name=_('Base URL'), help_text=_('Grenoble GRU API base URL')
@ -131,7 +145,7 @@ class GrenobleGRU(BaseResource):
'obs_motif': check_value(
data, 'intervention_reason', self.types('//motif', True, types_params)
),
'obs_description_probleme': data.get('comment_description', ''),
'obs_description_probleme': strip_emoji(data.get('comment_description', '')),
}
)
if data['intervention_reason'] == '24':

View File

@ -54,6 +54,7 @@ BASIC_PAYLOAD = {
"dysfonction_type": '3',
"intervention_reason": '2',
'dem_pav': 'déchetterie',
'comment_description': 'thank you 😘',
}
DEMAND = """<demande IdGRU="1324" idInterne="422">
@ -240,6 +241,7 @@ def test_demand_creation_params(app, setup):
assert request_post.call_args[1]['data']['dem_comp'] == 'Voirie'
assert request_post.call_args[1]['data']['dem_pav'] == u'déchetterie'
assert request_post.call_args[1]['data']['dem_reponse'] == 0
assert request_post.call_args[1]['data']['obs_description_probleme'] == 'thank you '
payload['applicant_requires_reply'] = True
payload['urgent_demand'] = 'True'