fixes tracker issue #342

This commit is contained in:
Nathan Dinsmore 2013-01-15 16:00:14 -05:00
parent 372b2e95e6
commit 83094b2b7e
3 changed files with 16 additions and 1 deletions

View file

@ -12,7 +12,7 @@ from django.utils.translation import ugettext_lazy as _
from djangobb_forum.models import Topic, Post, Profile, Reputation, Report, \
Attachment, Poll, PollChoice
from djangobb_forum import settings as forum_settings
from djangobb_forum.util import smiles, convert_text_to_html, set_language, UnapprovedImageError
from djangobb_forum.util import smiles, convert_text_to_html, filter_language, set_language, UnapprovedImageError
SORT_USER_BY_CHOICES = (
@ -85,6 +85,7 @@ class AddPostForm(forms.ModelForm):
if not subject.strip():
self._errors['name'] = self.error_class([errmsg])
del cleaned_data['name']
cleaned_data['name'] = filter_language(subject)
if body:
if not body.strip():
self._errors['body'] = self.error_class([errmsg])
@ -94,6 +95,7 @@ class AddPostForm(forms.ModelForm):
except UnapprovedImageError as e:
self._errors['body'] = self.error_class([e.user_error()])
del cleaned_data['body']
cleaned_data['body'] = filter_language(body)
try:
recent_post = Post.objects.filter(user=self.user).latest()
@ -170,6 +172,9 @@ class EditPostForm(forms.ModelForm):
def clean(self):
cleaned_data = self.cleaned_data
subject = cleaned_data.get('name')
if subject:
cleaned_data['name'] = filter_language(subject)
body = cleaned_data.get('body')
if body:
try:
@ -177,6 +182,7 @@ class EditPostForm(forms.ModelForm):
except UnapprovedImageError as e:
self._errors['body'] = self.error_class([e.user_error()])
del cleaned_data['body']
cleaned_data['body'] = filter_language(body)
return cleaned_data
def save(self, commit=True):

View file

@ -9,6 +9,7 @@ FORUM_BASE_TITLE = get('DJANGOBB_FORUM_BASE_TITLE', 'Django Bulletin Board')
FORUM_META_DESCRIPTION = get('DJANGOBB_FORUM_META_DESCRIPTION', '')
FORUM_META_KEYWORDS = get('DJANGOBB_FORUM_META_KEYWORDS', '')
IMAGE_HOST_WHITELIST = get('DJANGOBB_IMAGE_HOST_WHITELIST', '')
LANGUAGE_FILTER = get('DJANGOBB_LANGUAGE_FILTER', '')
TOPIC_PAGE_SIZE = get('DJANGOBB_TOPIC_PAGE_SIZE', 10)
FORUM_PAGE_SIZE = get('DJANGOBB_FORUM_PAGE_SIZE', 20)
SEARCH_PAGE_SIZE = get('DJANGOBB_SEARCH_PAGE_SIZE', 20)

View file

@ -185,6 +185,14 @@ def urlize(html):
return html
return urlized_html
def filter_language(text):
"""
Replaces filtered language in the given text with an asterisk.
"""
return re.sub(forum_settings.LANGUAGE_FILTER, '*', text)
def _smile_replacer(data):
for smile, path in _SMILES:
data = smile.sub(path, data)