Show More
@@ -0,0 +1,19 b'' | |||||
|
1 | from django.core.management import BaseCommand | |||
|
2 | from django.db import transaction | |||
|
3 | from django.db.models import Count | |||
|
4 | ||||
|
5 | from boards.models import Tag | |||
|
6 | ||||
|
7 | ||||
|
8 | __author__ = 'neko259' | |||
|
9 | ||||
|
10 | ||||
|
11 | class Command(BaseCommand): | |||
|
12 | help = 'Removed tags that have no threads' | |||
|
13 | ||||
|
14 | @transaction.atomic | |||
|
15 | def handle(self, *args, **options): | |||
|
16 | empty = Tag.objects.annotate(num_threads=Count('thread'))\ | |||
|
17 | .filter(num_threads=0).order_by('-required', 'name') | |||
|
18 | print('Removing {} empty tags'.format(empty.count())) | |||
|
19 | empty.delete() |
@@ -0,0 +1,29 b'' | |||||
|
1 | # -*- coding: utf-8 -*- | |||
|
2 | from __future__ import unicode_literals | |||
|
3 | ||||
|
4 | import uuid | |||
|
5 | ||||
|
6 | from django.db import models, migrations | |||
|
7 | ||||
|
8 | ||||
|
9 | class Migration(migrations.Migration): | |||
|
10 | ||||
|
11 | def assign_uids(apps, schema_editor): | |||
|
12 | Post = apps.get_model('boards', 'Post') | |||
|
13 | for post in Post.objects.all(): | |||
|
14 | post.uid = str(uuid.uuid4()) | |||
|
15 | post.save(update_fields=['uid']) | |||
|
16 | ||||
|
17 | dependencies = [ | |||
|
18 | ('boards', '0014_auto_20150418_1749'), | |||
|
19 | ] | |||
|
20 | ||||
|
21 | operations = [ | |||
|
22 | migrations.AddField( | |||
|
23 | model_name='post', | |||
|
24 | name='uid', | |||
|
25 | field=models.TextField(default=''), | |||
|
26 | preserve_default=False, | |||
|
27 | ), | |||
|
28 | migrations.RunPython(assign_uids), | |||
|
29 | ] |
@@ -10,7 +10,7 b' class PostAdmin(admin.ModelAdmin):' | |||||
10 | list_filter = ('pub_time',) |
|
10 | list_filter = ('pub_time',) | |
11 | search_fields = ('id', 'title', 'text') |
|
11 | search_fields = ('id', 'title', 'text') | |
12 | exclude = ('referenced_posts', 'refmap') |
|
12 | exclude = ('referenced_posts', 'refmap') | |
13 | readonly_fields = ('poster_ip', 'threads', 'thread', 'images') |
|
13 | readonly_fields = ('poster_ip', 'threads', 'thread', 'images', 'uid') | |
14 |
|
14 | |||
15 | def ban_poster(self, request, queryset): |
|
15 | def ban_poster(self, request, queryset): | |
16 | bans = 0 |
|
16 | bans = 0 |
@@ -2,6 +2,7 b' from datetime import datetime, timedelta' | |||||
2 | from datetime import time as dtime |
|
2 | from datetime import time as dtime | |
3 | import logging |
|
3 | import logging | |
4 | import re |
|
4 | import re | |
|
5 | import uuid | |||
5 |
|
6 | |||
6 | from django.core.exceptions import ObjectDoesNotExist |
|
7 | from django.core.exceptions import ObjectDoesNotExist | |
7 | from django.core.urlresolvers import reverse |
|
8 | from django.core.urlresolvers import reverse | |
@@ -175,7 +176,9 b' class Post(models.Model, Viewable):' | |||||
175 | refmap = models.TextField(null=True, blank=True) |
|
176 | refmap = models.TextField(null=True, blank=True) | |
176 | threads = models.ManyToManyField('Thread', db_index=True) |
|
177 | threads = models.ManyToManyField('Thread', db_index=True) | |
177 | thread = models.ForeignKey('Thread', db_index=True, related_name='pt+') |
|
178 | thread = models.ForeignKey('Thread', db_index=True, related_name='pt+') | |
|
179 | ||||
178 | url = models.TextField() |
|
180 | url = models.TextField() | |
|
181 | uid = models.TextField() | |||
179 |
|
182 | |||
180 | def __str__(self): |
|
183 | def __str__(self): | |
181 | return 'P#{}/{}'.format(self.id, self.title) |
|
184 | return 'P#{}/{}'.format(self.id, self.title) | |
@@ -358,6 +361,10 b' class Post(models.Model, Viewable):' | |||||
358 | update_fields=None): |
|
361 | update_fields=None): | |
359 | self._text_rendered = Parser().parse(self.get_raw_text()) |
|
362 | self._text_rendered = Parser().parse(self.get_raw_text()) | |
360 |
|
363 | |||
|
364 | self.uid = str(uuid.uuid4()) | |||
|
365 | if update_fields is not None and 'uid' not in update_fields: | |||
|
366 | update_fields += ['uid'] | |||
|
367 | ||||
361 | if self.id: |
|
368 | if self.id: | |
362 | for thread in self.get_threads().all(): |
|
369 | for thread in self.get_threads().all(): | |
363 | if thread.can_bump(): |
|
370 | if thread.can_bump(): |
@@ -86,26 +86,21 b' function getThreadDiff() {' | |||||
86 | var lastUpdateTime = $('.metapanel').attr('data-last-update'); |
|
86 | var lastUpdateTime = $('.metapanel').attr('data-last-update'); | |
87 | var lastPostId = $('.post').last().attr('id'); |
|
87 | var lastPostId = $('.post').last().attr('id'); | |
88 |
|
88 | |||
89 | var diffUrl = '/api/diff_thread?thread=' + threadId + '&last_update=' + encodeURIComponent(lastUpdateTime) |
|
89 | var uids = ''; | |
90 | + '&last_post=' + lastPostId; |
|
90 | var posts = $('.post'); | |
91 |
|
91 | for (var i = 0; i < posts.length; i++) { | ||
92 | $.getJSON(diffUrl) |
|
92 | uids += posts[i].getAttribute('data-uid') + ' '; | |
93 | .success(function(data) { |
|
93 | } | |
94 | var addedPosts = data.added; |
|
|||
95 |
|
94 | |||
96 | for (var i = 0; i < addedPosts.length; i++) { |
|
95 | var data = { | |
97 | var postText = addedPosts[i]; |
|
96 | uids: uids | |
98 | var post = $(postText); |
|
97 | } | |
99 |
|
||||
100 | updatePost(post); |
|
|||
101 | } |
|
|||
102 |
|
98 | |||
103 | var addedPostsCount = addedPosts.length; |
|
99 | var diffUrl = '/api/diff_thread?thread=' + threadId; | |
104 | if (addedPostsCount > 0) { |
|
|||
105 | updateBumplimitProgress(addedPostsCount); |
|
|||
106 | showNewPostsTitle(addedPostsCount); |
|
|||
107 | } |
|
|||
108 |
|
100 | |||
|
101 | $.post(diffUrl, | |||
|
102 | data, | |||
|
103 | function(data) { | |||
109 | var updatedPosts = data.updated; |
|
104 | var updatedPosts = data.updated; | |
110 |
|
105 | |||
111 | for (var i = 0; i < updatedPosts.length; i++) { |
|
106 | for (var i = 0; i < updatedPosts.length; i++) { | |
@@ -115,14 +110,16 b' function getThreadDiff() {' | |||||
115 | updatePost(post); |
|
110 | updatePost(post); | |
116 | } |
|
111 | } | |
117 |
|
112 | |||
118 |
var hasMetaUpdates = |
|
113 | var hasMetaUpdates = updatedPosts.length > 0; | |
119 | if (hasMetaUpdates) { |
|
114 | if (hasMetaUpdates) { | |
120 | updateMetadataPanel(); |
|
115 | updateMetadataPanel(); | |
121 | } |
|
116 | } | |
122 |
|
117 | |||
123 | // TODO Process removed posts if any |
|
118 | // TODO Process removed posts if any | |
124 | $('.metapanel').attr('data-last-update', data.last_update); |
|
119 | $('.metapanel').attr('data-last-update', data.last_update); | |
125 |
} |
|
120 | }, | |
|
121 | 'json' | |||
|
122 | ) | |||
126 | } |
|
123 | } | |
127 |
|
124 | |||
128 | /** |
|
125 | /** | |
@@ -150,6 +147,9 b' function updatePost(postHtml) {' | |||||
150 | if (bottom) { |
|
147 | if (bottom) { | |
151 | scrollToBottom(); |
|
148 | scrollToBottom(); | |
152 | } |
|
149 | } | |
|
150 | ||||
|
151 | updateBumplimitProgress(1); | |||
|
152 | showNewPostsTitle(1); | |||
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | processNewPost(post); |
|
155 | processNewPost(post); |
@@ -3,7 +3,7 b'' | |||||
3 |
|
3 | |||
4 | {% get_current_language as LANGUAGE_CODE %} |
|
4 | {% get_current_language as LANGUAGE_CODE %} | |
5 |
|
5 | |||
6 | <div class="{{ css_class }}" id="{{ post.id }}"> |
|
6 | <div class="{{ css_class }}" id="{{ post.id }}" data-uid="{{ post.uid }}"> | |
7 | <div class="post-info"> |
|
7 | <div class="post-info"> | |
8 | <a class="post_id" href="{{ post.get_url }}">({{ post.get_absolute_id }})</a> |
|
8 | <a class="post_id" href="{{ post.get_url }}">({{ post.get_absolute_id }})</a> | |
9 | <span class="title">{{ post.title }}</span> |
|
9 | <span class="title">{{ post.title }}</span> |
@@ -40,28 +40,20 b' def api_get_threaddiff(request):' | |||||
40 | """ |
|
40 | """ | |
41 |
|
41 | |||
42 | thread_id = request.GET.get('thread') |
|
42 | thread_id = request.GET.get('thread') | |
43 | last_update_time = request.GET.get('last_update') |
|
43 | uids_str = request.POST.get('uids').strip() | |
44 | last_post = request.GET.get('last_post') |
|
44 | uids = uids_str.split(' ') | |
45 |
|
45 | |||
46 | thread = get_object_or_404(Post, id=thread_id).get_thread() |
|
46 | thread = get_object_or_404(Post, id=thread_id).get_thread() | |
47 |
|
47 | |||
48 | json_data = { |
|
48 | json_data = { | |
49 | PARAMETER_ADDED: [], |
|
|||
50 | PARAMETER_UPDATED: [], |
|
49 | PARAMETER_UPDATED: [], | |
51 | 'last_update': None, |
|
50 | 'last_update': None, | |
52 | } |
|
51 | } | |
53 |
|
|
52 | posts = Post.objects.filter(threads__in=[thread]).exclude(uid__in=uids) | |
54 | id__gt=int(last_post)) \ |
|
|||
55 | .order_by('pub_time') |
|
|||
56 | updated_posts = Post.objects.filter(threads__in=[thread], |
|
|||
57 | pub_time__lte=last_update_time, |
|
|||
58 | last_edit_time__gt=last_update_time) |
|
|||
59 |
|
53 | |||
60 | diff_type = request.GET.get(PARAMETER_DIFF_TYPE, DIFF_TYPE_HTML) |
|
54 | diff_type = request.GET.get(PARAMETER_DIFF_TYPE, DIFF_TYPE_HTML) | |
61 |
|
55 | |||
62 |
for post in |
|
56 | for post in posts: | |
63 | json_data[PARAMETER_ADDED].append(get_post_data(post.id, diff_type, request)) |
|
|||
64 | for post in updated_posts: |
|
|||
65 | json_data[PARAMETER_UPDATED].append(get_post_data(post.id, diff_type, request)) |
|
57 | json_data[PARAMETER_UPDATED].append(get_post_data(post.id, diff_type, request)) | |
66 | json_data[PARAMETER_LAST_UPDATE] = str(thread.last_edit_time) |
|
58 | json_data[PARAMETER_LAST_UPDATE] = str(thread.last_edit_time) | |
67 |
|
59 |
General Comments 0
You need to be logged in to leave comments.
Login now