Mercurial > public > sg101
comparison 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 |
comparison
equal
deleted
inserted
replaced
1021:68c3343f3318 | 1022:82f1f6f905eb |
---|---|
8 from django.contrib.sites.models import Site | 8 from django.contrib.sites.models import Site |
9 from django.core.urlresolvers import reverse | 9 from django.core.urlresolvers import reverse |
10 from django.template.loader import render_to_string | 10 from django.template.loader import render_to_string |
11 | 11 |
12 from core.functions import send_mail | 12 from core.functions import send_mail |
13 from core.html import ImageCheckError | |
14 from core.html import image_check | |
15 from core.markup import site_markup | |
13 from core.widgets import AutoCompleteUserInput | 16 from core.widgets import AutoCompleteUserInput |
14 import messages | 17 import messages |
15 from messages.models import Flag, Message, Options | 18 from messages.models import Flag, Message, Options |
16 | 19 |
17 | 20 |
46 if self.user == self.rcvr_user: | 49 if self.user == self.rcvr_user: |
47 raise forms.ValidationError("You can't send a message to yourself.") | 50 raise forms.ValidationError("You can't send a message to yourself.") |
48 return receiver | 51 return receiver |
49 | 52 |
50 def clean_message(self): | 53 def clean_message(self): |
51 msg = self.cleaned_data['message'] | 54 msg = self.cleaned_data['message'].strip() |
52 if len(msg) > MESSAGE_MAX: | 55 if len(msg) > MESSAGE_MAX: |
53 raise forms.ValidationError("Your message is too long. Please trim some text.") | 56 raise forms.ValidationError("Your message is too long. Please trim some text.") |
57 | |
58 self.html = None | |
59 if not msg: | |
60 raise forms.ValidationError("Please enter a message.") | |
61 | |
62 self.html = site_markup(msg) | |
63 try: | |
64 image_check(self.html) | |
65 except ImageCheckError as ex: | |
66 raise forms.ValidationError(str(ex)) | |
67 | |
54 return msg | 68 return msg |
55 | 69 |
56 def clean(self): | 70 def clean(self): |
57 rcvr = self.cleaned_data.get('receiver') | 71 rcvr = self.cleaned_data.get('receiver') |
58 subject = self.cleaned_data.get('subject') | 72 subject = self.cleaned_data.get('subject') |
87 receiver=receiver, | 101 receiver=receiver, |
88 subject=subject, | 102 subject=subject, |
89 message=message, | 103 message=message, |
90 signature_attached=attach_signature, | 104 signature_attached=attach_signature, |
91 ) | 105 ) |
92 new_msg.save() | 106 new_msg.save(html=self.html) |
93 | 107 |
94 # Update the parent message (if there is one) | 108 # Update the parent message (if there is one) |
95 parent_id = self.cleaned_data['parent_id'] | 109 parent_id = self.cleaned_data['parent_id'] |
96 if parent_id: | 110 if parent_id: |
97 try: | 111 try: |