0001-grenoble_gru-strip-emojis-from-demand-description-54.patch
passerelle/contrib/grenoble_gru/models.py | ||
---|---|---|
14 | 14 |
# You should have received a copy of the GNU Affero General Public License |
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 |
import re |
|
18 | ||
17 | 19 |
from django.core.cache import cache |
18 | 20 |
from django.db import models |
19 | 21 |
from django.utils import dateparse |
... | ... | |
60 | 62 |
return value |
61 | 63 | |
62 | 64 | |
65 |
def strip_emoji(value): |
|
66 |
emoji_pattern = re.compile( |
|
67 |
"[" |
|
68 |
"\U00002700-\U000027BF" # Dingbats |
|
69 |
"\U0001F300-\U0001F5FF" # symbols & pictographs |
|
70 |
"\U0001F600-\U0001F64F" # emoticons |
|
71 |
"\U0001F680-\U0001F6FF" # transport & map symbols |
|
72 |
"]+", |
|
73 |
) |
|
74 |
return emoji_pattern.sub(r'', value) |
|
75 | ||
76 | ||
63 | 77 |
class GrenobleGRU(BaseResource): |
64 | 78 |
base_url = models.URLField( |
65 | 79 |
max_length=256, blank=False, verbose_name=_('Base URL'), help_text=_('Grenoble GRU API base URL') |
... | ... | |
131 | 145 |
'obs_motif': check_value( |
132 | 146 |
data, 'intervention_reason', self.types('//motif', True, types_params) |
133 | 147 |
), |
134 |
'obs_description_probleme': data.get('comment_description', ''),
|
|
148 |
'obs_description_probleme': strip_emoji(data.get('comment_description', '')),
|
|
135 | 149 |
} |
136 | 150 |
) |
137 | 151 |
if data['intervention_reason'] == '24': |
tests/test_grenoble_gru.py | ||
---|---|---|
54 | 54 |
"dysfonction_type": '3', |
55 | 55 |
"intervention_reason": '2', |
56 | 56 |
'dem_pav': 'déchetterie', |
57 |
'comment_description': 'thank you 😘', |
|
57 | 58 |
} |
58 | 59 | |
59 | 60 |
DEMAND = """<demande IdGRU="1324" idInterne="422"> |
... | ... | |
240 | 241 |
assert request_post.call_args[1]['data']['dem_comp'] == 'Voirie' |
241 | 242 |
assert request_post.call_args[1]['data']['dem_pav'] == u'déchetterie' |
242 | 243 |
assert request_post.call_args[1]['data']['dem_reponse'] == 0 |
244 |
assert request_post.call_args[1]['data']['obs_description_probleme'] == 'thank you ' |
|
243 | 245 | |
244 | 246 |
payload['applicant_requires_reply'] = True |
245 | 247 |
payload['urgent_demand'] = 'True' |
246 |
- |