Verified Commit b7abc016 authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Use get_language_from_request instead of directly checking the headers

parent 42357112
from django.utils.translation import get_language_from_request
from rest_framework import permissions
from rest_framework.decorators import list_route
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from pushnotifications.api.permissions import IsOwner
from pushnotifications.api.serializers import DeviceSerializer, \
CategorySerializer
from pushnotifications.api.serializers import (DeviceSerializer,
CategorySerializer)
from pushnotifications.models import Device, Category
from django.utils.translation import to_locale
class DeviceViewSet(ModelViewSet):
permission_classes = (permissions.IsAuthenticated, IsOwner)
......@@ -21,8 +20,7 @@ class DeviceViewSet(ModelViewSet):
return self.queryset.filter(user=self.request.user)
def perform_create(self, serializer):
locale = to_locale(self.request.META['HTTP_ACCEPT_LANGUAGE'])
language = locale.split('_')[0]
language = get_language_from_request(self.request)
try:
serializer.instance = Device.objects.get(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment