Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
concrexit
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
70
Issues
70
List
Boards
Labels
Service Desk
Milestones
Merge Requests
10
Merge Requests
10
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
thalia
concrexit
Commits
6ace705e
Verified
Commit
6ace705e
authored
Mar 14, 2018
by
Sébastiaan Versteeg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add failsafes, if no receive_category values are set in the API: enable them all
parent
a1b2460d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
1 deletion
+20
-1
website/pushnotifications/api/serializers.py
website/pushnotifications/api/serializers.py
+9
-0
website/pushnotifications/api/viewsets.py
website/pushnotifications/api/viewsets.py
+6
-1
website/pushnotifications/migrations/0005_populate_category.py
...te/pushnotifications/migrations/0005_populate_category.py
+5
-0
No files found.
website/pushnotifications/api/serializers.py
View file @
6ace705e
from
__future__
import
absolute_import
from
rest_framework.relations
import
ManyRelatedField
,
PrimaryKeyRelatedField
from
rest_framework.serializers
import
ModelSerializer
from
pushnotifications.models
import
Device
,
Category
class
DeviceSerializer
(
ModelSerializer
):
receive_category
=
ManyRelatedField
(
allow_empty
=
True
,
child_relation
=
PrimaryKeyRelatedField
(
allow_empty
=
True
,
queryset
=
Category
.
objects
.
all
(),
required
=
False
)
)
class
Meta
:
model
=
Device
...
...
website/pushnotifications/api/viewsets.py
View file @
6ace705e
...
...
@@ -29,7 +29,12 @@ class DeviceViewSet(ModelViewSet):
)
except
Device
.
DoesNotExist
:
pass
serializer
.
save
(
user
=
self
.
request
.
user
,
language
=
language
)
if
len
(
serializer
.
validated_data
[
'receive_category'
])
>
0
:
serializer
.
save
(
user
=
self
.
request
.
user
,
language
=
language
)
else
:
categories
=
[
c
.
pk
for
c
in
Category
.
objects
.
all
()]
serializer
.
save
(
user
=
self
.
request
.
user
,
language
=
language
,
receive_category
=
categories
)
def
perform_update
(
self
,
serializer
):
serializer
.
save
(
user
=
self
.
request
.
user
)
...
...
website/pushnotifications/migrations/0005_populate_category.py
View file @
6ace705e
...
...
@@ -17,6 +17,11 @@ def forwards_func(apps, schema_editor):
Category
(
key
=
"board"
,
name_en
=
"board"
,
name_nl
=
"bestuur"
),
])
Device
=
apps
.
get_model
(
"pushnotifications"
,
"Device"
)
for
device
in
Device
.
objects
.
using
(
db_alias
).
all
():
for
category
in
Category
.
objects
.
using
(
db_alias
).
all
():
device
.
receive_category
.
add
(
category
)
def
reverse_func
(
apps
,
schema_editor
):
Category
=
apps
.
get_model
(
"pushnotifications"
,
"Category"
)
...
...
Write
Preview
Markdown
is supported
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