changeset 1021:68c3343f3318

Perform image_check on gcalendar description. Also add image hotlink/upload forms to gcalendar add event page.
author Brian Neal <bgneal@gmail.com>
date Tue, 08 Dec 2015 21:39:19 -0600
parents a052798c146c
children 82f1f6f905eb
files comments/views.py gcalendar/forms.py gcalendar/models.py gcalendar/views.py sg101/templates/gcalendar/event.html
diffstat 5 files changed, 33 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/comments/views.py	Tue Dec 08 17:32:31 2015 -0600
+++ b/comments/views.py	Tue Dec 08 21:39:19 2015 -0600
@@ -27,9 +27,13 @@
 <p><strong>Error</strong>: {}</p>
 <p>Sorry, preview is unavailable.</p>
 <p>There is an image in your post which failed our image check. We can only
-accept images from a small number of sources for security reasons. You may use
-the forms below this box to safely hot-link to images hosted elsewhere on the
-Internet or upload from your computer or device.</p>
+accept images from a small number of sources for security reasons.</p>
+<p>If there are forms below this post box, you may use them to safely hot-link
+to images hosted elsewhere on the Internet or upload from your computer or
+device.</p>
+<p>If there are no image forms on this page, you can upload a photo from your
+computer or device from your user profile. Copy the image code you receive
+into the post box here.</p>
 """
 
 
--- a/gcalendar/forms.py	Tue Dec 08 17:32:31 2015 -0600
+++ b/gcalendar/forms.py	Tue Dec 08 21:39:19 2015 -0600
@@ -5,6 +5,9 @@
 import pytz
 from django import forms
 
+from core.html import ImageCheckError
+from core.html import image_check
+from core.markup import site_markup
 from gcalendar.models import Event
 
 
@@ -68,8 +71,12 @@
     end_time = forms.TimeField(required=False, widget=forms.Select(choices=TIME_CHOICES))
     time_zone = forms.CharField(required=False, widget=forms.HiddenInput())
     where = forms.CharField(required=False, widget=forms.TextInput(attrs={'size': 60}))
-    description = forms.CharField(required=False,
-            widget=forms.Textarea(attrs={'class': 'markItUp smileyTarget'}))
+    description = forms.CharField(
+            required=False,
+            widget=forms.Textarea(attrs={
+                'class': 'markItUp smileyTarget',
+                'id': 'id_body',    # needed for image related js
+                }))
 
     DATE_FORMAT = '%m/%d/%Y'    # must match the jQuery UI datepicker config
     TIME_FORMAT = '%H:%M'
@@ -116,6 +123,17 @@
         if instance is not None:
             del self.fields['create_forum_thread']
 
+    def clean_description(self):
+        description = self.cleaned_data['description']
+        self.html = None
+        if description:
+            self.html = site_markup(description, relative_urls=False)
+            try:
+                image_check(self.html)
+            except ImageCheckError as ex:
+                raise forms.ValidationError(str(ex))
+        return description
+
     def clean(self):
         start_date = self.cleaned_data.get('start_date')
         start_time = self.cleaned_data.get('start_time')
--- a/gcalendar/models.py	Tue Dec 08 17:32:31 2015 -0600
+++ b/gcalendar/models.py	Tue Dec 08 21:39:19 2015 -0600
@@ -69,7 +69,9 @@
         ordering = ('-date_submitted', )
 
     def save(self, *args, **kwargs):
-        self.html = site_markup(self.description, relative_urls=False)
+        self.html = kwargs.pop('html', None)
+        if not self.html and self.description:
+            self.html = site_markup(self.description, relative_urls=False)
         super(Event, self).save(*args, **kwargs)
 
     def is_approved(self):
--- a/gcalendar/views.py	Tue Dec 08 17:32:31 2015 -0600
+++ b/gcalendar/views.py	Tue Dec 08 21:39:19 2015 -0600
@@ -39,7 +39,7 @@
             event = form.save(commit=False)
             event.user = request.user
             event.repeat = 'none'
-            event.save()
+            event.save(html=form.html)
             return HttpResponseRedirect(reverse('gcalendar-add_thanks'))
     else:
         form = EventEntryForm()
--- a/sg101/templates/gcalendar/event.html	Tue Dec 08 17:32:31 2015 -0600
+++ b/sg101/templates/gcalendar/event.html	Tue Dec 08 21:39:19 2015 -0600
@@ -10,6 +10,7 @@
 {% script_tags 'jquery-ui markitup' %}
 <script src="{% static "js/timezone.js" %}"></script>
 <script src="{% static "js/gcalendar.js" %}"></script>
+<script src="{% static "js/jquery.form.min.js" %}"></script>
 {% endblock %}
 {% block content %}
 <div class="breadcrumbs"><a href="{% url 'gcalendar-index' %}">Calendar</a> &raquo; {{ title }}</div>
@@ -47,5 +48,6 @@
 <tr><td>&nbsp;</td><td>{% comment_dialogs %}<input type="submit" name="submit_button" value="Submit" /></td></tr>
 </table>
 </form>
+{% include 'user_photos/image_forms.html' %}
 <p><a href="{% url 'gcalendar-index' %}">&laquo; Back to the Event Calendar</a></p>
 {% endblock %}