diff --git a/boards/admin.py b/boards/admin.py --- a/boards/admin.py +++ b/boards/admin.py @@ -1,6 +1,7 @@ from django.contrib import admin from django.utils.translation import ugettext_lazy as _ from django.core.urlresolvers import reverse +from django.db.models import F from boards.models import Post, Tag, Ban, Thread, Banner, PostImage, KeyPair, GlobalId @@ -12,7 +13,8 @@ class PostAdmin(admin.ModelAdmin): search_fields = ('id', 'title', 'text', 'poster_ip') exclude = ('referenced_posts', 'refmap', 'images', 'global_id') readonly_fields = ('poster_ip', 'threads', 'thread', 'linked_images', - 'attachments', 'uid', 'url', 'pub_time', 'opening', 'linked_global_id') + 'attachments', 'uid', 'url', 'pub_time', 'opening', 'linked_global_id', + 'version') def ban_poster(self, request, queryset): bans = 0 @@ -54,6 +56,11 @@ class PostAdmin(admin.ModelAdmin): args=[global_id.id]), str(global_id)) linked_global_id.allow_tags = True + def save_model(self, request, obj, form, change): + obj.increment_version() + obj.save() + obj.clear_cache() + actions = ['ban_poster', 'ban_with_hiding'] @@ -96,6 +103,14 @@ class ThreadAdmin(admin.ModelAdmin): def save_related(self, request, form, formsets, change): super().save_related(request, form, formsets, change) form.instance.refresh_tags() + + def save_model(self, request, obj, form, change): + op = obj.get_opening_post() + op.increment_version() + op.save(update_fields=['version']) + obj.save() + op.clear_cache() + list_display = ('id', 'op', 'title', 'reply_count', 'status', 'ip', 'display_tags') list_filter = ('bump_time', 'status') diff --git a/boards/migrations/0045_post_version.py b/boards/migrations/0045_post_version.py new file mode 100644 --- /dev/null +++ b/boards/migrations/0045_post_version.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.5 on 2016-05-11 09:23 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('boards', '0044_globalid_content'), + ] + + operations = [ + migrations.AddField( + model_name='post', + name='version', + field=models.IntegerField(default=1), + ), + ] 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 @@ -11,7 +11,7 @@ from boards.utils import datetime_to_epo from django.core.exceptions import ObjectDoesNotExist from django.core.urlresolvers import reverse from django.db import models -from django.db.models import TextField, QuerySet +from django.db.models import TextField, QuerySet, F from django.template.defaultfilters import truncatewords, striptags from django.template.loader import render_to_string @@ -104,6 +104,7 @@ class Post(models.Model, Viewable): tripcode = models.CharField(max_length=50, blank=True, default='') opening = models.BooleanField(db_index=True) hidden = models.BooleanField(default=False) + version = models.IntegerField(default=1) def __str__(self): return 'P#{}/{}'.format(self.id, self.get_title()) @@ -379,3 +380,14 @@ class Post(models.Model, Viewable): def set_hidden(self, hidden): self.hidden = hidden + + def increment_version(self): + self.version = F('version') + 1 + + def clear_cache(self): + global_id = self.global_id + if global_id is not None and global_id.is_local()\ + and global_id.content is not None: + global_id.content = None + global_id.save() + global_id.signature_set.all().delete() diff --git a/boards/models/post/sync.py b/boards/models/post/sync.py --- a/boards/models/post/sync.py +++ b/boards/models/post/sync.py @@ -32,6 +32,7 @@ TAG_TAG = 'tag' TAG_ATTACHMENT_REFS = 'attachment-refs' TAG_ATTACHMENT_REF = 'attachment-ref' TAG_TRIPCODE = 'tripcode' +TAG_VERSION = 'version' TYPE_GET = 'get' @@ -126,6 +127,8 @@ class SyncManager: SyncManager._attachment_to_xml( attachments_tag, attachment_refs, file.file.file, file.hash, file.file.url) + version_tag = et.SubElement(content_tag, TAG_VERSION) + version_tag.text = str(post.version) global_id.content = et.tostring(content_tag, ENCODING_UNICODE) global_id.save()