diff --git a/boards/forms.py b/boards/forms.py --- a/boards/forms.py +++ b/boards/forms.py @@ -42,6 +42,8 @@ TAG_MAX_LENGTH = 20 TEXTAREA_ROWS = 4 +TRIPCODE_DELIM = '#' + def get_timezones(): timezones = [] @@ -239,14 +241,17 @@ class PostForm(NeboardForm): def get_tripcode(self): title = self.cleaned_data['title'] - if title is not None and '#' in title: - code = title.split('#', maxsplit=1)[1] + neboard.settings.SECRET_KEY - return hashlib.md5(code.encode()).hexdigest() + if title is not None and TRIPCODE_DELIM in title: + code = title.split(TRIPCODE_DELIM, maxsplit=1)[1] + neboard.settings.SECRET_KEY + tripcode = hashlib.md5(code.encode()).hexdigest() + else: + tripcode = '' + return tripcode def get_title(self): title = self.cleaned_data['title'] - if title is not None and '#' in title: - return title.split('#', maxsplit=1)[0] + if title is not None and TRIPCODE_DELIM in title: + return title.split(TRIPCODE_DELIM, maxsplit=1)[0] else: return title diff --git a/boards/migrations/0032_auto_20151014_2222.py b/boards/migrations/0032_auto_20151014_2222.py new file mode 100644 --- /dev/null +++ b/boards/migrations/0032_auto_20151014_2222.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('boards', '0031_post_hidden'), + ] + + operations = [ + migrations.AlterField( + model_name='post', + name='tripcode', + field=models.CharField(default='', blank=True, max_length=50), + ), + ] diff --git a/boards/migrations/0033_auto_20151014_2224.py b/boards/migrations/0033_auto_20151014_2224.py new file mode 100644 --- /dev/null +++ b/boards/migrations/0033_auto_20151014_2224.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('boards', '0032_auto_20151014_2222'), + ] + + operations = [ + migrations.AlterField( + model_name='tag', + name='parent', + field=models.ForeignKey(blank=True, related_name='children', to='boards.Tag', null=True), + ), + ] diff --git a/boards/models/post/__init__.py b/boards/models/post/__init__.py --- a/boards/models/post/__init__.py +++ b/boards/models/post/__init__.py @@ -97,7 +97,7 @@ class Post(models.Model, Viewable): url = models.TextField() uid = models.TextField(db_index=True) - tripcode = models.CharField(max_length=50, null=True) + tripcode = models.CharField(max_length=50, blank=True, default='') opening = models.BooleanField() hidden = models.BooleanField(default=False) diff --git a/boards/models/post/manager.py b/boards/models/post/manager.py --- a/boards/models/post/manager.py +++ b/boards/models/post/manager.py @@ -30,7 +30,8 @@ NO_IP = '0.0.0.0' class PostManager(models.Manager): @transaction.atomic def create_post(self, title: str, text: str, file=None, thread=None, - ip=NO_IP, tags: list=None, opening_posts: list=None, tripcode=None): + ip=NO_IP, tags: list=None, opening_posts: list=None, + tripcode=''): """ Creates new post """ diff --git a/boards/models/tag.py b/boards/models/tag.py --- a/boards/models/tag.py +++ b/boards/models/tag.py @@ -48,7 +48,8 @@ class Tag(models.Model, Viewable): required = models.BooleanField(default=False, db_index=True) description = models.TextField(blank=True) - parent = models.ForeignKey('Tag', null=True, related_name='children') + parent = models.ForeignKey('Tag', null=True, blank=True, + related_name='children') def __str__(self): return self.name