Add support for closing petitions, and emit notifications when relevant
This commit is contained in:
10
petition/management/__init__.py
Normal file
10
petition/management/__init__.py
Normal file
@@ -0,0 +1,10 @@
|
||||
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('petition_closed', 'Petition Closed', 'A petition was closed.')
|
||||
notification.create_notice_type('petition_commented', 'Petition Commented', 'A petition was commented upon.')
|
||||
notification.create_notice_type('petition_opened', 'Petition Opened', 'A petition was opened.')
|
||||
|
||||
post_syncdb.connect(create_notice_types, sender=notification)
|
||||
|
@@ -3,6 +3,7 @@ from django.conf.urls.defaults import patterns, include, url
|
||||
urlpatterns = patterns('petition',
|
||||
url('^$', 'views.index'),
|
||||
url('^create$', 'views.create'),
|
||||
url('^(?P<id>[0-9]+)/close', 'views.close'),
|
||||
url('^(?P<id>[0-9]+)', 'views.view'),
|
||||
url('^comment/(?P<id>[0-9]+)', 'views.comment'),
|
||||
)
|
||||
|
@@ -5,6 +5,9 @@ from django.template import RequestContext
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.contrib.auth.models import User
|
||||
from notification import models as notification
|
||||
from django.contrib import messages
|
||||
|
||||
@login_required
|
||||
def create(request):
|
||||
@@ -17,6 +20,9 @@ def create(request):
|
||||
petition.author = request.user
|
||||
petition.body = form.cleaned_data['body']
|
||||
petition.save()
|
||||
adminUsers = User.objects.filter(is_staff=True)
|
||||
notification.send(adminUsers, "petition_opened", {"petition": petition, 'notice_url': reverse('petition.views.view', kwargs={'id':petition.id}),'notice_description': petition.id})
|
||||
messages.info(request, "Petition created.")
|
||||
return HttpResponseRedirect(reverse('petition.views.view', kwargs={"id":petition.id}))
|
||||
return render_to_response('petition/create.html', {'form':form}, context_instance = RequestContext(request))
|
||||
|
||||
@@ -48,4 +54,17 @@ def comment(request, id):
|
||||
comment.body = form.cleaned_data['body']
|
||||
comment.petition = petition
|
||||
comment.save()
|
||||
if comment.author != petition.author:
|
||||
notification.send([petition.author], "petition_commented", {"petition": petition, 'notice_url': reverse('petition.views.view', kwargs={'id':petition.id}),'notice_description': petition.id, 'comment': comment})
|
||||
messages.info(request, "Comment added.")
|
||||
return HttpResponseRedirect(reverse('petition.views.view', kwargs={"id":petition.id})+"#c"+str(comment.id))
|
||||
|
||||
@login_required
|
||||
def close(request, id):
|
||||
petition = models.Petition.objects.get(id__exact=id)
|
||||
petition.closed = True
|
||||
petition.save()
|
||||
if petition.author != request.user:
|
||||
notification.send([petition.author], "petition_closed", {"petition": petition, 'notice_url': reverse('petition.views.view', kwargs={'id':petition.id}),'notice_description': petition.id})
|
||||
messages.info(request, "Petition closed.")
|
||||
return HttpResponseRedirect(reverse('petition.views.view', kwargs={"id":petition.id}))
|
||||
|
@@ -1,3 +1,5 @@
|
||||
{{reply.user}} replied to your post in {{reply.topic}}:
|
||||
|
||||
{{reply.body}}
|
||||
|
||||
{{reply.get_absolute_url}}
|
||||
|
6
templates/notification/petition_closed/full.txt
Normal file
6
templates/notification/petition_closed/full.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
Petition {{petition.id}} has been closed by {{closingUser}}:
|
||||
|
||||
{{petition.body}}
|
||||
|
||||
{{petition.get_absolute_url}}
|
||||
|
5
templates/notification/petition_commented/full.txt
Normal file
5
templates/notification/petition_commented/full.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
{{comment.author}} commented on petition {{petition.id}}:
|
||||
|
||||
{{comment.body}}
|
||||
|
||||
{{petition.get_absolute_url}}
|
5
templates/notification/petition_opened/full.txt
Normal file
5
templates/notification/petition_opened/full.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
{{petition.author}} opened petition {{petition.id}}:
|
||||
|
||||
{{petition.body}}
|
||||
|
||||
{{petition.get_absolute_url}}
|
Reference in New Issue
Block a user