changeset 1024:6164cc091649

Perform image_check on membermap messages.
author Brian Neal <bgneal@gmail.com>
date Thu, 10 Dec 2015 21:11:10 -0600
parents a5ebc74dc3f3
children 23e477c509dd
files membermap/forms.py membermap/models.py membermap/static/js/membermap.js membermap/views.py
diffstat 4 files changed, 33 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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')
--- 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)
 
--- 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');
                               }
                            });
                      });
--- 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)