notifications: force_text

This commit is contained in:
Frédéric Péters 2018-07-25 21:46:36 +02:00
parent 46847b2198
commit 263b2ed8d2
2 changed files with 5 additions and 3 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/>.
from django.utils.encoding import force_text
from rest_framework import serializers, permissions, status
from rest_framework.generics import GenericAPIView
from rest_framework.response import Response
@ -55,7 +57,7 @@ class Add(GenericAPIView):
duration=data.get('duration'),
)
except ValueError as e:
response = {'err': 1, 'err_desc': {'id': [unicode(e)]}}
response = {'err': 1, 'err_desc': {'id': [force_text(e)]}}
return Response(response, status.HTTP_400_BAD_REQUEST)
else:
response = {'err': 0, 'data': {'id': notification.public_id}}

View File

@ -18,7 +18,7 @@ import re
from django.conf import settings
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django.utils.encoding import force_text, python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _
from django.utils.timezone import now, timedelta
from django.db.models import Q
@ -138,7 +138,7 @@ class Notification(models.Model):
if id:
try:
id = unicode(id)
id = force_text(id)
except Exception as e:
raise ValueError('id must be convertible to unicode', e)
if not re.match(cls.ID_RE, id):