Add forum and news post notifications. Fixes #9
This commit is contained in:
7
forums/management/__init__.py
Normal file
7
forums/management/__init__.py
Normal 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)
|
@@ -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):
|
||||
|
@@ -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))
|
||||
|
||||
|
@@ -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
|
||||
|
3
templates/notification/forum_reply/full.txt
Normal file
3
templates/notification/forum_reply/full.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
{{reply.user}} replied to your post in {{reply.topic}}:
|
||||
|
||||
{{reply.body}}
|
3
templates/notification/news_comment_reply/full.txt
Normal file
3
templates/notification/news_comment_reply/full.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
{{comment.author}} replied to your comment on {{comment.news_post}}:
|
||||
|
||||
{{comment.body}}
|
Reference in New Issue
Block a user