-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from rshrc/notifications
Notifications for follow/issues/solutions
- Loading branch information
Showing
20 changed files
with
681 additions
and
195 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
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.
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,10 @@ | ||
from django.contrib import admin | ||
from .models import * | ||
|
||
# Register your models here. | ||
admin.site.register(IssueNotification) | ||
admin.site.register(SolutionNotification) | ||
admin.site.register(InterestedNotification) | ||
admin.site.register(FollowNotification) | ||
admin.site.register(IssueCommentNotification) | ||
admin.site.register(SolutionCommentNotification) |
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 = 'notifications' |
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,84 @@ | ||
# Generated by Django 2.0.6 on 2018-07-07 05:16 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('accounts', '0004_auto_20180705_0355'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='FollowNotification', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('text', models.CharField(max_length=300)), | ||
('date', models.DateField(auto_now_add=True)), | ||
('status', models.CharField(choices=[('1', 'Seen'), ('0', 'Unseen')], max_length=1)), | ||
('follow', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='accounts.Follow')), | ||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='InterestedNotification', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('text', models.CharField(max_length=300)), | ||
('date', models.DateField(auto_now_add=True)), | ||
('status', models.CharField(choices=[('1', 'Seen'), ('0', 'Unseen')], max_length=1)), | ||
('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='accounts.ProjectDetail')), | ||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='IssueCommentNotification', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('text', models.CharField(max_length=300)), | ||
('date', models.DateField(auto_now_add=True)), | ||
('status', models.CharField(choices=[('1', 'Seen'), ('0', 'Unseen')], max_length=1)), | ||
('issueComment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='accounts.IssueComment')), | ||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='IssueNotification', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('text', models.CharField(max_length=300)), | ||
('date', models.DateField(auto_now_add=True)), | ||
('status', models.CharField(choices=[('1', 'Seen'), ('0', 'Unseen')], max_length=1)), | ||
('issue', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='accounts.Issue')), | ||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='SolutionCommentNotification', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('text', models.CharField(max_length=300)), | ||
('date', models.DateField(auto_now_add=True)), | ||
('status', models.CharField(choices=[('1', 'Seen'), ('0', 'Unseen')], max_length=1)), | ||
('solutionComment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='accounts.SolutionComment')), | ||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='SolutionNotification', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('text', models.CharField(max_length=300)), | ||
('date', models.DateField(auto_now_add=True)), | ||
('status', models.CharField(choices=[('1', 'Seen'), ('0', 'Unseen')], max_length=1)), | ||
('solution', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='accounts.Solution')), | ||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
] |
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,74 @@ | ||
from django.db import models | ||
from django.contrib.auth.models import User | ||
import notifications.signals | ||
from django.db.models.signals import post_save | ||
from accounts.models import * | ||
|
||
|
||
# from accounts.models import Issue,Solution,ProjectPeopleInterested,Follow,IssueComment,SolutionComment | ||
# Create your models here. | ||
|
||
class IssueNotification(models.Model): | ||
user = models.ForeignKey(User, on_delete=models.CASCADE) | ||
issue = models.ForeignKey('accounts.Issue', on_delete=models.CASCADE) | ||
text = models.CharField(max_length=300) | ||
date = models.DateField(auto_now_add=True) | ||
status = models.CharField(max_length=1, choices=(("1", "Seen"), ("0", "Unseen"))) | ||
|
||
def __str__(self): | ||
return self.text | ||
|
||
|
||
class SolutionNotification(models.Model): | ||
user = models.ForeignKey(User, on_delete=models.CASCADE) | ||
solution = models.ForeignKey('accounts.Solution', on_delete=models.CASCADE) | ||
text = models.CharField(max_length=300) | ||
date = models.DateField(auto_now_add=True) | ||
status = models.CharField(max_length=1, choices=(("1", "Seen"), ("0", "Unseen"))) | ||
|
||
def __str__(self): | ||
return self.text | ||
|
||
|
||
class InterestedNotification(models.Model): | ||
user = models.ForeignKey(User, on_delete=models.CASCADE) | ||
project = models.ForeignKey('accounts.ProjectDetail', on_delete=models.CASCADE) | ||
text = models.CharField(max_length=300) | ||
date = models.DateField(auto_now_add=True) | ||
status = models.CharField(max_length=1, choices=(("1", "Seen"), ("0", "Unseen"))) | ||
|
||
def __str__(self): | ||
return elf.text | ||
|
||
|
||
class FollowNotification(models.Model): | ||
user = models.ForeignKey(User, on_delete=models.CASCADE) | ||
follow = models.ForeignKey('accounts.Follow', on_delete=models.CASCADE) | ||
text = models.CharField(max_length=300) | ||
date = models.DateField(auto_now_add=True) | ||
status = models.CharField(max_length=1, choices=(("1", "Seen"), ("0", "Unseen"))) | ||
|
||
def __str__(self): | ||
return self.text | ||
|
||
|
||
class IssueCommentNotification(models.Model): | ||
user = models.ForeignKey(User, on_delete=models.CASCADE) | ||
issueComment = models.ForeignKey('accounts.IssueComment', on_delete=models.CASCADE) | ||
text = models.CharField(max_length=300) | ||
date = models.DateField(auto_now_add=True) | ||
status = models.CharField(max_length=1, choices=(("1", "Seen"), ("0", "Unseen"))) | ||
|
||
def __str__(self): | ||
return self.text | ||
|
||
|
||
class SolutionCommentNotification(models.Model): | ||
user = models.ForeignKey(User, on_delete=models.CASCADE) | ||
solutionComment = models.ForeignKey('accounts.SolutionComment', on_delete=models.CASCADE) | ||
text = models.CharField(max_length=300) | ||
date = models.DateField(auto_now_add=True) | ||
status = models.CharField(max_length=1, choices=(("1", "Seen"), ("0", "Unseen"))) | ||
|
||
def __str__(self): | ||
return self.text |
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,50 @@ | ||
from django.contrib.auth.models import User | ||
from django.db.models.signals import post_save | ||
from django.dispatch import receiver | ||
from accounts.models import Issue,Solution,ProjectPeopleInterested,Follow,IssueComment,SolutionComment | ||
import notifications.models | ||
|
||
|
||
@receiver(post_save, sender=Issue) | ||
def createIssueNotification(sender, instance, **kwargs): | ||
notificationText = "{} created issue #{} on {}".format(instance.user,instance.id,instance.project.project_name) | ||
notifications.models.IssueNotification.objects.create(user=instance.project.initiated_by,issue=instance,text=notificationText) | ||
|
||
@receiver(post_save, sender=Solution) | ||
def createSolutionNotification(sender, instance, **kwargs): | ||
notificationText = "{} created solution #{} to issue #{} on {}".format(instance.user,instance.id, | ||
instance.issue.id,instance.issue.project.project_name) | ||
notifications.models.SolutionNotification.objects.create(user=instance.issue.project.initiated_by,solution=instance,text=notificationText) | ||
notifications.models.SolutionNotification.objects.create(user=instance.issue.user,solution=instance,text=notificationText) | ||
|
||
@receiver(post_save, sender=ProjectPeopleInterested) | ||
def createInterestedNotification(sender, instance, **kwargs): | ||
notificationText = "{} is interested in {}".format(instance.user,instance.project.project_name) | ||
notifications.models.InterestedNotification.objects.create(user=instance.project.initiated_by, | ||
project=instance.project,text=notificationText) | ||
|
||
@receiver(post_save, sender=Follow) | ||
def createFollowNotification(sender, instance, **kwargs): | ||
notificationText = "{} started following you".format(instance.follower) | ||
notifications.models.FollowNotification.objects.create(user=instance.following,follow=instance,text=notificationText) | ||
|
||
@receiver(post_save, sender=IssueComment) | ||
def createIssueCommentNotification(sender, instance, **kwargs): | ||
notificationText = "{} commented on issue #{} of project {}".format(instance.user, | ||
instance.issue.id,instance.issue.project.project_name) | ||
notifications.models.IssueCommentNotification.objects.create(user=instance.issue.project.initiated_by, | ||
issueComment=instance,text=notificationText) | ||
notifications.models.IssueCommentNotification.objects.create(user=instance.issue.user, | ||
issueComment=instance,text=notificationText) | ||
|
||
|
||
@receiver(post_save, sender=SolutionComment) | ||
def createSolutionCommentNotification(sender, instance, **kwargs): | ||
notificationText = "{} commented on solution #{} of project {}".format(instance.user, | ||
instance.solution.id,instance.solution.issue.project.project_name) | ||
notifications.models.SolutionCommentNotification.objects.create(user=instance.solution.issue.project.initiated_by, | ||
solutionComment=instance,text=notificationText) | ||
notifications.models.SolutionCommentNotification.objects.create(user=instance.solution.issue.user, | ||
solutionComment=instance,text=notificationText) | ||
notifications.models.SolutionCommentNotification.objects.create(user=instance.solution.user, | ||
solutionComment=instance,text=notificationText) |
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,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
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,6 @@ | ||
from django.urls import path | ||
from . import views | ||
|
||
urlpatterns = [ | ||
|
||
] |
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,28 @@ | ||
from django.shortcuts import render | ||
from notifications.models import * | ||
from accounts.models import UserProfile | ||
# Create your views here. | ||
|
||
def getNotifications(request): | ||
issueNotifications = IssueNotification.objects.filter(user=request.user).order_by("id") | ||
issueNotification_profile = {} | ||
for issueNotifc in issueNotifications: | ||
issueNotification_profile[issueNotifc] = UserProfile.objects.get(user=issueNotifc.issue.user) | ||
|
||
solutionNotification_profile = {} | ||
solutionNotifications = SolutionNotification.objects.filter(user=request.user).order_by("id") | ||
for solutionNotifc in solutionNotifications: | ||
solutionNotification_profile[solutionNotifc] = UserProfile.objects.get(user=solutionNotifc.solution.user) | ||
|
||
followNotification_profile = {} | ||
followNotifications = FollowNotification.objects.filter(user=request.user).order_by("id") | ||
for followNotifc in followNotifications: | ||
followNotification_profile[followNotifc] = UserProfile.objects.get(user=followNotifc.follow.follower) | ||
|
||
followNotifications = FollowNotification.objects.filter(follow__following=request.user).order_by("id") | ||
issueCommentNotifications = IssueCommentNotification.objects.filter(issueComment__user=request.user).order_by("id") | ||
solutionCommentNotification = SolutionCommentNotification.objects.filter(solutionComment__user=request.user).order_by("id") | ||
notifications = {"issuesNotifc":issueNotification_profile,"solutionsNotifc":solutionNotification_profile, | ||
"followNotifc":followNotification_profile,"issueCommentNotifc":issueCommentNotifications, | ||
"solutionCommentNotifc":solutionCommentNotification} | ||
return notifications |
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