# HG changeset patch # User Brian Neal # Date 1449803470 21600 # Node ID 6164cc0916493726614a1a08c4f152abfde4ba34 # Parent a5ebc74dc3f341d21140f329a8c1e6bcc086e32d Perform image_check on membermap messages. diff -r a5ebc74dc3f3 -r 6164cc091649 membermap/forms.py --- a/membermap/forms.py Thu Dec 10 20:57:50 2015 -0600 +++ b/membermap/forms.py Thu Dec 10 21:11:10 2015 -0600 @@ -3,6 +3,9 @@ """ from django import forms +from core.html import ImageCheckError +from core.html import image_check +from core.markup import site_markup from membermap.models import MapEntry @@ -12,6 +15,19 @@ message = forms.CharField(required=False, widget=forms.Textarea(attrs={'class': 'markItUp smileyTarget'})) + def clean_message(self): + message = self.cleaned_data['message'] + self.html = None + + if message: + self.html = site_markup(message) + try: + image_check(self.html) + except ImageCheckError as ex: + raise forms.ValidationError(str(ex)) + + return message + class Meta: model = MapEntry fields = ('location', 'message') diff -r a5ebc74dc3f3 -r 6164cc091649 membermap/models.py --- a/membermap/models.py Thu Dec 10 20:57:50 2015 -0600 +++ b/membermap/models.py Thu Dec 10 21:11:10 2015 -0600 @@ -26,7 +26,9 @@ verbose_name_plural = 'map entries' def save(self, *args, **kwargs): - self.html = site_markup(self.message) + self.html = kwargs.pop('html', None) + if not self.html and self.message: + self.html = site_markup(self.message) self.date_updated = datetime.datetime.now() super(MapEntry, self).save(*args, **kwargs) diff -r a5ebc74dc3f3 -r 6164cc091649 membermap/static/js/membermap.js --- a/membermap/static/js/membermap.js Thu Dec 10 20:57:50 2015 -0600 +++ b/membermap/static/js/membermap.js Thu Dec 10 21:11:10 2015 -0600 @@ -118,6 +118,7 @@ error: function (xhr, textStatus, ex) { alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + xhr.responseText); + submitButton.removeAttr('disabled').val('Update'); } }); }); diff -r a5ebc74dc3f3 -r 6164cc091649 membermap/views.py --- 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)