##// END OF EJS Templates
Added tripcodes
neko259 -
r1293:0b9a5210 default
parent child Browse files
Show More
@@ -0,0 +1,19 b''
1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
3
4 from django.db import models, migrations
5
6
7 class Migration(migrations.Migration):
8
9 dependencies = [
10 ('boards', '0023_auto_20150818_1026'),
11 ]
12
13 operations = [
14 migrations.AddField(
15 model_name='post',
16 name='tripcode',
17 field=models.CharField(max_length=50, null=True),
18 ),
19 ]
@@ -1,3 +1,4 b''
1 import hashlib
1 2 import re
2 3 import time
3 4 import pytz
@@ -151,6 +152,7 b' class PostForm(NeboardForm):'
151 152 threads = forms.CharField(required=False, label=_('Additional threads'),
152 153 widget=forms.TextInput(attrs={ATTRIBUTE_PLACEHOLDER:
153 154 '123 456 789'}))
155 tripcode = forms.BooleanField(label=_('Tripcode'), required=False)
154 156
155 157 session = None
156 158 need_to_ban = False
@@ -237,6 +239,10 b' class PostForm(NeboardForm):'
237 239 file = self.cleaned_data['file']
238 240 return file or self.cleaned_data['file_url']
239 241
242 def get_tripcode(self):
243 if self.cleaned_data['tripcode']:
244 return hashlib.sha1(self.session.session_key.encode()).hexdigest()
245
240 246 def _clean_text_file(self):
241 247 text = self.cleaned_data.get('text')
242 248 file = self.get_file()
@@ -74,7 +74,7 b' IMAGE_TYPES = ('
74 74 class PostManager(models.Manager):
75 75 @transaction.atomic
76 76 def create_post(self, title: str, text: str, file=None, thread=None,
77 ip=NO_IP, tags: list=None, opening_posts: list=None):
77 ip=NO_IP, tags: list=None, opening_posts: list=None, tripcode=None):
78 78 """
79 79 Creates new post
80 80 """
@@ -106,7 +106,8 b' class PostManager(models.Manager):'
106 106 pub_time=posting_time,
107 107 poster_ip=ip,
108 108 thread=thread,
109 last_edit_time=posting_time)
109 last_edit_time=posting_time,
110 tripcode=tripcode)
110 111 post.threads.add(thread)
111 112
112 113 logger = logging.getLogger('boards.post.create')
@@ -201,6 +202,8 b' class Post(models.Model, Viewable):'
201 202 url = models.TextField()
202 203 uid = models.TextField(db_index=True)
203 204
205 tripcode = models.CharField(max_length=50, null=True)
206
204 207 def __str__(self):
205 208 return 'P#{}/{}'.format(self.id, self.title)
206 209
@@ -436,3 +439,9 b' class Post(models.Model, Viewable):'
436 439 thread.last_edit_time = self.last_edit_time
437 440 thread.save(update_fields=['last_edit_time', 'bumpable'])
438 441 self.threads.add(opening_post.get_thread())
442
443 def get_tripcode_color(self):
444 return self.tripcode[:6]
445
446 def get_short_tripcode(self):
447 return self.tripcode[:10] No newline at end of file
@@ -167,7 +167,7 b' p, .br {'
167 167 display: table-cell;
168 168 }
169 169
170 .post-form input:not([name="image"]), .post-form textarea, .post-form select {
170 .post-form input:not([name="image"]):not([type="checkbox"]):not([type="submit"]), .post-form textarea, .post-form select {
171 171 background: #333;
172 172 color: #fff;
173 173 border: solid 1px;
@@ -192,7 +192,7 b' p, .br {'
192 192 margin-bottom: 0.5ex;
193 193 }
194 194
195 .post-form input[type="submit"], input[type="submit"] {
195 input[type="submit"] {
196 196 background: #222;
197 197 border: solid 2px #fff;
198 198 color: #fff;
@@ -8,6 +8,9 b''
8 8 <a class="post_id" href="{{ post.get_absolute_url }}">#{{ post.get_absolute_id }}</a>
9 9 <span class="title">{{ post.title }}</span>
10 10 <span class="pub_time"><time datetime="{{ post.pub_time|date:'c' }}">{{ post.pub_time }}</time></span>
11 {% if post.tripcode %}
12 <span style="color: #{{post.get_tripcode_color}}">{{ post.get_short_tripcode }}</span>
13 {% endif %}
11 14 {% comment %}
12 15 Thread death time needs to be shown only if the thread is alredy archived
13 16 and this is an opening post (thread death time) or a post for popup
@@ -151,7 +151,8 b' class AllThreadsView(PostMixin, BaseBoar'
151 151 tags = self.parse_tags_string(tag_strings)
152 152
153 153 post = Post.objects.create_post(title=title, text=text, file=file,
154 ip=ip, tags=tags, opening_posts=threads)
154 ip=ip, tags=tags, opening_posts=threads,
155 tripcode=form.get_tripcode())
155 156
156 157 # This is required to update the threads to which posts we have replied
157 158 # when creating this one
@@ -1,3 +1,4 b''
1 import hashlib
1 2 from django.core.exceptions import ObjectDoesNotExist
2 3 from django.http import Http404
3 4 from django.shortcuts import get_object_or_404, render, redirect
@@ -111,7 +112,8 b' class ThreadView(BaseBoardView, PostMixi'
111 112
112 113 post = Post.objects.create_post(title=title, text=text, file=file,
113 114 thread=post_thread, ip=ip,
114 opening_posts=threads)
115 opening_posts=threads,
116 tripcode=form.get_tripcode())
115 117 post.notify_clients()
116 118
117 119 if html_response:
General Comments 0
You need to be logged in to leave comments. Login now