Skip to content

Commit

Permalink
Merge pull request #90 from rshrc/notifications
Browse files Browse the repository at this point in the history
Notifications for follow/issues/solutions
  • Loading branch information
tsarchghs authored Jul 7, 2018
2 parents 547f365 + 59463da commit 88dacac
Show file tree
Hide file tree
Showing 20 changed files with 681 additions and 195 deletions.
Binary file modified accounts/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified accounts/__pycache__/admin.cpython-36.pyc
Binary file not shown.
Binary file modified accounts/__pycache__/forms.cpython-36.pyc
Binary file not shown.
Binary file modified accounts/__pycache__/models.cpython-36.pyc
Binary file not shown.
Binary file modified accounts/__pycache__/urls.cpython-36.pyc
Binary file not shown.
Binary file modified accounts/__pycache__/views.cpython-36.pyc
Binary file not shown.
607 changes: 413 additions & 194 deletions accounts/templates/base.html

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
)
from accounts.models import *
from django.views.generic import UpdateView, DeleteView
from notifications.views import getNotifications
from itertools import chain


@login_required
Expand Down Expand Up @@ -82,8 +84,11 @@ def projectEdit(request, ID):


def HomeView(request):
notifications = []
if request.user.is_authenticated:
notifications = getNotifications(request)
name = "NSP - Network Of Skilled People"
args = {'name': name}
args = {'name': name,"notifications":notifications}
return render(request, 'accounts/index.html', args)


Expand Down
Empty file added notifications/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions notifications/admin.py
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)
5 changes: 5 additions & 0 deletions notifications/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class NotificationsConfig(AppConfig):
name = 'notifications'
84 changes: 84 additions & 0 deletions notifications/migrations/0001_initial.py
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.
74 changes: 74 additions & 0 deletions notifications/models.py
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
50 changes: 50 additions & 0 deletions notifications/signals.py
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)
3 changes: 3 additions & 0 deletions notifications/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
6 changes: 6 additions & 0 deletions notifications/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.urls import path
from . import views

urlpatterns = [

]
28 changes: 28 additions & 0 deletions notifications/views.py
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
1 change: 1 addition & 0 deletions nsp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

INSTALLED_APPS = [
'bootstrapform',
'notifications',
'accounts',
'django.contrib.admin',
'django.contrib.auth',
Expand Down
1 change: 1 addition & 0 deletions nsp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def redirectToAccount(request):
urlpatterns = [
path('admin/', admin.site.urls),
path('account/', include('accounts.urls')),
path('notifications/',include('notifications.urls')),
path('', redirectToAccount, name="redirectToAccount")
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Expand Down

0 comments on commit 88dacac

Please sign in to comment.