Mercurial > public > sg101
diff membermap/views.py @ 1024:6164cc091649
Perform image_check on membermap messages.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 10 Dec 2015 21:11:10 -0600 |
parents | 21c592cac71c |
children | e1c03da72818 |
line wrap: on
line diff
--- a/membermap/views.py Thu Dec 10 20:57:50 2015 -0600 +++ b/membermap/views.py Thu Dec 10 21:11:10 2015 -0600 @@ -13,6 +13,9 @@ from django.views.decorators.http import require_POST from django.core.cache import cache +from core.html import ImageCheckError +from core.html import image_check +from core.markup import site_markup from membermap.models import MapEntry from membermap.forms import MapEntryForm @@ -104,7 +107,7 @@ loc = request.POST.get('loc', None) lat = request.POST.get('lat', None) lon = request.POST.get('lon', None) - msg = request.POST.get('msg', '') + msg = request.POST.get('msg', '').strip() if loc is None or lat is None or lon is None: return HttpResponseBadRequest('Missing parameters') @@ -115,6 +118,14 @@ except ValueError: return HttpResponseBadRequest('Invalid lat/lon') + html = '' + if msg: + html = site_markup(msg) + try: + image_check(html) + except ImageCheckError as ex: + return HttpResponseBadRequest(str(ex)) + try: entry = MapEntry.objects.get(user=request.user) except MapEntry.DoesNotExist: @@ -124,7 +135,7 @@ entry.lat = lat entry.lon = lon entry.message = msg - entry.save() + entry.save(html=html) cache.delete(CACHE_KEY)