Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
thalia
concrexit
Commits
42357112
Commit
42357112
authored
Mar 07, 2018
by
Gijs Hendriksen
Browse files
Save Accept-Language in the push notification Devices
parent
27f3126c
Changes
3
Hide whitespace changes
Inline
Side-by-side
website/pushnotifications/api/viewsets.py
View file @
42357112
...
...
@@ -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
)
...
...
website/pushnotifications/migrations/0007_auto_20180307_2148.py
0 → 100644
View file @
42357112
# 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'
),
),
]
website/pushnotifications/models.py
View file @
42357112
...
...
@@ -50,6 +50,7 @@ class Device(models.Model):
verbose_name
=
_
(
'language'
),
max_length
=
2
,
choices
=
settings
.
LANGUAGES
,
default
=
'en'
,
)
receive_category
=
models
.
ManyToManyField
(
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment