diff --git a/boards/admin.py b/boards/admin.py --- a/boards/admin.py +++ b/boards/admin.py @@ -10,7 +10,7 @@ class PostAdmin(admin.ModelAdmin): list_filter = ('pub_time',) search_fields = ('id', 'title', 'text') exclude = ('referenced_posts', 'refmap') - readonly_fields = ('poster_ip', 'threads', 'thread', 'images') + readonly_fields = ('poster_ip', 'threads', 'thread', 'images', 'uid') def ban_poster(self, request, queryset): bans = 0 diff --git a/boards/management/commands/cleantags.py b/boards/management/commands/cleantags.py new file mode 100644 --- /dev/null +++ b/boards/management/commands/cleantags.py @@ -0,0 +1,19 @@ +from django.core.management import BaseCommand +from django.db import transaction +from django.db.models import Count + +from boards.models import Tag + + +__author__ = 'neko259' + + +class Command(BaseCommand): + help = 'Removed tags that have no threads' + + @transaction.atomic + def handle(self, *args, **options): + empty = Tag.objects.annotate(num_threads=Count('thread'))\ + .filter(num_threads=0).order_by('-required', 'name') + print('Removing {} empty tags'.format(empty.count())) + empty.delete() diff --git a/boards/migrations/0015_auto_20150420_1331.py b/boards/migrations/0015_auto_20150420_1331.py new file mode 100644 --- /dev/null +++ b/boards/migrations/0015_auto_20150420_1331.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +import uuid + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + def assign_uids(apps, schema_editor): + Post = apps.get_model('boards', 'Post') + for post in Post.objects.all(): + post.uid = str(uuid.uuid4()) + post.save(update_fields=['uid']) + + dependencies = [ + ('boards', '0014_auto_20150418_1749'), + ] + + operations = [ + migrations.AddField( + model_name='post', + name='uid', + field=models.TextField(default=''), + preserve_default=False, + ), + migrations.RunPython(assign_uids), + ] diff --git a/boards/models/post.py b/boards/models/post.py --- a/boards/models/post.py +++ b/boards/models/post.py @@ -2,6 +2,7 @@ from datetime import datetime, timedelta from datetime import time as dtime import logging import re +import uuid from django.core.exceptions import ObjectDoesNotExist from django.core.urlresolvers import reverse @@ -175,7 +176,9 @@ class Post(models.Model, Viewable): refmap = models.TextField(null=True, blank=True) threads = models.ManyToManyField('Thread', db_index=True) thread = models.ForeignKey('Thread', db_index=True, related_name='pt+') + url = models.TextField() + uid = models.TextField() def __str__(self): return 'P#{}/{}'.format(self.id, self.title) @@ -358,6 +361,10 @@ class Post(models.Model, Viewable): update_fields=None): self._text_rendered = Parser().parse(self.get_raw_text()) + self.uid = str(uuid.uuid4()) + if update_fields is not None and 'uid' not in update_fields: + update_fields += ['uid'] + if self.id: for thread in self.get_threads().all(): if thread.can_bump(): diff --git a/boards/static/js/thread_update.js b/boards/static/js/thread_update.js --- a/boards/static/js/thread_update.js +++ b/boards/static/js/thread_update.js @@ -86,26 +86,21 @@ function getThreadDiff() { var lastUpdateTime = $('.metapanel').attr('data-last-update'); var lastPostId = $('.post').last().attr('id'); - var diffUrl = '/api/diff_thread?thread=' + threadId + '&last_update=' + encodeURIComponent(lastUpdateTime) - + '&last_post=' + lastPostId; - - $.getJSON(diffUrl) - .success(function(data) { - var addedPosts = data.added; + var uids = ''; + var posts = $('.post'); + for (var i = 0; i < posts.length; i++) { + uids += posts[i].getAttribute('data-uid') + ' '; + } - for (var i = 0; i < addedPosts.length; i++) { - var postText = addedPosts[i]; - var post = $(postText); - - updatePost(post); - } + var data = { + uids: uids + } - var addedPostsCount = addedPosts.length; - if (addedPostsCount > 0) { - updateBumplimitProgress(addedPostsCount); - showNewPostsTitle(addedPostsCount); - } + var diffUrl = '/api/diff_thread?thread=' + threadId; + $.post(diffUrl, + data, + function(data) { var updatedPosts = data.updated; for (var i = 0; i < updatedPosts.length; i++) { @@ -115,14 +110,16 @@ function getThreadDiff() { updatePost(post); } - var hasMetaUpdates = addedPostsCount > 0 || updatedPosts.length > 0; + var hasMetaUpdates = updatedPosts.length > 0; if (hasMetaUpdates) { updateMetadataPanel(); } // TODO Process removed posts if any $('.metapanel').attr('data-last-update', data.last_update); - }) + }, + 'json' + ) } /** @@ -150,6 +147,9 @@ function updatePost(postHtml) { if (bottom) { scrollToBottom(); } + + updateBumplimitProgress(1); + showNewPostsTitle(1); } processNewPost(post); 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 @@ -3,7 +3,7 @@ {% get_current_language as LANGUAGE_CODE %} -
+