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
76e11ca9
Commit
76e11ca9
authored
Jul 11, 2018
by
Luko van der Maas
Browse files
added model fields for the click action of a pushnotification message
parent
0d026aaf
Changes
3
Hide whitespace changes
Inline
Side-by-side
website/pushnotifications/admin.py
View file @
76e11ca9
...
...
@@ -34,21 +34,22 @@ class DeviceAdmin(admin.ModelAdmin):
@
admin
.
register
(
models
.
Message
)
class
MessageAdmin
(
TranslatedModelAdmin
):
"""Manage normal messages"""
list_display
=
(
'title'
,
'body'
,
'category'
,
'sent'
,
'success'
,
'failure'
)
list_display
=
(
'title'
,
'body'
,
'category'
,
'url'
,
'sent'
,
'success'
,
'failure'
)
filter_horizontal
=
(
'users'
,)
list_filter
=
(
'sent'
,
'category'
)
def
get_fields
(
self
,
request
,
obj
=
None
):
if
obj
and
obj
.
sent
:
return
(
'users'
,
'title_nl'
,
'title_en'
,
'body_nl'
,
'body_en'
,
'category'
,
'success'
,
'failure'
)
'url'
,
'category'
,
'success'
,
'failure'
)
return
(
'users'
,
'title_nl'
,
'title_en'
,
'body_nl'
,
'body_en'
,
'category'
)
'url'
,
'category'
)
def
get_readonly_fields
(
self
,
request
,
obj
=
None
):
if
obj
and
obj
.
sent
:
return
(
'users'
,
'title_nl'
,
'title_en'
,
'body_nl'
,
'body_en'
,
'category'
,
'success'
,
'failure'
)
'url'
,
'category'
,
'success'
,
'failure'
)
return
super
().
get_readonly_fields
(
request
,
obj
)
def
change_view
(
self
,
request
,
object_id
,
form_url
=
''
,
**
kwargs
):
...
...
@@ -69,12 +70,12 @@ class ScheduledMessageAdmin(TranslatedModelAdmin):
def
get_fields
(
self
,
request
,
obj
=
None
):
if
obj
and
obj
.
sent
:
return
(
'users'
,
'title_nl'
,
'title_en'
,
'body_nl'
,
'body_en'
,
'category'
,
'success'
,
'failure'
,
'time'
,
'task_id'
)
'url'
,
'category'
,
'success'
,
'failure'
,
'time'
,
'task_id'
)
return
(
'users'
,
'title_nl'
,
'title_en'
,
'body_nl'
,
'body_en'
,
'category'
,
'time'
,
'task_id'
)
'url'
,
'category'
,
'time'
,
'task_id'
)
def
get_readonly_fields
(
self
,
request
,
obj
=
None
):
if
obj
and
obj
.
sent
:
return
(
'users'
,
'title_nl'
,
'title_en'
,
'body_nl'
,
'body_en'
,
'category'
,
'success'
,
'failure'
,
'time'
,
'task_id'
)
'url'
,
'category'
,
'success'
,
'failure'
,
'time'
,
'task_id'
)
return
'task_id'
,
website/pushnotifications/migrations/0009_message_url.py
0 → 100644
View file @
76e11ca9
# Generated by Django 2.0.6 on 2018-07-11 17:34
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'pushnotifications'
,
'0008_scheduledmessage'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'message'
,
name
=
'url'
,
field
=
models
.
CharField
(
max_length
=
256
,
null
=
True
,
verbose_name
=
'url'
),
),
]
website/pushnotifications/models.py
View file @
76e11ca9
...
...
@@ -89,6 +89,11 @@ class Message(models.Model, metaclass=ModelTranslateMeta):
models
.
TextField
,
verbose_name
=
_
(
'body'
)
)
url
=
models
.
CharField
(
verbose_name
=
_
(
'url'
),
max_length
=
256
,
null
=
True
)
category
=
models
.
ForeignKey
(
Category
,
on_delete
=
models
.
CASCADE
,
...
...
@@ -135,15 +140,17 @@ class Message(models.Model, metaclass=ModelTranslateMeta):
any_reg_ids
=
True
if
self
.
url
is
not
None
:
kwargs
[
'click_action'
]
=
self
.
url
result
=
FCMNotification
(
api_key
=
settings
.
PUSH_NOTIFICATIONS_API_KEY
).
notify_multiple_devices
(
registration_ids
=
reg_ids
,
message_title
=
self
.
title
,
message_body
=
str
(
self
.
body
),
color
=
'#
0
62272'
,
color
=
'#
E
62272'
,
sound
=
'default'
,
click_action
=
'https://thalia.nu/pizzas/'
,
**
kwargs
)
...
...
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