# HG changeset patch # User Brian Neal # Date 1449632359 21600 # Node ID 68c3343f3318bf4d96592f05a7e04fe6163572b9 # Parent a052798c146c0dc7ef6c90c802aecbaf6fce4e79 Perform image_check on gcalendar description. Also add image hotlink/upload forms to gcalendar add event page. diff -r a052798c146c -r 68c3343f3318 comments/views.py --- 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 @@

Error: {}

Sorry, preview is unavailable.

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.

+accept images from a small number of sources for security reasons.

+

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.

+

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.

""" diff -r a052798c146c -r 68c3343f3318 gcalendar/forms.py --- 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') diff -r a052798c146c -r 68c3343f3318 gcalendar/models.py --- 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): diff -r a052798c146c -r 68c3343f3318 gcalendar/views.py --- 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() diff -r a052798c146c -r 68c3343f3318 sg101/templates/gcalendar/event.html --- 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' %} + {% endblock %} {% block content %} @@ -47,5 +48,6 @@  {% comment_dialogs %} +{% include 'user_photos/image_forms.html' %}

« Back to the Event Calendar

{% endblock %}