Add forum and news post notifications. Fixes #9

This commit is contained in:
Trever Fischer
2012-03-10 20:34:47 -05:00
parent eb442b9c96
commit f289be9a94
6 changed files with 20 additions and 3 deletions

View File

@@ -0,0 +1,7 @@
from django.db.models.signals import post_syncdb
from notification import models as notification
def create_notice_types(app, created_models, verbosity, **kwargs):
notification.create_notice_type('forum_reply', 'Forum Reply', 'A forum post you wrote recieved a reply.')
post_syncdb.connect(create_notice_types, sender=notification)

View File

@@ -91,10 +91,10 @@ class Post(MPTTModel):
created = models.DateTimeField(editable=False, auto_now_add=True)
updated = models.DateTimeField(editable=False, auto_now=True)
def forum(self):
def topic(self):
if parent is None:
return Forum.objects.get(rootTopic=self.id)
return parent.forum()
return Topic.objects.get(rootTopic=self.id)
return parent.topic()
@models.permalink
def get_absolute_url(self):

View File

@@ -5,6 +5,7 @@ from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from django.template import RequestContext
from django.core.urlresolvers import reverse
from notification import models as notification
def index(request):
forums = models.Forum.objects.filter(parent=None)
@@ -37,6 +38,7 @@ def reply(request, topicID=None):
reply.body = form.cleaned_data['body']
reply.user = request.user
reply.save()
notification.send([reply.parent.user], "forum_reply", {"reply": reply})
return HttpResponseRedirect(reverse('forums.views.post', kwargs={"id":reply.id}))
return render_to_response('forums/reply.html', {"post":parentPost, "form":form}, context_instance = RequestContext(request))

View File

@@ -5,6 +5,7 @@ from django.template import RequestContext
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import login_required
from notification import models as notification
import forms
def index(request, page=0):
@@ -31,6 +32,7 @@ def comment(request, id=None, parent=None):
if parent:
parentPost = models.Comment.objects.get(id__exact=parent)
c.parent = parentPost
notification.send([parentPost.author], "news_comment_reply", {"comment": c})
elif id:
newsPost = models.Post.objects.get(id__exact=id)
c.post = newsPost

View File

@@ -0,0 +1,3 @@
{{reply.user}} replied to your post in {{reply.topic}}:
{{reply.body}}

View File

@@ -0,0 +1,3 @@
{{comment.author}} replied to your comment on {{comment.news_post}}:
{{comment.body}}