Commit 42357112 authored by Gijs Hendriksen's avatar Gijs Hendriksen
Browse files

Save Accept-Language in the push notification Devices

parent 27f3126c
......@@ -8,6 +8,8 @@ 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)
......@@ -19,6 +21,9 @@ 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]
try:
serializer.instance = Device.objects.get(
user=self.request.user,
......@@ -26,7 +31,7 @@ class DeviceViewSet(ModelViewSet):
)
except Device.DoesNotExist:
pass
serializer.save(user=self.request.user)
serializer.save(user=self.request.user, language=language)
def perform_update(self, serializer):
serializer.save(user=self.request.user)
......
# Generated by Django 2.0.2 on 2018-03-07 20:48
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('pushnotifications', '0006_auto_20180228_1942'),
]
operations = [
migrations.AlterField(
model_name='device',
name='language',
field=models.CharField(choices=[('en', 'English'), ('nl', 'Dutch')], default='en', max_length=2, verbose_name='language'),
),
]
......@@ -50,6 +50,7 @@ class Device(models.Model):
verbose_name=_('language'),
max_length=2,
choices=settings.LANGUAGES,
default='en',
)
receive_category = models.ManyToManyField(
......
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