Commit b2543977 authored by Thom Wiggers's avatar Thom Wiggers 📐
Browse files

Merge branch 'feature/save-language-in-push-notification-api' into 'master'

Save Accept-Language in the push notification Devices

See merge request thalia/concrexit!744
parents 0deddef3 b7abc016
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
......@@ -19,6 +20,8 @@ class DeviceViewSet(ModelViewSet):
return self.queryset.filter(user=self.request.user)
def perform_create(self, serializer):
language = get_language_from_request(self.request)
try:
serializer.instance = Device.objects.get(
user=self.request.user,
......@@ -26,7 +29,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