-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add several functions and maps for notifications logic (#324)
* Add several functions and maps for notifications logic, not working * Finish notification sending function * Remove redundant check for valid notification channel for notification type * Send notifications when notification events occur * Recommend unused function * Add throttle classes back * Fix file extensions * Fix notification template prefix * Add message field to notification model to support notifications that mention project names * Properly create migrations and use char field * Use name instead of label for django integer choice class * Change notification link attribute to be a char field * Fix email templates for notifications
- Loading branch information
1 parent
e643519
commit 8c9ebc1
Showing
35 changed files
with
316 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,3 +82,4 @@ vine>=1.3.0 | |
watchdog>=0.10.2 | ||
wcwidth>=0.2.5 | ||
whitenoise>=4.1.4 | ||
django-extensions>=1.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
zubhub_backend/zubhub/creators/migrations/0005_alter_setting_contact.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 3.2 on 2022-03-20 21:33 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('creators', '0004_auto_20220222_0254'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='setting', | ||
name='contact', | ||
field=models.PositiveSmallIntegerField(blank=True, choices=[(1, 'WHATSAPP'), (2, 'EMAIL'), (3, 'SMS'), (4, 'WEB')], default=3, null=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from django.core.exceptions import FieldDoesNotExist | ||
|
||
from django.contrib.auth import get_user_model | ||
|
||
|
||
def user_field(user, field, *args): | ||
""" | ||
Gets or sets (optional) user model fields. No-op if fields do not exist. | ||
""" | ||
if not field: | ||
return | ||
User = get_user_model() | ||
try: | ||
field_meta = User._meta.get_field(field) | ||
max_length = field_meta.max_length | ||
except FieldDoesNotExist: | ||
if not hasattr(user, field): | ||
return | ||
max_length = None | ||
if args: | ||
# Setter | ||
v = args[0] | ||
if v: | ||
v = v[0:max_length] | ||
setattr(user, field, v) | ||
else: | ||
# Getter | ||
return getattr(user, field) | ||
|
||
|
||
def user_phone(user, *args): | ||
return user_field(user, "phone", *args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
zubhub_backend/zubhub/notifications/migrations/0005_alter_notification_type.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 3.2 on 2022-03-20 21:33 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('notifications', '0004_notification_link'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='notification', | ||
name='type', | ||
field=models.PositiveSmallIntegerField(choices=[(1, 'Bookmark'), (2, 'Clap'), (3, 'Comment'), (4, 'Follow'), (5, 'Following Project')]), | ||
), | ||
] |
18 changes: 18 additions & 0 deletions
18
zubhub_backend/zubhub/notifications/migrations/0006_notification_message.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 3.2 on 2022-03-20 21:42 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('notifications', '0005_alter_notification_type'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='notification', | ||
name='message', | ||
field=models.CharField(blank=True, max_length=255, null=True), | ||
), | ||
] |
18 changes: 18 additions & 0 deletions
18
zubhub_backend/zubhub/notifications/migrations/0007_alter_notification_link.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 3.2 on 2022-03-22 01:34 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('notifications', '0006_notification_message'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='notification', | ||
name='link', | ||
field=models.CharField(blank=True, max_length=1000, null=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
from notifications.models import Notification | ||
from django.utils import timezone | ||
|
||
|
||
def push_notification(recipient, source, type, link): | ||
return Notification.objects.create(recipient=recipient, source=source, type=type, link=link) | ||
def push_notification(recipient, source, notification_type, message, link): | ||
return Notification.objects.create(recipient=recipient, source=source, type=notification_type, message=message, link=link) |
Oops, something went wrong.