Commit d8ea55db authored by stef's avatar stef
Browse files

[enh] added approval/delete of submissions + tweeting on approval

parent c10c9f66
......@@ -7,6 +7,7 @@ from django.conf import settings
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.core.exceptions import ObjectDoesNotExist
from django.contrib import messages
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
from models import Violation, Attachment, Comment, Confirmation
from tempfile import mkstemp
......@@ -44,11 +45,39 @@ def sanitizeHtml(value, base_url=None):
def activate(request):
if v:
actid = hashlib.sha1(''.join([chr(randint(32, 122)) for x in range(12)])).hexdigest()
to=[ for x in User.objects.filter(groups__name='moderator')]
msg = MIMEText(_("A new report was submitted. To approve click here: %s/moderate/?key=%s\n") % (settings.ROOT_URL or 'http://localhost:8001/', actid))
msg['Subject'] = _('NNMon submission approval')
msg['From'] = ''
msg['To'] = ', '.join(to)
s = smtplib.SMTP('localhost')
s.sendmail('', to, msg.as_string())
messages.add_message(request, messages.INFO, _('Thank you for verifying your submission.'))
return HttpResponseRedirect('/') # Redirect after POST
def moderate(request):
if not v:
messages.add_message(request, messages.INFO, _('No such key'))
return HttpResponseRedirect('/') # Redirect after POST
if request.GET.get('action','')=='approve':
if settings.TWITTER_API:
settings.TWITTER_API.PostUpdate("New infringement reported for %s (%s) %s" % (v.operator,, v.contract))
messages.add_message(request, messages.INFO, _('Thank you for approving the submission.'))
return HttpResponseRedirect('/') # Redirect after POST
if request.GET.get('action','')=='delete':
messages.add_message(request, messages.INFO, _('Thank you for deleting the submission.'))
return HttpResponseRedirect('/') # Redirect after POST
return render_to_response('view.html', { 'v': v, 'key': request.GET.get('key') },context_instance=RequestContext(request))
def confirm(request, id, name=None):
if name:
if Confirmation.objects.filter(email=name, violation=id).count()==0:
......@@ -70,6 +70,7 @@ $(document).ready(function() {
{% if not key %}
<h3>{% trans "Comments" %}</h3>
{% render_comment_list for v %}
<h3>{% trans "Comment" %}</h3>
......@@ -77,4 +78,8 @@ $(document).ready(function() {
<div id="comment_form">
{% render_comment_form for v %}
{% else %}
<a href='/moderate/?key={{key}}&action=approve'>Approve Submission</a>
<a href='/moderate/?key={{key}}&action=delete'>Delete Submission</a>
{% endif %}
......@@ -18,6 +18,7 @@ urlpatterns = patterns('',
(r'^activate/$', bt.activate),
(r'^confirm/(?P<id>[0-9a-z]*)$', bt.confirm),
(r'^confirm/(?P<id>[0-9]*)/(?P<name>.*)$', bt.confirm),
(r'^moderate/$', bt.moderate),
(r'^accounts/logout$', 'django.contrib.auth.views.logout', {'next_page' : '/'}),
(r'^accounts/', include('registration.urls')),
(r'^comments/', include('django.contrib.comments.urls')),
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment