diff --git a/boards/forms.py b/boards/forms.py --- a/boards/forms.py +++ b/boards/forms.py @@ -1,3 +1,4 @@ +import hashlib import re import time import pytz @@ -151,6 +152,7 @@ class PostForm(NeboardForm): threads = forms.CharField(required=False, label=_('Additional threads'), widget=forms.TextInput(attrs={ATTRIBUTE_PLACEHOLDER: '123 456 789'})) + tripcode = forms.BooleanField(label=_('Tripcode'), required=False) session = None need_to_ban = False @@ -237,6 +239,10 @@ class PostForm(NeboardForm): file = self.cleaned_data['file'] return file or self.cleaned_data['file_url'] + def get_tripcode(self): + if self.cleaned_data['tripcode']: + return hashlib.sha1(self.session.session_key.encode()).hexdigest() + def _clean_text_file(self): text = self.cleaned_data.get('text') file = self.get_file() diff --git a/boards/migrations/0024_post_tripcode.py b/boards/migrations/0024_post_tripcode.py new file mode 100644 --- /dev/null +++ b/boards/migrations/0024_post_tripcode.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('boards', '0023_auto_20150818_1026'), + ] + + operations = [ + migrations.AddField( + model_name='post', + name='tripcode', + field=models.CharField(max_length=50, 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 @@ -74,7 +74,7 @@ IMAGE_TYPES = ( 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): + ip=NO_IP, tags: list=None, opening_posts: list=None, tripcode=None): """ Creates new post """ @@ -106,7 +106,8 @@ class PostManager(models.Manager): pub_time=posting_time, poster_ip=ip, thread=thread, - last_edit_time=posting_time) + last_edit_time=posting_time, + tripcode=tripcode) post.threads.add(thread) logger = logging.getLogger('boards.post.create') @@ -201,6 +202,8 @@ class Post(models.Model, Viewable): url = models.TextField() uid = models.TextField(db_index=True) + tripcode = models.CharField(max_length=50, null=True) + def __str__(self): return 'P#{}/{}'.format(self.id, self.title) @@ -436,3 +439,9 @@ class Post(models.Model, Viewable): thread.last_edit_time = self.last_edit_time thread.save(update_fields=['last_edit_time', 'bumpable']) self.threads.add(opening_post.get_thread()) + + def get_tripcode_color(self): + return self.tripcode[:6] + + def get_short_tripcode(self): + return self.tripcode[:10] \ No newline at end of file diff --git a/boards/static/css/md/base_page.css b/boards/static/css/md/base_page.css --- a/boards/static/css/md/base_page.css +++ b/boards/static/css/md/base_page.css @@ -167,7 +167,7 @@ p, .br { display: table-cell; } -.post-form input:not([name="image"]), .post-form textarea, .post-form select { +.post-form input:not([name="image"]):not([type="checkbox"]):not([type="submit"]), .post-form textarea, .post-form select { background: #333; color: #fff; border: solid 1px; @@ -192,7 +192,7 @@ p, .br { margin-bottom: 0.5ex; } -.post-form input[type="submit"], input[type="submit"] { +input[type="submit"] { background: #222; border: solid 2px #fff; color: #fff; diff --git a/boards/templates/boards/post.html b/boards/templates/boards/post.html --- a/boards/templates/boards/post.html +++ b/boards/templates/boards/post.html @@ -8,6 +8,9 @@ #{{ post.get_absolute_id }} {{ post.title }} + {% if post.tripcode %} + {{ post.get_short_tripcode }} + {% endif %} {% comment %} Thread death time needs to be shown only if the thread is alredy archived and this is an opening post (thread death time) or a post for popup diff --git a/boards/views/all_threads.py b/boards/views/all_threads.py --- a/boards/views/all_threads.py +++ b/boards/views/all_threads.py @@ -151,7 +151,8 @@ class AllThreadsView(PostMixin, BaseBoar tags = self.parse_tags_string(tag_strings) post = Post.objects.create_post(title=title, text=text, file=file, - ip=ip, tags=tags, opening_posts=threads) + ip=ip, tags=tags, opening_posts=threads, + tripcode=form.get_tripcode()) # This is required to update the threads to which posts we have replied # when creating this one diff --git a/boards/views/thread/thread.py b/boards/views/thread/thread.py --- a/boards/views/thread/thread.py +++ b/boards/views/thread/thread.py @@ -1,3 +1,4 @@ +import hashlib from django.core.exceptions import ObjectDoesNotExist from django.http import Http404 from django.shortcuts import get_object_or_404, render, redirect @@ -111,7 +112,8 @@ class ThreadView(BaseBoardView, PostMixi post = Post.objects.create_post(title=title, text=text, file=file, thread=post_thread, ip=ip, - opening_posts=threads) + opening_posts=threads, + tripcode=form.get_tripcode()) post.notify_clients() if html_response: