Skip to content

Commit

Permalink
comment.forms ST_COMMENT_MAX_LEN nitely#107
Browse files Browse the repository at this point in the history
  • Loading branch information
nitely committed Mar 15, 2016
1 parent 5b1dd98 commit 16e7cbf
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
3 changes: 3 additions & 0 deletions spirit/comment/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

class CommentForm(forms.ModelForm):

comment = forms.CharField(
max_length=settings.ST_COMMENT_MAX_LEN, widget=forms.Textarea)

class Meta:
model = Comment
fields = ['comment', ]
Expand Down
19 changes: 19 additions & 0 deletions spirit/comment/migrations/0004_auto_20160315_2021.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('spirit_comment', '0003_auto_20151115_0400'),
]

operations = [
migrations.AlterField(
model_name='comment',
name='comment',
field=models.TextField(verbose_name='comment'),
),
]
4 changes: 1 addition & 3 deletions spirit/comment/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
from .managers import CommentQuerySet


COMMENT_MAX_LEN = 3000 # changing this needs migration

COMMENT, MOVED, CLOSED, UNCLOSED, PINNED, UNPINNED = range(6)

ACTION = (
Expand All @@ -31,7 +29,7 @@ class Comment(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='st_comments')
topic = models.ForeignKey('spirit_topic.Topic')

comment = models.TextField(_("comment"), max_length=COMMENT_MAX_LEN)
comment = models.TextField(_("comment"))
comment_html = models.TextField(_("comment html"))
action = models.IntegerField(_("action"), choices=ACTION, default=COMMENT)
date = models.DateTimeField(default=timezone.now)
Expand Down
18 changes: 18 additions & 0 deletions spirit/comment/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,24 @@ def test_comment_image_upload_invalid(self):
form = CommentImageForm(data={}, files=files)
self.assertFalse(form.is_valid())

def test_comment_max_len(self):
"""
Restrict comment len
"""
comment = 'a' * settings.ST_COMMENT_MAX_LEN
form_data = {'comment': comment, }
form = CommentForm(data=form_data)
self.assertEqual(form.is_valid(), True)

def test_comment_max_len_invalid(self):
"""
Restrict comment len
"""
comment = 'a' * (settings.ST_COMMENT_MAX_LEN + 1)
form_data = {'comment': comment, }
form = CommentForm(data=form_data)
self.assertEqual(form.is_valid(), False)


class CommentUtilsTest(TestCase):

Expand Down
1 change: 1 addition & 0 deletions spirit/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

ST_NOTIFICATIONS_PER_PAGE = 20

ST_COMMENT_MAX_LEN = 3000
ST_MENTIONS_PER_COMMENT = 30

ST_YT_PAGINATOR_PAGE_RANGE = 3
Expand Down

0 comments on commit 16e7cbf

Please sign in to comment.