-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(push notification):send notification
- add follow model for user follower - add notification app - add notifications on installed apps - add notifications view [finishes #161254670]
- Loading branch information
Gidraf
committed
Nov 19, 2018
1 parent
615ace6
commit 3a4debe
Showing
23 changed files
with
667 additions
and
76 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
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from ..profiles.models import UserProfile, Follow | ||
from django.template.loader import render_to_string | ||
from django.core.mail import send_mail | ||
from .models import Article, Favorite | ||
from authors.settings import DEFAULT_DOMAIN, EMAIL_HOST_USER | ||
|
||
from ..notifications.models import NotificationsFollower, NotificationsArticle | ||
|
||
|
||
def send_article_notification(slug, data, request): | ||
""" | ||
send email to article favourites | ||
""" | ||
try: | ||
article = Article.objects.get(slug=slug) | ||
subscribers = Favorite.objects.filter(article=article) | ||
for subscriber in subscribers: | ||
message = request.user.username + " commented on this article " | ||
link = DEFAULT_DOMAIN + '/api/article/detail/' + \ | ||
article.slug | ||
msg = render_to_string('article_alert.html', { | ||
'user': subscriber.user.username, | ||
"link": link, | ||
"message": message, | ||
"comment": data["body"] | ||
}) | ||
send_mail('Authors Heaven New Article!', | ||
'New Comment!!!!', | ||
EMAIL_HOST_USER, | ||
[subscriber.user.email], | ||
html_message=msg, | ||
fail_silently=False) | ||
NotificationsArticle( | ||
subscriber_id=subscriber.pk, | ||
article_id=article.pk).save() | ||
except Exception as error: | ||
print(str(error)) | ||
|
||
|
||
def send_followers_notification(instance, request, user): | ||
""" | ||
send email to user following the author | ||
""" | ||
try: | ||
profile = UserProfile.objects.get(user=user) | ||
followers = Follow.objects.filter(follower=profile) | ||
article = Article.objects.get(title=instance["title"]) | ||
for follower in followers: | ||
message = article.user.username + " published new article " | ||
link = DEFAULT_DOMAIN + '/api/article/detail/' + \ | ||
article.slug | ||
follower_message = render_to_string('followee_alert.html', { | ||
'user': follower.followee.user.username, | ||
"link": link, | ||
"message": message, | ||
"title": instance["title"] | ||
}) | ||
send_mail('Authors Heaven New Article!', | ||
'New Article!!!!', | ||
EMAIL_HOST_USER, | ||
[follower.followee.user.email], | ||
html_message=follower_message, | ||
fail_silently=False) | ||
NotificationsFollower( | ||
follower=profile, | ||
followee=follower.followee, | ||
article=article).save() | ||
except Exception as error: | ||
print(str(error)) |
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<style> | ||
.card { | ||
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2); | ||
max-width: 600px; | ||
margin: auto; | ||
text-align: center; | ||
font-family: arial; | ||
} | ||
|
||
.title { | ||
color: grey; | ||
font-size: 13px; | ||
text-align: left; | ||
} | ||
|
||
button { | ||
border: none; | ||
outline: 0; | ||
display: inline-block; | ||
padding: 8px; | ||
color: #000;; | ||
background-color: #000; | ||
text-align: center; | ||
cursor: pointer; | ||
width: 100%; | ||
font-size: 18px; | ||
} | ||
|
||
a { | ||
text-decoration: none; | ||
font-size: 13px; | ||
color: black; | ||
} | ||
|
||
button:hover, a:hover { | ||
opacity: 0.7; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
|
||
<div class="card"> | ||
<p class="title"> | ||
Hi {{user}},<br></p> | ||
<p class="title"> New Comment!!!! <a href={{ENVIRONMENT}}> | ||
Authors Heaven</a>, the platform for | ||
people with expressive ideas.</p> | ||
<p class="title">{{message}}<a href={{link}}> {{comment}} </a>view it on Authors Haven</p> | ||
<p><button></button>Authors Heavens. All Rights Reserved</p> | ||
</div> | ||
|
||
</body> | ||
</html> |
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,56 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<style> | ||
.card { | ||
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2); | ||
max-width: 600px; | ||
margin: auto; | ||
text-align: center; | ||
font-family: arial; | ||
} | ||
|
||
.title { | ||
color: grey; | ||
font-size: 13px; | ||
text-align: left; | ||
} | ||
|
||
button { | ||
border: none; | ||
outline: 0; | ||
display: inline-block; | ||
padding: 8px; | ||
color: #000;; | ||
background-color: #000; | ||
text-align: center; | ||
cursor: pointer; | ||
width: 100%; | ||
font-size: 18px; | ||
} | ||
|
||
a { | ||
text-decoration: none; | ||
font-size: 13px; | ||
color: black; | ||
} | ||
|
||
button:hover, a:hover { | ||
opacity: 0.7; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
|
||
<div class="card"> | ||
<p class="title"> | ||
Hi {{user}},<br></p> | ||
<p class="title"> New Article!!!! <a href={{ENVIRONMENT}}> | ||
Authors Heaven</a>, the platform for | ||
people with expressive ideas.</p> | ||
<p class="title">{{message}}<a href={{link}}> {{title}} </a>view it on Authors Haven</p> | ||
<p><button></button>Authors Heavens. All Rights Reserved</p> | ||
</div> | ||
|
||
</body> | ||
</html> |
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
Oops, something went wrong.