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 ...@@ -7,6 +7,7 @@ from django.conf import settings
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from models import Violation, Attachment, Comment, Confirmation from models import Violation, Attachment, Comment, Confirmation
from tempfile import mkstemp from tempfile import mkstemp
...@@ -44,11 +45,39 @@ def sanitizeHtml(value, base_url=None): ...@@ -44,11 +45,39 @@ def sanitizeHtml(value, base_url=None):
def activate(request): def activate(request):
v=Violation.objects.get(activationid=request.GET.get('key','asdf')) v=Violation.objects.get(activationid=request.GET.get('key','asdf'))
v.activationid='' if v:
actid = hashlib.sha1(''.join([chr(randint(32, 122)) for x in range(12)])).hexdigest()
to=[x.email 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'] = 'nnmon@nnmon.lqdn.fr'
msg['To'] = ', '.join(to)
s = smtplib.SMTP('localhost')
s.sendmail('nnmon@nnmon.lqdn.fr', to, msg.as_string())
s.quit()
v.activationid=actid
v.save() v.save()
messages.add_message(request, messages.INFO, _('Thank you for verifying your submission.')) messages.add_message(request, messages.INFO, _('Thank you for verifying your submission.'))
return HttpResponseRedirect('/') # Redirect after POST return HttpResponseRedirect('/') # Redirect after POST
def moderate(request):
v=Violation.objects.get(activationid=request.GET.get('key','asdf'))
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.country, v.contract))
v.activationid=''
v.save()
messages.add_message(request, messages.INFO, _('Thank you for approving the submission.'))
return HttpResponseRedirect('/') # Redirect after POST
if request.GET.get('action','')=='delete':
v.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): def confirm(request, id, name=None):
if name: if name:
if Confirmation.objects.filter(email=name, violation=id).count()==0: if Confirmation.objects.filter(email=name, violation=id).count()==0:
......
...@@ -70,6 +70,7 @@ $(document).ready(function() { ...@@ -70,6 +70,7 @@ $(document).ready(function() {
</li> </li>
</ul> </ul>
{%endif%} {%endif%}
{% if not key %}
<h3>{% trans "Comments" %}</h3> <h3>{% trans "Comments" %}</h3>
{% render_comment_list for v %} {% render_comment_list for v %}
<h3>{% trans "Comment" %}</h3> <h3>{% trans "Comment" %}</h3>
...@@ -77,4 +78,8 @@ $(document).ready(function() { ...@@ -77,4 +78,8 @@ $(document).ready(function() {
<div id="comment_form"> <div id="comment_form">
{% render_comment_form for v %} {% render_comment_form for v %}
</div> </div>
{% else %}
<a href='/moderate/?key={{key}}&action=approve'>Approve Submission</a>
<a href='/moderate/?key={{key}}&action=delete'>Delete Submission</a>
{% endif %}
{%endblock%} {%endblock%}
...@@ -18,6 +18,7 @@ urlpatterns = patterns('', ...@@ -18,6 +18,7 @@ urlpatterns = patterns('',
(r'^activate/$', bt.activate), (r'^activate/$', bt.activate),
(r'^confirm/(?P<id>[0-9a-z]*)$', bt.confirm), (r'^confirm/(?P<id>[0-9a-z]*)$', bt.confirm),
(r'^confirm/(?P<id>[0-9]*)/(?P<name>.*)$', 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/logout$', 'django.contrib.auth.views.logout', {'next_page' : '/'}),
(r'^accounts/', include('registration.urls')), (r'^accounts/', include('registration.urls')),
(r'^comments/', include('django.contrib.comments.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