-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ft(notifications-system) : Implement the notification system
- add unit tests - implement notifications system - set up an asyncronuos task queing system - update the Read.me - Update requirements.txt - Update the .procfile for monitoring of the asyncronous tasks
- Loading branch information
1 parent
946a579
commit 7eabb8e
Showing
31 changed files
with
1,205 additions
and
85 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
release: ./release-tasks.sh | ||
web: gunicorn authors.wsgi —-log-file - | ||
release: ./release-tasks.sh | ||
web: gunicorn authors.wsgi —-log-file - | ||
worker: python manage.py qcluster |
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
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
Empty file.
Empty file.
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,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class FavouriteConfig(AppConfig): | ||
name = 'authors.apps.favourite' |
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,86 @@ | ||
""" | ||
Models for Favourite app | ||
""" | ||
import logging | ||
|
||
from django.contrib.auth import get_user_model | ||
from django.db import models | ||
|
||
# local imports | ||
from django.db.models.signals import post_save | ||
from django.dispatch import receiver | ||
from rest_framework.reverse import reverse | ||
|
||
from authors.apps.articles.models import Articles | ||
from authors.apps.authentication.models import User | ||
from authors.apps.notifier.utils import Notifier | ||
from authors.apps.profiles.models import Profile | ||
|
||
logger = logging.getLogger(__file__) | ||
|
||
|
||
# Create your models here. | ||
class Favourite(models.Model): | ||
""" | ||
Define the model for Favourite | ||
""" | ||
# Favourite can only be either 1 or -1 | ||
FAVOURITE_CHOICES = ( | ||
(1, 'FAVOURITE'), | ||
(-1, 'UNFAVOURITE'), | ||
) | ||
user = models.ForeignKey(Profile, on_delete=models.CASCADE) | ||
article = models.ForeignKey( | ||
Articles, on_delete=models.CASCADE) | ||
favourite = models.IntegerField(choices=FAVOURITE_CHOICES) | ||
set_on = models.DateTimeField(auto_now_add=True) | ||
|
||
class Meta: | ||
unique_together = ('user', 'article', 'favourite') | ||
|
||
def get_favouriters(self): | ||
""" | ||
Reuturn users who have favourited an article | ||
:return: | ||
""" | ||
article = self.article | ||
favourites = Favourite.objects.filter(article=article, favourite=1) | ||
favouriters = favourites.values('user') | ||
# get a null queryset and append users to it | ||
user = get_user_model() | ||
users = user.objects.filter(pk=None) | ||
for favouriter in favouriters: | ||
logger.debug(favouriter) | ||
u = user.objects.filter(pk=favouriter['user']) | ||
users = Notifier.intersect_querysets(users, u) | ||
# return a queryset of users | ||
return users | ||
|
||
|
||
@receiver(post_save, sender=Favourite) | ||
def fovourites_notifications_handler(sender, created, **kwargs): | ||
"""Notify the author when their article is favourited""" | ||
instance = kwargs['instance'] | ||
if created: | ||
logger.debug("article %s has been favourited by %s" % ( | ||
instance.article, instance.user)) | ||
|
||
url = reverse('articleSpecific', args=[instance.article.slug, ]) | ||
reverse_url = reverse('mailing-list-status') | ||
|
||
subject = "New Article favourite Notification" | ||
Message = """ | ||
Your article %s has been favourited by %s. | ||
You are seeing this email because you are subscribed to /n | ||
receive email notifications.To unsubscribe from this emails | ||
login and unsubscribe by following %s | ||
""" % (url, instance.user.username, reverse_url) | ||
|
||
Notifier.notify_multiple( | ||
actor=instance.user, | ||
action_object=instance.article, | ||
verb="Commented on the article", | ||
recipients=User.objects.filter(pk=instance.user.pk), | ||
message=Message, | ||
subject=subject | ||
) |
Empty file.
Empty file.
Empty file.
Empty file.
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,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class NotificationsConfig(AppConfig): | ||
name = 'authors.apps.notifier' |
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,44 @@ | ||
# # # import logging | ||
# # # | ||
# # # from django.db.models.signals import post_save | ||
# # # from django.dispatch import receiver | ||
# # # | ||
# # # from authors.apps.articles.models import Articles | ||
# # # | ||
# # # logger = logging.getLogger(__name__) | ||
# # # | ||
# # # | ||
# # # @receiver(post_save, sender=Articles) | ||
# # # def articles_notifications_handler(sender, **kwargs): | ||
# # # logger.error(sender) | ||
# # # logger.error(kwargs) | ||
# # from authors.apps.authentication.tests.factories.authentication import \ | ||
# # UserFactory2, ArticlesFactory, FollowerFactory | ||
# # from authors.apps.profiles.models import Profile | ||
# # | ||
# # prof = Profile.objects.get_or_create(user=4) | ||
# # prof = prof[0] | ||
# # ArticlesFactory(author=prof.user) | ||
# # | ||
# # from authors.apps.notifier.models import MailingList | ||
# # | ||
# # from django.contrib.auth import get_user_model | ||
# # | ||
# # user = get_user_model() | ||
# # users = user.objects.get(pk=1) | ||
# # MailingList.is_email_subscribed(users) | ||
# | ||
# from django.contrib.auth import get_user_model | ||
# | ||
# get_user_model() | ||
# user = get_user_model() | ||
# kinus = user.objects.get(username='fgkinus') | ||
# testuser = user.objects.get(pk=1) | ||
# from authors.apps.authentication.tests.factories.authentication import \ | ||
# UserFactory2, ArticlesFactory, FollowerFactory, CommentFactory | ||
# from authors.apps.profiles.models import Profile | ||
# | ||
# # FollowerFactory(followed=kinus, follower=testuser) | ||
# FollowerFactory() | ||
# # ArticlesFactory(author=testuser) | ||
# # CommentFactory() |
Oops, something went wrong.