45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
# zoo - versatile objects management
|
|
# Copyright (C) 2016 Entr'ouvert
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify it
|
|
# under the terms of the GNU Affero General Public License as published
|
|
# by the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# 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 unicodedata
|
|
|
|
from rest_framework.views import exception_handler
|
|
from rest_framework.response import Response
|
|
|
|
|
|
def rest_exception_handler(exc, context):
|
|
response = exception_handler(exc, context)
|
|
if response:
|
|
response.data = {
|
|
'err': 1,
|
|
'data': response.data,
|
|
}
|
|
else:
|
|
raise
|
|
response = Response({
|
|
'err': 1,
|
|
'exc_class': str(exc.__class__),
|
|
'exc_value': str(exc),
|
|
})
|
|
response.status = 400
|
|
return response
|
|
|
|
|
|
def strip_accents(s):
|
|
return ''.join(
|
|
c for c in unicodedata.normalize('NFD', s)
|
|
if unicodedata.category(c) != 'Mn')
|