diff messages/forms.py @ 1022:82f1f6f905eb

Perform image_check on private messages.
author Brian Neal <bgneal@gmail.com>
date Wed, 09 Dec 2015 21:16:04 -0600
parents 21c592cac71c
children 6abcecd3d277
line wrap: on
line diff
--- a/messages/forms.py	Tue Dec 08 21:39:19 2015 -0600
+++ b/messages/forms.py	Wed Dec 09 21:16:04 2015 -0600
@@ -10,6 +10,9 @@
 from django.template.loader import render_to_string
 
 from core.functions import send_mail
+from core.html import ImageCheckError
+from core.html import image_check
+from core.markup import site_markup
 from core.widgets import AutoCompleteUserInput
 import messages
 from messages.models import Flag, Message, Options
@@ -48,9 +51,20 @@
         return receiver
 
     def clean_message(self):
-        msg = self.cleaned_data['message']
+        msg = self.cleaned_data['message'].strip()
         if len(msg) > MESSAGE_MAX:
             raise forms.ValidationError("Your message is too long. Please trim some text.")
+
+        self.html = None
+        if not msg:
+            raise forms.ValidationError("Please enter a message.")
+
+        self.html = site_markup(msg)
+        try:
+            image_check(self.html)
+        except ImageCheckError as ex:
+            raise forms.ValidationError(str(ex))
+
         return msg
 
     def clean(self):
@@ -89,7 +103,7 @@
             message=message,
             signature_attached=attach_signature,
         )
-        new_msg.save()
+        new_msg.save(html=self.html)
 
         # Update the parent message (if there is one)
         parent_id = self.cleaned_data['parent_id']