Skip to content

Commit

Permalink
Merge c62b25a into e7c7c0a
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwellgithinji committed Nov 16, 2018
2 parents e7c7c0a + c62b25a commit 2daa302
Show file tree
Hide file tree
Showing 25 changed files with 1,215 additions and 13 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ before_script:

script:
- python manage.py makemigrations
- python manage.py migrate notifications
- coverage run manage.py test

after_success:
Expand Down
Binary file added authors/apps/.DS_Store
Binary file not shown.
63 changes: 63 additions & 0 deletions authors/apps/articles/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
"""articles/models.py"""
from django.db import models

from django.db.models.signals import post_save
from notifications.signals import notify

from django.contrib.postgres.fields import ArrayField
from authors.apps.authentication.models import User
from django.utils.text import slugify

from authors.apps.authentication.models import User
from authors.apps.profiles.models import Profile


class Article(models.Model):
Expand Down Expand Up @@ -106,6 +114,61 @@ def __str__(self):
return self.body


def article_handler(sender, instance, created, **kwargs):
"""
Notifications handler to notify all the followers
of an author that he has published a new article
:params: sender: the actor (author) who is doing the action of
posting an article
:params: instance: the author instance
:params: created: timestamp when the action happened
"""
try:
author = instance.author
#get all users following the user
my_followers = author.profile.get_my_followers()
#notify each follower that the user has published an article
for followers in my_followers:
followers = User.objects.filter(username=followers)
notify.send(
instance,
recipient=followers,
verb='{} published a new article'.format(author.username))
except Exception:
"author not found"


def favorite_comment_handler(sender, instance, created, **kwargs):
"""
Comment handler to notify the favouriters of a certain article
that it has received a comment
:params: sender: the actor (commenter) who is doing the action of
posting commenting on my article
:params: instance: the comment
:params: created: timestamp when the action happened
"""
try:
# initialize the author of the comment
author = instance.author
# initialize the author of the article
article_author = [instance.article.author]
article_slug = instance.article.slug
articles_instance = Article.objects.get(slug=article_slug)
favouriters = articles_instance.favorited_by.values()
for user_id in articles_instance.favorited_by.values():
favouriters_name = User.objects.get(id=user_id['user_id'])
# notify each favouriter of an article
notify.send(
instance,
recipient=favouriters_name,
verb='{} commented on an article you have favorited'.format(author.username))
except:
"article not found"

post_save.connect(article_handler, sender=Article)
post_save.connect(favorite_comment_handler, sender=Comment)


class LikesDislikes(models.Model):
article = models.ForeignKey(Article, related_name='like', on_delete=models.CASCADE)
reader = models.ForeignKey(User, related_name='like', on_delete=models.CASCADE)
Expand Down
82 changes: 82 additions & 0 deletions authors/apps/articles/templates/comments.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width">
<title>Authors Heaven</title>
<style>
body{
background-color: #f3f3f3;
}
div{
width: 80%;
margin: 0 auto;
background-color: #fefefe;
float: none;
padding-top: 32px;
padding-bottom: 16px;
padding-left: 16px;
padding-right: 16px;
}

h5{
margin-top: 56px;
font-size: 24px;
font-family: 'Open Sans', sans-serif;
text-align: right;
}

p{
text-align: left;
font-size: 16px;
color: #808080;
padding-top: 16px;
}

a{
font-weight: 800;
color: #039be5;
text-decoration: none;
}

h6{
color: grey;
font-family: Helvetica,Arial,sans-serif;
font-size: 10px;
font-weight: 400;
line-height: 1.3;
margin: 0;
margin-bottom: 10px;
padding: 0;
text-align: right;
padding-top: 16px;
}
</style>
</head>
<body style="background-color: #f3f3f3;">
<div style="width: 80%;margin: 0 auto;background-color: #fefefe;float: none;padding-top: 32px;padding-bottom: 16px;padding-left: 16px;padding-right: 16px;">
<h5 style="margin-top: 56px;font-size: 24px;font-family: 'Open Sans', sans-serif;text-align: left; color:orange;">Authors Haven</h5>
<p style="text-align: left;font-size: 16px;color: #808080;padding-top: 16px;">Hi {{username}},</p>
<p style="text-align: left;font-size: 16px;color: #808080;padding-top: 16px;"><strong>{{commenter}}</strong> has just commented on one of your favorite articles, <strong>{{article_title}}</strong></p>
<p style="text-align: left;font-size: 16px;color: #808080;padding-top: 16px;">Go to <a href="{{article_link}}">Author's Haven</a> an check it out</p></p>
<p style="text-align: left;font-size: 16px;color: #808080;padding-top: 16px;">If you wish unsubscribe from email notifications, click the link below</p>
<form action='{{unsubscribe_url}}' method="post">
<input
type="Submit"
value="Unsubscribe"
style="width: 30%;
margin-left: 30%;
padding: 10px;
box-shadow: 1px 1px 1px grey;
color:orange;
background-color: black;
opacity: .7;
border: none;
transition: .5s ease;">
</form>
<h6 style="color: grey;font-family: Helvetica,Arial,sans-serif;font-size: 10px;font-weight: 400;line-height: 1.3;margin: 0;margin-bottom: 10px;padding: 0;text-align: right;padding-top: 16px;">2018 Authors Haven . All Rights Reserved</h6>
</div>
</body>
</html>
82 changes: 82 additions & 0 deletions authors/apps/articles/templates/favorite.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width">
<title>Authors Heaven</title>
<style>
body{
background-color: #f3f3f3;
}
div{
width: 80%;
margin: 0 auto;
background-color: #fefefe;
float: none;
padding-top: 32px;
padding-bottom: 16px;
padding-left: 16px;
padding-right: 16px;
}

h5{
margin-top: 56px;
font-size: 24px;
font-family: 'Open Sans', sans-serif;
text-align: right;
}

p{
text-align: left;
font-size: 16px;
color: #808080;
padding-top: 16px;
}

a{
font-weight: 800;
color: #039be5;
text-decoration: none;
}

h6{
color: grey;
font-family: Helvetica,Arial,sans-serif;
font-size: 10px;
font-weight: 400;
line-height: 1.3;
margin: 0;
margin-bottom: 10px;
padding: 0;
text-align: right;
padding-top: 16px;
}
</style>
</head>
<body style="background-color: #f3f3f3;">
<div style="width: 80%;margin: 0 auto;background-color: #fefefe;float: none;padding-top: 32px;padding-bottom: 16px;padding-left: 16px;padding-right: 16px;">
<h5 style="margin-top: 56px;font-size: 24px;font-family: 'Open Sans', sans-serif;text-align: left; color:orange;">Authors Haven</h5>
<p style="text-align: left;font-size: 16px;color: #808080;padding-top: 16px;">Hi {{username}},</p>
<p style="text-align: left;font-size: 16px;color: #808080;padding-top: 16px;"><strong>{{favouriter}}</strong> has just marked your article, <strong>{{article_title}}</strong> , as their favorite</p>
<p style="text-align: left;font-size: 16px;color: #808080;padding-top: 16px;">Go to <a href="{{article_link}}">Author's Haven</a> an check it out</p></p>
<p style="text-align: left;font-size: 16px;color: #808080;padding-top: 16px;">If you wish unsubscribe from email notifications, click the link below</p>
<form action='{{unsubscribe_url}}' method="post">
<input
type="Submit"
value="Unsubscribe"
style="width: 30%;
margin-left: 30%;
padding: 10px;
box-shadow: 1px 1px 1px grey;
color:orange;
background-color: black;
opacity: .7;
border: none;
transition: .5s ease;">
</form>
<h6 style="color: grey;font-family: Helvetica,Arial,sans-serif;font-size: 10px;font-weight: 400;line-height: 1.3;margin: 0;margin-bottom: 10px;padding: 0;text-align: right;padding-top: 16px;">2018 Authors Haven . All Rights Reserved</h6>
</div>
</body>
</html>
82 changes: 82 additions & 0 deletions authors/apps/articles/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width">
<title>Authors Heaven</title>
<style>
body{
background-color: #f3f3f3;
}
div{
width: 80%;
margin: 0 auto;
background-color: #fefefe;
float: none;
padding-top: 32px;
padding-bottom: 16px;
padding-left: 16px;
padding-right: 16px;
}

h5{
margin-top: 56px;
font-size: 24px;
font-family: 'Open Sans', sans-serif;
text-align: right;
}

p{
text-align: left;
font-size: 16px;
color: #808080;
padding-top: 16px;
}

a{
font-weight: 800;
color: #039be5;
text-decoration: none;
}

h6{
color: grey;
font-family: Helvetica,Arial,sans-serif;
font-size: 10px;
font-weight: 400;
line-height: 1.3;
margin: 0;
margin-bottom: 10px;
padding: 0;
text-align: right;
padding-top: 16px;
}
</style>
</head>
<body style="background-color: #f3f3f3;">
<div style="width: 80%;margin: 0 auto;background-color: #fefefe;float: none;padding-top: 32px;padding-bottom: 16px;padding-left: 16px;padding-right: 16px;">
<h5 style="margin-top: 56px;font-size: 24px;font-family: 'Open Sans', sans-serif;text-align: left; color:orange;">Authors Haven</h5>
<p style="text-align: left;font-size: 16px;color: #808080;padding-top: 16px;">Hi {{username}},</p>
<p style="text-align: left;font-size: 16px;color: #808080;padding-top: 16px;">An author you follow, <strong>{{author}}</strong> has just published a new article, <strong>{{article_title}}</strong></p>
<p style="text-align: left;font-size: 16px;color: #808080;padding-top: 16px;">Go to <a href="{{article_link}}">Author's Haven</a> an check it out</p></p>
<p style="text-align: left;font-size: 16px;color: #808080;padding-top: 16px;">If you wish unsubscribe from email notifications, click the link below</p>
<form action='{{unsubscribe_url}}' method="post">
<input
type="Submit"
value="Unsubscribe"
style="width: 30%;
margin-left: 30%;
padding: 10px;
box-shadow: 1px 1px 1px grey;
color:orange;
background-color: black;
opacity: .7;
border: none;
transition: .5s ease;">
</form>
<h6 style="color: grey;font-family: Helvetica,Arial,sans-serif;font-size: 10px;font-weight: 400;line-height: 1.3;margin: 0;margin-bottom: 10px;padding: 0;text-align: right;padding-top: 16px;">2018 Authors Haven . All Rights Reserved</h6>
</div>
</body>
</html>
Loading

0 comments on commit 2daa302

Please sign in to comment.