comparison forums/views/main.py @ 955:71a671dab55d

First commit of whitelisting image hosts. This is behind a feature flag courtesy of waffle.
author Brian Neal <bgneal@gmail.com>
date Wed, 03 Jun 2015 21:13:08 -0500
parents 0ca691cccf8d
children
comparison
equal deleted inserted replaced
954:e56455f4626b 955:71a671dab55d
18 from django.shortcuts import render_to_response 18 from django.shortcuts import render_to_response
19 from django.template.loader import render_to_string 19 from django.template.loader import render_to_string
20 from django.template import RequestContext 20 from django.template import RequestContext
21 from django.views.decorators.http import require_POST 21 from django.views.decorators.http import require_POST
22 from django.db.models import F 22 from django.db.models import F
23 import waffle
23 24
24 import antispam 25 import antispam
25 import antispam.utils 26 import antispam.utils
26 from bio.models import BadgeOwnership 27 from bio.models import BadgeOwnership
27 from core.paginator import DiggPaginator 28 from core.paginator import DiggPaginator
28 from core.functions import email_admins, quote_message 29 from core.functions import email_admins, quote_message
29 30
30 from forums.models import (Forum, Topic, Post, FlaggedPost, TopicLastVisit, 31 from forums.models import (Forum, Topic, Post, FlaggedPost, TopicLastVisit,
31 ForumLastVisit) 32 ForumLastVisit)
32 from forums.forms import (NewTopicForm, NewPostForm, PostForm, MoveTopicForm, 33 from forums.forms import (NewTopicForm, NewPostForm, PostForm, MoveTopicForm,
33 SplitTopicForm) 34 SplitTopicForm, NewTopicFormS3)
34 from forums.unread import (get_forum_unread_status, get_topic_unread_status, 35 from forums.unread import (get_forum_unread_status, get_topic_unread_status,
35 get_post_unread_status, get_unread_topics) 36 get_post_unread_status, get_unread_topics)
36 37
37 import forums.permissions as perms 38 import forums.permissions as perms
38 from forums.signals import (notify_new_topic, notify_updated_topic, 39 from forums.signals import (notify_new_topic, notify_updated_topic,
293 forum = get_object_or_404(Forum.objects.select_related(), slug=slug) 294 forum = get_object_or_404(Forum.objects.select_related(), slug=slug)
294 295
295 if not perms.can_access(forum.category, request.user): 296 if not perms.can_access(forum.category, request.user):
296 return HttpResponseForbidden() 297 return HttpResponseForbidden()
297 298
299 form_class = (NewTopicFormS3 if waffle.flag_is_active(request, 's3_images')
300 else NewTopicForm)
301
298 if request.method == 'POST': 302 if request.method == 'POST':
299 form = NewTopicForm(request.user, forum, request.POST) 303 form = form_class(request.user, forum, request.POST)
300 if form.is_valid(): 304 if form.is_valid():
301 if antispam.utils.spam_check(request, form.cleaned_data['body']): 305 if antispam.utils.spam_check(request, form.cleaned_data['body']):
302 return HttpResponseRedirect(reverse('antispam-suspended')) 306 return HttpResponseRedirect(reverse('antispam-suspended'))
303 307
304 topic = form.save(request.META.get("REMOTE_ADDR")) 308 topic = form.save(request.META.get("REMOTE_ADDR"))
305 _bump_post_count(request.user) 309 _bump_post_count(request.user)
306 return HttpResponseRedirect(reverse('forums-new_topic_thanks', 310 return HttpResponseRedirect(reverse('forums-new_topic_thanks',
307 kwargs={'tid': topic.pk})) 311 kwargs={'tid': topic.pk}))
308 else: 312 else:
309 form = NewTopicForm(request.user, forum) 313 form = form_class(request.user, forum)
310 314
311 return render_to_response('forums/new_topic.html', { 315 return render_to_response('forums/new_topic.html', {
312 'forum': forum, 316 'forum': forum,
313 'form': form, 317 'form': form,
314 }, 318 },