Skip to content

Commit

Permalink
add requirement for certain number of non-punctuation characters to t…
Browse files Browse the repository at this point in the history
…itle
  • Loading branch information
evgenyfadeev committed Jul 11, 2015
1 parent b908afb commit a84d18a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions askbot/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from django.contrib.auth.models import User
from django_countries import countries
from askbot.utils.forms import NextUrlField, UserNameField
from askbot.utils.slug import slugify
from askbot.mail import extract_first_email_address
from recaptcha_works.fields import RecaptchaField
from askbot.conf import settings as askbot_settings
Expand Down Expand Up @@ -297,13 +298,16 @@ def clean(self, value):
also is supposed to work for unicode non-ascii characters"""
if value is None:
value = ''
if len(value) < askbot_settings.MIN_TITLE_LENGTH:

chars = slugify(value).replace('-', '')
if len(chars) < askbot_settings.MIN_TITLE_LENGTH:
msg = ungettext_lazy(
'must have > %d character',
'must have > %d characters',
'must have > %d non-punctuation character',
'must have > %d non-punctuation characters',
askbot_settings.MIN_TITLE_LENGTH
) % askbot_settings.MIN_TITLE_LENGTH
raise forms.ValidationError(msg)

encoded_value = value.encode('utf-8')
question_term = askbot_settings.WORDS_QUESTION_SINGULAR
if len(value) == len(encoded_value):
Expand Down

0 comments on commit a84d18a

Please sign in to comment.