diff --git a/bt/models.py b/bt/models.py index b30b2741603ab014519f38b8b54bf9b4d2855348..fb410bcd333cb160ced05ed41139c8075f15ccc0 100644 --- a/bt/models.py +++ b/bt/models.py @@ -61,6 +61,7 @@ class Violation(models.Model): contractual = models.BooleanField() contract_excerpt = models.TextField() loophole = models.BooleanField() + activationid= models.CharField(max_length=128) class Comment(models.Model): submitter_email = models.EmailField() diff --git a/bt/views.py b/bt/views.py index 1746a97f523de4ee06f133b9026ac5651079ce35..3fa5c2fcfd68959ab1b07f7f697697f359f00e17 100644 --- a/bt/views.py +++ b/bt/views.py @@ -6,10 +6,13 @@ from django.core.files import File 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 models import Violation, Attachment, Comment from tempfile import mkstemp from datetime import datetime -import hashlib, os, re, json, hashlib +import hashlib, os, re, json, smtplib +from random import randint +from email.mime.text import MIMEText from urlparse import urljoin from BeautifulSoup import BeautifulSoup, Comment as BComment @@ -38,10 +41,25 @@ def sanitizeHtml(value, base_url=None): return soup.renderContents().decode('utf8') +def activate(request): + v=Violation.objects.get(activationid=request.GET.get('key','asdf')) + v.activationid='' + v.save() + messages.add_message(request, messages.INFO, 'Thank you for verifying your submission.') + return HttpResponseRedirect('/') # Redirect after POST + def add(request): if request.method == 'POST': form = AddViolation(request.POST) if form.is_valid(): + actid = hashlib.sha1(''.join([chr(randint(32, 122)) for x in range(12)])).hexdigest() + msg = MIMEText("Your verification key is %s/activate?key=%s\n" % (settings.ROOT_URL or 'http://localhost:8001/',actid)) + msg['Subject'] = 'NNMon submission verification' + msg['From'] = 'nnmon@nnmon.lqdn.fr' + msg['To'] = form.cleaned_data['email'] + s = smtplib.SMTP('localhost') + s.sendmail('nnmon@nnmon.lqdn.fr', [form.cleaned_data['email']], msg.as_string()) + s.quit() v=Violation( country = form.cleaned_data['country'], operator = form.cleaned_data['operator'], @@ -53,7 +71,8 @@ def add(request): temporary = form.cleaned_data['temporary'], contractual = form.cleaned_data['contractual'], contract_excerpt = sanitizeHtml(form.cleaned_data['contract_excerpt']), - loophole = form.cleaned_data['loophole'] + loophole = form.cleaned_data['loophole'], + activationid = actid ) v.save() c = Comment( @@ -72,6 +91,8 @@ def add(request): sname=m.hexdigest() a.storage.save(sname,f) a.save() + + messages.add_message(request, messages.INFO, 'Thank you for submitting this report, you will receive a verification email shortly.') return HttpResponseRedirect('/') # Redirect after POST else: form = AddViolation() @@ -83,12 +104,12 @@ def add(request): def ajax(request, country=None, operator=None): if not operator: - return HttpResponse(json.dumps(sorted(list(set([x.operator for x in Violation.objects.filter(country=country)]))))) + return HttpResponse(json.dumps(sorted(list(set([x.operator for x in Violation.objects.filter(country=country,activationid='')]))))) else: - return HttpResponse(json.dumps(sorted(list(set([x.contract for x in Violation.objects.filter(country=country).filter(operator=operator)]))))) + return HttpResponse(json.dumps(sorted(list(set([x.contract for x in Violation.objects.filter(country=country,activationid='',operator=operator)]))))) def index(request): - v_list = Violation.objects.all() + v_list = Violation.objects.filter(activationid='') paginator = Paginator(v_list, 25) page = request.GET.get('page','1') @@ -99,7 +120,7 @@ def index(request): except EmptyPage: violations = paginator.page(paginator.num_pages) - return render_to_response('list.html', {"violations": violations}) + return render_to_response('list.html', {"violations": violations},context_instance=RequestContext(request)) def view(request,id): v = get_object_or_404(Violation, pk=id) diff --git a/media/css/style.css b/media/css/style.css index f5eb514c5cbc036a84444d7da5974a091ab74895..80518b6b8dfd50e84de23d832197325cf6368c23 100644 --- a/media/css/style.css +++ b/media/css/style.css @@ -23,3 +23,43 @@ li { list-style: none; } table.listing, .pagination { width: 90%; margin: auto; } table.listing thead td { font-weight: bold; border-bottom: 1px solid black; } + +/* tables */ +table.tablesorter { + font-family:arial; + background-color: #CDCDCD; + margin:10px 0pt 15px; + font-size: 8pt; + width: 100%; + text-align: left; +} +table.tablesorter thead tr th, table.tablesorter tfoot tr th { + background-color: #e6EEEE; + border: 1px solid #FFF; + font-size: 8pt; + padding: 4px; +} +table.tablesorter thead tr .header { + background-image: url(/site_media/img/bg.gif); + background-repeat: no-repeat; + background-position: center right; + cursor: pointer; +} +table.tablesorter tbody td { + color: #3D3D3D; + padding: 4px; + background-color: #FFF; + vertical-align: top; +} +table.tablesorter tbody tr.odd td { + background-color:#F0F0F6; +} +table.tablesorter thead tr .headerSortUp { + background-image: url(/site_media/img/asc.gif); +} +table.tablesorter thead tr .headerSortDown { + background-image: url(/site_media/img/desc.gif); +} +table.tablesorter thead tr .headerSortDown, table.tablesorter thead tr .headerSortUp { +background-color: #8dbdd8; +} diff --git a/settings.py b/settings.py index e2c18763391d3bf4687a676c5832ef8c8734e5ba..f6ac3195be342ccf75d0f5925a09799e775173e7 100644 --- a/settings.py +++ b/settings.py @@ -173,6 +173,8 @@ LOGIN_REDIRECT_URL = '/' CAPTCHA_NOISE_FUNCTIONS = ('captcha.helpers.noise_dots',) CAPTCHA_CHALLENGE_FUNCT = 'captcha.helpers.math_challenge' +MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage' + try: from local_settings import * except: diff --git a/templates/list.html b/templates/list.html index 93ff13ea753ea37c8690572f31247b1fa9e55933..477d60f89b5b438c877e10cae8863fde13e8a2f9 100644 --- a/templates/list.html +++ b/templates/list.html @@ -5,27 +5,36 @@ {% endblock %} {% block scripts %} - + + {% endblock %} {%block content%} -
id | -country | -operator | -contract | -resource | -type | -media | -temporary | -contractual | -contractual_excerpt | -loophole | +id | +country | +operator | +contract | +resource | +type | +media | +temporary | +contractual | +contractual_excerpt | +loophole |
---|